summaryrefslogtreecommitdiffstats
path: root/infra/translate-utils/src/main
diff options
context:
space:
mode:
authorJan Srnicek <jsrnicek@cisco.com>2016-09-28 14:42:39 +0200
committerMarek Gradzki <mgradzki@cisco.com>2016-09-28 13:02:01 +0000
commit58961d7103e1c7dfd411ab00ce3905e2e5fec94b (patch)
tree79a53f4e7f1ef6bf51aa2d2a611ea8a0bda4ed80 /infra/translate-utils/src/main
parent4a7047d82d70dd07684599b75cfd73c961d15108 (diff)
HONEYCOMB-210 - DumpEmptyCheck removed
Change-Id: I95ea94c3a1a581753f7eb667af7aacde832c21fd Signed-off-by: Jan Srnicek <jsrnicek@cisco.com>
Diffstat (limited to 'infra/translate-utils/src/main')
-rw-r--r--infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/cache/DumpCacheManager.java28
-rw-r--r--infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/cache/EntityDumpExecutor.java8
-rw-r--r--infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/cache/EntityDumpNonEmptyCheck.java31
-rw-r--r--infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/cache/exceptions/check/DumpCheckFailedException.java31
-rw-r--r--infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/cache/exceptions/check/i/DumpEmptyException.java40
-rw-r--r--infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/cache/exceptions/execution/i/DumpCallFailedException.java3
6 files changed, 12 insertions, 129 deletions
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<T, U> {
private static final Logger LOG = LoggerFactory.getLogger(DumpCacheManager.class);
private final EntityDumpExecutor<T, U> dumpExecutor;
- private final EntityDumpNonEmptyCheck<T> dumpNonEmptyCheck;
private final EntityDumpPostProcessingFunction<T> postProcessor;
private DumpCacheManager(DumpCacheManagerBuilder<T, U> builder) {
this.dumpExecutor = builder.dumpExecutor;
- this.dumpNonEmptyCheck = builder.dumpNonEmptyCheck;
this.postProcessor = builder.postProcessingFunction;
}
@@ -60,24 +57,14 @@ public final class DumpCacheManager<T, U> {
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<T, U> {
public static final class DumpCacheManagerBuilder<T, U> {
private EntityDumpExecutor<T, U> dumpExecutor;
- private EntityDumpNonEmptyCheck<T> dumpNonEmptyCheck;
private EntityDumpPostProcessingFunction<T> postProcessingFunction;
public DumpCacheManagerBuilder() {
@@ -98,11 +84,6 @@ public final class DumpCacheManager<T, U> {
return this;
}
- public DumpCacheManagerBuilder<T, U> withNonEmptyPredicate(@Nonnull EntityDumpNonEmptyCheck<T> check) {
- this.dumpNonEmptyCheck = check;
- return this;
- }
-
public DumpCacheManagerBuilder<T, U> withPostProcessingFunction(
EntityDumpPostProcessingFunction<T> postProcessingFunction) {
this.postProcessingFunction = postProcessingFunction;
@@ -111,7 +92,6 @@ public final class DumpCacheManager<T, U> {
public DumpCacheManager<T, U> 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<T, U> {
- 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<T> {
-
- /**
- * 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) {