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 ++ 6 files changed, 12 insertions(+), 129 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 (limited to 'infra/translate-utils') 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) { -- cgit 1.2.3-korg