From 58961d7103e1c7dfd411ab00ce3905e2e5fec94b Mon Sep 17 00:00:00 2001 From: Jan Srnicek Date: Wed, 28 Sep 2016 14:42:39 +0200 Subject: HONEYCOMB-210 - DumpEmptyCheck removed Change-Id: I95ea94c3a1a581753f7eb667af7aacde832c21fd Signed-off-by: Jan Srnicek --- .../util/read/cache/DumpCacheManager.java | 28 ++------ .../util/read/cache/EntityDumpExecutor.java | 8 ++- .../util/read/cache/EntityDumpNonEmptyCheck.java | 31 --------- .../exceptions/check/DumpCheckFailedException.java | 31 --------- .../exceptions/check/i/DumpEmptyException.java | 40 ----------- .../execution/i/DumpCallFailedException.java | 3 + .../lisp/translate/read/InterfaceCustomizer.java | 46 ++++++------ .../translate/read/LocalMappingCustomizer.java | 58 +++++++--------- .../lisp/translate/read/LocatorSetCustomizer.java | 46 ++++++------ .../lisp/translate/read/MapResolverCustomizer.java | 32 +++------ .../translate/read/RemoteMappingCustomizer.java | 59 ++++++++-------- .../lisp/translate/read/VniTableCustomizer.java | 18 ++--- .../read/dump/check/LocatorDumpCheck.java | 37 ---------- .../read/dump/check/LocatorSetsDumpCheck.java | 38 ---------- .../read/dump/check/MapResolverDumpCheck.java | 37 ---------- .../read/dump/check/MappingsDumpCheck.java | 40 ----------- .../read/dump/check/VniTableDumpCheck.java | 37 ---------- .../lisp/translate/write/LocatorSetCustomizer.java | 2 - .../read/dump/check/LocatorDumpCheckTest.java | 25 ------- .../read/dump/check/LocatorSetsDumpCheckTest.java | 26 ------- .../read/dump/check/MapResolverDumpCheckTest.java | 26 ------- .../read/dump/check/MappingsDumpCheckTest.java | 26 ------- .../read/dump/check/VniTableDumpCheckTest.java | 26 ------- .../interfacesstate/ip/Ipv4AddressCustomizer.java | 33 ++++----- .../ip/SubInterfaceIpv4AddressCustomizer.java | 2 - .../ip/dump/check/AddressDumpCheck.java | 16 ----- .../fd/honeycomb/vpp/test/read/DumpCheckTest.java | 81 ---------------------- .../vpp/util/cache/DumpCacheManagerTest.java | 42 +++++------ 28 files changed, 155 insertions(+), 739 deletions(-) delete mode 100644 infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/cache/EntityDumpNonEmptyCheck.java delete mode 100644 infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/cache/exceptions/check/DumpCheckFailedException.java delete mode 100644 infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/cache/exceptions/check/i/DumpEmptyException.java delete mode 100644 lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/check/LocatorDumpCheck.java delete mode 100755 lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/check/LocatorSetsDumpCheck.java delete mode 100755 lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/check/MapResolverDumpCheck.java delete mode 100755 lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/check/MappingsDumpCheck.java delete mode 100755 lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/check/VniTableDumpCheck.java delete mode 100644 lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/dump/check/LocatorDumpCheckTest.java delete mode 100644 lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/dump/check/LocatorSetsDumpCheckTest.java delete mode 100644 lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/dump/check/MapResolverDumpCheckTest.java delete mode 100644 lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/dump/check/MappingsDumpCheckTest.java delete mode 100644 lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/dump/check/VniTableDumpCheckTest.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/dump/check/AddressDumpCheck.java delete mode 100644 vpp-common/vpp-translate-test/src/main/java/io/fd/honeycomb/vpp/test/read/DumpCheckTest.java diff --git a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/cache/DumpCacheManager.java b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/cache/DumpCacheManager.java index dfb62146c..e5016657a 100644 --- a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/cache/DumpCacheManager.java +++ b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/cache/DumpCacheManager.java @@ -20,7 +20,6 @@ import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.base.Optional; import io.fd.honeycomb.translate.ModificationCache; -import io.fd.honeycomb.translate.util.read.cache.exceptions.check.DumpCheckFailedException; import io.fd.honeycomb.translate.util.read.cache.exceptions.execution.DumpExecutionFailedException; import io.fd.honeycomb.translate.util.read.cache.noop.NoopDumpPostProcessingFunction; import javax.annotation.Nonnull; @@ -36,12 +35,10 @@ public final class DumpCacheManager { private static final Logger LOG = LoggerFactory.getLogger(DumpCacheManager.class); private final EntityDumpExecutor dumpExecutor; - private final EntityDumpNonEmptyCheck dumpNonEmptyCheck; private final EntityDumpPostProcessingFunction postProcessor; private DumpCacheManager(DumpCacheManagerBuilder builder) { this.dumpExecutor = builder.dumpExecutor; - this.dumpNonEmptyCheck = builder.dumpNonEmptyCheck; this.postProcessor = builder.postProcessingFunction; } @@ -60,24 +57,14 @@ public final class DumpCacheManager { if (dump == null) { LOG.debug("Dump for KEY[{}] not present in cache,invoking dump executor", entityKey); // binds and execute dump to be thread-save - dump = dumpExecutor.executeDump(dumpParams); - - // TODO (HONEYCOMB-210): remove empty check (empty dump is normal state, special handling is not needed) - try { - dumpNonEmptyCheck.assertNotEmpty(dump); - } catch (DumpCheckFailedException e) { - LOG.debug("Dump for KEY[{}] has been resolved as empty: {}", entityKey, e.getMessage()); - return Optional.absent(); - } - - // no need to check if post processor active,if wasn't set,default no-op will be used - LOG.debug("Post-processing dump for KEY[{}]", entityKey); - dump = postProcessor.apply(dump); - + dump = postProcessor.apply(dumpExecutor.executeDump(dumpParams)); + // no need to check dump, if no data were dumped , DTO with empty list is returned + // no need to check if post processor is active,if it wasn't set,default no-op will be used LOG.debug("Caching dump for KEY[{}]", entityKey); cache.put(entityKey, dump); return Optional.of(dump); } else { + LOG.debug("Cached instance of dump was found for KEY[{}]", entityKey); return Optional.of(dump); } } @@ -85,7 +72,6 @@ public final class DumpCacheManager { public static final class DumpCacheManagerBuilder { private EntityDumpExecutor dumpExecutor; - private EntityDumpNonEmptyCheck dumpNonEmptyCheck; private EntityDumpPostProcessingFunction postProcessingFunction; public DumpCacheManagerBuilder() { @@ -98,11 +84,6 @@ public final class DumpCacheManager { return this; } - public DumpCacheManagerBuilder withNonEmptyPredicate(@Nonnull EntityDumpNonEmptyCheck check) { - this.dumpNonEmptyCheck = check; - return this; - } - public DumpCacheManagerBuilder withPostProcessingFunction( EntityDumpPostProcessingFunction postProcessingFunction) { this.postProcessingFunction = postProcessingFunction; @@ -111,7 +92,6 @@ public final class DumpCacheManager { public DumpCacheManager build() { checkNotNull(dumpExecutor, "Dump executor cannot be null"); - checkNotNull(dumpNonEmptyCheck, "Dump verifier cannot be null"); checkNotNull(postProcessingFunction, "Dump post-processor cannot be null cannot be null, default implementation is used if its not set"); diff --git a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/cache/EntityDumpExecutor.java b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/cache/EntityDumpExecutor.java index c220da4ff..05c455521 100644 --- a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/cache/EntityDumpExecutor.java +++ b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/cache/EntityDumpExecutor.java @@ -17,22 +17,24 @@ package io.fd.honeycomb.translate.util.read.cache; import io.fd.honeycomb.translate.util.read.cache.exceptions.execution.DumpExecutionFailedException; +import javax.annotation.Nonnull; import javax.annotation.concurrent.ThreadSafe; /** * Generic interface for classes that return dumps for Data objects. - * Must be implemented in Thread-save fashion. + * Must be implemented in Thread-safe fashion and return non-null data */ @ThreadSafe public interface EntityDumpExecutor { - static Void NO_PARAMS = null; + Void NO_PARAMS = null; /** - * Performs dump on {@link T} entity + * Performs dump on {@link T} entity. * * @return dump of specified {@link T} entity * @throws DumpExecutionFailedException when dump fails */ + @Nonnull T executeDump(final U params) throws DumpExecutionFailedException; } diff --git a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/cache/EntityDumpNonEmptyCheck.java b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/cache/EntityDumpNonEmptyCheck.java deleted file mode 100644 index 7c59270e0..000000000 --- a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/cache/EntityDumpNonEmptyCheck.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.honeycomb.translate.util.read.cache; - -import io.fd.honeycomb.translate.util.read.cache.exceptions.check.DumpCheckFailedException; -import io.fd.honeycomb.translate.util.read.cache.exceptions.check.i.DumpEmptyException; - -/** - * Generic interface for classes that verifies if dump of data object is non-empty - */ -public interface EntityDumpNonEmptyCheck { - - /** - * Verifies if data are non-empty,if not throws {@link DumpEmptyException} - */ - public void assertNotEmpty(T data) throws DumpCheckFailedException; -} diff --git a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/cache/exceptions/check/DumpCheckFailedException.java b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/cache/exceptions/check/DumpCheckFailedException.java deleted file mode 100644 index 097ef344d..000000000 --- a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/cache/exceptions/check/DumpCheckFailedException.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.honeycomb.translate.util.read.cache.exceptions.check; - -/** - * Abstract parent of exceptions thrown while checking if dump is not empty - */ -public abstract class DumpCheckFailedException extends Exception { - - public DumpCheckFailedException(String message) { - super(message); - } - - public DumpCheckFailedException(String message, Exception cause) { - super(message, cause); - } -} diff --git a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/cache/exceptions/check/i/DumpEmptyException.java b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/cache/exceptions/check/i/DumpEmptyException.java deleted file mode 100644 index 8769827ee..000000000 --- a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/cache/exceptions/check/i/DumpEmptyException.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.honeycomb.translate.util.read.cache.exceptions.check.i; - -import io.fd.honeycomb.translate.util.read.cache.EntityDumpNonEmptyCheck; -import io.fd.honeycomb.translate.util.read.cache.exceptions.check.DumpCheckFailedException; - -/** - * This exception occurs when dump is resolved as empty by {@link EntityDumpNonEmptyCheck} - */ -public class DumpEmptyException extends DumpCheckFailedException { - - /** - * Creates {@link DumpEmptyException} with specified reason - */ - public DumpEmptyException(String reason) { - super(reason); - } - - /** - * Creates {@link DumpEmptyException} with specified reason and sub-exception - */ - public DumpEmptyException(String reason, Exception e) { - super(reason, e); - } -} diff --git a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/cache/exceptions/execution/i/DumpCallFailedException.java b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/cache/exceptions/execution/i/DumpCallFailedException.java index ba794070b..6e09e8d66 100644 --- a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/cache/exceptions/execution/i/DumpCallFailedException.java +++ b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/cache/exceptions/execution/i/DumpCallFailedException.java @@ -21,6 +21,9 @@ import io.fd.honeycomb.translate.util.read.cache.exceptions.execution.DumpExecut /** * Wrapper exception for any execution exception during dumping */ +/* TODO - https://jira.fd.io/browse/HONEYCOMB-227 - Make it extends ReadFailedException. + Pay attention to description in issue. + */ public class DumpCallFailedException extends DumpExecutionFailedException { public DumpCallFailedException(String message, Exception cause) { diff --git a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/InterfaceCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/InterfaceCustomizer.java index 8af7a8682..958689df4 100755 --- a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/InterfaceCustomizer.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/InterfaceCustomizer.java @@ -21,7 +21,6 @@ import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkState; import com.google.common.base.Optional; -import io.fd.honeycomb.lisp.translate.read.dump.check.LocatorDumpCheck; import io.fd.honeycomb.lisp.translate.read.dump.executor.LocatorDumpExecutor; import io.fd.honeycomb.lisp.translate.read.dump.executor.params.LocatorDumpParams; import io.fd.honeycomb.lisp.translate.read.dump.executor.params.LocatorDumpParams.LocatorDumpParamsBuilder; @@ -29,10 +28,10 @@ import io.fd.honeycomb.translate.read.ReadContext; import io.fd.honeycomb.translate.read.ReadFailedException; import io.fd.honeycomb.translate.spi.read.ListReaderCustomizer; import io.fd.honeycomb.translate.util.RWUtils; -import io.fd.honeycomb.translate.vpp.util.FutureJVppCustomizer; -import io.fd.honeycomb.translate.vpp.util.NamingContext; import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager; import io.fd.honeycomb.translate.util.read.cache.exceptions.execution.DumpExecutionFailedException; +import io.fd.honeycomb.translate.vpp.util.FutureJVppCustomizer; +import io.fd.honeycomb.translate.vpp.util.NamingContext; import java.util.Collections; import java.util.List; import java.util.stream.Collectors; @@ -76,7 +75,6 @@ public class InterfaceCustomizer this.dumpCacheManager = new DumpCacheManager.DumpCacheManagerBuilder() .withExecutor(new LocatorDumpExecutor(futureJvpp)) - .withNonEmptyPredicate(new LocatorDumpCheck()) .build(); } @@ -111,20 +109,22 @@ public class InterfaceCustomizer throw new ReadFailedException(id, e); } - if (reply.isPresent()) { - final LispLocatorDetails details = reply.get() - .lispLocatorDetails - .stream() - .filter(a -> a.swIfIndex == referencedInterfaceIndex) - .collect(RWUtils.singleItemCollector()); + if (!reply.isPresent() || reply.get().lispLocatorDetails.isEmpty()) { + return; + } - final String interfaceRef = interfaceContext.getName(details.swIfIndex, ctx.getMappingContext()); + final LispLocatorDetails details = reply.get() + .lispLocatorDetails + .stream() + .filter(a -> a.swIfIndex == referencedInterfaceIndex) + .collect(RWUtils.singleItemCollector()); - builder.setPriority(Byte.valueOf(details.priority).shortValue()); - builder.setWeight(Byte.valueOf(details.weight).shortValue()); - builder.setInterfaceRef(interfaceRef); - builder.setKey(new InterfaceKey(interfaceRef)); - } + final String interfaceRef = interfaceContext.getName(details.swIfIndex, ctx.getMappingContext()); + + builder.setPriority(Byte.valueOf(details.priority).shortValue()); + builder.setWeight(Byte.valueOf(details.weight).shortValue()); + builder.setInterfaceRef(interfaceRef); + builder.setKey(new InterfaceKey(interfaceRef)); } @Override @@ -146,15 +146,15 @@ public class InterfaceCustomizer throw new ReadFailedException(id, e); } - if (reply.isPresent()) { - return reply.get() - .lispLocatorDetails - .stream() - .map(a -> new InterfaceKey(interfaceContext.getName(a.swIfIndex, context.getMappingContext()))) - .collect(Collectors.toList()); - } else { + if (!reply.isPresent() || reply.get().lispLocatorDetails.isEmpty()) { return Collections.emptyList(); } + + return reply.get() + .lispLocatorDetails + .stream() + .map(a -> new InterfaceKey(interfaceContext.getName(a.swIfIndex, context.getMappingContext()))) + .collect(Collectors.toList()); } @Override diff --git a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/LocalMappingCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/LocalMappingCustomizer.java index 015adc954..7524cd3b5 100755 --- a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/LocalMappingCustomizer.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/LocalMappingCustomizer.java @@ -25,7 +25,6 @@ import static io.fd.honeycomb.lisp.translate.read.dump.executor.params.MappingsD import com.google.common.base.Optional; import io.fd.honeycomb.lisp.context.util.EidMappingContext; -import io.fd.honeycomb.lisp.translate.read.dump.check.MappingsDumpCheck; import io.fd.honeycomb.lisp.translate.read.dump.executor.MappingsDumpExecutor; import io.fd.honeycomb.lisp.translate.read.dump.executor.params.MappingsDumpParams; import io.fd.honeycomb.lisp.translate.util.EidTranslator; @@ -81,7 +80,6 @@ public class LocalMappingCustomizer this.dumpManager = new DumpCacheManager.DumpCacheManagerBuilder() .withExecutor(dumpExecutor) - .withNonEmptyPredicate(new MappingsDumpCheck()) .build(); } @@ -125,24 +123,22 @@ public class LocalMappingCustomizer throw new ReadFailedException(id, e); } - if (replyOptional.isPresent()) { - LOG.debug("Valid dump loaded"); - - LispEidTableDetails details = replyOptional.get().lispEidTableDetails.stream() - .filter(a -> compareAddresses(eid.getAddress(), - getArrayAsEidLocal(valueOf(a.eidType), a.eid).getAddress())) - .collect( - RWUtils.singleItemCollector()); - - //in case of local mappings,locator_set_index stands for interface index - checkState(locatorSetContext.containsName(details.locatorSetIndex, ctx.getMappingContext()), - "No Locator Set name found for index %s", details.locatorSetIndex); - builder.setLocatorSet(locatorSetContext.getName(details.locatorSetIndex, ctx.getMappingContext())); - builder.setKey(new LocalMappingKey(new MappingId(id.firstKeyOf(LocalMapping.class).getId()))); - builder.setEid(getArrayAsEidLocal(valueOf(details.eidType), details.eid)); - } else { - LOG.debug("No data dumped"); + if (!replyOptional.isPresent() || replyOptional.get().lispEidTableDetails.isEmpty()) { + return; } + + LispEidTableDetails details = replyOptional.get().lispEidTableDetails.stream() + .filter(a -> compareAddresses(eid.getAddress(), + getArrayAsEidLocal(valueOf(a.eidType), a.eid).getAddress())) + .collect( + RWUtils.singleItemCollector()); + + //in case of local mappings,locator_set_index stands for interface index + checkState(locatorSetContext.containsName(details.locatorSetIndex, ctx.getMappingContext()), + "No Locator Set name found for index %s", details.locatorSetIndex); + builder.setLocatorSet(locatorSetContext.getName(details.locatorSetIndex, ctx.getMappingContext())); + builder.setKey(new LocalMappingKey(new MappingId(id.firstKeyOf(LocalMapping.class).getId()))); + builder.setEid(getArrayAsEidLocal(valueOf(details.eidType), details.eid)); } @Override @@ -173,21 +169,19 @@ public class LocalMappingCustomizer throw new ReadFailedException(id, e); } - if (replyOptional.isPresent()) { - LOG.debug("Valid dump loaded"); - return replyOptional.get().lispEidTableDetails.stream() - //filtering with vni to skip help local mappings that are created in vpp to handle remote mappings(vpp feature) - .filter(a -> a.vni == vni) - .map(a -> new LocalMappingKey( - new MappingId( - localMappingContext.getId( - getArrayAsEidLocal(valueOf(a.eidType), a.eid), - context.getMappingContext())))) - .collect(Collectors.toList()); - } else { - LOG.debug("No data dumped"); + if (!replyOptional.isPresent() || replyOptional.get().lispEidTableDetails.isEmpty()) { return Collections.emptyList(); } + + return replyOptional.get().lispEidTableDetails.stream() + //filtering with vni to skip help local mappings that are created in vpp to handle remote mappings(vpp feature) + .filter(a -> a.vni == vni) + .map(a -> new LocalMappingKey( + new MappingId( + localMappingContext.getId( + getArrayAsEidLocal(valueOf(a.eidType), a.eid), + context.getMappingContext())))) + .collect(Collectors.toList()); } @Override diff --git a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/LocatorSetCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/LocatorSetCustomizer.java index 3ce5c2f4e..a1379f49b 100755 --- a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/LocatorSetCustomizer.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/LocatorSetCustomizer.java @@ -20,7 +20,6 @@ import static com.google.common.base.Preconditions.checkNotNull; import static io.fd.honeycomb.translate.util.read.cache.EntityDumpExecutor.NO_PARAMS; import com.google.common.base.Optional; -import io.fd.honeycomb.lisp.translate.read.dump.check.LocatorSetsDumpCheck; import io.fd.honeycomb.lisp.translate.read.dump.executor.LocatorSetsDumpExecutor; import io.fd.honeycomb.translate.read.ReadContext; import io.fd.honeycomb.translate.read.ReadFailedException; @@ -63,7 +62,6 @@ public class LocatorSetCustomizer extends FutureJVppCustomizer this.locatorSetContext = checkNotNull(locatorSetContext, "Locator Set mapping context cannot be null"); this.dumpManager = new DumpCacheManager.DumpCacheManagerBuilder() .withExecutor(new LocatorSetsDumpExecutor(futureJvpp)) - .withNonEmptyPredicate(new LocatorSetsDumpCheck()) .build(); } @@ -84,8 +82,7 @@ public class LocatorSetCustomizer extends FutureJVppCustomizer } catch (DumpExecutionFailedException e) { throw new ReadFailedException(id, e); } - if (!dumpOptional.isPresent()) { - LOG.warn("No dump present for Locator Set {}", id); + if (!dumpOptional.isPresent() || dumpOptional.get().lispLocatorSetDetails.isEmpty()) { return; } @@ -119,29 +116,28 @@ public class LocatorSetCustomizer extends FutureJVppCustomizer return Collections.emptyList(); } - if (dumpOptional.isPresent()) { - return dumpOptional.get().lispLocatorSetDetails.stream() - .map(set -> { - - final String locatorSetName = toString(set.lsName); - //creates mapping for existing locator-set(if it is'nt already existing one) - if (!locatorSetContext.containsIndex(locatorSetName, context.getMappingContext())) { - locatorSetContext.addName(set.lsIndex, locatorSetName, context.getMappingContext()); - } - - LOG.trace("Locator Set with name: {}, VPP name: {} and index: {} found in VPP", - locatorSetContext.getName(set.lsIndex, context.getMappingContext()), - locatorSetName, - set.lsIndex); - - return set; - }) - .map(set -> new LocatorSetKey(toString(set.lsName))) - .collect(Collectors.toList()); - } else { - LOG.warn("No data dumped for Locator Set {}", id); + if (!dumpOptional.isPresent() || dumpOptional.get().lispLocatorSetDetails.isEmpty()) { return Collections.emptyList(); } + + return dumpOptional.get().lispLocatorSetDetails.stream() + .map(set -> { + + final String locatorSetName = toString(set.lsName); + //creates mapping for existing locator-set(if it is'nt already existing one) + if (!locatorSetContext.containsIndex(locatorSetName, context.getMappingContext())) { + locatorSetContext.addName(set.lsIndex, locatorSetName, context.getMappingContext()); + } + + LOG.trace("Locator Set with name: {}, VPP name: {} and index: {} found in VPP", + locatorSetContext.getName(set.lsIndex, context.getMappingContext()), + locatorSetName, + set.lsIndex); + + return set; + }) + .map(set -> new LocatorSetKey(toString(set.lsName))) + .collect(Collectors.toList()); } @Override diff --git a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/MapResolverCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/MapResolverCustomizer.java index 1458a2d56..faff2e2e1 100755 --- a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/MapResolverCustomizer.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/MapResolverCustomizer.java @@ -19,11 +19,11 @@ package io.fd.honeycomb.lisp.translate.read; import static io.fd.honeycomb.translate.util.read.cache.EntityDumpExecutor.NO_PARAMS; import com.google.common.base.Optional; -import io.fd.honeycomb.lisp.translate.read.dump.check.MapResolverDumpCheck; import io.fd.honeycomb.lisp.translate.read.dump.executor.MapResolversDumpExecutor; import io.fd.honeycomb.translate.read.ReadContext; import io.fd.honeycomb.translate.read.ReadFailedException; import io.fd.honeycomb.translate.spi.read.ListReaderCustomizer; +import io.fd.honeycomb.translate.util.RWUtils; import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager; import io.fd.honeycomb.translate.util.read.cache.exceptions.execution.DumpExecutionFailedException; import io.fd.honeycomb.translate.vpp.util.AddressTranslator; @@ -57,7 +57,6 @@ public class MapResolverCustomizer extends FutureJVppCustomizer super(futureJvpp); this.dumpManager = new DumpCacheManager.DumpCacheManagerBuilder() .withExecutor(new MapResolversDumpExecutor((futureJvpp))) - .withNonEmptyPredicate(new MapResolverDumpCheck()) .build(); } @@ -78,7 +77,7 @@ public class MapResolverCustomizer extends FutureJVppCustomizer throw new ReadFailedException(id, e); } - if (!dumpOptional.isPresent()) { + if (!dumpOptional.isPresent() || dumpOptional.get().lispMapResolverDetails.isEmpty()) { LOG.warn("No data dumped"); return; } @@ -86,25 +85,15 @@ public class MapResolverCustomizer extends FutureJVppCustomizer final MapResolverKey key = id.firstKeyOf(MapResolver.class); //revert searched key to match vpp's reversed order ip's final IpAddress address = reverseAddress(key.getIpAddress()); - final LispMapResolverDetailsReplyDump dump = dumpOptional.get(); - - //cannot use RWUtils.singleItemCollector(),there is some problem with generic params binding - java.util.Optional mapResolverOptional = - dump.lispMapResolverDetails.stream() + final LispMapResolverDetails mapResolverDetails = + dumpOptional.get().lispMapResolverDetails.stream() .filter(a -> address .equals(arrayToIpAddress(byteToBoolean(a.isIpv6), a.ipAddress))) - .findFirst(); - - if (mapResolverOptional.isPresent()) { - LispMapResolverDetails details = mapResolverOptional.get(); - - builder.setKey(key); - builder.setIpAddress( - arrayToIpAddress(byteToBoolean(details.isIpv6), details.ipAddress)); - } else { - LOG.warn("No data found with matching key"); - } + .collect(RWUtils.singleItemCollector()); + builder.setKey(key); + builder.setIpAddress( + arrayToIpAddress(byteToBoolean(mapResolverDetails.isIpv6), mapResolverDetails.ipAddress)); } @Override @@ -112,15 +101,14 @@ public class MapResolverCustomizer extends FutureJVppCustomizer throws ReadFailedException { LOG.debug("Dumping MapResolver..."); - Optional dumpOptional = null; + Optional dumpOptional; try { dumpOptional = dumpManager.getDump(MAP_RESOLVERS_CACHE_ID, context.getModificationCache(), NO_PARAMS); } catch (DumpExecutionFailedException e) { throw new ReadFailedException(id, e); } - if (!dumpOptional.isPresent()) { - LOG.warn("No data dumped"); + if (!dumpOptional.isPresent() || dumpOptional.get().lispMapResolverDetails.isEmpty()) { return Collections.emptyList(); } diff --git a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/RemoteMappingCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/RemoteMappingCustomizer.java index 72811fddc..50b9d7fa2 100755 --- a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/RemoteMappingCustomizer.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/RemoteMappingCustomizer.java @@ -24,7 +24,6 @@ import static io.fd.honeycomb.lisp.translate.read.dump.executor.params.MappingsD import com.google.common.base.Optional; import io.fd.honeycomb.lisp.context.util.EidMappingContext; -import io.fd.honeycomb.lisp.translate.read.dump.check.MappingsDumpCheck; import io.fd.honeycomb.lisp.translate.read.dump.executor.MappingsDumpExecutor; import io.fd.honeycomb.lisp.translate.read.dump.executor.params.MappingsDumpParams; import io.fd.honeycomb.lisp.translate.read.dump.executor.params.MappingsDumpParams.QuantityType; @@ -77,7 +76,6 @@ public class RemoteMappingCustomizer extends FutureJVppCustomizer this.dumpManager = new DumpCacheManager.DumpCacheManagerBuilder() .withExecutor(new MappingsDumpExecutor(futureJvpp)) - .withNonEmptyPredicate(new MappingsDumpCheck()) .build(); } @@ -125,24 +123,23 @@ public class RemoteMappingCustomizer extends FutureJVppCustomizer throw new ReadFailedException(id, e); } - if (replyOptional.isPresent()) { - LOG.debug("Valid dump loaded"); + if (!replyOptional.isPresent() || replyOptional.get().lispEidTableDetails.isEmpty()) { + return; + } - LispEidTableDetails details = replyOptional.get().lispEidTableDetails.stream() - .filter(a -> compareAddresses(eid.getAddress(), - getArrayAsEidLocal(valueOf(a.eidType), a.eid).getAddress())) - .collect( - RWUtils.singleItemCollector()); + LOG.debug("Valid dump loaded"); - builder.setEid(getArrayAsEidRemote(valueOf(details.eidType), details.eid)); - builder.setKey(new RemoteMappingKey(new MappingId(id.firstKeyOf(RemoteMapping.class).getId()))); - builder.setTtl(resolveTtl(details.ttl)); - builder.setAuthoritative( - new RemoteMapping.Authoritative(byteToBoolean(details.authoritative))); + LispEidTableDetails details = replyOptional.get().lispEidTableDetails.stream() + .filter(a -> compareAddresses(eid.getAddress(), + getArrayAsEidLocal(valueOf(a.eidType), a.eid).getAddress())) + .collect( + RWUtils.singleItemCollector()); - } else { - LOG.debug("No data dumped"); - } + builder.setEid(getArrayAsEidRemote(valueOf(details.eidType), details.eid)); + builder.setKey(new RemoteMappingKey(new MappingId(id.firstKeyOf(RemoteMapping.class).getId()))); + builder.setTtl(resolveTtl(details.ttl)); + builder.setAuthoritative( + new RemoteMapping.Authoritative(byteToBoolean(details.authoritative))); } //compensate ~0 as default value of ttl @@ -180,23 +177,21 @@ public class RemoteMappingCustomizer extends FutureJVppCustomizer throw new ReadFailedException(id, e); } - if (replyOptional.isPresent()) { - LOG.debug("Valid dump loaded"); - return replyOptional.get() - .lispEidTableDetails - .stream() - .filter(a -> a.vni == vni) - .map(detail -> new RemoteMappingKey( - new MappingId( - remoteMappingContext.getId( - getArrayAsEidRemote( - valueOf(detail.eidType), detail.eid), - context.getMappingContext())))) - .collect(Collectors.toList()); - } else { - LOG.debug("No data dumped"); + if (!replyOptional.isPresent() || replyOptional.get().lispEidTableDetails.isEmpty()) { return Collections.emptyList(); } + + return replyOptional.get() + .lispEidTableDetails + .stream() + .filter(a -> a.vni == vni) + .map(detail -> new RemoteMappingKey( + new MappingId( + remoteMappingContext.getId( + getArrayAsEidRemote( + valueOf(detail.eidType), detail.eid), + context.getMappingContext())))) + .collect(Collectors.toList()); } @Override diff --git a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/VniTableCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/VniTableCustomizer.java index 9acd58bbf..d0f69bf6c 100755 --- a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/VniTableCustomizer.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/VniTableCustomizer.java @@ -20,15 +20,14 @@ import static com.google.common.base.Preconditions.checkState; import static io.fd.honeycomb.translate.util.read.cache.EntityDumpExecutor.NO_PARAMS; import com.google.common.base.Optional; -import io.fd.honeycomb.lisp.translate.read.dump.check.VniTableDumpCheck; import io.fd.honeycomb.lisp.translate.read.dump.executor.VniTableDumpExecutor; import io.fd.honeycomb.translate.read.ReadContext; import io.fd.honeycomb.translate.read.ReadFailedException; import io.fd.honeycomb.translate.spi.read.ListReaderCustomizer; import io.fd.honeycomb.translate.util.RWUtils; -import io.fd.honeycomb.translate.vpp.util.FutureJVppCustomizer; import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager; import io.fd.honeycomb.translate.util.read.cache.exceptions.execution.DumpExecutionFailedException; +import io.fd.honeycomb.translate.vpp.util.FutureJVppCustomizer; import java.util.Collections; import java.util.List; import java.util.stream.Collectors; @@ -61,7 +60,6 @@ public class VniTableCustomizer extends FutureJVppCustomizer super(futureJvpp); this.dumpManager = new DumpCacheManager.DumpCacheManagerBuilder() .withExecutor(new VniTableDumpExecutor(futureJvpp)) - .withNonEmptyPredicate(new VniTableDumpCheck()) .build(); } @@ -95,18 +93,12 @@ public class VniTableCustomizer extends FutureJVppCustomizer throw new ReadFailedException(id, e); } - if (!optionalReply.isPresent()) { + if (!optionalReply.isPresent() || optionalReply.get().lispEidTableMapDetails.isEmpty()) { return Collections.emptyList(); } - LispEidTableMapDetailsReplyDump reply = optionalReply.get(); - LOG.debug("Dumped ..."); - - // Just transform received details into a list of keys - final List collect = reply.lispEidTableMapDetails.stream().map(VniTableCustomizer::detailsToKey) + return optionalReply.get().lispEidTableMapDetails.stream().map(VniTableCustomizer::detailsToKey) .collect(Collectors.toList()); - LOG.debug("All IDs found: {} ...", collect); - return collect; } @Override @@ -124,12 +116,12 @@ public class VniTableCustomizer extends FutureJVppCustomizer throw new ReadFailedException(id, e); } - if (!optionalReply.isPresent()) { + if (!optionalReply.isPresent() || optionalReply.get().lispEidTableMapDetails.isEmpty()) { return; } //transforming right away to single detail(specific request should do the magic) - LispEidTableMapDetails details = + final LispEidTableMapDetails details = optionalReply.get().lispEidTableMapDetails.stream().filter(a -> detailsToKey(a).equals(key)) .collect(RWUtils.singleItemCollector()); diff --git a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/check/LocatorDumpCheck.java b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/check/LocatorDumpCheck.java deleted file mode 100644 index 762aa3830..000000000 --- a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/check/LocatorDumpCheck.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.honeycomb.lisp.translate.read.dump.check; - -import io.fd.honeycomb.translate.util.read.cache.EntityDumpNonEmptyCheck; -import io.fd.honeycomb.translate.util.read.cache.exceptions.check.DumpCheckFailedException; -import io.fd.honeycomb.translate.util.read.cache.exceptions.check.i.DumpEmptyException; -import org.openvpp.jvpp.core.dto.LispLocatorDetailsReplyDump; - -public class LocatorDumpCheck implements EntityDumpNonEmptyCheck { - - @Override - public void assertNotEmpty(final LispLocatorDetailsReplyDump data) throws DumpCheckFailedException { - - if (data == null) { - throw new DumpEmptyException("Locator dump is null"); - } - - if (data.lispLocatorDetails == null) { - throw new DumpEmptyException("Locator dump is empty"); - } - } -} diff --git a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/check/LocatorSetsDumpCheck.java b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/check/LocatorSetsDumpCheck.java deleted file mode 100755 index a24341460..000000000 --- a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/check/LocatorSetsDumpCheck.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.honeycomb.lisp.translate.read.dump.check; - - -import io.fd.honeycomb.translate.util.read.cache.EntityDumpNonEmptyCheck; -import io.fd.honeycomb.translate.util.read.cache.exceptions.check.DumpCheckFailedException; -import io.fd.honeycomb.translate.util.read.cache.exceptions.check.i.DumpEmptyException; -import org.openvpp.jvpp.core.dto.LispLocatorSetDetailsReplyDump; - -public class LocatorSetsDumpCheck implements EntityDumpNonEmptyCheck { - - @Override - public void assertNotEmpty(final LispLocatorSetDetailsReplyDump data) throws DumpCheckFailedException { - - if (data == null) { - throw new DumpEmptyException("Locator sets dump is null"); - } - - if (data.lispLocatorSetDetails == null) { - throw new DumpEmptyException("Locator sets dump is empty"); - } - } -} diff --git a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/check/MapResolverDumpCheck.java b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/check/MapResolverDumpCheck.java deleted file mode 100755 index 18fc9c882..000000000 --- a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/check/MapResolverDumpCheck.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.honeycomb.lisp.translate.read.dump.check; - - -import io.fd.honeycomb.translate.util.read.cache.EntityDumpNonEmptyCheck; -import io.fd.honeycomb.translate.util.read.cache.exceptions.check.DumpCheckFailedException; -import io.fd.honeycomb.translate.util.read.cache.exceptions.check.i.DumpEmptyException; -import org.openvpp.jvpp.core.dto.LispMapResolverDetailsReplyDump; - -public class MapResolverDumpCheck implements EntityDumpNonEmptyCheck { - - @Override - public void assertNotEmpty(final LispMapResolverDetailsReplyDump data) throws DumpCheckFailedException { - if (data == null) { - throw new DumpEmptyException("Map resolvers dump is null"); - } - - if (data.lispMapResolverDetails == null) { - throw new DumpEmptyException("Map resolvers dump is empty"); - } - } -} diff --git a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/check/MappingsDumpCheck.java b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/check/MappingsDumpCheck.java deleted file mode 100755 index cf1d0210d..000000000 --- a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/check/MappingsDumpCheck.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.honeycomb.lisp.translate.read.dump.check; - - -import io.fd.honeycomb.translate.util.read.cache.EntityDumpNonEmptyCheck; -import io.fd.honeycomb.translate.util.read.cache.exceptions.check.DumpCheckFailedException; -import io.fd.honeycomb.translate.util.read.cache.exceptions.check.i.DumpEmptyException; -import org.openvpp.jvpp.core.dto.LispEidTableDetailsReplyDump; - -/** - * Common dump check for both local and remote mappings - */ -public class MappingsDumpCheck implements EntityDumpNonEmptyCheck { - - @Override - public void assertNotEmpty(final LispEidTableDetailsReplyDump data) throws DumpCheckFailedException { - if (data == null) { - throw new DumpEmptyException("Mappings dump is null"); - } - - if (data.lispEidTableDetails == null) { - throw new DumpEmptyException("Mappings dump is empty"); - } - } -} diff --git a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/check/VniTableDumpCheck.java b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/check/VniTableDumpCheck.java deleted file mode 100755 index bb5c03321..000000000 --- a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/check/VniTableDumpCheck.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.honeycomb.lisp.translate.read.dump.check; - - -import io.fd.honeycomb.translate.util.read.cache.EntityDumpNonEmptyCheck; -import io.fd.honeycomb.translate.util.read.cache.exceptions.check.DumpCheckFailedException; -import io.fd.honeycomb.translate.util.read.cache.exceptions.check.i.DumpEmptyException; -import org.openvpp.jvpp.core.dto.LispEidTableMapDetailsReplyDump; - -public class VniTableDumpCheck implements EntityDumpNonEmptyCheck { - - @Override - public void assertNotEmpty(final LispEidTableMapDetailsReplyDump data) throws DumpCheckFailedException { - if (data == null) { - throw new DumpEmptyException("Vni table dump is null"); - } - - if (data.lispEidTableMapDetails == null) { - throw new DumpEmptyException("Bni table dump is empty"); - } - } -} diff --git a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/write/LocatorSetCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/write/LocatorSetCustomizer.java index 105294e90..a310e9e46 100755 --- a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/write/LocatorSetCustomizer.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/write/LocatorSetCustomizer.java @@ -21,7 +21,6 @@ import static com.google.common.base.Preconditions.checkState; import static java.nio.charset.StandardCharsets.UTF_8; import com.google.common.base.Optional; -import io.fd.honeycomb.lisp.translate.read.dump.check.LocatorSetsDumpCheck; import io.fd.honeycomb.lisp.translate.read.dump.executor.LocatorSetsDumpExecutor; import io.fd.honeycomb.translate.ModificationCache; import io.fd.honeycomb.translate.spi.write.ListWriterCustomizer; @@ -67,7 +66,6 @@ public class LocatorSetCustomizer extends FutureJVppCustomizer this.locatorSetContext = checkNotNull(locatorSetContext, "Locator set context cannot be null"); this.dumpManager = new DumpCacheManager.DumpCacheManagerBuilder() .withExecutor(new LocatorSetsDumpExecutor(futureJvpp)) - .withNonEmptyPredicate(new LocatorSetsDumpCheck()) .build(); } diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/dump/check/LocatorDumpCheckTest.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/dump/check/LocatorDumpCheckTest.java deleted file mode 100644 index 8c52eb930..000000000 --- a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/dump/check/LocatorDumpCheckTest.java +++ /dev/null @@ -1,25 +0,0 @@ -package io.fd.honeycomb.lisp.translate.read.dump.check; - -import io.fd.honeycomb.vpp.test.read.DumpCheckTest; -import org.openvpp.jvpp.core.dto.LispLocatorDetailsReplyDump; - -public class LocatorDumpCheckTest extends DumpCheckTest { - - @Override - protected LocatorDumpCheck initCheck() { - return new LocatorDumpCheck(); - } - - @Override - protected LispLocatorDetailsReplyDump initEmptyData() { - final LispLocatorDetailsReplyDump replyDump = new LispLocatorDetailsReplyDump(); - replyDump.lispLocatorDetails = null; - - return replyDump; - } - - @Override - protected LispLocatorDetailsReplyDump initValidData() { - return new LispLocatorDetailsReplyDump(); - } -} \ No newline at end of file diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/dump/check/LocatorSetsDumpCheckTest.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/dump/check/LocatorSetsDumpCheckTest.java deleted file mode 100644 index f932c22e5..000000000 --- a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/dump/check/LocatorSetsDumpCheckTest.java +++ /dev/null @@ -1,26 +0,0 @@ -package io.fd.honeycomb.lisp.translate.read.dump.check; - -import io.fd.honeycomb.vpp.test.read.DumpCheckTest; -import org.openvpp.jvpp.core.dto.LispLocatorSetDetailsReplyDump; - - -public class LocatorSetsDumpCheckTest extends DumpCheckTest { - - @Override - protected LocatorSetsDumpCheck initCheck() { - return new LocatorSetsDumpCheck(); - } - - @Override - protected LispLocatorSetDetailsReplyDump initEmptyData() { - final LispLocatorSetDetailsReplyDump replyDump = new LispLocatorSetDetailsReplyDump(); - replyDump.lispLocatorSetDetails = null; - - return replyDump; - } - - @Override - protected LispLocatorSetDetailsReplyDump initValidData() { - return new LispLocatorSetDetailsReplyDump(); - } -} \ No newline at end of file diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/dump/check/MapResolverDumpCheckTest.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/dump/check/MapResolverDumpCheckTest.java deleted file mode 100644 index 236f3c494..000000000 --- a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/dump/check/MapResolverDumpCheckTest.java +++ /dev/null @@ -1,26 +0,0 @@ -package io.fd.honeycomb.lisp.translate.read.dump.check; - -import io.fd.honeycomb.vpp.test.read.DumpCheckTest; -import org.openvpp.jvpp.core.dto.LispMapResolverDetailsReplyDump; - - -public class MapResolverDumpCheckTest extends DumpCheckTest { - - @Override - protected MapResolverDumpCheck initCheck() { - return new MapResolverDumpCheck(); - } - - @Override - protected LispMapResolverDetailsReplyDump initEmptyData() { - final LispMapResolverDetailsReplyDump replyDump = new LispMapResolverDetailsReplyDump(); - replyDump.lispMapResolverDetails = null; - - return replyDump; - } - - @Override - protected LispMapResolverDetailsReplyDump initValidData() { - return new LispMapResolverDetailsReplyDump(); - } -} \ No newline at end of file diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/dump/check/MappingsDumpCheckTest.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/dump/check/MappingsDumpCheckTest.java deleted file mode 100644 index 6378e5f6b..000000000 --- a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/dump/check/MappingsDumpCheckTest.java +++ /dev/null @@ -1,26 +0,0 @@ -package io.fd.honeycomb.lisp.translate.read.dump.check; - -import io.fd.honeycomb.vpp.test.read.DumpCheckTest; -import org.openvpp.jvpp.core.dto.LispEidTableDetailsReplyDump; - - -public class MappingsDumpCheckTest extends DumpCheckTest { - - @Override - protected MappingsDumpCheck initCheck() { - return new MappingsDumpCheck(); - } - - @Override - protected LispEidTableDetailsReplyDump initEmptyData() { - final LispEidTableDetailsReplyDump replyDump = new LispEidTableDetailsReplyDump(); - replyDump.lispEidTableDetails = null; - - return replyDump; - } - - @Override - protected LispEidTableDetailsReplyDump initValidData() { - return new LispEidTableDetailsReplyDump(); - } -} \ No newline at end of file diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/dump/check/VniTableDumpCheckTest.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/dump/check/VniTableDumpCheckTest.java deleted file mode 100644 index 5f70e8a1e..000000000 --- a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/dump/check/VniTableDumpCheckTest.java +++ /dev/null @@ -1,26 +0,0 @@ -package io.fd.honeycomb.lisp.translate.read.dump.check; - -import io.fd.honeycomb.vpp.test.read.DumpCheckTest; -import org.openvpp.jvpp.core.dto.LispEidTableMapDetailsReplyDump; - - -public class VniTableDumpCheckTest extends DumpCheckTest { - - @Override - protected VniTableDumpCheck initCheck() { - return new VniTableDumpCheck(); - } - - @Override - protected LispEidTableMapDetailsReplyDump initEmptyData() { - final LispEidTableMapDetailsReplyDump replyDump = new LispEidTableMapDetailsReplyDump(); - replyDump.lispEidTableMapDetails = null; - - return replyDump; - } - - @Override - protected LispEidTableMapDetailsReplyDump initValidData() { - return new LispEidTableMapDetailsReplyDump(); - } -} \ No newline at end of file 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 16aa5fe17..ca191d46c 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 @@ -25,7 +25,6 @@ import io.fd.honeycomb.translate.spi.read.ListReaderCustomizer; import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager; import io.fd.honeycomb.translate.util.read.cache.exceptions.execution.DumpExecutionFailedException; import io.fd.honeycomb.translate.v3po.interfacesstate.ip.dump.AddressDumpExecutor; -import io.fd.honeycomb.translate.v3po.interfacesstate.ip.dump.check.AddressDumpCheck; import io.fd.honeycomb.translate.v3po.interfacesstate.ip.dump.params.AddressDumpParams; import io.fd.honeycomb.translate.vpp.util.FutureJVppCustomizer; import io.fd.honeycomb.translate.vpp.util.NamingContext; @@ -64,7 +63,6 @@ public class Ipv4AddressCustomizer extends FutureJVppCustomizer this.interfaceContext = checkNotNull(interfaceContext, "interfaceContext should not be null"); this.dumpManager = new DumpCacheManager.DumpCacheManagerBuilder() .withExecutor(new AddressDumpExecutor(futureJVppCore)) - .withNonEmptyPredicate(new AddressDumpCheck()) .build(); } @@ -91,24 +89,23 @@ public class Ipv4AddressCustomizer extends FutureJVppCustomizer throw new ReadFailedException(id, e); } - if (dumpOptional.isPresent()) { - final Optional ipAddressDetails = - findIpAddressDetailsByIp(dumpOptional, id.firstKeyOf(Address.class).getIp()); - - if (ipAddressDetails.isPresent()) { - final IpAddressDetails detail = ipAddressDetails.get(); - builder.setIp(arrayToIpv4AddressNoZone(detail.ip)) - .setSubnet( - new PrefixLengthBuilder().setPrefixLength(Short.valueOf(detail.prefixLength)).build()); - - if (LOG.isDebugEnabled()) { - LOG.debug("Attributes for {} interface (id={}) address {} successfully read: {}", - interfaceName, interfaceIndex, id, builder.build()); - } + if (!dumpOptional.isPresent() || dumpOptional.get().ipAddressDetails.isEmpty()) { + return; + } + final Optional ipAddressDetails = + findIpAddressDetailsByIp(dumpOptional, id.firstKeyOf(Address.class).getIp()); + + if (ipAddressDetails.isPresent()) { + final IpAddressDetails detail = ipAddressDetails.get(); + builder.setIp(arrayToIpv4AddressNoZone(detail.ip)) + .setSubnet( + new PrefixLengthBuilder().setPrefixLength(Short.valueOf(detail.prefixLength)).build()); + + if (LOG.isDebugEnabled()) { + LOG.debug("Attributes for {} interface (id={}) address {} successfully read: {}", + interfaceName, interfaceIndex, id, builder.build()); } } - - } @Override 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 3693433da..75791865e 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 @@ -25,7 +25,6 @@ import io.fd.honeycomb.translate.spi.read.ListReaderCustomizer; import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager; import io.fd.honeycomb.translate.util.read.cache.exceptions.execution.DumpExecutionFailedException; import io.fd.honeycomb.translate.v3po.interfacesstate.ip.dump.AddressDumpExecutor; -import io.fd.honeycomb.translate.v3po.interfacesstate.ip.dump.check.AddressDumpCheck; import io.fd.honeycomb.translate.v3po.interfacesstate.ip.dump.params.AddressDumpParams; import io.fd.honeycomb.translate.vpp.util.FutureJVppCustomizer; import io.fd.honeycomb.translate.vpp.util.NamingContext; @@ -66,7 +65,6 @@ public class SubInterfaceIpv4AddressCustomizer extends FutureJVppCustomizer this.interfaceContext = checkNotNull(interfaceContext, "interfaceContext should not be null"); this.dumpManager = new DumpCacheManager.DumpCacheManagerBuilder() .withExecutor(new AddressDumpExecutor(futureJVppCore)) - .withNonEmptyPredicate(new AddressDumpCheck()) .build(); } diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/dump/check/AddressDumpCheck.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/dump/check/AddressDumpCheck.java deleted file mode 100644 index d6ab28db0..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/dump/check/AddressDumpCheck.java +++ /dev/null @@ -1,16 +0,0 @@ -package io.fd.honeycomb.translate.v3po.interfacesstate.ip.dump.check; - -import io.fd.honeycomb.translate.util.read.cache.EntityDumpNonEmptyCheck; -import io.fd.honeycomb.translate.util.read.cache.exceptions.check.DumpCheckFailedException; -import io.fd.honeycomb.translate.util.read.cache.exceptions.check.i.DumpEmptyException; -import org.openvpp.jvpp.core.dto.IpAddressDetailsReplyDump; - -public class AddressDumpCheck implements EntityDumpNonEmptyCheck { - - @Override - public void assertNotEmpty(final IpAddressDetailsReplyDump data) throws DumpCheckFailedException { - if (data == null || data.ipAddressDetails == null) { - throw new DumpEmptyException("Invalid data dumped"); - } - } -} diff --git a/vpp-common/vpp-translate-test/src/main/java/io/fd/honeycomb/vpp/test/read/DumpCheckTest.java b/vpp-common/vpp-translate-test/src/main/java/io/fd/honeycomb/vpp/test/read/DumpCheckTest.java deleted file mode 100644 index a21f49b6e..000000000 --- a/vpp-common/vpp-translate-test/src/main/java/io/fd/honeycomb/vpp/test/read/DumpCheckTest.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.honeycomb.vpp.test.read; - - -import io.fd.honeycomb.translate.util.read.cache.EntityDumpNonEmptyCheck; -import io.fd.honeycomb.translate.util.read.cache.exceptions.check.DumpCheckFailedException; -import io.fd.honeycomb.translate.util.read.cache.exceptions.check.i.DumpEmptyException; -import org.junit.Before; -import org.junit.Test; - -/** - * Generic test for classes implementing {@link EntityDumpNonEmptyCheck} - * - * @param implementations of {@link EntityDumpNonEmptyCheck}, that will be tested - * @param data node handled by {@link EntityDumpNonEmptyCheck} - */ -public abstract class DumpCheckTest, U> { - - private T check; - private U emptyData; - private U validData; - - @Before - public void setupParent() { - this.check = initCheck(); - this.emptyData = initEmptyData(); - this.validData = initValidData(); - } - - @Test(expected = DumpEmptyException.class) - public void testWithNull() throws DumpCheckFailedException { - check.assertNotEmpty(null); - } - - @Test(expected = DumpEmptyException.class) - public void testWithEmpty() throws DumpCheckFailedException { - check.assertNotEmpty(emptyData); - } - - @Test - public void testWithValid() throws DumpCheckFailedException { - check.assertNotEmpty(validData); - } - - /** - * Initialize new {@link EntityDumpNonEmptyCheck}. - */ - protected abstract T initCheck(); - - /** - * Initialize data that should throw {@link DumpEmptyException} , - * while beeing processed by {@link EntityDumpNonEmptyCheck} - */ - protected abstract U initEmptyData(); - - /** - * Initialize data that should pass without exception , - * while beeing processed by {@link EntityDumpNonEmptyCheck} - */ - protected abstract U initValidData(); - - - protected T getCheck() { - return this.check; - } -} diff --git a/vpp-common/vpp-translate-utils/src/test/java/io/fd/honeycomb/translate/vpp/util/cache/DumpCacheManagerTest.java b/vpp-common/vpp-translate-utils/src/test/java/io/fd/honeycomb/translate/vpp/util/cache/DumpCacheManagerTest.java index 72924ac31..abb9866ec 100644 --- a/vpp-common/vpp-translate-utils/src/test/java/io/fd/honeycomb/translate/vpp/util/cache/DumpCacheManagerTest.java +++ b/vpp-common/vpp-translate-utils/src/test/java/io/fd/honeycomb/translate/vpp/util/cache/DumpCacheManagerTest.java @@ -16,6 +16,7 @@ package io.fd.honeycomb.translate.vpp.util.cache; +import static io.fd.honeycomb.translate.util.read.cache.EntityDumpExecutor.NO_PARAMS; import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.when; @@ -23,9 +24,7 @@ import com.google.common.base.Optional; import io.fd.honeycomb.translate.ModificationCache; import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager; import io.fd.honeycomb.translate.util.read.cache.EntityDumpExecutor; -import io.fd.honeycomb.translate.util.read.cache.EntityDumpNonEmptyCheck; import io.fd.honeycomb.translate.util.read.cache.EntityDumpPostProcessingFunction; -import io.fd.honeycomb.translate.util.read.cache.exceptions.check.i.DumpEmptyException; import io.fd.honeycomb.translate.util.read.cache.exceptions.execution.DumpExecutionFailedException; import org.junit.Before; import org.junit.Test; @@ -52,19 +51,16 @@ public class DumpCacheManagerTest { managerPositive = new DumpCacheManager.DumpCacheManagerBuilder() .withExecutor(executor) - .withNonEmptyPredicate(createPositivePredicate()) .build(); managerPositiveWithPostProcessing = new DumpCacheManager.DumpCacheManagerBuilder() .withExecutor(executor) - .withNonEmptyPredicate(createPositivePredicate()) .withPostProcessingFunction(createPostProcessor()) .build(); managerNegative = new DumpCacheManager.DumpCacheManagerBuilder() .withExecutor(executor) - .withNonEmptyPredicate(createNegativePredicate()) .build(); cache = new ModificationCache(); @@ -75,28 +71,34 @@ public class DumpCacheManagerTest { */ @Test public void testCaching() throws DumpExecutionFailedException { + final IpDetailsReplyDump stage1Data = new IpDetailsReplyDump(); + // executor cant return null data + when(executor.executeDump(NO_PARAMS)).thenReturn(new IpDetailsReplyDump()); - Optional stage1Optional = managerNegative.getDump(KEY, cache, null); + final Optional stage1Optional = managerNegative.getDump(KEY, cache, NO_PARAMS); - //this is first call so instance should be from executor - assertEquals(false, stage1Optional.isPresent()); - assertEquals(false, cache.containsKey(KEY)); + // this is first call so instance should be from executor + // and it should be cached after calling executor + assertEquals(true, stage1Optional.isPresent()); + assertEquals(stage1Data, stage1Optional.get()); + assertEquals(true, cache.containsKey(KEY)); + assertEquals(stage1Data, cache.get(KEY)); //rebind executor with other data IpDetailsReplyDump stage2LoadedDump = new IpDetailsReplyDump(); - when(executor.executeDump(null)).thenReturn(stage2LoadedDump); + when(executor.executeDump(NO_PARAMS)).thenReturn(stage2LoadedDump); - Optional stage2Optional = managerPositive.getDump(KEY, cache, null); + final Optional stage2Optional = managerPositive.getDump(KEY, cache, NO_PARAMS); assertEquals(true, stage2Optional.isPresent()); assertEquals(stage2LoadedDump, stage2Optional.get()); //rebind executor with other data IpDetailsReplyDump stage3LoadedDump = new IpDetailsReplyDump(); - when(executor.executeDump(null)).thenReturn(stage3LoadedDump); + when(executor.executeDump(NO_PARAMS)).thenReturn(stage3LoadedDump); - Optional stage3Optional = managerPositive.getDump(KEY, cache, null); + final Optional stage3Optional = managerPositive.getDump(KEY, cache, NO_PARAMS); assertEquals(true, stage3Optional.isPresent()); //check if it returns instance cached from previous stage assertEquals(stage2LoadedDump, stage3Optional.get()); @@ -111,25 +113,13 @@ public class DumpCacheManagerTest { when(executor.executeDump(null)).thenReturn(dump); - Optional optionalDump = managerPositiveWithPostProcessing.getDump(KEY, cache, null); + Optional optionalDump = managerPositiveWithPostProcessing.getDump(KEY, cache, NO_PARAMS); assertEquals(true, optionalDump.isPresent()); assertEquals(1, optionalDump.get().ipDetails.size()); assertEquals(7, optionalDump.get().ipDetails.get(0).swIfIndex); } - private EntityDumpNonEmptyCheck createNegativePredicate() { - return data -> { - throw new DumpEmptyException("Empty dump", new IllegalArgumentException()); - }; - } - - private EntityDumpNonEmptyCheck createPositivePredicate() { - return data -> { - //DO NOTHING - }; - } - private EntityDumpPostProcessingFunction createPostProcessor() { return ipDetailsReplyDump -> { IpDetailsReplyDump modified = new IpDetailsReplyDump(); -- cgit 1.2.3-korg