Search in sources :

Example 1 with EventTask

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;
        }
    }));
}
Also used : WorkletDescription(org.onosproject.workflow.api.WorkletDescription) CoreService(org.onosproject.core.CoreService) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) WorkflowStore(org.onosproject.workflow.api.WorkflowStore) Workflow(org.onosproject.workflow.api.Workflow) Workplace(org.onosproject.workflow.api.Workplace) EventHintSupplier(org.onosproject.workflow.api.EventHintSupplier) Executors.newSingleThreadScheduledExecutor(java.util.concurrent.Executors.newSingleThreadScheduledExecutor) Map(java.util.Map) ApplicationId(org.onosproject.core.ApplicationId) ProgramCounter(org.onosproject.workflow.api.ProgramCounter) WorkPartitionService(org.onosproject.net.intent.WorkPartitionService) Event(org.onosproject.event.Event) NodeId(org.onosproject.cluster.NodeId) REMOVE_AFTER_COMPLETE(org.onosproject.workflow.api.WorkflowAttribute.REMOVE_AFTER_COMPLETE) DefaultWorkplace(org.onosproject.workflow.api.DefaultWorkplace) AbstractListenerManager(org.onosproject.event.AbstractListenerManager) Deactivate(org.osgi.service.component.annotations.Deactivate) Collection(java.util.Collection) Set(java.util.Set) Executors.newSingleThreadExecutor(java.util.concurrent.Executors.newSingleThreadExecutor) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) WorkflowData(org.onosproject.workflow.api.WorkflowData) HandlerTask(org.onosproject.workflow.api.HandlerTask) List(java.util.List) EventTimeoutTask(org.onosproject.workflow.api.EventTimeoutTask) JsonNodeFactory(com.fasterxml.jackson.databind.node.JsonNodeFactory) ClusterService(org.onosproject.cluster.ClusterService) JsonDataModelTree(org.onosproject.workflow.api.JsonDataModelTree) JsonDataModelInjector(org.onosproject.workflow.api.JsonDataModelInjector) WorkflowState(org.onosproject.workflow.api.WorkflowState) HandlerTaskBatchDelegate(org.onosproject.workflow.api.HandlerTaskBatchDelegate) StorageException(org.onosproject.store.service.StorageException) WorkflowException(org.onosproject.workflow.api.WorkflowException) EventTask(org.onosproject.workflow.api.EventTask) WorkplaceStoreDelegate(org.onosproject.workflow.api.WorkplaceStoreDelegate) CompletableFuture(java.util.concurrent.CompletableFuture) WorkflowExecutionService(org.onosproject.workflow.api.WorkflowExecutionService) Worklet(org.onosproject.workflow.api.Worklet) Component(org.osgi.service.component.annotations.Component) WorkflowDataListener(org.onosproject.workflow.api.WorkflowDataListener) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Activate(org.osgi.service.component.annotations.Activate) TimeoutTask(org.onosproject.workflow.api.TimeoutTask) ContextEventMapStore(org.onosproject.workflow.api.ContextEventMapStore) ExecutorService(java.util.concurrent.ExecutorService) StaticDataModelInjector(org.onosproject.workflow.api.StaticDataModelInjector) Logger(org.slf4j.Logger) WorkflowContext(org.onosproject.workflow.api.WorkflowContext) WorkflowBatchDelegate(org.onosproject.workflow.api.WorkflowBatchDelegate) Executors.newFixedThreadPool(java.util.concurrent.Executors.newFixedThreadPool) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) WorkflowDataEvent(org.onosproject.workflow.api.WorkflowDataEvent) SystemWorkflowContext(org.onosproject.workflow.api.SystemWorkflowContext) WorkplaceStore(org.onosproject.workflow.api.WorkplaceStore) TimerChain(org.onosproject.workflow.api.TimerChain) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) CheckCondition.check(org.onosproject.workflow.api.CheckCondition.check) Reference(org.osgi.service.component.annotations.Reference) LeadershipService(org.onosproject.cluster.LeadershipService) WorkflowData(org.onosproject.workflow.api.WorkflowData)

Example 2 with EventTask

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);
        }
    }
}
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)2 EventTask (org.onosproject.workflow.api.EventTask)2 ProgramCounter (org.onosproject.workflow.api.ProgramCounter)2 SystemWorkflowContext (org.onosproject.workflow.api.SystemWorkflowContext)2 JsonNodeFactory (com.fasterxml.jackson.databind.node.JsonNodeFactory)1 Collection (java.util.Collection)1 List (java.util.List)1 Objects (java.util.Objects)1 Set (java.util.Set)1 UUID (java.util.UUID)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ExecutorService (java.util.concurrent.ExecutorService)1 Executors.newFixedThreadPool (java.util.concurrent.Executors.newFixedThreadPool)1 Executors.newSingleThreadExecutor (java.util.concurrent.Executors.newSingleThreadExecutor)1 Executors.newSingleThreadScheduledExecutor (java.util.concurrent.Executors.newSingleThreadScheduledExecutor)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 Collectors (java.util.stream.Collectors)1 Tools.groupedThreads (org.onlab.util.Tools.groupedThreads)1 ClusterService (org.onosproject.cluster.ClusterService)1 LeadershipService (org.onosproject.cluster.LeadershipService)1