summaryrefslogtreecommitdiffstats
path: root/adapters/mso-openstack-adapters/src
diff options
context:
space:
mode:
Diffstat (limited to 'adapters/mso-openstack-adapters/src')
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AbstractAuditService.java15
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditCreateStackService.java5
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditDataService.java77
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditDeleteStackService.java37
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditQueryStackService.java71
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditStackService.java13
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditVServer.java34
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/HeatStackAudit.java52
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/inventory/create/CreateInventoryTask.java16
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/network/MsoNetworkAdapterImpl.java26
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfAdapterImpl.java6
-rw-r--r--adapters/mso-openstack-adapters/src/main/resources/application-local.yaml105
-rw-r--r--adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditDataServiceTest.java101
-rw-r--r--adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditStackServiceDataTest.java25
-rw-r--r--adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditVServerTest.java73
-rw-r--r--adapters/mso-openstack-adapters/src/test/resources/vfModule.json38
16 files changed, 552 insertions, 142 deletions
diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AbstractAuditService.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AbstractAuditService.java
index 5060e554eb..8edce124ec 100644
--- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AbstractAuditService.java
+++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AbstractAuditService.java
@@ -43,6 +43,8 @@ public abstract class AbstractAuditService {
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;
@@ -68,12 +70,12 @@ public abstract class AbstractAuditService {
* @param auditList
* @return
*/
- protected boolean didDeleteAuditFail(Optional<AAIObjectAuditList> auditList) {
- if (auditList.get().getAuditList() != null && !auditList.get().getAuditList().isEmpty()) {
+ protected boolean didDeleteAuditFail(AAIObjectAuditList auditList) {
+ if (auditList.getAuditList() != null && !auditList.getAuditList().isEmpty()) {
if (logger.isInfoEnabled()) {
- logger.info("Audit Results: {}", auditList.get().toString());
+ logger.info("Audit Results: {}", auditList.toString());
}
- return auditList.get().getAuditList().stream().filter(AAIObjectAudit::isDoesObjectExist).findFirst()
+ return auditList.getAuditList().stream().filter(AAIObjectAudit::isDoesObjectExist).findFirst()
.map(v -> true).orElse(false);
} else {
return false;
@@ -85,9 +87,12 @@ public abstract class AbstractAuditService {
}
protected void setupMDC(ExternalTask externalTask) {
+ logger.info(ONAPLogConstants.Markers.ENTRY, "Entering");
String msoRequestId = externalTask.getVariable("mso-request-id");
- if (msoRequestId != null && !msoRequestId.isEmpty())
+ if (msoRequestId != null && !msoRequestId.isEmpty()) {
MDC.put(ONAPLogConstants.MDCs.REQUEST_ID, msoRequestId);
+ }
+ MDC.put(ONAPLogConstants.MDCs.SERVICE_NAME, externalTask.getTopicName());
}
protected long calculateRetryDelay(int currentRetries) {
diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditCreateStackService.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditCreateStackService.java
index 77229919cd..1e5b6de857 100644
--- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditCreateStackService.java
+++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditCreateStackService.java
@@ -27,6 +27,7 @@ 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.client.graphinventory.GraphInventoryCommonObjectMapperProvider;
import org.onap.so.objects.audit.AAIObjectAuditList;
@@ -48,9 +49,9 @@ public class AuditCreateStackService extends AbstractAuditService {
public Environment environment;
protected void executeExternalTask(ExternalTask externalTask, ExternalTaskService externalTaskService) {
+ setupMDC(externalTask);
AuditInventory auditInventory = externalTask.getVariable("auditInventory");
Map<String, Object> variables = new HashMap<>();
- setupMDC(externalTask);
boolean success = false;
try {
logger.info("Executing External Task Audit Inventory, Retry Number: {} \n {}", auditInventory,
@@ -71,6 +72,7 @@ public class AuditCreateStackService extends AbstractAuditService {
if (success) {
externalTaskService.complete(externalTask, variables);
logger.debug("The External Task Id: {} Successful", externalTask.getId());
+ logger.info(ONAPLogConstants.Markers.EXIT, "Exiting");
} else {
if (externalTask.getRetries() == null) {
logger.debug("The External Task Id: {} Failed, Setting Retries to Default Start Value: {}",
@@ -80,6 +82,7 @@ public class AuditCreateStackService extends AbstractAuditService {
} else if (externalTask.getRetries() != null && externalTask.getRetries() - 1 == 0) {
logger.debug("The External Task Id: {} Failed, All Retries Exhausted", externalTask.getId());
externalTaskService.complete(externalTask, variables);
+ logger.info(ONAPLogConstants.Markers.EXIT, "Exiting");
} else {
logger.debug("The External Task Id: {} Failed, Decrementing Retries: {} , Retry Delay: ",
externalTask.getId(), externalTask.getRetries() - 1,
diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditDataService.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditDataService.java
new file mode 100644
index 0000000000..1c707fe795
--- /dev/null
+++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditDataService.java
@@ -0,0 +1,77 @@
+package org.onap.so.adapters.audit;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Optional;
+import org.onap.so.audit.beans.AuditInventory;
+import org.onap.so.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 {
+
+ @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(), "AuditStackData");
+ 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("AuditStackData");
+ 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 JsonParseException, JsonMappingException, IOException {
+
+ List<RequestProcessingData> requestProcessingDataList =
+ requestsDbClient.getRequestProcessingDataByGroupingIdAndNameAndTag(auditInventory.getVfModuleId(),
+ auditInventory.getHeatStackName(), "AuditStackData");
+ 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/audit/AuditDeleteStackService.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditDeleteStackService.java
index 9b245ba695..0aa4f9bdc3 100644
--- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditDeleteStackService.java
+++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditDeleteStackService.java
@@ -25,6 +25,7 @@ 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.client.graphinventory.GraphInventoryCommonObjectMapperProvider;
import org.onap.so.objects.audit.AAIObjectAuditList;
@@ -40,28 +41,38 @@ public class AuditDeleteStackService extends AbstractAuditService {
private static final Logger logger = LoggerFactory.getLogger(AuditDeleteStackService.class);
@Autowired
- public HeatStackAudit heatStackAudit;
+ protected HeatStackAudit heatStackAudit;
@Autowired
- public Environment environment;
+ protected AuditVServer auditVservers;
+
+ @Autowired
+ protected AuditDataService auditDataService;
+
+ @Autowired
+ protected Environment env;
protected void executeExternalTask(ExternalTask externalTask, ExternalTaskService externalTaskService) {
+ setupMDC(externalTask);
AuditInventory auditInventory = externalTask.getVariable("auditInventory");
Map<String, Object> variables = new HashMap<>();
- setupMDC(externalTask);
boolean success = false;
try {
- logger.info("Executing External Task Audit Inventory, Retry Number: {} \n {}", auditInventory,
- externalTask.getRetries());
- Optional<AAIObjectAuditList> auditListOpt = heatStackAudit.auditHeatStack(auditInventory.getCloudRegion(),
- auditInventory.getCloudOwner(), auditInventory.getTenantId(), auditInventory.getHeatStackName());
+ logger.info("Executing External Task Delete Audit Inventory. Retry Number: {}", externalTask.getRetries());
+ Optional<AAIObjectAuditList> auditListOpt = auditDataService.getStackDataFromRequestDb(auditInventory);
if (auditListOpt.isPresent()) {
- auditListOpt.get().setAuditType("delete");
- auditListOpt.get().setHeatStackName(auditInventory.getHeatStackName());
- GraphInventoryCommonObjectMapperProvider objectMapper = new GraphInventoryCommonObjectMapperProvider();
- variables.put("auditInventoryResult", objectMapper.getMapper().writeValueAsString(auditListOpt.get()));
- success = !didDeleteAuditFail(auditListOpt);
+ 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);
}
@@ -69,6 +80,7 @@ public class AuditDeleteStackService extends AbstractAuditService {
if (success) {
externalTaskService.complete(externalTask, variables);
logger.debug("The External Task Id: {} Successful", externalTask.getId());
+ logger.info(ONAPLogConstants.Markers.EXIT, "Exiting");
} else {
if (externalTask.getRetries() == null) {
logger.debug("The External Task Id: {} Failed, Setting Retries to Default Start Value: {}",
@@ -78,6 +90,7 @@ public class AuditDeleteStackService extends AbstractAuditService {
} else if (externalTask.getRetries() != null && externalTask.getRetries() - 1 == 0) {
logger.debug("The External Task Id: {} Failed, All Retries Exhausted", externalTask.getId());
externalTaskService.complete(externalTask, variables);
+ logger.info(ONAPLogConstants.Markers.EXIT, "Exiting");
} else {
logger.debug("The External Task Id: {} Failed, Decrementing Retries: {} , Retry Delay: ",
externalTask.getId(), externalTask.getRetries() - 1,
diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditQueryStackService.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditQueryStackService.java
new file mode 100644
index 0000000000..2ef7d5b325
--- /dev/null
+++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditQueryStackService.java
@@ -0,0 +1,71 @@
+package org.onap.so.adapters.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.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;
+
+ protected void executeExternalTask(ExternalTask externalTask, ExternalTaskService externalTaskService) {
+ setupMDC(externalTask);
+ AuditInventory auditInventory = externalTask.getVariable("auditInventory");
+ boolean success = false;
+ Map<String, Object> variables = new HashMap<>();
+ try {
+ logger.info("Executing External Task Query Audit Inventory. Audit Inventory: {} \n Retry Number: {}",
+ auditInventory.toString(), externalTask.getRetries());
+
+ Optional<AAIObjectAuditList> auditList = heatStackAudit.queryHeatStack(auditInventory.getCloudOwner(),
+ auditInventory.getCloudRegion(), auditInventory.getTenantId(), auditInventory.getHeatStackName());
+
+ if (auditList.isPresent()) {
+ success = true;
+ auditDataService.writeStackDataToRequestDb(auditInventory, auditList.get());
+ }
+ if (success) {
+ externalTaskService.complete(externalTask, variables);
+ logger.debug("The External Task {} was Successful", externalTask.getId());
+ logger.info(ONAPLogConstants.Markers.EXIT, "Exiting");
+ } else {
+ if (externalTask.getRetries() == null) {
+ logger.debug("The External Task {} Failed. Setting Retries to Default Start Value: {}",
+ externalTask.getId(), getRetrySequence().length);
+ externalTaskService.handleFailure(externalTask, UNABLE_TO_FIND_V_SERVERS_IN_OPENSTACK,
+ UNABLE_TO_FIND_V_SERVERS_IN_OPENSTACK, getRetrySequence().length, 10000);
+ } else if (externalTask.getRetries() != null && externalTask.getRetries() - 1 == 0) {
+ logger.debug("The External Task {} Failed. All Retries Exhausted", externalTask.getId());
+ externalTaskService.complete(externalTask, variables);
+ logger.info(ONAPLogConstants.Markers.EXIT, "Exiting");
+ } else {
+ logger.debug("The External Task {} Failed. Decrementing Retries to {} , Retry Delay: ",
+ externalTask.getId(), externalTask.getRetries() - 1,
+ calculateRetryDelay(externalTask.getRetries()));
+ externalTaskService.handleFailure(externalTask, UNABLE_TO_FIND_V_SERVERS_IN_OPENSTACK,
+ UNABLE_TO_FIND_V_SERVERS_IN_OPENSTACK, externalTask.getRetries() - 1,
+ calculateRetryDelay(externalTask.getRetries()));
+ }
+ logger.debug("The External Task {} Failed", externalTask.getId());
+ }
+ } 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/audit/AuditStackService.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditStackService.java
index 576acb1fd8..999d27335b 100644
--- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditStackService.java
+++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditStackService.java
@@ -49,6 +49,9 @@ public class AuditStackService {
@Autowired
private AuditDeleteStackService auditDeleteStack;
+ @Autowired
+ private AuditQueryStackService auditQueryStack;
+
@PostConstruct
public void auditAddAAIInventory() throws Exception {
for (int i = 0; i < getMaxClients(); i++) {
@@ -69,6 +72,16 @@ public class AuditStackService {
}
}
+ @PostConstruct
+ public void auditQueryInventory() throws Exception {
+ for (int i = 0; i < getMaxClients(); i++) {
+ ExternalTaskClient client = createExternalTaskClient();
+ client.subscribe("InventoryQueryAudit")
+ .lockDuration(Long.parseLong(env.getProperty("mso.audit.lock-time", "60000")))
+ .handler(auditQueryStack::executeExternalTask).open();
+ }
+ }
+
protected ExternalTaskClient createExternalTaskClient() throws Exception {
ClientRequestInterceptor interceptor = createClientRequestInterceptor();
ExternalTaskClient client = ExternalTaskClient.create()
diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditVServer.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditVServer.java
index e009c0e2fd..89e0320615 100644
--- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditVServer.java
+++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditVServer.java
@@ -20,10 +20,12 @@
package org.onap.so.adapters.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.Vserver;
+import org.onap.so.client.aai.AAIObjectPlurals;
import org.onap.so.client.aai.AAIObjectType;
import org.onap.so.client.aai.entities.uri.AAIResourceUri;
import org.onap.so.client.aai.entities.uri.AAIUriFactory;
@@ -40,6 +42,38 @@ import com.fasterxml.jackson.core.JsonProcessingException;
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(AAIObjectType.VSERVER, aaiObjectAudit.getResourceURI()));
+ aaiObjectAudit.setDoesObjectExist(vserverExist);
+ });
+ }
+
+ public Optional<AAIObjectAuditList> auditVserversThroughRelationships(String genericVnfId, String vfModuleName) {
+ AAIObjectAuditList auditList = new AAIObjectAuditList();
+ AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.VF_MODULE, genericVnfId)
+ .queryParam("vf-module-name", vfModuleName);
+ if (getAaiClient().get(uri).getRelationships().isPresent()) {
+ List<AAIResourceUri> relatedVservers =
+ getAaiClient().get(uri).getRelationships().get().getRelatedUris(AAIObjectType.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(AAIObjectType.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()) {
diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/HeatStackAudit.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/HeatStackAudit.java
index 2be87ff076..06fff19205 100644
--- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/HeatStackAudit.java
+++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/HeatStackAudit.java
@@ -35,11 +35,16 @@ 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.so.client.aai.AAIObjectType;
+import org.onap.so.client.aai.entities.uri.AAIResourceUri;
+import org.onap.so.client.aai.entities.uri.AAIUriFactory;
+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;
@@ -66,6 +71,28 @@ public class HeatStackAudit {
@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 {
@@ -215,6 +242,31 @@ public class HeatStackAudit {
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(AAIObjectType.VSERVER.typeName());
+ aaiObjectAudit.setResourceURI(AAIUriFactory
+ .createResourceUri(AAIObjectType.VSERVER, cloudOwner, cloudRegion, tenantId, 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
diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/inventory/create/CreateInventoryTask.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/inventory/create/CreateInventoryTask.java
index 74cf7c38c9..a6c61704ad 100644
--- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/inventory/create/CreateInventoryTask.java
+++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/inventory/create/CreateInventoryTask.java
@@ -3,6 +3,8 @@
* ONAP - SO
* ================================================================================
* Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ *
+ * 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.
@@ -39,6 +41,8 @@ public class CreateInventoryTask {
private static final Logger logger = LoggerFactory.getLogger(CreateInventoryTask.class);
+ private static final String AAI_INVENTORY_FAILURE = "AAIInventoryFailure";
+
@Autowired
CreateAAIInventory createInventory;
@@ -73,9 +77,10 @@ public class CreateInventoryTask {
if (success) {
externalTaskService.complete(externalTask);
logger.debug("The External Task Id: {} Successful", externalTask.getId());
+ logger.info(ONAPLogConstants.Markers.EXIT, "Exiting");
} else if (inventoryException) {
logger.debug("The External Task Id: {} Failed, Retry not needed", externalTask.getId());
- externalTaskService.handleBpmnError(externalTask, "AAIInventoryFailure");
+ externalTaskService.handleBpmnError(externalTask, AAI_INVENTORY_FAILURE);
} else {
if (externalTask.getRetries() == null) {
logger.debug("The External Task Id: {} Failed, Setting Retries to Default Start Value: {}",
@@ -84,7 +89,8 @@ public class CreateInventoryTask {
UNABLE_TO_WRITE_ALL_INVENTORY_TO_A_AI, getRetrySequence().length, 10000);
} else if (externalTask.getRetries() != null && externalTask.getRetries() - 1 == 0) {
logger.debug("The External Task Id: {} Failed, All Retries Exhausted", externalTask.getId());
- externalTaskService.handleBpmnError(externalTask, "AAIInventoryFailure");
+ externalTaskService.handleBpmnError(externalTask, AAI_INVENTORY_FAILURE);
+ logger.info(ONAPLogConstants.Markers.EXIT, "Exiting");
} else {
logger.debug("The External Task Id: {} Failed, Decrementing Retries: {} , Retry Delay: ",
externalTask.getId(), externalTask.getRetries() - 1,
@@ -97,13 +103,15 @@ public class CreateInventoryTask {
}
} else {
logger.debug("The External Task Id: {} Failed, No Audit Results Written", externalTask.getId());
- externalTaskService.handleBpmnError(externalTask, "AAIInventoryFailure");
+ externalTaskService.handleBpmnError(externalTask, AAI_INVENTORY_FAILURE);
}
}
private void setupMDC(ExternalTask externalTask) {
try {
- String msoRequestId = (String) externalTask.getVariable("mso-request-id");
+ logger.info(ONAPLogConstants.Markers.ENTRY, "Entering");
+ MDC.put(ONAPLogConstants.MDCs.SERVICE_NAME, externalTask.getTopicName());
+ String msoRequestId = externalTask.getVariable("mso-request-id");
if (msoRequestId != null && !msoRequestId.isEmpty())
MDC.put(ONAPLogConstants.MDCs.REQUEST_ID, msoRequestId);
} catch (Exception e) {
diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/network/MsoNetworkAdapterImpl.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/network/MsoNetworkAdapterImpl.java
index d2c0d9cabd..d9f47f5c3a 100644
--- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/network/MsoNetworkAdapterImpl.java
+++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/network/MsoNetworkAdapterImpl.java
@@ -962,7 +962,7 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter {
if (netInfo != null) {
// Found. Populate the output elements
networkExists.value = Boolean.TRUE;
- if ("HEAT".equals(mode)) {
+ if ("HEAT".equals(mode) && heatStack != null) {
networkId.value = heatStack.getCanonicalName();
} else {
networkId.value = netInfo.getId();
@@ -1294,15 +1294,23 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter {
// Resource Property
List<ContrailPolicyRef> prlist = new ArrayList<>();
int index = 1;
- for (String pf : pFqdns) {
- if (!commonUtils.isNullOrEmpty(pf)) {
- ContrailPolicyRef pr = new ContrailPolicyRef();
- ContrailPolicyRefSeq refSeq = new ContrailPolicyRefSeq(String.valueOf(index), "0");
- pr.setSeq(refSeq);
- index++;
- logger.debug("Contrail PolicyRefs Data:{}", pr);
- prlist.add(pr);
+
+ if (pFqdns != null) {
+ for (String pf : pFqdns) {
+ if (!commonUtils.isNullOrEmpty(pf)) {
+ ContrailPolicyRef pr = new ContrailPolicyRef();
+ ContrailPolicyRefSeq refSeq = new ContrailPolicyRefSeq(String.valueOf(index), "0");
+ pr.setSeq(refSeq);
+ index++;
+ logger.debug("Contrail PolicyRefs Data:{}", pr);
+ prlist.add(pr);
+ }
}
+ } else {
+ String error = "Null pFqdns at start of mergePolicyRefs";
+ logger.error(LoggingAnchor.THREE, MessageEnum.RA_MARSHING_ERROR, ErrorCode.BusinessProcesssError.getValue(),
+ error);
+ throw new MsoAdapterException(error);
}
JsonNode node = null;
diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfAdapterImpl.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfAdapterImpl.java
index a141f59153..1d73bf21c9 100644
--- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfAdapterImpl.java
+++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfAdapterImpl.java
@@ -843,8 +843,10 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter {
// Add version check
// First - see if it's in the VnfResource record
// if we have a vf Module - then we have to query to get the VnfResource record.
- if (!oldWay && vf.getVnfResources() != null) {
- vnfResource = vf.getVnfResources();
+ if (!oldWay) {
+ if (vf != null) {
+ vnfResource = vf.getVnfResources();
+ }
if (vnfResource == null) {
logger.debug("Unable to find vnfResource will not error for now...");
}
diff --git a/adapters/mso-openstack-adapters/src/main/resources/application-local.yaml b/adapters/mso-openstack-adapters/src/main/resources/application-local.yaml
deleted file mode 100644
index 66d63d436b..0000000000
--- a/adapters/mso-openstack-adapters/src/main/resources/application-local.yaml
+++ /dev/null
@@ -1,105 +0,0 @@
-# will be used as entry in DB to say SITE OFF/ON for healthcheck
-# MSO Properties go here
-org:
- onap:
- so:
- adapters:
- default_keystone_url_version: /v2.0
- default_keystone_reg_ex: "/[vV][0-9]"
- vnf:
- bpelauth: 1DDAD7A55A230BB446AA2125053EFB46455F43E48B60155E1C53236E175DFC722A6BE120F6DB390C60034C7564AEB653EA
- checkRequiredParameters: true
- addGetFilesOnVolumeReq: false
- sockettimeout: 30
- connecttimeout: 30
- retrycount: 5
- retryinterval: -15
- retrylist: 408,429,500,502,503,504,900
- network:
- bpelauth: 1DDAD7A55A230BB446AA2125053EFB46455F43E48B60155E1C53236E175DFC722A6BE120F6DB390C60034C7564AEB653EA
- sockettimeout: 5
- connecttimeout: 5
- retrycount: 5
- retryinterval: -15
- retrylist: 408,429,500,502,503,504,900
- encryptionKey: aa3871669d893c7fb8abbcda31b88b4f
- tenant:
- default_x_aic_orm_client_string: ECOMP-MSO
- default_keystone_url_version: /v2.0
- default_keystone_reg_ex: "/[vV][0-9]"
- default_tenant_description: ECOMP Tenant
- default_region_type: single
- default_user_role: admin
- default_success_status_string: Success
- default_no_regions_status_string: no regions
- default_orm_request_path: /v1/orm/customers/
- default_orm_url_replace_this: 8080
- default_orm_url_replace_with_this: 7080
- default_quota_value: 10
- set_default_quota: false
- po:
- retryCodes: 504
- retryDelay: 5
- retryCount: 3
- pollTimeout: 7500
- pollInterval: 15
-
-server-port: 8080
-ssl-enable: false
-tomcat:
- max-threads: 50
-mso:
- msoKey: 07a7159d3bf51a0e53be7a8f89699be7
- auth: 6B466C603A260F3655DBF91E53CE54667041C01406D10E8CAF9CC24D8FA5388D06F90BFE4C852052B436
- audit:
- lock-time: 240000
- logPath: logs
- msb-ip: localhost
- msb-port: ${wiremock.server.port}
- workflow:
- endpoint: http://bpmn-infra:8081/sobpmnengine
- topics:
- retryMultiplier: 1000
- config:
- cadi:
- aafId: test
- catalog:
- db:
- spring:
- endpoint: "http://localhost:8080"
- db:
- auth: Basic YnBlbDptc28tZGItMTUwNyE=
- site-name: localDevEnv
- async:
- core-pool-size: 50
- max-pool-size: 50
- queue-capacity: 500
-
-spring:
- security:
- usercredentials:
- -
- username: sdnc
- password: '$2a$12$mukkC6IvLikKGBdwqGnev.H0ccvV6K13TFeLvyNhJoCuNkRjWhqi6'
- role: SDNC-Client
- -
- username: sitecontrol
- password: '$2a$12$VBUF.qBmeK1FNyO2MqTpD.P2M1tvlesZlhCkAjjHvF9hmYNVdMDmu'
- role: SiteControl-Client
- -
- username: bpel
- password: '$2a$12$/GW0/AVAUooTag.7GDc9a.jW7XH3nq/.QsJJJFZJ0N24iXB2W9ksO'
- role: BPEL-Client
- -
- username: sniro
- password: '$2a$12$lbOQWS1iDmdQPxW2Mb6OiuTzGaPUrkrvoKVn2zwpFWb6n5Y86Lf1y'
- role: SNIRO-Client
- -
- username: apih
- password: '$2a$12$e1BGJ7qknMN/b7bqsQvU2OT9iGunt9IlfQclKlCs6n240oHBfcO5y'
- role: MSO-Client
- -
- username: mso_admin
- password: '$2a$12$tidKuu.h88E2nuL95pTVY.ZOYMN/1dp29A9b1o.0GFDsVVSYlMkHa'
- role: ACTUATOR
-
diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditDataServiceTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditDataServiceTest.java
new file mode 100644
index 0000000000..d3380a6a33
--- /dev/null
+++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditDataServiceTest.java
@@ -0,0 +1,101 @@
+package org.onap.so.adapters.audit;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.when;
+import java.util.ArrayList;
+import java.util.List;
+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.so.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");
+ }
+
+}
diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditStackServiceDataTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditStackServiceDataTest.java
index f23486c45c..3432e4a8b6 100644
--- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditStackServiceDataTest.java
+++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditStackServiceDataTest.java
@@ -7,9 +7,9 @@
* 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.
@@ -40,6 +40,7 @@ import org.onap.so.audit.beans.AuditInventory;
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;
@@ -48,6 +49,9 @@ public class AuditStackServiceDataTest extends AuditCreateStackService {
@InjectMocks
private AuditCreateStackService auditStackService = new AuditCreateStackService();
+ @InjectMocks
+ private AuditQueryStackService auditQueryStackService = new AuditQueryStackService();
+
@Mock
private HeatStackAudit heatStackAuditMock;
@@ -60,6 +64,9 @@ public class AuditStackServiceDataTest extends AuditCreateStackService {
@Mock
private ExternalTaskService mockExternalTaskService;
+ @Mock
+ private AuditDataService auditDataService;
+
private ObjectMapper objectMapper = new ObjectMapper();
private AuditInventory auditInventory = new AuditInventory();
@@ -112,6 +119,20 @@ public class AuditStackServiceDataTest extends AuditCreateStackService {
}
@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");
diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditVServerTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditVServerTest.java
index 2075557721..3d9a128318 100644
--- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditVServerTest.java
+++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditVServerTest.java
@@ -7,9 +7,9 @@
* 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.
@@ -33,14 +33,19 @@ import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Stream;
+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.Relationship;
+import org.onap.aai.domain.yang.RelationshipList;
+import org.onap.aai.domain.yang.VfModule;
import org.onap.aai.domain.yang.Vserver;
import org.onap.so.client.aai.AAIObjectPlurals;
import org.onap.so.client.aai.AAIObjectType;
@@ -48,6 +53,7 @@ import org.onap.so.client.aai.AAIResourcesClient;
import org.onap.so.client.aai.entities.AAIResultWrapper;
import org.onap.so.client.aai.entities.uri.AAIResourceUri;
import org.onap.so.client.aai.entities.uri.AAIUriFactory;
+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;
@@ -362,6 +368,69 @@ public class AuditVServerTest extends AuditVServer {
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(AAIObjectType.VSERVER, cloudOwner, cloudRegion, tenantId, "testVserverId").build());
+ auditList.getAuditList().add(obj1);
+
+ doReturn(false).when(aaiResourcesMock).exists(AAIUriFactory.createResourceUri(AAIObjectType.VSERVER, cloudOwner,
+ cloudRegion, tenantId, "testVserverId"));
+
+ auditNova.auditVservers(auditList);
+
+ Mockito.verify(aaiResourcesMock).exists(AAIUriFactory.createResourceUri(AAIObjectType.VSERVER, cloudOwner,
+ cloudRegion, tenantId, "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(wrapper).when(aaiResourcesMock)
+ .get(AAIUriFactory.createResourceUri(AAIObjectPlurals.VF_MODULE, "genericVnfId")
+ .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(wrapper).when(aaiResourcesMock)
+ .get(AAIUriFactory.createResourceUri(AAIObjectPlurals.VF_MODULE, "genericVnfId")
+ .queryParam("vf-module-name", "vfModuleName"));
+
+ doReturn(vserverWrapper).when(aaiResourcesMock).get(AAIUriFactory.createResourceUri(AAIObjectType.VSERVER,
+ "cloud-owner", "cloud-region-id", "tenant-id", "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/resources/vfModule.json b/adapters/mso-openstack-adapters/src/test/resources/vfModule.json
new file mode 100644
index 0000000000..bfdca2c144
--- /dev/null
+++ b/adapters/mso-openstack-adapters/src/test/resources/vfModule.json
@@ -0,0 +1,38 @@
+{
+ "vf-module-id": "a62d14f0-421e-4e64-980a-a368722819db",
+ "vf-module-name": "vig30001vm001vig001_migrated.base.module-0",
+ "is-base-vf-module": false,
+ "resource-version": "1494001780539",
+ "relationship-list": {
+ "relationship": [
+ {
+ "related-to": "vserver",
+ "related-link": "/aai/v11/cloud-infrastructure/cloud-regions/cloud-region/cloud-owner/cloud-region-id/tenants/tenant/tenant-id/vservers/vserver/VUSCHGA1",
+ "relationship-data": [
+ {
+ "relationship-key": "cloud-region.cloud-owner",
+ "relationship-value": "cloud-owner"
+ },
+ {
+ "relationship-key": "cloud-region.cloud-region-id",
+ "relationship-value": "cloud-region-id"
+ },
+ {
+ "relationship-key": "tenant.tenant-id",
+ "relationship-value": "tenant-id"
+ },
+ {
+ "relationship-key": "vserver.vserver-id",
+ "relationship-value": "VUSCHGA1"
+ }
+ ],
+ "related-to-property": [
+ {
+ "property-key": "vserver.vserver-name",
+ "property-value": "VUSCHGA1"
+ }
+ ]
+ }
+ ]
+ }
+ }