aboutsummaryrefslogtreecommitdiffstats
path: root/adapters/mso-nssmf-adapter/src/main
diff options
context:
space:
mode:
authorhetengjiao <hetengjiao@chinamobile.com>2020-08-27 16:09:34 +0800
committerhetengjiao <hetengjiao@chinamobile.com>2020-08-27 16:09:55 +0800
commit5777b9e0cca899498270d8d9116055f84e902165 (patch)
tree039837550c9b580946dfdcab784fd8ca0f20ae05 /adapters/mso-nssmf-adapter/src/main
parent675f36d732aa5769e0023cc4378549252bcabc9b (diff)
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
Diffstat (limited to 'adapters/mso-nssmf-adapter/src/main')
-rw-r--r--adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/annotation/ServiceLogger.java36
-rw-r--r--adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/controller/NssmfAdapterController.java4
-rw-r--r--adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/interceptor/LoggerInterceptor.java92
-rw-r--r--adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/BaseNssmfManager.java6
-rw-r--r--adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/ExternalNssmfManager.java19
-rw-r--r--adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/InternalNssmfManager.java5
-rw-r--r--adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/external/ExternalAnNssmfManager.java4
-rw-r--r--adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/rest/NssmfManager.java3
-rw-r--r--adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/service/NssmfManagerService.java2
-rw-r--r--adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/service/impl/NssmfManagerServiceImpl.java2
10 files changed, 132 insertions, 41 deletions
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 0000000000..1de29bcc2b
--- /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 5360657f4f..02d7468a0c 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 @@ package org.onap.so.adapters.nssmf.controller;
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 @@ import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
@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 0000000000..ea6a1250d9
--- /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 185dfaff34..97a4c5e889 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.adapters.nssmf.util.RestUtil;
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 f6584da931..16a5b2ada0 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.exceptions.ApplicationException;
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 @@ import static org.onap.so.adapters.nssmf.util.NssmfAdapterUtil.unMarshal;
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 @@ public abstract class ExternalNssmfManager extends BaseNssmfManager {
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 @@ public abstract class ExternalNssmfManager extends BaseNssmfManager {
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 a945823f99..f439b400d9 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.Header;
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 e244a85a6c..0d2f2dfdeb 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.DeAllocateNssi;
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 @@ import static org.onap.so.adapters.nssmf.util.NssmfAdapterUtil.unMarshal;
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 bcce69fb0b..2d0980f60e 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 @@ public class NssmfManager {
}
- /**
- * 内部的,调用 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 9ad191b675..92fe5576dd 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 1408123be7..5f7fe76b72 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 @@ import org.springframework.stereotype.Service;
@Service
+@ServiceLogger
public class NssmfManagerServiceImpl implements NssmfManagerService {
@Autowired