From c4347b25ddf03c4f8e25b9443e0e25be102d0ba6 Mon Sep 17 00:00:00 2001 From: "Smokowski, Steve (ss835w)" Date: Thu, 20 Sep 2018 11:04:00 -0400 Subject: Update Logging Update logging to meet Casablanca Spec Change-Id: I029d6c63765992d6f091d96e2b4c34c60d30c484 Issue-ID: SO-947 Signed-off-by: Smokowski, Steve (ss835w) --- .../catalogdb/catalogrest/CatalogDBRestTest.java | 2 +- .../openstack/MsoOpenstackAdaptersApplication.java | 4 +++ .../org/onap/so/adapters/valet/ValetClient.java | 37 ++++++++++++---------- .../adapters/HealthCheckHandlerTest.java | 4 +-- .../so/adapters/sdnc/SDNCAdapterApplication.java | 5 ++- 5 files changed, 32 insertions(+), 20 deletions(-) (limited to 'adapters') diff --git a/adapters/mso-catalog-db-adapter/src/test/java/org/onap/so/adapters/catalogdb/catalogrest/CatalogDBRestTest.java b/adapters/mso-catalog-db-adapter/src/test/java/org/onap/so/adapters/catalogdb/catalogrest/CatalogDBRestTest.java index 8ccf40eff5..e15311eb0e 100644 --- a/adapters/mso-catalog-db-adapter/src/test/java/org/onap/so/adapters/catalogdb/catalogrest/CatalogDBRestTest.java +++ b/adapters/mso-catalog-db-adapter/src/test/java/org/onap/so/adapters/catalogdb/catalogrest/CatalogDBRestTest.java @@ -111,7 +111,7 @@ public class CatalogDBRestTest { assertEquals(Response.Status.OK.getStatusCode(),response.getStatusCode().value()); for(ILoggingEvent logEvent : TestAppender.events) if(logEvent.getLoggerName().equals("org.onap.so.logging.spring.interceptor.LoggingInterceptor") && - logEvent.getMarker().getName().equals("ENTRY") + logEvent.getMarker() != null && logEvent.getMarker().getName().equals("ENTRY") ){ Map mdc = logEvent.getMDCPropertyMap(); assertNotNull(mdc.get(ONAPLogConstants.MDCs.INSTANCE_UUID)); diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/openstack/MsoOpenstackAdaptersApplication.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/openstack/MsoOpenstackAdaptersApplication.java index 02aa0843ae..a9aa50f654 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/openstack/MsoOpenstackAdaptersApplication.java +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/openstack/MsoOpenstackAdaptersApplication.java @@ -22,6 +22,8 @@ package org.onap.so.adapters.openstack; import java.util.concurrent.Executor; +import org.onap.so.logging.jaxrs.filter.MDCTaskDecorator; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @@ -38,6 +40,7 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; @EntityScan({ "org.onap.so.db.catalog.beans", "org.onap.so.db.request.beans"}) public class MsoOpenstackAdaptersApplication { + @Value("${mso.async.core-pool-size}") private int corePoolSize; @@ -63,6 +66,7 @@ public class MsoOpenstackAdaptersApplication { @Bean public Executor asyncExecutor() { ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); + executor.setTaskDecorator(new MDCTaskDecorator()); executor.setCorePoolSize(corePoolSize); executor.setMaxPoolSize(maxPoolSize); executor.setQueueCapacity(queueCapacity); diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/valet/ValetClient.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/valet/ValetClient.java index 5cce4dd35f..2f688dbf48 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/valet/ValetClient.java +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/valet/ValetClient.java @@ -50,6 +50,8 @@ import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; +import org.springframework.http.client.BufferingClientHttpRequestFactory; +import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; import org.springframework.web.client.RestTemplate; import org.springframework.stereotype.Component; @@ -108,13 +110,11 @@ public class ValetClient { URI uri = builder.build(); ValetCreateRequest vcr = this.createValetCreateRequest(regionId, tenantId, serviceInstanceId, vnfId, vnfName, vfModuleId, vfModuleName, keystoneUrl, heatRequest); - RestTemplate restTemplate = new RestTemplate(); String body = mapper.writeValueAsString(vcr); HttpHeaders headers = generateHeaders(requestId); - HttpEntity entity = new HttpEntity<>(body, headers); - LOGGER.debug("valet create req: " + uri.toString() + HEADERS + headers.toString() + BODY + body); + HttpEntity entity = new HttpEntity<>(body, headers); - response = restTemplate.exchange(uri, HttpMethod.POST, entity, ValetCreateResponse.class); + response = getRestTemplate().exchange(uri, HttpMethod.POST, entity, ValetCreateResponse.class); gvr = this.getGVRFromResponse(response); } catch (Exception e) { LOGGER.error("An exception occurred in callValetCreateRequest", e); @@ -123,6 +123,12 @@ public class ValetClient { return gvr; } + private RestTemplate getRestTemplate(){ + RestTemplate restTemplate = new RestTemplate(); + restTemplate.setRequestFactory(new BufferingClientHttpRequestFactory(new HttpComponentsClientHttpRequestFactory())); + return restTemplate; + } + /* * This method will be invoked to send an Update request to Valet. */ @@ -135,14 +141,13 @@ public class ValetClient { UriBuilder builder = UriBuilder.fromPath(baseUrl).path(basePath).queryParam(REQUEST_ID, requestId); URI uri = builder.build(); - ValetUpdateRequest vur = this.createValetUpdateRequest(regionId, tenantId, serviceInstanceId, vnfId, vnfName, vfModuleId, vfModuleName, keystoneUrl, heatRequest); - RestTemplate restTemplate = new RestTemplate(); + ValetUpdateRequest vur = this.createValetUpdateRequest(regionId, tenantId, serviceInstanceId, vnfId, vnfName, vfModuleId, vfModuleName, keystoneUrl, heatRequest); String body = mapper.writeValueAsString(vur); HttpHeaders headers = generateHeaders(requestId); HttpEntity entity = new HttpEntity<>(body, headers); - LOGGER.debug("valet update req: " + uri.toString() + HEADERS + headers.toString() + BODY + body); + - response = restTemplate.exchange(uri, HttpMethod.PUT, entity, ValetUpdateResponse.class); + response = getRestTemplate().exchange(uri, HttpMethod.PUT, entity, ValetUpdateResponse.class); gvr = this.getGVRFromResponse(response); } catch (Exception e) { LOGGER.error("An exception occurred in callValetUpdateRequest", e); @@ -163,13 +168,13 @@ public class ValetClient { URI uri = builder.build(); ValetDeleteRequest vdr = this.createValetDeleteRequest(regionId, tenantId, vfModuleId, vfModuleName); - RestTemplate restTemplate = new RestTemplate(); + String body = mapper.writeValueAsString(vdr); HttpHeaders headers = generateHeaders(requestId); HttpEntity entity = new HttpEntity<>(body, headers); - LOGGER.debug("valet delete req: " + uri.toString() + HEADERS + headers.toString() + ", body=" + body); - response = restTemplate.exchange(uri, HttpMethod.DELETE, entity, ValetDeleteResponse.class); + + response = getRestTemplate().exchange(uri, HttpMethod.DELETE, entity, ValetDeleteResponse.class); gvr = this.getGVRFromResponse(response); } catch (Exception e) { LOGGER.error("An exception occurred in callValetDeleteRequest", e); @@ -190,13 +195,13 @@ public class ValetClient { URI uri = builder.build(requestId); ValetConfirmRequest vcr = this.createValetConfirmRequest(stackId); - RestTemplate restTemplate = new RestTemplate(); + String body = mapper.writeValueAsString(vcr); HttpHeaders headers = generateHeaders(requestId); HttpEntity entity = new HttpEntity<>(body, headers); LOGGER.debug("valet confirm req: " + uri.toString() + HEADERS + headers.toString() + BODY + body); - response = restTemplate.exchange(uri, HttpMethod.PUT, entity, ValetConfirmResponse.class); + response = getRestTemplate().exchange(uri, HttpMethod.PUT, entity, ValetConfirmResponse.class); gvr = this.getGVRFromResponse(response); } catch (Exception e) { LOGGER.error("An exception occurred in callValetConfirmRequest", e); @@ -217,13 +222,13 @@ public class ValetClient { URI uri = builder.build(requestId); ValetRollbackRequest vrr = this.createValetRollbackRequest(stackId, suppressRollback, errorMessage); - RestTemplate restTemplate = new RestTemplate(); + String body = mapper.writeValueAsString(vrr); HttpHeaders headers = generateHeaders(requestId); HttpEntity entity = new HttpEntity<>(body, headers); - LOGGER.debug("valet rollback req: " + uri.toString() + HEADERS + headers.toString() + BODY + body); - response = restTemplate.exchange(uri, HttpMethod.PUT, entity, ValetRollbackResponse.class); + + response = getRestTemplate().exchange(uri, HttpMethod.PUT, entity, ValetRollbackResponse.class); gvr = this.getGVRFromResponse(response); } catch (Exception e) { LOGGER.error("An exception occurred in callValetRollbackRequest", e); diff --git a/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/adapters/HealthCheckHandlerTest.java b/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/adapters/HealthCheckHandlerTest.java index 21ec8f7518..fc12120166 100644 --- a/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/adapters/HealthCheckHandlerTest.java +++ b/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/adapters/HealthCheckHandlerTest.java @@ -68,7 +68,7 @@ public class HealthCheckHandlerTest { assertEquals(Response.Status.OK.getStatusCode(),response.getStatusCode().value()); for(ILoggingEvent logEvent : TestAppender.events) if(logEvent.getLoggerName().equals("org.onap.so.logging.spring.interceptor.LoggingInterceptor") && - logEvent.getMarker().getName().equals("ENTRY") + logEvent.getMarker() != null && logEvent.getMarker().getName().equals("ENTRY") ){ Map mdc = logEvent.getMDCPropertyMap(); assertNotNull(mdc.get(ONAPLogConstants.MDCs.INSTANCE_UUID)); @@ -78,7 +78,7 @@ public class HealthCheckHandlerTest { assertEquals("/manage/health",mdc.get(ONAPLogConstants.MDCs.SERVICE_NAME)); assertEquals("INPROGRESS",mdc.get(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE)); }else if(logEvent.getLoggerName().equals("org.onap.so.logging.spring.interceptor.LoggingInterceptor") && - logEvent.getMarker()!= null && logEvent.getMarker().getName().equals("EXIT")){ + logEvent.getMarker() != null && logEvent.getMarker()!= null && logEvent.getMarker().getName().equals("EXIT")){ Map mdc = logEvent.getMDCPropertyMap(); assertNotNull(mdc.get(ONAPLogConstants.MDCs.REQUEST_ID)); assertNotNull(mdc.get(ONAPLogConstants.MDCs.INVOCATION_ID)); diff --git a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/SDNCAdapterApplication.java b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/SDNCAdapterApplication.java index 3d88a1467a..f88aab08a6 100644 --- a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/SDNCAdapterApplication.java +++ b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/SDNCAdapterApplication.java @@ -22,6 +22,8 @@ package org.onap.so.adapters.sdnc; import java.util.concurrent.Executor; +import org.onap.so.logging.jaxrs.filter.MDCTaskDecorator; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @@ -35,6 +37,7 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; @EntityScan({ "org.onap.so.db.request.beans"}) public class SDNCAdapterApplication { + @Value("${mso.async.core-pool-size}") private int corePoolSize; @@ -61,7 +64,7 @@ public class SDNCAdapterApplication { @Bean public Executor asyncExecutor() { ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); - + executor.setTaskDecorator(new MDCTaskDecorator()); executor.setCorePoolSize(corePoolSize); executor.setMaxPoolSize(maxPoolSize); executor.setQueueCapacity(queueCapacity); -- cgit 1.2.3-korg