add @ServiceLogger Annotation for log print and increase some code annotation
Issue-ID: SO-2963
Signed-off-by: hetengjiao <hetengjiao@chinamobile.com>
Change-Id: I8e7f88aa87cd59d8e5067a68dd49e1801c2fea9f
diff --git a/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/annotation/ServiceLogger.java b/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/annotation/ServiceLogger.java
new file mode 100644
index 0000000..1de29bc
--- /dev/null
+++ b/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/annotation/ServiceLogger.java
@@ -0,0 +1,36 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ # Copyright (c) 2020, CMCC Technologies Co., Ltd.
+ #
+ # 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.so.adapters.nssmf.annotation;
+
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Target({ElementType.METHOD, ElementType.TYPE})
+@Retention(RetentionPolicy.RUNTIME)
+public @interface ServiceLogger {
+
+ String value() default "";
+
+ boolean ignore() default false;
+}
diff --git a/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/controller/NssmfAdapterController.java b/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/controller/NssmfAdapterController.java
index 5360657..02d7468 100644
--- a/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/controller/NssmfAdapterController.java
+++ b/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/controller/NssmfAdapterController.java
@@ -2,8 +2,6 @@
import org.onap.so.adapters.nssmf.service.NssmfManagerService;
import org.onap.so.beans.nsmf.*;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
@@ -13,8 +11,6 @@
@RequestMapping(value = "/api/rest/provMns/v1", produces = {APPLICATION_JSON}, consumes = {APPLICATION_JSON})
public class NssmfAdapterController {
- private static final Logger logger = LoggerFactory.getLogger(NssmfAdapterController.class);
-
@Autowired
private NssmfManagerService nssmfManagerService;
diff --git a/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/interceptor/LoggerInterceptor.java b/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/interceptor/LoggerInterceptor.java
new file mode 100644
index 0000000..ea6a125
--- /dev/null
+++ b/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/interceptor/LoggerInterceptor.java
@@ -0,0 +1,92 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ # Copyright (c) 2020, CMCC Technologies Co., Ltd.
+ #
+ # 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.so.adapters.nssmf.interceptor;
+
+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.aspectj.lang.reflect.MethodSignature;
+import org.onap.so.adapters.nssmf.annotation.ServiceLogger;
+import org.onap.so.adapters.nssmf.util.NssmfAdapterUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.core.annotation.Order;
+import org.springframework.stereotype.Component;
+import java.lang.reflect.Method;
+
+/**
+ * support to print logger of service method
+ */
+@Aspect
+@Order(100)
+@Component
+public class LoggerInterceptor {
+
+ private static final Logger logger = LoggerFactory.getLogger(LoggerInterceptor.class);
+
+ @Pointcut("execution(* org.onap.so.adapters.nssmf.service..*(..))")
+ public void serviceLogger() {
+
+ }
+
+ @Around("serviceLogger()")
+ public Object around(ProceedingJoinPoint joinPoint) {
+ try {
+ MethodSignature signature = (MethodSignature) joinPoint.getSignature();
+ Method method = signature.getMethod();
+
+ Class<?> targetClass = method.getDeclaringClass();
+
+ StringBuilder classAndMethod = new StringBuilder();
+ ServiceLogger classAnnotation = targetClass.getAnnotation(ServiceLogger.class);
+ ServiceLogger methodAnnotation = method.getAnnotation(ServiceLogger.class);
+
+ if (classAnnotation == null && methodAnnotation == null) {
+ return joinPoint.proceed();
+ }
+
+ if (classAnnotation != null) {
+ if (classAnnotation.ignore()) {
+ return joinPoint.proceed();
+ }
+ classAndMethod.append(classAnnotation.value()).append("-");
+ }
+
+ String target = targetClass.getName() + "#" + method.getName();
+
+ String params = NssmfAdapterUtil.marshal(joinPoint.getArgs());
+
+ logger.info("{} Start: Method = {} \nParams = {}", classAndMethod.toString(), target, params);
+
+ long start = System.currentTimeMillis();
+ Object result = joinPoint.proceed();
+ long timeConsuming = System.currentTimeMillis() - start;
+
+ logger.info("\n{} End: Method = {}, Spend time = {}ms \nResult = {}", classAndMethod.toString(), target,
+ timeConsuming, NssmfAdapterUtil.marshal(result));
+ return result;
+
+ } catch (Throwable e) {
+ logger.error(e.getMessage(), e);
+ }
+ return null;
+ }
+}
diff --git a/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/BaseNssmfManager.java b/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/BaseNssmfManager.java
index 185dfaf..97a4c5e 100644
--- a/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/BaseNssmfManager.java
+++ b/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/BaseNssmfManager.java
@@ -31,20 +31,14 @@
import org.onap.so.beans.nsmf.*;
import org.onap.so.db.request.beans.ResourceOperationStatus;
import org.onap.so.db.request.data.repository.ResourceOperationStatusRepository;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Example;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
-import static org.onap.so.adapters.nssmf.util.NssmfAdapterUtil.StatusDesc.ALLOCATE_NSS_SUCCESS;
-import static org.onap.so.adapters.nssmf.util.NssmfAdapterUtil.StatusDesc.MODIFY_NSS_SUCCESS;
import static org.onap.so.adapters.nssmf.util.NssmfAdapterUtil.marshal;
public abstract class BaseNssmfManager implements NssmfManager {
- private static final Logger logger = LoggerFactory.getLogger(BaseNssmfManager.class);
-
protected RestUtil restUtil;
protected ResourceOperationStatusRepository repository;
diff --git a/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/ExternalNssmfManager.java b/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/ExternalNssmfManager.java
index f6584da..16a5b2a 100644
--- a/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/ExternalNssmfManager.java
+++ b/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/ExternalNssmfManager.java
@@ -30,8 +30,6 @@
import org.onap.so.adapters.nssmf.util.NssmfAdapterUtil;
import org.onap.so.beans.nsmf.*;
import org.onap.so.db.request.beans.ResourceOperationStatus;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import static java.lang.String.valueOf;
import static org.onap.so.adapters.nssmf.enums.JobStatus.*;
import static org.onap.so.adapters.nssmf.util.NssmfAdapterUtil.StatusDesc.*;
@@ -40,8 +38,6 @@
public abstract class ExternalNssmfManager extends BaseNssmfManager {
- private static final Logger logger = LoggerFactory.getLogger(ExternalNssmfManager.class);
-
@Override
protected String wrapAllocateReqBody(NssmfAdapterNBIRequest nbiRequest) throws ApplicationException {
return doWrapExtAllocateReqBody(nbiRequest);
@@ -112,19 +108,6 @@
return sendExternalRequest(content);
}
- protected void createStatus(JobStatus jobStatus) throws ApplicationException {
- if (valueOf(restResponse.getStatus()).startsWith("2")) {
- logger.info("save segment and operaton info -> begin");
- NssiResponse response = unMarshal(restResponse.getResponseContent(), NssiResponse.class);
- ResourceOperationStatus status = new ResourceOperationStatus(serviceInfo.getNsiId(), response.getJobId(),
- serviceInfo.getServiceUuid());
- status.setResourceInstanceID(response.getNssiId());
-
- updateDbStatus(status, restResponse.getStatus(), jobStatus, NssmfAdapterUtil.getStatusDesc(actionType));
- logger.info("save segment and operaton info -> end");
- }
- }
-
@Override
protected String getApiVersion() {
return "v1";
@@ -165,9 +148,7 @@
status.setErrorCode(valueOf(rspStatus));
status.setStatus(jobStatus.toString());
status.setStatusDescription(description);
- logger.info("Updating DB status");
repository.save(status);
- logger.info("Updating successful");
}
@Override
diff --git a/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/InternalNssmfManager.java b/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/InternalNssmfManager.java
index a945823..f439b40 100644
--- a/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/InternalNssmfManager.java
+++ b/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/InternalNssmfManager.java
@@ -24,20 +24,15 @@
import org.apache.http.message.BasicHeader;
import org.onap.so.adapters.nssmf.consts.NssmfAdapterConsts;
import org.onap.so.adapters.nssmf.entity.RestResponse;
-import org.onap.so.adapters.nssmf.enums.JobStatus;
import org.onap.so.adapters.nssmf.enums.SelectionType;
import org.onap.so.adapters.nssmf.exceptions.ApplicationException;
import org.onap.so.beans.nsmf.*;
import org.onap.so.db.request.beans.ResourceOperationStatus;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import static org.onap.so.adapters.nssmf.enums.JobStatus.PROCESSING;
import static org.onap.so.adapters.nssmf.util.NssmfAdapterUtil.marshal;
public abstract class InternalNssmfManager extends BaseNssmfManager {
- private static final Logger logger = LoggerFactory.getLogger(InternalNssmfManager.class);
-
@Override
protected String wrapAllocateReqBody(NssmfAdapterNBIRequest nbiRequest) throws ApplicationException {
return doWrapAllocateReqBody(nbiRequest);
diff --git a/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/external/ExternalAnNssmfManager.java b/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/external/ExternalAnNssmfManager.java
index e244a85..0d2f2df 100644
--- a/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/external/ExternalAnNssmfManager.java
+++ b/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/external/ExternalAnNssmfManager.java
@@ -31,8 +31,6 @@
import org.onap.so.beans.nsmf.NssiResponse;
import org.onap.so.beans.nsmf.NssmfAdapterNBIRequest;
import org.onap.so.db.request.beans.ResourceOperationStatus;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import java.util.HashMap;
import java.util.Map;
import static org.onap.so.adapters.nssmf.util.NssmfAdapterUtil.marshal;
@@ -41,8 +39,6 @@
public class ExternalAnNssmfManager extends ExternalNssmfManager {
- private static final Logger logger = LoggerFactory.getLogger(ExternalAnNssmfManager.class);
-
@Override
protected String doWrapExtAllocateReqBody(NssmfAdapterNBIRequest nbiRequest) throws ApplicationException {
return marshal(nbiRequest.getAllocateAnNssi().getSliceProfile());
diff --git a/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/rest/NssmfManager.java b/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/rest/NssmfManager.java
index bcce69f..2d0980f 100644
--- a/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/rest/NssmfManager.java
+++ b/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/rest/NssmfManager.java
@@ -142,9 +142,6 @@
}
- /**
- * 内部的,调用 workflow 外部的,访问第三方api
- */
RestResponse rsp = restUtil.sendRequest(allocateUrl, POST, allocateReq, nssmiAllocate.getEsrInfo());
assertObjectNotNull(rsp);
diff --git a/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/service/NssmfManagerService.java b/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/service/NssmfManagerService.java
index 9ad191b..92fe557 100644
--- a/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/service/NssmfManagerService.java
+++ b/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/service/NssmfManagerService.java
@@ -20,11 +20,13 @@
package org.onap.so.adapters.nssmf.service;
+import org.onap.so.adapters.nssmf.annotation.ServiceLogger;
import org.onap.so.beans.nsmf.*;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
@Service
+@ServiceLogger
public interface NssmfManagerService {
ResponseEntity allocateNssi(NssmfAdapterNBIRequest allocateRequest);
diff --git a/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/service/impl/NssmfManagerServiceImpl.java b/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/service/impl/NssmfManagerServiceImpl.java
index 1408123..5f7fe76 100644
--- a/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/service/impl/NssmfManagerServiceImpl.java
+++ b/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/service/impl/NssmfManagerServiceImpl.java
@@ -21,6 +21,7 @@
package org.onap.so.adapters.nssmf.service.impl;
import org.apache.commons.lang3.StringUtils;
+import org.onap.so.adapters.nssmf.annotation.ServiceLogger;
import org.onap.so.adapters.nssmf.config.NssmfAdapterConfig;
import org.onap.so.adapters.nssmf.enums.ActionType;
import org.onap.so.adapters.nssmf.exceptions.ApplicationException;
@@ -37,6 +38,7 @@
@Service
+@ServiceLogger
public class NssmfManagerServiceImpl implements NssmfManagerService {
@Autowired