Search in sources :

Example 11 with WorkflowSpecification

use of co.cask.cdap.api.workflow.WorkflowSpecification in project cdap by caskdata.

the class WorkflowHttpHandler method getWorkflowSpecForValidRun.

/**
 * Get the {@link WorkflowSpecification} if valid application id, workflow id, and runid are provided.
 * @param namespaceId the namespace id
 * @param applicationId the application id
 * @param workflowId the workflow id
 * @param runId the runid of the workflow
 * @return the specifications for the Workflow
 * @throws NotFoundException is thrown when the application, workflow, or runid is not found
 */
private WorkflowSpecification getWorkflowSpecForValidRun(String namespaceId, String applicationId, String workflowId, String runId) throws NotFoundException {
    ApplicationId appId = new ApplicationId(namespaceId, applicationId);
    ApplicationSpecification appSpec = store.getApplication(appId);
    if (appSpec == null) {
        throw new ApplicationNotFoundException(appId);
    }
    WorkflowSpecification workflowSpec = appSpec.getWorkflows().get(workflowId);
    ProgramId programId = new ProgramId(namespaceId, applicationId, ProgramType.WORKFLOW, workflowId);
    if (workflowSpec == null) {
        throw new ProgramNotFoundException(programId);
    }
    if (store.getRun(programId.run(runId)) == null) {
        throw new NotFoundException(new ProgramRunId(programId.getNamespace(), programId.getApplication(), programId.getType(), programId.getProgram(), runId));
    }
    return workflowSpec;
}
Also used : ApplicationSpecification(co.cask.cdap.api.app.ApplicationSpecification) ApplicationNotFoundException(co.cask.cdap.common.ApplicationNotFoundException) WorkflowSpecification(co.cask.cdap.api.workflow.WorkflowSpecification) ProgramNotFoundException(co.cask.cdap.common.ProgramNotFoundException) ApplicationNotFoundException(co.cask.cdap.common.ApplicationNotFoundException) InstanceNotFoundException(co.cask.cdap.api.dataset.InstanceNotFoundException) NotFoundException(co.cask.cdap.common.NotFoundException) ProgramRunId(co.cask.cdap.proto.id.ProgramRunId) ApplicationId(co.cask.cdap.proto.id.ApplicationId) ProgramId(co.cask.cdap.proto.id.ProgramId) ProgramNotFoundException(co.cask.cdap.common.ProgramNotFoundException)

Example 12 with WorkflowSpecification

use of co.cask.cdap.api.workflow.WorkflowSpecification in project cdap by caskdata.

the class WorkflowHttpHandler method getWorkflowNodeStates.

@GET
@Path("/apps/{app-id}/workflows/{workflow-id}/runs/{run-id}/nodes/state")
public void getWorkflowNodeStates(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("app-id") String applicationId, @PathParam("workflow-id") String workflowId, @PathParam("run-id") String runId) throws NotFoundException {
    ApplicationId appId = Ids.namespace(namespaceId).app(applicationId);
    ApplicationSpecification appSpec = store.getApplication(appId);
    if (appSpec == null) {
        throw new ApplicationNotFoundException(appId);
    }
    ProgramId workflowProgramId = appId.workflow(workflowId);
    WorkflowSpecification workflowSpec = appSpec.getWorkflows().get(workflowProgramId.getProgram());
    if (workflowSpec == null) {
        throw new ProgramNotFoundException(workflowProgramId);
    }
    ProgramRunId workflowRunId = workflowProgramId.run(runId);
    if (store.getRun(workflowRunId) == null) {
        throw new NotFoundException(workflowRunId);
    }
    List<WorkflowNodeStateDetail> nodeStateDetails = store.getWorkflowNodeStates(workflowRunId);
    Map<String, WorkflowNodeStateDetail> nodeStates = new HashMap<>();
    for (WorkflowNodeStateDetail nodeStateDetail : nodeStateDetails) {
        nodeStates.put(nodeStateDetail.getNodeId(), nodeStateDetail);
    }
    responder.sendJson(HttpResponseStatus.OK, GSON.toJson(nodeStates, STRING_TO_NODESTATEDETAIL_MAP_TYPE));
}
Also used : ApplicationSpecification(co.cask.cdap.api.app.ApplicationSpecification) HashMap(java.util.HashMap) ProgramNotFoundException(co.cask.cdap.common.ProgramNotFoundException) ApplicationNotFoundException(co.cask.cdap.common.ApplicationNotFoundException) InstanceNotFoundException(co.cask.cdap.api.dataset.InstanceNotFoundException) NotFoundException(co.cask.cdap.common.NotFoundException) ProgramId(co.cask.cdap.proto.id.ProgramId) WorkflowNodeStateDetail(co.cask.cdap.proto.WorkflowNodeStateDetail) ApplicationNotFoundException(co.cask.cdap.common.ApplicationNotFoundException) WorkflowSpecification(co.cask.cdap.api.workflow.WorkflowSpecification) ProgramRunId(co.cask.cdap.proto.id.ProgramRunId) ApplicationId(co.cask.cdap.proto.id.ApplicationId) ProgramNotFoundException(co.cask.cdap.common.ProgramNotFoundException) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 13 with WorkflowSpecification

use of co.cask.cdap.api.workflow.WorkflowSpecification in project cdap by caskdata.

the class ApplicationSpecificationCodec method deserialize.

@Override
public ApplicationSpecification deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    JsonObject jsonObj = json.getAsJsonObject();
    String name = jsonObj.get("name").getAsString();
    String appVersion = ApplicationId.DEFAULT_VERSION;
    if (jsonObj.has("appVersion")) {
        appVersion = jsonObj.get("appVersion").getAsString();
    }
    String description = jsonObj.get("description").getAsString();
    String configuration = null;
    if (jsonObj.has("configuration")) {
        configuration = jsonObj.get("configuration").getAsString();
    }
    ArtifactId artifactId = context.deserialize(jsonObj.get("artifactId"), ArtifactId.class);
    Map<String, StreamSpecification> streams = deserializeMap(jsonObj.get("streams"), context, StreamSpecification.class);
    Map<String, String> datasetModules = deserializeMap(jsonObj.get("datasetModules"), context, String.class);
    Map<String, DatasetCreationSpec> datasetInstances = deserializeMap(jsonObj.get("datasetInstances"), context, DatasetCreationSpec.class);
    Map<String, FlowSpecification> flows = deserializeMap(jsonObj.get("flows"), context, FlowSpecification.class);
    Map<String, MapReduceSpecification> mapReduces = deserializeMap(jsonObj.get("mapReduces"), context, MapReduceSpecification.class);
    Map<String, SparkSpecification> sparks = deserializeMap(jsonObj.get("sparks"), context, SparkSpecification.class);
    Map<String, WorkflowSpecification> workflows = deserializeMap(jsonObj.get("workflows"), context, WorkflowSpecification.class);
    Map<String, ServiceSpecification> services = deserializeMap(jsonObj.get("services"), context, ServiceSpecification.class);
    Map<String, ScheduleCreationSpec> programSchedules = deserializeMap(jsonObj.get("programSchedules"), context, ScheduleCreationSpec.class);
    Map<String, WorkerSpecification> workers = deserializeMap(jsonObj.get("workers"), context, WorkerSpecification.class);
    Map<String, Plugin> plugins = deserializeMap(jsonObj.get("plugins"), context, Plugin.class);
    return new DefaultApplicationSpecification(name, appVersion, description, configuration, artifactId, streams, datasetModules, datasetInstances, flows, mapReduces, sparks, workflows, services, programSchedules, workers, plugins);
}
Also used : ServiceSpecification(co.cask.cdap.api.service.ServiceSpecification) ArtifactId(co.cask.cdap.api.artifact.ArtifactId) JsonObject(com.google.gson.JsonObject) SparkSpecification(co.cask.cdap.api.spark.SparkSpecification) FlowSpecification(co.cask.cdap.api.flow.FlowSpecification) WorkflowSpecification(co.cask.cdap.api.workflow.WorkflowSpecification) StreamSpecification(co.cask.cdap.api.data.stream.StreamSpecification) WorkerSpecification(co.cask.cdap.api.worker.WorkerSpecification) MapReduceSpecification(co.cask.cdap.api.mapreduce.MapReduceSpecification) ScheduleCreationSpec(co.cask.cdap.internal.schedule.ScheduleCreationSpec) DatasetCreationSpec(co.cask.cdap.internal.dataset.DatasetCreationSpec) Plugin(co.cask.cdap.api.plugin.Plugin)

Example 14 with WorkflowSpecification

use of co.cask.cdap.api.workflow.WorkflowSpecification in project cdap by caskdata.

the class ApplicationVerificationStage method verifyPrograms.

protected void verifyPrograms(ApplicationId appId, ApplicationSpecification specification) {
    Iterable<ProgramSpecification> programSpecs = Iterables.concat(specification.getFlows().values(), specification.getMapReduce().values(), specification.getWorkflows().values());
    VerifyResult result;
    for (ProgramSpecification programSpec : programSpecs) {
        result = getVerifier(programSpec.getClass()).verify(appId, programSpec);
        if (!result.isSuccess()) {
            throw new RuntimeException(result.getMessage());
        }
    }
    for (Map.Entry<String, WorkflowSpecification> entry : specification.getWorkflows().entrySet()) {
        verifyWorkflowSpecifications(specification, entry.getValue());
    }
    for (Map.Entry<String, ScheduleCreationSpec> entry : specification.getProgramSchedules().entrySet()) {
        String programName = entry.getValue().getProgramName();
        if (!specification.getWorkflows().containsKey(programName)) {
            throw new RuntimeException(String.format("Schedule '%s' is invalid: Workflow '%s' is not configured " + "in application '%s'", entry.getValue().getName(), programName, specification.getName()));
        }
    }
}
Also used : ProgramSpecification(co.cask.cdap.api.ProgramSpecification) WorkflowSpecification(co.cask.cdap.api.workflow.WorkflowSpecification) VerifyResult(co.cask.cdap.app.verification.VerifyResult) ScheduleCreationSpec(co.cask.cdap.internal.schedule.ScheduleCreationSpec) Map(java.util.Map)

Example 15 with WorkflowSpecification

use of co.cask.cdap.api.workflow.WorkflowSpecification in project cdap by caskdata.

the class DistributedWorkflowProgramRunner method validateOptions.

@Override
protected void validateOptions(Program program, ProgramOptions options) {
    super.validateOptions(program, options);
    // Extract and verify parameters
    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 spec = appSpec.getWorkflows().get(program.getName());
    Preconditions.checkNotNull(spec, "Missing WorkflowSpecification for %s", program.getName());
    for (WorkflowNode node : spec.getNodes()) {
        if (node.getType().equals(WorkflowNodeType.ACTION)) {
            SystemArguments.validateTransactionTimeout(options.getUserArguments().asMap(), cConf, "action", node.getNodeId());
        }
    }
}
Also used : ApplicationSpecification(co.cask.cdap.api.app.ApplicationSpecification) WorkflowSpecification(co.cask.cdap.api.workflow.WorkflowSpecification) ProgramType(co.cask.cdap.proto.ProgramType) SchedulableProgramType(co.cask.cdap.api.schedule.SchedulableProgramType) WorkflowNode(co.cask.cdap.api.workflow.WorkflowNode)

Aggregations

WorkflowSpecification (co.cask.cdap.api.workflow.WorkflowSpecification)19 WorkflowNode (co.cask.cdap.api.workflow.WorkflowNode)7 ApplicationSpecification (co.cask.cdap.api.app.ApplicationSpecification)6 WorkflowActionNode (co.cask.cdap.api.workflow.WorkflowActionNode)5 DatasetCreationSpec (co.cask.cdap.internal.dataset.DatasetCreationSpec)5 ProgramId (co.cask.cdap.proto.id.ProgramId)5 Map (java.util.Map)5 ScheduleProgramInfo (co.cask.cdap.api.workflow.ScheduleProgramInfo)4 ProgramType (co.cask.cdap.proto.ProgramType)4 ApplicationId (co.cask.cdap.proto.id.ApplicationId)4 InstanceNotFoundException (co.cask.cdap.api.dataset.InstanceNotFoundException)3 ApplicationNotFoundException (co.cask.cdap.common.ApplicationNotFoundException)3 NotFoundException (co.cask.cdap.common.NotFoundException)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 FlowSpecification (co.cask.cdap.api.flow.FlowSpecification)2 SchedulableProgramType (co.cask.cdap.api.schedule.SchedulableProgramType)2 WorkflowForkNode (co.cask.cdap.api.workflow.WorkflowForkNode)2 ProgramNotFoundException (co.cask.cdap.common.ProgramNotFoundException)2 ScheduleCreationSpec (co.cask.cdap.internal.schedule.ScheduleCreationSpec)2