use of org.onosproject.workflow.api.Workflow in project onos by opennetworkinglab.
the class WorkFlowEngine method execEventTimeoutTask.
/**
* Executes event timeout task.
*
* @param task event timeout task
* @return handler task
*/
private HandlerTask execEventTimeoutTask(EventTimeoutTask task) {
if (!eventMapStore.isEventMapPresent(task.context().name())) {
log.trace("EventMap doesnt exist for taskcontext:{}", task.context().name());
return task;
}
log.debug("execEventTimeoutTask- task: {}, hash: {}", task, stringHash(task.context().distributor()));
WorkflowContext context = (WorkflowContext) (task.context());
Workflow workflow = workflowStore.get(context.workflowId());
if (workflow == null) {
log.error("execEventTimeoutTask: Invalid workflow {}", context.workflowId());
return task;
}
WorkflowContext latestContext = workplaceStore.getContext(context.name());
if (latestContext == null) {
log.error("execEventTimeoutTask: Invalid workflow context {}", context.name());
return task;
}
try {
if (!Objects.equals(latestContext.current(), task.programCounter())) {
log.error("execEventTimeoutTask: Current worklet({}) is not mismatched with task work({}). Ignored.", latestContext.current(), task.programCounter());
return task;
}
Worklet worklet = workflow.getWorkletInstance(task.programCounter());
if (worklet == Worklet.Common.COMPLETED || worklet == Worklet.Common.INIT) {
log.error("execEventTimeoutTask: Current worklet is {}, Ignored", worklet);
return task;
}
initWorkletExecution(latestContext);
eventMapStore.unregisterEventMap(task.eventType(), latestContext.name());
log.info("{} worklet.timeout(for event):{}", latestContext.name(), worklet.tag());
log.trace("{} task:{}, context: {}", latestContext.name(), task, latestContext);
dataModelInjector.inject(worklet, latestContext);
WorkletDescription workletDesc = workflow.getWorkletDesc(task.programCounter());
if (Objects.nonNull(workletDesc)) {
if (!(workletDesc.tag().equals("INIT") || workletDesc.tag().equals("COMPLETED"))) {
staticDataModelInjector.inject(worklet, workletDesc);
}
}
worklet.timeout(latestContext);
dataModelInjector.inhale(worklet, latestContext);
log.info("{} worklet.timeout(for event)(done):{}", latestContext.name(), worklet.tag());
log.trace("{} task:{}, context: {}", latestContext.name(), task, latestContext);
workplaceStore.commitContext(latestContext.name(), latestContext, latestContext.triggerNext());
} 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;
}
use of org.onosproject.workflow.api.Workflow in project onos by opennetworkinglab.
the class WorkFlowEngine method execInitWorklet.
@Override
public void execInitWorklet(WorkflowContext context) {
Workflow workflow = workflowStore.get(context.workflowId());
if (workflow == null) {
log.error("Invalid workflow id:{}", context.workflowId());
return;
}
initWorkletExecution(context);
try {
Worklet initWorklet = workflow.init(context);
if (initWorklet != null) {
log.info("{} worklet.process:{}", context.name(), initWorklet.tag());
log.trace("{} context: {}", context.name(), context);
dataModelInjector.inject(initWorklet, context);
initWorklet.process(context);
dataModelInjector.inhale(initWorklet, context);
log.info("{} worklet.process(done): {}", context.name(), initWorklet.tag());
log.trace("{} context: {}", context.name(), context);
}
check(workplaceStore.getContext(context.name()) == null, "Duplicated workflow context(" + context.name() + ") assignment.");
} catch (WorkflowException e) {
log.error("Exception: ", e);
context.setCause(e.getMessage());
context.setState(WorkflowState.EXCEPTION);
workplaceStore.commitContext(context.name(), context, false);
return;
}
// trigger the execution of next worklet.
workplaceStore.registerContext(context.name(), context);
}
use of org.onosproject.workflow.api.Workflow in project onos by opennetworkinglab.
the class WorkFlowEngine method execTimeoutTask.
/**
* Executes timeout task.
*
* @param task time out task
* @return handler task
*/
private HandlerTask execTimeoutTask(TimeoutTask task) {
log.debug("execTimeoutTask- task: {}, hash: {}", task, stringHash(task.context().distributor()));
WorkflowContext context = (WorkflowContext) (task.context());
Workflow workflow = workflowStore.get(context.workflowId());
if (workflow == null) {
log.error("execTimeoutTask: Invalid workflow {}", context.workflowId());
return task;
}
WorkflowContext latestContext = workplaceStore.getContext(context.name());
if (latestContext == null) {
log.error("execTimeoutTask: Invalid workflow context {}", context.name());
return task;
}
try {
if (!Objects.equals(latestContext.current(), task.programCounter())) {
log.error("execTimeoutTask: Current worklet({}) is not mismatched with task work({}). Ignored.", latestContext.current(), task.programCounter());
return task;
}
Worklet worklet = workflow.getWorkletInstance(task.programCounter());
if (worklet == Worklet.Common.COMPLETED || worklet == Worklet.Common.INIT) {
log.error("execTimeoutTask: Current worklet is {}, Ignored", worklet);
return task;
}
initWorkletExecution(latestContext);
log.info("{} worklet.timeout:{}", latestContext.name(), worklet.tag());
log.trace("{} context: {}", latestContext.name(), latestContext);
dataModelInjector.inject(worklet, latestContext);
WorkletDescription workletDesc = workflow.getWorkletDesc(task.programCounter());
if (Objects.nonNull(workletDesc)) {
if (!(workletDesc.tag().equals("INIT") || workletDesc.tag().equals("COMPLETED"))) {
staticDataModelInjector.inject(worklet, workletDesc);
}
}
worklet.timeout(latestContext);
dataModelInjector.inhale(worklet, latestContext);
log.info("{} worklet.timeout(done):{}", latestContext.name(), worklet.tag());
log.trace("{} context: {}", latestContext.name(), latestContext);
workplaceStore.commitContext(latestContext.name(), latestContext, latestContext.triggerNext());
} 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;
}
use of org.onosproject.workflow.api.Workflow in project onos by opennetworkinglab.
the class WorkFlowEngine method execWorkflowContext.
/**
* Executes workflow context.
*
* @param context workflow context
* @return workflow context
*/
private WorkflowContext execWorkflowContext(WorkflowContext context) {
Workflow workflow = workflowStore.get(context.workflowId());
if (workflow == null) {
log.error("Invalid workflow {}", context.workflowId());
return null;
}
final WorkflowContext latestContext = workplaceStore.getContext(context.name());
if (latestContext == null) {
log.error("Invalid workflow context {}", context.name());
return null;
}
initWorkletExecution(latestContext);
try {
final ProgramCounter pc = workflow.next(latestContext);
final Worklet worklet = workflow.getWorkletInstance(pc);
if (worklet == Worklet.Common.INIT) {
log.error("workflow.next gave INIT. It cannot be executed (context: {})", context.name());
return latestContext;
}
latestContext.setCurrent(pc);
if (worklet == Worklet.Common.COMPLETED) {
if (workflow.attributes().contains(REMOVE_AFTER_COMPLETE)) {
workplaceStore.removeContext(latestContext.name());
return null;
} else {
latestContext.setState(WorkflowState.IDLE);
workplaceStore.commitContext(latestContext.name(), latestContext, false);
return latestContext;
}
}
log.info("{} worklet.process:{}", latestContext.name(), worklet.tag());
log.trace("{} context: {}", latestContext.name(), latestContext);
dataModelInjector.inject(worklet, latestContext);
WorkletDescription workletDesc = workflow.getWorkletDesc(pc);
if (Objects.nonNull(workletDesc)) {
if (!(workletDesc.tag().equals("INIT") || workletDesc.tag().equals("COMPLETED"))) {
staticDataModelInjector.inject(worklet, workletDesc);
}
}
worklet.process(latestContext);
dataModelInjector.inhale(worklet, latestContext);
log.info("{} worklet.process(done): {}", latestContext.name(), worklet.tag());
log.trace("{} context: {}", latestContext.name(), latestContext);
if (latestContext.completionEventType() != null) {
if (latestContext.completionEventGenerator() == null) {
String msg = String.format("Invalid exepecting event(%s), generator(%s)", latestContext.completionEventType(), latestContext.completionEventGenerator());
throw new WorkflowException(msg);
}
registerEventMap(latestContext.completionEventType(), latestContext.completionEventHints(), latestContext.name(), pc.toString());
latestContext.completionEventGenerator().apply();
if (latestContext.completionEventTimeout() != 0L) {
final EventTimeoutTask eventTimeoutTask = EventTimeoutTask.builder().context(latestContext).programCounter(pc).eventType(latestContext.completionEventType().getName()).eventHintSet(latestContext.completionEventHints()).build();
timerChain.schedule(latestContext.completionEventTimeout(), () -> {
eventtaskAccumulator.add(eventTimeoutTask);
});
}
} else {
if (latestContext.completionEventTimeout() != 0L) {
final TimeoutTask timeoutTask = TimeoutTask.builder().context(latestContext).programCounter(pc).build();
timerChain.schedule(latestContext.completionEventTimeout(), () -> {
eventtaskAccumulator.add(timeoutTask);
});
} else {
// completed case
// increase program counter
latestContext.setCurrent(workflow.increased(pc));
}
}
workplaceStore.commitContext(latestContext.name(), latestContext, latestContext.triggerNext());
} 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 latestContext;
}
use of org.onosproject.workflow.api.Workflow in project onos by opennetworkinglab.
the class OfOverlayWorkflowRegister method registerWorkflows.
/**
* Registers workflows.
*/
private void registerWorkflows() {
try {
// registering class-loader
workflowStore.registerLocal(this.getClass().getClassLoader());
// registering new workflow definition
URI uri = URI.create("of-overlay.workflow-nova");
Workflow workflow = ImmutableListWorkflow.builder().id(uri).chain(Ovs.CreateOvsdbDevice.class.getName()).chain(Ovs.UpdateOvsVersion.class.getName()).chain(Ovs.UpdateBridgeId.class.getName()).chain(DefaultWorkletDescription.builder().name(Ovs.CreateBridge.class.getName()).staticDataModel(BRIDGE_NAME, "br-int").build()).chain(DefaultWorkletDescription.builder().name(Ovs.CreateBridge.class.getName()).staticDataModel(BRIDGE_NAME, "br-phy").build()).chain(Ovs.CreateOverlayBridgeVxlanPort.class.getName()).chain(Ovs.AddPhysicalPortsOnUnderlayBridge.class.getName()).chain(Ovs.ConfigureUnderlayBridgeLocalIp.class.getName()).build();
workflowStore.register(workflow);
// registering new workflow definition based on multi-event handling
uri = URI.create("of-overlay.workflow-nova-multiEvent-test");
workflow = ImmutableListWorkflow.builder().id(uri).chain(Ovs.CreateOvsdbDevice.class.getName()).chain(Ovs.UpdateOvsVersion.class.getName()).chain(Ovs.UpdateBridgeId.class.getName()).chain(Ovs.CreateOverlayBridgeMultiEvent.class.getName()).chain(Ovs.UpdateBridgeId.class.getName()).chain(DefaultWorkletDescription.builder().name(Ovs.CreateBridge.class.getName()).staticDataModel(BRIDGE_NAME, "br-phy").build()).chain(Ovs.CreateOverlayBridgeVxlanPort.class.getName()).chain(Ovs.AddPhysicalPortsOnUnderlayBridge.class.getName()).chain(Ovs.ConfigureUnderlayBridgeLocalIp.class.getName()).build();
workflowStore.register(workflow);
uri = URI.create("of-overlay.clean-workflow-nova");
workflow = ImmutableListWorkflow.builder().id(uri).chain(Ovs.DeleteOverlayBridgeConfig.class.getName()).chain(Ovs.RemoveOverlayBridgeOfDevice.class.getName()).chain(Ovs.DeleteUnderlayBridgeConfig.class.getName()).chain(Ovs.RemoveUnderlayBridgeOfDevice.class.getName()).chain(Ovs.RemoveOvsdbDevice.class.getName()).build();
workflowStore.register(workflow);
uri = URI.create("of-overlay.clean-workflow-nova-waitAll-Bridge-Del");
workflow = ImmutableListWorkflow.builder().id(uri).chain(Ovs.DeleteOverlayBridgeConfig.class.getName()).chain(Ovs.DeleteUnderlayBridgeConfig.class.getName()).chain(Ovs.RemoveBridgeOfDevice.class.getName()).chain(Ovs.RemoveOvsdbDevice.class.getName()).build();
workflowStore.register(workflow);
uri = URI.create("of-overlay.workflow-ovs-leaf");
workflow = ImmutableListWorkflow.builder().id(uri).chain(Ovs.CreateOvsdbDevice.class.getName()).chain(Ovs.UpdateOvsVersion.class.getName()).chain(Ovs.UpdateBridgeId.class.getName()).chain(DefaultWorkletDescription.builder().name(Ovs.CreateBridge.class.getName()).staticDataModel(BRIDGE_NAME, "br-phy").build()).chain(Ovs.AddPhysicalPortsOnUnderlayBridge.class.getName()).build();
workflowStore.register(workflow);
uri = URI.create("of-overlay.workflow-ovs-spine");
workflow = ImmutableListWorkflow.builder().id(uri).chain(Ovs.CreateOvsdbDevice.class.getName()).chain(Ovs.UpdateOvsVersion.class.getName()).chain(Ovs.UpdateBridgeId.class.getName()).chain(DefaultWorkletDescription.builder().name(Ovs.CreateBridge.class.getName()).staticDataModel(BRIDGE_NAME, "br-phy").build()).chain(Ovs.AddPhysicalPortsOnUnderlayBridge.class.getName()).build();
workflowStore.register(workflow);
deviceService.addListener(event -> {
// trigger EventTask for DeviceEvent
eventMapTriggerExecutor.submit(() -> workflowExecutionService.eventMapTrigger(event, // event hint supplier
(ev) -> {
if (ev == null || ev.subject() == null) {
return null;
}
String hint = event.subject().id().toString();
log.debug("hint: {}", hint);
return hint;
}));
});
} catch (WorkflowException e) {
e.printStackTrace();
}
}
Aggregations