summaryrefslogtreecommitdiffstats
path: root/adapters/mso-openstack-adapters
diff options
context:
space:
mode:
authorBenjamin, Max (mb388a) <mb388a@us.att.com>2019-02-14 19:54:00 -0500
committerBenjamin, Max (mb388a) <mb388a@us.att.com>2019-02-14 19:55:59 -0500
commitf950d102e204be4f23b675997648c370ad2c0c3b (patch)
treebc2adc620f5c82625c7ec6605f45b313344cbf70 /adapters/mso-openstack-adapters
parent1d69925fef5c972f045081db9b5e4795d96c6f84 (diff)
fix issue where we attempt audit with no servers
fix issue where we attempt audit with no servers Change-Id: I47f76121c616bf65a5f8be73910adcc0d7088bdb Issue-ID: SO-1513 Signed-off-by: Benjamin, Max (mb388a) <mb388a@us.att.com>
Diffstat (limited to 'adapters/mso-openstack-adapters')
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditStackService.java2
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditStackServiceData.java8
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/HeatStackAudit.java12
-rw-r--r--adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/HeatStackAuditTest.java11
-rw-r--r--adapters/mso-openstack-adapters/src/test/resources/GetResourcesNoServer.json25
5 files changed, 53 insertions, 5 deletions
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 38b00688a7..aace75ff99 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
@@ -60,7 +60,7 @@ public class AuditStackService {
auth);
ExternalTaskClient client = ExternalTaskClient.create()
.baseUrl(env.getRequiredProperty("mso.workflow.endpoint")).maxTasks(5).addInterceptor(interceptor)
- .asyncResponseTimeout(120000).backoffStrategy(new ExponentialBackoffStrategy(0, 0, 0)).build();
+ .asyncResponseTimeout(120000).backoffStrategy(new ExponentialBackoffStrategy(5000, 2, 30000)).build();
client.subscribe("InventoryAudit").lockDuration(5000)
.handler(auditStack::executeExternalTask).open();
}
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/AuditStackServiceData.java
index b0369395ed..ffbe1b4c46 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/AuditStackServiceData.java
@@ -24,9 +24,11 @@ import java.util.Collections;
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;
@@ -49,6 +51,7 @@ public class AuditStackServiceData {
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());
@@ -78,6 +81,11 @@ public class AuditStackServiceData {
}
+ 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"));
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 dfe5912fbf..da833c7b07 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
@@ -65,10 +65,14 @@ public class HeatStackAudit {
.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());
- Set<Vserver> vserversToAudit = createVserverSet(resources, novaResources);
- Set<Vserver> vserversWithSubInterfaces = processSubInterfaces(cloudRegion, tenantId, resourceGroups,
- vserversToAudit);
- return auditVservers.auditVservers(vserversWithSubInterfaces, tenantId, cloudOwner, cloudRegion);
+ 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);
+ }
} catch (Exception e) {
logger.error("Error during auditing stack resources", e);
return false;
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 b3cdd467bb..696784110b 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
@@ -196,6 +196,17 @@ public class HeatStackAuditTest extends HeatStackAudit {
JSONAssert.assertEquals(expectedValue, actualValue, false);
}
+ @Test
+ public void auditHeatStackNoServers_Test() throws Exception{
+
+
+ Resources getResource = objectMapper.readValue(new File("src/test/resources/Service1ResourceGroupResponse.json"), Resources.class);
+ doReturn(getResource).when(msoHeatUtilsMock).queryStackResources(cloudRegion, tenantId, "heatStackName");
+
+ boolean actual = heatStackAudit.auditHeatStack(cloudRegion, "cloudOwner", tenantId, "heatStackName");
+ assertEquals(true, actual);
+ }
+
@Test
public void findInterfaceInformation_Test(){
diff --git a/adapters/mso-openstack-adapters/src/test/resources/GetResourcesNoServer.json b/adapters/mso-openstack-adapters/src/test/resources/GetResourcesNoServer.json
new file mode 100644
index 0000000000..cfc9e5a0f1
--- /dev/null
+++ b/adapters/mso-openstack-adapters/src/test/resources/GetResourcesNoServer.json
@@ -0,0 +1,25 @@
+{
+ "resources": [
+ {
+ "resource_name": "OAMFW_SECURITY_GROUP",
+ "links": [
+ {
+ "href": "http://orchestration.com:443/v1/872f331350c54e59991a8de2cbffb40c/stacks/zauk51bfrwl03_base_NC_01/08c898a4-ba71-4365-9681-993d4129164a/resources/OAMFW_SECURITY_GROUP",
+ "rel": "self"
+ },
+ {
+ "href": "http://orchestration.com:443/v1/872f331350c54e59991a8de2cbffb40c/stacks/zauk51bfrwl03_base_NC_01/08c898a4-ba71-4365-9681-993d4129164a",
+ "rel": "stack"
+ }
+ ],
+ "logical_resource_id": "OAMFW_SECURITY_GROUP",
+ "creation_time": "2019-02-13T21:17:03Z",
+ "resource_status": "CREATE_COMPLETE",
+ "updated_time": "2019-02-13T21:17:03Z",
+ "required_by": [],
+ "resource_status_reason": "state changed",
+ "physical_resource_id": "420833ff-2733-4043-868c-2f2d5bee8f93",
+ "resource_type": "OS::Neutron::SecurityGroup"
+ }
+ ]
+} \ No newline at end of file