Search in sources :

Example 1 with WorkflowActionNode

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

the class ProgramClient method getWorkflowCurrent.

/**
   * Get the current run information for the Workflow based on the runid
   *
   * @param workflowId ID of the workflow
   * @param runId ID of the run for which the details are to be returned
   * @return list of {@link WorkflowActionNode} currently running for the given runid
   * @throws IOException if a network error occurred
   * @throws NotFoundException if the application, workflow, or runid could not be found
   * @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
   */
public List<WorkflowActionNode> getWorkflowCurrent(WorkflowId workflowId, String runId) throws IOException, NotFoundException, UnauthenticatedException, UnauthorizedException {
    String path = String.format("/apps/%s/workflows/%s/runs/%s/current", workflowId.getApplication(), workflowId.getProgram(), runId);
    URL url = config.resolveNamespacedURLV3(workflowId.getNamespaceId(), path);
    HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
    if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
        throw new NotFoundException(workflowId.run(runId));
    }
    ObjectResponse<List<WorkflowActionNode>> objectResponse = ObjectResponse.fromJsonBody(response, new TypeToken<List<WorkflowActionNode>>() {
    }.getType(), GSON);
    return objectResponse.getResponseObject();
}
Also used : TypeToken(com.google.common.reflect.TypeToken) WorkflowActionNode(co.cask.cdap.api.workflow.WorkflowActionNode) HttpResponse(co.cask.common.http.HttpResponse) ProgramNotFoundException(co.cask.cdap.common.ProgramNotFoundException) ApplicationNotFoundException(co.cask.cdap.common.ApplicationNotFoundException) NotFoundException(co.cask.cdap.common.NotFoundException) List(java.util.List) URL(java.net.URL)

Example 2 with WorkflowActionNode

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

the class GetWorkflowCurrentRunCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    String[] programIdParts = arguments.get(elementType.getArgumentName().toString()).split("\\.");
    ApplicationId appId = cliConfig.getCurrentNamespace().app(programIdParts[0]);
    List<WorkflowActionNode> nodes;
    if (elementType.getProgramType() != null) {
        if (programIdParts.length < 2) {
            throw new CommandInputError(this);
        }
        String workflowId = programIdParts[1];
        String runId = arguments.get(ArgumentName.RUN_ID.toString());
        nodes = programClient.getWorkflowCurrent(appId.workflow(workflowId), runId);
    } else {
        throw new IllegalArgumentException("Unrecognized program element type for current runs: " + elementType);
    }
    Table table = Table.builder().setHeader("node id", "program name", "program type").setRows(nodes, new RowMaker<WorkflowActionNode>() {

        @Override
        public List<?> makeRow(WorkflowActionNode object) {
            return Lists.newArrayList(object.getNodeId(), object.getProgram().getProgramName(), object.getProgram().getProgramType());
        }
    }).build();
    cliConfig.getTableRenderer().render(cliConfig, output, table);
}
Also used : CommandInputError(co.cask.cdap.cli.exception.CommandInputError) Table(co.cask.cdap.cli.util.table.Table) RowMaker(co.cask.cdap.cli.util.RowMaker) WorkflowActionNode(co.cask.cdap.api.workflow.WorkflowActionNode) ApplicationId(co.cask.cdap.proto.id.ApplicationId)

Example 3 with WorkflowActionNode

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

the class WorkflowVerificationTest method verifyWorkflowWithLocalDatasetSpecification.

private void verifyWorkflowWithLocalDatasetSpecification(ApplicationSpecification appSpec) {
    WorkflowSpecification spec = appSpec.getWorkflows().get("WorkflowWithLocalDatasets");
    List<WorkflowNode> nodes = spec.getNodes();
    Assert.assertTrue(nodes.size() == 2);
    WorkflowNode node = nodes.get(0);
    Assert.assertTrue(node.getType() == WorkflowNodeType.ACTION);
    WorkflowActionNode actionNode = (WorkflowActionNode) node;
    Assert.assertTrue(actionNode.getProgram().equals(new ScheduleProgramInfo(SchedulableProgramType.MAPREDUCE, "MR1")));
    node = nodes.get(1);
    Assert.assertTrue(node.getType() == WorkflowNodeType.ACTION);
    actionNode = (WorkflowActionNode) node;
    Assert.assertTrue(actionNode.getProgram().equals(new ScheduleProgramInfo(SchedulableProgramType.SPARK, "SP1")));
    Map<String, DatasetCreationSpec> localDatasetSpecs = spec.getLocalDatasetSpecs();
    Assert.assertEquals(5, localDatasetSpecs.size());
    DatasetCreationSpec datasetCreationSpec = localDatasetSpecs.get("mytable");
    Assert.assertEquals(Table.class.getName(), datasetCreationSpec.getTypeName());
    Assert.assertEquals(0, datasetCreationSpec.getProperties().getProperties().size());
    datasetCreationSpec = localDatasetSpecs.get("myfile");
    Assert.assertEquals(FileSet.class.getName(), datasetCreationSpec.getTypeName());
    Assert.assertEquals(0, datasetCreationSpec.getProperties().getProperties().size());
    datasetCreationSpec = localDatasetSpecs.get("myfile_with_properties");
    Assert.assertEquals(FileSet.class.getName(), datasetCreationSpec.getTypeName());
    Assert.assertEquals("prop_value", datasetCreationSpec.getProperties().getProperties().get("prop_key"));
    datasetCreationSpec = localDatasetSpecs.get("mytablefromtype");
    Assert.assertEquals(Table.class.getName(), datasetCreationSpec.getTypeName());
    Assert.assertEquals(0, datasetCreationSpec.getProperties().getProperties().size());
    datasetCreationSpec = localDatasetSpecs.get("myfilefromtype");
    Assert.assertEquals(FileSet.class.getName(), datasetCreationSpec.getTypeName());
    Assert.assertEquals("another_prop_value", datasetCreationSpec.getProperties().getProperties().get("another_prop_key"));
    // Check if the application specification has correct modules
    Map<String, String> datasetModules = appSpec.getDatasetModules();
    Assert.assertEquals(2, datasetModules.size());
    Assert.assertTrue(datasetModules.containsKey(FileSet.class.getName()));
    Assert.assertTrue(datasetModules.containsKey(Table.class.getName()));
}
Also used : Table(co.cask.cdap.api.dataset.table.Table) FileSet(co.cask.cdap.api.dataset.lib.FileSet) WorkflowActionNode(co.cask.cdap.api.workflow.WorkflowActionNode) DatasetCreationSpec(co.cask.cdap.internal.dataset.DatasetCreationSpec) WorkflowSpecification(co.cask.cdap.api.workflow.WorkflowSpecification) ScheduleProgramInfo(co.cask.cdap.api.workflow.ScheduleProgramInfo) WorkflowNode(co.cask.cdap.api.workflow.WorkflowNode)

Example 4 with WorkflowActionNode

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

the class DistributedWorkflowProgramRunner method setupLaunchConfig.

@Override
protected void setupLaunchConfig(LaunchConfig launchConfig, Program program, ProgramOptions options, CConfiguration cConf, Configuration hConf, File tempDir) throws IOException {
    WorkflowSpecification spec = program.getApplicationSpecification().getWorkflows().get(program.getName());
    List<ClassAcceptor> acceptors = new ArrayList<>();
    // Only interested in MapReduce and Spark nodes
    Set<SchedulableProgramType> runnerTypes = EnumSet.of(SchedulableProgramType.MAPREDUCE, SchedulableProgramType.SPARK);
    for (WorkflowActionNode node : Iterables.filter(spec.getNodeIdMap().values(), WorkflowActionNode.class)) {
        // For each type, we only need one node to setup the launch context
        ScheduleProgramInfo programInfo = node.getProgram();
        if (!runnerTypes.remove(programInfo.getProgramType())) {
            continue;
        }
        // Find the ProgramRunner of the given type and setup the launch context
        ProgramType programType = ProgramType.valueOfSchedulableType(programInfo.getProgramType());
        ProgramRunner runner = programRunnerFactory.create(programType);
        try {
            if (runner instanceof DistributedProgramRunner) {
                // Call setupLaunchConfig with the corresponding program
                ProgramId programId = program.getId().getParent().program(programType, programInfo.getProgramName());
                ((DistributedProgramRunner) runner).setupLaunchConfig(launchConfig, Programs.create(cConf, program, programId, runner), options, cConf, hConf, tempDir);
                acceptors.add(launchConfig.getClassAcceptor());
            }
        } finally {
            if (runner instanceof Closeable) {
                Closeables.closeQuietly((Closeable) runner);
            }
        }
    }
    // Set the class acceptor
    launchConfig.setClassAcceptor(new AndClassAcceptor(acceptors));
    // Clear and set the runnable for the workflow driver
    launchConfig.clearRunnables();
    Resources defaultResources = findDriverResources(program.getApplicationSpecification().getSpark(), program.getApplicationSpecification().getMapReduce(), spec);
    launchConfig.addRunnable(spec.getName(), new WorkflowTwillRunnable(spec.getName()), 1, options.getArguments().asMap(), defaultResources, 0);
}
Also used : WorkflowActionNode(co.cask.cdap.api.workflow.WorkflowActionNode) Closeable(java.io.Closeable) ArrayList(java.util.ArrayList) ClassAcceptor(org.apache.twill.api.ClassAcceptor) ProgramId(co.cask.cdap.proto.id.ProgramId) WorkflowSpecification(co.cask.cdap.api.workflow.WorkflowSpecification) SchedulableProgramType(co.cask.cdap.api.schedule.SchedulableProgramType) ProgramType(co.cask.cdap.proto.ProgramType) SchedulableProgramType(co.cask.cdap.api.schedule.SchedulableProgramType) Resources(co.cask.cdap.api.Resources) ScheduleProgramInfo(co.cask.cdap.api.workflow.ScheduleProgramInfo) ProgramRunner(co.cask.cdap.app.runtime.ProgramRunner)

Example 5 with WorkflowActionNode

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

the class WorkflowDriver method executeNode.

private void executeNode(ApplicationSpecification appSpec, WorkflowNode node, InstantiatorFactory instantiator, ClassLoader classLoader, WorkflowToken token) throws Exception {
    WorkflowNodeType nodeType = node.getType();
    ((BasicWorkflowToken) token).setCurrentNode(node.getNodeId());
    switch(nodeType) {
        case ACTION:
            WorkflowActionNode actionNode = (WorkflowActionNode) node;
            if (SchedulableProgramType.CUSTOM_ACTION == actionNode.getProgram().getProgramType()) {
                executeCustomAction(actionNode, instantiator, classLoader, token);
            } else {
                executeAction(actionNode, token);
            }
            break;
        case FORK:
            executeFork(appSpec, (WorkflowForkNode) node, instantiator, classLoader, token);
            break;
        case CONDITION:
            executeCondition(appSpec, (WorkflowConditionNode) node, instantiator, classLoader, token);
            break;
        default:
            break;
    }
}
Also used : WorkflowActionNode(co.cask.cdap.api.workflow.WorkflowActionNode) WorkflowNodeType(co.cask.cdap.api.workflow.WorkflowNodeType)

Aggregations

WorkflowActionNode (co.cask.cdap.api.workflow.WorkflowActionNode)13 ScheduleProgramInfo (co.cask.cdap.api.workflow.ScheduleProgramInfo)7 WorkflowNode (co.cask.cdap.api.workflow.WorkflowNode)5 WorkflowSpecification (co.cask.cdap.api.workflow.WorkflowSpecification)5 Resources (co.cask.cdap.api.Resources)2 SchedulableProgramType (co.cask.cdap.api.schedule.SchedulableProgramType)2 WorkflowForkNode (co.cask.cdap.api.workflow.WorkflowForkNode)2 ProgramType (co.cask.cdap.proto.ProgramType)2 ApplicationId (co.cask.cdap.proto.id.ApplicationId)2 ProgramId (co.cask.cdap.proto.id.ProgramId)2 ArrayList (java.util.ArrayList)2 ApplicationSpecification (co.cask.cdap.api.app.ApplicationSpecification)1 CustomActionSpecification (co.cask.cdap.api.customaction.CustomActionSpecification)1 FileSet (co.cask.cdap.api.dataset.lib.FileSet)1 Table (co.cask.cdap.api.dataset.table.Table)1 WorkflowActionSpecification (co.cask.cdap.api.workflow.WorkflowActionSpecification)1 WorkflowConditionNode (co.cask.cdap.api.workflow.WorkflowConditionNode)1 WorkflowNodeType (co.cask.cdap.api.workflow.WorkflowNodeType)1 ProgramRunner (co.cask.cdap.app.runtime.ProgramRunner)1 CommandInputError (co.cask.cdap.cli.exception.CommandInputError)1