Neutron port removal fixed
[groupbasedpolicy.git] / neutron-mapper / src / main / java / org / opendaylight / groupbasedpolicy / neutron / mapper / NeutronMapper.java
index ece7573cd272c1e04d7555b5294acf9babd63b0d..f5f1939b3f1bdaa92e2506a03af862e938f421fb 100644 (file)
@@ -7,22 +7,21 @@
  */
 package org.opendaylight.groupbasedpolicy.neutron.mapper;
 
-import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 import java.util.Set;
 
+import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 
+import org.opendaylight.controller.md.sal.binding.api.ClusteredDataTreeChangeListener;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
 import org.opendaylight.controller.md.sal.binding.api.DataObjectModification.ModificationType;
-import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener;
 import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
 import org.opendaylight.groupbasedpolicy.neutron.mapper.mapping.NeutronAware;
 import org.opendaylight.groupbasedpolicy.neutron.mapper.mapping.NeutronFloatingIpAware;
 import org.opendaylight.groupbasedpolicy.neutron.mapper.mapping.NeutronNetworkAware;
@@ -34,6 +33,7 @@ import org.opendaylight.groupbasedpolicy.neutron.mapper.mapping.rule.NeutronSecu
 import org.opendaylight.groupbasedpolicy.neutron.mapper.util.MappingUtils;
 import org.opendaylight.groupbasedpolicy.neutron.mapper.util.NetworkUtils;
 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.groupbasedpolicy.base_endpoint.rev160427.BaseEndpointService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.EndpointService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev150712.DirectionEgress;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev150712.DirectionIngress;
@@ -65,30 +65,32 @@ import com.google.common.collect.FluentIterable;
 import com.google.common.collect.Iterators;
 import com.google.common.collect.PeekingIterator;
 
-public class NeutronMapper implements DataTreeChangeListener<Neutron>, AutoCloseable {
+public class NeutronMapper implements ClusteredDataTreeChangeListener<Neutron>, AutoCloseable {
+
+    private static final String EXC_MSG_UNKNOWN_MODIFICATION_TYPE_WITHIN_DATA = "Unknown modification type within data ";
 
     private final static SecurityRuleBuilder EIG_INGRESS_IPV4_SEC_RULE_BUILDER = new SecurityRuleBuilder()
-        .setId(new Uuid("19b85ad2-bdfc-11e5-9912-ba0be0483c18"))
+        .setUuid(new Uuid("0a629f80-2408-11e6-b67b-9e71128cae77"))
         .setDirection(DirectionIngress.class)
         .setEthertype(EthertypeV4.class)
         .setSecurityGroupId(MappingUtils.EIG_UUID);
     private final static SecurityRuleBuilder EIG_EGRESS_IPV4_SEC_RULE_BUILDER = new SecurityRuleBuilder()
-        .setId(new Uuid("19b85ad2-bdfc-11e5-9912-ba0be0483c18"))
+        .setUuid(new Uuid("0f1789be-2408-11e6-b67b-9e71128cae77"))
         .setDirection(DirectionEgress.class)
         .setEthertype(EthertypeV4.class)
         .setSecurityGroupId(MappingUtils.EIG_UUID);
     private final static SecurityRuleBuilder EIG_INGRESS_IPV6_SEC_RULE_BUILDER = new SecurityRuleBuilder()
-        .setId(new Uuid("19b85ad2-bdfc-11e5-9912-ba0be0483c18"))
+        .setUuid(new Uuid("139b7f90-2408-11e6-b67b-9e71128cae77"))
         .setDirection(DirectionIngress.class)
         .setEthertype(EthertypeV6.class)
         .setSecurityGroupId(MappingUtils.EIG_UUID);
     private final static SecurityRuleBuilder EIG_EGRESS_IPV6_SEC_RULE_BUILDER = new SecurityRuleBuilder()
-        .setId(new Uuid("19b85ad2-bdfc-11e5-9912-ba0be0483c18"))
+        .setUuid(new Uuid("17517202-2408-11e6-b67b-9e71128cae77"))
         .setDirection(DirectionEgress.class)
         .setEthertype(EthertypeV6.class)
         .setSecurityGroupId(MappingUtils.EIG_UUID);
     private final static SecurityGroupBuilder EIG_SEC_GROUP_BUILDER =
-            new SecurityGroupBuilder().setUuid(MappingUtils.EIG_UUID).setDescription("EXTERNAL_group");
+            new SecurityGroupBuilder().setUuid(MappingUtils.EIG_UUID);
 
     private final NeutronNetworkAware networkAware;
     private final NeutronSecurityGroupAware securityGroupAware;
@@ -102,9 +104,9 @@ public class NeutronMapper implements DataTreeChangeListener<Neutron>, AutoClose
     private Neutron neutronBefore;
     private Neutron neutronAfter;
 
-    public NeutronMapper(DataBroker dataProvider, RpcProviderRegistry rpcProvider) {
-        EndpointService epService = rpcProvider.getRpcService(EndpointService.class);
-        EndpointRegistrator epRegistrator = new EndpointRegistrator(epService);
+    public NeutronMapper(DataBroker dataProvider, EndpointService epService,
+            BaseEndpointService baseEpService) {
+        EndpointRegistrator epRegistrator = new EndpointRegistrator(epService, baseEpService);
         networkAware = new NeutronNetworkAware(dataProvider);
         securityGroupAware = new NeutronSecurityGroupAware(dataProvider);
         securityRuleAware = new NeutronSecurityRuleAware(dataProvider);
@@ -118,7 +120,7 @@ public class NeutronMapper implements DataTreeChangeListener<Neutron>, AutoClose
     }
 
     @Override
-    public void onDataTreeChanged(Collection<DataTreeModification<Neutron>> changes) {
+    public void onDataTreeChanged(@Nonnull Collection<DataTreeModification<Neutron>> changes) {
         for (DataTreeModification<Neutron> change : changes) {
             DataObjectModification<Neutron> neutronModif = change.getRootNode();
             resolveAndSetNeutron(neutronModif);
@@ -162,24 +164,19 @@ public class NeutronMapper implements DataTreeChangeListener<Neutron>, AutoClose
     private <T extends DataObject> void onDataObjectModification(List<DataObjectModification<T>> dataModifs,
             NeutronAware<T> neutronAware) {
         for (DataObjectModification<T> dataModif : dataModifs) {
-            switch (dataModif.getModificationType()) {
-                case DELETE:
-                    neutronAware.onDeleted(dataModif.getDataBefore(), neutronBefore, neutronAfter);
-                    break;
-                case SUBTREE_MODIFIED:
-                    neutronAware.onUpdated(dataModif.getDataBefore(), dataModif.getDataAfter(), neutronBefore,
-                            neutronAfter);
-                    break;
-                case WRITE:
-                    if (dataModif.getDataBefore() == null) {
-                        neutronAware.onCreated(dataModif.getDataAfter(), neutronAfter);
-                    } else {
-                        neutronAware.onUpdated(dataModif.getDataBefore(), dataModif.getDataAfter(), neutronBefore,
-                                neutronAfter);
-                    }
-                    break;
-                default:
-                    throw new IllegalStateException("Unknown modification type within data " + dataModif);
+            final T dataBefore = dataModif.getDataBefore();
+            final T dataAfter = dataModif.getDataAfter();
+            if (dataBefore == null && dataAfter != null) {
+                neutronAware.onCreated(dataAfter, neutronAfter);
+            }
+            else if (dataBefore != null && dataAfter != null) {
+                neutronAware.onUpdated(dataBefore, dataAfter, neutronBefore, neutronAfter);
+            }
+            else if (dataBefore != null) {
+                neutronAware.onDeleted(dataBefore, neutronBefore, neutronAfter);
+            }
+            else {
+                throw new IllegalStateException(EXC_MSG_UNKNOWN_MODIFICATION_TYPE_WITHIN_DATA + dataModif);
             }
         }
     }
@@ -306,7 +303,7 @@ public class NeutronMapper implements DataTreeChangeListener<Neutron>, AutoClose
     }
 
     @Override
-    public void close() throws IOException {
+    public void close() {
         registerDataTreeChangeListener.close();
     }