summaryrefslogtreecommitdiffstats
path: root/v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/cache
diff options
context:
space:
mode:
Diffstat (limited to 'v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/cache')
-rw-r--r--v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/cache/DumpCacheManager.java124
-rw-r--r--v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/cache/EntityDumpExecutor.java41
-rw-r--r--v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/cache/EntityDumpNonEmptyCheck.java33
-rw-r--r--v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/cache/EntityDumpPostProcessingFunction.java36
-rw-r--r--v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/cache/exceptions/check/DumpCheckFailedException.java31
-rw-r--r--v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/cache/exceptions/check/i/DumpEmptyException.java40
-rw-r--r--v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/cache/exceptions/execution/DumpExecutionFailedException.java27
-rw-r--r--v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/cache/exceptions/execution/i/DumpCallFailedException.java34
-rw-r--r--v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/cache/exceptions/execution/i/DumpTimeoutException.java35
-rw-r--r--v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/cache/noop/NoopDumpPostProcessingFunction.java33
10 files changed, 0 insertions, 434 deletions
diff --git a/v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/cache/DumpCacheManager.java b/v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/cache/DumpCacheManager.java
deleted file mode 100644
index 9486ce171..000000000
--- a/v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/cache/DumpCacheManager.java
+++ /dev/null
@@ -1,124 +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.v3po.translate.v3po.util.cache;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-
-import com.google.common.base.Optional;
-import io.fd.honeycomb.v3po.translate.ModificationCache;
-import io.fd.honeycomb.v3po.translate.v3po.util.cache.exceptions.check.DumpCheckFailedException;
-import io.fd.honeycomb.v3po.translate.v3po.util.cache.exceptions.execution.DumpExecutionFailedException;
-import io.fd.honeycomb.v3po.translate.v3po.util.cache.noop.NoopDumpPostProcessingFunction;
-import javax.annotation.Nonnull;
-import org.openvpp.jvpp.dto.JVppReplyDump;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Manager responsible for returning Data object dumps<br> either from cache or by invoking specified {@link
- * EntityDumpExecutor}
- */
-public final class DumpCacheManager<T extends JVppReplyDump, 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 builder) {
- this.dumpExecutor = builder.dumpExecutor;
- this.dumpNonEmptyCheck = builder.dumpNonEmptyCheck;
- this.postProcessor = builder.postProcessingFunction;
- }
-
- /**
- * Returns {@link Optional<T>} of dump
- */
- public Optional<T> getDump(@Nonnull String entityKey, @Nonnull ModificationCache cache)
- throws DumpExecutionFailedException {
-
- //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
- LOG.debug("Loading dump for KEY[{}]", entityKey);
-
- T dump = (T) cache.get(entityKey);
-
- if (dump == null) {
- LOG.debug("Dump for KEY[{}] not present in cache,invoking dump executor", entityKey);
-
- dump = dumpExecutor.executeDump();
-
- //this is not a critical exception, so its only logged here
- try {
- dumpNonEmptyCheck.assertNotEmpty(dump);
- } catch (DumpCheckFailedException e) {
- LOG.warn("Dump for KEY[{}] has been resolved as empty", entityKey, e);
- return Optional.absent();
- }
-
- //no need to check if post processor active,if wasnt set,default no-op will be used
- LOG.debug("Post-processing dump for KEY[{}]", entityKey);
- dump = postProcessor.apply(dump);
-
- LOG.debug("Caching dump for KEY[{}]", entityKey);
- cache.put(entityKey, dump);
- return Optional.of(dump);
- } else {
- return Optional.of(dump);
- }
- }
-
- public static final class DumpCacheManagerBuilder<T extends JVppReplyDump, U> {
-
- private EntityDumpExecutor<T, U> dumpExecutor;
- private EntityDumpNonEmptyCheck<T> dumpNonEmptyCheck;
- private EntityDumpPostProcessingFunction<T> postProcessingFunction;
-
- public DumpCacheManagerBuilder() {
- //for cases when user does not set specific post-processor
- postProcessingFunction = new NoopDumpPostProcessingFunction<T>();
- }
-
- public DumpCacheManagerBuilder<T, U> withExecutor(@Nonnull EntityDumpExecutor<T, U> executor) {
- this.dumpExecutor = executor;
- return this;
- }
-
- public DumpCacheManagerBuilder<T, U> withNonEmptyPredicate(@Nonnull EntityDumpNonEmptyCheck<T> check) {
- this.dumpNonEmptyCheck = check;
- return this;
- }
-
- public DumpCacheManagerBuilder<T, U> withPostProcessingFunction(
- EntityDumpPostProcessingFunction postProcessingFunction) {
- this.postProcessingFunction = postProcessingFunction;
- return this;
- }
-
- 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");
-
- return new DumpCacheManager<T, U>(this);
- }
- }
-}
-
-
diff --git a/v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/cache/EntityDumpExecutor.java b/v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/cache/EntityDumpExecutor.java
deleted file mode 100644
index 82b30cf26..000000000
--- a/v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/cache/EntityDumpExecutor.java
+++ /dev/null
@@ -1,41 +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.v3po.translate.v3po.util.cache;
-
-import io.fd.honeycomb.v3po.translate.v3po.util.cache.exceptions.execution.DumpExecutionFailedException;
-import org.openvpp.jvpp.dto.JVppReplyDump;
-
-/**
- * Generic interface for classes that return dumps for Data objects
- */
-public interface EntityDumpExecutor<T extends JVppReplyDump, U> {
-
- /**
- * Performs dump on {link T} entity
- *
- * @return dump of specified {@link T} entity
- * @throws DumpExecutionFailedException when dump fails
- */
- public T executeDump() throws DumpExecutionFailedException;
-
- /**
- * Bind dumping params for executor
- */
- default public void bindDumpParams(U params) {
- throw new UnsupportedOperationException("You should override this method if you need to bind dumping params");
- }
-}
diff --git a/v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/cache/EntityDumpNonEmptyCheck.java b/v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/cache/EntityDumpNonEmptyCheck.java
deleted file mode 100644
index 6fb404a7a..000000000
--- a/v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/cache/EntityDumpNonEmptyCheck.java
+++ /dev/null
@@ -1,33 +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.v3po.translate.v3po.util.cache;
-
-import io.fd.honeycomb.v3po.translate.v3po.util.cache.exceptions.check.DumpCheckFailedException;
-import io.fd.honeycomb.v3po.translate.v3po.util.cache.exceptions.check.i.DumpEmptyException;
-import org.openvpp.jvpp.dto.JVppReplyDump;
-
-/**
- * Generic interface for classes that verifies if dump of data object is non-empty
- */
-public interface EntityDumpNonEmptyCheck<T extends JVppReplyDump> {
-
- /**
- * Verifies if data are non-empty,if not throws {@link DumpEmptyException}
- * @throws DumpEmptyException
- */
- public void assertNotEmpty(T data) throws DumpCheckFailedException;
-}
diff --git a/v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/cache/EntityDumpPostProcessingFunction.java b/v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/cache/EntityDumpPostProcessingFunction.java
deleted file mode 100644
index 3d0040ea6..000000000
--- a/v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/cache/EntityDumpPostProcessingFunction.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.v3po.translate.v3po.util.cache;
-
-import java.util.function.Function;
-import org.openvpp.jvpp.dto.JVppReplyDump;
-
-/**
- * Generic interface for class that are post-processing data dumped from vpp
- */
-@FunctionalInterface
-public interface EntityDumpPostProcessingFunction<T extends JVppReplyDump> extends Function<T, T> {
-
-
- /**
- * Performs postprocessing on dumped data
- *
- * @return Post-processed data
- */
- @Override
- T apply(T t);
-} \ No newline at end of file
diff --git a/v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/cache/exceptions/check/DumpCheckFailedException.java b/v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/cache/exceptions/check/DumpCheckFailedException.java
deleted file mode 100644
index f3f8f7fef..000000000
--- a/v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/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.v3po.translate.v3po.util.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/v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/cache/exceptions/check/i/DumpEmptyException.java b/v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/cache/exceptions/check/i/DumpEmptyException.java
deleted file mode 100644
index a5a228823..000000000
--- a/v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/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.v3po.translate.v3po.util.cache.exceptions.check.i;
-
-import io.fd.honeycomb.v3po.translate.v3po.util.cache.EntityDumpNonEmptyCheck;
-import io.fd.honeycomb.v3po.translate.v3po.util.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/v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/cache/exceptions/execution/DumpExecutionFailedException.java b/v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/cache/exceptions/execution/DumpExecutionFailedException.java
deleted file mode 100644
index 5f4939cfb..000000000
--- a/v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/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.v3po.translate.v3po.util.cache.exceptions.execution;
-
-/**
- * Default parent for all exceptions connected to dumping of VPP data
- */
-public abstract class DumpExecutionFailedException extends Exception {
-
- public DumpExecutionFailedException(String message, Exception cause) {
- super(message, cause);
- }
-}
diff --git a/v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/cache/exceptions/execution/i/DumpCallFailedException.java b/v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/cache/exceptions/execution/i/DumpCallFailedException.java
deleted file mode 100644
index 9b92409f5..000000000
--- a/v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/cache/exceptions/execution/i/DumpCallFailedException.java
+++ /dev/null
@@ -1,34 +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.v3po.translate.v3po.util.cache.exceptions.execution.i;
-
-import io.fd.honeycomb.v3po.translate.v3po.util.cache.exceptions.execution.DumpExecutionFailedException;
-import org.openvpp.jvpp.VppBaseCallException;
-
-/**
- * Wrapper exception for {@link org.openvpp.jvpp.VppBaseCallException} during dumping
- */
-public class DumpCallFailedException extends DumpExecutionFailedException {
-
- public DumpCallFailedException(String message, VppBaseCallException cause) {
- super(message, cause);
- }
-
- public static final DumpCallFailedException wrapFailedCallException(String message, VppBaseCallException cause) {
- return new DumpCallFailedException(message, cause);
- }
-}
diff --git a/v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/cache/exceptions/execution/i/DumpTimeoutException.java b/v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/cache/exceptions/execution/i/DumpTimeoutException.java
deleted file mode 100644
index afb278c9d..000000000
--- a/v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/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.v3po.translate.v3po.util.cache.exceptions.execution.i;
-
-import io.fd.honeycomb.v3po.translate.v3po.util.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);
- }
-}
diff --git a/v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/cache/noop/NoopDumpPostProcessingFunction.java b/v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/cache/noop/NoopDumpPostProcessingFunction.java
deleted file mode 100644
index 5efe439ab..000000000
--- a/v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/cache/noop/NoopDumpPostProcessingFunction.java
+++ /dev/null
@@ -1,33 +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.v3po.translate.v3po.util.cache.noop;
-
-import io.fd.honeycomb.v3po.translate.v3po.util.cache.EntityDumpPostProcessingFunction;
-import org.openvpp.jvpp.dto.JVppReplyDump;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class NoopDumpPostProcessingFunction<T extends JVppReplyDump> implements EntityDumpPostProcessingFunction<T> {
-
- private static final Logger LOG = LoggerFactory.getLogger(NoopDumpPostProcessingFunction.class);
-
- @Override
- public T apply(final T t) {
- LOG.debug("Default post processing function called for {}", t);
- return t;
- }
-}