summaryrefslogtreecommitdiffstats
path: root/adapters/mso-openstack-adapters/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'adapters/mso-openstack-adapters/src/main')
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditCreateStackService.java (renamed from adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditStackServiceData.java)9
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditDeleteStackService.java90
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditStackService.java30
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditVServer.java17
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/HeatStackAudit.java56
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/network/NetworkAdapterRest.java1
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/BpelRestClient.java2
-rw-r--r--adapters/mso-openstack-adapters/src/main/resources/application.yaml15
8 files changed, 187 insertions, 33 deletions
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: