diff options
author | Jan Srnicek <jsrnicek@cisco.com> | 2016-10-06 08:54:02 +0200 |
---|---|---|
committer | Jan Srnicek <jsrnicek@cisco.com> | 2016-10-06 08:54:02 +0200 |
commit | fb6666efe7b6009528e98702efc66e9118011174 (patch) | |
tree | e7dd2b205552c1a756f7f8410fc11536162db9aa /infra/translate-utils/src/main | |
parent | cf15cfe3593ec4c02cdb1121649bf95d19814e0c (diff) |
HONEYCOMB-236 - Unified read/write exceptions
Change-Id: Idde761d0c0c2c4d96555ef94dbdaa87fad889493
Signed-off-by: Jan Srnicek <jsrnicek@cisco.com>
Diffstat (limited to 'infra/translate-utils/src/main')
5 files changed, 18 insertions, 105 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 e5016657a..f5895038e 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,9 +20,10 @@ 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.execution.DumpExecutionFailedException; +import io.fd.honeycomb.translate.read.ReadFailedException; import io.fd.honeycomb.translate.util.read.cache.noop.NoopDumpPostProcessingFunction; import javax.annotation.Nonnull; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -44,9 +45,18 @@ public final class DumpCacheManager<T, U> { /** * Returns {@link Optional<T>} of dump + * + * @param identifier identifier for origin of dumping context + * @param entityKey key that defines scope for caching + * @param cache modification cache of current transaction + * @param dumpParams parameters to configure dump request + * @throws ReadFailedException if execution of dumping request failed + * @returns If present in cache ,returns cached instance, if not, tries to dump data using provided executor, otherwise + * Optional.absent() */ - public Optional<T> getDump(@Nonnull String entityKey, @Nonnull ModificationCache cache, final U dumpParams) - throws DumpExecutionFailedException { + public Optional<T> getDump(@Nonnull final InstanceIdentifier<?> identifier, @Nonnull String entityKey, + @Nonnull ModificationCache cache, final U dumpParams) + throws ReadFailedException { // this key binding to every log has its logic ,because every customizer have its own cache manager and if // there is need for debugging/fixing some complex call with a lot of data,you can get lost in those logs @@ -57,7 +67,7 @@ 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 = postProcessor.apply(dumpExecutor.executeDump(dumpParams)); + dump = postProcessor.apply(dumpExecutor.executeDump(identifier, 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); 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 05c455521..3a7062cfd 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 @@ -16,9 +16,10 @@ package io.fd.honeycomb.translate.util.read.cache; -import io.fd.honeycomb.translate.util.read.cache.exceptions.execution.DumpExecutionFailedException; +import io.fd.honeycomb.translate.read.ReadFailedException; import javax.annotation.Nonnull; import javax.annotation.concurrent.ThreadSafe; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; /** * Generic interface for classes that return dumps for Data objects. @@ -33,8 +34,8 @@ public interface EntityDumpExecutor<T, U> { * Performs dump on {@link T} entity. * * @return dump of specified {@link T} entity - * @throws DumpExecutionFailedException when dump fails + * @throws ReadFailedException when dump fails */ @Nonnull - T executeDump(final U params) throws DumpExecutionFailedException; + T executeDump(final InstanceIdentifier<?> identifier, final U params) throws ReadFailedException; } diff --git a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/cache/exceptions/execution/DumpExecutionFailedException.java b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/cache/exceptions/execution/DumpExecutionFailedException.java deleted file mode 100644 index 806a5500c..000000000 --- a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/cache/exceptions/execution/DumpExecutionFailedException.java +++ /dev/null @@ -1,27 +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.execution; - -/** - * Default parent for all exceptions connected to dumping of data - */ -public abstract class DumpExecutionFailedException extends Exception { - - public DumpExecutionFailedException(String message, Exception cause) { - super(message, cause); - } -} 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 deleted file mode 100644 index 6e09e8d66..000000000 --- a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/cache/exceptions/execution/i/DumpCallFailedException.java +++ /dev/null @@ -1,36 +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.execution.i; - -import io.fd.honeycomb.translate.util.read.cache.exceptions.execution.DumpExecutionFailedException; - -/** - * 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) { - super(message, cause); - } - - public static final DumpCallFailedException wrapFailedCallException(String message, Exception cause) { - return new DumpCallFailedException(message, cause); - } -} diff --git a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/cache/exceptions/execution/i/DumpTimeoutException.java b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/cache/exceptions/execution/i/DumpTimeoutException.java deleted file mode 100644 index be440ba4f..000000000 --- a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/cache/exceptions/execution/i/DumpTimeoutException.java +++ /dev/null @@ -1,35 +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.execution.i; - -import io.fd.honeycomb.translate.util.read.cache.exceptions.execution.DumpExecutionFailedException; -import java.util.concurrent.TimeoutException; - -/** - * Exception thrown when dump call ends in timeout - */ -public class DumpTimeoutException extends DumpExecutionFailedException { - - public DumpTimeoutException(String message, TimeoutException cause) { - super(message, cause); - - } - - public static final DumpTimeoutException wrapTimeoutException(String message, TimeoutException cause) { - return new DumpTimeoutException(message, cause); - } -} |