use of co.cask.cdap.app.runtime.ProgramController 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.app.runtime.ProgramController in project cdap by caskdata.
the class WorkflowTest method testOneActionWorkflow.
@Test(timeout = 120 * 1000L)
public void testOneActionWorkflow() throws Exception {
final ApplicationWithPrograms app = AppFabricTestHelper.deployApplicationWithManager(OneActionWorkflowApp.class, TEMP_FOLDER_SUPPLIER);
final Injector injector = AppFabricTestHelper.getInjector();
final ProgramDescriptor programDescriptor = Iterators.filter(app.getPrograms().iterator(), input -> input.getProgramId().getType() == ProgramType.WORKFLOW).next();
final SettableFuture<String> completion = SettableFuture.create();
final ProgramController controller = AppFabricTestHelper.submit(app, programDescriptor.getSpecification().getClassName(), new BasicArguments(), TEMP_FOLDER_SUPPLIER);
controller.addListener(new AbstractListener() {
@Override
public void init(ProgramController.State currentState, @Nullable Throwable cause) {
LOG.info("Initializing");
long nowSecs = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis());
setStartAndRunning(injector.getInstance(Store.class), controller.getProgramRunId().getParent(), controller.getProgramRunId().getRun(), nowSecs);
}
@Override
public void completed() {
LOG.info("Completed");
completion.set("Completed");
}
@Override
public void error(Throwable cause) {
LOG.info("Error", cause);
completion.setException(cause);
}
}, Threads.SAME_THREAD_EXECUTOR);
String run = completion.get();
Assert.assertEquals("Completed", run);
}
use of co.cask.cdap.app.runtime.ProgramController in project cdap by caskdata.
the class WorkflowHttpHandler method suspendWorkflowRun.
@POST
@Path("/apps/{app-id}/workflows/{workflow-name}/runs/{run-id}/suspend")
public void suspendWorkflowRun(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("app-id") String appId, @PathParam("workflow-name") String workflowName, @PathParam("run-id") String runId) throws Exception {
ProgramId id = new ProgramId(namespaceId, appId, ProgramType.WORKFLOW, workflowName);
ProgramRuntimeService.RuntimeInfo runtimeInfo = runtimeService.list(id).get(RunIds.fromString(runId));
if (runtimeInfo == null) {
throw new NotFoundException(id.run(runId));
}
ProgramController controller = runtimeInfo.getController();
if (controller.getState() == ProgramController.State.SUSPENDED) {
throw new ConflictException("Program run already suspended");
}
controller.suspend().get();
responder.sendString(HttpResponseStatus.OK, "Program run suspended.");
}
use of co.cask.cdap.app.runtime.ProgramController in project cdap by caskdata.
the class AppLifecycleHttpHandler method stopProgramIfRunning.
private void stopProgramIfRunning(ProgramId programId) throws InterruptedException, ExecutionException {
ProgramRuntimeService.RuntimeInfo programRunInfo = findRuntimeInfo(programId, runtimeService);
if (programRunInfo != null) {
ProgramController controller = programRunInfo.getController();
controller.stop().get();
}
}
use of co.cask.cdap.app.runtime.ProgramController in project cdap by caskdata.
the class WorkflowHttpHandler method resumeWorkflowRun.
@POST
@Path("/apps/{app-id}/workflows/{workflow-name}/runs/{run-id}/resume")
public void resumeWorkflowRun(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("app-id") String appId, @PathParam("workflow-name") String workflowName, @PathParam("run-id") String runId) throws Exception {
ProgramId id = new ProgramId(namespaceId, appId, ProgramType.WORKFLOW, workflowName);
ProgramRuntimeService.RuntimeInfo runtimeInfo = runtimeService.list(id).get(RunIds.fromString(runId));
if (runtimeInfo == null) {
throw new NotFoundException(id.run(runId));
}
ProgramController controller = runtimeInfo.getController();
if (controller.getState() == ProgramController.State.ALIVE) {
throw new ConflictException("Program is already running");
}
controller.resume().get();
responder.sendString(HttpResponseStatus.OK, "Program run resumed.");
}
Aggregations