summaryrefslogtreecommitdiffstats
path: root/v3po/v3po2vpp
diff options
context:
space:
mode:
authorJan Srnicek <jsrnicek@cisco.com>2016-11-03 09:37:28 +0100
committerMaros Marsalek <mmarsale@cisco.com>2016-11-03 10:51:24 +0000
commit918847c2202e943ca8e3e8c1ff1b8d3617cb502d (patch)
treec9ec38b9522e593ca2a1834b85a609ac0be6d6f1 /v3po/v3po2vpp
parente4813a654f93763577e792e4b67353fb27948580 (diff)
HONEYCOMB-259 - CacheKeyFactory
Provides logic for creating scoped keys Change-Id: I126bcb9255b4f8a3f2585f50e6e718948581e7f0 Signed-off-by: Jan Srnicek <jsrnicek@cisco.com>
Diffstat (limited to 'v3po/v3po2vpp')
-rw-r--r--v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/Ipv4AddressCustomizer.java23
-rw-r--r--v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/SubInterfaceIpv4AddressCustomizer.java5
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/Ipv4AddressCustomizerTest.java15
3 files changed, 25 insertions, 18 deletions
diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/Ipv4AddressCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/Ipv4AddressCustomizer.java
index 1aedba822..fb09e3a2e 100644
--- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/Ipv4AddressCustomizer.java
+++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/Ipv4AddressCustomizer.java
@@ -19,6 +19,7 @@ package io.fd.honeycomb.translate.v3po.interfacesstate.ip;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.base.Optional;
+import com.google.common.collect.ImmutableSet;
import com.google.common.base.Preconditions;
import io.fd.honeycomb.translate.read.ReadContext;
import io.fd.honeycomb.translate.read.ReadFailedException;
@@ -26,6 +27,7 @@ import io.fd.honeycomb.translate.spi.read.Initialized;
import io.fd.honeycomb.translate.spi.read.InitializingListReaderCustomizer;
import io.fd.honeycomb.translate.util.RWUtils;
import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager;
+import io.fd.honeycomb.translate.util.read.cache.IdentifierCacheKeyFactory;
import io.fd.honeycomb.translate.v3po.interfacesstate.InterfaceCustomizer;
import io.fd.honeycomb.translate.v3po.interfacesstate.ip.dump.params.AddressDumpParams;
import io.fd.honeycomb.translate.vpp.util.FutureJVppCustomizer;
@@ -66,9 +68,12 @@ public class Ipv4AddressCustomizer extends FutureJVppCustomizer
@Nonnull final NamingContext interfaceContext) {
super(futureJVppCore);
this.interfaceContext = checkNotNull(interfaceContext, "interfaceContext should not be null");
- this.dumpManager = new DumpCacheManager.DumpCacheManagerBuilder<IpAddressDetailsReplyDump, AddressDumpParams>()
- .withExecutor(createExecutor(futureJVppCore))
- .build();
+ this.dumpManager =
+ new DumpCacheManager.DumpCacheManagerBuilder<IpAddressDetailsReplyDump, AddressDumpParams>()
+ .withExecutor(createExecutor(futureJVppCore))
+ // Key needs to contain interface ID to distinguish dumps between interfaces
+ .withCacheKeyFactory(new IdentifierCacheKeyFactory(ImmutableSet.of(Interface.class)))
+ .build();
}
@Override
@@ -85,10 +90,8 @@ public class Ipv4AddressCustomizer extends FutureJVppCustomizer
final String interfaceName = id.firstKeyOf(Interface.class).getName();
final int interfaceIndex = interfaceContext.getIndex(interfaceName, ctx.getMappingContext());
- // Key needs to contain interface ID to distinguish dumps between interfaces
- final String cacheKey = CACHE_KEY + interfaceName;
- final Optional<IpAddressDetailsReplyDump> dumpOptional = dumpManager
- .getDump(id, cacheKey, ctx.getModificationCache(), new AddressDumpParams(interfaceIndex, false));
+ final Optional<IpAddressDetailsReplyDump> dumpOptional =
+ dumpManager.getDump(id, ctx.getModificationCache(), new AddressDumpParams(interfaceIndex, false));
if (!dumpOptional.isPresent() || dumpOptional.get().ipAddressDetails.isEmpty()) {
return;
@@ -116,10 +119,8 @@ public class Ipv4AddressCustomizer extends FutureJVppCustomizer
final String interfaceName = id.firstKeyOf(Interface.class).getName();
final int interfaceIndex = interfaceContext.getIndex(interfaceName, ctx.getMappingContext());
- // Key needs to contain interface ID to distinguish dumps between interfaces
- final String cacheKey = CACHE_KEY + interfaceName;
- final Optional<IpAddressDetailsReplyDump> dumpOptional = dumpManager
- .getDump(id, cacheKey, ctx.getModificationCache(), new AddressDumpParams(interfaceIndex, false));
+ final Optional<IpAddressDetailsReplyDump> dumpOptional =
+ dumpManager.getDump(id, ctx.getModificationCache(), new AddressDumpParams(interfaceIndex, false));
return getAllIpv4AddressIds(dumpOptional, AddressKey::new);
}
diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/SubInterfaceIpv4AddressCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/SubInterfaceIpv4AddressCustomizer.java
index 60171f768..a445c3f55 100644
--- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/SubInterfaceIpv4AddressCustomizer.java
+++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/SubInterfaceIpv4AddressCustomizer.java
@@ -56,7 +56,6 @@ public class SubInterfaceIpv4AddressCustomizer extends FutureJVppCustomizer
implements InitializingListReaderCustomizer<Address, AddressKey, AddressBuilder>, Ipv4Reader {
private static final Logger LOG = LoggerFactory.getLogger(SubInterfaceIpv4AddressCustomizer.class);
- private static final String CACHE_KEY = SubInterfaceIpv4AddressCustomizer.class.getName();
private final NamingContext interfaceContext;
private final DumpCacheManager<IpAddressDetailsReplyDump, AddressDumpParams> dumpManager;
@@ -85,7 +84,7 @@ public class SubInterfaceIpv4AddressCustomizer extends FutureJVppCustomizer
final String subInterfaceName = getSubInterfaceName(id);
final int subInterfaceIndex = interfaceContext.getIndex(subInterfaceName, ctx.getMappingContext());
final Optional<IpAddressDetailsReplyDump> dumpOptional = dumpManager
- .getDump(id, CACHE_KEY, ctx.getModificationCache(), new AddressDumpParams(subInterfaceIndex, false));
+ .getDump(id, ctx.getModificationCache(), new AddressDumpParams(subInterfaceIndex, false));
final Optional<IpAddressDetails> ipAddressDetails =
findIpAddressDetailsByIp(dumpOptional, id.firstKeyOf(Address.class).getIp());
@@ -110,7 +109,7 @@ public class SubInterfaceIpv4AddressCustomizer extends FutureJVppCustomizer
final String subInterfaceName = getSubInterfaceName(id);
final int subInterfaceIndex = interfaceContext.getIndex(subInterfaceName, ctx.getMappingContext());
final Optional<IpAddressDetailsReplyDump> dumpOptional = dumpManager
- .getDump(id, CACHE_KEY, ctx.getModificationCache(), new AddressDumpParams(subInterfaceIndex, false));
+ .getDump(id, ctx.getModificationCache(), new AddressDumpParams(subInterfaceIndex, false));
return getAllIpv4AddressIds(dumpOptional, AddressKey::new);
}
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/Ipv4AddressCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/Ipv4AddressCustomizerTest.java
index 42fae44a3..efe6c6afe 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/Ipv4AddressCustomizerTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/Ipv4AddressCustomizerTest.java
@@ -26,8 +26,11 @@ import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;
import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
import io.fd.honeycomb.translate.read.ReadFailedException;
import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
+import io.fd.honeycomb.translate.util.read.cache.CacheKeyFactory;
+import io.fd.honeycomb.translate.util.read.cache.IdentifierCacheKeyFactory;
import io.fd.honeycomb.translate.vpp.util.Ipv4Translator;
import io.fd.honeycomb.translate.vpp.util.NamingContext;
import io.fd.honeycomb.vpp.test.read.ListReaderCustomizerTest;
@@ -67,6 +70,7 @@ public class Ipv4AddressCustomizerTest extends ListReaderCustomizerTest<Address,
private NamingContext interfacesContext;
private InstanceIdentifier<Address> ifaceOneAddressOneIdentifier;
private InstanceIdentifier<Address> ifaceTwoAddressOneIdentifier;
+ private CacheKeyFactory cacheKeyFactory;
public Ipv4AddressCustomizerTest() {
super(Address.class, Ipv4Builder.class);
@@ -90,6 +94,9 @@ public class Ipv4AddressCustomizerTest extends ListReaderCustomizerTest<Address,
.augmentation(Interface2.class)
.child(Ipv4.class)
.child(Address.class, new AddressKey(new Ipv4AddressNoZone("192.168.2.1")));
+
+ // to simulate complex key
+ cacheKeyFactory = new IdentifierCacheKeyFactory(ImmutableSet.of(Interface.class));
}
@Override
@@ -258,8 +265,8 @@ public class Ipv4AddressCustomizerTest extends ListReaderCustomizerTest<Address,
ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1"))));
detailIfaceTwoAddressOne.prefixLength = 23;
- cache.put(Ipv4AddressCustomizer.class.getName() + IFACE_NAME, replyIfaceOne);
- cache.put(Ipv4AddressCustomizer.class.getName() + IFACE_2_NAME, replyIfaceTwo);
+ cache.put(cacheKeyFactory.createKey(ifaceOneAddressOneIdentifier), replyIfaceOne);
+ cache.put(cacheKeyFactory.createKey(ifaceTwoAddressOneIdentifier), replyIfaceTwo);
}
private void fillCacheForFirstIfaceSecondEmpty() {
@@ -271,7 +278,7 @@ public class Ipv4AddressCustomizerTest extends ListReaderCustomizerTest<Address,
ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1"))));
detailIfaceOneAddressOne.prefixLength = 22;
- cache.put(Ipv4AddressCustomizer.class.getName() + IFACE_NAME, replyIfaceOne);
- cache.put(Ipv4AddressCustomizer.class.getName() + IFACE_2_NAME, new IpAddressDetailsReplyDump());
+ cache.put(cacheKeyFactory.createKey(ifaceOneAddressOneIdentifier), replyIfaceOne);
+ cache.put(cacheKeyFactory.createKey(ifaceTwoAddressOneIdentifier), new IpAddressDetailsReplyDump());
}
}