diff options
author | Smokowski, Steven <steve.smokowski@att.com> | 2019-05-31 16:15:23 -0400 |
---|---|---|
committer | Benjamin, Max (mb388a) <mb388a@us.att.com> | 2019-05-31 16:15:37 -0400 |
commit | 96a2da847be40361ff8f0a27875101782fb6b80d (patch) | |
tree | 3d03f22eac888ada9c785b9d9152d54904dfc47c /adapters | |
parent | 89b396152a7f5ca62175d13342c1b3a1a9067ccb (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>
Diffstat (limited to 'adapters')
4 files changed, 136 insertions, 3 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()); + + } + + +} |