use of co.cask.cdap.proto.ProgramType in project cdap by caskdata.
the class DistributedFlowProgramRunner method getFlowSpecification.
private FlowSpecification getFlowSpecification(Program program) {
// Extract and verify parameters
ApplicationSpecification appSpec = program.getApplicationSpecification();
Preconditions.checkNotNull(appSpec, "Missing application specification.");
ProgramType processorType = program.getType();
Preconditions.checkNotNull(processorType, "Missing processor type.");
Preconditions.checkArgument(processorType == ProgramType.FLOW, "Only FLOW process type is supported.");
FlowSpecification flowSpec = appSpec.getFlows().get(program.getName());
Preconditions.checkNotNull(flowSpec, "Missing FlowSpecification for %s", program.getName());
return flowSpec;
}
use of co.cask.cdap.proto.ProgramType in project cdap by caskdata.
the class DistributedMapReduceProgramRunner method validateOptions.
@Override
protected void validateOptions(Program program, ProgramOptions options) {
super.validateOptions(program, options);
// Extract and verify parameters
ApplicationSpecification appSpec = program.getApplicationSpecification();
Preconditions.checkNotNull(appSpec, "Missing application specification.");
ProgramType processorType = program.getType();
Preconditions.checkNotNull(processorType, "Missing processor type.");
Preconditions.checkArgument(processorType == ProgramType.MAPREDUCE, "Only MapReduce process type is supported.");
MapReduceSpecification spec = appSpec.getMapReduce().get(program.getName());
Preconditions.checkNotNull(spec, "Missing MapReduceSpecification for %s", program.getName());
}
use of co.cask.cdap.proto.ProgramType in project cdap by caskdata.
the class ApplicationClient method listAllPrograms.
/**
* Lists all programs.
*
* @return list of {@link ProgramRecord}s
* @throws IOException if a network error occurred
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
*/
public Map<ProgramType, List<ProgramRecord>> listAllPrograms(NamespaceId namespace) throws IOException, UnauthenticatedException, UnauthorizedException {
ImmutableMap.Builder<ProgramType, List<ProgramRecord>> allPrograms = ImmutableMap.builder();
for (ProgramType programType : ProgramType.values()) {
if (programType.isListable()) {
List<ProgramRecord> programRecords = Lists.newArrayList();
programRecords.addAll(listAllPrograms(namespace, programType));
allPrograms.put(programType, programRecords);
}
}
return allPrograms.build();
}
use of co.cask.cdap.proto.ProgramType in project cdap by caskdata.
the class ServiceProgramRunner method run.
@Override
public ProgramController run(Program program, ProgramOptions options) {
int instanceId = Integer.parseInt(options.getArguments().getOption(ProgramOptionConstants.INSTANCE_ID, "-1"));
Preconditions.checkArgument(instanceId >= 0, "Missing instance Id");
int instanceCount = Integer.parseInt(options.getArguments().getOption(ProgramOptionConstants.INSTANCES, "0"));
Preconditions.checkArgument(instanceCount > 0, "Invalid or missing instance count");
RunId runId = ProgramRunners.getRunId(options);
ApplicationSpecification appSpec = program.getApplicationSpecification();
Preconditions.checkNotNull(appSpec, "Missing application specification.");
ProgramType programType = program.getType();
Preconditions.checkNotNull(programType, "Missing processor type.");
Preconditions.checkArgument(programType == ProgramType.SERVICE, "Only Service process type is supported.");
ServiceSpecification spec = appSpec.getServices().get(program.getName());
String host = options.getArguments().getOption(ProgramOptionConstants.HOST);
Preconditions.checkArgument(host != null, "No hostname is provided");
// Setup dataset framework context, if required
if (datasetFramework instanceof ProgramContextAware) {
ProgramId programId = program.getId();
((ProgramContextAware) datasetFramework).setContext(new BasicProgramContext(programId.run(runId)));
}
final PluginInstantiator pluginInstantiator = createPluginInstantiator(options, program.getClassLoader());
try {
RetryStrategy retryStrategy = SystemArguments.getRetryStrategy(options.getUserArguments().asMap(), program.getType(), cConf);
ArtifactManager artifactManager = artifactManagerFactory.create(program.getId().getNamespaceId(), retryStrategy);
ServiceHttpServer component = new ServiceHttpServer(host, program, options, cConf, spec, instanceId, instanceCount, serviceAnnouncer, metricsCollectionService, datasetFramework, txClient, discoveryServiceClient, pluginInstantiator, secureStore, secureStoreManager, messagingService, artifactManager);
// Add a service listener to make sure the plugin instantiator is closed when the http server is finished.
component.addListener(createRuntimeServiceListener(Collections.singleton((Closeable) pluginInstantiator)), Threads.SAME_THREAD_EXECUTOR);
ProgramController controller = new ServiceProgramControllerAdapter(component, program.getId().run(runId), spec.getName() + "-" + instanceId);
component.start();
return controller;
} catch (Throwable t) {
Closeables.closeQuietly(pluginInstantiator);
throw t;
}
}
use of co.cask.cdap.proto.ProgramType in project cdap by caskdata.
the class InMemoryProgramRuntimeService method stopAllPrograms.
private void stopAllPrograms() {
LOG.info("Stopping all running programs.");
List<ListenableFuture<ProgramController>> futures = Lists.newLinkedList();
for (ProgramType type : ProgramType.values()) {
for (Map.Entry<RunId, RuntimeInfo> entry : list(type).entrySet()) {
RuntimeInfo runtimeInfo = entry.getValue();
if (isRunning(runtimeInfo.getProgramId())) {
futures.add(runtimeInfo.getController().stop());
}
}
}
// unchecked because we cannot do much if it fails. We will still shutdown the standalone CDAP instance.
try {
Futures.successfulAsList(futures).get(60, TimeUnit.SECONDS);
LOG.info("All programs have been stopped.");
} catch (ExecutionException e) {
// note this should not happen because we wait on a successfulAsList
LOG.warn("Got exception while waiting for all programs to stop", e.getCause());
} catch (InterruptedException e) {
LOG.warn("Got interrupted exception while waiting for all programs to stop", e);
Thread.currentThread().interrupt();
} catch (TimeoutException e) {
// can't do much more than log it. We still want to exit.
LOG.warn("Timeout while waiting for all programs to stop.");
}
}
Aggregations