diff options
Diffstat (limited to 'champ-lib/champ-core/src/main/java/org/onap/aai/champcore/graph')
3 files changed, 56 insertions, 32 deletions
diff --git a/champ-lib/champ-core/src/main/java/org/onap/aai/champcore/graph/impl/AbstractTinkerpopChampGraph.java b/champ-lib/champ-core/src/main/java/org/onap/aai/champcore/graph/impl/AbstractTinkerpopChampGraph.java index f910b3c..3fbfd3d 100644 --- a/champ-lib/champ-core/src/main/java/org/onap/aai/champcore/graph/impl/AbstractTinkerpopChampGraph.java +++ b/champ-lib/champ-core/src/main/java/org/onap/aai/champcore/graph/impl/AbstractTinkerpopChampGraph.java @@ -31,7 +31,6 @@ import java.util.Optional; import java.util.Set; import java.util.Spliterator; import java.util.Spliterators; -import java.util.Vector; import java.util.concurrent.atomic.AtomicBoolean; import java.util.stream.Stream; import java.util.stream.StreamSupport; @@ -43,8 +42,8 @@ import org.apache.tinkerpop.gremlin.structure.Graph; import org.apache.tinkerpop.gremlin.structure.Property; import org.apache.tinkerpop.gremlin.structure.Vertex; import org.apache.tinkerpop.gremlin.structure.VertexProperty; +import org.onap.aai.champcore.ChampCoreMsgs; import org.onap.aai.champcore.ChampTransaction; -import org.onap.aai.champcore.NoOpTinkerPopTransaction; import org.onap.aai.champcore.exceptions.ChampMarshallingException; import org.onap.aai.champcore.exceptions.ChampObjectNotExistsException; import org.onap.aai.champcore.exceptions.ChampRelationshipNotExistsException; @@ -57,15 +56,15 @@ import org.onap.aai.champcore.model.ChampRelationship; import org.onap.aai.champcore.model.ChampSchema; import org.onap.aai.champcore.model.fluent.partition.CreateChampPartitionable; import org.onap.aai.champcore.transform.TinkerpopChampformer; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import org.onap.aai.cl.api.Logger; +import org.onap.aai.cl.eelf.LoggerFactory; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; public abstract class AbstractTinkerpopChampGraph extends AbstractValidatingChampGraph { - private static final Logger LOGGER = LoggerFactory.getLogger(AbstractTinkerpopChampGraph.class); + private static final Logger LOGGER = LoggerFactory.getInstance().getLogger(AbstractTinkerpopChampGraph.class); private static final TinkerpopChampformer TINKERPOP_CHAMPFORMER = new TinkerpopChampformer(); private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); @@ -282,7 +281,8 @@ public abstract class AbstractTinkerpopChampGraph extends AbstractValidatingCham return Stream.empty(); } } catch (ChampUnmarshallingException e) { - LOGGER.warn("Failed to unmarshall object", e); + LOGGER.warn(ChampCoreMsgs.CHAMPCORE_ABSTRACT_TINKERPOP_CHAMP_GRAPH_WARN, + "Failed to unmarshall object. " + e.getMessage()); return Stream.empty(); } } @@ -313,7 +313,8 @@ public abstract class AbstractTinkerpopChampGraph extends AbstractValidatingCham next = getChampformer().unmarshallObject(query.next()); return true; } catch (ChampUnmarshallingException e) { - LOGGER.warn("Failed to unmarshall tinkerpop vertex during query, returning partial results", e); + LOGGER.warn(ChampCoreMsgs.CHAMPCORE_ABSTRACT_TINKERPOP_CHAMP_GRAPH_WARN, + "Failed to unmarshall tinkerpop vertex during query, returning partial results" + e.getMessage()); } } @@ -324,7 +325,8 @@ public abstract class AbstractTinkerpopChampGraph extends AbstractValidatingCham tx.commit(); //Danger ahead if this iterator is not completely consumed //then the transaction cache will hold stale values } catch (ChampTransactionException e) { - LOGGER.warn("Failed transaction commit due to: " + e.getMessage()); + LOGGER.warn(ChampCoreMsgs.CHAMPCORE_ABSTRACT_TINKERPOP_CHAMP_GRAPH_WARN, + "Failed transaction commit due to: " + e.getMessage()); } } @@ -433,7 +435,8 @@ public abstract class AbstractTinkerpopChampGraph extends AbstractValidatingCham next = getChampformer().unmarshallRelationship(edges.next()); return true; } catch (ChampUnmarshallingException e) { - LOGGER.warn("Failed to unmarshall tinkerpop edge during query, returning partial results", e); + LOGGER.warn(ChampCoreMsgs.CHAMPCORE_ABSTRACT_TINKERPOP_CHAMP_GRAPH_WARN, + "Failed to unmarshall tinkerpop edge during query, returning partial results" + e.getMessage()); } } @@ -445,7 +448,8 @@ public abstract class AbstractTinkerpopChampGraph extends AbstractValidatingCham //consumed, then the transaction cache will be stale } catch (ChampTransactionException e) { - LOGGER.warn("Failed transaction commit due to: " + e.getMessage()); + LOGGER.warn(ChampCoreMsgs.CHAMPCORE_ABSTRACT_TINKERPOP_CHAMP_GRAPH_WARN, + "Failed transaction commit due to: " + e.getMessage()); } } @@ -698,7 +702,8 @@ public abstract class AbstractTinkerpopChampGraph extends AbstractValidatingCham } } catch (ChampUnmarshallingException e) { - LOGGER.warn("Failed to unmarshall relationship", e); + LOGGER.warn(ChampCoreMsgs.CHAMPCORE_ABSTRACT_TINKERPOP_CHAMP_GRAPH_WARN, + "Failed to unmarshall relationship" + e.getMessage()); return Stream.empty(); } } @@ -728,7 +733,8 @@ public abstract class AbstractTinkerpopChampGraph extends AbstractValidatingCham next = getChampformer().unmarshallRelationship(query.next()); return true; } catch (ChampUnmarshallingException e) { - LOGGER.warn("Failed to unmarshall tinkerpop vertex during query, returning partial results", e); + LOGGER.warn(ChampCoreMsgs.CHAMPCORE_ABSTRACT_TINKERPOP_CHAMP_GRAPH_WARN, + "Failed to unmarshall tinkerpop vertex during query, returning partial results" + e.getMessage()); } } @@ -740,7 +746,8 @@ public abstract class AbstractTinkerpopChampGraph extends AbstractValidatingCham //consumed, then the transaction cache will be stale } catch (ChampTransactionException e) { - LOGGER.warn("Failed transaction commit due to " + e.getMessage()); + LOGGER.warn(ChampCoreMsgs.CHAMPCORE_ABSTRACT_TINKERPOP_CHAMP_GRAPH_WARN, + "Failed transaction commit due to " + e.getMessage()); } } @@ -996,7 +1003,8 @@ public abstract class AbstractTinkerpopChampGraph extends AbstractValidatingCham try { getGraph().close(); } catch (Throwable t) { - LOGGER.error("Exception while shutting down graph", t); + LOGGER.error(ChampCoreMsgs.CHAMPCORE_ABSTRACT_TINKERPOP_CHAMP_GRAPH_ERROR, + "Exception while shutting down graph" + t.getMessage()); } } else { throw new IllegalStateException("Cannot call shutdown() after shutdown() was already initiated"); diff --git a/champ-lib/champ-core/src/main/java/org/onap/aai/champcore/graph/impl/ChampAPIImpl.java b/champ-lib/champ-core/src/main/java/org/onap/aai/champcore/graph/impl/ChampAPIImpl.java index 5a8b79e..2350d00 100644 --- a/champ-lib/champ-core/src/main/java/org/onap/aai/champcore/graph/impl/ChampAPIImpl.java +++ b/champ-lib/champ-core/src/main/java/org/onap/aai/champcore/graph/impl/ChampAPIImpl.java @@ -25,13 +25,15 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicBoolean; import org.onap.aai.champcore.ChampAPI; +import org.onap.aai.champcore.ChampCoreMsgs; import org.onap.aai.champcore.ChampGraph; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import org.onap.aai.cl.api.Logger; +import org.onap.aai.cl.eelf.LoggerFactory; + public class ChampAPIImpl implements ChampAPI { - private static final Logger LOGGER = LoggerFactory.getLogger(ChampAPIImpl.class); + private static final Logger LOGGER = LoggerFactory.getInstance().getLogger(ChampAPIImpl.class); private final AtomicBoolean shutdown; private final String type; @@ -67,13 +69,16 @@ public class ChampAPIImpl implements ChampAPI { public void shutdown() { if (shutdown.compareAndSet(false, true)) { for (Entry<String, ChampGraph> graphEntry : graphs.entrySet()) { - LOGGER.info("Shutting down graph {}", graphEntry.getKey()); + LOGGER.info(ChampCoreMsgs.CHAMPCORE_CHAMP_API_IMPL_INFO, + String.format("Shutting down graph %s", graphEntry.getKey())); try { graphEntry.getValue().shutdown(); - LOGGER.info("Graph {} shutdown successfully", graphEntry.getKey()); + LOGGER.info(ChampCoreMsgs.CHAMPCORE_CHAMP_API_IMPL_INFO, + String.format("Graph %s shutdown successfully", graphEntry.getKey())); } catch (Throwable t) { - LOGGER.warn("Caught exception while shutting down graph " + graphEntry.getKey(), t); + LOGGER.warn(ChampCoreMsgs.CHAMPCORE_CHAMP_API_IMPL_WARN, + String.format("Caught exception while shutting down graph %s: %s", graphEntry.getKey(), t.getMessage())); } } } diff --git a/champ-lib/champ-core/src/main/java/org/onap/aai/champcore/graph/impl/TinkerpopTransaction.java b/champ-lib/champ-core/src/main/java/org/onap/aai/champcore/graph/impl/TinkerpopTransaction.java index bd970dc..19c6f7c 100644 --- a/champ-lib/champ-core/src/main/java/org/onap/aai/champcore/graph/impl/TinkerpopTransaction.java +++ b/champ-lib/champ-core/src/main/java/org/onap/aai/champcore/graph/impl/TinkerpopTransaction.java @@ -21,11 +21,13 @@ package org.onap.aai.champcore.graph.impl; import java.security.SecureRandom; + import org.apache.tinkerpop.gremlin.structure.Graph; +import org.onap.aai.champcore.ChampCoreMsgs; import org.onap.aai.champcore.ChampTransaction; import org.onap.aai.champcore.exceptions.ChampTransactionException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import org.onap.aai.cl.api.Logger; +import org.onap.aai.cl.eelf.LoggerFactory; public class TinkerpopTransaction extends ChampTransaction { @@ -35,7 +37,7 @@ public class TinkerpopTransaction extends ChampTransaction { protected Graph threadedTransaction; - private static final Logger LOGGER = LoggerFactory.getLogger(TinkerpopTransaction.class); + private static final Logger LOGGER = LoggerFactory.getInstance().getLogger(TinkerpopTransaction.class); protected TinkerpopTransaction() { } @@ -55,7 +57,8 @@ public class TinkerpopTransaction extends ChampTransaction { // Request a threaded transaction object from the graph. this.threadedTransaction = aGraphInstance.tx().createThreadedTx(); - LOGGER.info("Open transaction - id: " + id); + LOGGER.info(ChampCoreMsgs.CHAMPCORE_TINKERPOP_TRANSACTION_INFO, + "Open transaction - id: " + id); } @Override @@ -82,7 +85,8 @@ public class TinkerpopTransaction extends ChampTransaction { // Do the commit. threadedTransaction.tx().commit(); - LOGGER.info("Committed transaction - id: " + id); + LOGGER.info(ChampCoreMsgs.CHAMPCORE_TINKERPOP_TRANSACTION_INFO, + "Committed transaction - id: " + id); return; } catch (Throwable e) { @@ -92,14 +96,16 @@ public class TinkerpopTransaction extends ChampTransaction { // Have we used up all of our retries? if (i == COMMIT_RETRY_COUNT - 1) { - LOGGER.error("Maxed out commit attempt retries, client must handle exception and retry", e); + LOGGER.error(ChampCoreMsgs.CHAMPCORE_TINKERPOP_TRANSACTION_ERROR, + "Maxed out commit attempt retries, client must handle exception and retry. " + e.getMessage()); threadedTransaction.tx().rollback(); throw new ChampTransactionException(e); } // Calculate how long we will wait before retrying... final long backoff = (long) Math.pow(2, i) * initialBackoff; - LOGGER.warn("Caught exception while retrying transaction commit, retrying in " + backoff + " ms"); + LOGGER.warn(ChampCoreMsgs.CHAMPCORE_TINKERPOP_TRANSACTION_WARN, + "Caught exception while retrying transaction commit, retrying in " + backoff + " ms"); // ...and sleep before trying the commit again. try { @@ -107,7 +113,8 @@ public class TinkerpopTransaction extends ChampTransaction { } catch (InterruptedException ie) { - LOGGER.info("Interrupted while backing off on transaction commit"); + LOGGER.info(ChampCoreMsgs.CHAMPCORE_TINKERPOP_TRANSACTION_INFO, + "Interrupted while backing off on transaction commit"); Thread.currentThread().interrupt(); return; } @@ -128,7 +135,8 @@ public class TinkerpopTransaction extends ChampTransaction { try { threadedTransaction.tx().rollback(); - LOGGER.info("Rolled back transaction - id: " + id); + LOGGER.info(ChampCoreMsgs.CHAMPCORE_TINKERPOP_TRANSACTION_INFO, + "Rolled back transaction - id: " + id); return; } catch (Throwable e) { @@ -138,13 +146,15 @@ public class TinkerpopTransaction extends ChampTransaction { // Have we used up all of our retries? if (i == COMMIT_RETRY_COUNT - 1) { - LOGGER.error("Maxed out rollback attempt retries, client must handle exception and retry", e); + LOGGER.error(ChampCoreMsgs.CHAMPCORE_TINKERPOP_TRANSACTION_ERROR, + "Maxed out rollback attempt retries, client must handle exception and retry. " + e.getMessage()); throw new ChampTransactionException(e); } // Calculate how long we will wait before retrying... final long backoff = (long) Math.pow(2, i) * initialBackoff; - LOGGER.warn("Caught exception while retrying transaction roll back, retrying in " + backoff + " ms"); + LOGGER.warn(ChampCoreMsgs.CHAMPCORE_TINKERPOP_TRANSACTION_WARN, + "Caught exception while retrying transaction roll back, retrying in " + backoff + " ms"); // ...and sleep before trying the commit again. try { @@ -152,7 +162,8 @@ public class TinkerpopTransaction extends ChampTransaction { } catch (InterruptedException ie) { - LOGGER.info("Interrupted while backing off on transaction rollback"); + LOGGER.info(ChampCoreMsgs.CHAMPCORE_TINKERPOP_TRANSACTION_INFO, + "Interrupted while backing off on transaction rollback"); Thread.currentThread().interrupt(); return; } |