use of org.onosproject.workflow.api.EventTask in project onos by opennetworkinglab.
the class WorkFlowEngine method post.
@Override
protected void post(WorkflowDataEvent event) {
if (event.subject() == null || !isRelevant(event.subject())) {
log.debug("ignore event {}", event);
return;
}
// trigger next worklet selection
WorkflowData dataModelContainer = event.subject();
switch(event.type()) {
case INSERT:
case UPDATE:
if (dataModelContainer.triggerNext()) {
log.debug("workflowAccumulator.add: {}", dataModelContainer);
workflowAccumulator.add(dataModelContainer);
} else {
log.debug("pass-workflowAccumulator.add: {}", dataModelContainer);
}
break;
case REMOVE:
break;
default:
}
// trigger EventTask for WorkflowDataEvent
eventMapTriggerExecutor.submit(() -> eventMapTrigger(event, // event hint supplier
(ev) -> {
if (ev == null || ev.subject() == null) {
return null;
}
if (ev.subject() instanceof WorkflowData) {
return ((WorkflowData) ev.subject()).name();
} else {
return null;
}
}));
}
use of org.onosproject.workflow.api.EventTask in project onos by opennetworkinglab.
the class WorkFlowEngine method eventMapTrigger.
@Override
public void eventMapTrigger(Event event, EventHintSupplier supplier) {
if (event.subject() instanceof SystemWorkflowContext) {
return;
}
Map<String, String> eventMap;
String eventHint;
try {
eventHint = supplier.apply(event);
} catch (Throwable e) {
log.error("Exception: ", e);
return;
}
if (eventHint == null) {
// do nothing
log.error("Invalid eventHint, event: {}", event);
return;
}
try {
eventMap = eventMapStore.getEventMapByHint(event.getClass().getName(), eventHint);
} catch (WorkflowException e) {
log.error("Exception: ", e);
return;
}
if (Objects.isNull(eventMap) || eventMap.isEmpty()) {
// do nothing;
log.debug("Invalid eventMap, event: {}", event);
return;
}
for (Map.Entry<String, String> entry : eventMap.entrySet()) {
String contextName = entry.getKey();
String strProgramCounter = entry.getValue();
ProgramCounter pc;
try {
pc = ProgramCounter.valueOf(strProgramCounter);
} catch (IllegalArgumentException e) {
log.error("Exception: ", e);
return;
}
WorkflowContext context = workplaceStore.getContext(contextName);
if (Objects.isNull(context)) {
log.info("Invalid context: {}, event: {}", contextName, event);
continue;
}
EventTask eventtask = null;
try {
eventtask = EventTask.builder().event(event).eventHint(eventHint).context(context).programCounter(pc).build();
} catch (WorkflowException e) {
log.error("Exception: ", e);
}
log.debug("eventtaskAccumulator.add: task: {}", eventtask);
if (!Objects.isNull(eventtask)) {
eventtaskAccumulator.add(eventtask);
}
}
}
Aggregations