diff options
7 files changed, 111 insertions, 31 deletions
@@ -28,7 +28,7 @@ ECOMP is a trademark and service mark of AT&T Intellectual Property. <groupId>org.onap.dcaegen2.platform</groupId> <artifactId>inventory-api</artifactId> - <version>3.0.1</version> + <version>3.0.2</version> <name>dcaegen2-platform-inventory-api</name> <!--internal <version>3.0.0</version>--> diff --git a/src/main/java/io/swagger/api/impl/DcaeServiceTypesApiServiceImpl.java b/src/main/java/io/swagger/api/impl/DcaeServiceTypesApiServiceImpl.java index 133f28d..0cb108c 100644 --- a/src/main/java/io/swagger/api/impl/DcaeServiceTypesApiServiceImpl.java +++ b/src/main/java/io/swagger/api/impl/DcaeServiceTypesApiServiceImpl.java @@ -47,7 +47,8 @@ import java.util.UUID; @javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaJerseyServerCodegen", date = "2016-04-18T20:16:22.119Z") public class DcaeServiceTypesApiServiceImpl extends DcaeServiceTypesApiService { - private static final Logger LOG = LoggerFactory.getLogger(DcaeServiceTypesApiServiceImpl.class); + private static final Logger metricsLogger = LoggerFactory.getLogger("metricsLogger"); + private static final Logger debugLogger = LoggerFactory.getLogger("debugLogger"); private static int PAGINATION_PAGE_SIZE = 25; private DCAEServiceType createDCAEServiceType(DCAEServiceTypeObject serviceTypeObject, UriInfo uriInfo) { @@ -139,6 +140,8 @@ public class DcaeServiceTypesApiServiceImpl extends DcaeServiceTypesApiService { // Sort by created timestamp - always descending. sb.append(" order by created desc"); + + metricsLogger.info("Query created as: {}." + sb.toString()); Query<DCAEServiceTypeObject> query = jdbiHandle.createQuery(sb.toString()).map(new DCAEServiceTypeObjectMapper()); @@ -208,6 +211,8 @@ public class DcaeServiceTypesApiServiceImpl extends DcaeServiceTypesApiService { response.setLinks(navigationLinks); + debugLogger.debug("Response: {}." + response.toString()); + return Response.ok().entity(response).build(); } @@ -278,7 +283,7 @@ public class DcaeServiceTypesApiServiceImpl extends DcaeServiceTypesApiService { DCAEServicesDAO servicesDAO = InventoryDAOManager.getInstance().getDCAEServicesDAO(); Integer count = servicesDAO.countByType(DCAEServiceObject.DCAEServiceStatus.RUNNING, typeId); - LOG.info(String.format("Checked num DCAE services running: %s, %d", typeId, count)); + metricsLogger.info(String.format("Checked num DCAE services running: %s, %d", typeId, count)); // Allow the updating of an existing DCAE service type IFF there are no running DCAE services for this type diff --git a/src/main/java/io/swagger/api/impl/DcaeServicesApiServiceImpl.java b/src/main/java/io/swagger/api/impl/DcaeServicesApiServiceImpl.java index 26949af..7f08501 100644 --- a/src/main/java/io/swagger/api/impl/DcaeServicesApiServiceImpl.java +++ b/src/main/java/io/swagger/api/impl/DcaeServicesApiServiceImpl.java @@ -47,7 +47,8 @@ import java.util.*; @javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaJerseyServerCodegen", date = "2016-04-18T20:16:22.119Z") public class DcaeServicesApiServiceImpl extends DcaeServicesApiService { - private static final Logger LOG = LoggerFactory.getLogger(DcaeServicesApiServiceImpl.class); + private static final Logger metricsLogger = LoggerFactory.getLogger("metricsLogger"); + private static final Logger debugLogger = LoggerFactory.getLogger("debugLogger"); private static final int PAGINATION_PAGE_SIZE = 25; private static final String COMPONENT_SOURCE_DATA_BUS_CONTROLLER = "DMAAPCONTROLLER"; @@ -93,14 +94,14 @@ public class DcaeServicesApiServiceImpl extends DcaeServicesApiService { .rel("component").title(component.getComponentId()).build(); component.setComponentLink(componentLink); } else { - LOG.warn(String.format("Feed/topic does not exist: %s", sco.getComponentId())); + debugLogger.warn(String.format("Feed/topic does not exist: %s", sco.getComponentId())); } } catch (DatabusControllerClientException e) { - LOG.warn(String.format("%s, %s", e.getMessage(), sco.toString()), e); + debugLogger.warn(String.format("%s, %s", e.getMessage(), sco.toString()), e); } } } else { - LOG.warn(String.format("Handling unknown component source: %s", sco.getComponentSource())); + debugLogger.warn(String.format("Handling unknown component source: %s", sco.getComponentSource())); } serviceComponents.add(component); @@ -118,11 +119,11 @@ public class DcaeServicesApiServiceImpl extends DcaeServicesApiService { List<DCAEServiceObject> serviceObjects = new ArrayList<>(); DateTime createdCutoff = created == null ? DateTime.now(DateTimeZone.UTC) : created; - LOG.info(String.format("Create time upper bound cutoff: %s", createdCutoff.toString())); + metricsLogger.info(String.format("Create time upper bound cutoff: %s", createdCutoff.toString())); // Offset is zero-based index offset = (offset == null) ? 0 : offset; - LOG.info(String.format("Query offset: %d", offset)); + metricsLogger.info(String.format("Query offset: %d", offset)); try (Handle jdbiHandle = InventoryDAOManager.getInstance().getHandle()) { // WATCH! There is the use of "distinct" here. @@ -302,7 +303,7 @@ public class DcaeServicesApiServiceImpl extends DcaeServicesApiService { serviceObjectToSendBack.setModified(modified); transactionContext.setServiceObjectToInsert(serviceObjectToSendBack); } else { - LOG.info(String.format("DCAEServiceObject already exists - updating: %s, %s", + metricsLogger.info(String.format("DCAEServiceObject already exists - updating: %s, %s", serviceObjectFromStore.getCreated().toString(), serviceObjectFromStore.getModified().toString())); 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<InventoryConfiguration> { - 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<InventoryConfiguration> { // 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<InventoryConfiguration> { public void initialize(Bootstrap<InventoryConfiguration> 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<InventoryConfiguration> { @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<InventoryConfiguration> { 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<Class> 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<T extends DBIException> implements ExceptionMapper<T> { - 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<T extends DBIException> 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."); } diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml index aa16762..0c63c48 100644 --- a/src/main/resources/logback.xml +++ b/src/main/resources/logback.xml @@ -19,16 +19,78 @@ ============LICENSE_END========================================================= --> -<configuration> +<configuration scan="true" scanPeriod="30 seconds"> + <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> <layout class="ch.qos.logback.classic.PatternLayout"> <Pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</Pattern> </layout> </appender> + + <property name="LOG_DIR" value="/opt/logs" /> + + <appender name="metricsAppender" class="ch.qos.logback.core.rolling.RollingFileAppender"> + <file>${LOG_DIR}/metrics.log</file> + <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy"> + <!-- rollover daily --> + <fileNamePattern>${LOG_DIR}/metrics-%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern> + <!-- each file should be at most 100MB, keep 2 days worth of history, but at most 200MB --> + <maxFileSize>100MB</maxFileSize> + <maxHistory>2</maxHistory> + <totalSizeCap>200MB</totalSizeCap> + </rollingPolicy> + <layout class="ch.qos.logback.classic.PatternLayout"> + <pattern>%d{yyyy-MM-dd'T'HH:mm:ss.SSS+00:00}|%d{yyyy-MM-dd'T'HH:mm:ss.SSS+00:00}|NULL|UNKNOWN|%thread||inventory||||COMPLETE|0|OK||%-5level||||||||||||||%class{36}:%M:%L: %m%n</pattern> + </layout> + </appender> + + <appender name="debugAppender" class="ch.qos.logback.core.rolling.RollingFileAppender"> + <file>${LOG_DIR}/debug.log</file> + <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy"> + <!-- rollover daily --> + <fileNamePattern>${LOG_DIR}/debug-%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern> + <!-- each file should be at most 100MB, keep 2 days worth of history, but at most 200MB --> + <maxFileSize>100MB</maxFileSize> + <maxHistory>2</maxHistory> + <totalSizeCap>200MB</totalSizeCap> + </rollingPolicy> + <layout class="ch.qos.logback.classic.PatternLayout"> + <pattern>%d{yyyy-MM-dd'T'HH:mm:ss.SSS+00:00}|NULL|%-5level:%class{36}:%M:%L: %m%n</pattern> + </layout> + </appender> + + <appender name="errorAppender" class="ch.qos.logback.core.rolling.RollingFileAppender"> + <file>${LOG_DIR}/error.log</file> + <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy"> + <!-- rollover daily --> + <fileNamePattern>${LOG_DIR}/error-%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern> + <!-- each file should be at most 100MB, keep 2 days worth of history, but at most 200MB --> + <maxFileSize>100MB</maxFileSize> + <maxHistory>2</maxHistory> + <totalSizeCap>200MB</totalSizeCap> + </rollingPolicy> + <layout class="ch.qos.logback.classic.PatternLayout"> + <pattern>%d{yyyy-MM-dd'T'HH:mm:ss.SSS+00:00}|NULL|%thread|inventory||||ERROR|0|ERROR:|%class{36}:%M:%L: %m%n</pattern> + </layout> + </appender> + + <logger name="metricsLogger" level="info" additivity="false"> + <appender-ref ref="metricsAppender" /> + </logger> + + <logger name="debugLogger" level="debug" additivity="false"> + <appender-ref ref="debugAppender" /> + </logger> + + <logger name="errorLogger" level="debug" additivity="false"> + <appender-ref ref="errorAppender" /> + </logger> - <logger name="com" level="INFO"/> + <!--<logger name="com" level="INFO"/> --> - <root level="debug"> - <appender-ref ref="STDOUT" /> - </root> -</configuration> + <root level="info"> + <!-- <appender-ref ref="STDOUT" /> --> + <appender-ref ref="debugAppender" /> + </root> + +</configuration>
\ No newline at end of file |