# ============LICENSE_START=======================================================\r
# Copyright (C) 2021 Pantheon.tech\r
# Modifications Copyright (C) 2021 Bell Canada\r
-# Modifications Copyright (C) 2021 Nordix Foundation\r
+# Modifications Copyright (C) 2021-2022 Nordix Foundation\r
# ================================================================================\r
# Licensed under the Apache License, Version 2.0 (the "License");\r
# you may not use this file except in compliance with the License.\r
spring:\r
main:\r
banner-mode: "off"\r
+ application:\r
+ name: "cps-application"\r
jpa:\r
ddl-auto: create\r
open-in-view: false\r
level:\r
org:\r
springframework: INFO\r
+ onap:\r
+ cps: INFO\r
\r
dmi:\r
auth:\r
/*
* ============LICENSE_START=======================================================
* Copyright (C) 2021 Pantheon.tech
- * Modifications Copyright (C) 2021 Nordix Foundation
+ * Modifications Copyright (C) 2021-2022 Nordix Foundation
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
package org.onap.cps.ncmp.rest.exceptions;
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.onap.cps.ncmp.api.impl.exception.NcmpException;
import org.onap.cps.ncmp.rest.controller.NetworkCmProxyController;
* Exception handler with error message return.
*/
@Slf4j
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
@RestControllerAdvice(assignableTypes = {NetworkCmProxyController.class})
public class NetworkCmProxyRestExceptionHandler {
/*
* ============LICENSE_START=======================================================
* Copyright (C) 2020 Pantheon.tech
- * Modifications Copyright (C) 2021 Nordix Foundation
+ * Modifications Copyright (C) 2021-2022 Nordix Foundation
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
QueryRestController.class})
public class CpsRestExceptionHandler {
- private CpsRestExceptionHandler() {
- }
-
/**
* Default exception handler.
*
<groupId>com.google.code.gson</groupId>\r
<artifactId>gson</artifactId>\r
</dependency>\r
+ <dependency>\r
+ <groupId>org.springframework.boot</groupId>\r
+ <artifactId>spring-boot-starter-aop</artifactId>\r
+ </dependency>\r
<!-- T E S T D E P E N D E N C I E S -->\r
<dependency>\r
<groupId>org.codehaus.groovy</groupId>\r
<artifactId>spring-kafka-test</artifactId>\r
<scope>test</scope>\r
</dependency>\r
+ <dependency>\r
+ <groupId>org.aspectj</groupId>\r
+ <artifactId>aspectjrt</artifactId>\r
+ <scope>test</scope>\r
+ </dependency>\r
</dependencies>\r
</project>\r
--- /dev/null
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 Nordix Foundation
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.cps.aop;
+
+import java.util.Arrays;
+import java.util.Optional;
+import lombok.SneakyThrows;
+import lombok.extern.slf4j.Slf4j;
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.annotation.Around;
+import org.aspectj.lang.annotation.Aspect;
+import org.aspectj.lang.reflect.MethodSignature;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
+import org.springframework.stereotype.Component;
+import org.springframework.util.StopWatch;
+
+@Aspect
+@Component
+@Slf4j
+@ConditionalOnExpression(
+ "'${logging.level.org.onap.cps}'.equalsIgnoreCase('DEBUG')"
+)
+public class CpsLoggingAspectService {
+
+ private static final String ALL_CPS_METHODS = "execution(* org.onap.cps..*(..)))";
+
+ /**
+ * To measure method execution time as a logging.
+ * @param proceedingJoinPoint exposes the proceed(..) method in order to support around advice.
+ * @return empty in case of void otherwise an object of return type
+ */
+ @Around(ALL_CPS_METHODS)
+ @SneakyThrows
+ public Object logMethodExecutionTime(final ProceedingJoinPoint proceedingJoinPoint) {
+ final StopWatch stopWatch = new StopWatch();
+
+ //Calculate method execution time
+ stopWatch.start();
+ final Object logObject = Optional.ofNullable(proceedingJoinPoint.proceed()).orElse("");
+ stopWatch.stop();
+ final MethodSignature methodSignature = (MethodSignature) proceedingJoinPoint.getSignature();
+ //Log method execution time
+ log.debug("Execution time of : {}.{}() with argument[s] = {} having result = {} :: {} ms",
+ methodSignature.getDeclaringType().getSimpleName(),
+ methodSignature.getName(), Arrays.toString(proceedingJoinPoint.getArgs()), logObject,
+ stopWatch.getTotalTimeMillis());
+
+ return logObject;
+ }
+
+}
--- /dev/null
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 Nordix Foundation
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.cps.aop
+
+import org.aspectj.lang.ProceedingJoinPoint
+import org.aspectj.lang.reflect.MethodSignature
+import org.onap.cps.spi.exceptions.DataValidationException
+import spock.lang.Specification
+
+class CpsLoggingAspectServiceSpec extends Specification {
+
+ def mockProceedingJoinPoint = Mock(ProceedingJoinPoint)
+ def mockMethodSignature = Mock(MethodSignature);
+ def objectUnderTest = new CpsLoggingAspectService()
+
+ def setup() {
+ mockMethodSignature.getDeclaringType() >> this.getClass()
+ mockMethodSignature.getDeclaringType().getSimpleName() >> 'CpsLoggingAspectServiceSpec'
+ mockMethodSignature.getName() >> 'logMethodExecutionTime'
+ mockProceedingJoinPoint.getSignature() >> mockMethodSignature
+ }
+
+ def 'Log method execution time.'() {
+ given: 'mock valid arguments'
+ mockProceedingJoinPoint.getArgs() >> 'dataspace-name'
+ when: 'aop intercepts cps method and start calculation of time'
+ objectUnderTest.logMethodExecutionTime(mockProceedingJoinPoint)
+ then: 'process successfully and log details of executed method'
+ 1 * mockProceedingJoinPoint.proceed()
+ }
+
+ def 'Creating a data validation exception for invalid args.'() {
+ given: 'a data validation exception is created'
+ mockProceedingJoinPoint.getArgs() >> {
+ throw new DataValidationException('invalid args',
+ 'invalid method arg(s) is passed', new Throwable())
+ }
+ when: 'aop intercepts cps method and start calculation of time'
+ objectUnderTest.logMethodExecutionTime(mockProceedingJoinPoint)
+ then: 'data validation exception is thrown'
+ thrown(DataValidationException.class)
+ }
+}