jaegonkim | dcf7c82 | 2019-02-06 15:00:14 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019-present Open Networking Foundation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.onosproject.ofoverlay.impl; |
| 17 | |
| 18 | import org.onosproject.net.device.DeviceService; |
| 19 | import org.onosproject.workflow.api.ImmutableListWorkflow; |
| 20 | import org.onosproject.workflow.api.Workflow; |
| 21 | import org.onosproject.workflow.api.WorkflowExecutionService; |
| 22 | import org.onosproject.workflow.api.WorkflowStore; |
| 23 | import org.onosproject.workflow.api.WorkplaceStore; |
| 24 | import org.osgi.service.component.annotations.Activate; |
| 25 | import org.osgi.service.component.annotations.Component; |
| 26 | import org.osgi.service.component.annotations.Deactivate; |
| 27 | import org.osgi.service.component.annotations.Reference; |
| 28 | import org.osgi.service.component.annotations.ReferenceCardinality; |
| 29 | import org.slf4j.Logger; |
| 30 | import org.slf4j.LoggerFactory; |
| 31 | |
| 32 | import java.net.URI; |
| 33 | import java.util.concurrent.ScheduledExecutorService; |
| 34 | |
| 35 | import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor; |
| 36 | import static org.onlab.util.Tools.groupedThreads; |
| 37 | |
| 38 | /** |
| 39 | * Class for Open-flow overlay configuration workflow. |
| 40 | */ |
| 41 | @Component(immediate = true) |
| 42 | public class OfOverlayWorkflow { |
| 43 | |
| 44 | private static final Logger log = LoggerFactory.getLogger(OfOverlayWorkflow.class); |
| 45 | |
| 46 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
| 47 | protected WorkflowStore workflowStore; |
| 48 | |
| 49 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
| 50 | protected WorkplaceStore workplaceStore; |
| 51 | |
| 52 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
| 53 | protected WorkflowExecutionService workflowExecutionService; |
| 54 | |
| 55 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
| 56 | protected DeviceService deviceService; |
| 57 | |
| 58 | private ScheduledExecutorService eventMapTriggerExecutor; |
| 59 | |
| 60 | @Activate |
| 61 | public void activate() { |
| 62 | log.info("Activated"); |
| 63 | |
| 64 | eventMapTriggerExecutor = newSingleThreadScheduledExecutor( |
| 65 | groupedThreads("onos/of-overlay", "eventmap-trigger-executor")); |
| 66 | |
| 67 | registerWorkflows(); |
| 68 | |
| 69 | } |
| 70 | |
| 71 | @Deactivate |
| 72 | public void deactivate() { |
| 73 | log.info("Deactivated"); |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Registers workflows. |
| 78 | */ |
| 79 | private void registerWorkflows() { |
| 80 | // registering class-loader |
| 81 | workflowStore.registerLocal(this.getClass().getClassLoader()); |
| 82 | |
| 83 | // registering new workflow definition |
| 84 | URI uri = URI.create("of-overlay.workflow-nova"); |
| 85 | Workflow workflow = ImmutableListWorkflow.builder() |
| 86 | .id(uri) |
| 87 | //.attribute(WorkflowAttribute.REMOVE_AFTER_COMPLETE) |
| 88 | .chain(Ovs.CreateOvsdbDevice.class.getName()) |
| 89 | .chain(Ovs.UpdateOvsVersion.class.getName()) |
| 90 | .chain(Ovs.UpdateOverlayBridgeId.class.getName()) |
| 91 | .chain(Ovs.CreateOverlayBridge.class.getName()) |
| 92 | .chain(Ovs.UpdateUnderlayBridgeId.class.getName()) |
| 93 | .chain(Ovs.CreateUnderlayBridge.class.getName()) |
| 94 | .chain(Ovs.CreateOverlayBridgeVxlanPort.class.getName()) |
| 95 | .chain(Ovs.AddPhysicalPortsOnUnderlayBridge.class.getName()) |
| 96 | .chain(Ovs.ConfigureUnderlayBridgeLocalIp.class.getName()) |
| 97 | .build(); |
| 98 | workflowStore.register(workflow); |
| 99 | |
nitinanand | 2a5c8fd | 2019-03-20 10:26:08 +0530 | [diff] [blame^] | 100 | // registering new workflow definition based on multi-event handling |
| 101 | uri = URI.create("of-overlay.workflow-nova-multiEvent-test"); |
| 102 | workflow = ImmutableListWorkflow.builder() |
| 103 | .id(uri) |
| 104 | //.attribute(WorkflowAttribute.REMOVE_AFTER_COMPLETE) |
| 105 | .chain(Ovs.CreateOvsdbDevice.class.getName()) |
| 106 | .chain(Ovs.UpdateOvsVersion.class.getName()) |
| 107 | .chain(Ovs.UpdateOverlayBridgeId.class.getName()) |
| 108 | .chain(Ovs.CreateOverlayBridgeMultiEvent.class.getName()) |
| 109 | .chain(Ovs.UpdateUnderlayBridgeId.class.getName()) |
| 110 | .chain(Ovs.CreateUnderlayBridge.class.getName()) |
| 111 | .chain(Ovs.CreateOverlayBridgeVxlanPort.class.getName()) |
| 112 | .chain(Ovs.AddPhysicalPortsOnUnderlayBridge.class.getName()) |
| 113 | .chain(Ovs.ConfigureUnderlayBridgeLocalIp.class.getName()) |
| 114 | .build(); |
| 115 | workflowStore.register(workflow); |
| 116 | |
jaegonkim | dcf7c82 | 2019-02-06 15:00:14 +0900 | [diff] [blame] | 117 | uri = URI.create("of-overlay.clean-workflow-nova"); |
| 118 | workflow = ImmutableListWorkflow.builder() |
| 119 | .id(uri) |
| 120 | //.attribute(WorkflowAttribute.REMOVE_AFTER_COMPLETE) |
| 121 | .chain(Ovs.DeleteOverlayBridgeConfig.class.getName()) |
| 122 | .chain(Ovs.RemoveOverlayBridgeOfDevice.class.getName()) |
| 123 | .chain(Ovs.DeleteUnderlayBridgeConfig.class.getName()) |
| 124 | .chain(Ovs.RemoveUnderlayBridgeOfDevice.class.getName()) |
| 125 | .chain(Ovs.RemoveOvsdbDevice.class.getName()) |
| 126 | .build(); |
| 127 | workflowStore.register(workflow); |
| 128 | |
| 129 | uri = URI.create("of-overlay.workflow-ovs-leaf"); |
| 130 | workflow = ImmutableListWorkflow.builder() |
| 131 | .id(uri) |
| 132 | .chain(Ovs.CreateOvsdbDevice.class.getName()) |
| 133 | .chain(Ovs.UpdateOvsVersion.class.getName()) |
| 134 | .chain(Ovs.UpdateUnderlayBridgeId.class.getName()) |
| 135 | .chain(Ovs.CreateUnderlayBridge.class.getName()) |
| 136 | .chain(Ovs.AddPhysicalPortsOnUnderlayBridge.class.getName()) |
| 137 | .build(); |
| 138 | workflowStore.register(workflow); |
| 139 | |
| 140 | uri = URI.create("of-overlay.workflow-ovs-spine"); |
| 141 | workflow = ImmutableListWorkflow.builder() |
| 142 | .id(uri) |
| 143 | .chain(Ovs.CreateOvsdbDevice.class.getName()) |
| 144 | .chain(Ovs.UpdateOvsVersion.class.getName()) |
| 145 | .chain(Ovs.UpdateUnderlayBridgeId.class.getName()) |
| 146 | .chain(Ovs.CreateUnderlayBridge.class.getName()) |
| 147 | .chain(Ovs.AddPhysicalPortsOnUnderlayBridge.class.getName()) |
| 148 | .build(); |
| 149 | workflowStore.register(workflow); |
| 150 | |
| 151 | deviceService.addListener( |
| 152 | event -> { |
| 153 | // trigger EventTask for DeviceEvent |
| 154 | eventMapTriggerExecutor.submit( |
| 155 | () -> workflowExecutionService.eventMapTrigger( |
| 156 | event, |
| 157 | // event hint supplier |
| 158 | (ev) -> { |
| 159 | if (ev == null || ev.subject() == null) { |
| 160 | return null; |
| 161 | } |
| 162 | String hint = event.subject().id().toString(); |
| 163 | log.debug("hint: {}", hint); |
| 164 | return hint; |
| 165 | } |
| 166 | ) |
| 167 | ); |
| 168 | } |
| 169 | ); |
| 170 | |
| 171 | } |
| 172 | |
| 173 | } |