Search in sources :

Example 6 with Workflow

use of org.onosproject.workflow.api.Workflow in project onos by opennetworkinglab.

the class SampleWorkflow method registerWorkflows.

/**
 * Registers example workflows.
 *
 * @throws WorkflowException wfex
 */
public void registerWorkflows() throws WorkflowException {
    // registering class-loader
    workflowStore.registerLocal(this.getClass().getClassLoader());
    // registering new workflow definition
    URI uri = URI.create("sample.workflow-0");
    Workflow workflow = null;
    workflow = ImmutableListWorkflow.builder().id(uri).chain(SampleWorklet1.class.getName()).chain(SampleWorklet2.class.getName()).chain(SampleWorklet3.class.getName()).chain(SampleWorklet4.class.getName()).chain(SampleWorklet5.class.getName()).build();
    workflowService.register(workflow);
    // registering new workflow definition
    uri = URI.create("sample.workflow-1");
    workflow = ImmutableListWorkflow.builder().id(uri).chain(SampleWorklet3.class.getName()).chain(SampleWorklet2.class.getName()).chain(SampleWorklet1.class.getName()).chain(SampleWorklet4.class.getName()).chain(SampleWorklet5.class.getName()).build();
    workflowService.register(workflow);
    // registering new workflow definition
    uri = URI.create("sample.workflow-2");
    workflow = ImmutableListWorkflow.builder().id(uri).chain(SampleWorklet1.class.getName()).chain(SampleWorklet3.class.getName()).chain(SampleWorklet2.class.getName()).chain(SampleWorklet4.class.getName()).chain(SampleWorklet5.class.getName()).build();
    workflowService.register(workflow);
    // registering new workflow definition
    uri = URI.create("sample.workflow-invalid-datamodel-type");
    workflow = ImmutableListWorkflow.builder().id(uri).chain(SampleWorklet6.class.getName()).build();
    workflowService.register(workflow);
    // registering new workflow definition
    uri = URI.create("sample.workflow-static-datamodel");
    workflow = ImmutableListWorkflow.builder().id(uri).chain(DefaultWorkletDescription.builder().name(SampleWorklet6.class.getName()).staticDataModel("/sample", "value").build()).build();
    workflowService.register(workflow);
}
Also used : Workflow(org.onosproject.workflow.api.Workflow) ImmutableListWorkflow(org.onosproject.workflow.api.ImmutableListWorkflow) URI(java.net.URI)

Example 7 with Workflow

use of org.onosproject.workflow.api.Workflow in project onos by opennetworkinglab.

the class WorkFlowTestCommand method defineInvalidWorkflow.

private void defineInvalidWorkflow() {
    WorkflowService service = get(WorkflowService.class);
    try {
        URI uri = URI.create("sample.workflow-invalid-datamodel-type");
        Workflow workflow = ImmutableListWorkflow.builder().id(uri).chain(SampleWorkflow.SampleWorklet5.class.getName()).chain(SampleWorkflow.SampleWorklet6.class.getName()).build();
        service.register(workflow);
    } catch (WorkflowException e) {
        error(e.getMessage() + ", trace: " + Arrays.asList(e.getStackTrace()));
    }
}
Also used : WorkflowService(org.onosproject.workflow.api.WorkflowService) WorkflowException(org.onosproject.workflow.api.WorkflowException) SampleWorkflow(org.onosproject.workflow.impl.example.SampleWorkflow) Workflow(org.onosproject.workflow.api.Workflow) SampleWorkflow(org.onosproject.workflow.impl.example.SampleWorkflow) ImmutableListWorkflow(org.onosproject.workflow.api.ImmutableListWorkflow) URI(java.net.URI)

Example 8 with Workflow

use of org.onosproject.workflow.api.Workflow in project onos by opennetworkinglab.

the class WorkflowStatusCommand method invoke.

private void invoke() {
    try {
        WorkflowStore workflowStore = get(WorkflowStore.class);
        WorkplaceStore workplaceStore = get(WorkplaceStore.class);
        System.out.printf("%-25s %-45s %-10s%n", "DEVICEIP", " WORKFLOW NAME", "WORKFLOW STATE");
        for (WorkflowContext context : workplaceStore.getContexts()) {
            for (Workflow workflow : workflowStore.getAll()) {
                if (context.workflowId().equals(workflow.id())) {
                    JsonDataModelTree tree = (JsonDataModelTree) context.data();
                    JsonNode mgmtIp = tree.nodeAt("/mgmtIp");
                    System.out.printf("%-25s %-45s %-10s%n", mgmtIp, context.name(), context.state().toString());
                }
            }
        }
    } catch (WorkflowException e) {
        e.printStackTrace();
    }
}
Also used : WorkflowStore(org.onosproject.workflow.api.WorkflowStore) WorkplaceStore(org.onosproject.workflow.api.WorkplaceStore) WorkflowContext(org.onosproject.workflow.api.WorkflowContext) WorkflowException(org.onosproject.workflow.api.WorkflowException) JsonDataModelTree(org.onosproject.workflow.api.JsonDataModelTree) Workflow(org.onosproject.workflow.api.Workflow) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 9 with Workflow

use of org.onosproject.workflow.api.Workflow in project onos by opennetworkinglab.

the class WorkplaceWorkflow method registerWorkflows.

public void registerWorkflows() {
    Workflow workflow = ImmutableListWorkflow.builder().id(URI.create(WF_CREATE_WORKFLOW)).attribute(WorkflowAttribute.REMOVE_AFTER_COMPLETE).init(ChangeDistributor.class.getName()).chain(CreateWorkplace.class.getName()).chain(CreateWorkflowContext.class.getName()).build();
    workflowStore.register(workflow);
}
Also used : Workflow(org.onosproject.workflow.api.Workflow) ImmutableListWorkflow(org.onosproject.workflow.api.ImmutableListWorkflow)

Example 10 with Workflow

use of org.onosproject.workflow.api.Workflow in project onos by opennetworkinglab.

the class WorkFlowEngine method execEventTask.

/**
 * Executes event task.
 *
 * @param task event task
 * @return event task
 */
private EventTask execEventTask(EventTask task) {
    if (!eventMapStore.isEventMapPresent(task.context().name())) {
        log.trace("EventMap doesnt exist for taskcontext:{}", task.context().name());
        return task;
    }
    log.debug("execEventTask- task: {}, hash: {}", task, stringHash(task.context().distributor()));
    WorkflowContext context = (WorkflowContext) (task.context());
    Workflow workflow = workflowStore.get(context.workflowId());
    if (workflow == null) {
        log.error("Invalid workflow {}", context.workflowId());
        return task;
    }
    WorkflowContext latestContext = workplaceStore.getContext(context.name());
    if (latestContext == null) {
        log.error("Invalid workflow context {}", context.name());
        return task;
    }
    try {
        if (!Objects.equals(latestContext.current(), task.programCounter())) {
            log.error("Current worklet({}) is not mismatched with task work({}). Ignored.", latestContext.current(), task.programCounter());
            return task;
        }
        Worklet worklet = workflow.getWorkletInstance(task.programCounter());
        if (Worklet.Common.COMPLETED.equals(worklet) || Worklet.Common.INIT.equals(worklet)) {
            log.error("Current worklet is {}, Ignored", worklet);
            return task;
        }
        initWorkletExecution(latestContext);
        log.info("{} worklet.isCompleted:{}", latestContext.name(), worklet.tag());
        log.trace("{} task:{}, context: {}", latestContext.name(), task, latestContext);
        dataModelInjector.inject(worklet, latestContext);
        boolean completed = worklet.isCompleted(latestContext, task.event());
        dataModelInjector.inhale(worklet, latestContext);
        if (completed) {
            log.info("{} worklet.isCompleted(true):{}", latestContext.name(), worklet.tag());
            log.trace("{} task:{}, context: {}", latestContext.name(), task, latestContext);
            eventMapStore.unregisterEventMap(task.eventType(), latestContext.name());
            // completed case
            // increase program counter
            ProgramCounter pc = latestContext.current();
            latestContext.setCurrent(workflow.increased(pc));
            workplaceStore.commitContext(latestContext.name(), latestContext, true);
            return null;
        } else {
            log.info("{} worklet.isCompleted(false):{}", latestContext.name(), worklet.tag());
            log.trace("{} task:{}, context: {}", latestContext.name(), task, latestContext);
            workplaceStore.commitContext(latestContext.name(), latestContext, false);
        }
    } catch (WorkflowException e) {
        log.error("Exception: ", e);
        latestContext.setCause(e.getMessage());
        latestContext.setState(WorkflowState.EXCEPTION);
        workplaceStore.commitContext(latestContext.name(), latestContext, false);
    } catch (StorageException e) {
        log.error("Exception: ", e);
    // StorageException does not commit context.
    } catch (Exception e) {
        log.error("Exception: ", e);
        latestContext.setCause(e.getMessage());
        latestContext.setState(WorkflowState.EXCEPTION);
        workplaceStore.commitContext(latestContext.name(), latestContext, false);
    }
    return task;
}
Also used : WorkflowContext(org.onosproject.workflow.api.WorkflowContext) SystemWorkflowContext(org.onosproject.workflow.api.SystemWorkflowContext) WorkflowException(org.onosproject.workflow.api.WorkflowException) Workflow(org.onosproject.workflow.api.Workflow) Worklet(org.onosproject.workflow.api.Worklet) ProgramCounter(org.onosproject.workflow.api.ProgramCounter) StorageException(org.onosproject.store.service.StorageException) StorageException(org.onosproject.store.service.StorageException) WorkflowException(org.onosproject.workflow.api.WorkflowException)

Aggregations

Workflow (org.onosproject.workflow.api.Workflow)11 WorkflowException (org.onosproject.workflow.api.WorkflowException)9 WorkflowContext (org.onosproject.workflow.api.WorkflowContext)6 Worklet (org.onosproject.workflow.api.Worklet)5 StorageException (org.onosproject.store.service.StorageException)4 ImmutableListWorkflow (org.onosproject.workflow.api.ImmutableListWorkflow)4 SystemWorkflowContext (org.onosproject.workflow.api.SystemWorkflowContext)4 URI (java.net.URI)3 WorkletDescription (org.onosproject.workflow.api.WorkletDescription)3 JsonDataModelTree (org.onosproject.workflow.api.JsonDataModelTree)2 ProgramCounter (org.onosproject.workflow.api.ProgramCounter)2 WorkflowStore (org.onosproject.workflow.api.WorkflowStore)2 WorkplaceStore (org.onosproject.workflow.api.WorkplaceStore)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 Executors.newSingleThreadScheduledExecutor (java.util.concurrent.Executors.newSingleThreadScheduledExecutor)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 Tools.groupedThreads (org.onlab.util.Tools.groupedThreads)1 DeviceService (org.onosproject.net.device.DeviceService)1 DefaultWorkletDescription (org.onosproject.workflow.api.DefaultWorkletDescription)1 DefaultWorkplace (org.onosproject.workflow.api.DefaultWorkplace)1