/*
* Copyright © 2014 Cask Data, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package co.cask.cdap.internal.app.runtime.distributed;
import co.cask.cdap.api.procedure.ProcedureSpecification;
import co.cask.cdap.app.ApplicationSpecification;
import co.cask.cdap.app.program.Program;
import co.cask.cdap.app.runtime.ProgramController;
import co.cask.cdap.app.runtime.ProgramOptions;
import co.cask.cdap.common.conf.CConfiguration;
import co.cask.cdap.proto.ProgramType;
import com.google.common.base.Preconditions;
import com.google.inject.Inject;
import org.apache.hadoop.conf.Configuration;
import org.apache.twill.api.TwillController;
import org.apache.twill.api.TwillRunner;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
/**
*
*/
public final class DistributedProcedureProgramRunner extends AbstractDistributedProgramRunner {
private static final Logger LOG = LoggerFactory.getLogger(DistributedProcedureProgramRunner.class);
@Inject
public DistributedProcedureProgramRunner(TwillRunner twillRunner, Configuration hConf, CConfiguration cConf) {
super(twillRunner, hConf, cConf);
}
@Override
protected ProgramController launch(Program program, ProgramOptions options,
File hConfFile, File cConfFile, ApplicationLauncher launcher) {
// Extract and verify parameters
ApplicationSpecification appSpec = program.getSpecification();
Preconditions.checkNotNull(appSpec, "Missing application specification.");
ProgramType processorType = program.getType();
Preconditions.checkNotNull(processorType, "Missing processor type.");
Preconditions.checkArgument(processorType == ProgramType.PROCEDURE, "Only PROCEDURE process type is supported.");
ProcedureSpecification procedureSpec = appSpec.getProcedures().get(program.getName());
Preconditions.checkNotNull(procedureSpec, "Missing ProcedureSpecification for %s", program.getName());
LOG.info("Launching distributed flow: " + program.getName() + ":" + procedureSpec.getName());
TwillController controller = launcher.launch(new ProcedureTwillApplication(program, procedureSpec,
hConfFile, cConfFile, eventHandler));
return new ProcedureTwillProgramController(program.getName(), controller).startListen();
}
}