/*
- * Copyright (c) 2016 Inocybe Technologies and others. All rights reserved.
+ * Copyright © 2016, 2017 Inocybe Technologies and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
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.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;
-
+import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
import org.opendaylight.ovsdb.schema.openvswitch.AutoAttach;
import org.opendaylight.ovsdb.schema.openvswitch.Bridge;
+import org.opendaylight.ovsdb.southbound.InstanceIdentifierCodec;
import org.opendaylight.ovsdb.southbound.SouthboundProvider;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeAugmentation;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeRef;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Sets;
-
-public class AutoAttachRemovedCommand extends AbstractTransactCommand {
+public class AutoAttachRemovedCommand implements TransactCommand {
private static final Logger LOG = LoggerFactory.getLogger(AutoAttachRemovedCommand.class);
- public AutoAttachRemovedCommand(BridgeOperationalState state,
- AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> changes) {
- super(state, changes);
+ @Override
+ public void execute(TransactionBuilder transaction, BridgeOperationalState state,
+ Collection<DataTreeModification<Node>> modifications, InstanceIdentifierCodec instanceIdentifierCodec) {
+ execute(transaction, state, TransactUtils.extractOriginal(modifications, OvsdbNodeAugmentation.class),
+ TransactUtils.extractUpdated(modifications, OvsdbNodeAugmentation.class));
}
@Override
- public void execute(TransactionBuilder transaction) {
-
- // FIXME: Remove if loop after ovs community supports external_ids column in AutoAttach Table
- if (true) {
- try {
- throw new UnsupportedOperationException("CRUD operations not supported from ODL for auto_attach column for"
- + " this version of ovsdb schema due to missing external_ids column");
- } catch (UnsupportedOperationException e) {
- LOG.debug(e.getMessage());
- }
- return;
- }
-
- @SuppressWarnings("unused")
- Map<InstanceIdentifier<OvsdbNodeAugmentation>, OvsdbNodeAugmentation> original =
- TransactUtils.extractOriginal(getChanges(), OvsdbNodeAugmentation.class);
+ public void execute(TransactionBuilder transaction, BridgeOperationalState state,
+ AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> events,
+ InstanceIdentifierCodec instanceIdentifierCodec) {
+ execute(transaction, state, TransactUtils.extractOriginal(events, OvsdbNodeAugmentation.class),
+ TransactUtils.extractUpdated(events, OvsdbNodeAugmentation.class));
+ }
- Map<InstanceIdentifier<OvsdbNodeAugmentation>, OvsdbNodeAugmentation> deleted =
- TransactUtils.extractUpdated(getChanges(), OvsdbNodeAugmentation.class);
+ private void execute(TransactionBuilder transaction, BridgeOperationalState state,
+ Map<InstanceIdentifier<OvsdbNodeAugmentation>, OvsdbNodeAugmentation> original,
+ Map<InstanceIdentifier<OvsdbNodeAugmentation>, OvsdbNodeAugmentation> updated) {
- for (Map.Entry<InstanceIdentifier<OvsdbNodeAugmentation>, OvsdbNodeAugmentation> originalEntry : original.entrySet()) {
- InstanceIdentifier<OvsdbNodeAugmentation> ovsdbNodeIid = originalEntry.getKey();
- OvsdbNodeAugmentation ovsdbNodeAugmentation = originalEntry.getValue();
- OvsdbNodeAugmentation deletedOvsdbNodeAugmentation = deleted.get(ovsdbNodeIid);
+ for (final Map.Entry<InstanceIdentifier<OvsdbNodeAugmentation>, OvsdbNodeAugmentation> originalEntry :
+ original.entrySet()) {
+ final InstanceIdentifier<OvsdbNodeAugmentation> ovsdbNodeIid = originalEntry.getKey();
+ final OvsdbNodeAugmentation ovsdbNodeAugmentation = originalEntry.getValue();
+ final OvsdbNodeAugmentation deletedOvsdbNodeAugmentation = updated.get(ovsdbNodeIid);
if (ovsdbNodeAugmentation != null && deletedOvsdbNodeAugmentation != null) {
- List<Autoattach> origAutoattachList = ovsdbNodeAugmentation.getAutoattach();
- List<Autoattach> deletedAutoattachList = deletedOvsdbNodeAugmentation.getAutoattach();
- if(origAutoattachList != null && !origAutoattachList.isEmpty() &&
- (deletedAutoattachList == null || deletedAutoattachList.isEmpty())) {
-
- OvsdbNodeAugmentation currentOvsdbNode =
- getOperationalState().getBridgeNode(ovsdbNodeIid).get().getAugmentation(OvsdbNodeAugmentation.class);
- List<Autoattach> currentAutoAttach = currentOvsdbNode.getAutoattach();
- for (Autoattach origAutoattach : origAutoattachList) {
- Uri autoAttachId = origAutoattach.getAutoattachId();
+ final List<Autoattach> origAutoattachList = ovsdbNodeAugmentation.getAutoattach();
+ final List<Autoattach> deletedAutoattachList = deletedOvsdbNodeAugmentation.getAutoattach();
+ if (origAutoattachList != null && !origAutoattachList.isEmpty()
+ && (deletedAutoattachList == null || deletedAutoattachList.isEmpty())) {
+
+ if (true) {
+ // FIXME: Remove if loop after ovs community supports external_ids column in AutoAttach Table
+ LOG.info("UNSUPPORTED FUNCTIONALITY: Auto Attach related CRUD operations are not supported for"
+ + " this version of OVSDB schema due to missing external_ids column.");
+ return;
+ }
+ final OvsdbNodeAugmentation currentOvsdbNode =
+ state.getBridgeNode(ovsdbNodeIid).get().getAugmentation(OvsdbNodeAugmentation.class);
+ final List<Autoattach> currentAutoAttach = currentOvsdbNode.getAutoattach();
+ for (final Autoattach origAutoattach : origAutoattachList) {
+ final Uri autoAttachId = origAutoattach.getAutoattachId();
deleteAutoAttach(transaction, ovsdbNodeIid, getAutoAttachUuid(currentAutoAttach, autoAttachId));
}
}
Uuid autoattachUuid) {
LOG.debug("Received request to delete Autoattach entry {}", autoattachUuid);
- OvsdbBridgeAugmentation bridgeAugmentation = getBridge(ovsdbNodeIid, autoattachUuid);
+ final OvsdbBridgeAugmentation bridgeAugmentation = getBridge(ovsdbNodeIid, autoattachUuid);
if (autoattachUuid != null && bridgeAugmentation != null) {
- UUID uuid = new UUID(autoattachUuid.getValue());
- AutoAttach autoattach = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), AutoAttach.class, null);
+ final UUID uuid = new UUID(autoattachUuid.getValue());
+ final AutoAttach autoattach =
+ TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), AutoAttach.class, null);
transaction.add(op.delete(autoattach.getSchema())
.where(autoattach.getUuidColumn().getSchema().opEqual(uuid))
.build());
transaction.add(op.comment("AutoAttach: Deleting {} " + uuid
+ " attached to " + bridgeAugmentation.getBridgeName().getValue()));
- Bridge bridge = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(),
+ final Bridge bridge = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(),
Bridge.class,null);
transaction.add(op.mutate(bridge.getSchema())
.addMutation(bridge.getAutoAttachColumn().getSchema(),
- Mutator.DELETE, Sets.newHashSet(uuid))
+ Mutator.DELETE, Collections.singleton(uuid))
.where(bridge.getNameColumn().getSchema()
.opEqual(bridgeAugmentation.getBridgeName().getValue())).build());
private Uuid getAutoAttachUuid(List<Autoattach> currentAutoAttach, Uri autoAttachId) {
if (currentAutoAttach != null && !currentAutoAttach.isEmpty()) {
- for (Autoattach autoAttach : currentAutoAttach) {
+ for (final Autoattach autoAttach : currentAutoAttach) {
if (autoAttach.getAutoattachId().equals(autoAttachId)) {
return autoAttach.getAutoattachUuid();
}
return null;
}
OvsdbBridgeAugmentation bridge = null;
- InstanceIdentifier<Node> nodeIid = key.firstIdentifierOf(Node.class);
+ final InstanceIdentifier<Node> nodeIid = key.firstIdentifierOf(Node.class);
try (ReadOnlyTransaction transaction = SouthboundProvider.getDb().newReadOnlyTransaction()) {
- Optional<Node> nodeOptional = transaction.read(LogicalDatastoreType.OPERATIONAL, nodeIid).get();
+ final Optional<Node> nodeOptional = transaction.read(LogicalDatastoreType.OPERATIONAL, nodeIid).get();
if (nodeOptional.isPresent()) {
- List<ManagedNodeEntry> managedNodes = nodeOptional.get().getAugmentation(OvsdbNodeAugmentation.class).getManagedNodeEntry();
- for (ManagedNodeEntry managedNode : managedNodes) {
- OvsdbBridgeRef ovsdbBridgeRef = managedNode.getBridgeRef();
- InstanceIdentifier<OvsdbBridgeAugmentation> brIid = ovsdbBridgeRef.getValue()
+ final List<ManagedNodeEntry> managedNodes =
+ nodeOptional.get().getAugmentation(OvsdbNodeAugmentation.class).getManagedNodeEntry();
+ for (final ManagedNodeEntry managedNode : managedNodes) {
+ final OvsdbBridgeRef ovsdbBridgeRef = managedNode.getBridgeRef();
+ final InstanceIdentifier<OvsdbBridgeAugmentation> brIid = ovsdbBridgeRef.getValue()
.firstIdentifierOf(Node.class).augmentation(OvsdbBridgeAugmentation.class);
- Optional<OvsdbBridgeAugmentation> optionalBridge = transaction.read(LogicalDatastoreType.OPERATIONAL, brIid).get();
+ final Optional<OvsdbBridgeAugmentation> optionalBridge =
+ transaction.read(LogicalDatastoreType.OPERATIONAL, brIid).get();
bridge = optionalBridge.orNull();
- if(bridge != null && bridge.getAutoAttach() != null
+ if (bridge != null && bridge.getAutoAttach() != null
&& bridge.getAutoAttach().equals(aaUuid)) {
return bridge;
}