ios-xe now uses sgt augments 27/39927/4
authorMatej Perina <matej.perina@pantheon.sk>
Tue, 7 Jun 2016 09:14:08 +0000 (11:14 +0200)
committerMatej Perina <matej.perina@pantheon.sk>
Fri, 17 Jun 2016 09:23:21 +0000 (09:23 +0000)
Change-Id: I849fd57fea053afc5d35c89dcdd973229239162b
Signed-off-by: Matej Perina <matej.perina@pantheon.sk>
renderers/ios-xe/src/main/java/org/opendaylight/groupbasedpolicy/renderer/ios_xe_provider/impl/IosXeRendererProviderImpl.java
renderers/ios-xe/src/main/java/org/opendaylight/groupbasedpolicy/renderer/ios_xe_provider/impl/cache/EpPolicyCacheImpl.java [deleted file]
renderers/ios-xe/src/main/java/org/opendaylight/groupbasedpolicy/renderer/ios_xe_provider/impl/cache/EpPolicyTemplateCacheKey.java [deleted file]
renderers/ios-xe/src/main/java/org/opendaylight/groupbasedpolicy/renderer/ios_xe_provider/impl/cache/EpPolicyTemplateCacheKeyFactory.java [deleted file]
renderers/ios-xe/src/main/java/org/opendaylight/groupbasedpolicy/renderer/ios_xe_provider/impl/listener/EpPolicyTemplateBySgtListenerImpl.java [deleted file]
renderers/ios-xe/src/main/java/org/opendaylight/groupbasedpolicy/renderer/ios_xe_provider/impl/manager/PolicyManagerImpl.java
renderers/ios-xe/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ios_xe_provider/impl/cache/EpPolicyCacheImplTest.java [deleted file]
renderers/ios-xe/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ios_xe_provider/impl/listener/EpPolicyTemplateBySgtListenerImplTest.java [deleted file]

index d6e5ad4f8e53cba70d590cc0fb889560f7619530..59acd1498d190518567c8c03a84963438a6e15b3 100644 (file)
@@ -18,8 +18,6 @@ import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
 import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
 import org.opendaylight.groupbasedpolicy.renderer.ios_xe_provider.api.IosXeRendererProvider;
 import org.opendaylight.groupbasedpolicy.renderer.ios_xe_provider.api.manager.PolicyManager;
-import org.opendaylight.groupbasedpolicy.renderer.ios_xe_provider.impl.cache.EpPolicyCacheImpl;
-import org.opendaylight.groupbasedpolicy.renderer.ios_xe_provider.impl.listener.EpPolicyTemplateBySgtListenerImpl;
 import org.opendaylight.groupbasedpolicy.renderer.ios_xe_provider.impl.listener.IosXeCapableNodeListenerImpl;
 import org.opendaylight.groupbasedpolicy.renderer.ios_xe_provider.impl.listener.RendererConfigurationListenerImpl;
 import org.opendaylight.groupbasedpolicy.renderer.ios_xe_provider.impl.manager.NodeManager;
@@ -59,9 +57,7 @@ public class IosXeRendererProviderImpl implements IosXeRendererProvider, Binding
     private final DataBroker dataBroker;
     private final RendererName rendererName;
     private RendererConfigurationListenerImpl rendererConfigurationListener;
-    private EpPolicyTemplateBySgtListenerImpl epPolicyTemplateBySgtListener;
     private IosXeCapableNodeListenerImpl iosXeCapableNodeListener;
-    private EpPolicyCacheImpl epPolicyCache;
     private PolicyManager policyManager;
     private NodeManager nodeManager;
 
@@ -80,15 +76,9 @@ public class IosXeRendererProviderImpl implements IosXeRendererProvider, Binding
         if (rendererConfigurationListener != null) {
             rendererConfigurationListener.close();
         }
-        if (epPolicyTemplateBySgtListener != null) {
-            epPolicyTemplateBySgtListener.close();
-        }
         if (iosXeCapableNodeListener != null) {
             iosXeCapableNodeListener.close();
         }
-        if (epPolicyCache != null) {
-            epPolicyCache.invalidateAll();
-        }
     }
 
     @Override
@@ -97,14 +87,11 @@ public class IosXeRendererProviderImpl implements IosXeRendererProvider, Binding
         //TODO register listeners:
         // node-manager
         nodeManager = new NodeManager(dataBroker, providerContext);
-        // ep-policy-template-by-sgt
-        epPolicyCache = new EpPolicyCacheImpl();
-        epPolicyTemplateBySgtListener = new EpPolicyTemplateBySgtListenerImpl(dataBroker, epPolicyCache);
         // network-topology
         iosXeCapableNodeListener = new IosXeCapableNodeListenerImpl(dataBroker, nodeManager);
 
         // policy-manager and delegates
-        policyManager = new PolicyManagerImpl(dataBroker, epPolicyCache);
+        policyManager = new PolicyManagerImpl(dataBroker);
         final PolicyManager policyManagerZip = new PolicyManagerZipImpl(policyManager);
 
         // renderer-configuration endpoints
diff --git a/renderers/ios-xe/src/main/java/org/opendaylight/groupbasedpolicy/renderer/ios_xe_provider/impl/cache/EpPolicyCacheImpl.java b/renderers/ios-xe/src/main/java/org/opendaylight/groupbasedpolicy/renderer/ios_xe_provider/impl/cache/EpPolicyCacheImpl.java
deleted file mode 100644 (file)
index 8752c04..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (c) 2016 Cisco Systems, Inc. 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,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.groupbasedpolicy.renderer.ios_xe_provider.impl.cache;
-
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-import org.opendaylight.groupbasedpolicy.renderer.ios_xe_provider.api.cache.DSTreeBasedCache;
-import org.opendaylight.groupbasedpolicy.renderer.ios_xe_provider.impl.util.RendererPolicyUtil;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.groupbasedpolicy.sxp.mapper.model.rev160302.sxp.mapper.EndpointPolicyTemplateBySgt;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.sxp.database.rev160308.Sgt;
-
-/**
- * Purpose: cache for {@link EndpointPolicyTemplateBySgt}
- */
-public class EpPolicyCacheImpl implements DSTreeBasedCache<EndpointPolicyTemplateBySgt, EpPolicyTemplateCacheKey, Sgt> {
-
-    private final ConcurrentMap<EpPolicyTemplateCacheKey, Sgt> cache;
-    private final EpPolicyTemplateCacheKeyFactory keyFactory;
-
-    public EpPolicyCacheImpl() {
-        cache = new ConcurrentHashMap<>();
-        keyFactory = new EpPolicyTemplateCacheKeyFactory(RendererPolicyUtil.createEndpointGroupIdOrdering(),
-                RendererPolicyUtil.createConditionNameOrdering());
-    }
-
-    @Override
-    public void invalidate(final EndpointPolicyTemplateBySgt exSource) {
-        cache.remove(keyFactory.createKey(exSource));
-    }
-
-    @Override
-    public void add(final EndpointPolicyTemplateBySgt newSource) {
-        final EpPolicyTemplateCacheKey key = keyFactory.createKey(newSource);
-        cache.put(key, newSource.getSgt());
-    }
-
-    @Override
-    public void update(final EndpointPolicyTemplateBySgt before, final EndpointPolicyTemplateBySgt after) {
-        cache.remove(keyFactory.createKey(before));
-        cache.put(keyFactory.createKey(after), after.getSgt());
-    }
-
-    @Override
-    public Sgt lookupValue(final EpPolicyTemplateCacheKey key) {
-        return cache.get(keyFactory.createKey(key));
-    }
-
-    @Override
-    public void invalidateAll() {
-        cache.clear();
-    }
-}
diff --git a/renderers/ios-xe/src/main/java/org/opendaylight/groupbasedpolicy/renderer/ios_xe_provider/impl/cache/EpPolicyTemplateCacheKey.java b/renderers/ios-xe/src/main/java/org/opendaylight/groupbasedpolicy/renderer/ios_xe_provider/impl/cache/EpPolicyTemplateCacheKey.java
deleted file mode 100644 (file)
index d9a18bb..0000000
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Copyright (c) 2016 Cisco Systems, Inc. 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,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.groupbasedpolicy.renderer.ios_xe_provider.impl.cache;
-
-import java.util.List;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ConditionName;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.EndpointGroupId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.endpoints.AddressEndpointWithLocation;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.groupbasedpolicy.sxp.mapper.model.rev160302.sxp.mapper.EndpointPolicyTemplateBySgt;
-
-/**
- * Purpose: composite key holcer for {@link EndpointPolicyTemplateBySgt}
- */
-public class EpPolicyTemplateCacheKey {
-
-    private final TenantId tenantId;
-    private final List<EndpointGroupId> epgId;
-    private final List<ConditionName> conditionName;
-
-    public EpPolicyTemplateCacheKey(final TenantId tenantId, final List<EndpointGroupId> epgId, final List<ConditionName> conditionName) {
-        this.tenantId = tenantId;
-        this.epgId = epgId;
-        this.conditionName = conditionName;
-    }
-
-    public EpPolicyTemplateCacheKey(AddressEndpointWithLocation endpoint) {
-        this(endpoint.getTenant(), endpoint.getEndpointGroup(), endpoint.getCondition());
-    }
-
-    public TenantId getTenantId() {
-        return tenantId;
-    }
-
-    public List<EndpointGroupId> getEpgId() {
-        return epgId;
-    }
-
-    public List<ConditionName> getConditionName() {
-        return conditionName;
-    }
-
-    @Override
-    public boolean equals(final Object o) {
-        if (this == o) return true;
-        if (o == null || getClass() != o.getClass()) return false;
-
-        final EpPolicyTemplateCacheKey that = (EpPolicyTemplateCacheKey) o;
-
-        if (tenantId != null ? !tenantId.equals(that.tenantId) : that.tenantId != null) return false;
-        if (epgId != null ? !epgId.equals(that.epgId) : that.epgId != null) return false;
-        return conditionName != null ? conditionName.equals(that.conditionName) : that.conditionName == null;
-
-    }
-
-    @Override
-    public int hashCode() {
-        return tenantId != null ? tenantId.hashCode() : 0;
-    }
-}
diff --git a/renderers/ios-xe/src/main/java/org/opendaylight/groupbasedpolicy/renderer/ios_xe_provider/impl/cache/EpPolicyTemplateCacheKeyFactory.java b/renderers/ios-xe/src/main/java/org/opendaylight/groupbasedpolicy/renderer/ios_xe_provider/impl/cache/EpPolicyTemplateCacheKeyFactory.java
deleted file mode 100644 (file)
index 2bffb36..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright (c) 2016 Cisco Systems, Inc. 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,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.groupbasedpolicy.renderer.ios_xe_provider.impl.cache;
-
-import com.google.common.collect.Ordering;
-import java.util.Collections;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ConditionName;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.EndpointGroupId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.groupbasedpolicy.sxp.mapper.model.rev160302.sxp.mapper.EndpointPolicyTemplateBySgt;
-
-/**
- * Purpose: create cache keys with ordered lists inside
- */
-public class EpPolicyTemplateCacheKeyFactory {
-    private final Ordering<EndpointGroupId> epgIdOrdering;
-    private final Ordering<ConditionName> conditionOrdering;
-
-    public EpPolicyTemplateCacheKeyFactory(final Ordering<EndpointGroupId> epgIdOrdering,
-                                           final Ordering<ConditionName> conditionOrdering) {
-        this.epgIdOrdering = epgIdOrdering;
-        this.conditionOrdering = conditionOrdering;
-    }
-
-    public EpPolicyTemplateCacheKey createKey(final EndpointPolicyTemplateBySgt newSource) {
-        Collections.sort(newSource.getEndpointGroups(), epgIdOrdering);
-        Collections.sort(newSource.getConditions(), conditionOrdering);
-
-        return new EpPolicyTemplateCacheKey(
-                newSource.getTenant(), newSource.getEndpointGroups(), newSource.getConditions());
-    }
-
-    public EpPolicyTemplateCacheKey createKey(final EpPolicyTemplateCacheKey existingKey) {
-        Collections.sort(existingKey.getEpgId(), epgIdOrdering);
-        Collections.sort(existingKey.getConditionName(), conditionOrdering);
-        return existingKey;
-    }
-}
diff --git a/renderers/ios-xe/src/main/java/org/opendaylight/groupbasedpolicy/renderer/ios_xe_provider/impl/listener/EpPolicyTemplateBySgtListenerImpl.java b/renderers/ios-xe/src/main/java/org/opendaylight/groupbasedpolicy/renderer/ios_xe_provider/impl/listener/EpPolicyTemplateBySgtListenerImpl.java
deleted file mode 100644 (file)
index 26aa107..0000000
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Copyright (c) 2016 Cisco Systems, Inc. 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,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.groupbasedpolicy.renderer.ios_xe_provider.impl.listener;
-
-import com.google.common.base.Preconditions;
-import java.util.Collection;
-import javax.annotation.Nonnull;
-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.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.groupbasedpolicy.renderer.ios_xe_provider.api.cache.DSTreeBasedCache;
-import org.opendaylight.groupbasedpolicy.renderer.ios_xe_provider.impl.cache.EpPolicyTemplateCacheKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.groupbasedpolicy.sxp.mapper.model.rev160302.SxpMapper;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.groupbasedpolicy.sxp.mapper.model.rev160302.sxp.mapper.EndpointPolicyTemplateBySgt;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.sxp.database.rev160308.Sgt;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Purpose: listen to {@link EndpointPolicyTemplateBySgt} changes for caching purposes
- */
-public class EpPolicyTemplateBySgtListenerImpl implements DataTreeChangeListener<EndpointPolicyTemplateBySgt>, AutoCloseable {
-
-    private static final Logger LOG = LoggerFactory.getLogger(EpPolicyTemplateBySgtListenerImpl.class);
-
-    private final ListenerRegistration<EpPolicyTemplateBySgtListenerImpl> listenerRegistration;
-    private final DSTreeBasedCache<EndpointPolicyTemplateBySgt, EpPolicyTemplateCacheKey, Sgt> cache;
-
-    public EpPolicyTemplateBySgtListenerImpl(final DataBroker dataBroker,
-                                             final DSTreeBasedCache<EndpointPolicyTemplateBySgt, EpPolicyTemplateCacheKey, Sgt> cache) {
-        this.cache = Preconditions.checkNotNull(cache, "missing ep-policy-template cache");
-        final InstanceIdentifier<EndpointPolicyTemplateBySgt> templatePath = InstanceIdentifier.create(SxpMapper.class)
-                .child(EndpointPolicyTemplateBySgt.class);
-
-        final DataTreeIdentifier<EndpointPolicyTemplateBySgt> treePath = new DataTreeIdentifier<>(
-                LogicalDatastoreType.CONFIGURATION, templatePath);
-        listenerRegistration = dataBroker.registerDataTreeChangeListener(treePath, this);
-        LOG.info("ep-policy-template listener registered");
-    }
-
-    @Override
-    public void onDataTreeChanged(@Nonnull final Collection<DataTreeModification<EndpointPolicyTemplateBySgt>> collection) {
-        LOG.debug("ep-policy-template changed");
-        for (DataTreeModification<EndpointPolicyTemplateBySgt> epPolicyTemplateModification : collection) {
-            final DataObjectModification<EndpointPolicyTemplateBySgt> rootNode = epPolicyTemplateModification
-                    .getRootNode();
-            final DataObjectModification.ModificationType modificationType = rootNode.getModificationType();
-            switch (modificationType) {
-                case DELETE:
-                    // invalidate cache
-                    cache.invalidate(rootNode.getDataBefore());
-                    break;
-                case WRITE:
-                    // extend cache
-                    cache.add(rootNode.getDataAfter());
-                    break;
-                case SUBTREE_MODIFIED:
-                    // update cache
-                    cache.update(rootNode.getDataBefore(), rootNode.getDataAfter());
-                    break;
-                default:
-                    LOG.warn("modification type not supported: {}", modificationType);
-            }
-        }
-    }
-
-    @Override
-    public void close() {
-        listenerRegistration.close();
-    }
-}
index 12aa97385d201de838bc61cd57a1d21c2d270e29..d22205825fde400fda327230ca605ad8c5719178 100644 (file)
@@ -8,15 +8,21 @@
 
 package org.opendaylight.groupbasedpolicy.renderer.ios_xe_provider.impl.manager;
 
-import com.google.common.base.Preconditions;
-import com.google.common.util.concurrent.Futures;
-import com.google.common.util.concurrent.ListenableFuture;
+import static org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.HasDirection.Direction.In;
+import static org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.HasDirection.Direction.Out;
+import static org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.EndpointPolicyParticipation.CONSUMER;
+import static org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.EndpointPolicyParticipation.PROVIDER;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.groupbasedpolicy.api.sf.AllowActionDefinition;
 import org.opendaylight.groupbasedpolicy.api.sf.ChainActionDefinition;
-import org.opendaylight.groupbasedpolicy.renderer.ios_xe_provider.api.cache.DSTreeBasedCache;
 import org.opendaylight.groupbasedpolicy.renderer.ios_xe_provider.api.manager.PolicyManager;
-import org.opendaylight.groupbasedpolicy.renderer.ios_xe_provider.impl.cache.EpPolicyTemplateCacheKey;
 import org.opendaylight.groupbasedpolicy.renderer.ios_xe_provider.impl.util.PolicyManagerUtil;
 import org.opendaylight.groupbasedpolicy.renderer.ios_xe_provider.impl.util.PolicyWriter;
 import org.opendaylight.groupbasedpolicy.renderer.ios_xe_provider.impl.util.RendererPolicyUtil;
@@ -63,28 +69,20 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.resolved.policy.rev150828.has.actions.Action;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.resolved.policy.rev150828.has.classifiers.Classifier;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.resolved.policy.rev150828.has.resolved.rules.ResolvedRule;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.groupbasedpolicy.sxp.mapper.model.rev160302.sxp.mapper.EndpointPolicyTemplateBySgt;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.groupbasedpolicy.sxp.mapper.model.rev160302.AddressEndpointWithLocationAug;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.sxp.database.rev160308.Sgt;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import static org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.HasDirection.Direction.In;
-import static org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.HasDirection.Direction.Out;
-import static org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.EndpointPolicyParticipation.CONSUMER;
-import static org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.EndpointPolicyParticipation.PROVIDER;
+import com.google.common.base.Preconditions;
+import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.ListenableFuture;
 
 public class PolicyManagerImpl implements PolicyManager {
 
     private static final Logger LOG = LoggerFactory.getLogger(PolicyMapper.class);
     private final DataBroker dataBroker;
-    private DSTreeBasedCache<EndpointPolicyTemplateBySgt, EpPolicyTemplateCacheKey, Sgt> epPolicyCache;
     private final PolicyMapper mapper;
     private final String policyMapName = "service-chains";
     private Map<DataBroker, PolicyWriter> perDeviceWriterCache = new HashMap<>();
@@ -92,10 +90,8 @@ public class PolicyManagerImpl implements PolicyManager {
     public enum ActionCase { ALLOW, CHAIN }
 
 
-    public PolicyManagerImpl(final DataBroker dataBroker,
-                             final DSTreeBasedCache<EndpointPolicyTemplateBySgt, EpPolicyTemplateCacheKey, Sgt> epPolicyCache) {
+    public PolicyManagerImpl(final DataBroker dataBroker) {
         this.dataBroker = Preconditions.checkNotNull(dataBroker);
-        this.epPolicyCache = Preconditions.checkNotNull(epPolicyCache);
         mapper = new PolicyMapper(dataBroker);
     }
 
@@ -170,7 +166,12 @@ public class PolicyManagerImpl implements PolicyManager {
         }
         AddressEndpointWithLocation endpointWithLocation = RendererPolicyUtil.lookupEndpoint(endpointKey,
                 endpointsWithLocation);
-        return epPolicyCache.lookupValue(new EpPolicyTemplateCacheKey(endpointWithLocation));
+        AddressEndpointWithLocationAug augmentation = endpointWithLocation.getAugmentation(AddressEndpointWithLocationAug.class);
+        if (augmentation == null) {
+            return null;
+        }
+
+        return augmentation.getSgt();
     }
 
     private List<Class> resolveChainAction(final PeerEndpointWithPolicy peerEndpoint, final Sgt sourceSgt,
diff --git a/renderers/ios-xe/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ios_xe_provider/impl/cache/EpPolicyCacheImplTest.java b/renderers/ios-xe/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ios_xe_provider/impl/cache/EpPolicyCacheImplTest.java
deleted file mode 100644 (file)
index 6d700a9..0000000
+++ /dev/null
@@ -1,153 +0,0 @@
-/*
- * Copyright (c) 2016 Cisco Systems, Inc. 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,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.groupbasedpolicy.renderer.ios_xe_provider.impl.cache;
-
-import java.util.ArrayList;
-import java.util.List;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ConditionName;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.EndpointGroupId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.endpoints.AddressEndpointWithLocationBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.groupbasedpolicy.sxp.mapper.model.rev160302.sxp.mapper.EndpointPolicyTemplateBySgt;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.groupbasedpolicy.sxp.mapper.model.rev160302.sxp.mapper.EndpointPolicyTemplateBySgtBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.sxp.database.rev160308.Sgt;
-
-/**
- * Test for {@link EpPolicyCacheImpl}.
- */
-public class EpPolicyCacheImplTest {
-
-    private static final int SGT1 = 1;
-    private static final int SGT2 = 2;
-    private static final String TENANT1 = "tenant1";
-    private static final String TENANT2 = "tenant2";
-
-    private static final EpPolicyTemplateCacheKey KEY_1 = createKey(TENANT1, new String[]{"n1", "n2"});
-    private static final EpPolicyTemplateCacheKey KEY_2 = createKey(TENANT2, new String[]{"n3"});
-
-    private static final EndpointPolicyTemplateBySgt TEMPLATE_1 = createTemplate(SGT1, TENANT1, new String[]{"n1", "n2"});
-    private static final EndpointPolicyTemplateBySgt TEMPLATE_2 = createTemplate(SGT2, TENANT2, new String[]{"n3"});
-
-    private EpPolicyCacheImpl cache;
-
-    @Before
-    public void setUp() throws Exception {
-        cache = new EpPolicyCacheImpl();
-    }
-
-    @Test
-    public void testInvalidate() throws Exception {
-        cache.add(TEMPLATE_1);
-        cache.add(TEMPLATE_2);
-
-        checkValuePresence(KEY_1, SGT1);
-
-        checkValuePresence(KEY_2, SGT2);
-
-        cache.invalidate(TEMPLATE_1);
-        Assert.assertNull(cache.lookupValue(KEY_1));
-        Assert.assertNotNull(cache.lookupValue(KEY_2));
-    }
-
-    @Test
-    public void testAdd() throws Exception {
-        cache.add(TEMPLATE_1);
-        checkValuePresence(KEY_1, SGT1);
-    }
-
-    @Test
-    public void testUpdate() throws Exception {
-        cache.add(TEMPLATE_1);
-        checkValuePresence(KEY_1, SGT1);
-
-        cache.update(TEMPLATE_1, TEMPLATE_2);
-
-        Assert.assertNull(cache.lookupValue(KEY_1));
-        checkValuePresence(KEY_2, SGT2);
-    }
-
-    @Test
-    public void testLookupValue() throws Exception {
-        cache.add(TEMPLATE_1);
-        checkValuePresence(KEY_1, SGT1);
-    }
-
-    private void checkValuePresence(final EpPolicyTemplateCacheKey key, final int expectedSgt) {
-        final Sgt sgt = cache.lookupValue(key);
-        Assert.assertNotNull(sgt);
-        Assert.assertEquals(expectedSgt, sgt.getValue().intValue());
-    }
-
-    @Test
-    public void testLookupValue_withChangedOrder() throws Exception {
-        Assert.assertNull(cache.lookupValue(KEY_1));
-        cache.add(TEMPLATE_1);
-        checkValuePresence(KEY_1, SGT1);
-
-        final EpPolicyTemplateCacheKey twistedKey1 = createKey(TENANT1, new String[]{"n1", "n2"}, new String[]{"n2", "n1"});
-        checkValuePresence(twistedKey1, SGT1);
-
-        final EpPolicyTemplateCacheKey twistedKey2 = createKey(TENANT1, new String[]{"n2", "n1"}, new String[]{"n1", "n2"});
-        checkValuePresence(twistedKey2, SGT1);
-    }
-
-    @Test
-    public void testInvalidateAll() throws Exception {
-        cache.add(TEMPLATE_1);
-        cache.add(TEMPLATE_2);
-        checkValuePresence(KEY_1, SGT1);
-
-        cache.invalidateAll();
-        Assert.assertNull(cache.lookupValue(KEY_1));
-        Assert.assertNull(cache.lookupValue(KEY_2));
-    }
-
-    private static EndpointPolicyTemplateBySgt createTemplate(final int sgt, final String tenant, final String[] names) {
-        final List<ConditionName> conditions = buildConditions(names);
-        final List<EndpointGroupId> endpointGroupIds = buildEndpointGroupIds(names);
-
-        return new EndpointPolicyTemplateBySgtBuilder()
-                .setSgt(new Sgt(sgt))
-                .setTenant(new TenantId(tenant))
-                .setConditions(conditions)
-                .setEndpointGroups(endpointGroupIds)
-                .build();
-    }
-
-    private static List<EndpointGroupId> buildEndpointGroupIds(final String[] names) {
-        final List<EndpointGroupId> endpointGroupIds = new ArrayList<>();
-        for (String epgId : names) {
-            endpointGroupIds.add(new EndpointGroupId(epgId));
-        }
-        return endpointGroupIds;
-    }
-
-    private static List<ConditionName> buildConditions(final String[] names) {
-        final List<ConditionName> conditions = new ArrayList<>();
-        for (String condition : names) {
-            conditions.add(new ConditionName(condition));
-        }
-        return conditions;
-    }
-
-    private static EpPolicyTemplateCacheKey createKey(final String tenant, final String[] names) {
-        return createKey(tenant, names, names);
-    }
-
-    private static EpPolicyTemplateCacheKey createKey(final String tenant, final String[] epgIds, final String[] conditionNames) {
-        return new EpPolicyTemplateCacheKey(new AddressEndpointWithLocationBuilder()
-                .setTenant(new TenantId(tenant))
-                .setEndpointGroup(buildEndpointGroupIds(epgIds))
-                .setCondition(buildConditions(conditionNames))
-                .build());
-    }
-}
\ No newline at end of file
diff --git a/renderers/ios-xe/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ios_xe_provider/impl/listener/EpPolicyTemplateBySgtListenerImplTest.java b/renderers/ios-xe/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ios_xe_provider/impl/listener/EpPolicyTemplateBySgtListenerImplTest.java
deleted file mode 100644 (file)
index 6c6931a..0000000
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * Copyright (c) 2016 Cisco Systems, Inc. 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,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.groupbasedpolicy.renderer.ios_xe_provider.impl.listener;
-
-import com.google.common.collect.Lists;
-import java.util.Collections;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Matchers;
-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.controller.md.sal.binding.api.DataObjectModification;
-import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
-import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
-import org.opendaylight.groupbasedpolicy.renderer.ios_xe_provider.api.cache.DSTreeBasedCache;
-import org.opendaylight.groupbasedpolicy.renderer.ios_xe_provider.impl.cache.EpPolicyTemplateCacheKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ConditionName;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.EndpointGroupId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.groupbasedpolicy.sxp.mapper.model.rev160302.sxp.mapper.EndpointPolicyTemplateBySgt;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.groupbasedpolicy.sxp.mapper.model.rev160302.sxp.mapper.EndpointPolicyTemplateBySgtBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.sxp.database.rev160308.Sgt;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
-
-/**
- * Test for {@link EpPolicyTemplateBySgtListenerImpl}.
- */
-@RunWith(MockitoJUnitRunner.class)
-public class EpPolicyTemplateBySgtListenerImplTest {
-
-    private static final Sgt SGT1 = new Sgt(1);
-    private static final TenantId TENANT1 = new TenantId("tenant1");
-    private static final TenantId TENANT2 = new TenantId("tenant2");
-    @Mock
-    private DataBroker dataBroker;
-    @Mock
-    private DSTreeBasedCache<EndpointPolicyTemplateBySgt, EpPolicyTemplateCacheKey, Sgt> cache;
-    @Mock
-    private ListenerRegistration<EpPolicyTemplateBySgtListenerImpl> listenerRegistration;
-    @Mock
-    private DataTreeModification<EndpointPolicyTemplateBySgt> dataTreeModification;
-    @Mock
-    private DataObjectModification<EndpointPolicyTemplateBySgt> rootNode;
-
-    private final EndpointPolicyTemplateBySgt template1;
-    private final EndpointPolicyTemplateBySgt template2;
-
-    private EpPolicyTemplateBySgtListenerImpl listener;
-
-    public EpPolicyTemplateBySgtListenerImplTest() {
-        this.template1 = new EndpointPolicyTemplateBySgtBuilder()
-                .setSgt(SGT1)
-                .setTenant(TENANT1)
-                .setEndpointGroups(Lists.newArrayList(new EndpointGroupId("epg1"), new EndpointGroupId("epg2")))
-                .setConditions(Lists.newArrayList(new ConditionName("condition1"), new ConditionName("condition2")))
-                .build();
-
-        this.template2 = new EndpointPolicyTemplateBySgtBuilder()
-                .setSgt(SGT1)
-                .setTenant(TENANT2)
-                .setEndpointGroups(Lists.newArrayList(new EndpointGroupId("epg3"), new EndpointGroupId("epg4")))
-                .setConditions(Lists.newArrayList(new ConditionName("condition2"), new ConditionName("condition3")))
-                .build();
-    }
-
-    @Before
-    public void setUp() throws Exception {
-        Mockito.when(dataBroker.registerDataTreeChangeListener(
-                Matchers.<DataTreeIdentifier<EndpointPolicyTemplateBySgt>>any(),
-                Matchers.<EpPolicyTemplateBySgtListenerImpl>any()))
-                .thenReturn(listenerRegistration);
-        listener = new EpPolicyTemplateBySgtListenerImpl(dataBroker, cache);
-    }
-
-    @After
-    public void tearDown() throws Exception {
-        Mockito.verifyNoMoreInteractions(cache);
-    }
-
-    @Test
-    public void testOnDataTreeChanged_add() throws Exception {
-        Mockito.when(rootNode.getDataAfter()).thenReturn(template1);
-        Mockito.when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.WRITE);
-        Mockito.when(dataTreeModification.getRootNode()).thenReturn(rootNode);
-
-        listener.onDataTreeChanged(Collections.singleton(dataTreeModification));
-        Mockito.verify(cache).add(template1);
-    }
-
-    @Test
-    public void testOnDataTreeChanged_remove() throws Exception {
-        Mockito.when(rootNode.getDataBefore()).thenReturn(template1);
-        Mockito.when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.DELETE);
-        Mockito.when(dataTreeModification.getRootNode()).thenReturn(rootNode);
-
-        listener.onDataTreeChanged(Collections.singleton(dataTreeModification));
-        Mockito.verify(cache).invalidate(template1);
-    }
-
-    @Test
-    public void testOnDataTreeChanged_update() throws Exception {
-        Mockito.when(rootNode.getDataBefore()).thenReturn(template1);
-        Mockito.when(rootNode.getDataAfter()).thenReturn(template2);
-        Mockito.when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.SUBTREE_MODIFIED);
-        Mockito.when(dataTreeModification.getRootNode()).thenReturn(rootNode);
-
-        listener.onDataTreeChanged(Collections.singleton(dataTreeModification));
-        Mockito.verify(cache).update(template1, template2);
-    }
-
-    @Test
-    public void testClose() throws Exception {
-        Mockito.verify(listenerRegistration, Mockito.never()).close();
-        listener.close();
-        Mockito.verify(listenerRegistration).close();
-        listener.close();
-        Mockito.verify(listenerRegistration, Mockito.times(2)).close();
-    }
-}
\ No newline at end of file