use of co.cask.cdap.app.program.ProgramDescriptor in project cdap by caskdata.
the class DistributedProgramRuntimeService method createRuntimeInfo.
@Nullable
private RuntimeInfo createRuntimeInfo(ProgramId programId, TwillController controller, RunId runId) {
try {
ProgramDescriptor programDescriptor = store.loadProgram(programId);
ProgramController programController = createController(programDescriptor, controller, runId);
return programController == null ? null : new SimpleRuntimeInfo(programController, programId, controller.getRunId());
} catch (Exception e) {
return null;
}
}
use of co.cask.cdap.app.program.ProgramDescriptor in project cdap by caskdata.
the class MapReduceTaskContextProvider method createProgram.
/**
* Creates a {@link Program} instance based on the information from the {@link MapReduceContextConfig}, using
* the given program ClassLoader.
*/
private Program createProgram(MapReduceContextConfig contextConfig, ClassLoader programClassLoader) {
Location programLocation;
LocationFactory locationFactory = new LocalLocationFactory();
if (isLocal(contextConfig.getHConf())) {
// Just create a local location factory. It's for temp usage only as the program location is always absolute.
programLocation = locationFactory.create(contextConfig.getProgramJarURI());
} else {
// In distributed mode, the program jar is localized to the container
programLocation = locationFactory.create(new File(contextConfig.getProgramJarName()).getAbsoluteFile().toURI());
}
return new DefaultProgram(new ProgramDescriptor(contextConfig.getProgramId(), contextConfig.getApplicationSpecification()), programLocation, programClassLoader);
}
use of co.cask.cdap.app.program.ProgramDescriptor in project cdap by caskdata.
the class ProgramLifecycleService method startInternal.
/**
* Start a Program.
*
* Note that this method can only be called through internal service, it does not have auth check for starting the
* program.
*
* @param programId the {@link ProgramId program} to start
* @param systemArgs system arguments
* @param userArgs user arguments
* @param debug enable debug mode
* @return {@link ProgramRuntimeService.RuntimeInfo}
* @throws IOException if there is an error starting the program
* @throws ProgramNotFoundException if program is not found
* @throws UnauthorizedException if the logged in user is not authorized to start the program. To start a program,
* a user requires {@link Action#EXECUTE} on the program
* @throws Exception if there were other exceptions checking if the current user is authorized to start the program
*/
public ProgramRuntimeService.RuntimeInfo startInternal(final ProgramId programId, final Map<String, String> systemArgs, final Map<String, String> userArgs, boolean debug) throws Exception {
LOG.info("{} tries to start {} Program {}", authenticationContext.getPrincipal().getName(), programId.getType(), programId.getProgram());
ProgramDescriptor programDescriptor = store.loadProgram(programId);
BasicArguments systemArguments = new BasicArguments(systemArgs);
BasicArguments userArguments = new BasicArguments(userArgs);
ProgramRuntimeService.RuntimeInfo runtimeInfo = runtimeService.run(programDescriptor, new SimpleProgramOptions(programId, systemArguments, userArguments, debug));
return runtimeInfo;
}
use of co.cask.cdap.app.program.ProgramDescriptor 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.program.ProgramDescriptor in project cdap by caskdata.
the class AppFabricTestHelper method submit.
/**
* Submits a program execution.
*
* @param app the application containing the program
* @param programClassName name of the program class
* @param userArgs runtime arguments
* @param folderSupplier a Supplier of temporary folder
* @return a {@link ProgramController} for controlling the program execution.
*/
public static ProgramController submit(ApplicationWithPrograms app, String programClassName, Arguments userArgs, Supplier<File> folderSupplier) throws Exception {
ProgramRunnerFactory runnerFactory = injector.getInstance(ProgramRunnerFactory.class);
ProgramRunner runner = null;
Program program = null;
for (ProgramDescriptor programDescriptor : app.getPrograms()) {
if (programDescriptor.getSpecification().getClassName().equals(programClassName)) {
runner = runnerFactory.create(programDescriptor.getProgramId().getType());
program = createProgram(programDescriptor, app.getArtifactLocation(), runner, folderSupplier);
break;
}
}
Assert.assertNotNull(program);
BasicArguments systemArgs = new BasicArguments(ImmutableMap.of(ProgramOptionConstants.RUN_ID, RunIds.generate().getId(), ProgramOptionConstants.HOST, InetAddress.getLoopbackAddress().getCanonicalHostName(), ProgramOptionConstants.ARTIFACT_ID, Joiner.on(":").join(app.getArtifactId().toIdParts())));
return runner.run(program, new SimpleProgramOptions(program.getId(), systemArgs, userArgs));
}
Aggregations