From: James Forsyth Date: Thu, 15 Aug 2019 13:43:24 +0000 (+0000) Subject: Merge "Updated champ-lib to use the correct logger" X-Git-Tag: 1.6.0~5 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=e9f19eaf902ff2c1cdc02a5f90aa06fd582848a6;hp=76796c55198d8b7865c60a05654ef1a7975b0fb9;p=aai%2Fchamp.git Merge "Updated champ-lib to use the correct logger" --- diff --git a/champ-lib/champ-core/src/main/java/org/onap/aai/champcore/ChampCoreMsgs.java b/champ-lib/champ-core/src/main/java/org/onap/aai/champcore/ChampCoreMsgs.java new file mode 100644 index 0000000..3e9bd71 --- /dev/null +++ b/champ-lib/champ-core/src/main/java/org/onap/aai/champcore/ChampCoreMsgs.java @@ -0,0 +1,60 @@ +/** + * ============LICENSE_START========================================== + * org.onap.aai + * =================================================================== + * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017-2018 Amdocs + * =================================================================== + * 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. + * ============LICENSE_END============================================ + */ +package org.onap.aai.champcore; + +import com.att.eelf.i18n.EELFResourceManager; +import org.onap.aai.cl.eelf.LogMessageEnum; + +public enum ChampCoreMsgs implements LogMessageEnum { + + CHAMPCORE_ABSTRACT_LOGGING_CHAMP_GRAPH_INFO, + CHAMPCORE_ABSTRACT_LOGGING_CHAMP_GRAPH_ERROR, + CHAMPCORE_ABSTRACT_LOGGING_CHAMP_GRAPH_WARN, + + CHAMPCORE_ABSTRACT_TINKERPOP_CHAMP_GRAPH_INFO, + CHAMPCORE_ABSTRACT_TINKERPOP_CHAMP_GRAPH_ERROR, + CHAMPCORE_ABSTRACT_TINKERPOP_CHAMP_GRAPH_WARN, + + CHAMPCORE_CHAMP_API_IMPL_INFO, + CHAMPCORE_CHAMP_API_IMPL_ERROR, + CHAMPCORE_CHAMP_API_IMPL_WARN, + + CHAMPCORE_TINKERPOP_TRANSACTION_INFO, + CHAMPCORE_TINKERPOP_TRANSACTION_ERROR, + CHAMPCORE_TINKERPOP_TRANSACTION_WARN, + + CHAMPCORE_GRAPH_ML_IMPORTER_EXPORTER_INFO, + CHAMPCORE_GRAPH_ML_IMPORTER_EXPORTER_ERROR, + CHAMPCORE_GRAPH_ML_IMPORTER_EXPORTER_WARN, + + CHAMPCORE_FORMATTER_INFO, + CHAMPCORE_FORMATTER_ERROR, + CHAMPCORE_FORMATTER_WARN; + + + + /** + * Static initializer to ensure the resource bundles for this class are loaded... + */ + static { + EELFResourceManager.loadMessageBundle("logging/ChampCoreMsgs"); + } +} diff --git a/champ-lib/champ-core/src/main/java/org/onap/aai/champcore/Formatter.java b/champ-lib/champ-core/src/main/java/org/onap/aai/champcore/Formatter.java index e85b672..dfb6143 100644 --- a/champ-lib/champ-core/src/main/java/org/onap/aai/champcore/Formatter.java +++ b/champ-lib/champ-core/src/main/java/org/onap/aai/champcore/Formatter.java @@ -30,9 +30,13 @@ import java.util.List; import java.util.Optional; import java.util.stream.Stream; +import org.onap.aai.champcore.ie.GraphMLImporterExporter; +import org.onap.aai.cl.api.Logger; +import org.onap.aai.cl.eelf.LoggerFactory; + public class Formatter { - private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(Formatter.class); + private static final Logger LOGGER = LoggerFactory.getInstance().getLogger(Formatter.class); protected JsonParser parser = new JsonParser(); protected final FormatMapper format; @@ -55,7 +59,8 @@ public class Formatter { try { return Optional.of(this.format.formatObject(v)); } catch (Exception var3) { - LOGGER.warn("Failed to format vertex, returning a partial list", var3); + LOGGER.warn(ChampCoreMsgs.CHAMPCORE_FORMATTER_WARN, + "Failed to format vertex, returning a partial list " + var3); return Optional.empty(); } }).forEach((obj) -> { diff --git a/champ-lib/champ-core/src/main/java/org/onap/aai/champcore/event/AbstractLoggingChampGraph.java b/champ-lib/champ-core/src/main/java/org/onap/aai/champcore/event/AbstractLoggingChampGraph.java index 6530b98..1ecf71b 100644 --- a/champ-lib/champ-core/src/main/java/org/onap/aai/champcore/event/AbstractLoggingChampGraph.java +++ b/champ-lib/champ-core/src/main/java/org/onap/aai/champcore/event/AbstractLoggingChampGraph.java @@ -32,7 +32,9 @@ import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Stream; + import org.onap.aai.champcore.ChampCapabilities; +import org.onap.aai.champcore.ChampCoreMsgs; import org.onap.aai.champcore.ChampGraph; import org.onap.aai.champcore.ChampTransaction; import org.onap.aai.champcore.event.ChampEvent.ChampOperation; @@ -52,9 +54,10 @@ import org.onap.aai.champcore.model.ChampRelationship; import org.onap.aai.champcore.model.ChampRelationshipConstraint; import org.onap.aai.champcore.model.ChampRelationshipIndex; import org.onap.aai.champcore.model.ChampSchema; +import org.onap.aai.cl.api.Logger; +import org.onap.aai.cl.eelf.LoggerFactory; import org.onap.aai.event.api.EventPublisher; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + @@ -89,7 +92,7 @@ public abstract class AbstractLoggingChampGraph implements ChampGraph { /** Number of event publisher worker threads. */ private Integer eventStreamPublisherPoolSize; - private static final Logger logger = LoggerFactory.getLogger(AbstractLoggingChampGraph.class); + private static final Logger logger = LoggerFactory.getInstance().getLogger(AbstractLoggingChampGraph.class); /** @@ -105,8 +108,10 @@ public abstract class AbstractLoggingChampGraph implements ChampGraph { // Make sure we were passed an event producer as one of our properties, otherwise // there is really nothing more we can do... if(producer == null) { - logger.error("No event stream producer was supplied."); - logger.error("NOTE!! Champ events will NOT be published to the event stream!"); + logger.error(ChampCoreMsgs.CHAMPCORE_ABSTRACT_LOGGING_CHAMP_GRAPH_ERROR, + "No event stream producer was supplied."); + logger.error(ChampCoreMsgs.CHAMPCORE_ABSTRACT_LOGGING_CHAMP_GRAPH_ERROR, + "NOTE!! Champ events will NOT be published to the event stream!"); return; } @@ -128,8 +133,10 @@ public abstract class AbstractLoggingChampGraph implements ChampGraph { } catch (Exception e) { - logger.error("Failed to instantiate event stream producer thread due to: '" + e.getMessage() + "'"); - logger.error("NOTE!! Champ events may NOT be published to the event stream!"); + logger.error(ChampCoreMsgs.CHAMPCORE_ABSTRACT_LOGGING_CHAMP_GRAPH_ERROR, + "Failed to instantiate event stream producer thread due to: '" + e.getMessage() + "'"); + logger.error(ChampCoreMsgs.CHAMPCORE_ABSTRACT_LOGGING_CHAMP_GRAPH_ERROR, + "NOTE!! Champ events may NOT be published to the event stream!"); return; } } @@ -395,7 +402,8 @@ public abstract class AbstractLoggingChampGraph implements ChampGraph { try { publisherPool.awaitTermination(1000, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { - logger.warn("Termination interrupted"); + logger.warn(ChampCoreMsgs.CHAMPCORE_ABSTRACT_LOGGING_CHAMP_GRAPH_WARN, + "Termination interrupted"); Thread.currentThread().interrupt(); } } @@ -406,7 +414,8 @@ public abstract class AbstractLoggingChampGraph implements ChampGraph { producer.close(); } catch (Exception e) { - logger.error("Failed to stop event stream producer: " + e.getMessage()); + logger.error(ChampCoreMsgs.CHAMPCORE_ABSTRACT_LOGGING_CHAMP_GRAPH_ERROR, + "Failed to stop event stream producer: " + e.getMessage()); } } } @@ -421,7 +430,8 @@ public abstract class AbstractLoggingChampGraph implements ChampGraph { } catch (ChampTransactionException e) { - logger.warn("Events associated with transaction " + transaction.id() + " not generated due to transaction commit failure."); + logger.warn(ChampCoreMsgs.CHAMPCORE_ABSTRACT_LOGGING_CHAMP_GRAPH_WARN, + "Events associated with transaction " + transaction.id() + " not generated due to transaction commit failure."); List enqueuedEvents = transaction.getEnqueuedEvents(); for(ChampEvent event : enqueuedEvents) { @@ -509,7 +519,8 @@ public abstract class AbstractLoggingChampGraph implements ChampGraph { objectToDelete = retrieveObject(key, transaction); } catch (ChampUnmarshallingException e) { - logger.error("Unable to generate delete object log: " + e.getMessage()); + logger.error(ChampCoreMsgs.CHAMPCORE_ABSTRACT_LOGGING_CHAMP_GRAPH_ERROR, + "Unable to generate delete object log: " + e.getMessage()); } executeDeleteObject(key, transaction); @@ -731,14 +742,16 @@ public abstract class AbstractLoggingChampGraph implements ChampGraph { return; } - logger.info("Log champcore event with transaction id: " + anEvent.getTransactionId() + " to event bus"); + logger.info(ChampCoreMsgs.CHAMPCORE_ABSTRACT_LOGGING_CHAMP_GRAPH_INFO, + "Log champcore event with transaction id: " + anEvent.getTransactionId() + " to event bus"); if(logger.isDebugEnabled()) { logger.debug("Event payload: " + anEvent.toString()); } // Try to submit the event to be published to the event bus. if(!eventQueue.offer(anEvent)) { - logger.error("Event could not be published to the event bus due to: Internal buffer capacity exceeded."); + logger.error(ChampCoreMsgs.CHAMPCORE_ABSTRACT_LOGGING_CHAMP_GRAPH_ERROR, + "Event could not be published to the event bus due to: Internal buffer capacity exceeded."); } } @@ -783,7 +796,8 @@ public abstract class AbstractLoggingChampGraph implements ChampGraph { } catch (Exception e) { - logger.error("Failed to publish event to event bus: " + e.getMessage()); + logger.error(ChampCoreMsgs.CHAMPCORE_ABSTRACT_LOGGING_CHAMP_GRAPH_ERROR, + "Failed to publish event to event bus: " + e.getMessage()); } } } 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 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; } diff --git a/champ-lib/champ-core/src/main/java/org/onap/aai/champcore/ie/GraphMLImporterExporter.java b/champ-lib/champ-core/src/main/java/org/onap/aai/champcore/ie/GraphMLImporterExporter.java index 36a3da0..c73b973 100644 --- a/champ-lib/champ-core/src/main/java/org/onap/aai/champcore/ie/GraphMLImporterExporter.java +++ b/champ-lib/champ-core/src/main/java/org/onap/aai/champcore/ie/GraphMLImporterExporter.java @@ -43,8 +43,8 @@ import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamWriter; import org.onap.aai.champcore.ChampAPI; +import org.onap.aai.champcore.ChampCoreMsgs; import org.onap.aai.champcore.ChampGraph; -import org.onap.aai.champcore.ChampTransaction; import org.onap.aai.champcore.exceptions.ChampMarshallingException; import org.onap.aai.champcore.exceptions.ChampObjectNotExistsException; import org.onap.aai.champcore.exceptions.ChampRelationshipNotExistsException; @@ -54,8 +54,8 @@ import org.onap.aai.champcore.exceptions.ChampUnmarshallingException; import org.onap.aai.champcore.model.ChampObject; import org.onap.aai.champcore.model.ChampObjectIndex; import org.onap.aai.champcore.model.ChampRelationship; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import org.onap.aai.cl.api.Logger; +import org.onap.aai.cl.eelf.LoggerFactory; import org.w3c.dom.Document; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; @@ -65,7 +65,7 @@ import org.xml.sax.SAXException; public class GraphMLImporterExporter implements Importer, Exporter { - private static final Logger LOGGER = LoggerFactory.getLogger(GraphMLImporterExporter.class); + private static final Logger LOGGER = LoggerFactory.getInstance().getLogger(GraphMLImporterExporter.class); private static class GraphMLKey { private final String id; @@ -141,7 +141,8 @@ public class GraphMLImporterExporter implements Importer, Exporter { } else if (elementType.equals("edge")) { edgePropertyDefinitions.put(id, propertyDefinitions); } else { - LOGGER.warn("Unknown element type {}, skipping", elementType); + LOGGER.warn(ChampCoreMsgs.CHAMPCORE_GRAPH_ML_IMPORTER_EXPORTER_WARN, + String.format("Unknown element type %s, skipping", elementType)); } } @@ -170,7 +171,8 @@ public class GraphMLImporterExporter implements Importer, Exporter { } else if (nodeOrEdge.getNodeName().equals("edge")) { writeEdge(api.getGraph(graphName), nodeOrEdge, edgePropertyDefinitions, edgeDefaults); } else { - LOGGER.warn("Unknown object {} found in graphML, skipping", nodeOrEdge.getNodeName()); + LOGGER.warn(ChampCoreMsgs.CHAMPCORE_GRAPH_ML_IMPORTER_EXPORTER_WARN, + String.format("Unknown object %s found in graphML, skipping", nodeOrEdge.getNodeName())); } } } @@ -212,16 +214,20 @@ public class GraphMLImporterExporter implements Importer, Exporter { } else targetObject = target.get(); } catch (ChampMarshallingException e) { - LOGGER.error("Failed to marshall object to backend type, skipping this edge", e); + LOGGER.error(ChampCoreMsgs.CHAMPCORE_GRAPH_ML_IMPORTER_EXPORTER_ERROR, + "Failed to marshall object to backend type, skipping this edge. " + e.getMessage()); return; } catch (ChampSchemaViolationException e) { - LOGGER.error("Source/target object violates schema constraint(s)", e); + LOGGER.error(ChampCoreMsgs.CHAMPCORE_GRAPH_ML_IMPORTER_EXPORTER_ERROR, + "Source/target object violates schema constraint(s). " + e.getMessage()); return; } catch (ChampObjectNotExistsException e) { - LOGGER.error("Failed to update existing source/target ChampObject", e); + LOGGER.error(ChampCoreMsgs.CHAMPCORE_GRAPH_ML_IMPORTER_EXPORTER_ERROR, + "Failed to update existing source/target ChampObject. " + e.getMessage()); return; } catch (ChampTransactionException e) { - LOGGER.error("Failed to commit or rollback transaction", e); + LOGGER.error(ChampCoreMsgs.CHAMPCORE_GRAPH_ML_IMPORTER_EXPORTER_ERROR, + "Failed to commit or rollback transaction. " + e.getMessage()); } final ChampRelationship.Builder champRelBuilder = new ChampRelationship.Builder(sourceObject, targetObject, "undefined"); @@ -267,17 +273,23 @@ public class GraphMLImporterExporter implements Importer, Exporter { try { graph.storeRelationship(relToStore, Optional.empty()); } catch (ChampMarshallingException e) { - LOGGER.warn("Failed to marshall ChampObject to backend type", e); + LOGGER.warn(ChampCoreMsgs.CHAMPCORE_GRAPH_ML_IMPORTER_EXPORTER_WARN, + "Failed to marshall ChampObject to backend type. " + e.getMessage()); } catch (ChampSchemaViolationException e) { - LOGGER.error("Failed to store object (schema violated): " + relToStore, e); + LOGGER.error(ChampCoreMsgs.CHAMPCORE_GRAPH_ML_IMPORTER_EXPORTER_ERROR, + "Failed to store object (schema violated): " + relToStore + " " + e.getMessage()); } catch (ChampRelationshipNotExistsException e) { - LOGGER.error("Failed to update existing ChampRelationship", e); + LOGGER.error(ChampCoreMsgs.CHAMPCORE_GRAPH_ML_IMPORTER_EXPORTER_ERROR, + "Failed to update existing ChampRelationship. " + e.getMessage()); } catch (ChampObjectNotExistsException e) { - LOGGER.error("Objects bound to relationship do not exist (should never happen)"); + LOGGER.error(ChampCoreMsgs.CHAMPCORE_GRAPH_ML_IMPORTER_EXPORTER_ERROR, + "Objects bound to relationship do not exist (should never happen)"); } catch (ChampUnmarshallingException e) { - LOGGER.error("Failed to unmarshall ChampObject to backend type"); + LOGGER.error(ChampCoreMsgs.CHAMPCORE_GRAPH_ML_IMPORTER_EXPORTER_ERROR, + "Failed to unmarshall ChampObject to backend type"); } catch (ChampTransactionException e) { - LOGGER.error("Failed to commit or rollback transaction"); + LOGGER.error(ChampCoreMsgs.CHAMPCORE_GRAPH_ML_IMPORTER_EXPORTER_ERROR, + "Failed to commit or rollback transaction"); } } @@ -338,13 +350,17 @@ public class GraphMLImporterExporter implements Importer, Exporter { try { graph.storeObject(objectToStore, Optional.empty()); } catch (ChampMarshallingException e) { - LOGGER.warn("Failed to marshall ChampObject to backend type", e); + LOGGER.warn(ChampCoreMsgs.CHAMPCORE_GRAPH_ML_IMPORTER_EXPORTER_WARN, + "Failed to marshall ChampObject to backend type. " + e.getMessage()); } catch (ChampSchemaViolationException e) { - LOGGER.error("Failed to store object (schema violated): " + objectToStore, e); + LOGGER.error(ChampCoreMsgs.CHAMPCORE_GRAPH_ML_IMPORTER_EXPORTER_ERROR, + "Failed to store object (schema violated): " + objectToStore + " " + e.getMessage()); } catch (ChampObjectNotExistsException e) { - LOGGER.error("Failed to update existing ChampObject", e); + LOGGER.error(ChampCoreMsgs.CHAMPCORE_GRAPH_ML_IMPORTER_EXPORTER_ERROR, + "Failed to update existing ChampObject. " + e.getMessage()); } catch (ChampTransactionException e) { - LOGGER.error("Failed to commit or rollback transaction"); + LOGGER.error(ChampCoreMsgs.CHAMPCORE_GRAPH_ML_IMPORTER_EXPORTER_ERROR, + "Failed to commit or rollback transaction"); } } diff --git a/champ-lib/champ-core/src/main/resources/logging/ChampCoreMsgs.properties b/champ-lib/champ-core/src/main/resources/logging/ChampCoreMsgs.properties new file mode 100644 index 0000000..58c1188 --- /dev/null +++ b/champ-lib/champ-core/src/main/resources/logging/ChampCoreMsgs.properties @@ -0,0 +1,88 @@ +#Resource key=Error Code|Message text|Resolution text |Description text +####### +#Newlines can be utilized to add some clarity ensuring continuing line +#has atleast one leading space +#ResourceKey=\ +# ERR0000E\ +# Sample error msg txt\ +# Sample resolution msg\ +# Sample description txt +# +###### +#Error code classification category +#000 Info/Debug +#100 Permission errors +#200 Availability errors/Timeouts +#300 Data errors +#400 Schema Interface type/validation errors +#500 Business process errors +#900 Unknown errors +# +######################################################################## + +CHAMPCORE_ABSTRACT_LOGGING_CHAMP_GRAPH_INFO=\ + CCE0011I|\ + AbstractLoggingChampGraph: {0} +CHAMPCORE_ABSTRACT_LOGGING_CHAMP_GRAPH_ERROR=\ + CCE0511E|\ + AbstractLoggingChampGraph Error: {0} +CHAMPCORE_ABSTRACT_LOGGING_CHAMP_GRAPH_WARN=\ + CCE0512E|\ + AbstractLoggingChampGraph Warning: {0} + + +CHAMPCORE_ABSTRACT_TINKERPOP_CHAMP_GRAPH_INFO=\ + CCG0012I|\ + AbstractTinkerpopChampGraph: {0} +CHAMPCORE_ABSTRACT_TINKERPOP_CHAMP_GRAPH_ERROR=\ + CCG0513E|\ + AbstractTinkerpopChampGraph Error: {0} +CHAMPCORE_ABSTRACT_TINKERPOP_CHAMP_GRAPH_WARN=\ + CCG0514E|\ + AbstractTinkerpopChampGraph Warning: {0} + + +CHAMPCORE_CHAMP_API_IMPL_INFO=\ + CCG0013I|\ + ChampAPIImpl: {0} +CHAMPCORE_CHAMP_API_IMPL_ERROR=\ + CCG0515E|\ + ChampAPIImpl Error: {0} +CHAMPCORE_CHAMP_API_IMPL_WARN=\ + CCG0516E|\ + ChampAPIImpl Warning: {0} + + +CHAMPCORE_TINKERPOP_TRANSACTION_INFO=\ + CCG0014I|\ + TinkerpopTransaction: {0} +CHAMPCORE_TINKERPOP_TRANSACTION_ERROR=\ + CCG0517E|\ + TinkerpopTransaction Error: {0} +CHAMPCORE_TINKERPOP_TRANSACTION_WARN=\ + CCG0518E|\ + TinkerpopTransaction Warning: {0} + + +CHAMPCORE_GRAPH_ML_IMPORTER_EXPORTER_INFO=\ + CCIE0015I|\ + GraphMLImporterExporter: {0} +CHAMPCORE_GRAPH_ML_IMPORTER_EXPORTER_ERROR=\ + CCIE0519E|\ + GraphMLImporterExporter Error: {0} +CHAMPCORE_GRAPH_ML_IMPORTER_EXPORTER_WARN=\ + CCIE0520E|\ + GraphMLImporterExporter Warning: {0} + + +CHAMPCORE_FORMATTER_INFO=\ + CCIE0015I|\ + Formatter: {0} +CHAMPCORE_FORMATTER_ERROR=\ + CCIE0519E|\ + Formatter Error: {0} +CHAMPCORE_FORMATTER_WARN=\ + CCIE0520E|\ + Formatter Warning: {0} + + diff --git a/champ-lib/champ-core/src/test/java/org/onap/aai/champcore/event/envelope/ChampEventEnvelopeTest.java b/champ-lib/champ-core/src/test/java/org/onap/aai/champcore/event/envelope/ChampEventEnvelopeTest.java index 56cf8ea..8ed0f45 100644 --- a/champ-lib/champ-core/src/test/java/org/onap/aai/champcore/event/envelope/ChampEventEnvelopeTest.java +++ b/champ-lib/champ-core/src/test/java/org/onap/aai/champcore/event/envelope/ChampEventEnvelopeTest.java @@ -23,6 +23,8 @@ package org.onap.aai.champcore.event.envelope; import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertThat; + +import org.junit.Assert; import org.junit.Test; import org.onap.aai.champcore.event.ChampEvent; import org.onap.aai.champcore.model.ChampObject; @@ -32,6 +34,7 @@ import org.skyscreamer.jsonassert.Customization; import org.skyscreamer.jsonassert.JSONAssert; import org.skyscreamer.jsonassert.JSONCompareMode; import org.skyscreamer.jsonassert.comparator.CustomComparator; + import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; @@ -101,4 +104,44 @@ public class ChampEventEnvelopeTest { new Customization("body.timestamp", (o1, o2) -> true), new Customization("body.transaction-id", (o1, o2) -> true))); } + + @Test + public void testChampEventHeader() { + String link = "link1"; + String requestId = "request-id1"; + String entityType = "entity-type1"; + String topEntityType = "top-entity-type1"; + + ChampEventHeader header1 = new ChampEventHeader.Builder(ChampEventHeader.EventType.UPDATE_NOTIFICATION) + .entityLink(link) + .requestId(requestId) + .validationEntityType(entityType) + .validationTopEntityType(topEntityType) + .build(); + + Assert.assertEquals(link, header1.getEntityLink()); + Assert.assertEquals(requestId, header1.getRequestId()); + Assert.assertEquals(entityType, header1.getValidationEntityType()); + Assert.assertEquals(topEntityType, header1.getValidationTopEntityType()); + + ChampEventHeader header2 = new ChampEventHeader.Builder(ChampEventHeader.EventType.UPDATE_RESULT) + .entityLink("link2") + .requestId("request-id2") + .validationEntityType("entity-type2") + .validationTopEntityType("top-entity-type2") + .build(); + + Assert.assertNotEquals(header1, header2); + + + header2.setEntityLink(link); + header2.setRequestId(requestId); + header2.setValidationEntityType(entityType); + header2.setValidationTopEntityType(topEntityType); + header2.setEventType(header1.getEventType()); + header2.setTimestamp(header1.getTimestamp()); + + Assert.assertEquals(header1, header2); + + } } diff --git a/champ-lib/champ-core/src/test/java/org/onap/aai/champcore/ie/ImportTest.java b/champ-lib/champ-core/src/test/java/org/onap/aai/champcore/ie/ImportTest.java index 858c377..756d4ca 100644 --- a/champ-lib/champ-core/src/test/java/org/onap/aai/champcore/ie/ImportTest.java +++ b/champ-lib/champ-core/src/test/java/org/onap/aai/champcore/ie/ImportTest.java @@ -90,4 +90,22 @@ public class ImportTest { api.shutdown(); } + + @Test + public void testUndefinedEdgeSourceAndTarget() throws ChampTransactionException, AssertionError { + + final GraphMLImporterExporter importer = new GraphMLImporterExporter(); + final ChampAPI api = ChampAPI.Factory.newInstance("IN_MEMORY"); + + importer.importData(api, getClass().getClassLoader().getResourceAsStream("import-test2.graphml")); + + final ChampGraph graph = api.getGraph(GRAPH_NAME); + + graph.queryObjects(Collections.emptyMap(), Optional.empty()).forEach(object -> { + final Optional nameOpt = object.getProperty("name"); + assertTrue(!nameOpt.isPresent()); + }); + + api.shutdown(); + } } diff --git a/champ-lib/champ-core/src/test/resources/import-test2.graphml b/champ-lib/champ-core/src/test/resources/import-test2.graphml new file mode 100644 index 0000000..8fa63c2 --- /dev/null +++ b/champ-lib/champ-core/src/test/resources/import-test2.graphml @@ -0,0 +1,29 @@ + + + + + + + + + green + + + + + + + abc + + + green + + + + 12348234 + Dog + + + + \ No newline at end of file diff --git a/champ-lib/champ-janus/src/main/java/org/onap/aai/champjanus/graph/impl/ChampJanusMsgs.java b/champ-lib/champ-janus/src/main/java/org/onap/aai/champjanus/graph/impl/ChampJanusMsgs.java new file mode 100644 index 0000000..765630c --- /dev/null +++ b/champ-lib/champ-janus/src/main/java/org/onap/aai/champjanus/graph/impl/ChampJanusMsgs.java @@ -0,0 +1,40 @@ +/** + * ============LICENSE_START========================================== + * org.onap.aai + * =================================================================== + * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017-2018 Amdocs + * =================================================================== + * 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. + * ============LICENSE_END============================================ + */ +package org.onap.aai.champjanus.graph.impl; + +import com.att.eelf.i18n.EELFResourceManager; +import org.onap.aai.cl.eelf.LogMessageEnum; + +public enum ChampJanusMsgs implements LogMessageEnum { + + JANUS_CHAMP_GRAPH_IMPL_INFO, + JANUS_CHAMP_GRAPH_IMPL_ERROR, + JANUS_CHAMP_GRAPH_IMPL_WARN; + + + + /** + * Static initializer to ensure the resource bundles for this class are loaded... + */ + static { + EELFResourceManager.loadMessageBundle("logging/ChampJanusMsgs"); + } +} diff --git a/champ-lib/champ-janus/src/main/java/org/onap/aai/champjanus/graph/impl/JanusChampGraphImpl.java b/champ-lib/champ-janus/src/main/java/org/onap/aai/champjanus/graph/impl/JanusChampGraphImpl.java index ea90ce9..ab7c265 100644 --- a/champ-lib/champ-janus/src/main/java/org/onap/aai/champjanus/graph/impl/JanusChampGraphImpl.java +++ b/champ-lib/champ-janus/src/main/java/org/onap/aai/champjanus/graph/impl/JanusChampGraphImpl.java @@ -20,10 +20,32 @@ */ package org.onap.aai.champjanus.graph.impl; +import java.security.SecureRandom; +import java.time.temporal.ChronoUnit; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Optional; +import java.util.Spliterator; +import java.util.Spliterators; +import java.util.concurrent.ExecutionException; +import java.util.stream.Stream; +import java.util.stream.StreamSupport; + import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; import org.apache.tinkerpop.gremlin.structure.Edge; import org.apache.tinkerpop.gremlin.structure.Vertex; -import org.janusgraph.core.*; +import org.janusgraph.core.Cardinality; +import org.janusgraph.core.EdgeLabel; +import org.janusgraph.core.JanusGraph; +import org.janusgraph.core.JanusGraphEdge; +import org.janusgraph.core.JanusGraphFactory; +import org.janusgraph.core.JanusGraphVertex; +import org.janusgraph.core.PropertyKey; +import org.janusgraph.core.SchemaViolationException; import org.janusgraph.core.schema.JanusGraphIndex; import org.janusgraph.core.schema.JanusGraphManagement; import org.janusgraph.core.schema.JanusGraphManagement.IndexBuilder; @@ -34,21 +56,23 @@ import org.onap.aai.champcore.ChampCapabilities; import org.onap.aai.champcore.exceptions.ChampIndexNotExistsException; import org.onap.aai.champcore.exceptions.ChampSchemaViolationException; import org.onap.aai.champcore.graph.impl.AbstractTinkerpopChampGraph; -import org.onap.aai.champcore.model.*; +import org.onap.aai.champcore.model.ChampCardinality; +import org.onap.aai.champcore.model.ChampField; +import org.onap.aai.champcore.model.ChampObject; +import org.onap.aai.champcore.model.ChampObjectConstraint; +import org.onap.aai.champcore.model.ChampObjectIndex; +import org.onap.aai.champcore.model.ChampPropertyConstraint; +import org.onap.aai.champcore.model.ChampRelationship; +import org.onap.aai.champcore.model.ChampRelationshipConstraint; +import org.onap.aai.champcore.model.ChampRelationshipIndex; +import org.onap.aai.champcore.model.ChampSchema; import org.onap.aai.champcore.schema.ChampSchemaEnforcer; import org.onap.aai.champcore.schema.DefaultChampSchemaEnforcer; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.security.SecureRandom; -import java.time.temporal.ChronoUnit; -import java.util.*; -import java.util.concurrent.ExecutionException; -import java.util.stream.Stream; -import java.util.stream.StreamSupport; +import org.onap.aai.cl.api.Logger; +import org.onap.aai.cl.eelf.LoggerFactory; public final class JanusChampGraphImpl extends AbstractTinkerpopChampGraph { - private static final Logger LOGGER = LoggerFactory.getLogger(JanusChampGraphImpl.class); + private static final Logger LOGGER = LoggerFactory.getInstance().getLogger(JanusChampGraphImpl.class); private static final String JANUS_CASSANDRA_KEYSPACE = "storage.cassandra.keyspace"; private static final String JANUS_CQL_KEYSPACE = "storage.cql.keyspace"; private static final String JANUS_HBASE_TABLE = "storage.hbase.table"; @@ -106,11 +130,13 @@ public final class JanusChampGraphImpl extends AbstractTinkerpopChampGraph { } catch (Exception ex) { // Swallow exception. Cassandra may not be reachable. Will retry next time we need to use the graph. - LOGGER.error("Error opening graph: " + ex.getMessage()); + LOGGER.error(ChampJanusMsgs.JANUS_CHAMP_GRAPH_IMPL_ERROR, + "Error opening graph: " + ex.getMessage()); return; } - LOGGER.info("Instantiated data access layer for Janus graph data store with backend: " + storageBackend); + LOGGER.info(ChampJanusMsgs.JANUS_CHAMP_GRAPH_IMPL_INFO, + "Instantiated data access layer for Janus graph data store with backend: " + storageBackend); } public static class Builder { @@ -178,11 +204,13 @@ public final class JanusChampGraphImpl extends AbstractTinkerpopChampGraph { if (createIndexMgmt.getGraphIndex(index.getName()) != null) { createIndexMgmt.rollback(); - LOGGER.info("Index " + index.getName() + " already exists"); + LOGGER.info(ChampJanusMsgs.JANUS_CHAMP_GRAPH_IMPL_INFO, + "Index " + index.getName() + " already exists"); return; //Ignore, index already exists } - LOGGER.info("Create index " + index.getName()); + LOGGER.info(ChampJanusMsgs.JANUS_CHAMP_GRAPH_IMPL_INFO, + "Create index " + index.getName()); IndexBuilder ib = createIndexMgmt.buildIndex(index.getName(), Vertex.class); for (ChampField field : index.getFields()) { PropertyKey pk = createIndexMgmt.getOrCreatePropertyKey(field.getName()); @@ -296,7 +324,8 @@ public final class JanusChampGraphImpl extends AbstractTinkerpopChampGraph { return; //Ignore, index already exists } - LOGGER.info("Create edge index " + index.getName()); + LOGGER.info(ChampJanusMsgs.JANUS_CHAMP_GRAPH_IMPL_INFO, + "Create edge index " + index.getName()); createIndexMgmt.buildIndex(index.getName(), Edge.class).addKey(pk).buildCompositeIndex(); createIndexMgmt.commit(); @@ -410,11 +439,13 @@ public final class JanusChampGraphImpl extends AbstractTinkerpopChampGraph { .timeout(REGISTER_OBJECT_INDEX_TIMEOUT_SECS, ChronoUnit.SECONDS) .call() .getSucceeded()) { - LOGGER.warn("Object index was created, but timed out while waiting for it to be registered"); + LOGGER.warn(ChampJanusMsgs.JANUS_CHAMP_GRAPH_IMPL_WARN, + "Object index was created, but timed out while waiting for it to be registered"); return; } } catch (InterruptedException e) { - LOGGER.warn("Interrupted while waiting for object index creation status"); + LOGGER.warn(ChampJanusMsgs.JANUS_CHAMP_GRAPH_IMPL_WARN, + "Interrupted while waiting for object index creation status"); Thread.currentThread().interrupt(); return; } @@ -426,11 +457,13 @@ public final class JanusChampGraphImpl extends AbstractTinkerpopChampGraph { updateIndexMgmt.updateIndex(updateIndexMgmt.getGraphIndex(indexName), SchemaAction.REINDEX).get(); updateIndexMgmt.commit(); } catch (InterruptedException e) { - LOGGER.warn("Interrupted while reindexing for object index"); + LOGGER.warn(ChampJanusMsgs.JANUS_CHAMP_GRAPH_IMPL_WARN, + "Interrupted while reindexing for object index"); Thread.currentThread().interrupt(); return; } catch (ExecutionException e) { - LOGGER.warn("Exception occurred during reindexing procedure for creating object index " + indexName, e); + LOGGER.warn(ChampJanusMsgs.JANUS_CHAMP_GRAPH_IMPL_WARN, + "Exception occurred during reindexing procedure for creating object index " + indexName + ". " + e.getMessage()); } try { @@ -439,7 +472,8 @@ public final class JanusChampGraphImpl extends AbstractTinkerpopChampGraph { .timeout(2, ChronoUnit.MINUTES) .call(); } catch (InterruptedException e) { - LOGGER.warn("Interrupted while waiting for index to transition to ENABLED state"); + LOGGER.warn(ChampJanusMsgs.JANUS_CHAMP_GRAPH_IMPL_WARN, + "Interrupted while waiting for index to transition to ENABLED state"); Thread.currentThread().interrupt(); return; } @@ -552,11 +586,13 @@ public final class JanusChampGraphImpl extends AbstractTinkerpopChampGraph { PropertyKey pk = createIndexMgmt.getOrCreatePropertyKey(KEY_PROPERTY_NAME); if (!vertexIndexExists) { - LOGGER.info("Create Index " + KEY_PROPERTY_NAME); + LOGGER.info(ChampJanusMsgs.JANUS_CHAMP_GRAPH_IMPL_INFO, + "Create Index " + KEY_PROPERTY_NAME); createIndexMgmt.buildIndex(KEY_PROPERTY_NAME, Vertex.class).addKey(pk).buildCompositeIndex(); } if (!edgeIndexExists) { - LOGGER.info("Create Index " + EDGE_IX_NAME); + LOGGER.info(ChampJanusMsgs.JANUS_CHAMP_GRAPH_IMPL_INFO, + "Create Index " + EDGE_IX_NAME); createIndexMgmt.buildIndex(EDGE_IX_NAME, Edge.class).addKey(pk).buildCompositeIndex(); } createIndexMgmt.commit(); @@ -570,13 +606,15 @@ public final class JanusChampGraphImpl extends AbstractTinkerpopChampGraph { } else { createIndexMgmt.rollback(); - LOGGER.info("Index " + KEY_PROPERTY_NAME + " and " + EDGE_IX_NAME + " already exist"); + LOGGER.info(ChampJanusMsgs.JANUS_CHAMP_GRAPH_IMPL_INFO, + "Index " + KEY_PROPERTY_NAME + " and " + EDGE_IX_NAME + " already exist"); } if (!nodeTypeIndexExists) { - LOGGER.info("Create Index " + NODE_TYPE_PROPERTY_NAME); + LOGGER.info(ChampJanusMsgs.JANUS_CHAMP_GRAPH_IMPL_INFO, + "Create Index " + NODE_TYPE_PROPERTY_NAME); createIndexMgmt = graph.openManagement(); PropertyKey pk = createIndexMgmt.getOrCreatePropertyKey(NODE_TYPE_PROPERTY_NAME); createIndexMgmt.buildIndex(NODE_TYPE_PROPERTY_NAME, Vertex.class).addKey(pk).buildCompositeIndex(); diff --git a/champ-lib/champ-janus/src/main/resources/logging/ChampJanusMsgs.properties b/champ-lib/champ-janus/src/main/resources/logging/ChampJanusMsgs.properties new file mode 100644 index 0000000..08a05c6 --- /dev/null +++ b/champ-lib/champ-janus/src/main/resources/logging/ChampJanusMsgs.properties @@ -0,0 +1,31 @@ +#Resource key=Error Code|Message text|Resolution text |Description text +####### +#Newlines can be utilized to add some clarity ensuring continuing line +#has atleast one leading space +#ResourceKey=\ +# ERR0000E\ +# Sample error msg txt\ +# Sample resolution msg\ +# Sample description txt +# +###### +#Error code classification category +#000 Info/Debug +#100 Permission errors +#200 Availability errors/Timeouts +#300 Data errors +#400 Schema Interface type/validation errors +#500 Business process errors +#900 Unknown errors +# +######################################################################## + +JANUS_CHAMP_GRAPH_IMPL_INFO=\ + CJ0011I|\ + JanusChampGraphImpl: {0} +JANUS_CHAMP_GRAPH_IMPL_ERROR=\ + CJ0511E|\ + JanusChampGraphImpl Error: {0} +JANUS_CHAMP_GRAPH_IMPL_WARN=\ + CJ0512E|\ + JanusChampGraphImpl Warning: {0} diff --git a/champ-lib/champ-titan/src/main/java/org/onap/aai/champtitan/graph/impl/ChampTitanMsgs.java b/champ-lib/champ-titan/src/main/java/org/onap/aai/champtitan/graph/impl/ChampTitanMsgs.java new file mode 100644 index 0000000..39bce81 --- /dev/null +++ b/champ-lib/champ-titan/src/main/java/org/onap/aai/champtitan/graph/impl/ChampTitanMsgs.java @@ -0,0 +1,40 @@ +/** + * ============LICENSE_START========================================== + * org.onap.aai + * =================================================================== + * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017-2018 Amdocs + * =================================================================== + * 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. + * ============LICENSE_END============================================ + */ +package org.onap.aai.champtitan.graph.impl; + +import com.att.eelf.i18n.EELFResourceManager; +import org.onap.aai.cl.eelf.LogMessageEnum; + +public enum ChampTitanMsgs implements LogMessageEnum { + + TITAN_CHAMP_GRAPH_IMPL_INFO, + TITAN_CHAMP_GRAPH_IMPL_ERROR, + TITAN_CHAMP_GRAPH_IMPL_WARN; + + + + /** + * Static initializer to ensure the resource bundles for this class are loaded... + */ + static { + EELFResourceManager.loadMessageBundle("logging/ChampTitanMsgs"); + } +} diff --git a/champ-lib/champ-titan/src/main/java/org/onap/aai/champtitan/graph/impl/TitanChampGraphImpl.java b/champ-lib/champ-titan/src/main/java/org/onap/aai/champtitan/graph/impl/TitanChampGraphImpl.java index 293b51c..2cec6ef 100644 --- a/champ-lib/champ-titan/src/main/java/org/onap/aai/champtitan/graph/impl/TitanChampGraphImpl.java +++ b/champ-lib/champ-titan/src/main/java/org/onap/aai/champtitan/graph/impl/TitanChampGraphImpl.java @@ -22,8 +22,16 @@ package org.onap.aai.champtitan.graph.impl; import java.security.SecureRandom; import java.time.temporal.ChronoUnit; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; import java.util.Map.Entry; +import java.util.NoSuchElementException; +import java.util.Optional; +import java.util.Spliterator; +import java.util.Spliterators; import java.util.concurrent.ExecutionException; import java.util.stream.Stream; import java.util.stream.StreamSupport; @@ -47,8 +55,8 @@ import org.onap.aai.champcore.model.ChampRelationshipIndex; import org.onap.aai.champcore.model.ChampSchema; import org.onap.aai.champcore.schema.ChampSchemaEnforcer; import org.onap.aai.champcore.schema.DefaultChampSchemaEnforcer; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import org.onap.aai.cl.api.Logger; +import org.onap.aai.cl.eelf.LoggerFactory; import com.thinkaurelius.titan.core.Cardinality; import com.thinkaurelius.titan.core.EdgeLabel; @@ -67,7 +75,7 @@ import com.thinkaurelius.titan.graphdb.database.management.ManagementSystem; public final class TitanChampGraphImpl extends AbstractTinkerpopChampGraph { - private static final Logger LOGGER = LoggerFactory.getLogger(TitanChampGraphImpl.class); + private static final Logger LOGGER = LoggerFactory.getInstance().getLogger(TitanChampGraphImpl.class); private static final String TITAN_UNIQUE_SUFFIX = "graph.unique-instance-id-suffix"; private static final String TITAN_CASSANDRA_KEYSPACE = "storage.cassandra.keyspace"; private static final String TITAN_HBASE_TABLE = "storage.hbase.table"; @@ -115,7 +123,8 @@ public final class TitanChampGraphImpl extends AbstractTinkerpopChampGraph { throw new RuntimeException("Unknown storage.backend=" + storageBackend); } - LOGGER.info("Instantiated data access layer for Titan graph data store with backend: " + storageBackend); + LOGGER.info(ChampTitanMsgs.TITAN_CHAMP_GRAPH_IMPL_INFO, + "Instantiated data access layer for Titan graph data store with backend: " + storageBackend); this.graph = titanGraphBuilder.open(); } @@ -371,11 +380,13 @@ public final class TitanChampGraphImpl extends AbstractTinkerpopChampGraph { .timeout(REGISTER_OBJECT_INDEX_TIMEOUT_SECS, ChronoUnit.SECONDS) .call() .getSucceeded()) { - LOGGER.warn("Object index was created, but timed out while waiting for it to be registered"); + LOGGER.warn(ChampTitanMsgs.TITAN_CHAMP_GRAPH_IMPL_WARN, + "Object index was created, but timed out while waiting for it to be registered"); return; } } catch (InterruptedException e) { - LOGGER.warn("Interrupted while waiting for object index creation status"); + LOGGER.warn(ChampTitanMsgs.TITAN_CHAMP_GRAPH_IMPL_WARN, + "Interrupted while waiting for object index creation status"); Thread.currentThread().interrupt(); return; } @@ -387,11 +398,13 @@ public final class TitanChampGraphImpl extends AbstractTinkerpopChampGraph { updateIndexMgmt.updateIndex(updateIndexMgmt.getGraphIndex(indexName),SchemaAction.REINDEX).get(); updateIndexMgmt.commit(); } catch (InterruptedException e) { - LOGGER.warn("Interrupted while reindexing for object index"); + LOGGER.warn(ChampTitanMsgs.TITAN_CHAMP_GRAPH_IMPL_WARN, + "Interrupted while reindexing for object index"); Thread.currentThread().interrupt(); return; } catch (ExecutionException e) { - LOGGER.warn("Exception occurred during reindexing procedure for creating object index " + indexName, e); + LOGGER.warn(ChampTitanMsgs.TITAN_CHAMP_GRAPH_IMPL_WARN, + "Exception occurred during reindexing procedure for creating object index " + indexName + ". " + e.getMessage()); } try { @@ -400,7 +413,8 @@ public final class TitanChampGraphImpl extends AbstractTinkerpopChampGraph { .timeout(10, ChronoUnit.MINUTES) .call(); } catch (InterruptedException e) { - LOGGER.warn("Interrupted while waiting for index to transition to ENABLED state"); + LOGGER.warn(ChampTitanMsgs.TITAN_CHAMP_GRAPH_IMPL_WARN, + "Interrupted while waiting for index to transition to ENABLED state"); Thread.currentThread().interrupt(); return; } @@ -489,6 +503,7 @@ public final class TitanChampGraphImpl extends AbstractTinkerpopChampGraph { @Override public void createDefaultIndexes() { - LOGGER.error("No default indexes being created"); + LOGGER.error(ChampTitanMsgs.TITAN_CHAMP_GRAPH_IMPL_ERROR, + "No default indexes being created"); } } diff --git a/champ-lib/champ-titan/src/main/resources/logging/ChampTitanMsgs.properties b/champ-lib/champ-titan/src/main/resources/logging/ChampTitanMsgs.properties new file mode 100644 index 0000000..5b0e1bc --- /dev/null +++ b/champ-lib/champ-titan/src/main/resources/logging/ChampTitanMsgs.properties @@ -0,0 +1,31 @@ +#Resource key=Error Code|Message text|Resolution text |Description text +####### +#Newlines can be utilized to add some clarity ensuring continuing line +#has atleast one leading space +#ResourceKey=\ +# ERR0000E\ +# Sample error msg txt\ +# Sample resolution msg\ +# Sample description txt +# +###### +#Error code classification category +#000 Info/Debug +#100 Permission errors +#200 Availability errors/Timeouts +#300 Data errors +#400 Schema Interface type/validation errors +#500 Business process errors +#900 Unknown errors +# +######################################################################## + +TITAN_CHAMP_GRAPH_IMPL_INFO=\ + CT0011I|\ + TitanChampGraphImpl: {0} +TITAN_CHAMP_GRAPH_IMPL_ERROR=\ + CT0511E|\ + TitanChampGraphImpl Error: {0} +TITAN_CHAMP_GRAPH_IMPL_WARN=\ + CT0512E|\ + TitanChampGraphImpl Warning: {0} diff --git a/champ-service/src/main/java/org/onap/champ/ChampApplication.java b/champ-service/src/main/java/org/onap/champ/ChampApplication.java index 1f1fa3c..bb0a448 100644 --- a/champ-service/src/main/java/org/onap/champ/ChampApplication.java +++ b/champ-service/src/main/java/org/onap/champ/ChampApplication.java @@ -22,8 +22,11 @@ package org.onap.champ; import java.util.HashMap; import java.util.Map; + import javax.annotation.PostConstruct; + import org.eclipse.jetty.util.security.Password; +import org.onap.champ.service.logging.LoggingUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; @@ -39,6 +42,8 @@ public class ChampApplication extends SpringBootServletInitializer { private Environment env; public static void main(String[] args) { + LoggingUtil.initMdcContext(); + String keyStorePassword = System.getProperty("KEY_STORE_PASSWORD"); if (keyStorePassword == null || keyStorePassword.isEmpty()) { throw new RuntimeException("Environment property KEY_STORE_PASSWORD not set"); diff --git a/champ-service/src/main/java/org/onap/champ/service/logging/LoggingUtil.java b/champ-service/src/main/java/org/onap/champ/service/logging/LoggingUtil.java index 17ac270..a99be4c 100644 --- a/champ-service/src/main/java/org/onap/champ/service/logging/LoggingUtil.java +++ b/champ-service/src/main/java/org/onap/champ/service/logging/LoggingUtil.java @@ -56,6 +56,10 @@ public class LoggingUtil { MdcContext.initialize(transId, "ChampService", "", fromAppId, fromIp); } + + public static void initMdcContext() { + MdcContext.initialize("", "ChampService", "", "", ""); + } /** * Logs the rest request.