added translation of augments to AddrEpWithLocation 35/39635/2
authorMatej Perina <matej.perina@pantheon.sk>
Tue, 31 May 2016 09:50:59 +0000 (11:50 +0200)
committerMartin Sunal <msunal@cisco.com>
Tue, 31 May 2016 11:51:00 +0000 (11:51 +0000)
Change-Id: I8db75b2fa7b0f68160dc9d32d0844a91bd91f3c5
Signed-off-by: Matej Perina <matej.perina@pantheon.sk>
groupbasedpolicy/src/main/java/org/opendaylight/controller/config/yang/config/groupbasedpolicy/DomainSpecificRegistryModule.java
groupbasedpolicy/src/main/java/org/opendaylight/groupbasedpolicy/forwarding/NetworkDomainAugmentorRegistryImpl.java
groupbasedpolicy/src/main/java/org/opendaylight/groupbasedpolicy/renderer/RendererConfigurationBuilder.java
groupbasedpolicy/src/main/java/org/opendaylight/groupbasedpolicy/renderer/RendererManager.java
groupbasedpolicy/src/test/java/org/opendaylight/groupbasedpolicy/renderer/RendererManagerDataBrokerTest.java
groupbasedpolicy/src/test/java/org/opendaylight/groupbasedpolicy/renderer/RendererManagerTest.java

index b237883b130a88c4813d17c1c631b8be871e2bac..aed35222d879e73b715cb21fb64e603ce03f2e01 100644 (file)
@@ -57,7 +57,7 @@ public class DomainSpecificRegistryModule extends org.opendaylight.controller.co
             endpointAugmentorRegistryImpl = new EndpointAugmentorRegistryImpl();
             netDomainAugmentorRegistryImpl = new NetworkDomainAugmentorRegistryImpl();
             baseEndpointServiceImpl = new BaseEndpointServiceImpl(dataProvider, rpcRegistry, endpointAugmentorRegistryImpl);
-            rendererManager = new RendererManager(dataProvider, netDomainAugmentorRegistryImpl);
+            rendererManager = new RendererManager(dataProvider, netDomainAugmentorRegistryImpl, endpointAugmentorRegistryImpl);
         }
 
         @Override
index 9c9cf04a4d68c9e7bc1c9ed986310f4e8b5a11ba..5e38d7e99d14a31b82a89e83cc1ba8ee03e0642c 100644 (file)
@@ -36,7 +36,7 @@ public class NetworkDomainAugmentorRegistryImpl implements NetworkDomainAugmento
         }
     }
 
-    public Set<NetworkDomainAugmentor> getEndpointAugmentors() {
+    public Set<NetworkDomainAugmentor> getNetworkDomainAugmentors() {
         return augmentors;
     }
 
index f23160eeb864877a6d8141fbf4e29044b0f5cf95..33908b4b1422bb399939d032d11f0ca1e73dcadd 100644 (file)
@@ -20,6 +20,7 @@ import java.util.Set;
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 
+import org.opendaylight.groupbasedpolicy.api.EndpointAugmentor;
 import org.opendaylight.groupbasedpolicy.api.NetworkDomainAugmentor;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.endpoint.locations.AddressEndpointLocation;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.endpoint.locations.ContainmentEndpointLocation;
@@ -271,11 +272,11 @@ public class RendererConfigurationBuilder {
     }
 
     public Endpoints buildEndoints(EndpointInfo epInfo, EndpointLocationInfo epLocInfo,
-            Map<InstanceIdentifier<?>, RendererName> rendererByNode) {
+            Map<InstanceIdentifier<?>, RendererName> rendererByNode, Set<EndpointAugmentor> augmentors) {
         List<AddressEndpointWithLocation> epsWithLoc =
-                resolveEpsWithLoc(getAddressEndpointKeys(), epInfo, epLocInfo, rendererByNode);
+                resolveEpsWithLoc(getAddressEndpointKeys(), epInfo, epLocInfo, rendererByNode, augmentors);
         List<ContainmentEndpointWithLocation> contEpsWithLoc =
-                resolveContEpsWithLoc(getContainmentEndpointKeys(), epInfo, epLocInfo);
+                resolveContEpsWithLoc(getContainmentEndpointKeys(), epInfo, epLocInfo, augmentors);
         return new EndpointsBuilder().setAddressEndpointWithLocation(epsWithLoc)
             .setContainmentEndpointWithLocation(contEpsWithLoc)
             .build();
@@ -283,7 +284,7 @@ public class RendererConfigurationBuilder {
 
     private static List<AddressEndpointWithLocation> resolveEpsWithLoc(Set<AddressEndpointKey> epKeys,
             EndpointInfo epInfo, EndpointLocationInfo epLocInfo,
-            Map<InstanceIdentifier<?>, RendererName> rendererByNode) {
+            Map<InstanceIdentifier<?>, RendererName> rendererByNode, Set<EndpointAugmentor> augmentors) {
         List<AddressEndpointWithLocation> result = new ArrayList<>();
         for (AddressEndpointKey epKey : epKeys) {
             Optional<AddressEndpoint> potentialEp = epInfo.getEndpoint(epKey);
@@ -291,7 +292,7 @@ public class RendererConfigurationBuilder {
             Optional<AddressEndpointLocation> potentionalEpLoc = epLocInfo.getAdressEndpointLocation(epKey);
             Preconditions.checkArgument(potentionalEpLoc.isPresent());
             RendererName rendererName = resolveRendererName(potentionalEpLoc.get(), rendererByNode);
-            result.add(createEpWithLoc(potentialEp.get(), potentionalEpLoc.get(), rendererName));
+            result.add(createEpWithLoc(potentialEp.get(), potentionalEpLoc.get(), rendererName, augmentors));
         }
         return result;
     }
@@ -306,8 +307,9 @@ public class RendererConfigurationBuilder {
     }
 
     private static AddressEndpointWithLocation createEpWithLoc(AddressEndpoint ep, AddressEndpointLocation epLoc,
-            RendererName rendererName) {
-        return new AddressEndpointWithLocationBuilder().setAddress(ep.getAddress())
+            RendererName rendererName, Set<EndpointAugmentor> augmentors) {
+        AddressEndpointWithLocationBuilder addrEpWithLoc = new AddressEndpointWithLocationBuilder()
+            .setAddress(ep.getAddress())
             .setAddressType(ep.getAddressType())
             .setContextId(ep.getContextId())
             .setContextType(ep.getContextType())
@@ -320,12 +322,19 @@ public class RendererConfigurationBuilder {
             .setTimestamp(ep.getTimestamp())
             .setAbsoluteLocation(epLoc.getAbsoluteLocation())
             .setRelativeLocations(epLoc.getRelativeLocations())
-            .setRendererName(rendererName)
-            .build();
+            .setRendererName(rendererName);
+        for (EndpointAugmentor augmentor : augmentors) {
+            Entry<Class<? extends Augmentation<AddressEndpointWithLocation>>, Augmentation<AddressEndpointWithLocation>> addrEpWithLocAug =
+                    augmentor.buildAddressEndpointWithLocationAugmentation(ep);
+            if (addrEpWithLocAug != null) {
+                addrEpWithLoc.addAugmentation(addrEpWithLocAug.getKey(), addrEpWithLocAug.getValue());
+            }
+        }
+        return addrEpWithLoc.build();
     }
 
     private static List<ContainmentEndpointWithLocation> resolveContEpsWithLoc(Set<ContainmentEndpointKey> contEpKeys,
-            EndpointInfo epInfo, EndpointLocationInfo epLocInfo) {
+            EndpointInfo epInfo, EndpointLocationInfo epLocInfo, Set<EndpointAugmentor> augmentors) {
         List<ContainmentEndpointWithLocation> result = new ArrayList<>();
         for (ContainmentEndpointKey contEpKey : contEpKeys) {
             Optional<ContainmentEndpoint> potentialContEp = epInfo.getContainmentEndpoint(contEpKey);
@@ -333,14 +342,15 @@ public class RendererConfigurationBuilder {
             Optional<ContainmentEndpointLocation> potentialContEpLoc =
                     epLocInfo.getContainmentEndpointLocation(contEpKey);
             Preconditions.checkArgument(potentialContEpLoc.isPresent());
-            result.add(createContEpWithLoc(potentialContEp.get(), potentialContEpLoc.get()));
+            result.add(createContEpWithLoc(potentialContEp.get(), potentialContEpLoc.get(), augmentors));
         }
         return result;
     }
 
     private static ContainmentEndpointWithLocation createContEpWithLoc(ContainmentEndpoint contEp,
-            ContainmentEndpointLocation contEpLoc) {
-        return new ContainmentEndpointWithLocationBuilder().setContextId(contEp.getContextId())
+            ContainmentEndpointLocation contEpLoc, Set<EndpointAugmentor> augmentors) {
+        ContainmentEndpointWithLocationBuilder contEpWithLoc = new ContainmentEndpointWithLocationBuilder()
+            .setContextId(contEp.getContextId())
             .setContextType(contEp.getContextType())
             .setTenant(contEp.getTenant())
             .setChildEndpoint(contEp.getChildEndpoint())
@@ -348,8 +358,15 @@ public class RendererConfigurationBuilder {
             .setCondition(contEp.getCondition())
             .setNetworkContainment(contEp.getNetworkContainment())
             .setTimestamp(contEp.getTimestamp())
-            .setRelativeLocations(contEpLoc.getRelativeLocations())
-            .build();
+            .setRelativeLocations(contEpLoc.getRelativeLocations());
+        for (EndpointAugmentor augmentor : augmentors) {
+            Entry<Class<? extends Augmentation<ContainmentEndpointWithLocation>>, Augmentation<ContainmentEndpointWithLocation>> contEpWithLocAug =
+                    augmentor.buildContainmentEndpointWithLocationAugmentation(contEp);
+            if (contEpWithLocAug != null) {
+                contEpWithLoc.addAugmentation(contEpWithLocAug.getKey(), contEpWithLocAug.getValue());
+            }
+        }
+        return contEpWithLoc.build();
     }
 
     public RuleGroups buildRuluGroups(ResolvedPolicyInfo policyInfo) {
index 15116792ce94aefe811b9bc3c65fa1bd4b24c2a0..9f79a90a65ac005cb25300e01e1c8f45aad6f8cc 100644 (file)
@@ -23,6 +23,7 @@ import javax.annotation.Nullable;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.groupbasedpolicy.base_endpoint.EndpointAugmentorRegistryImpl;
 import org.opendaylight.groupbasedpolicy.dto.ConsEpgKey;
 import org.opendaylight.groupbasedpolicy.dto.EpgKeyDto;
 import org.opendaylight.groupbasedpolicy.dto.ProvEpgKey;
@@ -85,6 +86,7 @@ public class RendererManager implements AutoCloseable {
 
     private final DataBroker dataProvider;
     private final NetworkDomainAugmentorRegistryImpl netDomainAugmentorRegistry;
+    private final EndpointAugmentorRegistryImpl epAugmentorRegistry;
     private final Set<RendererName> processingRenderers = new HashSet<>();
     private Map<InstanceIdentifier<?>, RendererName> rendererByNode = new HashMap<>();
     private ResolvedPolicyInfo policyInfo;
@@ -100,9 +102,11 @@ public class RendererManager implements AutoCloseable {
     private final ForwardingListener forwardingListener;
     private final RenderersListener renderersListener;
 
-    public RendererManager(DataBroker dataProvider, NetworkDomainAugmentorRegistryImpl netDomainAugmentorRegistry) {
+    public RendererManager(DataBroker dataProvider, NetworkDomainAugmentorRegistryImpl netDomainAugmentorRegistry,
+            EndpointAugmentorRegistryImpl epAugmentorRegistry) {
         this.dataProvider = checkNotNull(dataProvider);
         this.netDomainAugmentorRegistry = checkNotNull(netDomainAugmentorRegistry);
+        this.epAugmentorRegistry = checkNotNull(epAugmentorRegistry);
         endpointsListener = new EndpointsListener(this, dataProvider);
         endpointLocationsListener = new EndpointLocationsListener(this, dataProvider);
         resolvedPoliciesListener = new ResolvedPoliciesListener(this, dataProvider);
@@ -290,14 +294,14 @@ public class RendererManager implements AutoCloseable {
         configBuilder.setRendererEndpoints(rendererEndpoints);
 
         org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.Endpoints endpoints =
-                rendererPolicyBuilder.buildEndoints(epInfo, epLocInfo, rendererByNode);
+                rendererPolicyBuilder.buildEndoints(epInfo, epLocInfo, rendererByNode, epAugmentorRegistry.getEndpointAugmentors());
         configBuilder.setEndpoints(endpoints);
 
         RuleGroups ruleGroups = rendererPolicyBuilder.buildRuluGroups(policyInfo);
         configBuilder.setRuleGroups(ruleGroups);
 
         RendererForwarding rendererForwarding = rendererPolicyBuilder.buildRendererForwarding(forwarding,
-                netDomainAugmentorRegistry.getEndpointAugmentors());
+                netDomainAugmentorRegistry.getNetworkDomainAugmentors());
         configBuilder.setRendererForwarding(rendererForwarding);
 
         return Optional.of(configBuilder.build());
index 5834cf52217b93cb650ee5d3b73f0b8ac54f340b..c6e209c2e9537d8e2a94ac729e7c257062cbca84 100644 (file)
@@ -23,6 +23,7 @@ import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
+import org.opendaylight.groupbasedpolicy.base_endpoint.EndpointAugmentorRegistryImpl;
 import org.opendaylight.groupbasedpolicy.forwarding.NetworkDomainAugmentorRegistryImpl;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.EndpointLocations;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.EndpointLocationsBuilder;
@@ -97,6 +98,8 @@ public class RendererManagerDataBrokerTest {
     @Mock
     private NetworkDomainAugmentorRegistryImpl netDomainAugmentorRegistry;
     @Mock
+    private EndpointAugmentorRegistryImpl epAugmentorRegistry;
+    @Mock
     private WriteTransaction wTx;
     @Mock
     private CheckedFuture<Void, TransactionCommitFailedException> submitFuture;
@@ -107,8 +110,9 @@ public class RendererManagerDataBrokerTest {
     public void init() {
         Mockito.when(dataProvider.newWriteOnlyTransaction()).thenReturn(wTx);
         Mockito.when(wTx.submit()).thenReturn(submitFuture);
-        Mockito.when(netDomainAugmentorRegistry.getEndpointAugmentors()).thenReturn(Collections.emptySet());
-        rendererManager = new RendererManager(dataProvider, netDomainAugmentorRegistry);
+        Mockito.when(netDomainAugmentorRegistry.getNetworkDomainAugmentors()).thenReturn(Collections.emptySet());
+        Mockito.when(epAugmentorRegistry.getEndpointAugmentors()).thenReturn(Collections.emptySet());
+        rendererManager = new RendererManager(dataProvider, netDomainAugmentorRegistry, epAugmentorRegistry);
         RendererManager.resetVersion();
     }
 
index 0aa8a2574bd150447d0e11b70cdf08fd8da852b7..84973e308ad827d047e7a2d6c026154976100904 100644 (file)
@@ -22,6 +22,7 @@ import org.mockito.Mock;
 import org.mockito.Mockito;
 import org.mockito.runners.MockitoJUnitRunner;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.groupbasedpolicy.base_endpoint.EndpointAugmentorRegistryImpl;
 import org.opendaylight.groupbasedpolicy.forwarding.NetworkDomainAugmentorRegistryImpl;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.EndpointLocations;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.EndpointLocationsBuilder;
@@ -75,13 +76,16 @@ public class RendererManagerTest {
     private DataBroker dataProvider;
     @Mock
     private NetworkDomainAugmentorRegistryImpl netDomainAugmentorRegistry;
+    @Mock
+    private EndpointAugmentorRegistryImpl epAugmentorRegistry;
 
     private RendererManager rendererManager;
 
     @Before
     public void init() {
-        Mockito.when(netDomainAugmentorRegistry.getEndpointAugmentors()).thenReturn(Collections.emptySet());
-        rendererManager = new RendererManager(dataProvider, netDomainAugmentorRegistry);
+        Mockito.when(netDomainAugmentorRegistry.getNetworkDomainAugmentors()).thenReturn(Collections.emptySet());
+        Mockito.when(epAugmentorRegistry.getEndpointAugmentors()).thenReturn(Collections.emptySet());
+        rendererManager = new RendererManager(dataProvider, netDomainAugmentorRegistry, epAugmentorRegistry);
     }
 
     /**