Search in sources :

Example 21 with ProgramType

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);
    }
}
Also used : Discoverable(org.apache.twill.discovery.Discoverable) ResolvingDiscoverable(co.cask.cdap.common.discovery.ResolvingDiscoverable) CommonNettyHttpServiceBuilder(co.cask.cdap.common.http.CommonNettyHttpServiceBuilder) InetSocketAddress(java.net.InetSocketAddress) Cancellable(org.apache.twill.common.Cancellable) NettyHttpService(co.cask.http.NettyHttpService) ProgramType(co.cask.cdap.proto.ProgramType) RunId(org.apache.twill.api.RunId)

Example 22 with ProgramType

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);
    }
}
Also used : ApplicationSpecification(co.cask.cdap.api.app.ApplicationSpecification) ProgramController(co.cask.cdap.app.runtime.ProgramController) Closeable(java.io.Closeable) ArrayList(java.util.ArrayList) ProgramId(co.cask.cdap.proto.id.ProgramId) BasicProgramContext(co.cask.cdap.internal.app.runtime.BasicProgramContext) WorkflowSpecification(co.cask.cdap.api.workflow.WorkflowSpecification) PluginInstantiator(co.cask.cdap.internal.app.runtime.plugin.PluginInstantiator) ProgramType(co.cask.cdap.proto.ProgramType) RunId(org.apache.twill.api.RunId) ProgramContextAware(co.cask.cdap.data.ProgramContextAware)

Example 23 with ProgramType

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;
}
Also used : ProgramSpecification(co.cask.cdap.api.ProgramSpecification) ProgramType(co.cask.cdap.proto.ProgramType)

Example 24 with ProgramType

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;
}
Also used : SimpleRuntimeInfo(co.cask.cdap.internal.app.runtime.service.SimpleRuntimeInfo) ArrayList(java.util.ArrayList) ProgramType(co.cask.cdap.proto.ProgramType) RunId(org.apache.twill.api.RunId) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 25 with ProgramType

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);
}
Also used : Table(co.cask.cdap.cli.util.table.Table) ProgramRecord(co.cask.cdap.proto.ProgramRecord) RowMaker(co.cask.cdap.cli.util.RowMaker) List(java.util.List) ProgramType(co.cask.cdap.proto.ProgramType)

Aggregations

ProgramType (co.cask.cdap.proto.ProgramType)71 ProgramId (co.cask.cdap.proto.id.ProgramId)33 ApplicationId (co.cask.cdap.proto.id.ApplicationId)22 ApplicationSpecification (co.cask.cdap.api.app.ApplicationSpecification)21 Path (javax.ws.rs.Path)16 BadRequestException (co.cask.cdap.common.BadRequestException)13 GET (javax.ws.rs.GET)13 NamespaceNotFoundException (co.cask.cdap.common.NamespaceNotFoundException)12 NotFoundException (co.cask.cdap.common.NotFoundException)12 RunId (org.apache.twill.api.RunId)11 ProgramController (co.cask.cdap.app.runtime.ProgramController)8 ArrayList (java.util.ArrayList)8 ProgramContextAware (co.cask.cdap.data.ProgramContextAware)6 BasicProgramContext (co.cask.cdap.internal.app.runtime.BasicProgramContext)6 FlowSpecification (co.cask.cdap.api.flow.FlowSpecification)5 UnauthorizedException (co.cask.cdap.security.spi.authorization.UnauthorizedException)5 JsonSyntaxException (com.google.gson.JsonSyntaxException)5 MetricsCollectionService (co.cask.cdap.api.metrics.MetricsCollectionService)4 WorkflowSpecification (co.cask.cdap.api.workflow.WorkflowSpecification)4 PluginInstantiator (co.cask.cdap.internal.app.runtime.plugin.PluginInstantiator)4