Search in sources :

Example 1 with SystemWorkflowContext

use of org.onosproject.workflow.api.SystemWorkflowContext 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);
        }
    }
}
Also used : SystemWorkflowContext(org.onosproject.workflow.api.SystemWorkflowContext) WorkflowException(org.onosproject.workflow.api.WorkflowException) WorkflowContext(org.onosproject.workflow.api.WorkflowContext) SystemWorkflowContext(org.onosproject.workflow.api.SystemWorkflowContext) ProgramCounter(org.onosproject.workflow.api.ProgramCounter) Map(java.util.Map) EventTask(org.onosproject.workflow.api.EventTask)

Aggregations

Map (java.util.Map)1 EventTask (org.onosproject.workflow.api.EventTask)1 ProgramCounter (org.onosproject.workflow.api.ProgramCounter)1 SystemWorkflowContext (org.onosproject.workflow.api.SystemWorkflowContext)1 WorkflowContext (org.onosproject.workflow.api.WorkflowContext)1 WorkflowException (org.onosproject.workflow.api.WorkflowException)1