Search in sources :

Example 1 with Workflow

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

the class WorkflowDriver method initializeWorkflow.

@SuppressWarnings("unchecked")
private Workflow initializeWorkflow() throws Exception {
    Class<?> clz = Class.forName(workflowSpec.getClassName(), true, program.getClassLoader());
    if (!Workflow.class.isAssignableFrom(clz)) {
        throw new IllegalStateException(String.format("%s is not Workflow.", clz));
    }
    Class<? extends Workflow> workflowClass = (Class<? extends Workflow>) clz;
    final Workflow workflow = new InstantiatorFactory(false).get(TypeToken.of(workflowClass)).create();
    // set metrics
    Reflections.visit(workflow, workflow.getClass(), new MetricsFieldSetter(basicWorkflowContext.getMetrics()));
    if (!(workflow instanceof ProgramLifecycle)) {
        return workflow;
    }
    final TransactionControl txControl = Transactions.getTransactionControl(TransactionControl.IMPLICIT, Workflow.class, workflow, "initialize", WorkflowContext.class);
    basicWorkflowToken.setCurrentNode(workflowSpec.getName());
    basicWorkflowContext.setState(new ProgramState(ProgramStatus.INITIALIZING, null));
    basicWorkflowContext.initializeProgram((ProgramLifecycle) workflow, basicWorkflowContext, txControl, false);
    runtimeStore.updateWorkflowToken(workflowRunId, basicWorkflowToken);
    return workflow;
}
Also used : InstantiatorFactory(co.cask.cdap.common.lang.InstantiatorFactory) MetricsFieldSetter(co.cask.cdap.internal.app.runtime.MetricsFieldSetter) ProgramLifecycle(co.cask.cdap.api.ProgramLifecycle) TransactionControl(co.cask.cdap.api.annotation.TransactionControl) Workflow(co.cask.cdap.api.workflow.Workflow) ProgramState(co.cask.cdap.api.ProgramState)

Aggregations

ProgramLifecycle (co.cask.cdap.api.ProgramLifecycle)1 ProgramState (co.cask.cdap.api.ProgramState)1 TransactionControl (co.cask.cdap.api.annotation.TransactionControl)1 Workflow (co.cask.cdap.api.workflow.Workflow)1 InstantiatorFactory (co.cask.cdap.common.lang.InstantiatorFactory)1 MetricsFieldSetter (co.cask.cdap.internal.app.runtime.MetricsFieldSetter)1