Search in sources :

Example 6 with ProgramDescriptor

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;
    }
}
Also used : ProgramController(co.cask.cdap.app.runtime.ProgramController) ProgramDescriptor(co.cask.cdap.app.program.ProgramDescriptor) IOException(java.io.IOException) SimpleRuntimeInfo(co.cask.cdap.internal.app.runtime.service.SimpleRuntimeInfo) Nullable(javax.annotation.Nullable)

Example 7 with ProgramDescriptor

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);
}
Also used : DefaultProgram(co.cask.cdap.app.program.DefaultProgram) ProgramDescriptor(co.cask.cdap.app.program.ProgramDescriptor) LocalLocationFactory(org.apache.twill.filesystem.LocalLocationFactory) File(java.io.File) Location(org.apache.twill.filesystem.Location) LocalLocationFactory(org.apache.twill.filesystem.LocalLocationFactory) LocationFactory(org.apache.twill.filesystem.LocationFactory)

Example 8 with ProgramDescriptor

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;
}
Also used : RuntimeInfo(co.cask.cdap.app.runtime.ProgramRuntimeService.RuntimeInfo) ProgramDescriptor(co.cask.cdap.app.program.ProgramDescriptor) BasicArguments(co.cask.cdap.internal.app.runtime.BasicArguments) SimpleProgramOptions(co.cask.cdap.internal.app.runtime.SimpleProgramOptions) ProgramRuntimeService(co.cask.cdap.app.runtime.ProgramRuntimeService)

Example 9 with ProgramDescriptor

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);
}
Also used : ProgramDescriptor(co.cask.cdap.app.program.ProgramDescriptor) ProgramController(co.cask.cdap.app.runtime.ProgramController) Supplier(com.google.common.base.Supplier) LoggerFactory(org.slf4j.LoggerFactory) SettableFuture(com.google.common.util.concurrent.SettableFuture) Iterators(com.google.common.collect.Iterators) ProgramType(co.cask.cdap.proto.ProgramType) WorkflowApp(co.cask.cdap.WorkflowApp) Store(co.cask.cdap.app.store.Store) ProgramId(co.cask.cdap.proto.id.ProgramId) MissingMapReduceWorkflowApp(co.cask.cdap.MissingMapReduceWorkflowApp) ClassRule(org.junit.ClassRule) Nullable(javax.annotation.Nullable) Threads(org.apache.twill.common.Threads) NonUniqueProgramsInWorkflowWithForkApp(co.cask.cdap.NonUniqueProgramsInWorkflowWithForkApp) AbstractListener(co.cask.cdap.internal.app.runtime.AbstractListener) Logger(org.slf4j.Logger) OneActionWorkflowApp(co.cask.cdap.OneActionWorkflowApp) ImmutableMap(com.google.common.collect.ImmutableMap) BufferedWriter(java.io.BufferedWriter) FileWriter(java.io.FileWriter) Throwables(com.google.common.base.Throwables) Test(org.junit.Test) IOException(java.io.IOException) Category(org.junit.experimental.categories.Category) File(java.io.File) NonUniqueProgramsInWorkflowApp(co.cask.cdap.NonUniqueProgramsInWorkflowApp) ApplicationWithPrograms(co.cask.cdap.internal.app.deploy.pipeline.ApplicationWithPrograms) Injector(com.google.inject.Injector) TimeUnit(java.util.concurrent.TimeUnit) BasicArguments(co.cask.cdap.internal.app.runtime.BasicArguments) ScheduleAppWithMissingWorkflow(co.cask.cdap.ScheduleAppWithMissingWorkflow) XSlowTests(co.cask.cdap.test.XSlowTests) AppWithAnonymousWorkflow(co.cask.cdap.AppWithAnonymousWorkflow) AppFabricTestHelper(co.cask.cdap.internal.AppFabricTestHelper) MissingSparkWorkflowApp(co.cask.cdap.MissingSparkWorkflowApp) Assert(org.junit.Assert) WorkflowSchedulesWithSameNameApp(co.cask.cdap.WorkflowSchedulesWithSameNameApp) TemporaryFolder(org.junit.rules.TemporaryFolder) ProgramController(co.cask.cdap.app.runtime.ProgramController) ApplicationWithPrograms(co.cask.cdap.internal.app.deploy.pipeline.ApplicationWithPrograms) Injector(com.google.inject.Injector) AbstractListener(co.cask.cdap.internal.app.runtime.AbstractListener) ProgramDescriptor(co.cask.cdap.app.program.ProgramDescriptor) BasicArguments(co.cask.cdap.internal.app.runtime.BasicArguments) Test(org.junit.Test)

Example 10 with ProgramDescriptor

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));
}
Also used : Program(co.cask.cdap.app.program.Program) ProgramDescriptor(co.cask.cdap.app.program.ProgramDescriptor) BasicArguments(co.cask.cdap.internal.app.runtime.BasicArguments) SimpleProgramOptions(co.cask.cdap.internal.app.runtime.SimpleProgramOptions) ProgramRunner(co.cask.cdap.app.runtime.ProgramRunner) ProgramRunnerFactory(co.cask.cdap.app.runtime.ProgramRunnerFactory)

Aggregations

ProgramDescriptor (co.cask.cdap.app.program.ProgramDescriptor)20 Test (org.junit.Test)11 BasicArguments (co.cask.cdap.internal.app.runtime.BasicArguments)10 ProgramController (co.cask.cdap.app.runtime.ProgramController)9 File (java.io.File)9 IOException (java.io.IOException)8 ApplicationWithPrograms (co.cask.cdap.internal.app.deploy.pipeline.ApplicationWithPrograms)7 ProgramId (co.cask.cdap.proto.id.ProgramId)7 ApplicationSpecification (co.cask.cdap.api.app.ApplicationSpecification)5 SimpleProgramOptions (co.cask.cdap.internal.app.runtime.SimpleProgramOptions)5 Location (org.apache.twill.filesystem.Location)4 CConfiguration (co.cask.cdap.common.conf.CConfiguration)3 RandomEndpointStrategy (co.cask.cdap.common.discovery.RandomEndpointStrategy)3 Discoverable (org.apache.twill.discovery.Discoverable)3 DiscoveryServiceClient (org.apache.twill.discovery.DiscoveryServiceClient)3 AppWithAnonymousWorkflow (co.cask.cdap.AppWithAnonymousWorkflow)2 MissingMapReduceWorkflowApp (co.cask.cdap.MissingMapReduceWorkflowApp)2 MissingSparkWorkflowApp (co.cask.cdap.MissingSparkWorkflowApp)2 NonUniqueProgramsInWorkflowApp (co.cask.cdap.NonUniqueProgramsInWorkflowApp)2 NonUniqueProgramsInWorkflowWithForkApp (co.cask.cdap.NonUniqueProgramsInWorkflowWithForkApp)2