summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSmokowski, Steven <steve.smokowski@att.com>2019-06-09 10:39:47 -0400
committerBenjamin, Max (mb388a) <mb388a@us.att.com>2019-06-09 10:39:53 -0400
commit6370f8f99b9cea4e1b3e2010c380f6e9c22aa18f (patch)
treeacd482f3cd1954fc0f5d95c97d5be479a398c096
parent242e71883f59b8ad971f77c9bbdf032527fd77c0 (diff)
Update stack save to only save the params object
use get parameters not store entire request of stack Update stack save to only save off the params object Change-Id: I41e0e03b412e37f12d348c84a1512c9bf4403748 Issue-ID: SO-2002 Signed-off-by: Benjamin, Max (mb388a) <mb388a@us.att.com>
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatUtils.java6
-rw-r--r--adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoHeatUtilsTest.java40
2 files changed, 20 insertions, 26 deletions
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 b634b0c3a5..c323bb699d 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
@@ -253,7 +253,7 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin {
protected Stack createStack(CreateStackParam stack, String cloudSiteId, String tenantId) throws MsoException {
try {
OpenStackRequest<Stack> request = getHeatClient(cloudSiteId, tenantId).getStacks().create(stack);
- saveStackRequest(request, MDC.get(ONAPLogConstants.MDCs.REQUEST_ID), stack.getStackName());
+ saveStackRequest(stack, MDC.get(ONAPLogConstants.MDCs.REQUEST_ID), stack.getStackName());
return executeAndRecordOpenstackRequest(request);
} catch (OpenStackResponseException e) {
if (e.getStatus() == 409) {
@@ -341,11 +341,11 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin {
}
}
- protected void saveStackRequest(OpenStackRequest<Stack> request, String requestId, String stackName) {
+ protected void saveStackRequest(CreateStackParam request, String requestId, String stackName) {
try {
ObjectMapper mapper = new ObjectMapper();
InfraActiveRequests foundRequest = requestDBClient.getInfraActiveRequestbyRequestId(requestId);
- String stackRequest = mapper.writeValueAsString(request.entity());
+ String stackRequest = mapper.writeValueAsString(request.getParameters());
CloudApiRequests cloudReq = new CloudApiRequests();
cloudReq.setCloudIdentifier(stackName);
cloudReq.setRequestBody(stackRequest);
diff --git a/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoHeatUtilsTest.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoHeatUtilsTest.java
index 28ad069f8b..6673e69a09 100644
--- a/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoHeatUtilsTest.java
+++ b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoHeatUtilsTest.java
@@ -34,7 +34,9 @@ import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.times;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -52,7 +54,6 @@ import org.onap.so.openstack.exceptions.MsoException;
import org.onap.so.openstack.exceptions.MsoOpenstackException;
import org.onap.so.openstack.exceptions.MsoStackAlreadyExists;
import org.springframework.core.env.Environment;
-import com.woorea.openstack.base.client.Entity;
import com.woorea.openstack.base.client.OpenStackResponseException;
import com.woorea.openstack.heat.Heat;
import com.woorea.openstack.heat.StackResource;
@@ -122,7 +123,6 @@ public class MsoHeatUtilsTest extends MsoHeatUtils {
latestStack.setStackName("stackName");
latestStack.setStackStatus("CREATE_COMPLETE");
latestStack.setStackStatusReason("Stack Finished");
- doNothing().when(stackStatusHandler).updateStackStatus(stack);
doReturn(latestStack).when(heatUtils).queryHeatStack(isA(Heat.class), eq("stackName/id"));
doReturn(heatClient).when(heatUtils).getHeatClient(cloudSiteId, tenantId);
Stack actual = heatUtils.pollStackForStatus(1, stack, "CREATE_IN_PROGRESS", cloudSiteId, tenantId);
@@ -397,26 +397,23 @@ public class MsoHeatUtilsTest extends MsoHeatUtils {
heatUtils.createStack(createStackParam, cloudSiteId, tenantId);
Mockito.verify(stackResource, times(1)).create(createStackParam);
- Mockito.verify(heatUtils, times(1)).saveStackRequest(eq(mockCreateStack), isNull(), eq("stackName"));
+ Mockito.verify(heatUtils, times(1)).saveStackRequest(eq(createStackParam), isNull(), eq("stackName"));
Mockito.verify(heatClient, times(1)).getStacks();
Mockito.verify(stackResource, times(1)).create(createStackParam);
}
@Test
public final void saveStack_Test() throws MsoException, IOException, NovaClientException {
- Stack stack = new Stack();
- stack.setId("id");
- stack.setStackName("stackName");
- stack.setStackStatus("CREATE_FAILED");
- stack.setStackStatusReason(
- "Resource CREATE failed: Conflict: resources.my_keypair: Key pair 'hst3bbfnm0011vm001' already exists. (HTTP 409) (Request-ID: req-941b0af6-63ae-4d6a-afbc-90b728bacf82");
- Entity<Stack> entity = new Entity(stack, "application/json");
- doReturn(entity).when(mockCreateStack).entity();
+ CreateStackParam createStackParam = new CreateStackParam();
+ createStackParam.setStackName("stackName");
+ Map<String, Object> parameters = new HashMap<String, Object>();
+ parameters.put("test", "value");
+ createStackParam.setParameters(parameters);
InfraActiveRequests request = new InfraActiveRequests();
request.setRequestId("requestId");
doReturn(request).when(requestDbClient).getInfraActiveRequestbyRequestId("requestId");
doNothing().when(requestDbClient).updateInfraActiveRequests(request);
- heatUtils.saveStackRequest(mockCreateStack, "requestId", "stackName");
+ heatUtils.saveStackRequest(createStackParam, "requestId", "stackName");
Mockito.verify(requestDbClient, times(1)).updateInfraActiveRequests(request);
assertNotNull(request.getCloudApiRequests().get(0));
assertEquals(request.getCloudApiRequests().get(0).getRequestId(), "requestId");
@@ -424,14 +421,11 @@ public class MsoHeatUtilsTest extends MsoHeatUtils {
@Test
public final void saveStack__Exists_Test() throws MsoException, IOException, NovaClientException {
- Stack stack = new Stack();
- stack.setId("id");
- stack.setStackName("stackName");
- stack.setStackStatus("CREATE_FAILED");
- stack.setStackStatusReason(
- "Resource CREATE failed: Conflict: resources.my_keypair: Key pair 'hst3bbfnm0011vm001' already exists. (HTTP 409) (Request-ID: req-941b0af6-63ae-4d6a-afbc-90b728bacf82");
- Entity<Stack> entity = new Entity(stack, "application/json");
- doReturn(entity).when(mockCreateStack).entity();
+ CreateStackParam createStackParam = new CreateStackParam();
+ createStackParam.setStackName("stackName");
+ Map<String, Object> parameters = new HashMap<String, Object>();
+ parameters.put("test", "value");
+ createStackParam.setParameters(parameters);
InfraActiveRequests request = new InfraActiveRequests();
request.setRequestId("requestId");
CloudApiRequests cloudRequest = new CloudApiRequests();
@@ -441,7 +435,7 @@ public class MsoHeatUtilsTest extends MsoHeatUtils {
request.getCloudApiRequests().add(cloudRequest);
doReturn(request).when(requestDbClient).getInfraActiveRequestbyRequestId("requestId");
doNothing().when(requestDbClient).updateInfraActiveRequests(request);
- heatUtils.saveStackRequest(mockCreateStack, "requestId", "stackName");
+ heatUtils.saveStackRequest(createStackParam, "requestId", "stackName");
Mockito.verify(requestDbClient, times(1)).updateInfraActiveRequests(request);
assertNotNull(request.getCloudApiRequests().get(0));
assertEquals("requestId", request.getCloudApiRequests().get(0).getRequestId());
@@ -463,7 +457,7 @@ public class MsoHeatUtilsTest extends MsoHeatUtils {
exceptionRule.expectMessage("Unknown Error");
heatUtils.createStack(createStackParam, cloudSiteId, tenantId);
Mockito.verify(stackResource, times(1)).create(createStackParam);
- Mockito.verify(heatUtils, times(1)).saveStackRequest(eq(mockCreateStack), isNull(), eq("stackName"));
+ Mockito.verify(heatUtils, times(1)).saveStackRequest(eq(createStackParam), isNull(), eq("stackName"));
Mockito.verify(heatClient, times(1)).getStacks();
Mockito.verify(stackResource, times(1)).create(createStackParam);
}
@@ -483,7 +477,7 @@ public class MsoHeatUtilsTest extends MsoHeatUtils {
exceptionRule.expectMessage("Stack stackName already exists in Tenant tenantId in Cloud cloudSiteId");
heatUtils.createStack(createStackParam, cloudSiteId, tenantId);
Mockito.verify(stackResource, times(1)).create(createStackParam);
- Mockito.verify(heatUtils, times(1)).saveStackRequest(eq(mockCreateStack), isNull(), eq("stackName"));
+ Mockito.verify(heatUtils, times(1)).saveStackRequest(eq(createStackParam), isNull(), eq("stackName"));
Mockito.verify(heatClient, times(1)).getStacks();
Mockito.verify(stackResource, times(1)).create(createStackParam);
}