Search in sources :

Example 11 with FlowSpecification

use of co.cask.cdap.api.flow.FlowSpecification in project cdap by caskdata.

the class DistributedFlowProgramRunner method setupLaunchConfig.

@Override
protected void setupLaunchConfig(LaunchConfig launchConfig, Program program, ProgramOptions options, CConfiguration cConf, Configuration hConf, File tempDir) {
    // Add runnables
    Map<String, String> args = options.getUserArguments().asMap();
    FlowSpecification flowSpec = getFlowSpecification(program);
    for (Map.Entry<String, FlowletDefinition> entry : flowSpec.getFlowlets().entrySet()) {
        FlowletDefinition flowletDefinition = entry.getValue();
        FlowletSpecification flowletSpec = flowletDefinition.getFlowletSpec();
        String flowletName = entry.getKey();
        Map<String, String> flowletArgs = RuntimeArguments.extractScope(FlowUtils.FLOWLET_SCOPE, flowletName, args);
        launchConfig.addRunnable(flowletName, new FlowletTwillRunnable(flowletName), flowletDefinition.getInstances(), flowletArgs, flowletSpec.getResources());
    }
}
Also used : FlowletDefinition(co.cask.cdap.api.flow.FlowletDefinition) FlowSpecification(co.cask.cdap.api.flow.FlowSpecification) FlowletSpecification(co.cask.cdap.api.flow.flowlet.FlowletSpecification) Map(java.util.Map)

Example 12 with FlowSpecification

use of co.cask.cdap.api.flow.FlowSpecification in project cdap by caskdata.

the class ApplicationLifecycleService method deleteApp.

// deletes without performs checks that no programs are running
/**
 * Delete the specified application without performing checks that its programs are stopped.
 *
 * @param appId the id of the application to delete
 * @param spec the spec of the application to delete
 * @throws Exception
 */
private void deleteApp(final ApplicationId appId, ApplicationSpecification spec) throws Exception {
    // Delete the schedules
    scheduler.deleteSchedules(appId);
    for (WorkflowSpecification workflowSpec : spec.getWorkflows().values()) {
        scheduler.modifySchedulesTriggeredByDeletedProgram(appId.workflow(workflowSpec.getName()));
    }
    deleteMetrics(appId);
    // Delete all preferences of the application and of all its programs
    deletePreferences(appId);
    // Delete all streams and queues state of each flow
    for (final FlowSpecification flowSpecification : spec.getFlows().values()) {
        FlowUtils.clearDeletedFlow(impersonator, queueAdmin, streamConsumerFactory, appId.flow(flowSpecification.getName()), flowSpecification);
    }
    ApplicationSpecification appSpec = store.getApplication(appId);
    deleteAppMetadata(appId, appSpec);
    deleteRouteConfig(appId, appSpec);
    store.deleteWorkflowStats(appId);
    store.removeApplication(appId);
    try {
        // delete the owner as it has already been determined that this is the only version of the app
        ownerAdmin.delete(appId);
    } catch (Exception e) {
        LOG.warn("Failed to delete app owner principal for application {} if one existed while deleting the " + "application.", appId);
    }
    try {
        usageRegistry.unregister(appId);
    } catch (Exception e) {
        LOG.warn("Failed to unregister usage of app: {}", appId, e);
    }
}
Also used : ApplicationSpecification(co.cask.cdap.api.app.ApplicationSpecification) FlowSpecification(co.cask.cdap.api.flow.FlowSpecification) WorkflowSpecification(co.cask.cdap.api.workflow.WorkflowSpecification) CannotBeDeletedException(co.cask.cdap.common.CannotBeDeletedException) ApplicationNotFoundException(co.cask.cdap.common.ApplicationNotFoundException) ArtifactNotFoundException(co.cask.cdap.common.ArtifactNotFoundException) ArtifactAlreadyExistsException(co.cask.cdap.common.ArtifactAlreadyExistsException) IOException(java.io.IOException) InvalidArtifactException(co.cask.cdap.common.InvalidArtifactException) ExecutionException(java.util.concurrent.ExecutionException) NotFoundException(co.cask.cdap.common.NotFoundException)

Example 13 with FlowSpecification

use of co.cask.cdap.api.flow.FlowSpecification in project cdap by caskdata.

the class DefaultStore method setFlowletInstances.

@Override
public FlowSpecification setFlowletInstances(ProgramId id, String flowletId, int count) {
    Preconditions.checkArgument(count > 0, "Cannot change number of flowlet instances to %s", count);
    LOG.trace("Setting flowlet instances: namespace: {}, application: {}, flow: {}, flowlet: {}, " + "new instances count: {}", id.getNamespace(), id.getApplication(), id.getProgram(), flowletId, count);
    FlowSpecification flowSpec = Transactionals.execute(transactional, context -> {
        AppMetadataStore metaStore = getAppMetadataStore(context);
        ApplicationSpecification appSpec = getAppSpecOrFail(metaStore, id);
        ApplicationSpecification newAppSpec = updateFlowletInstancesInAppSpec(appSpec, id, flowletId, count);
        metaStore.updateAppSpec(id.getNamespace(), id.getApplication(), id.getVersion(), newAppSpec);
        return appSpec.getFlows().get(id.getProgram());
    });
    LOG.trace("Set flowlet instances: namespace: {}, application: {}, flow: {}, flowlet: {}, instances now: {}", id.getNamespaceId(), id.getApplication(), id.getProgram(), flowletId, count);
    return flowSpec;
}
Also used : ApplicationSpecification(co.cask.cdap.api.app.ApplicationSpecification) ForwardingApplicationSpecification(co.cask.cdap.internal.app.ForwardingApplicationSpecification) FlowSpecification(co.cask.cdap.api.flow.FlowSpecification) ForwardingFlowSpecification(co.cask.cdap.internal.app.ForwardingFlowSpecification)

Example 14 with FlowSpecification

use of co.cask.cdap.api.flow.FlowSpecification in project cdap by caskdata.

the class DefaultAppConfigurer method addFlow.

@Override
public void addFlow(Flow flow) {
    Preconditions.checkArgument(flow != null, "Flow cannot be null.");
    DefaultFlowConfigurer configurer = new DefaultFlowConfigurer(flow);
    flow.configure(configurer);
    FlowSpecification spec = configurer.createSpecification();
    addDatasets(configurer);
    flows.put(spec.getName(), spec);
}
Also used : DefaultFlowConfigurer(co.cask.cdap.internal.app.runtime.flow.DefaultFlowConfigurer) FlowSpecification(co.cask.cdap.api.flow.FlowSpecification)

Example 15 with FlowSpecification

use of co.cask.cdap.api.flow.FlowSpecification in project cdap by caskdata.

the class ProgramLifecycleHttpHandler method getProgramInstances.

/**
 * Get requested and provisioned instances for a program type.
 * The program type passed here should be one that can have instances (flows, services, ...)
 * Requires caller to do this validation.
 */
private BatchRunnableInstances getProgramInstances(BatchRunnable runnable, ApplicationSpecification spec, ProgramId programId) {
    int requested;
    String programName = programId.getProgram();
    String runnableId = programName;
    ProgramType programType = programId.getType();
    if (programType == ProgramType.WORKER) {
        if (!spec.getWorkers().containsKey(programName)) {
            return new BatchRunnableInstances(runnable, HttpResponseStatus.NOT_FOUND.code(), "Worker: " + programName + " not found");
        }
        requested = spec.getWorkers().get(programName).getInstances();
    } else if (programType == ProgramType.SERVICE) {
        if (!spec.getServices().containsKey(programName)) {
            return new BatchRunnableInstances(runnable, HttpResponseStatus.NOT_FOUND.code(), "Service: " + programName + " not found");
        }
        requested = spec.getServices().get(programName).getInstances();
    } else if (programType == ProgramType.FLOW) {
        // flows must have runnable id
        runnableId = runnable.getRunnableId();
        if (runnableId == null) {
            return new BatchRunnableInstances(runnable, HttpResponseStatus.BAD_REQUEST.code(), "Must provide the flowlet id as the runnableId for flows");
        }
        FlowSpecification flowSpec = spec.getFlows().get(programName);
        if (flowSpec == null) {
            return new BatchRunnableInstances(runnable, HttpResponseStatus.NOT_FOUND.code(), "Flow: " + programName + " not found");
        }
        FlowletDefinition flowletDefinition = flowSpec.getFlowlets().get(runnableId);
        if (flowletDefinition == null) {
            return new BatchRunnableInstances(runnable, HttpResponseStatus.NOT_FOUND.code(), "Flowlet: " + runnableId + " not found");
        }
        requested = flowletDefinition.getInstances();
    } else {
        return new BatchRunnableInstances(runnable, HttpResponseStatus.BAD_REQUEST.code(), "Instances not supported for program type + " + programType);
    }
    int provisioned = getInstanceCount(programId, runnableId);
    // use the pretty name of program types to be consistent
    return new BatchRunnableInstances(runnable, HttpResponseStatus.OK.code(), provisioned, requested);
}
Also used : FlowletDefinition(co.cask.cdap.api.flow.FlowletDefinition) FlowSpecification(co.cask.cdap.api.flow.FlowSpecification) BatchRunnableInstances(co.cask.cdap.proto.BatchRunnableInstances) ProgramType(co.cask.cdap.proto.ProgramType) Constraint(co.cask.cdap.internal.schedule.constraint.Constraint)

Aggregations

FlowSpecification (co.cask.cdap.api.flow.FlowSpecification)25 ApplicationSpecification (co.cask.cdap.api.app.ApplicationSpecification)15 FlowletDefinition (co.cask.cdap.api.flow.FlowletDefinition)7 ApplicationId (co.cask.cdap.proto.id.ApplicationId)7 ProgramType (co.cask.cdap.proto.ProgramType)5 Test (org.junit.Test)4 VerifyResult (co.cask.cdap.app.verification.VerifyResult)3 ApplicationSpecificationAdapter (co.cask.cdap.internal.app.ApplicationSpecificationAdapter)3 ForwardingFlowSpecification (co.cask.cdap.internal.app.ForwardingFlowSpecification)3 ProgramId (co.cask.cdap.proto.id.ProgramId)3 WebCrawlApp (co.cask.cdap.WebCrawlApp)2 MapReduceSpecification (co.cask.cdap.api.mapreduce.MapReduceSpecification)2 ServiceSpecification (co.cask.cdap.api.service.ServiceSpecification)2 SparkSpecification (co.cask.cdap.api.spark.SparkSpecification)2 WorkflowSpecification (co.cask.cdap.api.workflow.WorkflowSpecification)2 ProgramController (co.cask.cdap.app.runtime.ProgramController)2 NotFoundException (co.cask.cdap.common.NotFoundException)2 QueueName (co.cask.cdap.common.queue.QueueName)2 ForwardingApplicationSpecification (co.cask.cdap.internal.app.ForwardingApplicationSpecification)2 SimpleQueueSpecificationGenerator (co.cask.cdap.internal.app.queue.SimpleQueueSpecificationGenerator)2