diff options
5 files changed, 51 insertions, 211 deletions
diff --git a/epsdk-app-onap/src/main/java/org/onap/portalapp/conf/ExternalAppConfig.java b/epsdk-app-onap/src/main/java/org/onap/portalapp/conf/ExternalAppConfig.java index d9b0f092e..39fb99a95 100644 --- a/epsdk-app-onap/src/main/java/org/onap/portalapp/conf/ExternalAppConfig.java +++ b/epsdk-app-onap/src/main/java/org/onap/portalapp/conf/ExternalAppConfig.java @@ -57,7 +57,6 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.DependsOn; -import org.springframework.context.annotation.EnableAspectJAutoProxy; import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Profile; import org.springframework.context.annotation.PropertySource; @@ -81,7 +80,6 @@ import org.springframework.web.servlet.config.annotation.InterceptorRegistry; @Profile("src") @EnableAsync @EnableScheduling -@EnableAspectJAutoProxy(proxyTargetClass=true) public class ExternalAppConfig extends AppConfig implements Configurable { /** The Constant LOG. */ diff --git a/vid-app-common/src/main/java/org/onap/vid/logging/VidLoggerAspect.java b/vid-app-common/src/main/java/org/onap/vid/logging/VidLoggerAspect.java deleted file mode 100644 index 08aaf09ce..000000000 --- a/vid-app-common/src/main/java/org/onap/vid/logging/VidLoggerAspect.java +++ /dev/null @@ -1,170 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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.vid.logging; - -import static com.att.eelf.configuration.Configuration.MDC_SERVER_FQDN; -import static org.apache.commons.lang3.StringUtils.defaultIfEmpty; - -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.util.Arrays; -import javax.servlet.http.HttpServletRequest; -import org.apache.commons.lang3.StringUtils; -import org.aspectj.lang.ProceedingJoinPoint; -import org.aspectj.lang.annotation.Around; -import org.aspectj.lang.annotation.Aspect; -import org.aspectj.lang.annotation.Pointcut; -import org.onap.portalsdk.core.logging.aspect.EELFLoggerAdvice; -import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; -import org.onap.portalsdk.core.service.AppService; -import org.onap.portalsdk.core.util.SystemProperties; -import org.onap.portalsdk.core.web.support.UserUtils; -import org.onap.vid.controller.ControllersUtils; -import org.onap.vid.utils.SystemPropertiesWrapper; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.context.request.RequestContextHolder; -import org.springframework.web.context.request.ServletRequestAttributes; - - -@Aspect -@org.springframework.context.annotation.Configuration -public class VidLoggerAspect { - - private String canonicalHostName; - private final ControllersUtils controllersUtils; - private final String appName; - - private final EELFLoggerAdvice advice; - - @Autowired - public VidLoggerAspect(EELFLoggerAdvice advice, SystemPropertiesWrapper systemPropertiesWrapper, - AppService appService) { - try { - final InetAddress localHost = InetAddress.getLocalHost(); - canonicalHostName = localHost.getCanonicalHostName(); - } catch (UnknownHostException e) { - // YOLO - canonicalHostName = null; - } - this.advice = advice; - this.controllersUtils = new ControllersUtils(systemPropertiesWrapper); - - this.appName = defaultIfEmpty(appService.getDefaultAppName(), SystemProperties.SDK_NAME); - } - - @Pointcut("execution(public * org.onap.vid.controller..*Controller.*(..))") - public void vidControllers() {} - - @Around("vidControllers() && (" + - " @within(org.onap.portalsdk.core.logging.aspect.AuditLog)" + - " || @annotation(org.onap.portalsdk.core.logging.aspect.AuditLog)" + - " || @annotation(org.springframework.web.bind.annotation.RequestMapping)" + - ")") - public Object logAuditMethodClassAround(ProceedingJoinPoint joinPoint) throws Throwable { - return logAroundMethod(joinPoint, SystemProperties.SecurityEventTypeEnum.INCOMING_REST_MESSAGE); - } - - private Object logAroundMethod(ProceedingJoinPoint joinPoint, SystemProperties.SecurityEventTypeEnum securityEventType) throws Throwable { - //Before - Object[] passOnArgs = new Object[] {joinPoint.getSignature().getDeclaringType().getName(),joinPoint.getSignature().getName()}; - Object[] returnArgs = advice.before(securityEventType, fabricateArgsWithNull(), passOnArgs); - - HttpServletRequest httpServletRequest = httpServletRequestOrNull(joinPoint); - fixSetRequestBasedDefaultsIntoGlobalLoggingContext(httpServletRequest, - joinPoint.getSignature().getDeclaringType().getName()); - - fixServerFqdnInMDC(); - - //Execute the actual method - Object result; - String restStatus = "COMPLETE"; - try { - result = joinPoint.proceed(); - } catch(Exception e) { - restStatus = "ERROR"; - throw e; - } finally { - fixStatusCodeInMDC(restStatus); - advice.after(securityEventType, restStatus, joinPoint.getArgs(), returnArgs, passOnArgs); - } - - return result; - } - - // Set the status code into MDC *before* the metrics log is written by advice.after() - private void fixStatusCodeInMDC(String restStatus) { - EELFLoggerDelegate.mdcPut(SystemProperties.STATUS_CODE, restStatus); - } - - /** - * Returns an array with a single entry with a null value. This will stop org.onap.portalsdk.core.logging.aspect.EELFLoggerAdvice.before - * from throwing on ArrayIndexOutOfBound, and also prevent SessionExpiredException. - */ - private Object[] fabricateArgsWithNull() { - return new Object[]{null}; - } - - /** - * Finds the first joinPoint's param which is an HttpServletRequest. If not found, use Spring's RequestContextHolder - * to retrieve it. - * - * @return null or the current httpServletRequest - */ - private HttpServletRequest httpServletRequestOrNull(ProceedingJoinPoint joinPoint) { - final Object httpServletRequest = Arrays.stream(joinPoint.getArgs()) - .filter(param -> param instanceof HttpServletRequest) - .findFirst() - .orElseGet(() -> { - try { - return ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest(); - } catch (Exception e) { // ClassCast, IllegalState, etc. - return null; - } - }); - - return (HttpServletRequest) httpServletRequest; - } - - /** - * Mimics a part from org.onap.portalsdk.core.logging.aspect.EELFLoggerAdvice.before, but with much more carefulness - * of exceptions and defaults. Main difference is that if no session, function does not throw. It just fallback to - * an empty loginId. - */ - private void fixSetRequestBasedDefaultsIntoGlobalLoggingContext(HttpServletRequest httpServletRequest, String className) { - if (httpServletRequest != null) { - - EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(className); - String requestId = UserUtils.getRequestId(httpServletRequest); - String loginId = controllersUtils.extractUserId(httpServletRequest); - - logger.setRequestBasedDefaultsIntoGlobalLoggingContext(httpServletRequest, appName, requestId, loginId); - } - } - - // Override the non-canonical hostname set by EELFLoggerDelegate::setGlobalLoggingContext() - // that was invoked by advice.before() (and some other SDK cases) - private void fixServerFqdnInMDC() { - if (!StringUtils.isBlank(canonicalHostName)) { - EELFLoggerDelegate.mdcPut(MDC_SERVER_FQDN, canonicalHostName); - } - } - -} diff --git a/vid-automation/src/test/java/org/onap/vid/api/AsyncInstantiationMacroApiTest.java b/vid-automation/src/test/java/org/onap/vid/api/AsyncInstantiationMacroApiTest.java index 1f0b0f3aa..538a4d03a 100644 --- a/vid-automation/src/test/java/org/onap/vid/api/AsyncInstantiationMacroApiTest.java +++ b/vid-automation/src/test/java/org/onap/vid/api/AsyncInstantiationMacroApiTest.java @@ -1,21 +1,57 @@ package org.onap.vid.api; +import static java.util.stream.Collectors.counting; +import static java.util.stream.Collectors.groupingBy; +import static java.util.stream.Collectors.toList; +import static java.util.stream.Collectors.toMap; +import static org.hamcrest.CoreMatchers.hasItem; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.CoreMatchers.startsWith; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.hasSize; +import static org.onap.simulator.presetGenerator.presets.mso.PresetMSOOrchestrationRequestGet.COMPLETE; +import static org.onap.simulator.presetGenerator.presets.mso.PresetMSOServiceInstanceGen2WithNames.Keys; +import static org.testng.AssertJUnit.assertEquals; +import static org.testng.AssertJUnit.assertTrue; +import static vid.automation.test.infra.Features.FLAG_1906_INSTANTIATION_API_USER_VALIDATION; +import static vid.automation.test.services.SimulatorApi.registerExpectationFromPresets; +import static vid.automation.test.utils.ExtendedHamcrestMatcher.hasItemsFromCollection; + import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; +import java.util.Arrays; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; +import java.util.UUID; +import java.util.concurrent.atomic.AtomicReference; +import java.util.stream.IntStream; +import java.util.stream.Stream; import net.bytebuddy.utility.RandomString; import net.javacrumbs.jsonunit.JsonAssert; import org.apache.commons.lang3.StringUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.hamcrest.collection.IsCollectionWithSize; +import org.onap.sdc.ci.tests.datatypes.UserCredentials; import org.onap.simulator.presetGenerator.presets.BasePresets.BasePreset; import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetCloudOwnersByCloudRegionId; import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetSubscribersGet; import org.onap.simulator.presetGenerator.presets.ecompportal_att.PresetGetSessionSlotCheckIntervalGet; -import org.onap.simulator.presetGenerator.presets.mso.*; +import org.onap.simulator.presetGenerator.presets.mso.PresetMSOAssignServiceInstanceGen2WithNames; +import org.onap.simulator.presetGenerator.presets.mso.PresetMSOCreateServiceInstanceGen2WithNames; +import org.onap.simulator.presetGenerator.presets.mso.PresetMSODeleteMacroService; +import org.onap.simulator.presetGenerator.presets.mso.PresetMSOOrchestrationRequestGet; +import org.onap.simulator.presetGenerator.presets.mso.PresetMSOOrchestrationRequestGetErrorResponse; +import org.onap.simulator.presetGenerator.presets.mso.PresetMSOOrchestrationRequestsManyInstanceStatusesGet; +import org.onap.simulator.presetGenerator.presets.mso.PresetMSOServiceInstanceGen2ErrorResponse; import org.onap.vid.model.asyncInstantiation.JobAuditStatus; import org.onap.vid.model.asyncInstantiation.ServiceInfo; -import org.onap.sdc.ci.tests.datatypes.UserCredentials; import org.springframework.http.HttpStatus; import org.springframework.web.client.HttpClientErrorException; import org.springframework.web.client.HttpServerErrorException; @@ -28,23 +64,6 @@ import vid.automation.test.model.JobStatus; import vid.automation.test.model.ServiceAction; import vid.automation.test.services.SimulatorApi; -import java.util.*; -import java.util.concurrent.atomic.AtomicReference; -import java.util.stream.IntStream; -import java.util.stream.Stream; - -import static java.util.stream.Collectors.*; -import static org.hamcrest.CoreMatchers.*; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.hasSize; -import static org.onap.simulator.presetGenerator.presets.mso.PresetMSOOrchestrationRequestGet.COMPLETE; -import static org.onap.simulator.presetGenerator.presets.mso.PresetMSOServiceInstanceGen2WithNames.Keys; -import static org.testng.AssertJUnit.assertEquals; -import static org.testng.AssertJUnit.assertTrue; -import static vid.automation.test.infra.Features.FLAG_1906_INSTANTIATION_API_USER_VALIDATION; -import static vid.automation.test.services.SimulatorApi.registerExpectationFromPresets; -import static vid.automation.test.utils.ExtendedHamcrestMatcher.hasItemsFromCollection; - public class AsyncInstantiationMacroApiTest extends AsyncInstantiationBase { private static final Logger logger = LogManager.getLogger(AsyncInstantiationMacroApiTest.class); @@ -116,9 +135,12 @@ public class AsyncInstantiationMacroApiTest extends AsyncInstantiationBase { deleteOneJobHavingTheStatus(jobs, JobStatus.IN_PROGRESS); } catch (HttpClientErrorException e) { JsonAssert.assertJsonPartEquals( - "Service status does not allow deletion from the queue (Request id: null)", - e.getResponseBodyAsString(), - "message" + String.format( + "Service status does not allow deletion from the queue (Request id: %s)", + e.getResponseHeaders().getFirst("X-ECOMP-RequestID-echo") + ), + e.getResponseBodyAsString(), + "message" ); assertThat(e.getStatusCode(), is(HttpStatus.METHOD_NOT_ALLOWED)); diff --git a/vid-automation/src/test/java/org/onap/vid/more/LoggerFormatTest.java b/vid-automation/src/test/java/org/onap/vid/more/LoggerFormatTest.java index 7f2d48469..81d255391 100644 --- a/vid-automation/src/test/java/org/onap/vid/more/LoggerFormatTest.java +++ b/vid-automation/src/test/java/org/onap/vid/more/LoggerFormatTest.java @@ -40,7 +40,7 @@ public class LoggerFormatTest extends BaseApiTest { private final Logger logger = LogManager.getLogger(LoggerFormatTest.class); public enum LogName { - audit, error, audit2019, metrics2019, metrics + audit2019, error, metrics2019 } @BeforeClass @@ -54,13 +54,8 @@ public class LoggerFormatTest extends BaseApiTest { } @Test - public void validateAuditLogsFormat() { - validateLogsFormat(LogName.audit); - } - - @Test public void validateAudit2019LogsFormat() { - validateLogsFormat(LogName.audit2019, "audit-ELS-2019.11", 0); + validateLogsFormat(LogName.audit2019, "audit-ELS-2019.11", 0.8); } @Test(enabled = false) // no total-score is returned for error-log @@ -69,11 +64,6 @@ public class LoggerFormatTest extends BaseApiTest { } @Test - public void validateMetricsLogsFormat() { - validateLogsFormat(LogName.metrics, "metric"); - } - - @Test public void validateMetrics2019LogsFormat() { validateLogsFormat(LogName.metrics2019, "metric-ELS-2019.11"); } diff --git a/vid-automation/src/test/java/org/onap/vid/more/RequestIdFilterInstalled.java b/vid-automation/src/test/java/org/onap/vid/more/RequestIdFilterInstalled.java index 07bd3b0dc..93ab14036 100644 --- a/vid-automation/src/test/java/org/onap/vid/more/RequestIdFilterInstalled.java +++ b/vid-automation/src/test/java/org/onap/vid/more/RequestIdFilterInstalled.java @@ -61,7 +61,7 @@ public class RequestIdFilterInstalled extends BaseApiTest { null, OperationalEnvironmentControllerApiTest.GET_CLOUD_RESOURCES_REQUEST_STATUS ); - assertThatUuidInResponseAndUuidIsInARecentLog(LogName.audit, responseAndUuid); + assertThatUuidInResponseAndUuidIsInARecentLog(LogName.audit2019, responseAndUuid); } @@ -74,7 +74,7 @@ public class RequestIdFilterInstalled extends BaseApiTest { "{}", ServiceInstanceMsoApiTest.DEACTIVATE_OK_JSON ); - assertThatUuidInResponseAndUuidIsInARecentLog(LogName.audit, responseAndUuid); + assertThatUuidInResponseAndUuidIsInARecentLog(LogName.audit2019, responseAndUuid); } @Test @@ -98,7 +98,7 @@ public class RequestIdFilterInstalled extends BaseApiTest { "/" + MAINTENANCE_CATEGORY_PARAMETER + "?familyName=PARAMETER_STANDARDIZATION", null ); - assertThatUuidInResponseAndUuidIsInARecentLog(LogName.audit, responseAndUuid); + assertThatUuidInResponseAndUuidIsInARecentLog(LogName.audit2019, responseAndUuid); /* test should be for: @@ -130,7 +130,7 @@ public class RequestIdFilterInstalled extends BaseApiTest { "/change-management/workflow/" + anyInstanceId, "{}" ); - assertThatUuidInResponseAndUuidIsInARecentLog(LogName.audit, responseAndUuid); + assertThatUuidInResponseAndUuidIsInARecentLog(LogName.audit2019, responseAndUuid); } @@ -139,7 +139,7 @@ public class RequestIdFilterInstalled extends BaseApiTest { final Pair<HttpEntity, String> responseAndUuid = makeRequest( HttpMethod.GET, "/healthCheck", null ); - assertThatUuidInResponseAndUuidIsInARecentLog(LogName.audit, responseAndUuid); + assertThatUuidInResponseAndUuidIsInARecentLog(LogName.audit2019, responseAndUuid); } private void assertThatUuidInResponseAndUuidIsInARecentLog(LogName logName, Pair<HttpEntity, String> responseAndUuid) { |