summaryrefslogtreecommitdiffstats
path: root/adapters
diff options
context:
space:
mode:
Diffstat (limited to 'adapters')
-rw-r--r--adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/annotation/RequestLogger.java31
-rw-r--r--adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/consts/NssmfAdapterConsts.java2
-rw-r--r--adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/controller/NssmfAdapterController.java2
-rw-r--r--adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/extclients/aai/AaiServiceProvider.java3
-rw-r--r--adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/extclients/aai/AaiServiceProviderImpl.java20
-rw-r--r--adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/interceptor/LoggerInterceptor.java83
-rw-r--r--adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/interceptor/RequestLogAspect.java227
-rw-r--r--adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/BaseNssmfManager.java2
-rw-r--r--adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/ExternalNssmfManager.java37
-rw-r--r--adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/InternalNssmfManager.java4
-rw-r--r--adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/external/ExternalAnNssmfManager.java3
-rw-r--r--adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/util/RestUtil.java39
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/inventory/delete/DeleteInventoryService.java52
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/TaskServices.java46
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/audit/AbstractAudit.java39
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/audit/AbstractAuditService.java87
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/audit/AuditCreateStackService.java110
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/audit/AuditDataService.java78
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/audit/AuditDeleteStackService.java122
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/audit/AuditQueryStackService.java85
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/audit/AuditVServer.java173
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/audit/HeatStackAudit.java330
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/inventory/CreateAAIInventory.java132
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/inventory/CreateInventoryTask.java12
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/inventory/DeleteAAIInventory.java (renamed from adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/inventory/delete/DeleteAAIInventory.java)29
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/inventory/DeleteInventoryTask.java (renamed from adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/inventory/delete/DeleteInventoryTask.java)8
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/HeatBridgeImpl.java30
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/helpers/AaiHelper.java7
-rw-r--r--adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/audit/AbstractAuditServiceTest.java51
-rw-r--r--adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/audit/AuditDataServiceTest.java113
-rw-r--r--adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/audit/AuditStackServiceDataTest.java191
-rw-r--r--adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/audit/AuditVServerTest.java444
-rw-r--r--adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/audit/HeatStackAuditTest.java298
-rw-r--r--adapters/mso-openstack-adapters/src/test/java/org/onap/so/heatbridge/HeatBridgeImplTest.java14
34 files changed, 495 insertions, 2409 deletions
diff --git a/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/annotation/RequestLogger.java b/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/annotation/RequestLogger.java
new file mode 100644
index 0000000000..44f814aa10
--- /dev/null
+++ b/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/annotation/RequestLogger.java
@@ -0,0 +1,31 @@
+/*-
+ * ============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.*;
+
+@Target({ElementType.METHOD, ElementType.TYPE})
+@Retention(RetentionPolicy.RUNTIME)
+@Documented
+public @interface RequestLogger {
+ boolean ignore() default false;
+}
diff --git a/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/consts/NssmfAdapterConsts.java b/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/consts/NssmfAdapterConsts.java
index 28789f2a98..84e1eb2acc 100644
--- a/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/consts/NssmfAdapterConsts.java
+++ b/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/consts/NssmfAdapterConsts.java
@@ -159,7 +159,7 @@ public class NssmfAdapterConsts {
new NssmfUrlInfo(EXTERNAL_QUERY_JOB_STATUS, HttpMethod.GET));
urlInfoMap.put(generateKey(ExecutorType.INTERNAL, null, ActionType.QUERY_SUB_NET_CAPABILITY),
- new NssmfUrlInfo(INTERNAL_QUERY_SUB_NET_CAPABILITY, HttpMethod.POST));
+ new NssmfUrlInfo(INTERNAL_QUERY_SUB_NET_CAPABILITY, HttpMethod.GET));
}
/**
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 02d7468a0c..3732e2c256 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
@@ -1,5 +1,6 @@
package org.onap.so.adapters.nssmf.controller;
+import org.onap.so.adapters.nssmf.annotation.RequestLogger;
import org.onap.so.adapters.nssmf.service.NssmfManagerService;
import org.onap.so.beans.nsmf.*;
import org.springframework.beans.factory.annotation.Autowired;
@@ -9,6 +10,7 @@ import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
@RestController
@RequestMapping(value = "/api/rest/provMns/v1", produces = {APPLICATION_JSON}, consumes = {APPLICATION_JSON})
+@RequestLogger
public class NssmfAdapterController {
@Autowired
diff --git a/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/extclients/aai/AaiServiceProvider.java b/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/extclients/aai/AaiServiceProvider.java
index 665b111e03..77662bf272 100644
--- a/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/extclients/aai/AaiServiceProvider.java
+++ b/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/extclients/aai/AaiServiceProvider.java
@@ -33,4 +33,7 @@ public interface AaiServiceProvider {
void invokeCreateServiceInstance(ServiceInstance nssiInstance, String globalSubscriberId, String serviceType,
String serviceInstanceId);
+ ServiceInstance invokeGetServiceInstance(String globalSubscriberId, String serviceType, String serviceInstanceId);
+
+ void invokeDeleteServiceInstance(String globalSubscriberId, String serviceType, String serviceInstanceId);
}
diff --git a/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/extclients/aai/AaiServiceProviderImpl.java b/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/extclients/aai/AaiServiceProviderImpl.java
index b972517338..1d7c42aafe 100644
--- a/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/extclients/aai/AaiServiceProviderImpl.java
+++ b/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/extclients/aai/AaiServiceProviderImpl.java
@@ -75,4 +75,24 @@ public class AaiServiceProviderImpl implements AaiServiceProvider {
.customer(globalSubscriberId).serviceSubscription(serviceType).serviceInstance(serviceInstanceId));
aaiClientProvider.getAaiClient().create(uri, nssiInstance);
}
+
+ @Override
+ public ServiceInstance invokeGetServiceInstance(String globalSubscriberId, String serviceType,
+ String serviceInstanceId) {
+ AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business()
+ .customer(globalSubscriberId).serviceSubscription(serviceType).serviceInstance(serviceInstanceId));
+
+ return aaiClientProvider.getAaiClient().get(ServiceInstance.class, uri).orElseGet(() -> {
+ logger.debug("ServiceInstance " + serviceInstanceId + " not found in AAI");
+ return null;
+ });
+ }
+
+ @Override
+ public void invokeDeleteServiceInstance(String globalSubscriberId, String serviceType, String serviceInstanceId) {
+ AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business()
+ .customer(globalSubscriberId).serviceSubscription(serviceType).serviceInstance(serviceInstanceId));
+
+ aaiClientProvider.getAaiClient().delete(uri);
+ }
}
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
index ea6a1250d9..bca4a12d4b 100644
--- 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
@@ -17,76 +17,39 @@
# 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.apache.logging.log4j.ThreadContext;
import org.springframework.stereotype.Component;
-import java.lang.reflect.Method;
+import org.springframework.web.servlet.HandlerInterceptor;
+import org.springframework.web.servlet.ModelAndView;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.util.UUID;
-/**
- * support to print logger of service method
- */
-@Aspect
-@Order(100)
@Component
-public class LoggerInterceptor {
-
- private static final Logger logger = LoggerFactory.getLogger(LoggerInterceptor.class);
+public class LoggerInterceptor implements HandlerInterceptor {
- @Pointcut("execution(* org.onap.so.adapters.nssmf.service..*(..))")
- public void serviceLogger() {
+ private final static String TRACE_ID = "traceId";
+ @Override
+ public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
+ throws Exception {
+ String traceId = UUID.randomUUID().toString().replaceAll("-", "").toUpperCase();
+ ThreadContext.put(TRACE_ID, traceId);
+ return true;
}
- @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();
- }
+ @Override
+ public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
+ ModelAndView modelAndView) throws Exception {
- 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;
+ @Override
+ public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
+ throws Exception {
+ ThreadContext.remove(TRACE_ID);
}
}
diff --git a/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/interceptor/RequestLogAspect.java b/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/interceptor/RequestLogAspect.java
new file mode 100644
index 0000000000..95f26b4ad5
--- /dev/null
+++ b/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/interceptor/RequestLogAspect.java
@@ -0,0 +1,227 @@
+/*-
+ * ============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 lombok.Data;
+import lombok.ToString;
+import org.aspectj.lang.JoinPoint;
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.annotation.*;
+import org.aspectj.lang.reflect.MethodSignature;
+import org.onap.so.adapters.nssmf.annotation.RequestLogger;
+import org.onap.so.adapters.nssmf.annotation.ServiceLogger;
+import org.onap.so.adapters.nssmf.exceptions.ApplicationException;
+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 org.springframework.web.context.request.RequestContextHolder;
+import org.springframework.web.context.request.ServletRequestAttributes;
+import org.springframework.web.multipart.MultipartFile;
+import javax.servlet.http.HttpServletRequest;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * support to print logger of service method
+ */
+@Aspect
+@Order(100)
+@Component
+public class RequestLogAspect {
+
+ private static final Logger logger = LoggerFactory.getLogger(RequestLogAspect.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;
+ }
+
+ @Pointcut("execution(* org.onap.so.adapters.nssmf.controller..*(..))")
+ public void controllerLogger() {
+
+ }
+
+ @Around("controllerLogger()")
+ public Object doAroundRequest(ProceedingJoinPoint point) throws Throwable {
+ MethodSignature signature = (MethodSignature) point.getSignature();
+ Method method = signature.getMethod();
+ Class<?> targetClass = method.getDeclaringClass();
+
+ RequestLogger classAnnotation = targetClass.getAnnotation(RequestLogger.class);
+ RequestLogger methodAnnotation = method.getAnnotation(RequestLogger.class);
+
+ if ((classAnnotation == null && methodAnnotation == null)
+ || (classAnnotation != null && classAnnotation.ignore())
+ || (methodAnnotation != null && methodAnnotation.ignore())) {
+ return point.proceed();
+ }
+
+ long start = System.currentTimeMillis();
+ ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
+
+ assert attributes != null;
+ HttpServletRequest request = attributes.getRequest();
+ Object result = point.proceed();
+ RequestInfo requestInfo = new RequestInfo();
+ requestInfo.setIp(request.getRemoteAddr());
+ requestInfo.setUrl(request.getRequestURL().toString());
+ requestInfo.setHttpMethod(request.getMethod());
+ requestInfo.setClassMethod(String.format("%s.%s", signature.getDeclaringTypeName(), signature.getName()));
+ requestInfo.setRequestParams(getRequestParamsByProceedingJoinPoint(point));
+ requestInfo.setResult(result);
+ requestInfo.setTimeCost(System.currentTimeMillis() - start);
+ logger.info("Request Info : {}", NssmfAdapterUtil.marshal(requestInfo));
+ return result;
+ }
+
+ @AfterThrowing(pointcut = "controllerLogger()", throwing = "e")
+ public void doAfterRequestThrow(JoinPoint joinPoint, RuntimeException e) {
+ MethodSignature signature = (MethodSignature) joinPoint.getSignature();
+ Method method = signature.getMethod();
+ Class<?> targetClass = method.getDeclaringClass();
+
+ RequestLogger classAnnotation = targetClass.getAnnotation(RequestLogger.class);
+ RequestLogger methodAnnotation = method.getAnnotation(RequestLogger.class);
+
+ if ((classAnnotation == null && methodAnnotation == null)
+ || (classAnnotation != null && classAnnotation.ignore())
+ || (methodAnnotation != null && methodAnnotation.ignore())) {
+ return;
+ }
+ ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
+ assert attributes != null;
+ HttpServletRequest request = attributes.getRequest();
+ RequestErrorInfo requestErrorInfo = new RequestErrorInfo();
+ requestErrorInfo.setIp(request.getRemoteAddr());
+ requestErrorInfo.setUrl(request.getRequestURL().toString());
+ requestErrorInfo.setHttpMethod(request.getMethod());
+ requestErrorInfo.setClassMethod(String.format("%s.%s", joinPoint.getSignature().getDeclaringTypeName(),
+ joinPoint.getSignature().getName()));
+ requestErrorInfo.setRequestParams(getRequestParamsByJoinPoint(joinPoint));
+ requestErrorInfo.setException(e);
+ String res;
+ try {
+ res = NssmfAdapterUtil.marshal(requestErrorInfo);
+ logger.info("Error Request Info : {}", res);
+ } catch (ApplicationException ex) {
+ logger.info("Error Request Info : {}", requestErrorInfo);
+ }
+ }
+
+ private Map<String, Object> getRequestParamsByJoinPoint(JoinPoint joinPoint) {
+ String[] paramNames = ((MethodSignature) joinPoint.getSignature()).getParameterNames();
+ Object[] paramValues = joinPoint.getArgs();
+
+ return buildRequestParam(paramNames, paramValues);
+ }
+
+
+ private Map<String, Object> getRequestParamsByProceedingJoinPoint(ProceedingJoinPoint proceedingJoinPoint) {
+ String[] paramNames = ((MethodSignature) proceedingJoinPoint.getSignature()).getParameterNames();
+ Object[] paramValues = proceedingJoinPoint.getArgs();
+
+ return buildRequestParam(paramNames, paramValues);
+ }
+
+ private Map<String, Object> buildRequestParam(String[] paramNames, Object[] paramValues) {
+ Map<String, Object> requestParams = new HashMap<>();
+ for (int i = 0; i < paramNames.length; i++) {
+ Object value = paramValues[i];
+
+ if (value instanceof MultipartFile) {
+ MultipartFile file = (MultipartFile) value;
+ value = file.getOriginalFilename();
+ }
+
+ requestParams.put(paramNames[i], value);
+ }
+
+ return requestParams;
+ }
+
+ @Data
+ @ToString
+ private class RequestInfo {
+ private String ip;
+ private String url;
+ private String httpMethod;
+ private String classMethod;
+ private Object requestParams;
+ private Object result;
+ private Long timeCost;
+ }
+
+ @Data
+ @ToString
+ private class RequestErrorInfo {
+ private String ip;
+ private String url;
+ private String httpMethod;
+ private String classMethod;
+ private Object requestParams;
+ private RuntimeException exception;
+ }
+}
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 2ccd88a358..c4f269c3a0 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
@@ -193,7 +193,7 @@ public abstract class BaseNssmfManager implements NssmfManager {
return doQuerySubnetCapability(nbiRequest.getSubnetCapabilityQuery());
}
- protected abstract RestResponse doQuerySubnetCapability(String req) throws ApplicationException;
+ protected abstract <T> RestResponse doQuerySubnetCapability(T req) throws ApplicationException;
/**
* send request to nssmf
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 0d0d896370..bb2b83fd59 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
@@ -25,6 +25,7 @@ import org.apache.http.message.BasicHeader;
import org.onap.aai.domain.yang.ServiceInstance;
import org.onap.so.adapters.nssmf.entity.NssmfInfo;
import org.onap.so.adapters.nssmf.entity.RestResponse;
+import org.onap.so.adapters.nssmf.enums.ActionType;
import org.onap.so.adapters.nssmf.enums.JobStatus;
import org.onap.so.adapters.nssmf.exceptions.ApplicationException;
import org.onap.so.adapters.nssmf.util.NssmfAdapterUtil;
@@ -63,24 +64,32 @@ public abstract class ExternalNssmfManager extends BaseNssmfManager {
protected void afterQueryJobStatus(ResourceOperationStatus status) {
if (Integer.parseInt(status.getProgress()) == 100) {
- ServiceInstance nssiInstance = new ServiceInstance();
- nssiInstance.setServiceInstanceId(serviceInfo.getNssiId());
- nssiInstance.setServiceInstanceName(serviceInfo.getNssiName());
- nssiInstance.setServiceType(serviceInfo.getSST());
+ ActionType jobOperType = ActionType.valueOf(status.getOperType());
- nssiInstance.setOrchestrationStatus(initStatus);
- nssiInstance.setModelInvariantId(serviceInfo.getServiceInvariantUuid());
- nssiInstance.setModelVersionId(serviceInfo.getServiceUuid());
- nssiInstance.setServiceInstanceLocationId(serviceInfo.getPLMNIdList());
- nssiInstance.setEnvironmentContext(esrInfo.getNetworkType().getNetworkType());
- nssiInstance.setServiceRole("nssi");
+ if (ActionType.ALLOCATE.equals(jobOperType)) {
+ ServiceInstance nssiInstance = restUtil.getServiceInstance(serviceInfo);
+ if (nssiInstance == null) {
+ nssiInstance = new ServiceInstance();
+ }
- restUtil.createServiceInstance(nssiInstance, serviceInfo);
+ nssiInstance.setServiceInstanceId(serviceInfo.getNssiId());
+ nssiInstance.setServiceInstanceName(serviceInfo.getNssiName());
+ nssiInstance.setServiceType(serviceInfo.getSST());
+
+ nssiInstance.setOrchestrationStatus(initStatus);
+ nssiInstance.setModelInvariantId(serviceInfo.getServiceInvariantUuid());
+ nssiInstance.setModelVersionId(serviceInfo.getServiceUuid());
+ nssiInstance.setServiceInstanceLocationId(serviceInfo.getPLMNIdList());
+ nssiInstance.setEnvironmentContext(esrInfo.getNetworkType().getNetworkType());
+ nssiInstance.setServiceRole("nssi");
+
+ restUtil.createServiceInstance(nssiInstance, serviceInfo);
+ } else if (ActionType.DEALLOCATE.equals(jobOperType)) {
+ restUtil.deleteServiceInstance(serviceInfo);
+ }
}
}
-
-
@Override
protected String wrapActDeActReqBody(ActDeActNssi actDeActNssi) throws ApplicationException {
return marshal(actDeActNssi);
@@ -157,7 +166,7 @@ public abstract class ExternalNssmfManager extends BaseNssmfManager {
}
@Override
- protected RestResponse doQuerySubnetCapability(String req) throws ApplicationException {
+ protected <T> RestResponse doQuerySubnetCapability(T req) throws ApplicationException {
RestResponse response = new RestResponse();
response.setStatus(200);
response.setResponseContent(null);
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 348bf12bcb..4705e871f3 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
@@ -122,8 +122,8 @@ public abstract class InternalNssmfManager extends BaseNssmfManager {
protected abstract String doWrapModifyReqBody(NssmfAdapterNBIRequest nbiRequest) throws ApplicationException;
@Override
- protected RestResponse doQuerySubnetCapability(String req) throws ApplicationException {
+ protected <T> RestResponse doQuerySubnetCapability(T req) throws ApplicationException {
// handler
- return sendRequest(req);
+ return sendRequest(marshal(req));
}
}
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 491da0aab4..c51b72d61e 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
@@ -76,6 +76,7 @@ public class ExternalAnNssmfManager extends ExternalNssmfManager {
ResourceOperationStatus status =
new ResourceOperationStatus(serviceInfo.getNsiId(), resp.getJobId(), serviceInfo.getServiceUuid());
status.setResourceInstanceID(nssiId);
+ status.setOperType(actionType.toString());
updateDbStatus(status, restResponse.getStatus(), JobStatus.FINISHED,
NssmfAdapterUtil.getStatusDesc(actionType));
@@ -128,6 +129,8 @@ public class ExternalAnNssmfManager extends ExternalNssmfManager {
updateRequestDbJobStatus(responseDescriptor, status, restResponse);
+ status.setProgress(Integer.toString(responseDescriptor.getProgress()));
+
return restResponse;
}
diff --git a/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/util/RestUtil.java b/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/util/RestUtil.java
index 0c5999b20e..a7adbe116a 100644
--- a/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/util/RestUtil.java
+++ b/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/util/RestUtil.java
@@ -77,6 +77,16 @@ public class RestUtil {
serviceInfo.getSubscriptionServiceType(), serviceInfo.getNssiId());
}
+ public ServiceInstance getServiceInstance(ServiceInfo serviceInfo) {
+ return aaiSvcProv.invokeGetServiceInstance(serviceInfo.getGlobalSubscriberId(),
+ serviceInfo.getSubscriptionServiceType(), serviceInfo.getNssiId());
+ }
+
+ public void deleteServiceInstance(ServiceInfo serviceInfo) {
+ aaiSvcProv.invokeDeleteServiceInstance(serviceInfo.getGlobalSubscriberId(),
+ serviceInfo.getSubscriptionServiceType(), serviceInfo.getNssiId());
+ }
+
public NssmfInfo getNssmfHost(EsrInfo esrInfo) throws ApplicationException {
EsrThirdpartySdncList sdncList = aaiSvcProv.invokeGetThirdPartySdncList();
if (sdncList != null && sdncList.getEsrThirdpartySdnc() != null) {
@@ -214,7 +224,11 @@ public class RestUtil {
break;
case GET:
- base = new HttpGet(url);
+ HttpGetWithBody get = new HttpGetWithBody(url);
+ if (content != null) {
+ get.setEntity(new StringEntity(content, APPLICATION_JSON));
+ }
+ base = get;
break;
case PUT:
@@ -275,6 +289,29 @@ public class RestUtil {
}
}
+ class HttpGetWithBody extends HttpEntityEnclosingRequestBase {
+ public static final String METHOD_NAME = "GET";
+
+ public HttpGetWithBody() {
+ super();
+ }
+
+ public HttpGetWithBody(final String uri) {
+ super();
+ setURI(URI.create(uri));
+ }
+
+ public HttpGetWithBody(final URI uri) {
+ super();
+ setURI(uri);
+ }
+
+ @Override
+ public String getMethod() {
+ return METHOD_NAME;
+ }
+ }
+
public HttpClient getHttpsClient() {
diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/inventory/delete/DeleteInventoryService.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/inventory/delete/DeleteInventoryService.java
deleted file mode 100644
index 4e5e880f80..0000000000
--- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/inventory/delete/DeleteInventoryService.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP - SO
- * ================================================================================
- * Copyright (C) 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.so.adapters.inventory.delete;
-
-import javax.annotation.PostConstruct;
-import org.onap.so.utils.ExternalTaskServiceUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.annotation.Profile;
-import org.springframework.core.env.Environment;
-import org.springframework.stereotype.Component;
-
-@Component
-@Profile("!test")
-public class DeleteInventoryService {
-
- @Autowired
- public Environment env;
-
- @Autowired
- private DeleteInventoryTask deleteInventory;
-
- @Autowired
- private ExternalTaskServiceUtils externalTaskServiceUtils;
-
- @PostConstruct
- public void auditAAIInventory() throws Exception {
- for (int i = 0; i < externalTaskServiceUtils.getMaxClients(); i++) {
- externalTaskServiceUtils.createExternalTaskClient().subscribe("InventoryDelete")
- .lockDuration(externalTaskServiceUtils.getLockDurationMedium())
- .handler(deleteInventory::executeExternalTask).open();
- }
- }
-
-}
diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/TaskServices.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/TaskServices.java
index d4a4bb792f..b176892192 100644
--- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/TaskServices.java
+++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/TaskServices.java
@@ -22,10 +22,8 @@ package org.onap.so.adapters.tasks;
import javax.annotation.PostConstruct;
import org.camunda.bpm.client.ExternalTaskClient;
-import org.onap.so.adapters.tasks.audit.AuditCreateStackService;
-import org.onap.so.adapters.tasks.audit.AuditDeleteStackService;
-import org.onap.so.adapters.tasks.audit.AuditQueryStackService;
import org.onap.so.adapters.tasks.inventory.CreateInventoryTask;
+import org.onap.so.adapters.tasks.inventory.DeleteInventoryTask;
import org.onap.so.adapters.tasks.orchestration.PollService;
import org.onap.so.adapters.tasks.orchestration.RollbackService;
import org.onap.so.adapters.tasks.orchestration.StackService;
@@ -46,15 +44,6 @@ public class TaskServices {
private ExternalTaskServiceUtils externalTaskServiceUtils;
@Autowired
- private AuditCreateStackService auditCreateStack;
-
- @Autowired
- private AuditDeleteStackService auditDeleteStack;
-
- @Autowired
- private AuditQueryStackService auditQueryStack;
-
- @Autowired
private CreateInventoryTask createInventory;
@Autowired
@@ -66,39 +55,24 @@ public class TaskServices {
@Autowired
private RollbackService rollbackService;
- @PostConstruct
- public void auditAddAAIInventory() throws Exception {
- for (int i = 0; i < externalTaskServiceUtils.getMaxClients(); i++) {
- ExternalTaskClient client = externalTaskServiceUtils.createExternalTaskClient();
- client.subscribe("InventoryAddAudit").lockDuration(externalTaskServiceUtils.getLockDurationLong())
- .handler(auditCreateStack::executeExternalTask).open();
- }
- }
-
- @PostConstruct
- public void auditDeleteAAIInventory() throws Exception {
- for (int i = 0; i < externalTaskServiceUtils.getMaxClients(); i++) {
- ExternalTaskClient client = externalTaskServiceUtils.createExternalTaskClient();
- client.subscribe("InventoryDeleteAudit").lockDuration(externalTaskServiceUtils.getLockDurationLong())
- .handler(auditDeleteStack::executeExternalTask).open();
- }
- }
+ @Autowired
+ private DeleteInventoryTask deleteInventory;
@PostConstruct
- public void auditQueryInventory() throws Exception {
+ public void createtAAIInventory() throws Exception {
for (int i = 0; i < externalTaskServiceUtils.getMaxClients(); i++) {
ExternalTaskClient client = externalTaskServiceUtils.createExternalTaskClient();
- client.subscribe("InventoryQueryAudit").lockDuration(externalTaskServiceUtils.getLockDuration())
- .handler(auditQueryStack::executeExternalTask).open();
+ client.subscribe("InventoryCreate").lockDuration(externalTaskServiceUtils.getLongLockDuration())
+ .handler(createInventory::executeExternalTask).open();
}
}
@PostConstruct
- public void createtAAIInventory() throws Exception {
+ public void auditAAIInventory() throws Exception {
for (int i = 0; i < externalTaskServiceUtils.getMaxClients(); i++) {
- ExternalTaskClient client = externalTaskServiceUtils.createExternalTaskClient();
- client.subscribe("InventoryCreate").lockDuration(externalTaskServiceUtils.getLongLockDuration())
- .handler(createInventory::executeExternalTask).open();
+ externalTaskServiceUtils.createExternalTaskClient().subscribe("InventoryDelete")
+ .lockDuration(externalTaskServiceUtils.getLockDurationMedium())
+ .handler(deleteInventory::executeExternalTask).open();
}
}
diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/audit/AbstractAudit.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/audit/AbstractAudit.java
deleted file mode 100644
index 0c6bb6f387..0000000000
--- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/audit/AbstractAudit.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP - SO
- * ================================================================================
- * Copyright (C) 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.so.adapters.tasks.audit;
-
-import org.onap.aaiclient.client.aai.AAIResourcesClient;
-
-public class AbstractAudit {
-
- private AAIResourcesClient aaiClient;
-
- protected AAIResourcesClient getAaiClient() {
- if (aaiClient == null)
- return new AAIResourcesClient();
- else
- return aaiClient;
- }
-
- protected void setAaiClient(AAIResourcesClient aaiResource) {
- aaiClient = aaiResource;
- }
-}
diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/audit/AbstractAuditService.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/audit/AbstractAuditService.java
deleted file mode 100644
index 8cdd37d43f..0000000000
--- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/audit/AbstractAuditService.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP - SO
- * ================================================================================
- * Copyright (C) 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.so.adapters.tasks.audit;
-
-import org.onap.so.objects.audit.AAIObjectAudit;
-import org.onap.so.objects.audit.AAIObjectAuditList;
-import org.onap.so.utils.ExternalTaskUtils;
-import org.onap.so.utils.RetrySequenceLevel;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.core.env.Environment;
-import org.springframework.stereotype.Component;
-
-@Component
-public abstract class AbstractAuditService extends ExternalTaskUtils {
-
- private static final Logger logger = LoggerFactory.getLogger(AbstractAuditService.class);
-
- protected static final String UNABLE_TO_FIND_ALL_V_SERVERS_AND_L_INTERACES_IN_A_AI =
- "Unable to find all VServers and L-Interaces in A&AI";
-
- protected static final String UNABLE_TO_FIND_V_SERVERS_IN_OPENSTACK = "Unable to find VServers in Openstack";
-
- @Autowired
- public Environment env;
-
- public AbstractAuditService() {
- super(RetrySequenceLevel.LONG);
- }
-
- /**
- * @param auditList
- * @return
- */
- protected boolean didCreateAuditFail(AAIObjectAuditList auditList) {
- if (isAuditListNotNullAndNotEmpty(auditList)) {
- if (logger.isInfoEnabled()) {
- logger.info("Audit Results: {}", auditList.toString());
- }
- return auditList.getAuditList().stream().filter(auditObject -> !auditObject.isDoesObjectExist()).findFirst()
- .map(v -> true).orElse(false);
- } else {
- return false;
- }
- }
-
- /**
- * @param auditList
- * @return
- */
- protected boolean didDeleteAuditFail(AAIObjectAuditList auditList) {
- if (isAuditListNotNullAndNotEmpty(auditList)) {
- if (logger.isInfoEnabled()) {
- logger.info("Audit Results: {}", auditList.toString());
- }
- return auditList.getAuditList().stream().filter(AAIObjectAudit::isDoesObjectExist).findFirst()
- .map(v -> true).orElse(false);
- } else {
- return false;
- }
- }
-
- private boolean isAuditListNotNullAndNotEmpty(AAIObjectAuditList auditList) {
- return auditList != null && auditList.getAuditList() != null && !auditList.getAuditList().isEmpty();
- }
-
-}
diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/audit/AuditCreateStackService.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/audit/AuditCreateStackService.java
deleted file mode 100644
index a4afcf1378..0000000000
--- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/audit/AuditCreateStackService.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP - SO
- * ================================================================================
- * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Modifications Copyright (c) 2019 Samsung
- * ================================================================================
- * 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.tasks.audit;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Optional;
-import org.camunda.bpm.client.task.ExternalTask;
-import org.camunda.bpm.client.task.ExternalTaskService;
-import org.onap.logging.ref.slf4j.ONAPLogConstants;
-import org.onap.so.audit.beans.AuditInventory;
-import org.onap.aaiclient.client.graphinventory.GraphInventoryCommonObjectMapperProvider;
-import org.onap.so.logging.tasks.AuditMDCSetup;
-import org.onap.so.objects.audit.AAIObjectAuditList;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
-
-@Component
-public class AuditCreateStackService extends AbstractAuditService {
-
- private static final Logger logger = LoggerFactory.getLogger(AuditCreateStackService.class);
-
- @Autowired
- public HeatStackAudit heatStackAudit;
-
- @Autowired
- public AuditMDCSetup mdcSetup;
-
- public AuditCreateStackService() {
- super();
- }
-
- public void executeExternalTask(ExternalTask externalTask, ExternalTaskService externalTaskService) {
- mdcSetup.setupMDC(externalTask);
- AuditInventory auditInventory = externalTask.getVariable("auditInventory");
- Map<String, Object> variables = new HashMap<>();
- boolean success = false;
- try {
- Integer retryCount = externalTask.getRetries();
- logger.info("Executing External Task Audit Inventory, Retry Number: {} \n {}", retryCount, auditInventory);
- Optional<AAIObjectAuditList> auditListOpt = heatStackAudit.auditHeatStack(auditInventory.getCloudRegion(),
- auditInventory.getCloudOwner(), auditInventory.getTenantId(), auditInventory.getHeatStackName());
- if (auditListOpt.isPresent()) {
- auditListOpt.get().setAuditType("create");
- auditListOpt.get().setHeatStackName(auditInventory.getHeatStackName());
- GraphInventoryCommonObjectMapperProvider objectMapper = new GraphInventoryCommonObjectMapperProvider();
- variables.put("auditInventoryResult", objectMapper.getMapper().writeValueAsString(auditListOpt.get()));
- success = !didCreateAuditFail(auditListOpt.get());
- }
- } catch (Exception e) {
- logger.error("Error during audit of stack", e);
- }
- variables.put("auditIsSuccessful", success);
- mdcSetup.setElapsedTime();
- String externalTaskId = externalTask.getId();
- if (success) {
- externalTaskService.complete(externalTask, variables);
- mdcSetup.setResponseCode(ONAPLogConstants.ResponseStatus.COMPLETE.toString());
- logger.debug("The External Task Id: {} Successful", externalTaskId);
- logger.info(ONAPLogConstants.Markers.EXIT, "Exiting");
- mdcSetup.clearClientMDCs();
- } else {
- Integer retryCount = externalTask.getRetries();
- if (retryCount == null) {
- logger.debug("The External Task Id: {} Failed, Setting Retries to Default Start Value: {}",
- externalTaskId, getRetrySequence().length);
- externalTaskService.handleFailure(externalTask, UNABLE_TO_FIND_ALL_V_SERVERS_AND_L_INTERACES_IN_A_AI,
- UNABLE_TO_FIND_ALL_V_SERVERS_AND_L_INTERACES_IN_A_AI, getRetrySequence().length, 10000);
- } else if (retryCount == 1) {
- externalTaskService.complete(externalTask, variables);
- mdcSetup.setResponseCode(ONAPLogConstants.ResponseStatus.ERROR.toString());
- logger.debug("The External Task Id: {} Failed, All Retries Exhausted", externalTaskId);
- logger.info(ONAPLogConstants.Markers.EXIT, "Exiting");
- mdcSetup.clearClientMDCs();
- } else {
- logger.debug("The External Task Id: {} Failed, Decrementing Retries: {} , Retry Delay: ",
- externalTaskId, retryCount - 1, calculateRetryDelay(retryCount));
- externalTaskService.handleFailure(externalTask, UNABLE_TO_FIND_ALL_V_SERVERS_AND_L_INTERACES_IN_A_AI,
- UNABLE_TO_FIND_ALL_V_SERVERS_AND_L_INTERACES_IN_A_AI, retryCount - 1,
- calculateRetryDelay(retryCount));
- }
- logger.debug("The External Task Id: {} Failed", externalTaskId);
- }
- }
-
-
-
-}
diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/audit/AuditDataService.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/audit/AuditDataService.java
deleted file mode 100644
index 200f6375ea..0000000000
--- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/audit/AuditDataService.java
+++ /dev/null
@@ -1,78 +0,0 @@
-package org.onap.so.adapters.tasks.audit;
-
-import java.io.IOException;
-import java.util.List;
-import java.util.Optional;
-import org.onap.so.audit.beans.AuditInventory;
-import org.onap.aaiclient.client.graphinventory.GraphInventoryCommonObjectMapperProvider;
-import org.onap.so.db.request.beans.RequestProcessingData;
-import org.onap.so.db.request.client.RequestsDbClient;
-import org.onap.so.objects.audit.AAIObjectAuditList;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
-import com.fasterxml.jackson.core.JsonParseException;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.JsonMappingException;
-
-@Component
-public class AuditDataService {
-
- private static final String AUDIT_STACK_DATA = "AuditStackData";
-
- @Autowired
- private RequestsDbClient requestsDbClient;
-
- /**
- * Checks to see if an entry already exist for the given heat stack and writes audit stack data to the request
- * database if it doesn't.
- *
- * @throws JsonProcessingException
- */
- public void writeStackDataToRequestDb(AuditInventory auditInventory, AAIObjectAuditList auditList)
- throws JsonProcessingException {
- List<RequestProcessingData> requestProcessingDataList =
- requestsDbClient.getRequestProcessingDataByGroupingIdAndNameAndTag(auditInventory.getVfModuleId(),
- auditInventory.getHeatStackName(), AUDIT_STACK_DATA);
- if (requestProcessingDataList.isEmpty()) {
- GraphInventoryCommonObjectMapperProvider objectMapper = new GraphInventoryCommonObjectMapperProvider();
- String auditListString = objectMapper.getMapper().writeValueAsString(auditList);;
-
- RequestProcessingData requestProcessingData = new RequestProcessingData();
- requestProcessingData.setSoRequestId(auditInventory.getMsoRequestId());
- requestProcessingData.setGroupingId(auditInventory.getVfModuleId());
- requestProcessingData.setName(auditInventory.getHeatStackName());
- requestProcessingData.setTag(AUDIT_STACK_DATA);
- requestProcessingData.setValue(auditListString);
-
- requestsDbClient.saveRequestProcessingData(requestProcessingData);
- }
- }
-
- /**
- * Retrieves audit stack data from the request database.
- *
- * @throws IOException
- * @throws JsonMappingException
- * @throws JsonParseException
- */
- public Optional<AAIObjectAuditList> getStackDataFromRequestDb(AuditInventory auditInventory) throws IOException {
-
- List<RequestProcessingData> requestProcessingDataList =
- requestsDbClient.getRequestProcessingDataByGroupingIdAndNameAndTag(auditInventory.getVfModuleId(),
- auditInventory.getHeatStackName(), AUDIT_STACK_DATA);
- if (!requestProcessingDataList.isEmpty()) {
- RequestProcessingData requestProcessingData = requestProcessingDataList.get(0);
- String auditListString = requestProcessingData.getValue();
-
- GraphInventoryCommonObjectMapperProvider objectMapper = new GraphInventoryCommonObjectMapperProvider();
- AAIObjectAuditList auditList =
- objectMapper.getMapper().readValue(auditListString, AAIObjectAuditList.class);
-
- return Optional.of(auditList);
- } else {
- return Optional.empty();
- }
- }
-
-
-}
diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/audit/AuditDeleteStackService.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/audit/AuditDeleteStackService.java
deleted file mode 100644
index a7fdc352cd..0000000000
--- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/audit/AuditDeleteStackService.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP - SO
- * ================================================================================
- * 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.so.adapters.tasks.audit;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Optional;
-import org.camunda.bpm.client.task.ExternalTask;
-import org.camunda.bpm.client.task.ExternalTaskService;
-import org.onap.logging.ref.slf4j.ONAPLogConstants;
-import org.onap.so.audit.beans.AuditInventory;
-import org.onap.aaiclient.client.graphinventory.GraphInventoryCommonObjectMapperProvider;
-import org.onap.so.logging.tasks.AuditMDCSetup;
-import org.onap.so.objects.audit.AAIObjectAuditList;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.core.env.Environment;
-import org.springframework.stereotype.Component;
-
-@Component
-public class AuditDeleteStackService extends AbstractAuditService {
-
- private static final Logger logger = LoggerFactory.getLogger(AuditDeleteStackService.class);
-
- @Autowired
- protected HeatStackAudit heatStackAudit;
-
- @Autowired
- protected AuditVServer auditVservers;
-
- @Autowired
- protected AuditDataService auditDataService;
-
- @Autowired
- protected Environment env;
-
- @Autowired
- public AuditMDCSetup mdcSetup;
-
- public AuditDeleteStackService() {
- super();
- }
-
- public void executeExternalTask(ExternalTask externalTask, ExternalTaskService externalTaskService) {
-
- mdcSetup.setupMDC(externalTask);
- AuditInventory auditInventory = externalTask.getVariable("auditInventory");
- Map<String, Object> variables = new HashMap<>();
- boolean success = false;
- try {
- Integer retryCount = externalTask.getRetries();
- logger.info("Executing External Task Delete Audit Inventory. Retry Number: {}", retryCount);
- Optional<AAIObjectAuditList> auditListOpt = auditDataService.getStackDataFromRequestDb(auditInventory);
- if (auditListOpt.isPresent()) {
- auditVservers.auditVservers(auditListOpt.get());
- } else {
- logger.debug("Auditing Vservers based on vf module relationships");
- auditListOpt = auditVservers.auditVserversThroughRelationships(auditInventory.getGenericVnfId(),
- auditInventory.getHeatStackName());
- }
- auditListOpt.get().setHeatStackName(auditInventory.getHeatStackName());
- auditListOpt.get().setAuditType("delete");
- GraphInventoryCommonObjectMapperProvider objectMapper = new GraphInventoryCommonObjectMapperProvider();
- variables.put("auditInventoryResult", objectMapper.getMapper().writeValueAsString(auditListOpt.get()));
- success = !didDeleteAuditFail(auditListOpt.get());
-
- } catch (Exception e) {
- logger.error("Error during audit of stack", e);
- }
- variables.put("auditIsSuccessful", success);
- mdcSetup.setElapsedTime();
- String externalTaskId = externalTask.getId();
- if (success) {
- externalTaskService.complete(externalTask, variables);
- mdcSetup.setResponseCode(ONAPLogConstants.ResponseStatus.COMPLETE.toString());
- logger.debug("The External Task Id: {} Successful", externalTaskId);
- logger.info(ONAPLogConstants.Markers.EXIT, "Exiting");
- mdcSetup.clearClientMDCs();
- } else {
- Integer retryCount = externalTask.getRetries();
- if (retryCount == null) {
- logger.debug("The External Task Id: {} Failed, Setting Retries to Default Start Value: {}",
- externalTaskId, getRetrySequence().length);
- externalTaskService.handleFailure(externalTask, UNABLE_TO_FIND_ALL_V_SERVERS_AND_L_INTERACES_IN_A_AI,
- UNABLE_TO_FIND_ALL_V_SERVERS_AND_L_INTERACES_IN_A_AI, getRetrySequence().length, 10000);
- } else if (retryCount == 1) {
- externalTaskService.complete(externalTask, variables);
- mdcSetup.setResponseCode(ONAPLogConstants.ResponseStatus.ERROR.toString());
- logger.debug("The External Task Id: {} Failed, All Retries Exhausted", externalTaskId);
- logger.info(ONAPLogConstants.Markers.EXIT, "Exiting");
- mdcSetup.clearClientMDCs();
- } else {
- logger.debug("The External Task Id: {} Failed, Decrementing Retries: {} , Retry Delay: ",
- externalTaskId, retryCount - 1, calculateRetryDelay(retryCount));
- externalTaskService.handleFailure(externalTask, UNABLE_TO_FIND_ALL_V_SERVERS_AND_L_INTERACES_IN_A_AI,
- UNABLE_TO_FIND_ALL_V_SERVERS_AND_L_INTERACES_IN_A_AI, retryCount - 1,
- calculateRetryDelay(retryCount));
- }
- logger.debug("The External Task Id: {} Failed", externalTaskId);
- }
- }
-
-}
diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/audit/AuditQueryStackService.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/audit/AuditQueryStackService.java
deleted file mode 100644
index ebef4425eb..0000000000
--- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/audit/AuditQueryStackService.java
+++ /dev/null
@@ -1,85 +0,0 @@
-package org.onap.so.adapters.tasks.audit;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Optional;
-import org.camunda.bpm.client.task.ExternalTask;
-import org.camunda.bpm.client.task.ExternalTaskService;
-import org.onap.logging.ref.slf4j.ONAPLogConstants;
-import org.onap.so.audit.beans.AuditInventory;
-import org.onap.so.logging.tasks.AuditMDCSetup;
-import org.onap.so.objects.audit.AAIObjectAuditList;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
-
-@Component
-public class AuditQueryStackService extends AbstractAuditService {
-
- private static final Logger logger = LoggerFactory.getLogger(AuditQueryStackService.class);
-
- @Autowired
- protected HeatStackAudit heatStackAudit;
-
- @Autowired
- protected AuditDataService auditDataService;
-
- @Autowired
- public AuditMDCSetup mdcSetup;
-
- public AuditQueryStackService() {
- super();
- }
-
- public void executeExternalTask(ExternalTask externalTask, ExternalTaskService externalTaskService) {
- mdcSetup.setupMDC(externalTask);
- AuditInventory auditInventory = externalTask.getVariable("auditInventory");
- boolean success = false;
- Map<String, Object> variables = new HashMap<>();
- try {
- Integer retryCount = externalTask.getRetries();
- logger.info("Executing External Task Query Audit Inventory. Audit Inventory: {} \n Retry Number: {}",
- auditInventory.toString(), retryCount);
-
- Optional<AAIObjectAuditList> auditList = heatStackAudit.queryHeatStack(auditInventory.getCloudOwner(),
- auditInventory.getCloudRegion(), auditInventory.getTenantId(), auditInventory.getHeatStackName());
-
- if (auditList.isPresent()) {
- mdcSetup.setResponseCode(ONAPLogConstants.ResponseStatus.COMPLETE.toString());
- success = true;
- auditDataService.writeStackDataToRequestDb(auditInventory, auditList.get());
- }
- mdcSetup.setElapsedTime();
- String externalTaskId = externalTask.getId();
- if (success) {
- externalTaskService.complete(externalTask, variables);
- mdcSetup.setResponseCode(ONAPLogConstants.ResponseStatus.COMPLETE.toString());
- logger.debug("The External Task {} was Successful", externalTaskId);
- logger.info(ONAPLogConstants.Markers.EXIT, "Exiting");
- mdcSetup.clearClientMDCs();
- } else {
- if (retryCount == null) {
- logger.debug("The External Task {} Failed. Setting Retries to Default Start Value: {}",
- externalTaskId, getRetrySequence().length);
- externalTaskService.handleFailure(externalTask, UNABLE_TO_FIND_V_SERVERS_IN_OPENSTACK,
- UNABLE_TO_FIND_V_SERVERS_IN_OPENSTACK, getRetrySequence().length, 10000);
- } else if (retryCount == 1) {
- externalTaskService.complete(externalTask, variables);
- mdcSetup.setResponseCode(ONAPLogConstants.ResponseStatus.ERROR.toString());
- logger.debug("The External Task {} Failed. All Retries Exhausted", externalTaskId);
- logger.info(ONAPLogConstants.Markers.EXIT, "Exiting");
- mdcSetup.clearClientMDCs();
- } else {
- logger.debug("The External Task {} Failed. Decrementing Retries to {} , Retry Delay: ",
- externalTaskId, retryCount - 1, calculateRetryDelay(retryCount));
- externalTaskService.handleFailure(externalTask, UNABLE_TO_FIND_V_SERVERS_IN_OPENSTACK,
- UNABLE_TO_FIND_V_SERVERS_IN_OPENSTACK, retryCount - 1, calculateRetryDelay(retryCount));
- }
- logger.debug("The External Task {} Failed", externalTaskId);
- }
- } catch (Exception e) {
- logger.error("Error during audit query of stack", e);
- }
- }
-}
diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/audit/AuditVServer.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/audit/AuditVServer.java
deleted file mode 100644
index 6f87b6b309..0000000000
--- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/audit/AuditVServer.java
+++ /dev/null
@@ -1,173 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP - SO
- * ================================================================================
- * Copyright (C) 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.so.adapters.tasks.audit;
-
-import java.util.List;
-import java.util.Optional;
-import java.util.Set;
-import org.onap.aai.domain.yang.LInterface;
-import org.onap.aai.domain.yang.VfModule;
-import org.onap.aai.domain.yang.VfModules;
-import org.onap.aai.domain.yang.Vserver;
-import org.onap.aaiclient.client.aai.AAIObjectType;
-import org.onap.aaiclient.client.aai.entities.AAIResultWrapper;
-import org.onap.aaiclient.client.aai.entities.uri.AAIPluralResourceUri;
-import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri;
-import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory;
-import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder;
-import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types;
-import org.onap.aaiclient.client.graphinventory.GraphInventoryCommonObjectMapperProvider;
-import org.onap.so.objects.audit.AAIObjectAudit;
-import org.onap.so.objects.audit.AAIObjectAuditList;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.BeanUtils;
-import org.springframework.stereotype.Component;
-import com.fasterxml.jackson.core.JsonProcessingException;
-
-@Component
-public class AuditVServer extends AbstractAudit {
- private static final Logger logger = LoggerFactory.getLogger(AuditVServer.class);
-
- public void auditVservers(AAIObjectAuditList aaiObjectAuditList) {
-
- aaiObjectAuditList.getAuditList().forEach(aaiObjectAudit -> {
- boolean vserverExist = getAaiClient().exists(
- AAIUriFactory.createResourceFromExistingURI(Types.VSERVER, aaiObjectAudit.getResourceURI()));
- aaiObjectAudit.setDoesObjectExist(vserverExist);
- });
- }
-
- public Optional<AAIObjectAuditList> auditVserversThroughRelationships(String genericVnfId, String vfModuleName) {
- AAIObjectAuditList auditList = new AAIObjectAuditList();
- AAIPluralResourceUri uri =
- AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf(genericVnfId).vfModules())
- .queryParam("vf-module-name", vfModuleName);
- Optional<AAIResultWrapper> wrapper = getAaiClient().getFirstWrapper(VfModules.class, VfModule.class, uri);
- if (wrapper.isPresent() && wrapper.get().getRelationships().isPresent()) {
- List<AAIResourceUri> relatedVservers = wrapper.get().getRelationships().get().getRelatedUris(Types.VSERVER);
- if (!relatedVservers.isEmpty()) {
- relatedVservers.forEach(vserverUri -> {
- Optional<Vserver> vserver = getAaiClient().get(vserverUri).asBean(Vserver.class);
- Vserver vServerShallow = new Vserver();
- BeanUtils.copyProperties(vserver, vServerShallow);
- AAIObjectAudit vServerAudit = new AAIObjectAudit();
- vServerAudit.setAaiObject(vServerShallow);
- vServerAudit.setAaiObjectType(Types.VSERVER.typeName());
- vServerAudit.setDoesObjectExist(true);
- auditList.getAuditList().add(vServerAudit);
- });
- }
- }
- return Optional.of(auditList);
- }
-
- public Optional<AAIObjectAuditList> auditVservers(Set<Vserver> vServersToAudit, String tenantId, String cloudOwner,
- String cloudRegion) {
- if (vServersToAudit == null || vServersToAudit.isEmpty()) {
- return Optional.empty();
- }
- GraphInventoryCommonObjectMapperProvider objectMapper = new GraphInventoryCommonObjectMapperProvider();
- vServersToAudit.stream().forEach(vserver -> {
- try {
- logger.debug("Vserver to Audit: {}", objectMapper.getMapper().writeValueAsString(vserver));
- } catch (JsonProcessingException e) {
- logger.error("Json parse exception: ", e);
- }
-
- });
- AAIObjectAuditList auditList = new AAIObjectAuditList();
- vServersToAudit.stream().forEach(vServer -> auditList.getAuditList()
- .addAll(doesVServerExistInAAI(vServer, tenantId, cloudOwner, cloudRegion).getAuditList()));
- return Optional.of(auditList);
- }
-
- private AAIObjectAuditList doesVServerExistInAAI(Vserver vServer, String tenantId, String cloudOwner,
- String cloudRegion) {
- AAIObjectAuditList auditList = new AAIObjectAuditList();
- AAIObjectAudit vServerAudit = new AAIObjectAudit();
- AAIResourceUri vserverURI = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure()
- .cloudRegion(cloudOwner, cloudRegion).tenant(tenantId).vserver(vServer.getVserverId()));
- Vserver vServerShallow = new Vserver();
- BeanUtils.copyProperties(vServer, vServerShallow, "LInterfaces");
- boolean vServerExists = getAaiClient().exists(vserverURI);
- logger.info("v-server {} exists: {}", vServer.getVserverId(), vServerExists);
- vServerAudit.setAaiObject(vServerShallow);
- vServerAudit.setDoesObjectExist(vServerExists);
- vServerAudit.setResourceURI(vserverURI.build());
- vServerAudit.setAaiObjectType(Types.VSERVER.typeName());
- auditList.getAuditList().add(vServerAudit);
- if (vServer.getLInterfaces() != null) {
- vServer.getLInterfaces().getLInterface().stream().forEach(lInterface -> auditList.getAuditList().addAll(
- doesLinterfaceExistinAAI(lInterface, vServer.getVserverId(), tenantId, cloudOwner, cloudRegion)
- .getAuditList()));
- }
- return auditList;
- }
-
- private AAIObjectAuditList doesLinterfaceExistinAAI(LInterface lInterface, String vServerId, String tenantId,
- String cloudOwner, String cloudRegion) {
- AAIObjectAuditList auditList = new AAIObjectAuditList();
- AAIObjectAudit lInterfaceAudit = new AAIObjectAudit();
- AAIResourceUri linterfaceURI = AAIUriFactory
- .createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure().cloudRegion(cloudOwner, cloudRegion)
- .tenant(tenantId).vserver(vServerId).lInterface(lInterface.getInterfaceName()));
- Optional<LInterface> queriedLInterface = getAaiClient().get(LInterface.class, linterfaceURI);
- if (queriedLInterface.isPresent()) {
- lInterfaceAudit.setDoesObjectExist(true);
- lInterface.setInterfaceName(lInterface.getInterfaceName());
- }
- lInterfaceAudit.setAaiObject(lInterface);
- lInterfaceAudit.setResourceURI(linterfaceURI.build());
- lInterfaceAudit.setAaiObjectType(Types.L_INTERFACE.typeName());
- auditList.getAuditList().add(lInterfaceAudit);
- logger.info("l-interface id:{} name: {} exists: {} ", lInterface.getInterfaceId(),
- lInterface.getInterfaceName(), lInterfaceAudit.isDoesObjectExist());
-
- if (lInterface.getLInterfaces() != null) {
- lInterface.getLInterfaces().getLInterface().stream()
- .forEach(subInterface -> auditList.getAuditList().add(doesSubInterfaceExistinAAI(subInterface,
- lInterface.getInterfaceName(), vServerId, tenantId, cloudOwner, cloudRegion)));
- }
- logger.debug("l-interface {} does not contain any sub-iterfaces, skipping audit of sub-interfaces",
- lInterface.getInterfaceId());
-
- return auditList;
- }
-
- private AAIObjectAudit doesSubInterfaceExistinAAI(LInterface subInterface, String linterfaceName, String vServerId,
- String tenantId, String cloudOwner, String cloudRegion) {
- logger.info("checking if sub-l-interface {} , linterfaceName: {} vserverId: {} exists",
- subInterface.getInterfaceName(), linterfaceName, vServerId);
- AAIObjectAudit subInterfaceAudit = new AAIObjectAudit();
-
-
- AAIResourceUri subInterfaceURI = AAIUriFactory.createResourceUri(AAIObjectType.SUB_L_INTERFACE, cloudOwner,
- cloudRegion, tenantId, vServerId, linterfaceName, subInterface.getInterfaceName());
- subInterfaceAudit.setResourceURI(subInterfaceURI.build());
- boolean doesExist = getAaiClient().exists(subInterfaceURI);
- logger.info("sub-l-interface-id:{} exists: {}", subInterface.getInterfaceId(), doesExist);
- subInterfaceAudit.setAaiObject(subInterface);
- subInterfaceAudit.setDoesObjectExist(doesExist);
- subInterfaceAudit.setAaiObjectType(AAIObjectType.SUB_L_INTERFACE.typeName());
- return subInterfaceAudit;
- }
-}
diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/audit/HeatStackAudit.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/audit/HeatStackAudit.java
deleted file mode 100644
index c58e568ea4..0000000000
--- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/audit/HeatStackAudit.java
+++ /dev/null
@@ -1,330 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP - SO
- * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
- *
- * Modifications Copyright (C) 2019 IBM.
- * ================================================================================
- * 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.tasks.audit;
-
-import java.net.URI;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Optional;
-import java.util.Set;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
-import org.onap.aai.domain.yang.LInterface;
-import org.onap.aai.domain.yang.LInterfaces;
-import org.onap.aai.domain.yang.Vlan;
-import org.onap.aai.domain.yang.Vlans;
-import org.onap.aai.domain.yang.Vserver;
-import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory;
-import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder;
-import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types;
-import org.onap.so.objects.audit.AAIObjectAudit;
-import org.onap.so.objects.audit.AAIObjectAuditList;
-import org.onap.so.openstack.utils.MsoHeatUtils;
-import org.onap.so.openstack.utils.MsoNeutronUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.BeanUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
-import com.woorea.openstack.heat.model.Link;
-import com.woorea.openstack.heat.model.Resource;
-import com.woorea.openstack.heat.model.Resources;
-import com.woorea.openstack.heat.model.Stack;
-import com.woorea.openstack.quantum.model.Port;
-
-@Component
-public class HeatStackAudit {
-
- private static final String RESOURCES = "/resources";
-
- protected static final Logger logger = LoggerFactory.getLogger(HeatStackAudit.class);
-
- private static final String EXCEPTION_MSG = "Error finding Path from Self Link";
-
- @Autowired
- protected MsoHeatUtils heat;
-
- @Autowired
- protected MsoNeutronUtils neutron;
-
- @Autowired
- protected AuditVServer auditVservers;
-
- public Optional<AAIObjectAuditList> queryHeatStack(String cloudOwner, String cloudRegion, String tenantId,
- String heatStackName) {
- try {
- logger.debug("Fetching Top Level Stack Information");
- Resources resources = heat.queryStackResources(cloudRegion, tenantId, heatStackName, 3);
- List<Resource> novaResources = resources.getList().stream()
- .filter(p -> "OS::Nova::Server".equals(p.getType())).collect(Collectors.toList());
- if (novaResources.isEmpty())
- return Optional.of(new AAIObjectAuditList());
- else {
- Set<Vserver> vserversToAudit = createVserverSet(novaResources);
- AAIObjectAuditList aaiObjectAuditList = new AAIObjectAuditList();
- vserversToAudit.stream().forEach(vServer -> aaiObjectAuditList.getAuditList()
- .add(createAAIObjectAudit(cloudOwner, cloudRegion, tenantId, vServer)));
- return Optional.of(aaiObjectAuditList);
- }
- } catch (Exception e) {
- logger.error("Error during query stack resources", e);
- return Optional.of(new AAIObjectAuditList());
- }
- }
-
- public Optional<AAIObjectAuditList> auditHeatStack(String cloudRegion, String cloudOwner, String tenantId,
- String heatStackName) {
- try {
- logger.debug("Fetching Top Level Stack Information");
- Resources resources = heat.queryStackResources(cloudRegion, tenantId, heatStackName, 3);
- List<Resource> novaResources = resources.getList().stream()
- .filter(p -> "OS::Nova::Server".equals(p.getType())).collect(Collectors.toList());
- List<Resource> resourceGroups = resources.getList().stream()
- .filter(p -> "OS::Heat::ResourceGroup".equals(p.getType()) && p.getName().contains("subinterfaces"))
- .collect(Collectors.toList());
- List<Optional<Port>> neutronPortDetails = retrieveNeutronPortDetails(resources, cloudRegion, tenantId);
- if (novaResources.isEmpty())
- return Optional.of(new AAIObjectAuditList());
- else {
- Set<Vserver> vserversToAudit = createVserverSet(resources, novaResources, neutronPortDetails);
- Set<Vserver> vserversWithSubInterfaces =
- processSubInterfaces(cloudRegion, tenantId, resourceGroups, vserversToAudit);
- return auditVservers.auditVservers(vserversWithSubInterfaces, tenantId, cloudOwner, cloudRegion);
- }
- } catch (Exception e) {
- logger.error("Error during auditing stack resources", e);
- return Optional.empty();
- }
- }
-
- protected Set<Vserver> processSubInterfaces(String cloudRegion, String tenantId, List<Resource> resourceGroups,
- Set<Vserver> vServersToAudit) throws Exception {
- for (Resource resourceGroup : resourceGroups) {
- processResourceGroups(cloudRegion, tenantId, vServersToAudit, resourceGroup);
- }
- return vServersToAudit;
- }
-
- protected void processResourceGroups(String cloudRegion, String tenantId, Set<Vserver> vServersWithLInterface,
- Resource resourceGroup) throws Exception {
- Optional<Link> stackLink =
- resourceGroup.getLinks().stream().filter(link -> "nested".equals(link.getRel())).findAny();
- if (stackLink.isPresent()) {
- try {
- Optional<String> path = extractResourcePathFromHref(stackLink.get().getHref());
- if (path.isPresent()) {
- logger.debug("Fetching nested Resource Stack Information");
- Resources nestedResourceGroupResources =
- heat.executeHeatClientRequest(path.get(), cloudRegion, tenantId, Resources.class);
- processNestedResourceGroup(cloudRegion, tenantId, vServersWithLInterface,
- nestedResourceGroupResources);
- } else
- throw new Exception(EXCEPTION_MSG);
- } catch (Exception e) {
- logger.error("Error Parsing Link to obtain Path", e);
- throw new Exception(EXCEPTION_MSG);
- }
- }
- }
-
- protected void processNestedResourceGroup(String cloudRegion, String tenantId, Set<Vserver> vServersWithLInterface,
- Resources nestedResourceGroupResources) throws Exception {
- for (Resource resourceGroupNested : nestedResourceGroupResources) {
- Optional<Link> subInterfaceStackLink =
- resourceGroupNested.getLinks().stream().filter(link -> "nested".equals(link.getRel())).findAny();
- if (subInterfaceStackLink.isPresent()) {
- addSubInterface(cloudRegion, tenantId, vServersWithLInterface, subInterfaceStackLink.get());
- }
- }
- }
-
- protected void addSubInterface(String cloudRegion, String tenantId, Set<Vserver> vServersWithLInterface,
- Link subInterfaceStackLink) throws Exception {
- Optional<String> resourcePath = extractResourcePathFromHref(subInterfaceStackLink.getHref());
- Optional<String> stackPath = extractStackPathFromHref(subInterfaceStackLink.getHref());
- if (resourcePath.isPresent() && stackPath.isPresent()) {
- logger.debug("Fetching nested Sub-Interface Stack Information");
- Stack subinterfaceStack =
- heat.executeHeatClientRequest(stackPath.get(), cloudRegion, tenantId, Stack.class);
- Resources subinterfaceResources =
- heat.executeHeatClientRequest(resourcePath.get(), cloudRegion, tenantId, Resources.class);
- if (subinterfaceStack != null) {
- addSubInterfaceToVserver(vServersWithLInterface, subinterfaceStack, subinterfaceResources);
- }
- } else
- throw new Exception(EXCEPTION_MSG);
-
- }
-
- protected void addSubInterfaceToVserver(Set<Vserver> vServersWithLInterface, Stack subinterfaceStack,
- Resources subinterfaceResources) throws Exception {
- String parentNeutronPortId = (String) subinterfaceStack.getParameters().get("port_interface");
- logger.debug("Parent neutron Port: {} on SubInterface: {}", parentNeutronPortId, subinterfaceStack.getId());
- for (Vserver auditVserver : vServersWithLInterface)
- for (LInterface lInterface : auditVserver.getLInterfaces().getLInterface())
-
- if (parentNeutronPortId.equals(lInterface.getInterfaceId())) {
- logger.debug("Found Parent Port on VServer: {} on Port: {}", auditVserver.getVserverId(),
- lInterface.getInterfaceId());
- Resource contrailVm = subinterfaceResources.getList().stream()
- .filter(resource -> "OS::ContrailV2::VirtualMachineInterface".equals(resource.getType()))
- .findAny().orElse(null);
- if (contrailVm == null) {
- throw new Exception("Cannnot find Contrail Virtual Machine Interface on Stack: "
- + subinterfaceStack.getId());
- }
- LInterface subInterface = new LInterface();
- subInterface.setInterfaceId(contrailVm.getPhysicalResourceId());
- subInterface.setIsPortMirrored(false);
- subInterface.setInMaint(false);
- subInterface.setIsIpUnnumbered(false);
- String macAddr = (String) subinterfaceStack.getParameters().get("mac_address");
- subInterface.setMacaddr(macAddr);
-
- String namePrefix = (String) subinterfaceStack.getParameters().get("subinterface_name_prefix");
- Integer vlanIndex = Integer.parseInt((String) subinterfaceStack.getParameters().get("counter"));
- String vlanTagList = (String) subinterfaceStack.getParameters().get("vlan_tag");
- List<String> subInterfaceVlanTagList = Arrays.asList(vlanTagList.split(","));
- subInterface.setInterfaceName(namePrefix + "_" + subInterfaceVlanTagList.get(vlanIndex));
- subInterface.setVlans(new Vlans());
- Vlan vlan = new Vlan();
- vlan.setInMaint(false);
- vlan.setIsIpUnnumbered(false);
- vlan.setVlanIdInner(Long.parseLong(subInterfaceVlanTagList.get(vlanIndex)));
- vlan.setVlanInterface(namePrefix + "_" + subInterfaceVlanTagList.get(vlanIndex));
- subInterface.getVlans().getVlan().add(vlan);
- if (lInterface.getLInterfaces() == null)
- lInterface.setLInterfaces(new LInterfaces());
-
- lInterface.getLInterfaces().getLInterface().add(subInterface);
- } else
- logger.debug("Did Not Find Parent Port on VServer: {} Parent Port: SubInterface: {}",
- auditVserver.getVserverId(), lInterface.getInterfaceId(), subinterfaceStack.getId());
- }
-
- protected Set<Vserver> createVserverSet(Resources resources, List<Resource> novaResources,
- List<Optional<Port>> neutronPortDetails) {
- Set<Vserver> vserversToAudit = new HashSet<>();
- for (Resource novaResource : novaResources) {
- Vserver auditVserver = new Vserver();
- auditVserver.setLInterfaces(new LInterfaces());
- auditVserver.setVserverId(novaResource.getPhysicalResourceId());
- Stream<Port> filteredNeutronPorts = filterNeutronPorts(novaResource, neutronPortDetails);
- filteredNeutronPorts.forEach(port -> {
- LInterface lInterface = new LInterface();
- lInterface.setInterfaceId(port.getId());
- lInterface.setInterfaceName(port.getName());
- auditVserver.getLInterfaces().getLInterface().add(lInterface);
- });
- vserversToAudit.add(auditVserver);
- }
- return vserversToAudit;
- }
-
- protected Set<Vserver> createVserverSet(List<Resource> novaResources) {
- Set<Vserver> vserversToAudit = new HashSet<>();
- for (Resource novaResource : novaResources) {
- Vserver auditVserver = new Vserver();
- auditVserver.setLInterfaces(new LInterfaces());
- auditVserver.setVserverId(novaResource.getPhysicalResourceId());
- vserversToAudit.add(auditVserver);
- }
- return vserversToAudit;
- }
-
- protected AAIObjectAudit createAAIObjectAudit(String cloudOwner, String cloudRegion, String tenantId,
- Vserver vServer) {
- AAIObjectAudit aaiObjectAudit = new AAIObjectAudit();
- Vserver vServerShallow = new Vserver();
- BeanUtils.copyProperties(vServer, vServerShallow);
- aaiObjectAudit.setAaiObject(vServerShallow);
- aaiObjectAudit.setAaiObjectType(Types.VSERVER.typeName());
- aaiObjectAudit
- .setResourceURI(AAIUriFactory
- .createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure()
- .cloudRegion(cloudOwner, cloudRegion).tenant(tenantId).vserver(vServer.getVserverId()))
- .build());
-
- return aaiObjectAudit;
- }
-
- /**
- * @param novaResource Single openstack resource that is of type Nova
- * @param neutronPorts List of Neutron ports created within the stack
- * @return Filtered list of neutron ports taht relate to the nova server in openstack
- */
- protected Stream<Port> filterNeutronPorts(Resource novaResource, List<Optional<Port>> neutronPorts) {
- List<Port> filteredNeutronPorts =
- neutronPorts.stream().filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList());
- return filteredNeutronPorts.stream()
- .filter(port -> port.getDeviceId().equalsIgnoreCase(novaResource.getPhysicalResourceId()));
- }
-
- /**
- * @param resources Resource stream created by the stack in openstack
- * @param cloudSiteId Unique site id to identify which openstack we talk to
- * @param tenantId The tenant within the cloud we are talking to where resouces exist
- * @return List of optional neutron ports found within the cloud site and tenant
- */
- protected List<Optional<Port>> retrieveNeutronPortDetails(Resources resources, String cloudSiteId,
- String tenantId) {
- return resources.getList().stream().filter(resource -> "OS::Neutron::Port".equals(resource.getType()))
- .map(resource -> neutron.getNeutronPort(resource.getPhysicalResourceId(), tenantId, cloudSiteId))
- .collect(Collectors.toList());
-
- }
-
- protected Optional<String> extractResourcePathFromHref(String href) {
- try {
- Optional<String> stackPath = extractStackPathFromHref(href);
- if (stackPath.isPresent()) {
- return Optional.of(stackPath.get() + RESOURCES);
- } else
- return Optional.empty();
- } catch (Exception e) {
- logger.error("Error parsing URI", e);
- }
- return Optional.empty();
- }
-
- protected Optional<String> extractStackPathFromHref(String href) {
- try {
- URI uri = new URI(href);
- Pattern p = Pattern.compile("/stacks.*");
- Matcher m = p.matcher(uri.getPath());
- if (m.find()) {
- return Optional.of(m.group());
- } else
- return Optional.empty();
- } catch (Exception e) {
- logger.error("Error parsing URI", e);
- }
- return Optional.empty();
- }
-
-
-}
-
diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/inventory/CreateAAIInventory.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/inventory/CreateAAIInventory.java
index 3f79c43bf8..a6194517c2 100644
--- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/inventory/CreateAAIInventory.java
+++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/inventory/CreateAAIInventory.java
@@ -29,6 +29,7 @@ import org.onap.so.cloud.resource.beans.CloudInformation;
import org.onap.so.db.catalog.beans.CloudIdentity;
import org.onap.so.db.catalog.beans.CloudSite;
import org.onap.so.heatbridge.HeatBridgeApi;
+import org.onap.so.heatbridge.HeatBridgeException;
import org.onap.so.heatbridge.HeatBridgeImpl;
import org.onap.so.openstack.exceptions.MsoCloudSiteNotFound;
import org.openstack4j.model.compute.Flavor;
@@ -55,75 +56,70 @@ public class CreateAAIInventory {
@Autowired
protected Environment env;
- public void heatbridge(CloudInformation cloudInformation) {
- try {
- CloudSite cloudSite = cloudConfig.getCloudSite(cloudInformation.getRegionId())
- .orElseThrow(() -> new MsoCloudSiteNotFound(cloudInformation.getRegionId()));
- CloudIdentity cloudIdentity = cloudSite.getIdentityService();
- String heatStackId = cloudInformation.getTemplateInstanceId().split("/")[1];
-
- List<String> oobMgtNetNames = new ArrayList<>();
-
- HeatBridgeApi heatBridgeClient = new HeatBridgeImpl(new AAIResourcesClient(), cloudIdentity,
- cloudInformation.getOwner(), cloudInformation.getRegionId(), cloudSite.getRegionId(),
- cloudInformation.getTenantId(), cloudInformation.getNodeType());
-
- heatBridgeClient.authenticate();
-
- List<Resource> stackResources =
- heatBridgeClient.queryNestedHeatStackResources(cloudInformation.getTemplateInstanceId());
-
- List<Network> osNetworks = heatBridgeClient.getAllOpenstackProviderNetworks(stackResources);
- heatBridgeClient.buildAddNetworksToAaiAction(cloudInformation.getVnfId(), cloudInformation.getVfModuleId(),
- osNetworks);
-
- List<Server> osServers = heatBridgeClient.getAllOpenstackServers(stackResources);
-
- heatBridgeClient.createPserversAndPinterfacesIfNotPresentInAai(stackResources);
-
- List<Image> osImages = heatBridgeClient.extractOpenstackImagesFromServers(osServers);
-
- List<Flavor> osFlavors = heatBridgeClient.extractOpenstackFlavorsFromServers(osServers);
-
- logger.debug("Successfully queried heat stack{} for resources.", heatStackId);
- // os images
- if (osImages != null && !osImages.isEmpty()) {
- heatBridgeClient.buildAddImagesToAaiAction(osImages);
- logger.debug("Successfully built AAI actions to add images.");
- } else {
- logger.debug("No images to update to AAI.");
- }
- // flavors
- if (osFlavors != null && !osFlavors.isEmpty()) {
- heatBridgeClient.buildAddFlavorsToAaiAction(osFlavors);
- logger.debug("Successfully built AAI actions to add flavors.");
- } else {
- logger.debug("No flavors to update to AAI.");
- }
-
- // compute resources
- heatBridgeClient.buildAddVserversToAaiAction(cloudInformation.getVnfId(), cloudInformation.getVfModuleId(),
- osServers);
- logger.debug("Successfully queried compute resources and built AAI vserver actions.");
-
- // neutron resources
- List<String> oobMgtNetIds = new ArrayList<>();
-
- // if no network-id list is provided, however network-name list is
- if (!CollectionUtils.isEmpty(oobMgtNetNames)) {
- oobMgtNetIds = heatBridgeClient.extractNetworkIds(oobMgtNetNames);
- }
- heatBridgeClient.buildAddVserverLInterfacesToAaiAction(stackResources, oobMgtNetIds,
- cloudInformation.getOwner());
- logger.debug(
- "Successfully queried neutron resources and built AAI actions to add l-interfaces to vservers.");
-
- // Update AAI
- logger.debug("Current Dry Run Value: {}", env.getProperty("heatBridgeDryrun", Boolean.class, false));
- heatBridgeClient.submitToAai(env.getProperty("heatBridgeDryrun", Boolean.class, false));
- } catch (Exception ex) {
- logger.debug("Heatbrige failed for stackId: " + cloudInformation.getTemplateInstanceId(), ex);
+ public void heatbridge(CloudInformation cloudInformation) throws HeatBridgeException, MsoCloudSiteNotFound {
+ CloudSite cloudSite = cloudConfig.getCloudSite(cloudInformation.getRegionId())
+ .orElseThrow(() -> new MsoCloudSiteNotFound(cloudInformation.getRegionId()));
+ CloudIdentity cloudIdentity = cloudSite.getIdentityService();
+ String heatStackId = cloudInformation.getTemplateInstanceId().split("/")[1];
+
+ List<String> oobMgtNetNames = new ArrayList<>();
+
+ HeatBridgeApi heatBridgeClient = new HeatBridgeImpl(new AAIResourcesClient(), cloudIdentity,
+ cloudInformation.getOwner(), cloudInformation.getRegionId(), cloudSite.getRegionId(),
+ cloudInformation.getTenantId(), cloudInformation.getNodeType());
+
+ heatBridgeClient.authenticate();
+
+ List<Resource> stackResources =
+ heatBridgeClient.queryNestedHeatStackResources(cloudInformation.getTemplateInstanceId());
+
+ List<Network> osNetworks = heatBridgeClient.getAllOpenstackProviderNetworks(stackResources);
+ heatBridgeClient.buildAddNetworksToAaiAction(cloudInformation.getVnfId(), cloudInformation.getVfModuleId(),
+ osNetworks);
+
+ List<Server> osServers = heatBridgeClient.getAllOpenstackServers(stackResources);
+
+ heatBridgeClient.createPserversAndPinterfacesIfNotPresentInAai(stackResources);
+
+ List<Image> osImages = heatBridgeClient.extractOpenstackImagesFromServers(osServers);
+
+ List<Flavor> osFlavors = heatBridgeClient.extractOpenstackFlavorsFromServers(osServers);
+
+ logger.debug("Successfully queried heat stack{} for resources.", heatStackId);
+ // os images
+ if (osImages != null && !osImages.isEmpty()) {
+ heatBridgeClient.buildAddImagesToAaiAction(osImages);
+ logger.debug("Successfully built AAI actions to add images.");
+ } else {
+ logger.debug("No images to update to AAI.");
+ }
+ // flavors
+ if (osFlavors != null && !osFlavors.isEmpty()) {
+ heatBridgeClient.buildAddFlavorsToAaiAction(osFlavors);
+ logger.debug("Successfully built AAI actions to add flavors.");
+ } else {
+ logger.debug("No flavors to update to AAI.");
+ }
+
+ // compute resources
+ heatBridgeClient.buildAddVserversToAaiAction(cloudInformation.getVnfId(), cloudInformation.getVfModuleId(),
+ osServers);
+ logger.debug("Successfully queried compute resources and built AAI vserver actions.");
+
+ // neutron resources
+ List<String> oobMgtNetIds = new ArrayList<>();
+
+ // if no network-id list is provided, however network-name list is
+ if (!CollectionUtils.isEmpty(oobMgtNetNames)) {
+ oobMgtNetIds = heatBridgeClient.extractNetworkIds(oobMgtNetNames);
}
+ heatBridgeClient.buildAddVserverLInterfacesToAaiAction(stackResources, oobMgtNetIds,
+ cloudInformation.getOwner());
+ logger.debug("Successfully queried neutron resources and built AAI actions to add l-interfaces to vservers.");
+
+ // Update AAI
+ logger.debug("Current Dry Run Value: {}", env.getProperty("heatBridgeDryrun", Boolean.class, false));
+ heatBridgeClient.submitToAai(env.getProperty("heatBridgeDryrun", Boolean.class, false));
}
protected AAIResourcesClient getAaiClient() {
diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/inventory/CreateInventoryTask.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/inventory/CreateInventoryTask.java
index 2202e97e71..3c9a4833ae 100644
--- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/inventory/CreateInventoryTask.java
+++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/inventory/CreateInventoryTask.java
@@ -57,7 +57,6 @@ public class CreateInventoryTask extends ExternalTaskUtils {
public void executeExternalTask(ExternalTask externalTask, ExternalTaskService externalTaskService) {
mdcSetup.setupMDC(externalTask);
- boolean inventoryException = false;
String externalTaskId = externalTask.getId();
CloudInformation cloudInformation = externalTask.getVariable("cloudInformation");
boolean success = true;
@@ -75,30 +74,29 @@ public class CreateInventoryTask extends ExternalTaskUtils {
if (success) {
externalTaskService.complete(externalTask);
mdcSetup.setResponseCode(ONAPLogConstants.ResponseStatus.COMPLETE.toString());
- logger.debug("The External Task Id: {} Successful", externalTaskId);
+ logger.debug("The External Task {} was successful", externalTaskId);
logger.info(ONAPLogConstants.Markers.EXIT, "Exiting");
mdcSetup.clearClientMDCs();
} else {
if (retryCount == null) {
- logger.error("The External Task Id: {} Failed, Setting Retries to Default Start Value: {}",
+ logger.error("The External Task {} Failed, Setting Retries to Default Start Value: {}",
externalTaskId, getRetrySequence().length);
externalTaskService.handleFailure(externalTask, UNABLE_TO_WRITE_ALL_INVENTORY_TO_A_AI,
UNABLE_TO_WRITE_ALL_INVENTORY_TO_A_AI, getRetrySequence().length, 10000);
} else if (retryCount != null && retryCount - 1 == 0) {
externalTaskService.handleBpmnError(externalTask, AAI_INVENTORY_FAILURE);
mdcSetup.setResponseCode(ONAPLogConstants.ResponseStatus.ERROR.toString());
- logger.error("The External Task Id: {} Failed, All Retries Exhausted", externalTaskId);
+ logger.error("The External Task {} Failed, All Retries Exhausted", externalTaskId);
logger.info(ONAPLogConstants.Markers.EXIT, "Exiting");
} else {
- logger.error("The External Task Id: {} Failed, Decrementing Retries: {} , Retry Delay: ",
+ logger.error("The External Task {} Failed, Decrementing Retries: {} , Retry Delay: ",
externalTaskId, retryCount - 1, calculateRetryDelay(retryCount));
externalTaskService.handleFailure(externalTask, UNABLE_TO_WRITE_ALL_INVENTORY_TO_A_AI,
UNABLE_TO_WRITE_ALL_INVENTORY_TO_A_AI, retryCount - 1, calculateRetryDelay(retryCount));
}
- logger.error("The External Task Id: {} Failed", externalTaskId);
}
} else {
- logger.error("The External Task Id: {} Failed, No Cloud Information Provided", externalTaskId);
+ logger.error("The External Task {} Failed, No Cloud Information Provided", externalTaskId);
externalTaskService.handleBpmnError(externalTask, AAI_INVENTORY_FAILURE);
}
}
diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/inventory/delete/DeleteAAIInventory.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/inventory/DeleteAAIInventory.java
index 22e6b1fc22..f5a6355529 100644
--- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/inventory/delete/DeleteAAIInventory.java
+++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/inventory/DeleteAAIInventory.java
@@ -18,7 +18,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.so.adapters.inventory.delete;
+package org.onap.so.adapters.tasks.inventory;
import org.onap.aaiclient.client.aai.AAIResourcesClient;
import org.onap.so.cloud.CloudConfig;
@@ -26,6 +26,7 @@ import org.onap.so.cloud.resource.beans.CloudInformation;
import org.onap.so.db.catalog.beans.CloudIdentity;
import org.onap.so.db.catalog.beans.CloudSite;
import org.onap.so.heatbridge.HeatBridgeApi;
+import org.onap.so.heatbridge.HeatBridgeException;
import org.onap.so.heatbridge.HeatBridgeImpl;
import org.onap.so.openstack.exceptions.MsoCloudSiteNotFound;
import org.slf4j.Logger;
@@ -47,22 +48,16 @@ public class DeleteAAIInventory {
@Autowired
protected Environment env;
- public void heatbridge(CloudInformation cloudInformation) {
- try {
- logger.debug("Heatbridge delete executing");
-
- CloudSite cloudSite = cloudConfig.getCloudSite(cloudInformation.getRegionId())
- .orElseThrow(() -> new MsoCloudSiteNotFound(cloudInformation.getRegionId()));
- CloudIdentity cloudIdentity = cloudSite.getIdentityService();
- HeatBridgeApi heatBridgeClient = new HeatBridgeImpl(new AAIResourcesClient(), cloudIdentity,
- cloudInformation.getOwner(), cloudInformation.getRegionId(), cloudSite.getRegionId(),
- cloudInformation.getTenantId(), cloudInformation.getNodeType());
- heatBridgeClient.authenticate();
- heatBridgeClient.deleteVfModuleData(cloudInformation.getVnfId(), cloudInformation.getVfModuleId());
-
- } catch (Exception ex) {
- logger.debug("Heatbrige failed for stackId: " + cloudInformation.getTemplateInstanceId(), ex);
- }
+ public void heatbridge(CloudInformation cloudInformation) throws MsoCloudSiteNotFound, HeatBridgeException {
+ logger.debug("Heatbridge delete executing");
+ CloudSite cloudSite = cloudConfig.getCloudSite(cloudInformation.getRegionId())
+ .orElseThrow(() -> new MsoCloudSiteNotFound(cloudInformation.getRegionId()));
+ CloudIdentity cloudIdentity = cloudSite.getIdentityService();
+ HeatBridgeApi heatBridgeClient = new HeatBridgeImpl(new AAIResourcesClient(), cloudIdentity,
+ cloudInformation.getOwner(), cloudInformation.getRegionId(), cloudSite.getRegionId(),
+ cloudInformation.getTenantId(), cloudInformation.getNodeType());
+ heatBridgeClient.authenticate();
+ heatBridgeClient.deleteVfModuleData(cloudInformation.getVnfId(), cloudInformation.getVfModuleId());
}
protected AAIResourcesClient getAaiClient() {
diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/inventory/delete/DeleteInventoryTask.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/inventory/DeleteInventoryTask.java
index 10faa2b08f..08361bdbbf 100644
--- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/inventory/delete/DeleteInventoryTask.java
+++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/inventory/DeleteInventoryTask.java
@@ -20,7 +20,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.so.adapters.inventory.delete;
+package org.onap.so.adapters.tasks.inventory;
import org.camunda.bpm.client.task.ExternalTask;
import org.camunda.bpm.client.task.ExternalTaskService;
@@ -32,7 +32,6 @@ import org.onap.so.utils.RetrySequenceLevel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
@@ -49,16 +48,13 @@ public class DeleteInventoryTask extends ExternalTaskUtils {
private DeleteAAIInventory deleteInventory;
@Autowired
- private Environment env;
-
- @Autowired
private AuditMDCSetup mdcSetup;
public DeleteInventoryTask() {
super(RetrySequenceLevel.SHORT);
}
- protected void executeExternalTask(ExternalTask externalTask, ExternalTaskService externalTaskService) {
+ public void executeExternalTask(ExternalTask externalTask, ExternalTaskService externalTaskService) {
mdcSetup.setupMDC(externalTask);
String externalTaskId = externalTask.getId();
CloudInformation cloudInformation = externalTask.getVariable("cloudInformation");
diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/HeatBridgeImpl.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/HeatBridgeImpl.java
index 45b29244d1..1264727f35 100644
--- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/HeatBridgeImpl.java
+++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/HeatBridgeImpl.java
@@ -324,10 +324,23 @@ public class HeatBridgeImpl implements HeatBridgeApi {
// Build vserver relationships to: image, flavor, pserver, vf-module
vserver.setRelationshipList(
aaiHelper.getVserverRelationshipList(cloudOwner, cloudRegionId, genericVnfId, vfModuleId, server));
- transaction.createIfNotExists(
- AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure()
- .cloudRegion(cloudOwner, cloudRegionId).tenant(tenantId).vserver(vserver.getVserverId())),
- Optional.of(vserver));
+ AAIResourceUri vserverUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure()
+ .cloudRegion(cloudOwner, cloudRegionId).tenant(tenantId).vserver(vserver.getVserverId()));
+ if (resourcesClient.exists(vserverUri)) {
+ AAIResultWrapper existingVserver = resourcesClient.get(vserverUri);
+ if (!existingVserver.hasRelationshipsTo(Types.VF_MODULE)) {
+ AAIResourceUri vfModuleUri = AAIUriFactory.createResourceUri(
+ AAIFluentTypeBuilder.network().genericVnf(genericVnfId).vfModule(vfModuleId));
+ transaction.connect(vserverUri, vfModuleUri);
+ }
+ if (!existingVserver.hasRelationshipsTo(Types.PSERVER)) {
+ AAIResourceUri pServerUri = AAIUriFactory.createResourceUri(
+ AAIFluentTypeBuilder.cloudInfrastructure().pserver(server.getHypervisorHostname()));
+ transaction.connect(vserverUri, pServerUri);
+ }
+ } else {
+ transaction.create(vserverUri, vserver);
+ }
});
}
@@ -380,10 +393,9 @@ public class HeatBridgeImpl implements HeatBridgeApi {
if (cloudOwner.equals(env.getProperty("mso.cloudOwner.included", ""))) {
Server server = getOpenstackServerById(port.getDeviceId());
- updateLInterfaceVlan(port, lIf, server.getHypervisorHostname());
+ createVlanAndSriovVF(port, lIf, server.getHypervisorHostname());
+ updateSriovPfToSriovVF(port, lIf);
}
-
- updateSriovPfToPserver(port, lIf);
}
}
@@ -464,7 +476,7 @@ public class HeatBridgeImpl implements HeatBridgeApi {
resourcesClient.createIfNotExists(uri, Optional.of(pInterface));
}
- protected void updateLInterfaceVlan(final Port port, final LInterface lIf, final String hostName)
+ protected void createVlanAndSriovVF(final Port port, final LInterface lIf, final String hostName)
throws HeatBridgeException {
// add back all vlan logic
Vlan vlan = new Vlan();
@@ -582,7 +594,7 @@ public class HeatBridgeImpl implements HeatBridgeApi {
* @param lIf AAI l-interface object
* @throws HeatBridgeException
*/
- protected void updateSriovPfToPserver(final Port port, final LInterface lIf) throws HeatBridgeException {
+ protected void updateSriovPfToSriovVF(final Port port, final LInterface lIf) throws HeatBridgeException {
if (port.getvNicType().equalsIgnoreCase(HeatBridgeConstants.OS_SRIOV_PORT_TYPE)) {
AAIResourceUri sriovVfUri = AAIUriFactory
diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/helpers/AaiHelper.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/helpers/AaiHelper.java
index c1a97cefc4..8e6f8cc69b 100644
--- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/helpers/AaiHelper.java
+++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/helpers/AaiHelper.java
@@ -92,13 +92,6 @@ public class AaiHelper {
AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf(genericVnfId)));
relationships.add(genericVnfRelationship);
- // vserver to vnfc relationship
- if (!StringUtils.isEmpty(server.getName())) {
- Relationship vnfcRelationship = buildRelationship(
- AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().vnfc(server.getName())));
- relationships.add(vnfcRelationship);
- }
-
// vserver to vf-module relationship
Relationship vfModuleRelationship = buildRelationship(AAIUriFactory
.createResourceUri(AAIFluentTypeBuilder.network().genericVnf(genericVnfId).vfModule(vfModuleId)));
diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/audit/AbstractAuditServiceTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/audit/AbstractAuditServiceTest.java
deleted file mode 100644
index c70e60e9d3..0000000000
--- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/audit/AbstractAuditServiceTest.java
+++ /dev/null
@@ -1,51 +0,0 @@
-package org.onap.so.adapters.tasks.audit;
-
-import org.junit.Test;
-import org.onap.so.objects.audit.AAIObjectAudit;
-import org.onap.so.objects.audit.AAIObjectAuditList;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-public class AbstractAuditServiceTest extends AbstractAuditService {
-
- private AAIObjectAuditList getAuditListWithObjectWithExistenceStateOf(boolean existenceState) {
- AAIObjectAudit auditObject = new AAIObjectAudit();
- AAIObjectAuditList auditList = new AAIObjectAuditList();
-
- auditObject.setDoesObjectExist(existenceState);
- auditList.getAuditList().add(auditObject);
-
- return auditList;
- }
-
- @Test
- public void didCreateAuditFail_shouldReturnFalse_whenGivenNull() {
- assertFalse(didCreateAuditFail(null));
- }
-
- @Test
- public void didCreateAuditFail_shouldReturnTrue_whenGivenNotExistingObject() {
- assertTrue(didCreateAuditFail(getAuditListWithObjectWithExistenceStateOf(false)));
- }
-
- @Test
- public void didCreateAuditFail_shouldReturnFalse_whenGivenExistingObject() {
- assertFalse(didCreateAuditFail(getAuditListWithObjectWithExistenceStateOf(true)));
- }
-
- @Test
- public void didDeleteAuditFail_shouldReturnFalse_whenGivenNull() {
- assertFalse(didDeleteAuditFail(null));
- }
-
- @Test
- public void didDeleteAuditFail_shouldReturnTrue_whenGivenExistingObject() {
- assertTrue(didDeleteAuditFail(getAuditListWithObjectWithExistenceStateOf(true)));
- }
-
- @Test
- public void didDeleteAuditFail_shouldReturnFalse_whenGivenNotExistingObject() {
- assertFalse(didDeleteAuditFail(getAuditListWithObjectWithExistenceStateOf(false)));
- }
-
-}
diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/audit/AuditDataServiceTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/audit/AuditDataServiceTest.java
deleted file mode 100644
index 76e5bbc47f..0000000000
--- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/audit/AuditDataServiceTest.java
+++ /dev/null
@@ -1,113 +0,0 @@
-package org.onap.so.adapters.tasks.audit;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Optional;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.InjectMocks;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.junit.MockitoJUnitRunner;
-import org.onap.aai.domain.yang.Vserver;
-import org.onap.so.audit.beans.AuditInventory;
-import org.onap.aaiclient.client.graphinventory.GraphInventoryCommonObjectMapperProvider;
-import org.onap.so.db.request.beans.RequestProcessingData;
-import org.onap.so.db.request.client.RequestsDbClient;
-import org.onap.so.objects.audit.AAIObjectAudit;
-import org.onap.so.objects.audit.AAIObjectAuditList;
-import com.fasterxml.jackson.core.JsonProcessingException;
-
-
-@RunWith(MockitoJUnitRunner.Silent.class)
-public class AuditDataServiceTest {
-
- @InjectMocks
- AuditDataService auditDataService = new AuditDataService();
-
- @Mock
- protected RequestsDbClient requestsDbClient;
-
- AuditInventory auditInventory = new AuditInventory();
-
- @Before
- public void before() throws JsonProcessingException {
- auditInventory.setCloudOwner("testCloudOwner");
- auditInventory.setCloudRegion("testLcpCloudRegionId");
- auditInventory.setHeatStackName("testVfModuleName1");
- auditInventory.setVfModuleId("testVnfModuleId");
- auditInventory.setTenantId("testTenantId");
- auditInventory.setGenericVnfId("testVnfId1");
- }
-
- @Test
- public void testWriteStackDataToRequestDb() throws Exception {
- Mockito.doReturn(new ArrayList<RequestProcessingData>()).when(requestsDbClient)
- .getRequestProcessingDataByGroupingIdAndNameAndTag(Mockito.any(), Mockito.any(), Mockito.any());
- Mockito.doNothing().when(requestsDbClient).saveRequestProcessingData(Mockito.any());
-
- AAIObjectAuditList auditList = new AAIObjectAuditList();
- auditList.setHeatStackName("testHeatStackName");
- AAIObjectAudit audit = new AAIObjectAudit();
- Vserver vserver = new Vserver();
- vserver.setVserverId("testVserverId");
- audit.setAaiObject(vserver);
- auditList.getAuditList().add(audit);
- GraphInventoryCommonObjectMapperProvider objectMapper = new GraphInventoryCommonObjectMapperProvider();
- String auditListString = objectMapper.getMapper().writeValueAsString(auditList);
-
- RequestProcessingData requestProcessingData = new RequestProcessingData();
- requestProcessingData.setSoRequestId(auditInventory.getMsoRequestId());
- requestProcessingData.setGroupingId(auditInventory.getVfModuleId());
- requestProcessingData.setName(auditInventory.getHeatStackName());
- requestProcessingData.setTag("AuditStackData");
- requestProcessingData.setValue(auditListString);
-
- auditDataService.writeStackDataToRequestDb(auditInventory, auditList);
- Mockito.verify(requestsDbClient, Mockito.times(1)).saveRequestProcessingData(requestProcessingData);
- }
-
- @Test
- public void testGetStackDataToRequestDb() throws Exception {
- AAIObjectAuditList auditList = new AAIObjectAuditList();
- auditList.setHeatStackName("testHeatStackName");
- AAIObjectAudit audit = new AAIObjectAudit();
- Vserver vserver = new Vserver();
- vserver.setVserverId("testVserverId");
- audit.setAaiObject(vserver);
- auditList.getAuditList().add(audit);
- GraphInventoryCommonObjectMapperProvider objectMapper = new GraphInventoryCommonObjectMapperProvider();
- String auditListString = objectMapper.getMapper().writeValueAsString(audit);
-
- List<RequestProcessingData> list = new ArrayList();
- RequestProcessingData requestProcessingData = new RequestProcessingData();
- requestProcessingData.setId(234321432);
- requestProcessingData.setGroupingId("testVfModuleId");
- requestProcessingData.setName("heatStackName");
- requestProcessingData.setTag("AuditStackData");
- requestProcessingData.setValue(auditListString);
- list.add(requestProcessingData);
-
- Mockito.doReturn(list).when(requestsDbClient).getRequestProcessingDataByGroupingIdAndNameAndTag(Mockito.any(),
- Mockito.any(), Mockito.any());
- auditDataService.getStackDataFromRequestDb(auditInventory);
- Mockito.verify(requestsDbClient, Mockito.times(1)).getRequestProcessingDataByGroupingIdAndNameAndTag(
- "testVnfModuleId", "testVfModuleName1", "AuditStackData");
- }
-
- @Test
- public void testGetStackDataToRequestDbWhenRequestProcessingDataListIsEmpty() throws Exception {
-
- Mockito.doReturn(new ArrayList<RequestProcessingData>()).when(requestsDbClient)
- .getRequestProcessingDataByGroupingIdAndNameAndTag(Mockito.any(), Mockito.any(), Mockito.any());
- Optional<AAIObjectAuditList> result = auditDataService.getStackDataFromRequestDb(auditInventory);
- Mockito.verify(requestsDbClient, Mockito.times(1)).getRequestProcessingDataByGroupingIdAndNameAndTag(
- "testVnfModuleId", "testVfModuleName1", "AuditStackData");
- assertThat(result).isEmpty();
-
- }
-
-
-}
diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/audit/AuditStackServiceDataTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/audit/AuditStackServiceDataTest.java
deleted file mode 100644
index 78dbcd94c2..0000000000
--- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/audit/AuditStackServiceDataTest.java
+++ /dev/null
@@ -1,191 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP - SO
- * ================================================================================
- * 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.so.adapters.tasks.audit;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.mockito.Mockito.doReturn;
-import java.io.File;
-import java.io.IOException;
-import java.util.Map;
-import java.util.Optional;
-import org.camunda.bpm.client.task.ExternalTask;
-import org.camunda.bpm.client.task.ExternalTaskService;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.ArgumentCaptor;
-import org.mockito.InjectMocks;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
-import org.onap.so.adapters.tasks.audit.AuditCreateStackService;
-import org.onap.so.adapters.tasks.audit.AuditDataService;
-import org.onap.so.adapters.tasks.audit.AuditQueryStackService;
-import org.onap.so.adapters.tasks.audit.HeatStackAudit;
-import org.onap.so.audit.beans.AuditInventory;
-import org.onap.so.logging.tasks.AuditMDCSetup;
-import org.onap.so.objects.audit.AAIObjectAuditList;
-import org.springframework.core.env.Environment;
-import com.fasterxml.jackson.core.JsonParseException;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.JsonMappingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-
-public class AuditStackServiceDataTest extends AuditCreateStackService {
-
- @InjectMocks
- private AuditCreateStackService auditStackService = new AuditCreateStackService();
-
- @InjectMocks
- private AuditQueryStackService auditQueryStackService = new AuditQueryStackService();
-
- @Mock
- private HeatStackAudit heatStackAuditMock;
-
- @Mock
- private Environment mockEnv;
-
- @Mock
- private ExternalTask mockExternalTask;
-
- @Mock
- private ExternalTaskService mockExternalTaskService;
-
- @Mock
- private AuditDataService auditDataService;
-
- @Mock
- private AuditMDCSetup mdcSetup;
-
- private ObjectMapper objectMapper = new ObjectMapper();
-
- private AuditInventory auditInventory = new AuditInventory();
-
- Optional<AAIObjectAuditList> auditListOptSuccess;
-
- Optional<AAIObjectAuditList> auditListOptFailure;
-
- @Before
- public void setup() throws JsonParseException, JsonMappingException, IOException {
- auditInventory.setCloudOwner("cloudOwner");
- auditInventory.setCloudRegion("cloudRegion");
- auditInventory.setTenantId("tenantId");
- auditInventory.setHeatStackName("stackName");
- MockitoAnnotations.initMocks(this);
-
- AAIObjectAuditList auditListSuccess = objectMapper
- .readValue(new File("src/test/resources/ExpectedVServerFound.json"), AAIObjectAuditList.class);
- auditListOptSuccess = Optional.of(auditListSuccess);
-
- AAIObjectAuditList auditListFailure = objectMapper.readValue(
- new File("src/test/resources/Vserver2_Found_VServer1_Not_Found.json"), AAIObjectAuditList.class);
- auditListOptFailure = Optional.of(auditListFailure);
- String[] retrySequence = new String[8];
- retrySequence[0] = "1";
- retrySequence[1] = "1";
- retrySequence[2] = "2";
- retrySequence[3] = "3";
- retrySequence[4] = "5";
- retrySequence[5] = "8";
- retrySequence[6] = "13";
- retrySequence[7] = "20";
- doReturn(auditInventory).when(mockExternalTask).getVariable("auditInventory");
- doReturn("6000").when(mockEnv).getProperty("mso.workflow.topics.retryMultiplier", "6000");
- doReturn(retrySequence).when(mockEnv).getProperty("mso.workflow.topics.retrySequence", String[].class);
- doReturn("aasdfasdf").when(mockExternalTask).getId();
- }
-
- @Test
- public void execute_external_task_audit_success_Test() {
- doReturn(auditListOptSuccess).when(heatStackAuditMock).auditHeatStack("cloudRegion", "cloudOwner", "tenantId",
- "stackName");
- auditStackService.executeExternalTask(mockExternalTask, mockExternalTaskService);
- ArgumentCaptor<Map> captor = ArgumentCaptor.forClass(Map.class);
- ArgumentCaptor<ExternalTask> taskCaptor = ArgumentCaptor.forClass(ExternalTask.class);
- Mockito.verify(mockExternalTaskService).complete(taskCaptor.capture(), captor.capture());
- Map actualMap = captor.getValue();
- assertEquals(true, actualMap.get("auditIsSuccessful"));
- assertNotNull(actualMap.get("auditInventoryResult"));
- }
-
- @Test
- public void executeExternalTaskQueryAuditTest() throws JsonProcessingException {
- doReturn(auditListOptSuccess).when(heatStackAuditMock).queryHeatStack("cloudOwner", "cloudRegion", "tenantId",
- "stackName");
- Mockito.doNothing().when(auditDataService).writeStackDataToRequestDb(Mockito.any(AuditInventory.class),
- Mockito.any(AAIObjectAuditList.class));
- auditQueryStackService.executeExternalTask(mockExternalTask, mockExternalTaskService);
- ArgumentCaptor<Map> captor = ArgumentCaptor.forClass(Map.class);
- ArgumentCaptor<ExternalTask> taskCaptor = ArgumentCaptor.forClass(ExternalTask.class);
- Mockito.verify(mockExternalTaskService).complete(taskCaptor.capture(), captor.capture());
- Mockito.verify(auditDataService).writeStackDataToRequestDb(Mockito.any(AuditInventory.class),
- Mockito.any(AAIObjectAuditList.class));
- }
-
- @Test
- public void execute_external_task_audit_first_failure_Test() {
- doReturn(auditListOptFailure).when(heatStackAuditMock).auditHeatStack("cloudRegion", "cloudOwner", "tenantId",
- "stackName");
- doReturn(null).when(mockExternalTask).getRetries();
- auditStackService.executeExternalTask(mockExternalTask, mockExternalTaskService);
- Mockito.verify(mockExternalTaskService).handleFailure(mockExternalTask,
- "Unable to find all VServers and L-Interaces in A&AI",
- "Unable to find all VServers and L-Interaces in A&AI", 8, 10000L);
- }
-
- @Test
- public void execute_external_task_audit_intermediate_failure_Test() {
- doReturn(auditListOptFailure).when(heatStackAuditMock).auditHeatStack("cloudRegion", "cloudOwner", "tenantId",
- "stackName");
- doReturn(6).when(mockExternalTask).getRetries();
- auditStackService.executeExternalTask(mockExternalTask, mockExternalTaskService);
- Mockito.verify(mockExternalTaskService).handleFailure(mockExternalTask,
- "Unable to find all VServers and L-Interaces in A&AI",
- "Unable to find all VServers and L-Interaces in A&AI", 5, 12000L);
-
- }
-
- @Test
- public void execute_external_task_audit_final_failure_Test() {
- doReturn(auditListOptFailure).when(heatStackAuditMock).auditHeatStack("cloudRegion", "cloudOwner", "tenantId",
- "stackName");
- doReturn(1).when(mockExternalTask).getRetries();
- auditStackService.executeExternalTask(mockExternalTask, mockExternalTaskService);
- ArgumentCaptor<Map> captor = ArgumentCaptor.forClass(Map.class);
- ArgumentCaptor<ExternalTask> taskCaptor = ArgumentCaptor.forClass(ExternalTask.class);
- Mockito.verify(mockExternalTaskService).complete(taskCaptor.capture(), captor.capture());
- Map actualMap = captor.getValue();
- assertEquals(false, actualMap.get("auditIsSuccessful"));
- assertNotNull(actualMap.get("auditInventoryResult"));
- }
-
- @Test
- public void determineAuditResult_Test() throws Exception {
- boolean actual = auditStackService.didCreateAuditFail(auditListOptSuccess.get());
- assertEquals(false, actual);
- }
-
- @Test
- public void determineAuditResult_Failure_Test() throws Exception {
- boolean actual = auditStackService.didCreateAuditFail(auditListOptFailure.get());
- assertEquals(true, actual);
- }
-}
diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/audit/AuditVServerTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/audit/AuditVServerTest.java
deleted file mode 100644
index 2e496c50cd..0000000000
--- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/audit/AuditVServerTest.java
+++ /dev/null
@@ -1,444 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP - SO
- * ================================================================================
- * 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 perservice2sions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.so.adapters.tasks.audit;
-
-import static org.junit.Assert.assertEquals;
-import static org.mockito.Mockito.doReturn;
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Paths;
-import java.util.HashSet;
-import java.util.Optional;
-import java.util.Set;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.InjectMocks;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.junit.MockitoJUnitRunner;
-import org.onap.aai.domain.yang.LInterface;
-import org.onap.aai.domain.yang.LInterfaces;
-import org.onap.aai.domain.yang.VfModule;
-import org.onap.aai.domain.yang.VfModules;
-import org.onap.aai.domain.yang.Vserver;
-import org.onap.aaiclient.client.aai.AAIObjectType;
-import org.onap.aaiclient.client.aai.AAIResourcesClient;
-import org.onap.aaiclient.client.aai.entities.AAIResultWrapper;
-import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri;
-import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory;
-import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder;
-import org.onap.so.objects.audit.AAIObjectAudit;
-import org.onap.so.objects.audit.AAIObjectAuditList;
-import org.skyscreamer.jsonassert.JSONAssert;
-import com.fasterxml.jackson.annotation.JsonInclude.Include;
-import com.fasterxml.jackson.core.JsonParseException;
-import com.fasterxml.jackson.databind.JsonMappingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-
-@RunWith(MockitoJUnitRunner.Silent.class)
-public class AuditVServerTest extends AuditVServer {
-
- private ObjectMapper objectMapper = new ObjectMapper();
-
- @InjectMocks
- private AuditVServer auditNova = new AuditVServer();
-
- @Mock
- private AAIResourcesClient aaiResourcesMock;
-
- private String cloudOwner = "cloudOwner";
- private String cloudRegion = "cloudRegion";
- private String tenantId = "tenantId";
-
- private AAIResourceUri vserverURI = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure()
- .cloudRegion(cloudOwner, cloudRegion).tenant(tenantId).vserver("3a4c2ca5-27b3-4ecc-98c5-06804867c4db"));
-
- private AAIResourceUri vserverURI2 = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure()
- .cloudRegion(cloudOwner, cloudRegion).tenant(tenantId).vserver("3a4c2ca5-27b3-4ecc-98c5-06804867c4dz"));
-
- private AAIResourceUri ssc_1_trusted_port_0_uri = AAIUriFactory.createResourceUri(
- AAIFluentTypeBuilder.cloudInfrastructure().cloudRegion(cloudOwner, cloudRegion).tenant(tenantId)
- .vserver("3a4c2ca5-27b3-4ecc-98c5-06804867c4db").lInterface("ssc_1_trusted_port_0"));
-
- private AAIResourceUri ssc_1_service1_port_0_uri = AAIUriFactory.createResourceUri(
- AAIFluentTypeBuilder.cloudInfrastructure().cloudRegion(cloudOwner, cloudRegion).tenant(tenantId)
- .vserver("3a4c2ca5-27b3-4ecc-98c5-06804867c4db").lInterface("ssc_1_service1_port_0"));
-
- private AAIResourceUri ssc_1_mgmt_port_1_uri = AAIUriFactory
- .createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure().cloudRegion(cloudOwner, cloudRegion)
- .tenant(tenantId).vserver("3a4c2ca5-27b3-4ecc-98c5-06804867c4db").lInterface("ssc_1_mgmt_port_1"));
-
- private AAIResourceUri ssc_1_mgmt_port_0_uri = AAIUriFactory
- .createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure().cloudRegion(cloudOwner, cloudRegion)
- .tenant(tenantId).vserver("3a4c2ca5-27b3-4ecc-98c5-06804867c4db").lInterface("ssc_1_mgmt_port_0"));
-
- private AAIResourceUri ssc_1_service2_port_0_uri = AAIUriFactory.createResourceUri(
- AAIFluentTypeBuilder.cloudInfrastructure().cloudRegion(cloudOwner, cloudRegion).tenant(tenantId)
- .vserver("3a4c2ca5-27b3-4ecc-98c5-06804867c4db").lInterface("ssc_1_service2_port_0"));
-
- private AAIResourceUri ssc_1_int_ha_port_0_uri = AAIUriFactory.createResourceUri(
- AAIFluentTypeBuilder.cloudInfrastructure().cloudRegion(cloudOwner, cloudRegion).tenant(tenantId)
- .vserver("3a4c2ca5-27b3-4ecc-98c5-06804867c4db").lInterface("ssc_1_int_ha_port_0"));
-
- private AAIResourceUri test_port_1_uri = AAIUriFactory
- .createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure().cloudRegion(cloudOwner, cloudRegion)
- .tenant(tenantId).vserver("3a4c2ca5-27b3-4ecc-98c5-06804867c4dz").lInterface("test_port_1"));
-
- private AAIResourceUri test_port_2_uri = AAIUriFactory
- .createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure().cloudRegion(cloudOwner, cloudRegion)
- .tenant(tenantId).vserver("3a4c2ca5-27b3-4ecc-98c5-06804867c4dz").lInterface("test_port_2"));
-
- private AAIResourceUri service2_sub_1_uri =
- AAIUriFactory.createResourceUri(AAIObjectType.SUB_L_INTERFACE, cloudOwner, cloudRegion, tenantId,
- "3a4c2ca5-27b3-4ecc-98c5-06804867c4db", "ssc_1_service2_port_0", "service2_sub_interface_1");
-
- private AAIResourceUri service1_sub_0_uri =
- AAIUriFactory.createResourceUri(AAIObjectType.SUB_L_INTERFACE, cloudOwner, cloudRegion, tenantId,
- "3a4c2ca5-27b3-4ecc-98c5-06804867c4db", "ssc_1_service1_port_0", "service1_sub_interface_1");
-
- private AAIResourceUri service1_sub_1_uri =
- AAIUriFactory.createResourceUri(AAIObjectType.SUB_L_INTERFACE, cloudOwner, cloudRegion, tenantId,
- "3a4c2ca5-27b3-4ecc-98c5-06804867c4db", "ssc_1_service1_port_0", "service1_sub_interface_2");
-
-
-
- private Set<Vserver> vserversToAudit = new HashSet<>();
-
- LInterface test_port_1 = new LInterface();
- LInterface test_port_2 = new LInterface();
- LInterface ssc_1_int_ha_port_0 = new LInterface();
- LInterface service2_sub_interface_1 = new LInterface();
- LInterface ssc_1_service2_port_0 = new LInterface();
- LInterface ssc_1_mgmt_port_0 = new LInterface();
- LInterface ssc_1_mgmt_port_1 = new LInterface();
- LInterface service1_sub_interface_2 = new LInterface();
- LInterface service1_sub_interface_1 = new LInterface();
- LInterface ssc_1_service1_port_0 = new LInterface();
- LInterface ssc_1_trusted_port_0 = new LInterface();
-
-
-
- @Before
- public void setup() {
- objectMapper.setSerializationInclusion(Include.NON_NULL);
- auditNova.setAaiClient(aaiResourcesMock);
-
- Vserver vServer1 = new Vserver();
- vServer1.setVserverId("3a4c2ca5-27b3-4ecc-98c5-06804867c4db");
- LInterfaces vServer1Linterfaces = new LInterfaces();
- vServer1.setLInterfaces(vServer1Linterfaces);
-
- ssc_1_trusted_port_0.setInterfaceId("dec8bdc7-5718-41dc-bfbb-561ff6eeb81c");
- ssc_1_trusted_port_0.setInterfaceName("ssc_1_trusted_port_0");
- vServer1.getLInterfaces().getLInterface().add(ssc_1_trusted_port_0);
-
-
- ssc_1_service1_port_0.setInterfaceId("1c56a24b-5f03-435a-850d-31cd4252de56");
- ssc_1_service1_port_0.setInterfaceName("ssc_1_service1_port_0");
- vServer1.getLInterfaces().getLInterface().add(ssc_1_service1_port_0);
- ssc_1_service1_port_0.setLInterfaces(new LInterfaces());
-
-
- service1_sub_interface_1.setInterfaceId("0d9cd813-2ae1-46c0-9ebb-48081f6cffbb");
- service1_sub_interface_1.setInterfaceName("service1_sub_interface_1");
- ssc_1_service1_port_0.getLInterfaces().getLInterface().add(service1_sub_interface_1);
-
-
- service1_sub_interface_2.setInterfaceId("b7019dd0-2ee9-4447-bdef-ac25676b205a");
- service1_sub_interface_2.setInterfaceName("service1_sub_interface_2");
- ssc_1_service1_port_0.getLInterfaces().getLInterface().add(service1_sub_interface_2);
-
-
- ssc_1_mgmt_port_1.setInterfaceId("12afcd28-929f-4d80-8a5a-0833bfd5e20b");
- ssc_1_mgmt_port_1.setInterfaceName("ssc_1_mgmt_port_1");
- vServer1.getLInterfaces().getLInterface().add(ssc_1_mgmt_port_1);
-
- ssc_1_mgmt_port_0.setInterfaceId("80baec42-ffae-425f-ad8c-3f7b2c24bfff");
- ssc_1_mgmt_port_0.setInterfaceName("ssc_1_mgmt_port_0");
- vServer1.getLInterfaces().getLInterface().add(ssc_1_mgmt_port_0);
-
-
- ssc_1_service2_port_0.setLInterfaces(new LInterfaces());
- ssc_1_service2_port_0.setInterfaceId("13eddf95-4cf3-45f2-823a-2d890a6549b4");
- ssc_1_service2_port_0.setInterfaceName("ssc_1_service2_port_0");
- vServer1.getLInterfaces().getLInterface().add(ssc_1_service2_port_0);
-
-
- service2_sub_interface_1.setInterfaceId("f711be16-2654-4a09-b89d-0511fda20e81");
- service2_sub_interface_1.setInterfaceName("service2_sub_interface_1");
- ssc_1_service2_port_0.getLInterfaces().getLInterface().add(service2_sub_interface_1);
-
-
- ssc_1_int_ha_port_0.setInterfaceId("9cab2903-70f7-44fd-b681-491d6ae2adb8");
- ssc_1_int_ha_port_0.setInterfaceName("ssc_1_int_ha_port_0");
- vServer1.getLInterfaces().getLInterface().add(ssc_1_int_ha_port_0);
-
- Vserver vServer2 = new Vserver();
- vServer2.setVserverId("3a4c2ca5-27b3-4ecc-98c5-06804867c4dz");
- LInterfaces vServer2Linterfaces = new LInterfaces();
- vServer2.setLInterfaces(vServer2Linterfaces);
-
- test_port_1.setInterfaceId("9cab2903-70f7-44fd-b681-491d6ae2adz1");
- test_port_1.setInterfaceName("test_port_1");
-
-
- test_port_2.setInterfaceId("9cab2903-70f7-44fd-b681-491d6ae2adz2");
- test_port_2.setInterfaceName("test_port_2");
-
- vServer2.getLInterfaces().getLInterface().add(test_port_1);
- vServer2.getLInterfaces().getLInterface().add(test_port_2);
-
- vserversToAudit.add(vServer1);
- vserversToAudit.add(vServer2);
- }
-
- @Test
- public void audit_Vserver_Empty_HashSet() throws JsonParseException, JsonMappingException, IOException {
- Optional<AAIObjectAuditList> actual =
- auditNova.auditVservers(new HashSet<Vserver>(), tenantId, cloudOwner, cloudRegion);
- assertEquals(Optional.empty(), actual);
- }
-
- @Test
- public void audit_Vserver_Found_Test() throws JsonParseException, JsonMappingException, IOException {
- doReturn(true).when(aaiResourcesMock).exists(vserverURI);
- doReturn(true).when(aaiResourcesMock).exists(vserverURI2);
- doReturn(Optional.of(ssc_1_trusted_port_0)).when(aaiResourcesMock).get(LInterface.class,
- ssc_1_trusted_port_0_uri);
- doReturn(Optional.of(ssc_1_service1_port_0)).when(aaiResourcesMock).get(LInterface.class,
- ssc_1_service1_port_0_uri);
- doReturn(Optional.of(ssc_1_mgmt_port_1)).when(aaiResourcesMock).get(LInterface.class, ssc_1_mgmt_port_1_uri);
- doReturn(Optional.of(ssc_1_mgmt_port_0)).when(aaiResourcesMock).get(LInterface.class, ssc_1_mgmt_port_0_uri);
- doReturn(Optional.of(ssc_1_service2_port_0)).when(aaiResourcesMock).get(LInterface.class,
- ssc_1_service2_port_0_uri);
- doReturn(Optional.of(service2_sub_interface_1)).when(aaiResourcesMock).get(LInterface.class,
- service1_sub_1_uri);
- doReturn(Optional.of(ssc_1_int_ha_port_0)).when(aaiResourcesMock).get(LInterface.class,
- ssc_1_int_ha_port_0_uri);
- doReturn(Optional.of(test_port_1)).when(aaiResourcesMock).get(LInterface.class, test_port_1_uri);
- doReturn(Optional.of(test_port_2)).when(aaiResourcesMock).get(LInterface.class, test_port_2_uri);
-
- doReturn(true).when(aaiResourcesMock).exists(service2_sub_1_uri);
- doReturn(true).when(aaiResourcesMock).exists(service1_sub_0_uri);
- doReturn(true).when(aaiResourcesMock).exists(service1_sub_1_uri);
-
- Optional<AAIObjectAuditList> actual =
- auditNova.auditVservers(vserversToAudit, tenantId, cloudOwner, cloudRegion);
- String actualString = objectMapper.writeValueAsString(actual.get());
- String expected = getJson("ExpectedVServerFound.json");
- JSONAssert.assertEquals(expected, actualString, false);
- }
-
- @Test
- public void audit_Vserver_Found_Test_Network_Not_Found()
- throws JsonParseException, JsonMappingException, IOException {
- doReturn(true).when(aaiResourcesMock).exists(vserverURI);
- doReturn(true).when(aaiResourcesMock).exists(vserverURI2);
- doReturn(Optional.of(ssc_1_trusted_port_0)).when(aaiResourcesMock).get(LInterface.class,
- ssc_1_trusted_port_0_uri);
- doReturn(Optional.of(ssc_1_service1_port_0)).when(aaiResourcesMock).get(LInterface.class,
- ssc_1_service1_port_0_uri);
- doReturn(Optional.of(ssc_1_mgmt_port_1)).when(aaiResourcesMock).get(LInterface.class, ssc_1_mgmt_port_1_uri);
- doReturn(Optional.empty()).when(aaiResourcesMock).get(LInterface.class, ssc_1_mgmt_port_0_uri);
- doReturn(Optional.of(ssc_1_service2_port_0)).when(aaiResourcesMock).get(LInterface.class,
- ssc_1_service2_port_0_uri);
- doReturn(Optional.of(ssc_1_int_ha_port_0)).when(aaiResourcesMock).get(LInterface.class,
- ssc_1_int_ha_port_0_uri);
- doReturn(Optional.of(test_port_1)).when(aaiResourcesMock).get(LInterface.class, test_port_1_uri);
- doReturn(Optional.of(test_port_2)).when(aaiResourcesMock).get(LInterface.class, test_port_2_uri);
-
- doReturn(true).when(aaiResourcesMock).exists(service2_sub_1_uri);
- doReturn(true).when(aaiResourcesMock).exists(service1_sub_0_uri);
- doReturn(true).when(aaiResourcesMock).exists(service1_sub_1_uri);
-
- Optional<AAIObjectAuditList> actual =
- auditNova.auditVservers(vserversToAudit, tenantId, cloudOwner, cloudRegion);
- String actualString = objectMapper.writeValueAsString(actual.get());
- String expected = getJson("VServer_Found_network_Not_Found.json");
- JSONAssert.assertEquals(expected, actualString, false);
- }
-
- @Test
- public void audit_Vserver_Found_Test_Network_Not_Found_Second_Server()
- throws JsonParseException, JsonMappingException, IOException {
- doReturn(true).when(aaiResourcesMock).exists(vserverURI);
- doReturn(true).when(aaiResourcesMock).exists(vserverURI2);
- doReturn(Optional.of(ssc_1_trusted_port_0)).when(aaiResourcesMock).get(LInterface.class,
- ssc_1_trusted_port_0_uri);
- doReturn(Optional.of(ssc_1_service1_port_0)).when(aaiResourcesMock).get(LInterface.class,
- ssc_1_service1_port_0_uri);
- doReturn(Optional.of(ssc_1_mgmt_port_1)).when(aaiResourcesMock).get(LInterface.class, ssc_1_mgmt_port_1_uri);
- doReturn(Optional.of(ssc_1_mgmt_port_0)).when(aaiResourcesMock).get(LInterface.class, ssc_1_mgmt_port_0_uri);
- doReturn(Optional.of(ssc_1_service2_port_0)).when(aaiResourcesMock).get(LInterface.class,
- ssc_1_service2_port_0_uri);
- doReturn(Optional.of(ssc_1_int_ha_port_0)).when(aaiResourcesMock).get(LInterface.class,
- ssc_1_int_ha_port_0_uri);
- doReturn(Optional.of(test_port_1)).when(aaiResourcesMock).get(LInterface.class, test_port_1_uri);
- doReturn(Optional.empty()).when(aaiResourcesMock).get(LInterface.class, test_port_2_uri);
- doReturn(true).when(aaiResourcesMock).exists(service2_sub_1_uri);
- doReturn(true).when(aaiResourcesMock).exists(service1_sub_0_uri);
- doReturn(true).when(aaiResourcesMock).exists(service1_sub_1_uri);
- Optional<AAIObjectAuditList> actual =
- auditNova.auditVservers(vserversToAudit, tenantId, cloudOwner, cloudRegion);
- String actualString = objectMapper.writeValueAsString(actual.get());
- String expected = getJson("VServer_Found_Network_Sec_Server_Not_Found.json");
- JSONAssert.assertEquals(expected, actualString, false);
- }
-
- @Test
- public void audit_Vserver_Not_Found_Test() throws JsonParseException, JsonMappingException, IOException {
- doReturn(false).when(aaiResourcesMock).exists(vserverURI);
- doReturn(false).when(aaiResourcesMock).exists(vserverURI2);
- Optional<AAIObjectAuditList> actual =
- auditNova.auditVservers(vserversToAudit, tenantId, cloudOwner, cloudRegion);
- String actualString = objectMapper.writeValueAsString(actual.get());
- String expected = getJson("Vservers_Not_Found.json");
- JSONAssert.assertEquals(expected, actualString, false);
- }
-
- @Test
- public void audit_Vserver_first_Not_Found_Test() throws JsonParseException, JsonMappingException, IOException {
- doReturn(false).when(aaiResourcesMock).exists(vserverURI);
- doReturn(true).when(aaiResourcesMock).exists(vserverURI2);
- doReturn(Optional.of(test_port_1)).when(aaiResourcesMock).get(LInterface.class, test_port_1_uri);
- doReturn(Optional.of(test_port_2)).when(aaiResourcesMock).get(LInterface.class, test_port_2_uri);
- Optional<AAIObjectAuditList> actual =
- auditNova.auditVservers(vserversToAudit, tenantId, cloudOwner, cloudRegion);
- String actualString = objectMapper.writeValueAsString(actual.get());
- String expected = getJson("Vserver2_Found_VServer1_Not_Found.json");
- JSONAssert.assertEquals(expected, actualString, false);
- }
-
-
- @Test
- public void doesSubInterfaceExistinAAI_Test() {
- AAIResourceUri subInterfaceURI = AAIUriFactory.createResourceUri(AAIObjectType.SUB_L_INTERFACE, cloudOwner,
- cloudRegion, tenantId, "vserverId", "l-interface", "sub-interface");
-
- assertEquals(
- "/cloud-infrastructure/cloud-regions/cloud-region/cloudOwner/cloudRegion/tenants/tenant/tenantId/vservers/vserver/vserverId/l-interfaces/l-interface/l-interface/l-interfaces/l-interface/sub-interface",
- subInterfaceURI.build().toString());
- }
-
- @Test
- public void audit_Vserver_Second_Not_Found_Test() throws JsonParseException, JsonMappingException, IOException {
- doReturn(true).when(aaiResourcesMock).exists(vserverURI);
- doReturn(Optional.of(ssc_1_trusted_port_0)).when(aaiResourcesMock).get(LInterface.class,
- ssc_1_trusted_port_0_uri);
- doReturn(Optional.of(ssc_1_service1_port_0)).when(aaiResourcesMock).get(LInterface.class,
- ssc_1_service1_port_0_uri);
- doReturn(Optional.of(ssc_1_mgmt_port_1)).when(aaiResourcesMock).get(LInterface.class, ssc_1_mgmt_port_1_uri);
- doReturn(Optional.of(ssc_1_mgmt_port_0)).when(aaiResourcesMock).get(LInterface.class, ssc_1_mgmt_port_0_uri);
- doReturn(Optional.of(ssc_1_service2_port_0)).when(aaiResourcesMock).get(LInterface.class,
- ssc_1_service2_port_0_uri);
- doReturn(Optional.of(ssc_1_int_ha_port_0)).when(aaiResourcesMock).get(LInterface.class,
- ssc_1_int_ha_port_0_uri);
- doReturn(Optional.empty()).when(aaiResourcesMock).get(LInterface.class, test_port_1_uri);
- doReturn(Optional.empty()).when(aaiResourcesMock).get(LInterface.class, test_port_2_uri);
- doReturn(true).when(aaiResourcesMock).exists(service2_sub_1_uri);
- doReturn(true).when(aaiResourcesMock).exists(service1_sub_0_uri);
- doReturn(true).when(aaiResourcesMock).exists(service1_sub_1_uri);
-
- doReturn(false).when(aaiResourcesMock).exists(vserverURI2);
- Optional<AAIObjectAuditList> actual =
- auditNova.auditVservers(vserversToAudit, tenantId, cloudOwner, cloudRegion);
- String actualString = objectMapper.writeValueAsString(actual.get());
- String expected = getJson("VServer_Found_Sec_Server_Not_Found2.json");
-
- JSONAssert.assertEquals(expected, actualString, false);
- }
-
- @Test
- public void testAuditVserversWithList() {
-
- AAIObjectAuditList auditList = new AAIObjectAuditList();
- AAIObjectAudit obj1 = new AAIObjectAudit();
- Vserver vserver = new Vserver();
- vserver.setVserverId("testVserverId");
- obj1.setAaiObject(vserver);
- obj1.setResourceURI(
- AAIUriFactory
- .createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure()
- .cloudRegion(cloudOwner, cloudRegion).tenant(tenantId).vserver("testVserverId"))
- .build());
- auditList.getAuditList().add(obj1);
-
- doReturn(false).when(aaiResourcesMock).exists(AAIUriFactory.createResourceUri(AAIFluentTypeBuilder
- .cloudInfrastructure().cloudRegion(cloudOwner, cloudRegion).tenant(tenantId).vserver("testVserverId")));
-
- auditNova.auditVservers(auditList);
-
- Mockito.verify(aaiResourcesMock).exists(AAIUriFactory.createResourceUri(AAIFluentTypeBuilder
- .cloudInfrastructure().cloudRegion(cloudOwner, cloudRegion).tenant(tenantId).vserver("testVserverId")));
-
- Assert.assertEquals(false, auditList.getAuditList().get(0).isDoesObjectExist());
- }
-
- @Test
- public void testAuditVserversThroughRelationships() {
-
- VfModule vfModule = new VfModule();
- vfModule.setVfModuleId("id");
-
- AAIResultWrapper wrapper = new AAIResultWrapper(vfModule);
-
- doReturn(Optional.of(wrapper)).when(aaiResourcesMock).getFirstWrapper(VfModules.class, VfModule.class,
- AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf("genericVnfId").vfModules())
- .queryParam("vf-module-name", "vfModuleName"));
-
- Optional<AAIObjectAuditList> auditList =
- auditNova.auditVserversThroughRelationships("genericVnfId", "vfModuleName");
-
- Assert.assertTrue(auditList.get().getAuditList().isEmpty());
- }
-
- @Test
- public void testAuditVserversThroughRelationships_exists() throws IOException {
-
- String vfModule = getJson("vfModule.json");
-
- AAIResultWrapper wrapper = new AAIResultWrapper(vfModule);
- AAIResultWrapper vserverWrapper = new AAIResultWrapper(new Vserver());
-
- doReturn(Optional.of(wrapper)).when(aaiResourcesMock).getFirstWrapper(VfModules.class, VfModule.class,
- AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf("genericVnfId").vfModules())
- .queryParam("vf-module-name", "vfModuleName"));
-
- doReturn(vserverWrapper).when(aaiResourcesMock)
- .get(AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure()
- .cloudRegion("cloud-owner", "cloud-region-id").tenant("tenant-id").vserver("VUSCHGA1")));
-
- Optional<AAIObjectAuditList> auditList =
- auditNova.auditVserversThroughRelationships("genericVnfId", "vfModuleName");
-
- Assert.assertFalse(auditList.get().getAuditList().isEmpty());
- }
-
-
- private String getJson(String filename) throws IOException {
- return new String(Files.readAllBytes(Paths.get("src/test/resources/" + filename)));
- }
-
-
-
-}
diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/audit/HeatStackAuditTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/audit/HeatStackAuditTest.java
deleted file mode 100644
index d1d0d96042..0000000000
--- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/audit/HeatStackAuditTest.java
+++ /dev/null
@@ -1,298 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP - SO
- * ================================================================================
- * 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.so.adapters.tasks.audit;
-
-import static com.shazam.shazamcrest.MatcherAssert.assertThat;
-import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
-import static org.junit.Assert.assertEquals;
-import static org.mockito.Mockito.doReturn;
-import java.io.File;
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Paths;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Optional;
-import java.util.Set;
-import java.util.stream.Collectors;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.InjectMocks;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
-import org.onap.aai.domain.yang.LInterface;
-import org.onap.aai.domain.yang.LInterfaces;
-import org.onap.aai.domain.yang.Vserver;
-import org.onap.so.adapters.tasks.audit.AuditVServer;
-import org.onap.so.adapters.tasks.audit.HeatStackAudit;
-import org.onap.so.objects.audit.AAIObjectAuditList;
-import org.onap.so.openstack.utils.MsoHeatUtils;
-import org.onap.so.openstack.utils.MsoNeutronUtils;
-import org.skyscreamer.jsonassert.JSONAssert;
-import com.fasterxml.jackson.annotation.JsonInclude.Include;
-import com.fasterxml.jackson.databind.DeserializationFeature;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.woorea.openstack.heat.model.Resource;
-import com.woorea.openstack.heat.model.Resources;
-import com.woorea.openstack.heat.model.Stack;
-import com.woorea.openstack.quantum.model.Port;
-
-
-@RunWith(MockitoJUnitRunner.Silent.class)
-public class HeatStackAuditTest extends HeatStackAudit {
-
- @InjectMocks
- private HeatStackAudit heatStackAudit = new HeatStackAudit();
-
- @Mock
- private MsoHeatUtils msoHeatUtilsMock;
-
- @Mock
- private MsoNeutronUtils neutronUtilsMock;
-
- @Mock
- private AuditVServer auditVserver;
-
- private static final String cloudRegion = "cloudRegion";
- private static final String tenantId = "tenantId";
-
- private Resources resources = new Resources();
-
- private ObjectMapper objectMapper =
- new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
- .setSerializationInclusion(Include.NON_NULL);
-
- private ObjectMapper stackObjectMapper = new ObjectMapper()
- .configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true).setSerializationInclusion(Include.NON_NULL);
-
- private List<Optional<Port>> portList = new ArrayList<>();
-
- @Before
- public void setup() throws Exception {
- resources = objectMapper.readValue(new File("src/test/resources/GetResources.json"), Resources.class);
- Port neutronPort1 = stackObjectMapper.readValue(new File("src/test/resources/NeutronPort1.json"), Port.class);
- doReturn(Optional.of(neutronPort1)).when(neutronUtilsMock)
- .getNeutronPort("7ee06d9d-3d18-411c-9d3e-aec930f70413", cloudRegion, tenantId);
- Port neutronPort2 = stackObjectMapper.readValue(new File("src/test/resources/NeutronPort2.json"), Port.class);
- doReturn(Optional.of(neutronPort2)).when(neutronUtilsMock)
- .getNeutronPort("27391d94-33af-474a-927d-d409249e8fd3", cloudRegion, tenantId);
- Port neutronPort3 = stackObjectMapper.readValue(new File("src/test/resources/NeutronPort3.json"), Port.class);
- doReturn(Optional.of(neutronPort3)).when(neutronUtilsMock)
- .getNeutronPort("fdeedf37-c01e-4ab0-bdd6-8d5fc4913943", cloudRegion, tenantId);
- Port neutronPort4 = stackObjectMapper.readValue(new File("src/test/resources/NeutronPort4.json"), Port.class);
- doReturn(Optional.of(neutronPort4)).when(neutronUtilsMock)
- .getNeutronPort("8d93f63e-e972-48c7-ad98-b2122da47315", cloudRegion, tenantId);
- Port neutronPort5 = stackObjectMapper.readValue(new File("src/test/resources/NeutronPort5.json"), Port.class);
- doReturn(Optional.of(neutronPort5)).when(neutronUtilsMock)
- .getNeutronPort("0594a2f2-7ea4-42eb-abc2-48ea49677fca", cloudRegion, tenantId);
- Port neutronPort6 = stackObjectMapper.readValue(new File("src/test/resources/NeutronPort6.json"), Port.class);
- doReturn(Optional.of(neutronPort6)).when(neutronUtilsMock)
- .getNeutronPort("00bb8407-650e-48b5-b919-33b88d6f8fe3", cloudRegion, tenantId);
-
-
- portList.add(Optional.empty());
- portList.add(Optional.of(neutronPort1));
- portList.add(Optional.of(neutronPort2));
- portList.add(Optional.of(neutronPort3));
- portList.add(Optional.of(neutronPort4));
- portList.add(Optional.of(neutronPort5));
- portList.add(Optional.of(neutronPort6));
- }
-
- @Test
- public void extract_proper_path_Test() {
- Optional<String> actualResult = extractStackPathFromHref(
- "https://orchestration.com:8004/v1/stacks/test_stack/f711be16-2654-4a09-b89d-0511fda20e81");
- assertEquals("/stacks/test_stack/f711be16-2654-4a09-b89d-0511fda20e81", actualResult.get());
- }
-
- @Test
- public void extract_proper_resources_path_Test() {
- Optional<String> actualResult = extractResourcePathFromHref(
- "https://orchestration.com:8004/v1/stacks/test_stack/f711be16-2654-4a09-b89d-0511fda20e81");
- assertEquals("/stacks/test_stack/f711be16-2654-4a09-b89d-0511fda20e81/resources", actualResult.get());
- }
-
- @Test
- public void extract_invalid_uri_Test() {
- Optional<String> actualResult = extractStackPathFromHref(
- "orchestrn.com:8004/v18b44d60a6f94bdcb2738f9e//stacks/test_stack/f711be16-2654-4a09-b89d-0511fda20e81");
- assertEquals(false, actualResult.isPresent());
- }
-
- @Test
- public void createVserverSet_Test() throws Exception {
- List<Resource> novaResources = resources.getList().stream().filter(p -> "OS::Nova::Server".equals(p.getType()))
- .collect(Collectors.toList());
-
- List<Resource> resourceGroups = resources.getList().stream()
- .filter(p -> "OS::Heat::ResourceGroup".equals(p.getType())).collect(Collectors.toList());
-
- Resources service1QueryResponse = objectMapper
- .readValue(new File("src/test/resources/Service1ResourceGroupResponse.json"), Resources.class);
- doReturn(service1QueryResponse).when(msoHeatUtilsMock).executeHeatClientRequest(
- "/stacks/tsbc0005vm002ssc001-ssc_1_subint_service1_port_0_subinterfaces-dtmxjmny7yjz/31d0647a-6043-49a4-81b6-ccab29380672/resources",
- cloudRegion, tenantId, Resources.class);
-
- Resources service2QueryResponse = objectMapper
- .readValue(new File("src/test/resources/Service2ResourceGroupResponse.json"), Resources.class);
- doReturn(service2QueryResponse).when(msoHeatUtilsMock).executeHeatClientRequest(
- "/stacks/tsbc0005vm002ssc001-ssc_1_subint_service2_port_0_subinterfaces-hlzdigtimzst/447a9b41-714e-434b-b1d0-6cce8d9f0f0c/resources",
- cloudRegion, tenantId, Resources.class);
-
-
- Stack service2StackQuerySubInt =
- stackObjectMapper.readValue(new File("src/test/resources/Service2SubInterface0.json"), Stack.class);
- doReturn(service2StackQuerySubInt).when(msoHeatUtilsMock).executeHeatClientRequest(
- "/stacks/tsbc0005vm002ssc001-ssc_1_subint_service2_port_0_subinterfaces-hlzdigtimzst-0-upfi5nhurk7y/f711be16-2654-4a09-b89d-0511fda20e81",
- cloudRegion, tenantId, Stack.class);
- Resources service2ResourceQuerySubInt = objectMapper
- .readValue(new File("src/test/resources/Service2SubInterface1Resources.json"), Resources.class);
- doReturn(service2ResourceQuerySubInt).when(msoHeatUtilsMock).executeHeatClientRequest(
- "/stacks/tsbc0005vm002ssc001-ssc_1_subint_service2_port_0_subinterfaces-hlzdigtimzst-0-upfi5nhurk7y/f711be16-2654-4a09-b89d-0511fda20e81/resources",
- cloudRegion, tenantId, Resources.class);
-
- Stack service1StackQuerySubInt1 =
- stackObjectMapper.readValue(new File("src/test/resources/Service1SubInterface0.json"), Stack.class);
- doReturn(service1StackQuerySubInt1).when(msoHeatUtilsMock).executeHeatClientRequest(
- "/stacks/tsbc0005vm002ssc001-ssc_1_subint_service1_port_0_subinterfaces-dtmxjmny7yjz-1-fmn5laetg5cs/0d9cd813-2ae1-46c0-9ebb-48081f6cffbb",
- cloudRegion, tenantId, Stack.class);
- Resources service1ResourceQuerySubInt1 = objectMapper
- .readValue(new File("src/test/resources/Service1SubInterface0Resources.json"), Resources.class);
- doReturn(service1ResourceQuerySubInt1).when(msoHeatUtilsMock).executeHeatClientRequest(
- "/stacks/tsbc0005vm002ssc001-ssc_1_subint_service1_port_0_subinterfaces-dtmxjmny7yjz-1-fmn5laetg5cs/0d9cd813-2ae1-46c0-9ebb-48081f6cffbb/resources",
- cloudRegion, tenantId, Resources.class);
-
-
- Stack service1StackQuerySubInt2 =
- stackObjectMapper.readValue(new File("src/test/resources/Service1SubInterface1.json"), Stack.class);
- doReturn(service1StackQuerySubInt2).when(msoHeatUtilsMock).executeHeatClientRequest(
- "/stacks/tsbc0005vm002ssc001-ssc_1_subint_service1_port_0_subinterfaces-dtmxjmny7yjz-0-yghihziaf36m/b7019dd0-2ee9-4447-bdef-ac25676b205a",
- cloudRegion, tenantId, Stack.class);
- Resources service1ResourceQuerySubInt2 = objectMapper
- .readValue(new File("src/test/resources/Service1SubInterface1Resources.json"), Resources.class);
- doReturn(service1ResourceQuerySubInt2).when(msoHeatUtilsMock).executeHeatClientRequest(
- "/stacks/tsbc0005vm002ssc001-ssc_1_subint_service1_port_0_subinterfaces-dtmxjmny7yjz-0-yghihziaf36m/b7019dd0-2ee9-4447-bdef-ac25676b205a/resources",
- cloudRegion, tenantId, Resources.class);
-
- Stack service1StackQuerySubInt3 =
- stackObjectMapper.readValue(new File("src/test/resources/Service1SubInterface2.json"), Stack.class);
- doReturn(service1StackQuerySubInt3).when(msoHeatUtilsMock).executeHeatClientRequest(
- "/stacks/tsbc0005vm002ssc001-ssc_1_subint_service1_port_0_subinterfaces-dtmxjmny7yjz-2-y3ndsavmsymv/bd0fc728-cbde-4301-a581-db56f494675c",
- cloudRegion, tenantId, Stack.class);
- Resources service1ResourceQuerySubInt3 = objectMapper
- .readValue(new File("src/test/resources/Service1SubInterface2Resources.json"), Resources.class);
- doReturn(service1ResourceQuerySubInt3).when(msoHeatUtilsMock).executeHeatClientRequest(
- "/stacks/tsbc0005vm002ssc001-ssc_1_subint_service1_port_0_subinterfaces-dtmxjmny7yjz-2-y3ndsavmsymv/bd0fc728-cbde-4301-a581-db56f494675c/resources",
- cloudRegion, tenantId, Resources.class);
-
- Set<Vserver> vServersToAudit = heatStackAudit.createVserverSet(resources, novaResources, portList);
- Set<Vserver> vserversWithSubInterfaces =
- heatStackAudit.processSubInterfaces(cloudRegion, tenantId, resourceGroups, vServersToAudit);
-
- String actualValue = objectMapper.writeValueAsString(vserversWithSubInterfaces);
- String expectedValue = getJson("ExpectedVserversToAudit.json");
- JSONAssert.assertEquals(expectedValue, actualValue, false);
- }
-
- @Test
- public void auditHeatStackNoServers_Test() throws Exception {
- Resources getResource = objectMapper
- .readValue(new File("src/test/resources/Service1ResourceGroupResponse.json"), Resources.class);
- doReturn(getResource).when(msoHeatUtilsMock).queryStackResources(cloudRegion, tenantId, "heatStackName", 3);
-
- Optional<AAIObjectAuditList> actual =
- heatStackAudit.auditHeatStack(cloudRegion, "cloudOwner", tenantId, "heatStackName");
- assertEquals(true, actual.get().getAuditList().isEmpty());
- }
-
- @Test
- public void auditHeatStackNestedServers_Test() throws Exception {
- Resources getResource =
- objectMapper.readValue(new File("src/test/resources/GetNestedResources.json"), Resources.class);
- List<Resource> novaResources = getResource.getList().stream()
- .filter(p -> "OS::Nova::Server".equals(p.getType())).collect(Collectors.toList());
- List<Resource> resourceGroups = getResource.getList().stream()
- .filter(p -> "OS::Heat::ResourceGroup".equals(p.getType())).collect(Collectors.toList());
-
- doReturn(getResource).when(msoHeatUtilsMock).queryStackResources(cloudRegion, tenantId, "heatStackName", 3);
- Set<Vserver> vServersToAudit = heatStackAudit.createVserverSet(resources, novaResources, portList);
- Set<Vserver> vserversWithSubInterfaces =
- heatStackAudit.processSubInterfaces(cloudRegion, tenantId, resourceGroups, vServersToAudit);
- String actualValue = objectMapper.writeValueAsString(vserversWithSubInterfaces);
- String expectedValue = getJson("NestedExpectedValue.json");
- JSONAssert.assertEquals(expectedValue, actualValue, false);
- }
-
-
- @Test
- public void findInterfaceInformation_Test() {
- List<Resource> novaResources = resources.getList().stream().filter(p -> "OS::Nova::Server".equals(p.getType()))
- .collect(Collectors.toList());
- Set<Vserver> expectedVservers = new HashSet<>();
- Vserver vServer1 = new Vserver();
- vServer1.setVserverId("92272b67-d23f-42ca-87fa-7b06a9ec81f3");
- LInterfaces vServer1Linterfaces = new LInterfaces();
- vServer1.setLInterfaces(vServer1Linterfaces);
-
- LInterface ssc_1_trusted_port_0 = new LInterface();
- ssc_1_trusted_port_0.setInterfaceId("7ee06d9d-3d18-411c-9d3e-aec930f70413");
- ssc_1_trusted_port_0.setInterfaceName("ibcx0026v_ibcx0026vm003_untrusted_port");
- vServer1.getLInterfaces().getLInterface().add(ssc_1_trusted_port_0);
-
- LInterface ssc_1_svc2_port_0 = new LInterface();
- ssc_1_svc2_port_0.setInterfaceId("27391d94-33af-474a-927d-d409249e8fd3");
- ssc_1_svc2_port_0.setInterfaceName("ibcx0026v_ibcx0026vm003_untrusted_port");
- vServer1.getLInterfaces().getLInterface().add(ssc_1_svc2_port_0);
-
- LInterface ssc_1_mgmt_port_1 = new LInterface();
- ssc_1_mgmt_port_1.setInterfaceId("fdeedf37-c01e-4ab0-bdd6-8d5fc4913943");
- ssc_1_mgmt_port_1.setInterfaceName("ibcx0026v_ibcx0026vm003_untrusted_port");
- vServer1.getLInterfaces().getLInterface().add(ssc_1_mgmt_port_1);
-
- LInterface ssc_1_mgmt_port_0 = new LInterface();
- ssc_1_mgmt_port_0.setInterfaceId("8d93f63e-e972-48c7-ad98-b2122da47315");
- ssc_1_mgmt_port_0.setInterfaceName("ibcx0026v_ibcx0026vm003_untrusted_port");
- vServer1.getLInterfaces().getLInterface().add(ssc_1_mgmt_port_0);
-
- LInterface ssc_1_svc1_port_0 = new LInterface();
- ssc_1_svc1_port_0.setInterfaceId("0594a2f2-7ea4-42eb-abc2-48ea49677fca");
- ssc_1_svc1_port_0.setInterfaceName("ibcx0026v_ibcx0026vm003_untrusted_port");
- vServer1.getLInterfaces().getLInterface().add(ssc_1_svc1_port_0);
-
- LInterface ssc_1_int_ha_port_0 = new LInterface();
- ssc_1_int_ha_port_0.setInterfaceId("00bb8407-650e-48b5-b919-33b88d6f8fe3");
- ssc_1_int_ha_port_0.setInterfaceName("ibcx0026v_ibcx0026vm003_untrusted_port");
- vServer1.getLInterfaces().getLInterface().add(ssc_1_int_ha_port_0);
-
- expectedVservers.add(vServer1);
-
- Set<Vserver> actualVservers = heatStackAudit.createVserverSet(resources, novaResources, portList);
-
- assertThat(actualVservers, sameBeanAs(expectedVservers));
- }
-
- private String getJson(String filename) throws IOException {
- return new String(Files.readAllBytes(Paths.get("src/test/resources/" + filename)));
- }
-}
diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/heatbridge/HeatBridgeImplTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/heatbridge/HeatBridgeImplTest.java
index ebc7c3a81e..7912bceede 100644
--- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/heatbridge/HeatBridgeImplTest.java
+++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/heatbridge/HeatBridgeImplTest.java
@@ -215,7 +215,7 @@ public class HeatBridgeImplTest {
// Assert
ArgumentCaptor<AAIResourceUri> captor = ArgumentCaptor.forClass(AAIResourceUri.class);
- verify(transaction, times(2)).createIfNotExists(captor.capture(), any(Optional.class));
+ verify(transaction, times(2)).create(captor.capture(), any());
List<AAIResourceUri> uris = captor.getAllValues();
assertEquals(AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure()
@@ -259,7 +259,7 @@ public class HeatBridgeImplTest {
// Assert
ArgumentCaptor<AAIResourceUri> captor = ArgumentCaptor.forClass(AAIResourceUri.class);
- verify(transaction, times(2)).createIfNotExists(captor.capture(), any(Optional.class));
+ verify(transaction, times(2)).create(captor.capture(), any());
List<AAIResourceUri> uris = captor.getAllValues();
assertEquals(AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure()
@@ -297,15 +297,15 @@ public class HeatBridgeImplTest {
org.onap.aai.domain.yang.RelationshipList relList = aaiHelper.getVserverRelationshipList(CLOUD_OWNER, REGION_ID,
"test-genericVnf-id", "test-vfModule-id", server1);
- assertEquals(4, relList.getRelationship().size());
+ assertEquals(3, relList.getRelationship().size());
org.onap.aai.domain.yang.RelationshipList relList2 = aaiHelper.getVserverRelationshipList(CLOUD_OWNER,
REGION_ID, "test-genericVnf-id", "test-vfModule-id", server2);
- assertEquals(3, relList2.getRelationship().size());
+ assertEquals(2, relList2.getRelationship().size());
org.onap.aai.domain.yang.RelationshipList relList3 = aaiHelper.getVserverRelationshipList(CLOUD_OWNER,
REGION_ID, "test-genericVnf-id", "test-vfModule-id", server3);
- assertEquals(3, relList3.getRelationship().size());
+ assertEquals(2, relList3.getRelationship().size());
}
@@ -539,7 +539,7 @@ public class HeatBridgeImplTest {
when(resourcesClient.get(eq(PInterface.class), any(AAIResourceUri.class))).thenReturn(Optional.of(pIf));
// Act
- heatbridge.updateLInterfaceVlan(port, lIf, "hostname");
+ heatbridge.createVlanAndSriovVF(port, lIf, "hostname");
// Assert
verify(transaction, times(2)).createIfNotExists(any(AAIResourceUri.class), any(Optional.class));
@@ -625,7 +625,7 @@ public class HeatBridgeImplTest {
PInterface pIf = mock(PInterface.class);
when(pIf.getInterfaceName()).thenReturn("test-port-id");
- doNothing().when(heatbridge).updateSriovPfToPserver(any(), any());
+ doNothing().when(heatbridge).updateSriovPfToSriovVF(any(), any());
// Act
heatbridge.buildAddVserverLInterfacesToAaiAction(stackResources, Arrays.asList("1", "2"), "CloudOwner");