From eaef24e96c1ce95195845258ce0a304ab9c0c21a Mon Sep 17 00:00:00 2001 From: "Boslet, Cory" Date: Wed, 17 Jul 2019 13:36:05 -0400 Subject: add query stack data and populate table step Need to check if audit is enabled first in the delete record task Updates to audit delete redeisgn and data to table Various updates to logging, audit object, added tag to query, updated tag value. Updated write method to make sure an entry for this heat stack doesnt already exist to avoid duplicate entrys Updated unit test to account for get query Added so that id is not hidden from query results Updated the was delete is done plus minor updates. Updated delete method to use resttemplate instead of bowman client Combined the write and get stack data task into the external tasks. Removed the task to delete the stack data from db Updates to junit request id so its not a random id for test Updated service tasks in att BB to call external task Update to be a real uuid format due to failing unit test Updated fields to protected and updated unit test Issue-ID: SO-2111 Signed-off-by: Benjamin, Max (mb388a) Change-Id: I8f479a046cf837403f60c330ed6ad8bc08a9c82f --- .../org/onap/so/audit/beans/AuditInventory.java | 36 +- .../so/adapters/audit/AbstractAuditService.java | 10 +- .../onap/so/adapters/audit/AuditDataService.java | 77 ++++ .../so/adapters/audit/AuditDeleteStackService.java | 32 +- .../so/adapters/audit/AuditQueryStackService.java | 68 ++++ .../onap/so/adapters/audit/AuditStackService.java | 13 + .../org/onap/so/adapters/audit/AuditVServer.java | 34 ++ .../org/onap/so/adapters/audit/HeatStackAudit.java | 52 +++ .../so/adapters/audit/AuditDataServiceTest.java | 101 ++++++ .../adapters/audit/AuditStackServiceDataTest.java | 25 +- .../onap/so/adapters/audit/AuditVServerTest.java | 73 +++- .../src/test/resources/vfModule.json | 38 ++ .../RequestDbRepositoryConfiguration.java | 23 ++ .../subprocess/BuildingBlock/DeleteVfModuleBB.bpmn | 393 ++++++++++++--------- .../bpmn/subprocess/DeleteVfModuleBBTest.java | 27 +- .../so/bpmn/infrastructure/audit/AuditTasks.java | 11 + .../onap/so/bpmn/common/data/TestDataSetup.java | 2 +- .../bpmn/infrastructure/audit/AuditTasksTest.java | 34 +- .../RequestProcessingDataRepository.java | 7 +- .../so/db/request/client/RequestsDbClient.java | 23 +- .../so/db/catalog/client/CatalogDbClientTest.java | 5 +- 21 files changed, 879 insertions(+), 205 deletions(-) create mode 100644 adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditDataService.java create mode 100644 adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditQueryStackService.java create mode 100644 adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditDataServiceTest.java create mode 100644 adapters/mso-openstack-adapters/src/test/resources/vfModule.json create mode 100644 adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/RequestDbRepositoryConfiguration.java diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/audit/beans/AuditInventory.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/audit/beans/AuditInventory.java index 7e612b3b41..eff32cf826 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/audit/beans/AuditInventory.java +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/audit/beans/AuditInventory.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. @@ -25,18 +25,24 @@ import java.io.Serializable; public class AuditInventory implements Serializable { /** - * + * */ private static final long serialVersionUID = 4937350343452380760L; + private String msoRequestId; + private String cloudRegion; private String cloudOwner; private String tenantId; + private String vfModuleId; + private String heatStackName; + private String genericVnfId; + public String getCloudRegion() { return cloudRegion; } @@ -69,6 +75,30 @@ public class AuditInventory implements Serializable { this.heatStackName = heatStackName; } + public String getGenericVnfId() { + return genericVnfId; + } + + public void setGenericVnfId(String genericVnfId) { + this.genericVnfId = genericVnfId; + } + + public String getVfModuleId() { + return vfModuleId; + } + + public void setVfModuleId(String vfModuleId) { + this.vfModuleId = vfModuleId; + } + + public String getMsoRequestId() { + return msoRequestId; + } + + public void setMsoRequestId(String msoRequestId) { + this.msoRequestId = msoRequestId; + } + } 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..7500097b6a 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 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; 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 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 getStackDataFromRequestDb(AuditInventory auditInventory) + throws JsonParseException, JsonMappingException, IOException { + + List 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..b99eaa98d9 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 @@ -40,10 +40,16 @@ 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) { AuditInventory auditInventory = externalTask.getVariable("auditInventory"); @@ -51,17 +57,21 @@ public class AuditDeleteStackService extends AbstractAuditService { setupMDC(externalTask); boolean success = false; try { - logger.info("Executing External Task Audit Inventory, Retry Number: {} \n {}", auditInventory, - externalTask.getRetries()); - Optional auditListOpt = heatStackAudit.auditHeatStack(auditInventory.getCloudRegion(), - auditInventory.getCloudOwner(), auditInventory.getTenantId(), auditInventory.getHeatStackName()); + logger.info("Executing External Task Delete Audit Inventory. Retry Number: {}", externalTask.getRetries()); + Optional 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); } 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..c8ac9d1a58 --- /dev/null +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditQueryStackService.java @@ -0,0 +1,68 @@ +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.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) { + AuditInventory auditInventory = externalTask.getVariable("auditInventory"); + setupMDC(externalTask); + boolean success = false; + Map variables = new HashMap<>(); + try { + logger.info("Executing External Task Query Audit Inventory. Audit Inventory: {} \n Retry Number: {}", + auditInventory.toString(), externalTask.getRetries()); + + Optional 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()); + } 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); + } 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 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 relatedVservers = + getAaiClient().get(uri).getRelationships().get().getRelatedUris(AAIObjectType.VSERVER); + if (!relatedVservers.isEmpty()) { + relatedVservers.forEach(vserverUri -> { + Optional 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 auditVservers(Set 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 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 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 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 auditHeatStack(String cloudRegion, String cloudOwner, String tenantId, String heatStackName) { try { @@ -215,6 +242,31 @@ public class HeatStackAudit { return vserversToAudit; } + protected Set createVserverSet(List novaResources) { + Set 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/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()).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 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(); @@ -111,6 +118,20 @@ public class AuditStackServiceDataTest extends AuditCreateStackService { 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 captor = ArgumentCaptor.forClass(Map.class); + ArgumentCaptor 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", 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 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 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" + } + ] + } + ] + } + } diff --git a/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/RequestDbRepositoryConfiguration.java b/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/RequestDbRepositoryConfiguration.java new file mode 100644 index 0000000000..c32525a62b --- /dev/null +++ b/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/RequestDbRepositoryConfiguration.java @@ -0,0 +1,23 @@ +package org.onap.so.adapters.requestsdb; + +import java.util.stream.Collectors; +import javax.persistence.EntityManager; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.rest.core.config.RepositoryRestConfiguration; +import org.springframework.data.rest.webmvc.config.RepositoryRestConfigurerAdapter; + +@Configuration +public class RequestDbRepositoryConfiguration extends RepositoryRestConfigurerAdapter { + + @Autowired + private EntityManager entityManager; + + @Override + public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) { + config.exposeIdsFor(entityManager.getMetamodel().getEntities().stream().map(e -> e.getJavaType()) + .collect(Collectors.toList()).toArray(new Class[0])); + } + + +} diff --git a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/DeleteVfModuleBB.bpmn b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/DeleteVfModuleBB.bpmn index 33335ab2c4..ca0f8452cf 100644 --- a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/DeleteVfModuleBB.bpmn +++ b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/DeleteVfModuleBB.bpmn @@ -2,13 +2,12 @@ - SequenceFlow_1537yw5 + SequenceFlow_1oeootm - - SequenceFlow_1n8gab5 + + SequenceFlow_028rmiu SequenceFlow_08tvhtf - SequenceFlow_01vfwtp SequenceFlow_09l7pcg @@ -70,44 +69,22 @@ SequenceFlow_0khqfnc SequenceFlow_0yuz21z - - - SequenceFlow_1537yw5 - SequenceFlow_1n8gab5 - SequenceFlow_1v3jgqe - - + - - - SequenceFlow_1v3jgqe - SequenceFlow_1odt2wt + SequenceFlow_1oeootm + SequenceFlow_10af0fk - - - - - SequenceFlow_1swistn - SequenceFlow_0qfmmgt + + SequenceFlow_0f5ljoh + SequenceFlow_0hpj2mm SequenceFlow_032jv5j - SequenceFlow_1swistn + SequenceFlow_1iulltd - - - SequenceFlow_1odt2wt - SequenceFlow_032jv5j - SequenceFlow_1mgunf3 - - - SequenceFlow_1mgunf3 - SequenceFlow_17cd9e2 - SequenceFlow_1ut7n32 - SequenceFlow_1fhst92 @@ -120,7 +97,7 @@ SequenceFlow_0xuodpy - + @@ -132,19 +109,14 @@ SequenceFlow_179btn2 - + - - SequenceFlow_02lpx87 - SequenceFlow_1ut7n32 - SequenceFlow_14bu4ys - - SequenceFlow_0qfmmgt + SequenceFlow_0hpj2mm SequenceFlow_17cd9e2 SequenceFlow_1gdyk9j @@ -152,6 +124,54 @@ SequenceFlow_1gdyk9j + + SequenceFlow_10af0fk + SequenceFlow_032jv5j + SequenceFlow_1bt1p2u + + + SequenceFlow_1bt1p2u + SequenceFlow_0dzf7hz + SequenceFlow_1bq9g02 + + + + + + SequenceFlow_1iulltd + SequenceFlow_0dzf7hz + + + + + + + + SequenceFlow_1bq9g02 + SequenceFlow_0mtzl4z + SequenceFlow_028rmiu + + + SequenceFlow_02lpx87 + SequenceFlow_13mlz57 + SequenceFlow_14bu4ys + + + + SequenceFlow_0mtzl4z + SequenceFlow_0f5ljoh + SequenceFlow_1gjwivp + + + + + + SequenceFlow_17cd9e2 + SequenceFlow_1gjwivp + SequenceFlow_13mlz57 + + + @@ -164,40 +184,33 @@ - + - - - - - - - - - + + - + - + - + - + - - - + + + - + @@ -234,9 +247,9 @@ - + - + @@ -279,101 +292,29 @@ - - - - - - - - - - - - - - - - - + + + - - - - - - - - + - - + + - - - - - - - - - - + - + - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - + @@ -409,9 +350,9 @@ - + - + @@ -421,30 +362,26 @@ - - - + + + - + - - + + + + - + - - - - - - - + - + @@ -454,11 +391,143 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/infrastructure/bpmn/subprocess/DeleteVfModuleBBTest.java b/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/infrastructure/bpmn/subprocess/DeleteVfModuleBBTest.java index d9166c9138..47d0ad9b7f 100644 --- a/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/infrastructure/bpmn/subprocess/DeleteVfModuleBBTest.java +++ b/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/infrastructure/bpmn/subprocess/DeleteVfModuleBBTest.java @@ -46,18 +46,20 @@ public class DeleteVfModuleBBTest extends BaseBPMNTest { mockSubprocess("VnfAdapter", "Mocked VnfAdapter", "GenericStub"); ProcessInstance pi = runtimeService.startProcessInstanceByKey("DeleteVfModuleBB", variables); List tasks = externalTaskService.fetchAndLock(100, "externalWorkerId") - .topic("InventoryDeleteAudit", 60L * 1000L).execute(); + .topic("InventoryDeleteAudit", 60L * 1000L).topic("InventoryQueryAudit", 60L * 1000L).execute(); while (!tasks.isEmpty()) { for (LockedExternalTask task : tasks) { externalTaskService.complete(task.getId(), "externalWorkerId"); } tasks = externalTaskService.fetchAndLock(100, "externalWorkerId").topic("InventoryDeleteAudit", 60L * 1000L) - .execute(); + .topic("InventoryQueryAudit", 60L * 1000L).execute(); } assertThat(pi).isNotNull(); - assertThat(pi).isStarted().hasPassed("DeleteVfModuleBB_Start", "ExclusiveGateway_0xrgzm7", - "ExclusiveGateway_1yvh16a", "Check_Audit", "Setup_Audit_Variable", "Audit_Inventory", - "DeleteVfModuleVnfAdapter", "VnfAdapter", "DeleteNetworkPolicies", "UpdateVnfIpv4OamAddress", + assertThat(pi).isStarted().hasPassed("DeleteVfModuleBB_Start", "Check_Audit", "auditEnabledCheck", + "Setup_Audit_Variable", "Setup_Audit_Variable", "aicQueryStack", "ExclusiveGateway_1t9q2jl", + "ExclusiveGateway_1naduhl", "ExclusiveGateway_13fhmpf", "DeleteVfModuleVnfAdapter", "VnfAdapter", + "Audit_Inventory", "ExclusiveGateway_1yvh16a", "auditSuccessfulCheck", "ExclusiveGateway_01wvywu", + "ExclusiveGateway_1yvh16a", "DeleteNetworkPolicies", "UpdateVnfIpv4OamAddress", "UpdateVnfManagementV6Address", "UpdateVfModuleContrailServiceInstanceFqdn", "UpdateVfModuleHeatStackId", "UpdateVfModuleDeleteStatus", "DeleteVfModuleBB_End"); assertThat(pi).isEnded(); @@ -68,19 +70,22 @@ public class DeleteVfModuleBBTest extends BaseBPMNTest { doThrow(BpmnError.class).when(vnfAdapterDeleteTasks).deleteVfModule(any(BuildingBlockExecution.class)); ProcessInstance pi = runtimeService.startProcessInstanceByKey("DeleteVfModuleBB", variables); List tasks = externalTaskService.fetchAndLock(100, "externalWorkerId") - .topic("InventoryDeleteAudit", 60L * 1000L).execute(); + .topic("InventoryDeleteAudit", 60L * 1000L).topic("InventoryQueryAudit", 60L * 1000L).execute(); while (!tasks.isEmpty()) { for (LockedExternalTask task : tasks) { externalTaskService.complete(task.getId(), "externalWorkerId"); } tasks = externalTaskService.fetchAndLock(100, "externalWorkerId").topic("InventoryDeleteAudit", 60L * 1000L) - .execute(); + .topic("InventoryQueryAudit", 60L * 1000L).execute(); } assertThat(pi).isNotNull(); - assertThat(pi).isStarted().hasPassed("DeleteVfModuleBB_Start", "DeleteVfModuleVnfAdapter").hasNotPassed( - "VnfAdapter", "DeleteNetworkPolicies", "UpdateVnfIpv4OamAddress", "UpdateVnfManagementV6Address", - "UpdateVfModuleContrailServiceInstanceFqdn", "UpdateVfModuleHeatStackId", "UpdateVfModuleDeleteStatus", - "DeleteVfModuleBB_End"); + assertThat(pi).isStarted() + .hasPassed("DeleteVfModuleBB_Start", "Check_Audit", "auditEnabledCheck", "Setup_Audit_Variable", + "Setup_Audit_Variable", "aicQueryStack", "ExclusiveGateway_1t9q2jl", "ExclusiveGateway_1naduhl", + "ExclusiveGateway_13fhmpf") + .hasNotPassed("VnfAdapter", "DeleteNetworkPolicies", "UpdateVnfIpv4OamAddress", + "UpdateVnfManagementV6Address", "UpdateVfModuleContrailServiceInstanceFqdn", + "UpdateVfModuleHeatStackId", "UpdateVfModuleDeleteStatus", "DeleteVfModuleBB_End"); assertThat(pi).isEnded(); } } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/audit/AuditTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/audit/AuditTasks.java index 62878fd4f7..922b721098 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/audit/AuditTasks.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/audit/AuditTasks.java @@ -21,15 +21,21 @@ package org.onap.so.bpmn.infrastructure.audit; +import java.util.List; import org.onap.so.audit.beans.AuditInventory; import org.onap.so.bpmn.common.BuildingBlockExecution; import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; +import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule; import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock; import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; import org.onap.so.client.exception.BBObjectNotFoundException; import org.onap.so.client.exception.ExceptionBuilder; +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.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -83,12 +89,17 @@ public class AuditTasks { GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock(); VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID); + GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID); CloudRegion cloudRegion = gBBInput.getCloudRegion(); + auditInventory.setMsoRequestId(gBBInput.getRequestContext().getMsoRequestId()); auditInventory.setCloudOwner(cloudRegion.getCloudOwner()); auditInventory.setCloudRegion(cloudRegion.getLcpCloudRegionId()); auditInventory.setTenantId(cloudRegion.getTenantId()); + auditInventory.setVfModuleId(vfModule.getVfModuleId()); auditInventory.setHeatStackName(vfModule.getVfModuleName()); + auditInventory.setGenericVnfId(genericVnf.getVnfId()); return auditInventory; } + } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/common/data/TestDataSetup.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/common/data/TestDataSetup.java index 825c703b74..4f1ad996dc 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/common/data/TestDataSetup.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/common/data/TestDataSetup.java @@ -159,7 +159,7 @@ public class TestDataSetup { public RequestContext buildRequestContext() { RequestContext requestContext = new RequestContext(); - requestContext.setMsoRequestId(UUID.randomUUID().toString()); + requestContext.setMsoRequestId("fb06f44c-c797-4f38-9b17-b4b975344600"); requestContext.setProductFamilyId("testProductFamilyId"); requestContext.setRequestorId("testRequestorId"); diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/audit/AuditTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/audit/AuditTasksTest.java index 3bf24291ea..cee06caa75 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/audit/AuditTasksTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/audit/AuditTasksTest.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. @@ -21,14 +21,20 @@ package org.onap.so.bpmn.infrastructure.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.ArgumentMatchers.any; import static org.mockito.Mockito.when; +import java.util.ArrayList; +import java.util.List; +import org.junit.Assert; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.mockito.ArgumentMatchers; import org.mockito.InjectMocks; +import org.mockito.Mockito; +import org.onap.aai.domain.yang.Vserver; import org.onap.so.audit.beans.AuditInventory; import org.onap.so.bpmn.BaseTaskTest; import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; @@ -36,6 +42,11 @@ import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule; import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; import org.onap.so.client.exception.BBObjectNotFoundException; +import org.onap.so.client.graphinventory.GraphInventoryCommonObjectMapperProvider; +import org.onap.so.db.request.beans.RequestProcessingData; +import org.onap.so.objects.audit.AAIObjectAudit; +import org.onap.so.objects.audit.AAIObjectAuditList; +import com.fasterxml.jackson.core.JsonProcessingException; public class AuditTasksTest extends BaseTaskTest { @@ -50,16 +61,29 @@ public class AuditTasksTest extends BaseTaskTest { public final ExpectedException exception = ExpectedException.none(); @Before - public void before() throws BBObjectNotFoundException { + public void before() throws BBObjectNotFoundException, JsonProcessingException { serviceInstance = setServiceInstance(); genericVnf = setGenericVnf(); vfModule = setVfModule(); + buildRequestContext(); setCloudRegion(); + setRequestContext(); when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.GENERIC_VNF_ID))) .thenReturn(genericVnf); when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.VF_MODULE_ID))).thenReturn(vfModule); when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.SERVICE_INSTANCE_ID))) .thenReturn(serviceInstance); + execution.setVariable("auditQuerySuccess", true); + 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); + execution.setVariable("auditList", auditListString); } @Test @@ -68,8 +92,12 @@ public class AuditTasksTest extends BaseTaskTest { expectedAuditInventory.setCloudOwner("testCloudOwner"); expectedAuditInventory.setCloudRegion("testLcpCloudRegionId"); expectedAuditInventory.setHeatStackName("testVfModuleName1"); + expectedAuditInventory.setVfModuleId("testVfModuleId1"); expectedAuditInventory.setTenantId("testTenantId"); + expectedAuditInventory.setGenericVnfId("testVnfId1"); + expectedAuditInventory.setMsoRequestId("fb06f44c-c797-4f38-9b17-b4b975344600"); auditTasks.setupAuditVariable(execution); assertThat((AuditInventory) execution.getVariable("auditInventory"), sameBeanAs(expectedAuditInventory)); } + } diff --git a/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/RequestProcessingDataRepository.java b/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/RequestProcessingDataRepository.java index ba2d021010..708171366d 100644 --- a/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/RequestProcessingDataRepository.java +++ b/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/RequestProcessingDataRepository.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. @@ -38,4 +38,7 @@ public interface RequestProcessingDataRepository extends JpaRepository findBySoRequestIdOrderByGroupingIdDesc(@Param("SO_REQUEST_ID") String soRequestId); + + List findByGroupingIdAndNameAndTag(@Param("GROUPING_ID") String groupingId, + @Param("NAME") String name, @Param("TAG") String tag); } diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/client/RequestsDbClient.java b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/client/RequestsDbClient.java index c0ce59dc66..7a24d14e9b 100644 --- a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/client/RequestsDbClient.java +++ b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/client/RequestsDbClient.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. @@ -26,6 +26,8 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; +import java.util.stream.StreamSupport; import javax.annotation.PostConstruct; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.UriBuilder; @@ -72,6 +74,7 @@ public class RequestsDbClient { private static final String REQUEST_ID = "REQUEST_ID"; private static final String OPERATIONAL_ENVIRONMENT_ID = "OPERATIONAL_ENV_ID"; private static final String SERVICE_MODEL_VERSION_ID = "SERVICE_MODEL_VERSION_ID"; + private static final String TAG = "TAG"; private static final String FLOW_EXECUTION_PATH = "flowExecutionPath"; private static final String BPMN_EXECUTION_DATA_TAG = "BPMNExecutionData"; @@ -119,6 +122,8 @@ public class RequestsDbClient { private static final String findBySoRequestIdOrderByGroupingIdDesc = "/requestProcessingData/search/findBySoRequestIdOrderByGroupingIdDesc"; + private static final String findByGroupingIdAndNameAndTag = + "/requestProcessingData/search/findByGroupingIdAndNameAndTag"; @Autowired protected RestTemplate restTemplate; @@ -368,6 +373,20 @@ public class RequestsDbClient { .queryParam(GROUPING_ID, groupingId).build().toString())); } + public List getRequestProcessingDataByGroupingIdAndNameAndTag(String groupingId, String name, + String tag) { + Iterable requestProcessingDataListIt = + getClientFactory().create(RequestProcessingData.class) + .getAll(getUri(UriBuilder.fromUri(endpoint + findByGroupingIdAndNameAndTag) + .queryParam(GROUPING_ID, groupingId).queryParam(NAME, name).queryParam(TAG, tag).build() + .toString())); + + List requestProcessingDataList = + StreamSupport.stream(requestProcessingDataListIt.spliterator(), false).collect(Collectors.toList()); + + return requestProcessingDataList; + } + public RequestProcessingData getRequestProcessingDataBySoRequestIdAndName(String soRequestId, String name) { return getClientFactory().create(RequestProcessingData.class) .get(getUri(UriBuilder.fromUri(endpoint + findBySoRequestIdAndName) diff --git a/mso-catalog-db/src/test/java/org/onap/so/db/catalog/client/CatalogDbClientTest.java b/mso-catalog-db/src/test/java/org/onap/so/db/catalog/client/CatalogDbClientTest.java index 9c257bdec3..b82c17dc84 100644 --- a/mso-catalog-db/src/test/java/org/onap/so/db/catalog/client/CatalogDbClientTest.java +++ b/mso-catalog-db/src/test/java/org/onap/so/db/catalog/client/CatalogDbClientTest.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. @@ -170,4 +170,5 @@ public class CatalogDbClientTest { CvnfcCustomization aCvnfc = catalogDbClient.findCvnfcCustomizationInAList(cvnfcCustomizationUuid, cvnfcs); assertTrue(aCvnfc.getModelCustomizationUUID().equals("a123")); } + } -- cgit 1.2.3-korg