aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSmokowski, Steven <steve.smokowski@att.com>2019-05-31 16:15:23 -0400
committerBenjamin, Max (mb388a) <mb388a@us.att.com>2019-05-31 16:15:37 -0400
commit96a2da847be40361ff8f0a27875101782fb6b80d (patch)
tree3d03f22eac888ada9c785b9d9152d54904dfc47c
parent89b396152a7f5ca62175d13342c1b3a1a9067ccb (diff)
Fix issue where request was not being updated
Fix issue where request was not being updated Change-Id: Ib4b3809797449224ac417facfaa4bf48d91a1ecb Issue-ID: SO-1966 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.java8
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/StackStatusHandler.java7
-rw-r--r--adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoHeatUtilsTest.java55
-rw-r--r--adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/StackStatusHandlerTest.java69
-rw-r--r--mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/InfraRequests.java3
-rw-r--r--mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/client/RequestsDbClient.java7
6 files changed, 145 insertions, 4 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 683bb28726..bf6374bc2f 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
@@ -350,7 +350,13 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin {
cloudReq.setCloudIdentifier(stackName);
cloudReq.setRequestBody(stackRequest);
cloudReq.setRequestId(requestId);
- foundRequest.getCloudApiRequests().add(cloudReq);
+ CloudApiRequests foundCloudReq = foundRequest.getCloudApiRequests().stream()
+ .filter(cloudReqToFind -> stackName.equals(cloudReq.getCloudIdentifier())).findAny().orElse(null);
+ if (foundCloudReq != null) {
+ foundCloudReq.setRequestBody(stackRequest);
+ } else {
+ foundRequest.getCloudApiRequests().add(cloudReq);
+ }
requestDBClient.updateInfraActiveRequests(foundRequest);
} catch (Exception e) {
logger.error("Error updating in flight request with Openstack Create Request", e);
diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/StackStatusHandler.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/StackStatusHandler.java
index 53337b33f8..df173c002d 100644
--- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/StackStatusHandler.java
+++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/StackStatusHandler.java
@@ -36,9 +36,12 @@ public class StackStatusHandler {
requestProcessingData.setName(stack.getStackName());
requestProcessingData.setTag("StackInformation");
requestProcessingData.setSoRequestId(requestId);
+ requestProcessingData.setValue(stackStatus);
+ requestDBClient.saveRequestProcessingData(requestProcessingData);
+ } else {
+ requestProcessingData.setValue(stackStatus);
+ requestDBClient.updateRequestProcessingData(requestProcessingData);
}
- requestProcessingData.setValue(stackStatus);
- requestDBClient.saveRequestProcessingData(requestProcessingData);
} catch (Exception e) {
logger.warn("Error adding stack status to request database", e);
}
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 1d38bc2431..5a2515a81e 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
@@ -23,6 +23,8 @@ package org.onap.so.openstack.utils;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isA;
import static org.mockito.ArgumentMatchers.isNull;
@@ -43,10 +45,14 @@ import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.Spy;
import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.so.db.request.beans.CloudApiRequests;
+import org.onap.so.db.request.beans.InfraActiveRequests;
+import org.onap.so.db.request.client.RequestsDbClient;
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;
@@ -68,6 +74,9 @@ public class MsoHeatUtilsTest extends MsoHeatUtils {
private MsoHeatUtils heatUtils;
@Mock
+ private RequestsDbClient requestDbClient;
+
+ @Mock
private Heat heatClient;
@Mock
@@ -394,6 +403,52 @@ public class MsoHeatUtilsTest extends MsoHeatUtils {
}
@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();
+ InfraActiveRequests request = new InfraActiveRequests();
+ request.setRequestId("requestId");
+ doReturn(request).when(requestDbClient).getInfraActiveRequestbyRequestId("requestId");
+ doNothing().when(requestDbClient).updateInfraActiveRequests(request);
+ heatUtils.saveStackRequest(mockCreateStack, "requestId", "stackName");
+ Mockito.verify(requestDbClient, times(1)).updateInfraActiveRequests(request);
+ assertNotNull(request.getCloudApiRequests().get(0));
+ assertEquals(request.getCloudApiRequests().get(0).getRequestId(), "requestId");
+ }
+
+ @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();
+ InfraActiveRequests request = new InfraActiveRequests();
+ request.setRequestId("requestId");
+ CloudApiRequests cloudRequest = new CloudApiRequests();
+ cloudRequest.setCloudIdentifier("stackName");
+ cloudRequest.setRequestBody("testMe");
+ cloudRequest.setRequestId("requestId");
+ request.getCloudApiRequests().add(cloudRequest);
+ doReturn(request).when(requestDbClient).getInfraActiveRequestbyRequestId("requestId");
+ doNothing().when(requestDbClient).updateInfraActiveRequests(request);
+ heatUtils.saveStackRequest(mockCreateStack, "requestId", "stackName");
+ Mockito.verify(requestDbClient, times(1)).updateInfraActiveRequests(request);
+ assertNotNull(request.getCloudApiRequests().get(0));
+ assertEquals("requestId", request.getCloudApiRequests().get(0).getRequestId());
+ assertNotEquals("testMe", request.getCloudApiRequests().get(0).getRequestBody());
+ }
+
+ @Test
public final void createStack_Error_Test() throws MsoException, IOException, NovaClientException {
CreateStackParam createStackParam = new CreateStackParam();
createStackParam.setStackName("stackName");
diff --git a/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/StackStatusHandlerTest.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/StackStatusHandlerTest.java
new file mode 100644
index 0000000000..54e2bbf06d
--- /dev/null
+++ b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/StackStatusHandlerTest.java
@@ -0,0 +1,69 @@
+package org.onap.so.openstack.utils;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.times;
+import java.io.IOException;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.so.db.request.beans.RequestProcessingData;
+import org.onap.so.db.request.client.RequestsDbClient;
+import org.onap.so.openstack.exceptions.MsoException;
+import com.woorea.openstack.heat.model.Stack;
+
+@RunWith(MockitoJUnitRunner.class)
+public class StackStatusHandlerTest {
+
+ @InjectMocks
+ StackStatusHandler statusHandler;
+
+ @Mock
+ RequestsDbClient requestDBClient;
+
+ @Test
+ public final void recordExists_Test() throws MsoException, IOException {
+ RequestProcessingData requestProcessingData = new RequestProcessingData();
+ requestProcessingData.setValue("testMe");
+
+ doReturn(requestProcessingData).when(requestDBClient)
+ .getRequestProcessingDataBySoRequestIdAndNameAndGrouping(null, "id", "stackName");
+ Stack latestStack = new Stack();
+ latestStack.setId("id");
+ latestStack.setStackName("stackName");
+ latestStack.setStackStatus("CREATE_COMPLETE");
+ latestStack.setStackStatusReason("Stack Finished");
+
+ statusHandler.updateStackStatus(latestStack);
+ Mockito.verify(requestDBClient, times(1)).updateRequestProcessingData(requestProcessingData);
+ assertNotEquals("testMe", requestProcessingData.getValue());
+ }
+
+ @Test
+ public final void record_Not_Exists_Test() throws MsoException, IOException {
+ ArgumentCaptor<RequestProcessingData> requestCaptor = ArgumentCaptor.forClass(RequestProcessingData.class);
+ doReturn(null).when(requestDBClient).getRequestProcessingDataBySoRequestIdAndNameAndGrouping(null, "id",
+ "stackName");
+ Stack latestStack = new Stack();
+ latestStack.setId("id");
+ latestStack.setStackName("stackName");
+ latestStack.setStackStatus("CREATE_COMPLETE");
+ latestStack.setStackStatusReason("Stack Finished");
+ statusHandler.updateStackStatus(latestStack);
+ Mockito.verify(requestDBClient, times(1)).saveRequestProcessingData(requestCaptor.capture());
+ RequestProcessingData actualRequest = requestCaptor.getValue();
+ assertEquals("id", actualRequest.getGroupingId());
+ assertEquals("StackInformation", actualRequest.getTag());
+ assertEquals("stackName", actualRequest.getName());
+ assertNotNull(actualRequest.getValue());
+
+ }
+
+
+}
diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/InfraRequests.java b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/InfraRequests.java
index 1a925f2531..5b40e40eb9 100644
--- a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/InfraRequests.java
+++ b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/InfraRequests.java
@@ -22,6 +22,7 @@ package org.onap.so.db.request.beans;
import java.net.URI;
import java.sql.Timestamp;
+import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;
@@ -157,7 +158,7 @@ public abstract class InfraRequests implements java.io.Serializable {
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name = "SO_REQUEST_ID", referencedColumnName = "REQUEST_ID")
- private List<CloudApiRequests> cloudApiRequests;
+ private List<CloudApiRequests> cloudApiRequests = new ArrayList<>();
@ResourceId
public URI getRequestURI() {
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 ca2f52690c..1867b85de6 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
@@ -338,6 +338,13 @@ public class RequestsDbClient {
restTemplate.postForLocation(uri, entity);
}
+ public void updateRequestProcessingData(RequestProcessingData requestProcessingData) {
+ HttpHeaders headers = getHttpHeaders();
+ URI uri = getUri(requestProcessingDataURI);
+ HttpEntity<RequestProcessingData> entity = new HttpEntity<>(requestProcessingData, headers);
+ restTemplate.put(uri, entity);
+ }
+
public List<RequestProcessingData> getRequestProcessingDataBySoRequestId(String soRequestId) {
return this
.getRequestProcessingData(getUri(UriBuilder.fromUri(endpoint + findBySoRequestIdOrderByGroupingIdDesc)