diff options
author | Steve Smokowski <ss835w@att.com> | 2019-03-06 17:26:20 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2019-03-06 17:26:20 +0000 |
commit | 4cb3383f0bb967e0ae17311309743b373f4678e1 (patch) | |
tree | dc291bcf6d5d9d5ac14e4e05c6e82ace37a69f8b /adapters | |
parent | 42dd47e5c8431cafee7b949122672d422e100ae3 (diff) | |
parent | a339f93a736c9503888d05e47d79b173229042fc (diff) |
Merge "improvements to audit inventory feature"
Diffstat (limited to 'adapters')
16 files changed, 327 insertions, 99 deletions
diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloud/authentication/KeystoneV3Authentication.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloud/authentication/KeystoneV3Authentication.java index 00602af216..8fbccaaf69 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloud/authentication/KeystoneV3Authentication.java +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloud/authentication/KeystoneV3Authentication.java @@ -128,6 +128,6 @@ public class KeystoneV3Authentication { } } } - throw new ServiceEndpointNotFoundException("endpoint url not found"); + throw new ServiceEndpointNotFoundException("endpoint url not found: type:" + type +" region: " + region + " facing: " + facing); } } diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatUtils.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatUtils.java index ee1c79c09c..a0fbd485d1 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatUtils.java +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatUtils.java @@ -999,6 +999,7 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin{ OpenStackRequest <Stack> request = heatClient.getStacks ().byName (stackName); return executeAndRecordOpenstackRequest (request); } catch (OpenStackResponseException e) { + logger.error("Error in Query Stack", e); if (e.getStatus () == 404) { logger.debug ("queryHeatStack - stack not found: {}", stackName); return null; diff --git a/adapters/mso-catalog-db-adapter/src/main/resources/application.yaml b/adapters/mso-catalog-db-adapter/src/main/resources/application.yaml index aa9317c920..07b000875e 100644 --- a/adapters/mso-catalog-db-adapter/src/main/resources/application.yaml +++ b/adapters/mso-catalog-db-adapter/src/main/resources/application.yaml @@ -28,6 +28,7 @@ spring: password: ${DB_ADMIN_PASSWORD} outOfOrder: true validateOnMigrate: false + repeatableSqlMigrationPrefix: RATT jpa: show-sql: true hibernate: diff --git a/adapters/mso-openstack-adapters/pom.xml b/adapters/mso-openstack-adapters/pom.xml index f2f411d5b6..cb35e90860 100644 --- a/adapters/mso-openstack-adapters/pom.xml +++ b/adapters/mso-openstack-adapters/pom.xml @@ -13,8 +13,8 @@ <build> <finalName>${project.artifactId}-${project.version}</finalName> - - <plugins> + + <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> @@ -36,25 +36,75 @@ </executions> </plugin> - <!-- run the following plugin only when there's a wsdl change and you - need to recompile the java classes <plugin> <groupId>org.codehaus.mojo</groupId> - <artifactId>jaxws-maven-plugin</artifactId> <version>2.4.1</version> <executions> - <execution> <id>generate-network-async-stubs</id> <phase>process-classes</phase> - <goals> <goal>wsimport</goal> </goals> <configuration> <vmArgs> <vmArg>-Djavax.xml.accessExternalSchema=all</vmArg> - </vmArgs> <wsdlDirectory>src/main/resources/wsdl</wsdlDirectory> <wsdlFiles> - <wsdlFile>NetworkAdapterNotify.wsdl</wsdlFile> </wsdlFiles> <wsdlLocation>/NetworkAdapterNotify.wsdl</wsdlLocation> - <packageName>org.onap.so.adapters.network.async.client</packageName> <xnocompile>false</xnocompile> - <keep>true</keep> </configuration> </execution> <execution> <id>generate-vnf-async-stubs</id> - <phase>process-classes</phase> <goals> <goal>wsimport</goal> </goals> <configuration> - <vmArgs> <vmArg>-Djavax.xml.accessExternalSchema=all</vmArg> </vmArgs> <wsdlDirectory>src/main/resources/wsdl</wsdlDirectory> - <wsdlFiles> <wsdlFile>VnfAdapterNotify.wsdl</wsdlFile> </wsdlFiles> <wsdlLocation>/VnfAdapterNotify.wsdl</wsdlLocation> - <packageName>org.onap.so.adapters.vnf.async.client</packageName> <xnocompile>false</xnocompile> - <keep>true</keep> </configuration> </execution> </executions> </plugin> <plugin> - <groupId>org.codehaus.mojo</groupId> <artifactId>build-helper-maven-plugin</artifactId> - <version>3.0.0</version> <executions> <execution> <id>add-source</id> <phase>generate-sources</phase> - <goals> <goal>add-source</goal> </goals> <configuration> <sources> <source>${project.build.directory}/generated-sources/wsimport/</source> - </sources> </configuration> </execution> </executions> </plugin> --> +<!-- run the following plugin only when there's a wsdl change and you need to recompile the java classes + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>jaxws-maven-plugin</artifactId> + <version>2.4.1</version> + <executions> + <execution> + <id>generate-network-async-stubs</id> + <phase>process-classes</phase> + <goals> + <goal>wsimport</goal> + </goals> + <configuration> + <vmArgs> + <vmArg>-Djavax.xml.accessExternalSchema=all</vmArg> + </vmArgs> + <wsdlDirectory>src/main/resources/wsdl</wsdlDirectory> + <wsdlFiles> + <wsdlFile>NetworkAdapterNotify.wsdl</wsdlFile> + </wsdlFiles> + <wsdlLocation>/NetworkAdapterNotify.wsdl</wsdlLocation> + <packageName>org.onap.so.adapters.network.async.client</packageName> + <xnocompile>false</xnocompile> + <keep>true</keep> + </configuration> + </execution> + + <execution> + <id>generate-vnf-async-stubs</id> + <phase>process-classes</phase> + <goals> + <goal>wsimport</goal> + </goals> + <configuration> + <vmArgs> + <vmArg>-Djavax.xml.accessExternalSchema=all</vmArg> + </vmArgs> + <wsdlDirectory>src/main/resources/wsdl</wsdlDirectory> + <wsdlFiles> + <wsdlFile>VnfAdapterNotify.wsdl</wsdlFile> + </wsdlFiles> + <wsdlLocation>/VnfAdapterNotify.wsdl</wsdlLocation> + <packageName>org.onap.so.adapters.vnf.async.client</packageName> + <xnocompile>false</xnocompile> + <keep>true</keep> + </configuration> + </execution> + </executions> + </plugin> <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>build-helper-maven-plugin</artifactId> + <version>3.0.0</version> + <executions> + <execution> + <id>add-source</id> + <phase>generate-sources</phase> + <goals> + <goal>add-source</goal> + </goals> + <configuration> + <sources> + <source>${project.build.directory}/generated-sources/wsimport/</source> + </sources> + </configuration> + </execution> + </executions> + </plugin> + --> <plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> </plugin> @@ -76,12 +126,12 @@ </execution> </executions> </plugin> - </plugins> - - + </plugins> + + <pluginManagement> <plugins> - <!--This plugin's configuration is used to store Eclipse m2e settings + <!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself. --> <plugin> <groupId>org.eclipse.m2e</groupId> @@ -118,10 +168,10 @@ </build> <dependencies> - <!-- added for spring boot support --> + <!-- added for spring boot support --> <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-actuator</artifactId> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> @@ -134,7 +184,7 @@ <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-spring-boot-starter-jaxws</artifactId> - <version>${cxf.version}</version> + <version>${cxf.version}</version> </dependency> <dependency> <groupId>org.apache.cxf</groupId> @@ -142,9 +192,9 @@ <version>${cxf.version}</version> </dependency> <dependency> - <groupId>org.apache.cxf</groupId> - <artifactId>cxf-rt-rs-service-description-swagger</artifactId> - <version>${cxf.version}</version> + <groupId>org.apache.cxf</groupId> + <artifactId>cxf-rt-rs-service-description-swagger</artifactId> + <version>${cxf.version}</version> </dependency> <dependency> <groupId>org.webjars</groupId> @@ -157,16 +207,16 @@ <scope>test</scope> </dependency> <dependency> - <groupId>janino</groupId> - <artifactId>janino</artifactId> - <version>2.5.15</version> + <groupId>janino</groupId> + <artifactId>janino</artifactId> + <version>2.5.15</version> </dependency> - - <!-- end added for spring boot support --> - - - - <!-- added for unit testing --> + + <!-- end added for spring boot support --> + + + + <!-- added for unit testing --> <dependency> <groupId>org.onap.so.adapters</groupId> <artifactId>mso-adapter-utils</artifactId> @@ -181,11 +231,11 @@ <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <scope>test</scope> - </dependency> + </dependency> <dependency> <groupId>org.mariadb.jdbc</groupId> <artifactId>mariadb-java-client</artifactId> - </dependency> + </dependency> <dependency> <groupId>org.onap.so</groupId> <artifactId>common</artifactId> @@ -214,9 +264,9 @@ <version>${openstack.version}</version> </dependency> <dependency> - <groupId>org.camunda.bpm</groupId> - <artifactId>camunda-external-task-client</artifactId> - <version>1.0.0</version> - </dependency> + <groupId>org.camunda.bpm</groupId> + <artifactId>camunda-external-task-client</artifactId> + <version>1.1.1</version> + </dependency> </dependencies> </project> diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditStackServiceData.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditCreateStackService.java index 773705d566..24980ae4e0 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditStackServiceData.java +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditCreateStackService.java @@ -22,7 +22,6 @@ package org.onap.so.adapters.audit; - import org.camunda.bpm.client.task.ExternalTask; import org.camunda.bpm.client.task.ExternalTaskService; import org.onap.logging.ref.slf4j.ONAPLogConstants; @@ -35,14 +34,14 @@ import org.springframework.core.env.Environment; import org.springframework.stereotype.Component; @Component -public class AuditStackServiceData { +public class AuditCreateStackService { private 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"; private static final int[] RETRY_SEQUENCE = new int[] { 1, 1, 2, 3, 5, 8, 13, 20}; - private static final Logger logger = LoggerFactory.getLogger(AuditStackServiceData.class); + private static final Logger logger = LoggerFactory.getLogger(AuditCreateStackService.class); @Autowired public HeatStackAudit heatStackAudit; @@ -56,7 +55,7 @@ public class AuditStackServiceData { boolean success = false; try { logger.info("Executing External Task Audit Inventory, Retry Number: {} \n {}", auditInventory,externalTask.getRetries()); - success=heatStackAudit.auditHeatStack(auditInventory.getCloudRegion(), auditInventory.getCloudOwner(), + success=heatStackAudit.auditHeatStackCreate(auditInventory.getCloudRegion(), auditInventory.getCloudOwner(), auditInventory.getTenantId(), auditInventory.getHeatStackName()); } catch (Exception e) { logger.error("Error during audit of stack", e); @@ -72,7 +71,7 @@ public class AuditStackServiceData { }else if(externalTask.getRetries() != null && externalTask.getRetries()-1 == 0){ logger.debug("The External Task Id: {} Failed, All Retries Exhausted", externalTask.getId()); - externalTaskService.handleBpmnError(externalTask, "AuditAAIInventoryFailure"); + externalTaskService.handleBpmnError(externalTask, "AuditAAIInventoryFailure", "Number of Retries Exceeded auditing inventory"); }else{ logger.debug("The External Task Id: {} Failed, Decrementing Retries: {} , Retry Delay: ", externalTask.getId(),externalTask.getRetries()-1, calculateRetryDelay(externalTask.getRetries())); externalTaskService.handleFailure(externalTask, UNABLE_TO_FIND_ALL_V_SERVERS_AND_L_INTERACES_IN_A_AI, UNABLE_TO_FIND_ALL_V_SERVERS_AND_L_INTERACES_IN_A_AI, externalTask.getRetries()-1, calculateRetryDelay(externalTask.getRetries())); 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 new file mode 100644 index 0000000000..66d8fbd47c --- /dev/null +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditDeleteStackService.java @@ -0,0 +1,90 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.adapters.audit; + +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.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.slf4j.MDC; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.env.Environment; +import org.springframework.stereotype.Component; + +@Component +public class AuditDeleteStackService { + + private static final String UNABLE_TO_FIND_ALL_V_SERVERS_AND_L_INTERACES_IN_A_AI = "All VServers have not been deleted in A&AI"; + + private static final int[] RETRY_SEQUENCE = new int[] { 1, 1, 2, 3, 5, 8, 13, 20}; + + + private static final Logger logger = LoggerFactory.getLogger(AuditDeleteStackService.class); + + @Autowired + public HeatStackAudit heatStackAudit; + + @Autowired + public Environment env; + + protected void executeExternalTask(ExternalTask externalTask, ExternalTaskService externalTaskService){ + AuditInventory auditInventory = externalTask.getVariable("auditInventory"); + setupMDC(externalTask); + boolean success = false; + try { + logger.info("Executing External Task Audit Inventory, Retry Number: {} \n {}", auditInventory,externalTask.getRetries()); + success=heatStackAudit.auditHeatStackDeleted(auditInventory.getCloudRegion(), auditInventory.getCloudOwner(), + auditInventory.getTenantId(), auditInventory.getHeatStackName()); + } catch (Exception e) { + logger.error("Error during audit of stack", e); + } + + if (success) { + externalTaskService.complete(externalTask); + logger.debug("The External Task Id: {} Successful", externalTask.getId()); + } else { + if(externalTask.getRetries() == null){ + logger.debug("The External Task Id: {} Failed, Setting Retries to Default Start Value: {}", externalTask.getId(),RETRY_SEQUENCE.length); + externalTaskService.handleFailure(externalTask, UNABLE_TO_FIND_ALL_V_SERVERS_AND_L_INTERACES_IN_A_AI, UNABLE_TO_FIND_ALL_V_SERVERS_AND_L_INTERACES_IN_A_AI, RETRY_SEQUENCE.length, 10000); + }else if(externalTask.getRetries() != null && + externalTask.getRetries()-1 == 0){ + logger.debug("The External Task Id: {} Failed, All Retries Exhausted", externalTask.getId()); + externalTaskService.complete(externalTask); + }else{ + logger.debug("The External Task Id: {} Failed, Decrementing Retries: {} , Retry Delay: ", externalTask.getId(),externalTask.getRetries()-1, calculateRetryDelay(externalTask.getRetries())); + externalTaskService.handleFailure(externalTask, UNABLE_TO_FIND_ALL_V_SERVERS_AND_L_INTERACES_IN_A_AI, UNABLE_TO_FIND_ALL_V_SERVERS_AND_L_INTERACES_IN_A_AI, externalTask.getRetries()-1, calculateRetryDelay(externalTask.getRetries())); + } + logger.debug("The External Task Id: {} Failed", externalTask.getId()); + } + } + private void setupMDC(ExternalTask externalTask) { + String msoRequestId = (String)externalTask.getVariable("mso-request-id"); + if(msoRequestId != null && !msoRequestId.isEmpty()) + MDC.put(ONAPLogConstants.MDCs.REQUEST_ID, msoRequestId); + } + protected long calculateRetryDelay(int currentRetries){ + int retrySequence = RETRY_SEQUENCE.length - currentRetries; + long retryMultiplier = Long.parseLong(env.getProperty("mso.workflow.topics.retryMultiplier","6000")); + return RETRY_SEQUENCE[retrySequence] * retryMultiplier; + } +} 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 499c1137c7..6ea14dcac7 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 @@ -46,10 +46,30 @@ public class AuditStackService { public Environment env; @Autowired - private AuditStackServiceData auditStack; + private AuditCreateStackService auditCreateStack; + + @Autowired + private AuditDeleteStackService auditDeleteStack; @PostConstruct - public void auditAAIInventory() { + public void auditAddAAIInventory() { + String auth = ""; + try { + auth = CryptoUtils.decrypt(env.getRequiredProperty("mso.auth"), env.getRequiredProperty("mso.msoKey")); + } catch (IllegalStateException | GeneralSecurityException e) { + logger.error("Error Decrypting Password", e); + } + ClientRequestInterceptor interceptor = new BasicAuthProvider(env.getRequiredProperty("mso.config.cadi.aafId"), + auth); + ExternalTaskClient client = ExternalTaskClient.create() + .baseUrl(env.getRequiredProperty("mso.workflow.endpoint")).maxTasks(1).addInterceptor(interceptor) + .asyncResponseTimeout(120000).build(); + client.subscribe("InventoryAddAudit").lockDuration(60000) + .handler(auditCreateStack::executeExternalTask).open(); + } + + @PostConstruct + public void auditDeleteAAIInventory() { String auth = ""; try { auth = CryptoUtils.decrypt(env.getRequiredProperty("mso.auth"), env.getRequiredProperty("mso.msoKey")); @@ -60,9 +80,9 @@ public class AuditStackService { auth); ExternalTaskClient client = ExternalTaskClient.create() .baseUrl(env.getRequiredProperty("mso.workflow.endpoint")).maxTasks(1).addInterceptor(interceptor) - .asyncResponseTimeout(120000).backoffStrategy(new ExponentialBackoffStrategy(10000, 2, 120000)).build(); - client.subscribe("InventoryAudit").lockDuration(60000) - .handler(auditStack::executeExternalTask).open(); + .asyncResponseTimeout(120000).build(); + client.subscribe("InventoryDeleteAudit").lockDuration(60000) + .handler(auditDeleteStack::executeExternalTask).open(); } } 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 6e6ecd51d4..c81dac7c6f 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 @@ -39,23 +39,32 @@ import org.springframework.stereotype.Component; public class AuditVServer extends AbstractAudit { private static final Logger logger = LoggerFactory.getLogger(AuditVServer.class); - public boolean auditVservers(Set<Vserver> vServersToAudit, String tenantId, String cloudOwner, String cloudRegion) { + public boolean auditAllVserversDoExist(Set<Vserver> vServersToAudit, String tenantId, String cloudOwner, String cloudRegion) { if (vServersToAudit == null || vServersToAudit.isEmpty()){ return false; } return vServersToAudit.stream() - .filter(vServer -> !doesVServerExistInAAI(vServer, tenantId, cloudOwner, cloudRegion)).findFirst() + .filter(vServer -> !doesVServerExistInAAI(vServer, tenantId, cloudOwner, cloudRegion,true)).findFirst() + .map(v -> false).orElse(true); + } + + public boolean auditAllVserversDoNotExist(Set<Vserver> vServersToAudit, String tenantId, String cloudOwner, String cloudRegion) { + if (vServersToAudit == null || vServersToAudit.isEmpty()){ + return true; + } + return vServersToAudit.stream() + .filter(vServer -> doesVServerExistInAAI(vServer, tenantId, cloudOwner, cloudRegion,false)).findFirst() .map(v -> false).orElse(true); } - private boolean doesVServerExistInAAI(Vserver vServer, String tenantId, String cloudOwner, String cloudRegion) { + private boolean doesVServerExistInAAI(Vserver vServer, String tenantId, String cloudOwner, String cloudRegion, boolean checkLinterfaces) { AAIResourceUri vserverURI = AAIUriFactory.createResourceUri(AAIObjectType.VSERVER, cloudOwner, cloudRegion, tenantId, vServer.getVserverId()); boolean vServerExists = getAaiClient().exists(vserverURI); boolean doesExist = getAaiClient().exists(vserverURI); logger.info("v-server {} exists: {}", vServer.getVserverId(), doesExist); boolean allNeutronNetworksExist = true; - if (vServerExists && vServer.getLInterfaces() != null) { + if (vServerExists && vServer.getLInterfaces() != null && checkLinterfaces) { allNeutronNetworksExist = vServer.getLInterfaces() .getLInterface().stream().filter(lInterface -> !doesLinterfaceExistinAAI(lInterface, vServer.getVserverId(), tenantId, cloudOwner, cloudRegion)) 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 da833c7b07..19e3ab71f5 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 @@ -57,26 +57,51 @@ public class HeatStackAudit { @Autowired protected AuditVServer auditVservers; - public boolean auditHeatStack(String cloudRegion, String cloudOwner, String tenantId, String heatStackName) { + public boolean auditHeatStackCreate(String cloudRegion, String cloudOwner, String tenantId, String heatStackName) { try { - logger.debug("Fetching Top Level Stack Information"); - Resources resources = heat.queryStackResources(cloudRegion, tenantId, heatStackName); - List<Resource> novaResources = resources.getList().stream() - .filter(p -> "OS::Nova::Server".equals(p.getType())).collect(Collectors.toList()); - List<Resource> resourceGroups = resources.getList().stream() - .filter(p -> "OS::Heat::ResourceGroup".equals(p.getType()) && p.getName().contains("subinterfaces")).collect(Collectors.toList()); - if(novaResources.isEmpty()) - return true; - else{ - Set<Vserver> vserversToAudit = createVserverSet(resources, novaResources); - Set<Vserver> vserversWithSubInterfaces = processSubInterfaces(cloudRegion, tenantId, resourceGroups, - vserversToAudit); - return auditVservers.auditVservers(vserversWithSubInterfaces, tenantId, cloudOwner, cloudRegion); - } + return auditStack(cloudRegion,cloudOwner,tenantId,heatStackName,true); } catch (Exception e) { logger.error("Error during auditing stack resources", e); return false; } + } + + public boolean auditHeatStackDeleted(String cloudRegion, String cloudOwner, String tenantId, String heatStackName) { + try { + return auditStack(cloudRegion,cloudOwner,tenantId,heatStackName,false); + } catch (Exception e) { + logger.error("Error during auditing stack resources", e); + return false; + } + } + + private boolean auditStack(String cloudRegion, String cloudOwner, String tenantId, String heatStackName,boolean isCreateAudit) throws Exception{ + logger.debug("Fetching Top Level Stack Information"); + Resources resources = heat.queryStackResources(cloudRegion, tenantId, heatStackName); + List<Resource> novaResources = extractNovaResources(resources); + if(novaResources.isEmpty()) + return true; + else{ + List<Resource> resourceGroups = extractResourceGroups(resources); + Set<Vserver> vserversToAudit = createVserverSet(resources, novaResources); + Set<Vserver> vserversWithSubInterfaces = processSubInterfaces(cloudRegion, tenantId, resourceGroups, + vserversToAudit); + if(isCreateAudit){ + return auditVservers.auditAllVserversDoExist(vserversWithSubInterfaces, tenantId, cloudOwner, cloudRegion); + }else{ + return auditVservers.auditAllVserversDoNotExist(vserversWithSubInterfaces, tenantId, cloudOwner, cloudRegion); + } + } + } + + private List<Resource> extractResourceGroups(Resources resources) { + return resources.getList().stream() + .filter(p -> "OS::Heat::ResourceGroup".equals(p.getType()) && p.getName().contains("subinterfaces")).collect(Collectors.toList()); + } + + private List<Resource> extractNovaResources(Resources resources) { + return resources.getList().stream() + .filter(p -> "OS::Nova::Server".equals(p.getType())).collect(Collectors.toList()); } protected Set<Vserver> processSubInterfaces(String cloudRegion, String tenantId, List<Resource> resourceGroups, @@ -208,5 +233,4 @@ public class HeatStackAudit { return Optional.empty(); } - } diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/network/NetworkAdapterRest.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/network/NetworkAdapterRest.java index 8f9152a86d..253f13d57d 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/network/NetworkAdapterRest.java +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/network/NetworkAdapterRest.java @@ -90,6 +90,7 @@ public class NetworkAdapterRest { @Autowired private MsoNetworkAdapterImpl adapter; + @Autowired private Provider<BpelRestClient> bpelRestClientProvider; diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/BpelRestClient.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/BpelRestClient.java index 7265a59397..8a5a083c63 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/BpelRestClient.java +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/BpelRestClient.java @@ -59,7 +59,7 @@ import org.springframework.stereotype.Component; * org.onap.so.adapters.vnf.retrylist list of response codes that will trigger a retry (the special code * 900 means "connection was not established") */ -@Component() +@Component @Scope("prototype") public class BpelRestClient { public static final String MSO_PROP_VNF_ADAPTER = "MSO_PROP_VNF_ADAPTER"; diff --git a/adapters/mso-openstack-adapters/src/main/resources/application.yaml b/adapters/mso-openstack-adapters/src/main/resources/application.yaml index 4e8d389998..cdd04b8c21 100644 --- a/adapters/mso-openstack-adapters/src/main/resources/application.yaml +++ b/adapters/mso-openstack-adapters/src/main/resources/application.yaml @@ -30,8 +30,19 @@ spring: ddl-auto: validate naming-strategy: org.hibernate.cfg.ImprovedNamingStrategy enable-lazy-load-no-trans: true - - +org: + onap: + so: + adapters: + default_keystone_url_version: /v2.0 + default_keystone_reg_ex: "/[vV][0-9]" + po: + retryCodes: 504 + retryDelay: 5 + retryCount: 3 + pollTimeout: 7500 + pollInterval: 15 + #Actuator management: endpoints: 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/AuditCreateStackServiceTest.java index d7739e56f6..bcf126d887 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/AuditCreateStackServiceTest.java @@ -40,10 +40,10 @@ import org.springframework.core.env.Environment; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonMappingException; -public class AuditStackServiceDataTest extends AuditStackServiceData { +public class AuditCreateStackServiceTest extends AuditCreateStackService { @InjectMocks - AuditStackServiceData auditStackService = new AuditStackServiceData(); + AuditCreateStackService auditStackService = new AuditCreateStackService(); @Mock HeatStackAudit heatStackAuditMock; @@ -73,14 +73,14 @@ public class AuditStackServiceDataTest extends AuditStackServiceData { @Test public void execute_external_task_audit_success_Test() { - doReturn(true).when(heatStackAuditMock).auditHeatStack("cloudRegion", "cloudOwner", "tenantId", "stackName"); + doReturn(true).when(heatStackAuditMock).auditHeatStackCreate("cloudRegion", "cloudOwner", "tenantId", "stackName"); auditStackService.executeExternalTask(mockExternalTask, mockExternalTaskService); Mockito.verify(mockExternalTaskService).complete(mockExternalTask); } @Test public void execute_external_task_audit_first_failure_Test() { - doReturn(false).when(heatStackAuditMock).auditHeatStack("cloudRegion", "cloudOwner", "tenantId", "stackName"); + doReturn(false).when(heatStackAuditMock).auditHeatStackCreate("cloudRegion", "cloudOwner", "tenantId", "stackName"); doReturn(null).when(mockExternalTask).getRetries(); auditStackService.executeExternalTask(mockExternalTask, mockExternalTaskService); Mockito.verify(mockExternalTaskService).handleFailure(mockExternalTask, @@ -90,7 +90,7 @@ public class AuditStackServiceDataTest extends AuditStackServiceData { @Test public void execute_external_task_audit_intermediate_failure_Test() { - doReturn(false).when(heatStackAuditMock).auditHeatStack("cloudRegion", "cloudOwner", "tenantId", "stackName"); + doReturn(false).when(heatStackAuditMock).auditHeatStackCreate("cloudRegion", "cloudOwner", "tenantId", "stackName"); doReturn(6).when(mockExternalTask).getRetries(); auditStackService.executeExternalTask(mockExternalTask, mockExternalTaskService); Mockito.verify(mockExternalTaskService).handleFailure(mockExternalTask, @@ -101,11 +101,11 @@ public class AuditStackServiceDataTest extends AuditStackServiceData { @Test public void execute_external_task_audit_final_failure_Test() { - doReturn(false).when(heatStackAuditMock).auditHeatStack("cloudRegion", "cloudOwner", "tenantId", "stackName"); + doReturn(false).when(heatStackAuditMock).auditHeatStackCreate("cloudRegion", "cloudOwner", "tenantId", "stackName"); doReturn(1).when(mockExternalTask).getRetries(); auditStackService.executeExternalTask(mockExternalTask, mockExternalTaskService); Mockito.verify(mockExternalTaskService).handleBpmnError(mockExternalTask, - "AuditAAIInventoryFailure"); + "AuditAAIInventoryFailure", "Number of Retries Exceeded auditing inventory"); } @Test 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 02557d8c20..9176b58de8 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 @@ -58,8 +58,6 @@ import com.woorea.openstack.heat.model.Resources; @RunWith(MockitoJUnitRunner.Silent.class) public class AuditVServerTest extends AuditVServer { - private ObjectMapper objectMapper = new ObjectMapper(); - @InjectMocks private AuditVServer auditNova = new AuditVServer(); @@ -225,9 +223,13 @@ public class AuditVServerTest extends AuditVServer { @Test public void audit_Vserver_Empty_HashSet() throws JsonParseException, JsonMappingException, IOException { - boolean exists = auditNova.auditVservers(new HashSet<Vserver>(), tenantId, cloudOwner, cloudRegion); + boolean exists = auditNova.auditAllVserversDoExist(new HashSet<Vserver>(), tenantId, cloudOwner, cloudRegion); assertEquals(false, exists); + + boolean doNotExist = auditNova.auditAllVserversDoNotExist(new HashSet<Vserver>(), tenantId, cloudOwner, cloudRegion); + assertEquals(true, doNotExist); } + @Test public void audit_Vserver_Found_Test() throws JsonParseException, JsonMappingException, IOException { @@ -246,8 +248,11 @@ public class AuditVServerTest extends AuditVServer { doReturn(true).when(aaiResourcesMock).exists(service1_sub_0_uri); doReturn(true).when(aaiResourcesMock).exists(service1_sub_1_uri); - boolean exists = auditNova.auditVservers(vserversToAudit, tenantId, cloudOwner, cloudRegion); + boolean exists = auditNova.auditAllVserversDoExist(vserversToAudit, tenantId, cloudOwner, cloudRegion); assertEquals(true, exists); + + boolean doNotExist = auditNova.auditAllVserversDoNotExist(vserversToAudit, tenantId, cloudOwner, cloudRegion); + assertEquals(false, doNotExist); } @Test @@ -268,8 +273,11 @@ public class AuditVServerTest extends AuditVServer { doReturn(true).when(aaiResourcesMock).exists(service1_sub_0_uri); doReturn(true).when(aaiResourcesMock).exists(service1_sub_1_uri); - boolean exists = auditNova.auditVservers(vserversToAudit, tenantId, cloudOwner, cloudRegion); + boolean exists = auditNova.auditAllVserversDoExist(vserversToAudit, tenantId, cloudOwner, cloudRegion); assertEquals(false, exists); + + boolean doNotExist = auditNova.auditAllVserversDoNotExist(vserversToAudit, tenantId, cloudOwner, cloudRegion); + assertEquals(false, doNotExist); } @Test @@ -288,16 +296,23 @@ public class AuditVServerTest extends AuditVServer { doReturn(true).when(aaiResourcesMock).exists(service2_sub_1_uri); doReturn(true).when(aaiResourcesMock).exists(service1_sub_0_uri); doReturn(true).when(aaiResourcesMock).exists(service1_sub_1_uri); - boolean exists = auditNova.auditVservers(vserversToAudit, tenantId, cloudOwner, cloudRegion); + boolean exists = auditNova.auditAllVserversDoExist(vserversToAudit, tenantId, cloudOwner, cloudRegion); assertEquals(false, exists); + + boolean doNotExist = auditNova.auditAllVserversDoNotExist(vserversToAudit, tenantId, cloudOwner, cloudRegion); + assertEquals(false, doNotExist); } @Test - public void audit_Vserver_Not_Found_Test() throws JsonParseException, JsonMappingException, IOException { + public void audit_Vservers_Not_Found_Test() throws JsonParseException, JsonMappingException, IOException { doReturn(false).when(aaiResourcesMock).exists(vserverURI); doReturn(false).when(aaiResourcesMock).exists(vserverURI2); - boolean exists = auditNova.auditVservers(vserversToAudit, tenantId, cloudOwner, cloudRegion); + + boolean exists = auditNova.auditAllVserversDoExist(vserversToAudit, tenantId, cloudOwner, cloudRegion); assertEquals(false, exists); + + boolean doNotExist = auditNova.auditAllVserversDoNotExist(vserversToAudit, tenantId, cloudOwner, cloudRegion); + assertEquals(true, doNotExist); } @Test @@ -306,8 +321,11 @@ public class AuditVServerTest extends AuditVServer { doReturn(true).when(aaiResourcesMock).exists(vserverURI2); doReturn(Optional.of(test_port_1_plural)).when(aaiResourcesMock).get(LInterface.class,test_port_1_uri); doReturn(Optional.of(test_port_2_plural)).when(aaiResourcesMock).get(LInterface.class,test_port_2_uri); - boolean exists = auditNova.auditVservers(vserversToAudit, tenantId, cloudOwner, cloudRegion); + boolean exists = auditNova.auditAllVserversDoExist(vserversToAudit, tenantId, cloudOwner, cloudRegion); assertEquals(false, exists); + + boolean doNotExist = auditNova.auditAllVserversDoNotExist(vserversToAudit, tenantId, cloudOwner, cloudRegion); + assertEquals(false, doNotExist); } @Test @@ -325,8 +343,12 @@ public class AuditVServerTest extends AuditVServer { doReturn(true).when(aaiResourcesMock).exists(service1_sub_0_uri); doReturn(true).when(aaiResourcesMock).exists(service1_sub_1_uri); doReturn(false).when(aaiResourcesMock).exists(vserverURI2); - boolean exists = auditNova.auditVservers(vserversToAudit, tenantId, cloudOwner, cloudRegion); + + boolean exists = auditNova.auditAllVserversDoExist(vserversToAudit, tenantId, cloudOwner, cloudRegion); assertEquals(false, exists); + + boolean doNotExist = auditNova.auditAllVserversDoNotExist(vserversToAudit, tenantId, cloudOwner, cloudRegion); + assertEquals(false, doNotExist); } } diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/HeatStackAuditTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/HeatStackAuditTest.java index 696784110b..5eea46d09f 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/HeatStackAuditTest.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/HeatStackAuditTest.java @@ -203,7 +203,7 @@ public class HeatStackAuditTest extends HeatStackAudit { Resources getResource = objectMapper.readValue(new File("src/test/resources/Service1ResourceGroupResponse.json"), Resources.class); doReturn(getResource).when(msoHeatUtilsMock).queryStackResources(cloudRegion, tenantId, "heatStackName"); - boolean actual = heatStackAudit.auditHeatStack(cloudRegion, "cloudOwner", tenantId, "heatStackName"); + boolean actual = heatStackAudit.auditHeatStackCreate(cloudRegion, "cloudOwner", tenantId, "heatStackName"); assertEquals(true, actual); } diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfMulticloudAdapterImplTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfMulticloudAdapterImplTest.java index 75cea9eafc..376076a0a0 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfMulticloudAdapterImplTest.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfMulticloudAdapterImplTest.java @@ -65,7 +65,7 @@ public class MsoVnfMulticloudAdapterImplTest extends BaseRestTestUtils{ @Test public void createVfModule() throws Exception { - //expectedException.expect(VnfException.class); + Map<String, Object> stackInputs = new HashMap<>(); stackInputs.put("oof_directives", "{}"); stackInputs.put("sdnc_directives", "{}"); |