From 9d6aea2f8b0edb2a6bb3d6fb449148a096e43a76 Mon Sep 17 00:00:00 2001 From: Shadi Haidar Date: Fri, 13 Jul 2018 11:26:29 -0400 Subject: InventoryAPI Syncup with ECOMP Logging Issue-ID: DCAEGEN2-575 Change-Id: I9df025e3f8ddeb282f980758bdf1dc30491e0d01 Signed-off-by: Shadi Haidar --- .../onap/dcae/inventory/InventoryApplication.java | 26 ++++++++++++++++------ .../dcae/inventory/daos/InventoryDAOManager.java | 10 ++++----- .../exceptions/mappers/DBIExceptionMapper.java | 6 ++--- 3 files changed, 27 insertions(+), 15 deletions(-) (limited to 'src/main/java/org/onap/dcae') diff --git a/src/main/java/org/onap/dcae/inventory/InventoryApplication.java b/src/main/java/org/onap/dcae/inventory/InventoryApplication.java index 09ee260..259ce93 100644 --- a/src/main/java/org/onap/dcae/inventory/InventoryApplication.java +++ b/src/main/java/org/onap/dcae/inventory/InventoryApplication.java @@ -47,6 +47,8 @@ import org.eclipse.jetty.servlets.CrossOriginFilter; import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import ch.qos.logback.classic.LoggerContext; +import ch.qos.logback.classic.util.ContextInitializer; import javax.servlet.DispatcherType; import javax.servlet.FilterRegistration; @@ -62,10 +64,12 @@ import java.util.Locale; */ public class InventoryApplication extends Application { - static final Logger LOG = LoggerFactory.getLogger(InventoryApplication.class); + static final Logger metricsLogger = LoggerFactory.getLogger("metricsLogger"); + static final Logger debugLogger = LoggerFactory.getLogger("debugLogger"); static boolean shouldRemoteFetchConfig = false; public static void main(String[] args) throws Exception { + metricsLogger.info("DCAE inventory application main Startup"); // This is here to try to fix a "high" issue caught by Fortify. Did this **plus** setting locale for each of the // string comparisons that use `toUpper` because of this StackOverflow post: // http://stackoverflow.com/questions/38308777/fixed-fortify-scan-locale-changes-are-reappearing @@ -85,6 +89,15 @@ public class InventoryApplication extends Application { // You are here because you want to use the default way of configuring inventory - YAML file. new InventoryApplication().run(args); } + // revert to using logback.xml: + LoggerContext context = (LoggerContext)LoggerFactory.getILoggerFactory(); + context.reset(); + ContextInitializer initializer = new ContextInitializer(context); + initializer.autoConfig(); + + metricsLogger.info("Starting DCAE inventory application..."); + debugLogger.debug(String.format("Starting DCAE inventory application... args[0]: %s", args[0])); + } @Override @@ -103,7 +116,7 @@ public class InventoryApplication extends Application { public void initialize(Bootstrap bootstrap) { // This Info object was lifted from the Swagger generated io.swagger.api.Bootstrap file. Although it was not generated // correctly. - Info info = new Info().title("DCAE Inventory API").version("0.8.0") + Info info = new Info().title("DCAE Inventory API").version("0.8.1") .description("DCAE Inventory is a web service that provides the following:\n\n1. Real-time data on all DCAE services and their components\n2. Comprehensive details on available DCAE service types\n") .contact(new Contact().email("dcae@lists.onap.org")); // Swagger/servlet/jax-rs magic! @@ -121,8 +134,8 @@ public class InventoryApplication extends Application { @Override public void run(InventoryConfiguration configuration, Environment environment) { - LOG.info("Starting DCAE inventory application"); - LOG.info(String.format("DB driver properties: %s", configuration.getDataSourceFactory().getProperties().toString())); + debugLogger.info("Starting DCAE inventory application"); + debugLogger.info(String.format("DB driver properties: %s", configuration.getDataSourceFactory().getProperties().toString())); InventoryDAOManager.getInstance().setup(environment, configuration); InventoryDAOManager.getInstance().initialize(); @@ -152,10 +165,9 @@ public class InventoryApplication extends Application { final DatabusControllerClient databusControllerClient = new DatabusControllerClient(clientDatabusController, configuration.getDatabusControllerConnection()); DcaeServicesApiServiceFactory.setDatabusControllerClient(databusControllerClient); - - LOG.info("Use of databus controller client is required. Turned on."); + debugLogger.info("Use of DCAE controller client is required. Turned on."); } else { - LOG.warn("Use of databus controller client is *not* required. Turned off."); + debugLogger.warn("Use of DCAE controller client is *not* required. Turned off."); } environment.jersey().register(NotFoundExceptionMapper.class); diff --git a/src/main/java/org/onap/dcae/inventory/daos/InventoryDAOManager.java b/src/main/java/org/onap/dcae/inventory/daos/InventoryDAOManager.java index dbdf546..af1b3e9 100644 --- a/src/main/java/org/onap/dcae/inventory/daos/InventoryDAOManager.java +++ b/src/main/java/org/onap/dcae/inventory/daos/InventoryDAOManager.java @@ -60,7 +60,7 @@ public final class InventoryDAOManager { } - private static final Logger LOG = LoggerFactory.getLogger(InventoryDAOManager.class); + private final static Logger debugLogger = LoggerFactory.getLogger("debugLogger"); // WATCH! Table creation order matters where mapping tables refer to other tables for foreign keys. private static final List DAO_CLASSES = Arrays.asList(DCAEServiceTypesDAO.class, DCAEServicesDAO.class, DCAEServiceComponentsDAO.class, DCAEServicesComponentsMapsDAO.class); @@ -105,10 +105,10 @@ public final class InventoryDAOManager { final InventoryDAO dao = jdbi_local.onDemand(daoClass); if (dao.checkIfTableExists()) { - LOG.info(String.format("Sql table exists: %s", daoClass.getSimpleName())); + debugLogger.info(String.format("Sql table exists: %s", daoClass.getSimpleName())); } else { dao.createTable(); - LOG.info(String.format("Sql table created: %s", daoClass.getSimpleName())); + debugLogger.info(String.format("Sql table created: %s", daoClass.getSimpleName())); } } @@ -120,7 +120,7 @@ public final class InventoryDAOManager { viewName); if (jdbiHandle.createQuery(checkQuery).map(BooleanMapper.FIRST).first()) { - LOG.info(String.format("Sql view exists: %s", viewName)); + debugLogger.info(String.format("Sql view exists: %s", viewName)); } else { StringBuilder sb = new StringBuilder(String.format("create view %s as ", viewName)); sb.append("select s.* from dcae_service_types s "); @@ -128,7 +128,7 @@ public final class InventoryDAOManager { sb.append("on s.type_name = f.type_name and s.type_version = f.max_version"); jdbiHandle.execute(sb.toString()); - LOG.info(String.format("Sql view created: %s", viewName)); + debugLogger.info(String.format("Sql view created: %s", viewName)); } } catch (Exception e) { throw new InventoryDAOManagerSetupException("view does not exist, " + e); diff --git a/src/main/java/org/onap/dcae/inventory/exceptions/mappers/DBIExceptionMapper.java b/src/main/java/org/onap/dcae/inventory/exceptions/mappers/DBIExceptionMapper.java index fb16a51..f461d26 100644 --- a/src/main/java/org/onap/dcae/inventory/exceptions/mappers/DBIExceptionMapper.java +++ b/src/main/java/org/onap/dcae/inventory/exceptions/mappers/DBIExceptionMapper.java @@ -42,7 +42,7 @@ import javax.ws.rs.ext.ExceptionMapper; */ public class DBIExceptionMapper implements ExceptionMapper { - private static final Logger LOG = LoggerFactory.getLogger(DBIExceptionMapper.class); + private final static Logger errorLogger = LoggerFactory.getLogger("errorLogger"); /** * Upon a DBIException, this handler will attempt to re-initialize the Inventory's database connection @@ -53,14 +53,14 @@ public class DBIExceptionMapper implements ExceptionMapp */ @Override public Response toResponse(T exception) { - LOG.error("", exception); + errorLogger.error("", exception); StringBuilder clientMessage = new StringBuilder("There is a database issue."); try { InventoryDAOManager.getInstance().initialize(); clientMessage.append(" Connection has been successfully reset. Please try again."); } catch(Exception e) { - LOG.error(String.format("Failed to re-initialize database connection: %s", e)); + errorLogger.error(String.format("Failed to re-initialize database connection: %s", e.getMessage())); clientMessage.append(" Connection reset attempt has failed. Please try again soon."); } -- cgit 1.2.3-korg