summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteve Smokowski <ss835w@att.com>2019-05-31 21:57:41 +0000
committerGerrit Code Review <gerrit@onap.org>2019-05-31 21:57:41 +0000
commita6bbe76f5eacd614ccc2f06ebc574939b2705c44 (patch)
treee5b46e440ef1a788bbeb75371edae4b57a980a9a
parent852a257aa9712c28fb10fc8bcdd5fad5350120c4 (diff)
parent96a2da847be40361ff8f0a27875101782fb6b80d (diff)
Merge "Fix issue where request was not being updated"
-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)