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);
}
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()));
}
}
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();
}
}
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);
}
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;
}
Aggregations