use of co.cask.cdap.proto.ProgramType in project cdap by caskdata.
the class WebappProgramRunner method run.
@Override
public ProgramController run(Program program, ProgramOptions options) {
try {
ProgramType processorType = program.getType();
Preconditions.checkNotNull(processorType, "Missing processor type");
Preconditions.checkArgument(processorType == ProgramType.WEBAPP, "Only WEBAPP process type is supported");
LOG.info("Initializing Webapp for app {} with jar {}", program.getApplicationId(), program.getJarLocation().getName());
String serviceName = getServiceName(program.getId());
Preconditions.checkNotNull(serviceName, "Cannot determine service name for program %s", program.getName());
LOG.info("Got service name {}", serviceName);
// Start netty server
// TODO: add metrics reporting
JarHttpHandler jarHttpHandler = webappHttpHandlerFactory.createHandler(program.getJarLocation());
NettyHttpService.Builder builder = new CommonNettyHttpServiceBuilder(cConf, program.getId().toString());
builder.setHttpHandlers(jarHttpHandler);
builder.setUrlRewriter(new WebappURLRewriter(jarHttpHandler));
builder.setHost(hostname.getCanonicalHostName());
NettyHttpService httpService = builder.build();
httpService.start();
final InetSocketAddress address = httpService.getBindAddress();
RunId runId = ProgramRunners.getRunId(options);
// Register service, and the serving host names.
final List<Cancellable> cancellables = Lists.newArrayList();
LOG.info("Webapp {} running on address {} registering as {}", program.getApplicationId(), address, serviceName);
cancellables.add(serviceAnnouncer.announce(serviceName, address.getPort()));
for (String hname : getServingHostNames(Locations.newInputSupplier(program.getJarLocation()))) {
final String sname = ProgramType.WEBAPP.name().toLowerCase() + "/" + hname;
LOG.info("Webapp {} running on address {} registering as {}", program.getApplicationId(), address, sname);
cancellables.add(discoveryService.register(ResolvingDiscoverable.of(new Discoverable(sname, address))));
}
return new WebappProgramController(program.getId().run(runId), httpService, new Cancellable() {
@Override
public void cancel() {
for (Cancellable cancellable : cancellables) {
cancellable.cancel();
}
}
});
} catch (Exception e) {
throw Throwables.propagate(e);
}
}
use of co.cask.cdap.proto.ProgramType in project cdap by caskdata.
the class WorkflowProgramRunner method run.
@Override
public ProgramController run(final Program program, final ProgramOptions options) {
// Extract and verify options
ApplicationSpecification appSpec = program.getApplicationSpecification();
Preconditions.checkNotNull(appSpec, "Missing application specification.");
ProgramType processorType = program.getType();
Preconditions.checkNotNull(processorType, "Missing processor type.");
Preconditions.checkArgument(processorType == ProgramType.WORKFLOW, "Only WORKFLOW process type is supported.");
WorkflowSpecification workflowSpec = appSpec.getWorkflows().get(program.getName());
Preconditions.checkNotNull(workflowSpec, "Missing WorkflowSpecification for %s", program.getName());
final RunId runId = ProgramRunners.getRunId(options);
// Setup dataset framework context, if required
if (datasetFramework instanceof ProgramContextAware) {
ProgramId programId = program.getId();
((ProgramContextAware) datasetFramework).setContext(new BasicProgramContext(programId.run(runId)));
}
// List of all Closeable resources that needs to be cleanup
final List<Closeable> closeables = new ArrayList<>();
try {
PluginInstantiator pluginInstantiator = createPluginInstantiator(options, program.getClassLoader());
if (pluginInstantiator != null) {
closeables.add(pluginInstantiator);
}
WorkflowDriver driver = new WorkflowDriver(program, options, workflowSpec, programRunnerFactory, metricsCollectionService, datasetFramework, discoveryServiceClient, txClient, runtimeStore, cConf, pluginInstantiator, secureStore, secureStoreManager, messagingService, programStateWriter);
// Controller needs to be created before starting the driver so that the state change of the driver
// service can be fully captured by the controller.
ProgramController controller = new WorkflowProgramController(program.getId().run(runId), driver);
driver.start();
return controller;
} catch (Exception e) {
closeAllQuietly(closeables);
throw Throwables.propagate(e);
}
}
use of co.cask.cdap.proto.ProgramType in project cdap by caskdata.
the class ProgramLifecycleService method getExistingAppProgramSpecification.
/**
* Returns the {@link ProgramSpecification} for the specified {@link ProgramId program}.
* @param appSpec the {@link ApplicationSpecification} of the existing application
* @param programId the {@link ProgramId program} for which the {@link ProgramSpecification} is requested
* @return the {@link ProgramSpecification} for the specified {@link ProgramId program}
*/
private ProgramSpecification getExistingAppProgramSpecification(ApplicationSpecification appSpec, ProgramId programId) throws Exception {
String programName = programId.getProgram();
ProgramType type = programId.getType();
ProgramSpecification programSpec;
if (type == ProgramType.FLOW && appSpec.getFlows().containsKey(programName)) {
programSpec = appSpec.getFlows().get(programName);
} else if (type == ProgramType.MAPREDUCE && appSpec.getMapReduce().containsKey(programName)) {
programSpec = appSpec.getMapReduce().get(programName);
} else if (type == ProgramType.SPARK && appSpec.getSpark().containsKey(programName)) {
programSpec = appSpec.getSpark().get(programName);
} else if (type == ProgramType.WORKFLOW && appSpec.getWorkflows().containsKey(programName)) {
programSpec = appSpec.getWorkflows().get(programName);
} else if (type == ProgramType.SERVICE && appSpec.getServices().containsKey(programName)) {
programSpec = appSpec.getServices().get(programName);
} else if (type == ProgramType.WORKER && appSpec.getWorkers().containsKey(programName)) {
programSpec = appSpec.getWorkers().get(programName);
} else {
programSpec = null;
}
return programSpec;
}
use of co.cask.cdap.proto.ProgramType in project cdap by caskdata.
the class AbstractProgramRuntimeService method listAll.
@Override
public List<RuntimeInfo> listAll(ProgramType... types) {
List<RuntimeInfo> runningPrograms = new ArrayList<>();
for (ProgramType type : types) {
for (Map.Entry<RunId, ProgramRuntimeService.RuntimeInfo> entry : list(type).entrySet()) {
ProgramController.State programState = entry.getValue().getController().getState();
if (programState.isDone()) {
continue;
}
runningPrograms.add(entry.getValue());
}
}
return runningPrograms;
}
use of co.cask.cdap.proto.ProgramType in project cdap by caskdata.
the class ListAllProgramsCommand method perform.
@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
Map<ProgramType, List<ProgramRecord>> allPrograms = appClient.listAllPrograms(cliConfig.getCurrentNamespace());
List<ProgramRecord> allProgramsList = Lists.newArrayList();
for (List<ProgramRecord> subList : allPrograms.values()) {
allProgramsList.addAll(subList);
}
Table table = Table.builder().setHeader("type", "app", "id", "description").setRows(allProgramsList, new RowMaker<ProgramRecord>() {
@Override
public List<?> makeRow(ProgramRecord object) {
return Lists.newArrayList(object.getType().getCategoryName(), object.getApp(), object.getName(), object.getDescription());
}
}).build();
cliConfig.getTableRenderer().render(cliConfig, output, table);
}
Aggregations