package org.opendaylight.ovsdb.hwvtepsouthbound.transact;
+import static org.opendaylight.ovsdb.lib.operations.Operations.op;
+
import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
import org.opendaylight.controller.md.sal.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.hardwarevtep.Global;
+import org.opendaylight.ovsdb.schema.hardwarevtep.PhysicalSwitch;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.PhysicalSwitchAugmentation;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.google.common.base.Optional;
+import com.google.common.collect.Sets;
+
public class PhysicalSwitchRemoveCommand extends AbstractTransactCommand {
private static final Logger LOG = LoggerFactory.getLogger(PhysicalSwitchRemoveCommand.class);
@Override
public void execute(TransactionBuilder transaction) {
- //TODO
+ Map<InstanceIdentifier<Node>, PhysicalSwitchAugmentation> removeds =
+ extractRemoved(getChanges(),PhysicalSwitchAugmentation.class);
+ if (!removeds.isEmpty()) {
+ for (Entry<InstanceIdentifier<Node>, PhysicalSwitchAugmentation> removed:
+ removeds.entrySet()) {
+ removePhysicalSwitch(transaction, removed.getKey(), removed.getValue());
+ }
+ }
}
+ private void removePhysicalSwitch(TransactionBuilder transaction,
+ InstanceIdentifier<Node> iid, PhysicalSwitchAugmentation physicalSwitchAugmentation) {
+ LOG.debug("Removing a physical switch named: {}", physicalSwitchAugmentation.getHwvtepNodeName().getValue());
+ Optional<PhysicalSwitchAugmentation> operationalPhysicalSwitchOptional =
+ getOperationalState().getPhysicalSwitchAugmentation(iid);
+ PhysicalSwitch physicalSwitch = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), PhysicalSwitch.class, null);
+ if (operationalPhysicalSwitchOptional.isPresent() &&
+ operationalPhysicalSwitchOptional.get().getPhysicalSwitchUuid() != null) {
+ UUID physicalSwitchUuid = new UUID(operationalPhysicalSwitchOptional.get().getPhysicalSwitchUuid().getValue());
+ Global global = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(),
+ Global.class, null);
+ transaction.add(op.delete(physicalSwitch.getSchema())
+ .where(physicalSwitch.getUuidColumn().getSchema().opEqual(physicalSwitchUuid)).build());
+ transaction.add(op.comment("Physical Switch: Deleting " + physicalSwitchAugmentation.getHwvtepNodeName().getValue()));
+ transaction.add(op.mutate(global.getSchema())
+ .addMutation(global.getSwitchesColumn().getSchema(), Mutator.DELETE,
+ Sets.newHashSet(physicalSwitchUuid)));
+ transaction.add(op.comment("Global: Mutating " + physicalSwitchAugmentation.getHwvtepNodeName().getValue() + " " + physicalSwitchUuid));
+ } else {
+ LOG.warn("Unable to delete physical switch {} because it was not found in the operational store",
+ physicalSwitchAugmentation.getHwvtepNodeName().getValue());
+ }
+ }
+
+ private Map<InstanceIdentifier<Node>, PhysicalSwitchAugmentation> extractRemoved(
+ Collection<DataTreeModification<Node>> changes, Class<PhysicalSwitchAugmentation> class1) {
+ Map<InstanceIdentifier<Node>, PhysicalSwitchAugmentation> result
+ = new HashMap<InstanceIdentifier<Node>, PhysicalSwitchAugmentation>();
+ if (changes != null && !changes.isEmpty()) {
+ for (DataTreeModification<Node> change : changes) {
+ final InstanceIdentifier<Node> key = change.getRootPath().getRootIdentifier();
+ final DataObjectModification<Node> mod = change.getRootNode();
+ Node removed = TransactUtils.getRemoved(mod);
+ if (removed != null) {
+ PhysicalSwitchAugmentation physicalSwitch = removed.getAugmentation(PhysicalSwitchAugmentation.class);
+ if (physicalSwitch != null) {
+ result.put(key, physicalSwitch);
+ }
+ }
+ }
+ }
+ return result;
+ }
}
"time": 1447909152443,
"preRequestScript": "",
"tests": "",
- "rawModeData": "{\n \"network-topology:node\": [\n {\n \"node-id\": \"hwvtep://{{hwvtepNodeIp}}:6640/physicalswitch/ps0\",\n \"hwvtep-node-name\": \"ps0\",\n \"hwvtep-node-description\": \"\",\n \"management-ips\": [\n {\n \"management-ips-key\": \"{{managementIp}}\"\n }\n ],\n \"tunnel-ips\": [\n {\n \"tunnel-ips-key\": \"{{tunnleIp}}\"\n }\n ],\n \"managed-by\": \"/network-topology:network-topology/network-topology:topology[network-topology:topology-id='hwvtep:1']/network-topology:node[network-topology:node-id='hwvtep://{{hwvtepNodeIp}}:6640']\" \n }\n ]\n}"
+ "rawModeData": "{\n \"network-topology:node\": [\n {\n \"node-id\": \"hwvtep://{{hwvtepNodeIp}}:6640/physicalswitch/br0\",\n \"hwvtep-node-name\": \"br0\",\n \"hwvtep-node-description\": \"\",\n \"management-ips\": [\n {\n \"management-ips-key\": \"{{managementIp}}\"\n }\n ],\n \"tunnel-ips\": [\n {\n \"tunnel-ips-key\": \"{{tunnelIp}}\"\n }\n ],\n \"managed-by\": \"/network-topology:network-topology/network-topology:topology[network-topology:topology-id='hwvtep:1']/network-topology:node[network-topology:node-id='hwvtep://{{hwvtepNodeIp}}:6640']\" \n }\n ]\n}"
},
{
"collectionId": "19f6b1a8-4d54-62f8-6bd6-f52e0b6e40b8",
"id": "e25f67e4-3a3f-5da7-f7c8-41b371156719",
"headers": "Authorization: Basic YWRtaW46YWRtaW4=\nContent-Type: application/json\n",
- "url": "http://{{controllerHost}}:8181/restconf/config/network-topology:network-topology/topology/hwvtep:1/node/hwvtep:%2F%2F{{hwvtepNodeIp}}:6640%phsicalswitch%2Fps0",
+ "url": "http://{{controllerHost}}:8181/restconf/config/network-topology:network-topology/topology/hwvtep:1/node/hwvtep:%2F%2F{{hwvtepNodeIp}}:6640%2Fphysicalswitch%2Fbr0",
"preRequestScript": "",
"pathVariables": {},
"method": "PUT",
"time": 1448552632013,
"name": "Update Specific Config Physical Switch",
"description": "Fire this Restconf request if you want to update a exsiting physical switch.",
- "rawModeData": "{\n \"network-topology:node\": [\n {\n \"node-id\": \"hwvtep://{{hwvtepNodeIp}}:6640/physicalswitch/ps0\",\n \"hwvtep-node-name\": \"ps0\",\n \"hwvtep-node-description\": \"\",\n \"management-ips\": [\n {\n \"management-ips-key\": \"{{managementIp}}\"\n }\n ],\n \"tunnel-ips\": [\n {\n \"tunnel-ips-key\": \"{{tunnleIp}}\"\n }\n ],\n \"managed-by\": \"/network-topology:network-topology/network-topology:topology[network-topology:topology-id='hwvtep:1']/network-topology:node[network-topology:node-id='hwvtep://{{hwvtepNodeIp}}:6640']\" \n }\n ]\n}"
+ "rawModeData": "{\n \"network-topology:node\": [\n {\n \"node-id\": \"hwvtep://{{hwvtepNodeIp}}:6640/physicalswitch/br0\",\n \"hwvtep-node-name\": \"br0\",\n \"hwvtep-node-description\": \"\",\n \"management-ips\": [\n {\n \"management-ips-key\": \"{{managementIp}}\"\n }\n ],\n \"tunnel-ips\": [\n {\n \"tunnel-ips-key\": \"{{tunnelIp}}\"\n }\n ],\n \"managed-by\": \"/network-topology:network-topology/network-topology:topology[network-topology:topology-id='hwvtep:1']/network-topology:node[network-topology:node-id='hwvtep://{{hwvtepNodeIp}}:6640']\" \n }\n ]\n}"
},
{
"collectionId": "19f6b1a8-4d54-62f8-6bd6-f52e0b6e40b8",
"id": "f7d33d50-7c8e-69e2-6d60-5c6155c5d210",
"headers": "Authorization: Basic YWRtaW46YWRtaW4=\nContent-Type: application/json\n",
- "url": "http://{{controllerHost}}:8181/restconf/config/network-topology:network-topology/topology/hwvtep:1/node/hwvtep:%2F%2F{{hwvtepNodeIp}}:6640%phsicalswitch%2Fps0",
+ "url": "http://{{controllerHost}}:8181/restconf/config/network-topology:network-topology/topology/hwvtep:1/node/hwvtep:%2F%2F{{hwvtepNodeIp}}:6640%2Fphysicalswitch%2Fbr0",
"preRequestScript": "",
"pathVariables": {},
"method": "GET",
"collectionId": "19f6b1a8-4d54-62f8-6bd6-f52e0b6e40b8",
"id": "233b5ab5-8177-4416-6912-2477520a0654",
"headers": "Authorization: Basic YWRtaW46YWRtaW4=\nContent-Type: application/json\n",
- "url": "http://{{controllerHost}}:8181/restconf/config/network-topology:network-topology/topology/hwvtep:1/node/hwvtep:%2F%2F{{hwvtepNodeIp}}:6640%phsicalswitch%2Fps0",
+ "url": "http://{{controllerHost}}:8181/restconf/config/network-topology:network-topology/topology/hwvtep:1/node/hwvtep:%2F%2F{{hwvtepNodeIp}}:6640%2Fphysicalswitch%2Fbr0",
"preRequestScript": "",
"pathVariables": {},
"method": "DELETE",
"id": "a13e6877-997e-84e1-c8e8-e83ef5e9a002",
"name": "Get Specific Operational Physical Switch",
"description": "",
- "url": "http://{{controllerHost}}:8181/restconf/operational/network-topology:network-topology/topology/hwvtep:1/node/hwvtep:%2F%2F{{hwvtepNodeIp}}:6640%2Fphysicalswitch%2Fps0",
+ "url": "http://{{controllerHost}}:8181/restconf/operational/network-topology:network-topology/topology/hwvtep:1/node/hwvtep:%2F%2F{{hwvtepNodeIp}}:6640%2Fphysicalswitch%2Fbr0",
"method": "GET",
"headers": "Authorization: Basic YWRtaW46YWRtaW4=\n",
"data": [],