Bump versions by x.(y+1).z
[ovsdb.git] / southbound / southbound-impl / src / main / java / org / opendaylight / ovsdb / southbound / ovsdb / transact / ControllerUpdateCommand.java
index 736fe4dbc1418c27b3943aabb8fe5a1b6bd1d267..98e62de3c5881ea72c194e4ad81eba0ae4ac94b3 100644 (file)
@@ -9,16 +9,15 @@ package org.opendaylight.ovsdb.southbound.ovsdb.transact;
 
 import static org.opendaylight.ovsdb.lib.operations.Operations.op;
 
-import com.google.common.base.Optional;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Map;
 import java.util.Map.Entry;
-import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
+import java.util.Optional;
+import org.opendaylight.mdsal.binding.api.DataTreeModification;
 import org.opendaylight.ovsdb.lib.notation.Mutator;
 import org.opendaylight.ovsdb.lib.notation.UUID;
 import org.opendaylight.ovsdb.lib.operations.TransactionBuilder;
-import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
 import org.opendaylight.ovsdb.schema.openvswitch.Bridge;
 import org.opendaylight.ovsdb.schema.openvswitch.Controller;
 import org.opendaylight.ovsdb.southbound.InstanceIdentifierCodec;
@@ -34,22 +33,23 @@ public class ControllerUpdateCommand implements TransactCommand {
     private static final Logger LOG = LoggerFactory.getLogger(ControllerUpdateCommand.class);
 
     @Override
-    public void execute(TransactionBuilder transaction, BridgeOperationalState state,
-            DataChangeEvent events, InstanceIdentifierCodec instanceIdentifierCodec) {
+    public void execute(final TransactionBuilder transaction, final BridgeOperationalState state,
+            final DataChangeEvent events, final InstanceIdentifierCodec instanceIdentifierCodec) {
         execute(transaction, state, TransactUtils.extractCreatedOrUpdated(events, ControllerEntry.class),
                 TransactUtils.extractCreatedOrUpdated(events, OvsdbBridgeAugmentation.class));
     }
 
     @Override
-    public void execute(TransactionBuilder transaction, BridgeOperationalState state,
-            Collection<DataTreeModification<Node>> modifications, InstanceIdentifierCodec instanceIdentifierCodec) {
+    public void execute(final TransactionBuilder transaction, final BridgeOperationalState state,
+            final Collection<DataTreeModification<Node>> modifications,
+            final InstanceIdentifierCodec instanceIdentifierCodec) {
         execute(transaction, state, TransactUtils.extractCreatedOrUpdated(modifications, ControllerEntry.class),
                 TransactUtils.extractCreatedOrUpdated(modifications, OvsdbBridgeAugmentation.class));
     }
 
-    private void execute(TransactionBuilder transaction, BridgeOperationalState state,
-                         Map<InstanceIdentifier<ControllerEntry>, ControllerEntry> controllers,
-                         Map<InstanceIdentifier<OvsdbBridgeAugmentation>, OvsdbBridgeAugmentation> bridges) {
+    private static void execute(final TransactionBuilder transaction, final BridgeOperationalState state,
+            final Map<InstanceIdentifier<ControllerEntry>, ControllerEntry> controllers,
+            final Map<InstanceIdentifier<OvsdbBridgeAugmentation>, OvsdbBridgeAugmentation> bridges) {
         LOG.info("Register ODL controllers : {}  bridges detail : {}",
                 controllers, bridges);
         for (Entry<InstanceIdentifier<ControllerEntry>, ControllerEntry> entry: controllers.entrySet()) {
@@ -60,26 +60,27 @@ public class ControllerUpdateCommand implements TransactCommand {
                         entry.getKey().firstIdentifierOf(OvsdbBridgeAugmentation.class);
                 Optional<OvsdbBridgeAugmentation> bridgeOptional =
                         state.getOvsdbBridgeAugmentation(bridgeIid);
-                OvsdbBridgeAugmentation ovsdbBridge = bridgeOptional.or(bridges.get(bridgeIid));
+                OvsdbBridgeAugmentation ovsdbBridge = bridgeOptional.isPresent()
+                    ? bridgeOptional.orElseThrow() : bridges.get(bridgeIid);
                 if (ovsdbBridge != null
                         && ovsdbBridge.getBridgeName() != null
                         && entry.getValue() != null
                         && entry.getValue().getTarget() != null) {
                     ControllerEntry controllerEntry = entry.getValue();
-                    Controller controller =
-                            TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), Controller.class);
+                    Controller controller = transaction.getTypedRowWrapper(Controller.class);
                     controller.setTarget(controllerEntry.getTarget().getValue());
                     if (controllerEntry.getMaxBackoff() != null) {
-                        controller.setMaxBackoff(Collections.singleton(controllerEntry.getMaxBackoff()));
+                        controller.setMaxBackoff(Collections.singleton(controllerEntry.getMaxBackoff().toJava()));
                     }
                     if (controllerEntry.getInactivityProbe() != null) {
-                        controller.setInactivityProbe(Collections.singleton(controllerEntry.getInactivityProbe()));
+                        controller.setInactivityProbe(Collections.singleton(
+                            controllerEntry.getInactivityProbe().toJava()));
                     }
                     String controllerNamedUuidString = SouthboundMapper.getRandomUuid();
                     UUID controllerNamedUuid = new UUID(controllerNamedUuidString);
                     transaction.add(op.insert(controller).withId(controllerNamedUuidString));
 
-                    Bridge bridge = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), Bridge.class);
+                    Bridge bridge = transaction.getTypedRowWrapper(Bridge.class);
                     bridge.setName(ovsdbBridge.getBridgeName().getValue());
                     bridge.setController(Collections.singleton(controllerNamedUuid));
                     LOG.trace("Added controller : {} for bridge : {}",
@@ -95,5 +96,4 @@ public class ControllerUpdateCommand implements TransactCommand {
         LOG.trace("Executed transaction: {}", transaction.build());
 
     }
-
 }