diff options
20 files changed, 960 insertions, 174 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/adapters/mso-catalog-db-adapter/src/test/java/org/onap/so/db/catalog/client/CatalogDbClientTest.java b/adapters/mso-catalog-db-adapter/src/test/java/org/onap/so/db/catalog/client/CatalogDbClientTest.java index 31cb1248d6..858216fd27 100644 --- a/adapters/mso-catalog-db-adapter/src/test/java/org/onap/so/db/catalog/client/CatalogDbClientTest.java +++ b/adapters/mso-catalog-db-adapter/src/test/java/org/onap/so/db/catalog/client/CatalogDbClientTest.java @@ -77,8 +77,12 @@ public class CatalogDbClientTest extends CatalogDbAdapterBaseTest { @Before public void initialize() { client.wiremockPort = String.valueOf(port); + client.setEndpoint(getEndpoint(port)); } + protected String getEndpoint(int port) { + return "http://localhost:" + port; + } @Test public void testGetRainyDayHandler_Regex() { @@ -88,6 +92,14 @@ public class CatalogDbClientTest extends CatalogDbAdapterBaseTest { } @Test + public void testGetRainyDayHandler__Encoding_Regex() { + RainyDayHandlerStatus rainyDayHandlerStatus = client.getRainyDayHandlerStatus("AssignServiceInstanceBB", "*", + "*", "*", "*", + "resources.lba_0_dmz_vmi_0: Unknown id: Error: oper 1 url /fqname-to-id body {\"fq_name\": [\"zrdm6bvota05-dmz_sec_group\"], \"type\": \"security-group\"} response Name ['zrdm6bvota05-dmz_sec_group'] not found"); + Assert.assertEquals("Rollback", rainyDayHandlerStatus.getPolicy()); + } + + @Test public void testGetCloudSiteHappyPath() throws Exception { CloudSite cloudSite = client.getCloudSite(MTN13); Assert.assertNotNull(cloudSite); diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfAdapterImpl.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfAdapterImpl.java index 352cd7b554..dea84abbf9 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfAdapterImpl.java +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfAdapterImpl.java @@ -938,7 +938,8 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { if (heatTemplate == null) { String error = "UpdateVF: No Heat Template ID defined in catalog database for " + vfModuleType - + ", reqType=" + requestTypeString; + + ", modelCustomizationUuid=" + mcu + ", vfModuleUuid=" + vf.getModelUUID() + + ", vnfResourceModelUuid=" + vnfResource.getModelUUID() + ", reqType=" + requestTypeString; logger.error("{} {} {} {} {} {}", MessageEnum.RA_VNF_UNKNOWN_PARAM.toString(), "Heat Template ID", vfModuleType, OPENSTACK, ErrorCode.DataError.getValue(), error); logger.debug(error); @@ -952,7 +953,9 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { logger.debug("No environment parameter found for this Type " + vfModuleType); } else { if (heatEnvironment == null) { - String error = "Update VNF: undefined Heat Environment. VF=" + vfModuleType; + String error = "Update VNF: undefined Heat Environment. VF=" + vfModuleType + + ", modelCustomizationUuid=" + mcu + ", vfModuleUuid=" + vf.getModelUUID() + + ", vnfResourceModelUuid=" + vnfResource.getModelUUID() + ", reqType=" + requestTypeString; logger.error("{} {} {} {} {}", MessageEnum.RA_VNF_UNKNOWN_PARAM.toString(), "Heat Environment ID", OPENSTACK, ErrorCode.DataError.getValue(), error); logger.debug(error); @@ -1639,7 +1642,8 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { if (heatTemplate == null) { String error = "UpdateVF: No Heat Template ID defined in catalog database for " + vfModuleType - + ", reqType=" + requestTypeString; + + ", modelCustomizationUuid=" + mcu + ", vfModuleUuid=" + vf.getModelUUID() + ", reqType=" + + requestTypeString; logger.error("{} {} {} {} {} {}", MessageEnum.RA_VNF_UNKNOWN_PARAM.toString(), "Heat Template ID", vfModuleType, OPENSTACK, ErrorCode.DataError.getValue(), error); throw new VnfException(error, MsoExceptionCategory.INTERNAL); @@ -1648,7 +1652,8 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { } if (heatEnvironment == null) { - String error = "Update VNF: undefined Heat Environment. VF=" + vfModuleType; + String error = "Update VNF: undefined Heat Environment. VF=" + vfModuleType + ", modelCustomizationUuid=" + + mcu + ", vfModuleUuid=" + vf.getModelUUID() + ", reqType=" + requestTypeString; logger.error("{} {} {} {} {}", MessageEnum.RA_VNF_UNKNOWN_PARAM.toString(), "Heat Environment ID", OPENSTACK, ErrorCode.DataError.getValue(), error); throw new VnfException(error, MsoExceptionCategory.INTERNAL); diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfCloudifyAdapterImpl.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfCloudifyAdapterImpl.java index d092b49d8c..b21a1a0755 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfCloudifyAdapterImpl.java +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfCloudifyAdapterImpl.java @@ -818,6 +818,7 @@ public class MsoVnfCloudifyAdapterImpl implements MsoVnfAdapter { if (heatTemplate == null) { String error = "UpdateVF: No Heat Template ID defined in catalog database for " + vfModuleType + + ", modelCustomizationUuid=" + modelCustomizationUuid + ", vfModuleUuid=" + vf.getModelUUID() + ", reqType=" + requestType; logger.error("{} {} {} {} {} {}", MessageEnum.RA_VNF_UNKNOWN_PARAM.toString(), "Heat Template ID", vfModuleType, OPENSTACK, ErrorCode.DataError.getValue(), error); @@ -827,7 +828,8 @@ public class MsoVnfCloudifyAdapterImpl implements MsoVnfAdapter { } if (heatEnvironment == null) { - String error = "Update VNF: undefined Heat Environment. VF=" + vfModuleType; + String error = "Update VNF: undefined Heat Environment. VF=" + vfModuleType + ", modelCustomizationUuid=" + + modelCustomizationUuid + ", vfModuleUuid=" + vf.getModelUUID() + ", reqType=" + requestType; logger.error("{} {} {} {} {}", MessageEnum.RA_VNF_UNKNOWN_PARAM.toString(), "Heat Environment ID", OPENSTACK, ErrorCode.DataError.getValue(), error); // Alarm on this error, configuration must be fixed diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfPluginAdapterImpl.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfPluginAdapterImpl.java index ed797f10d9..00b7e59404 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfPluginAdapterImpl.java +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfPluginAdapterImpl.java @@ -862,6 +862,7 @@ public class MsoVnfPluginAdapterImpl implements MsoVnfAdapter { if (heatTemplate == null) { String error = "UpdateVF: No Heat Template ID defined in catalog database for " + vfModuleType + + ", modelCustomizationUuid=" + modelCustomizationUuid + ", vfModuleUuid=" + vfModule.getModelUUID() + ", reqType=" + requestType; logger.error("{} {} {} {} {} {}", MessageEnum.RA_VNF_UNKNOWN_PARAM.toString(), "Heat Template ID", vfModuleType, "VNF", ErrorCode.DataError.getValue(), error); @@ -872,7 +873,8 @@ public class MsoVnfPluginAdapterImpl implements MsoVnfAdapter { } if (heatEnvironment == null) { - String error = "Update VNF: undefined Heat Environment. VF=" + vfModuleType; + String error = "Update VNF: undefined Heat Environment. VF=" + vfModuleType + ", modelCustomizationUuid=" + + modelCustomizationUuid + ", vfModuleUuid=" + vfModule.getModelUUID() + ", reqType=" + requestType; logger.error("{} {} {} {} {}", MessageEnum.RA_VNF_UNKNOWN_PARAM.toString(), "Heat Environment ID", "OpenStack", ErrorCode.DataError.getValue(), error); throw new VnfException(error, MsoExceptionCategory.INTERNAL); diff --git a/common/src/main/java/org/onap/so/serviceinstancebeans/ModelType.java b/common/src/main/java/org/onap/so/serviceinstancebeans/ModelType.java index 11cd3d42b7..34edf91c0c 100644 --- a/common/src/main/java/org/onap/so/serviceinstancebeans/ModelType.java +++ b/common/src/main/java/org/onap/so/serviceinstancebeans/ModelType.java @@ -20,18 +20,75 @@ package org.onap.so.serviceinstancebeans; +import java.lang.reflect.InvocationTargetException; +import com.google.common.base.CaseFormat; + /* * Enum for Model Type values returned by API Handler to BPMN */ public enum ModelType { - service, - vnf, - vfModule, - volumeGroup, - network, - configuration, - connectionPoint, - pnf, - networkInstanceGroup, - instanceGroup + service("serviceInstance"), + vnf("vnf"), + vfModule("vfModule"), + volumeGroup("volumeGroup"), + network("network"), + configuration("configuration"), + connectionPoint("connectionPoint"), + pnf("pnf"), + networkInstanceGroup("networkInstanceGroup"), + instanceGroup("instanceGroup"); + + final String name; + + private ModelType(String name) { + this.name = name; + } + + + public <T> T getId(Object obj) { + return this.get(obj, "Id"); + } + + public <T> T getName(Object obj) { + return this.get(obj, "Name"); + } + + public void setId(Object obj, Object value) { + this.set(obj, "Id", value); + } + + public void setName(Object obj, Object value) { + this.set(obj, "Name", value); + } + + protected <T> T get(Object obj, String field) { + T result = null; + if (obj != null) { + try { + result = (T) obj.getClass().getMethod(String.format("%s%s%s", "get", + CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, this.name), field)).invoke(obj); + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException + | NoSuchMethodException | SecurityException e) { + // silent fail + } + } + + return result; + } + + protected void set(Object obj, String field, Object value) { + if (obj != null) { + try { + obj.getClass() + .getMethod( + String.format("%s%s%s", "set", + CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, this.name), field), + value.getClass()) + .invoke(obj, value); + } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException + | InvocationTargetException e) { + // silent fail + } + } + } } diff --git a/common/src/test/java/org/onap/so/serviceinstancebeans/ModelTypeTest.java b/common/src/test/java/org/onap/so/serviceinstancebeans/ModelTypeTest.java new file mode 100644 index 0000000000..e4b694cd15 --- /dev/null +++ b/common/src/test/java/org/onap/so/serviceinstancebeans/ModelTypeTest.java @@ -0,0 +1,38 @@ +package org.onap.so.serviceinstancebeans; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import org.junit.Test; + +public class ModelTypeTest { + + + + @Test + public void reflectionTest() { + TestServiceInstanceBean a = new TestServiceInstanceBean(); + TestServiceInstanceBean b = new TestServiceInstanceBean(); + + a.setServiceInstanceId("my-id-a"); + a.setServiceInstanceName("my-name-a"); + + b.setServiceInstanceId("my-id-b"); + b.setServiceInstanceName("my-name-b"); + + assertEquals("my-id-a", ModelType.service.getId(a)); + assertEquals("my-name-a", ModelType.service.getName(a)); + ModelType.service.setName(a, ModelType.service.getName(b)); + ModelType.service.setId(a, ModelType.service.getId(b)); + assertEquals("my-name-b", ModelType.service.getName(a)); + assertEquals("my-id-b", ModelType.service.getId(a)); + } + + @Test + public void testSilentFail() { + TestServiceInstanceBean a = new TestServiceInstanceBean(); + + a.setServiceInstanceId("my-id-a"); + a.setServiceInstanceName("my-name-a"); + assertNull(ModelType.service.get(a, "NoField")); + } +} diff --git a/common/src/test/java/org/onap/so/serviceinstancebeans/TestServiceInstanceBean.java b/common/src/test/java/org/onap/so/serviceinstancebeans/TestServiceInstanceBean.java new file mode 100644 index 0000000000..b8cf6141e3 --- /dev/null +++ b/common/src/test/java/org/onap/so/serviceinstancebeans/TestServiceInstanceBean.java @@ -0,0 +1,24 @@ +package org.onap.so.serviceinstancebeans; + +public class TestServiceInstanceBean { + + private String serviceInstanceId; + private String serviceInstanceName; + + public String getServiceInstanceId() { + return serviceInstanceId; + } + + public void setServiceInstanceId(String serviceInstanceId) { + this.serviceInstanceId = serviceInstanceId; + } + + public String getServiceInstanceName() { + return serviceInstanceName; + } + + public void setServiceInstanceName(String serviceInstanceName) { + this.serviceInstanceName = serviceInstanceName; + } + +} diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/RequestHandlerUtils.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/RequestHandlerUtils.java index 2a0718aeba..4e910e5382 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/RequestHandlerUtils.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/RequestHandlerUtils.java @@ -59,7 +59,9 @@ import org.onap.so.apihandlerinfra.exceptions.ContactCamundaException; import org.onap.so.apihandlerinfra.exceptions.DuplicateRequestException; import org.onap.so.apihandlerinfra.exceptions.RequestDbFailureException; import org.onap.so.apihandlerinfra.exceptions.ValidateException; +import org.onap.so.apihandlerinfra.exceptions.VfModuleNotFoundException; import org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo; +import org.onap.so.db.catalog.beans.VfModule; import org.onap.so.db.catalog.client.CatalogDbClient; import org.onap.so.db.request.beans.InfraActiveRequests; import org.onap.so.db.request.client.RequestsDbClient; @@ -67,6 +69,7 @@ import org.onap.so.exceptions.ValidationException; import org.onap.so.logger.ErrorCode; import org.onap.so.logger.LogConstants; import org.onap.so.logger.MessageEnum; +import org.onap.so.serviceinstancebeans.ModelInfo; import org.onap.so.serviceinstancebeans.ModelType; import org.onap.so.serviceinstancebeans.RelatedInstance; import org.onap.so.serviceinstancebeans.RelatedInstanceList; @@ -638,11 +641,70 @@ public class RequestHandlerUtils { request.setRequestBody(infraActiveRequest.getRequestBody()); request.setAicCloudRegion(infraActiveRequest.getAicCloudRegion()); request.setRequestScope(infraActiveRequest.getRequestScope()); - request.setServiceInstanceId(infraActiveRequest.getServiceInstanceId()); - request.setServiceInstanceName(infraActiveRequest.getServiceInstanceName()); request.setRequestAction(infraActiveRequest.getRequestAction()); + setInstanceIdAndName(infraActiveRequest, request); } return request; } + protected void setInstanceIdAndName(InfraActiveRequests infraActiveRequest, + InfraActiveRequests currentActiveRequest) { + String requestScope = infraActiveRequest.getRequestScope(); + try { + ModelType type = ModelType.valueOf(requestScope); + type.setName(currentActiveRequest, type.getName(infraActiveRequest)); + type.setId(currentActiveRequest, type.getId(infraActiveRequest)); + } catch (IllegalArgumentException e) { + logger.error( + "requestScope \"{}\" does not match a ModelType enum. Unable to set instanceId and instanceName from the original request.", + requestScope); + } + } + + protected Boolean getIsBaseVfModule(ModelInfo modelInfo, Actions action, String vnfType, + String sdcServiceModelVersion, InfraActiveRequests currentActiveReq) throws ApiException { + // Get VF Module-specific base module indicator + VfModule vfm = null; + String modelVersionId = modelInfo.getModelVersionId(); + Boolean isBaseVfModule = false; + + if (modelVersionId != null) { + vfm = catalogDbClient.getVfModuleByModelUUID(modelVersionId); + } else if (modelInfo.getModelInvariantId() != null && modelInfo.getModelVersion() != null) { + vfm = catalogDbClient.getVfModuleByModelInvariantUUIDAndModelVersion(modelInfo.getModelInvariantId(), + modelInfo.getModelVersion()); + } + + if (vfm != null) { + if (vfm.getIsBase()) { + isBaseVfModule = true; + } + } else if (action == Action.createInstance || action == Action.updateInstance) { + String serviceVersionText = ""; + if (sdcServiceModelVersion != null && !sdcServiceModelVersion.isEmpty()) { + serviceVersionText = " with version " + sdcServiceModelVersion; + } + String errorMessage = "VnfType " + vnfType + " and VF Module Model Name " + modelInfo.getModelName() + + serviceVersionText + " not found in MSO Catalog DB"; + ErrorLoggerInfo errorLoggerInfo = + new ErrorLoggerInfo.Builder(MessageEnum.APIH_DB_ATTRIBUTE_NOT_FOUND, ErrorCode.DataError) + .errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build(); + VfModuleNotFoundException vfModuleException = new VfModuleNotFoundException.Builder(errorMessage, + HttpStatus.SC_NOT_FOUND, ErrorNumbers.SVC_BAD_PARAMETER).errorInfo(errorLoggerInfo).build(); + updateStatus(currentActiveReq, Status.FAILED, vfModuleException.getMessage()); + throw vfModuleException; + } + return isBaseVfModule; + } + + protected ModelType getModelType(Actions action, ModelInfo modelInfo) { + if (action == Action.applyUpdatedConfig || action == Action.inPlaceSoftwareUpdate) { + return ModelType.vnf; + } else if (action == Action.addMembers || action == Action.removeMembers) { + return ModelType.instanceGroup; + } else { + return modelInfo.getModelType(); + } + } + } diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ResumeOrchestrationRequest.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ResumeOrchestrationRequest.java index abf3729215..32d2c50978 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ResumeOrchestrationRequest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ResumeOrchestrationRequest.java @@ -47,6 +47,8 @@ import org.onap.so.logger.HttpHeadersConstants; import org.onap.so.logger.LogConstants; import org.onap.so.logger.MdcConstants; import org.onap.so.logger.MessageEnum; +import org.onap.so.serviceinstancebeans.ModelInfo; +import org.onap.so.serviceinstancebeans.ModelType; import org.onap.so.serviceinstancebeans.ServiceInstancesRequest; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -74,6 +76,8 @@ public class ResumeOrchestrationRequest { @Autowired private RequestsDbClient requestsDbClient; + @Autowired + private MsoRequest msoRequest; @POST @Path("/{version:[vV][7]}/requests/{requestId}/resume") @@ -128,24 +132,26 @@ public class ResumeOrchestrationRequest { String requestBody = infraActiveRequest.getRequestBody(); Action action = Action.valueOf(infraActiveRequest.getRequestAction()); String requestId = currentActiveRequest.getRequestId(); - String serviceInstanceName = infraActiveRequest.getServiceInstanceName(); String requestScope = infraActiveRequest.getRequestScope(); - String serviceInstanceId = infraActiveRequest.getServiceInstanceId(); + String instanceName = getInstanceName(infraActiveRequest, requestScope, currentActiveRequest); + HashMap<String, String> instanceIdMap = setInstanceIdMap(infraActiveRequest, requestScope); - checkForInProgressRequest(currentActiveRequest, serviceInstanceId, requestScope, serviceInstanceName, action); + checkForInProgressRequest(currentActiveRequest, instanceIdMap, requestScope, instanceName, action); ServiceInstancesRequest sir = null; sir = requestHandlerUtils.convertJsonToServiceInstanceRequest(requestBody, action, requestId, requestUri); Boolean aLaCarte = sir.getRequestDetails().getRequestParameters().getALaCarte(); - if (aLaCarte == null) { - aLaCarte = false; - } String pnfCorrelationId = serviceInstances.getPnfCorrelationId(sir); - RecipeLookupResult recipeLookupResult = serviceRecipeLookup(currentActiveRequest, sir, action, aLaCarte); + RecipeLookupResult recipeLookupResult = serviceInstances.getServiceInstanceOrchestrationURI(sir, action, + msoRequest.getAlacarteFlag(sir), currentActiveRequest); requestDbSave(currentActiveRequest); + if (aLaCarte == null) { + aLaCarte = setALaCarteFlagIfNull(requestScope, action); + } + RequestClientParameter requestClientParameter = setRequestClientParameter(recipeLookupResult, version, infraActiveRequest, currentActiveRequest, pnfCorrelationId, aLaCarte, sir); @@ -153,40 +159,60 @@ public class ResumeOrchestrationRequest { recipeLookupResult.getOrchestrationURI(), requestScope); } - protected void checkForInProgressRequest(InfraActiveRequests currentActiveRequest, String serviceInstanceId, - String requestScope, String serviceInstanceName, Action action) throws ApiException { - boolean inProgress = false; - HashMap<String, String> instanceIdMap = new HashMap<>(); - instanceIdMap.put("serviceInstanceId", serviceInstanceId); - InfraActiveRequests requestInProgress = requestHandlerUtils.duplicateCheck(action, instanceIdMap, - serviceInstanceName, requestScope, currentActiveRequest); - if (requestInProgress != null) { - inProgress = requestHandlerUtils.camundaHistoryCheck(requestInProgress, currentActiveRequest); + protected Boolean setALaCarteFlagIfNull(String requestScope, Action action) { + Boolean aLaCarteFlag; + if (!requestScope.equalsIgnoreCase(ModelType.service.name()) && action != Action.recreateInstance) { + aLaCarteFlag = true; + } else { + aLaCarteFlag = false; } - if (inProgress) { - requestHandlerUtils.buildErrorOnDuplicateRecord(currentActiveRequest, action, instanceIdMap, - serviceInstanceName, requestScope, requestInProgress); + return aLaCarteFlag; + } + + protected HashMap<String, String> setInstanceIdMap(InfraActiveRequests infraActiveRequest, String requestScope) { + HashMap<String, String> instanceIdMap = new HashMap<>(); + ModelType type; + try { + type = ModelType.valueOf(requestScope); + instanceIdMap.put(type.name() + "InstanceId", type.getId(infraActiveRequest)); + } catch (IllegalArgumentException e) { + logger.error("requestScope \"{}\" does not match a ModelType enum.", requestScope); } + return instanceIdMap; } - protected RecipeLookupResult serviceRecipeLookup(InfraActiveRequests currentActiveRequest, - ServiceInstancesRequest sir, Action action, Boolean aLaCarte) - throws ValidateException, RequestDbFailureException { - RecipeLookupResult recipeLookupResult = null; + protected String getInstanceName(InfraActiveRequests infraActiveRequest, String requestScope, + InfraActiveRequests currentActiveRequest) throws ValidateException, RequestDbFailureException { + ModelType type; + String instanceName = ""; try { - recipeLookupResult = serviceInstances.getServiceURI(sir, action, aLaCarte); - } catch (IOException e) { - logger.error("IOException while performing service recipe lookup", e); - ErrorLoggerInfo errorLoggerInfo = - new ErrorLoggerInfo.Builder(MessageEnum.APIH_REQUEST_VALIDATION_ERROR, ErrorCode.SchemaError) - .errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build(); - ValidateException validateException = - new ValidateException.Builder(e.getMessage(), HttpStatus.SC_BAD_REQUEST, - ErrorNumbers.SVC_BAD_PARAMETER).cause(e).errorInfo(errorLoggerInfo).build(); + type = ModelType.valueOf(requestScope); + instanceName = type.getName(infraActiveRequest); + } catch (IllegalArgumentException e) { + logger.error("requestScope \"{}\" does not match a ModelType enum.", requestScope); + ValidateException validateException = new ValidateException.Builder( + "requestScope: \"" + requestScope + "\" from request: " + infraActiveRequest.getRequestId() + + " does not match a ModelType enum.", + HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_BAD_PARAMETER).cause(e).build(); requestHandlerUtils.updateStatus(currentActiveRequest, Status.FAILED, validateException.getMessage()); throw validateException; } - return recipeLookupResult; + return instanceName; + } + + protected void checkForInProgressRequest(InfraActiveRequests currentActiveRequest, + HashMap<String, String> instanceIdMap, String requestScope, String instanceName, Action action) + throws ApiException { + boolean inProgress = false; + InfraActiveRequests requestInProgress = requestHandlerUtils.duplicateCheck(action, instanceIdMap, instanceName, + requestScope, currentActiveRequest); + if (requestInProgress != null) { + inProgress = requestHandlerUtils.camundaHistoryCheck(requestInProgress, currentActiveRequest); + } + if (inProgress) { + requestHandlerUtils.buildErrorOnDuplicateRecord(currentActiveRequest, action, instanceIdMap, instanceName, + requestScope, requestInProgress); + } } protected void requestDbSave(InfraActiveRequests currentActiveRequest) throws RequestDbFailureException { @@ -204,23 +230,37 @@ public class ResumeOrchestrationRequest { protected RequestClientParameter setRequestClientParameter(RecipeLookupResult recipeLookupResult, String version, InfraActiveRequests infraActiveRequest, InfraActiveRequests currentActiveRequest, String pnfCorrelationId, - Boolean aLaCarte, ServiceInstancesRequest sir) throws ValidateException { + Boolean aLaCarte, ServiceInstancesRequest sir) throws ApiException { RequestClientParameter requestClientParameter = null; + Action action = Action.valueOf(infraActiveRequest.getRequestAction()); + ModelInfo modelInfo = sir.getRequestDetails().getModelInfo(); + + Boolean isBaseVfModule = false; + if (requestHandlerUtils.getModelType(action, modelInfo).equals(ModelType.vfModule)) { + isBaseVfModule = requestHandlerUtils.getIsBaseVfModule(modelInfo, action, infraActiveRequest.getVnfType(), + msoRequest.getSDCServiceModelVersion(sir), currentActiveRequest); + } + try { - requestClientParameter = new RequestClientParameter.Builder() - .setRequestId(currentActiveRequest.getRequestId()) - .setRecipeTimeout(recipeLookupResult.getRecipeTimeout()) - .setRequestAction(infraActiveRequest.getRequestAction()) - .setServiceInstanceId(infraActiveRequest.getServiceInstanceId()) - .setPnfCorrelationId(pnfCorrelationId).setVnfId(infraActiveRequest.getVnfId()) - .setVfModuleId(infraActiveRequest.getVfModuleId()) - .setVolumeGroupId(infraActiveRequest.getVolumeGroupId()) - .setNetworkId(infraActiveRequest.getNetworkId()).setServiceType(infraActiveRequest.getServiceType()) - .setVnfType(infraActiveRequest.getVnfType()).setNetworkType(infraActiveRequest.getNetworkType()) - .setRequestDetails(requestHandlerUtils.mapJSONtoMSOStyle(infraActiveRequest.getRequestBody(), sir, - aLaCarte, Action.valueOf(infraActiveRequest.getRequestAction()))) - .setApiVersion(version).setALaCarte(aLaCarte).setRequestUri(currentActiveRequest.getRequestUrl()) - .setInstanceGroupId(infraActiveRequest.getInstanceGroupId()).build(); + requestClientParameter = + new RequestClientParameter.Builder().setRequestId(currentActiveRequest.getRequestId()) + .setBaseVfModule(isBaseVfModule).setRecipeTimeout(recipeLookupResult.getRecipeTimeout()) + .setRequestAction(infraActiveRequest.getRequestAction()) + .setServiceInstanceId(infraActiveRequest.getServiceInstanceId()) + .setPnfCorrelationId(pnfCorrelationId).setVnfId(infraActiveRequest.getVnfId()) + .setVfModuleId(infraActiveRequest.getVfModuleId()) + .setVolumeGroupId(infraActiveRequest.getVolumeGroupId()) + .setNetworkId(infraActiveRequest.getNetworkId()) + .setServiceType(infraActiveRequest.getServiceType()) + .setVnfType(infraActiveRequest.getVnfType()) + .setVfModuleType(msoRequest.getVfModuleType(sir, infraActiveRequest.getRequestScope(), + action, Integer.parseInt(version))) + .setNetworkType(infraActiveRequest.getNetworkType()) + .setRequestDetails(requestHandlerUtils + .mapJSONtoMSOStyle(infraActiveRequest.getRequestBody(), sir, aLaCarte, action)) + .setApiVersion(version).setALaCarte(aLaCarte) + .setRequestUri(currentActiveRequest.getRequestUrl()) + .setInstanceGroupId(infraActiveRequest.getInstanceGroupId()).build(); } catch (IOException e) { logger.error("IOException while generating requestClientParameter to send to BPMN", e); ErrorLoggerInfo errorLoggerInfo = diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java index 45319de5e8..68fa6e4f56 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java @@ -814,64 +814,20 @@ public class ServiceInstances { referencesResponse.setRequestId(requestId); serviceResponse.setRequestReferences(referencesResponse); - Boolean isBaseVfModule = false; - RecipeLookupResult recipeLookupResult = getServiceInstanceOrchestrationURI(sir, action, alaCarteFlag, currentActiveReq); String serviceInstanceType = requestHandlerUtils.getServiceType(requestScope, sir, alaCarteFlag); - ModelType modelType; - ModelInfo modelInfo = sir.getRequestDetails().getModelInfo(); - if (action == Action.applyUpdatedConfig || action == Action.inPlaceSoftwareUpdate) { - modelType = ModelType.vnf; - } else if (action == Action.addMembers || action == Action.removeMembers) { - modelType = ModelType.instanceGroup; - } else { - modelType = modelInfo.getModelType(); - } - - if (modelType.equals(ModelType.vfModule)) { - - - // Get VF Module-specific base module indicator - VfModule vfm = null; - - String modelVersionId = modelInfo.getModelVersionId(); - if (modelVersionId != null) { - vfm = catalogDbClient.getVfModuleByModelUUID(modelVersionId); - } else if (modelInfo.getModelInvariantId() != null && modelInfo.getModelVersion() != null) { - vfm = catalogDbClient.getVfModuleByModelInvariantUUIDAndModelVersion(modelInfo.getModelInvariantId(), - modelInfo.getModelVersion()); - } - - if (vfm != null) { - if (vfm.getIsBase()) { - isBaseVfModule = true; - } - } else if (action == Action.createInstance || action == Action.updateInstance) { - // There is no entry for this vfModuleType with this version, if specified, in VF_MODULE table in - // Catalog DB. - // This request cannot proceed - - String serviceVersionText = ""; - if (sdcServiceModelVersion != null && !sdcServiceModelVersion.isEmpty()) { - serviceVersionText = " with version " + sdcServiceModelVersion; - } + ModelInfo modelInfo = sir.getRequestDetails().getModelInfo(); + ModelType modelType = requestHandlerUtils.getModelType(action, modelInfo); - String errorMessage = "VnfType " + vnfType + " and VF Module Model Name " + modelInfo.getModelName() - + serviceVersionText + " not found in MSO Catalog DB"; - ErrorLoggerInfo errorLoggerInfo = - new ErrorLoggerInfo.Builder(MessageEnum.APIH_DB_ATTRIBUTE_NOT_FOUND, ErrorCode.DataError) - .errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build(); - VfModuleNotFoundException vfModuleException = new VfModuleNotFoundException.Builder(errorMessage, - HttpStatus.SC_NOT_FOUND, ErrorNumbers.SVC_BAD_PARAMETER).errorInfo(errorLoggerInfo).build(); - requestHandlerUtils.updateStatus(currentActiveReq, Status.FAILED, vfModuleException.getMessage()); + Boolean isBaseVfModule = false; - throw vfModuleException; - } + if (modelType.equals(ModelType.vfModule)) { + isBaseVfModule = requestHandlerUtils.getIsBaseVfModule(modelInfo, action, vnfType, sdcServiceModelVersion, + currentActiveReq); } - serviceInstanceId = requestHandlerUtils.setServiceInstanceId(requestScope, sir); String vnfId = ""; String vfModuleId = ""; @@ -1030,7 +986,7 @@ public class ServiceInstances { .orElse(""); } - private RecipeLookupResult getServiceInstanceOrchestrationURI(ServiceInstancesRequest sir, Actions action, + protected RecipeLookupResult getServiceInstanceOrchestrationURI(ServiceInstancesRequest sir, Actions action, boolean alaCarteFlag, InfraActiveRequests currentActiveReq) throws ApiException { RecipeLookupResult recipeLookupResult = null; // if the aLaCarte flag is set to TRUE, the API-H should choose the VID_DEFAULT recipe for the requested action diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/RequestHandlerUtilsUnitTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/RequestHandlerUtilsUnitTest.java index b9d9974701..e92417728c 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/RequestHandlerUtilsUnitTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/RequestHandlerUtilsUnitTest.java @@ -21,33 +21,69 @@ package org.onap.so.apihandlerinfra; import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThat; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doReturn; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; import java.sql.Timestamp; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; import org.mockito.Spy; import org.mockito.junit.MockitoJUnitRunner; +import org.onap.so.apihandlerinfra.exceptions.ApiException; +import org.onap.so.apihandlerinfra.exceptions.VfModuleNotFoundException; +import org.onap.so.db.catalog.beans.VfModule; +import org.onap.so.db.catalog.client.CatalogDbClient; import org.onap.so.db.request.beans.InfraActiveRequests; +import org.onap.so.serviceinstancebeans.ModelInfo; +import org.onap.so.serviceinstancebeans.ModelType; @RunWith(MockitoJUnitRunner.class) public class RequestHandlerUtilsUnitTest { + @Mock + private CatalogDbClient catDbClient; + + @InjectMocks @Spy private RequestHandlerUtils requestHandler; + @Rule + public ExpectedException thrown = ExpectedException.none(); + private static final String CURRENT_REQUEST_ID = "eca3a1b1-43ab-457e-ab1c-367263d148b4"; private static final String RESUMED_REQUEST_ID = "59c7247f-839f-4923-90c3-05faa3ab354d"; private static final String SERVICE_INSTANCE_ID = "00032ab7-na18-42e5-965d-8ea592502018"; + private static final String SERVICE_INSTANCE_NAME = "serviceInstanceName"; + private static final String VNF_ID = "00032ab7-na18-42e5-965d-8ea592502017"; + private static final String VFMODULE_ID = "00032ab7-na18-42e5-965d-8ea592502016"; + private static final String NETWORK_ID = "00032ab7-na18-42e5-965d-8ea592502015"; + private static final String VOLUME_GROUP_ID = "00032ab7-na18-42e5-965d-8ea592502014"; + private static final String VNF_NAME = "vnfName"; + private static final String VFMODULE_NAME = "vfModuleName"; + private static final String NETWORK_NAME = "networkName"; + private static final String VOLUME_GROUP_NAME = "volumeGroupName"; + private static final String MODEL_VERSION_ID = "883f4a7a-b5a5-44e0-8738-361c6413d24c"; + private static final String MODEL_VERSION = "1.0"; + private static final String MODEL_INVARIANT_ID = "d358b828-e7f8-4833-ac96-2782bed1a9a9"; + private static final String MODEL_NAME = "modelName"; private final Timestamp startTimeStamp = new Timestamp(System.currentTimeMillis()); private String requestUri = "http:localhost:6746/onap/so/infra/orchestrationRequests/v7/00032ab7-na18-42e5-965d-8ea592502019/resume"; private InfraActiveRequests infraActiveRequest = new InfraActiveRequests(); private InfraActiveRequests currentActiveRequest = new InfraActiveRequests(); private InfraActiveRequests currentActiveRequestIARNull = new InfraActiveRequests(); + private Action action = Action.createInstance; + private String vnfType = "vnfType"; + private String sdcServiceModelVersion = "7"; public String getRequestBody(String request) throws IOException { request = "src/test/resources/ResumeOrchestrationRequest" + request; @@ -67,7 +103,7 @@ public class RequestHandlerUtilsUnitTest { infraActiveRequest.setAicCloudRegion("cloudRegion"); infraActiveRequest.setRequestScope("service"); infraActiveRequest.setServiceInstanceId(SERVICE_INSTANCE_ID); - infraActiveRequest.setServiceInstanceName("serviceInstanceName"); + infraActiveRequest.setServiceInstanceName(SERVICE_INSTANCE_NAME); infraActiveRequest.setRequestStatus(Status.IN_PROGRESS.toString()); infraActiveRequest.setRequestAction(Action.createInstance.toString()); infraActiveRequest.setServiceType("serviceType"); @@ -81,8 +117,6 @@ public class RequestHandlerUtilsUnitTest { currentActiveRequest.setRequestBody(getRequestBody("/RequestBody.json")); currentActiveRequest.setAicCloudRegion("cloudRegion"); currentActiveRequest.setRequestScope("service"); - currentActiveRequest.setServiceInstanceId(SERVICE_INSTANCE_ID); - currentActiveRequest.setServiceInstanceName("serviceInstanceName"); currentActiveRequest.setRequestStatus(Status.IN_PROGRESS.toString()); currentActiveRequest.setLastModifiedBy(Constants.MODIFIED_BY_APIHANDLER); currentActiveRequest.setRequestAction(Action.createInstance.toString()); @@ -107,6 +141,7 @@ public class RequestHandlerUtilsUnitTest { @Test public void createNewRecordCopyFromInfraActiveRequestTest() { + doNothing().when(requestHandler).setInstanceIdAndName(infraActiveRequest, currentActiveRequest); InfraActiveRequests result = requestHandler.createNewRecordCopyFromInfraActiveRequest(infraActiveRequest, CURRENT_REQUEST_ID, startTimeStamp, "VID", requestUri, "xxxxxx", RESUMED_REQUEST_ID); assertThat(currentActiveRequest, sameBeanAs(result)); @@ -118,4 +153,247 @@ public class RequestHandlerUtilsUnitTest { startTimeStamp, "VID", requestUri, "xxxxxx", RESUMED_REQUEST_ID); assertThat(currentActiveRequestIARNull, sameBeanAs(result)); } + + @Test + public void setInstanceIdAndNameServiceTest() { + InfraActiveRequests serviceRequest = new InfraActiveRequests(); + + InfraActiveRequests expected = new InfraActiveRequests(); + expected.setServiceInstanceId(SERVICE_INSTANCE_ID); + expected.setServiceInstanceName(SERVICE_INSTANCE_NAME); + + requestHandler.setInstanceIdAndName(infraActiveRequest, serviceRequest); + assertThat(serviceRequest, sameBeanAs(expected)); + } + + @Test + public void setInstanceIdAndNameRequestScopeNotValidTest() { + InfraActiveRequests originalServiceRequest = new InfraActiveRequests(); + originalServiceRequest.setRequestScope("test"); + InfraActiveRequests serviceRequest = new InfraActiveRequests(); + + InfraActiveRequests expected = new InfraActiveRequests(); + + requestHandler.setInstanceIdAndName(originalServiceRequest, serviceRequest); + assertThat(serviceRequest, sameBeanAs(expected)); + } + + @Test + public void setInstanceIdAndNameVnfTest() { + InfraActiveRequests vnfRequestOriginal = new InfraActiveRequests(); + vnfRequestOriginal.setRequestScope("vnf"); + vnfRequestOriginal.setVnfId(VNF_ID); + vnfRequestOriginal.setVnfName(VNF_NAME); + InfraActiveRequests vnfRequest = new InfraActiveRequests(); + + InfraActiveRequests expected = new InfraActiveRequests(); + expected.setVnfId(VNF_ID); + expected.setVnfName(VNF_NAME); + + requestHandler.setInstanceIdAndName(vnfRequestOriginal, vnfRequest); + assertThat(vnfRequest, sameBeanAs(expected)); + } + + @Test + public void setInstanceIdAndNameVfModuleTest() { + InfraActiveRequests vfModuleRequestOriginal = new InfraActiveRequests(); + vfModuleRequestOriginal.setRequestScope("vfModule"); + vfModuleRequestOriginal.setVfModuleId(VFMODULE_ID); + vfModuleRequestOriginal.setVfModuleName(VFMODULE_NAME); + InfraActiveRequests vfModuleRequest = new InfraActiveRequests(); + + InfraActiveRequests expected = new InfraActiveRequests(); + expected.setVfModuleId(VFMODULE_ID); + expected.setVfModuleName(VFMODULE_NAME); + + requestHandler.setInstanceIdAndName(vfModuleRequestOriginal, vfModuleRequest); + assertThat(vfModuleRequest, sameBeanAs(expected)); + } + + @Test + public void setInstanceIdAndNameNetworkTest() { + InfraActiveRequests networkRequestOriginal = new InfraActiveRequests(); + networkRequestOriginal.setRequestScope("network"); + networkRequestOriginal.setNetworkId(NETWORK_ID); + networkRequestOriginal.setNetworkName(NETWORK_NAME); + InfraActiveRequests networkRequest = new InfraActiveRequests(); + + InfraActiveRequests expected = new InfraActiveRequests(); + expected.setNetworkId(NETWORK_ID); + expected.setNetworkName(NETWORK_NAME); + + requestHandler.setInstanceIdAndName(networkRequestOriginal, networkRequest); + assertThat(networkRequest, sameBeanAs(expected)); + } + + @Test + public void setInstanceIdAndNameVolumeGroupTest() { + InfraActiveRequests volumeGroupRequestOriginal = new InfraActiveRequests(); + volumeGroupRequestOriginal.setRequestScope("volumeGroup"); + volumeGroupRequestOriginal.setVolumeGroupId(VOLUME_GROUP_ID); + volumeGroupRequestOriginal.setVolumeGroupName(VOLUME_GROUP_NAME); + InfraActiveRequests volumeGroupRequest = new InfraActiveRequests(); + + InfraActiveRequests expected = new InfraActiveRequests(); + expected.setVolumeGroupId(VOLUME_GROUP_ID); + expected.setVolumeGroupName(VOLUME_GROUP_NAME); + + requestHandler.setInstanceIdAndName(volumeGroupRequestOriginal, volumeGroupRequest); + assertThat(volumeGroupRequest, sameBeanAs(expected)); + } + + @Test + public void getIsBaseVfModuleTrueTest() throws ApiException { + VfModule vfModule = new VfModule(); + vfModule.setIsBase(true); + ModelInfo modelInfo = new ModelInfo(); + modelInfo.setModelVersionId(MODEL_VERSION_ID); + + doReturn(vfModule).when(catDbClient).getVfModuleByModelUUID(MODEL_VERSION_ID); + Boolean expected = true; + + Boolean result = requestHandler.getIsBaseVfModule(modelInfo, action, vnfType, sdcServiceModelVersion, + currentActiveRequest); + assertEquals(result, expected); + } + + @Test + public void getIsBaseVfModuleFalseTest() throws ApiException { + VfModule vfModule = new VfModule(); + vfModule.setIsBase(false); + ModelInfo modelInfo = new ModelInfo(); + modelInfo.setModelVersionId(MODEL_VERSION_ID); + + doReturn(vfModule).when(catDbClient).getVfModuleByModelUUID(MODEL_VERSION_ID); + Boolean expected = false; + + Boolean result = requestHandler.getIsBaseVfModule(modelInfo, action, vnfType, sdcServiceModelVersion, + currentActiveRequest); + assertEquals(result, expected); + } + + @Test + public void getIsBaseVfModuleNullTest() throws ApiException { + ModelInfo modelInfo = new ModelInfo(); + modelInfo.setModelVersionId(MODEL_VERSION_ID); + modelInfo.setModelName(MODEL_NAME); + String errorMessage = + "VnfType vnfType and VF Module Model Name modelName with version 7 not found in MSO Catalog DB"; + + doNothing().when(requestHandler).updateStatus(currentActiveRequest, Status.FAILED, errorMessage); + doReturn(null).when(catDbClient).getVfModuleByModelUUID(MODEL_VERSION_ID); + + thrown.expect(VfModuleNotFoundException.class); + thrown.expectMessage(errorMessage); + requestHandler.getIsBaseVfModule(modelInfo, action, vnfType, sdcServiceModelVersion, currentActiveRequest); + } + + @Test + public void getIsBaseVfModuleModelVersionIdNullTest() throws ApiException { + ModelInfo modelInfo = new ModelInfo(); + modelInfo.setModelInvariantId(MODEL_INVARIANT_ID); + modelInfo.setModelVersion(MODEL_VERSION); + modelInfo.setModelName(MODEL_NAME); + Boolean expected = false; + + doReturn(null).when(catDbClient).getVfModuleByModelInvariantUUIDAndModelVersion(MODEL_INVARIANT_ID, + MODEL_VERSION); + + Boolean result = requestHandler.getIsBaseVfModule(modelInfo, Action.deleteInstance, vnfType, + sdcServiceModelVersion, currentActiveRequest); + assertEquals(result, expected); + } + + @Test + public void getIsBaseVfModuleModelInfoNotSetTest() throws ApiException { + ModelInfo modelInfo = new ModelInfo(); + Boolean expected = false; + + Boolean result = requestHandler.getIsBaseVfModule(modelInfo, Action.deleteInstance, vnfType, + sdcServiceModelVersion, currentActiveRequest); + assertEquals(result, expected); + } + + @Test + public void getIsBaseVfModuleModelVersionNullTest() throws ApiException { + ModelInfo modelInfo = new ModelInfo(); + modelInfo.setModelInvariantId(MODEL_INVARIANT_ID); + modelInfo.setModelName(MODEL_NAME); + Boolean expected = false; + + Boolean result = requestHandler.getIsBaseVfModule(modelInfo, Action.deleteInstance, vnfType, + sdcServiceModelVersion, currentActiveRequest); + assertEquals(result, expected); + } + + @Test + public void getIsBaseVfModuleModelVersionNullUpdateTest() throws ApiException { + ModelInfo modelInfo = new ModelInfo(); + modelInfo.setModelInvariantId(MODEL_INVARIANT_ID); + modelInfo.setModelName(MODEL_NAME); + String errorMessage = "VnfType vnfType and VF Module Model Name modelName not found in MSO Catalog DB"; + + doNothing().when(requestHandler).updateStatus(currentActiveRequest, Status.FAILED, errorMessage); + + thrown.expect(VfModuleNotFoundException.class); + thrown.expectMessage(errorMessage); + requestHandler.getIsBaseVfModule(modelInfo, Action.updateInstance, vnfType, null, currentActiveRequest); + } + + @Test + public void getIsBaseVfModulesdcModelVersionEmptyTest() throws ApiException { + ModelInfo modelInfo = new ModelInfo(); + modelInfo.setModelInvariantId(MODEL_INVARIANT_ID); + modelInfo.setModelName(MODEL_NAME); + String errorMessage = "VnfType vnfType and VF Module Model Name modelName not found in MSO Catalog DB"; + + doNothing().when(requestHandler).updateStatus(currentActiveRequest, Status.FAILED, errorMessage); + + thrown.expect(VfModuleNotFoundException.class); + thrown.expectMessage(errorMessage); + requestHandler.getIsBaseVfModule(modelInfo, Action.updateInstance, vnfType, "", currentActiveRequest); + } + + @Test + public void getModelTypeApplyUpdatedConfigTest() { + ModelType modelTypeExpected = ModelType.vnf; + + ModelType modelTypeResult = requestHandler.getModelType(Action.applyUpdatedConfig, null); + assertEquals(modelTypeResult, modelTypeExpected); + } + + @Test + public void getModelTypeInPlaceSoftwareUpdateTest() { + ModelType modelTypeExpected = ModelType.vnf; + + ModelType modelTypeResult = requestHandler.getModelType(Action.inPlaceSoftwareUpdate, null); + assertEquals(modelTypeResult, modelTypeExpected); + } + + @Test + public void getModelTypeAddMembersTest() { + ModelType modelTypeExpected = ModelType.instanceGroup; + + ModelType modelTypeResult = requestHandler.getModelType(Action.addMembers, null); + assertEquals(modelTypeResult, modelTypeExpected); + } + + @Test + public void getModelTypeRemoveMembersTest() { + ModelType modelTypeExpected = ModelType.instanceGroup; + + ModelType modelTypeResult = requestHandler.getModelType(Action.removeMembers, null); + assertEquals(modelTypeResult, modelTypeExpected); + } + + @Test + public void getModelTypeTest() { + ModelType modelTypeExpected = ModelType.service; + ModelInfo modelInfo = new ModelInfo(); + modelInfo.setModelType(ModelType.service); + + ModelType modelTypeResult = requestHandler.getModelType(Action.createInstance, modelInfo); + assertEquals(modelTypeResult, modelTypeExpected); + } + } diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ResumeOrchestrationRequestTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ResumeOrchestrationRequestTest.java index 7e49fff50d..398966b0b3 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ResumeOrchestrationRequestTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ResumeOrchestrationRequestTest.java @@ -30,6 +30,7 @@ import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import static org.junit.Assert.assertEquals; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; @@ -53,9 +54,11 @@ import org.onap.so.apihandlerinfra.exceptions.RequestDbFailureException; import org.onap.so.apihandlerinfra.exceptions.ValidateException; import org.onap.so.db.request.beans.InfraActiveRequests; import org.onap.so.db.request.client.RequestsDbClient; +import org.onap.so.serviceinstancebeans.ModelInfo; import org.onap.so.serviceinstancebeans.ServiceInstancesRequest; import org.springframework.web.client.HttpClientErrorException; import com.fasterxml.jackson.databind.ObjectMapper; +import org.onap.so.serviceinstancebeans.ModelType; @RunWith(MockitoJUnitRunner.class) public class ResumeOrchestrationRequestTest { @@ -81,8 +84,20 @@ public class ResumeOrchestrationRequestTest { private static final String CURRENT_REQUEST_ID = "eca3a1b1-43ab-457e-ab1c-367263d148b4"; private static final String REQUEST_ID = "00032ab7-na18-42e5-965d-8ea592502019"; private static final String SERVICE_INSTANCE_ID = "00032ab7-na18-42e5-965d-8ea592502018"; + private static final String VNF_ID = "00032ab7-na18-42e5-965d-8ea592502017"; + private static final String VFMODULE_ID = "00032ab7-na18-42e5-965d-8ea592502016"; + private static final String NETWORK_ID = "00032ab7-na18-42e5-965d-8ea592502015"; + private static final String VOLUME_GROUP_ID = "00032ab7-na18-42e5-965d-8ea592502014"; private static final String SERVICE_INSTANCE_NAME = "serviceInstanceName"; - private static final String REQUEST_SCOPE = "service"; + private static final String VNF_NAME = "vnfName"; + private static final String VFMODULE_NAME = "vfModuleName"; + private static final String NETWORK_NAME = "networkName"; + private static final String VOLUME_GROUP_NAME = "volumeGroupName"; + private static final String SERVICE = "service"; + private static final String VNF = "vnf"; + private static final String VFMODULE = "vfModule"; + private static final String NETWORK = "network"; + private static final String VOLUME_GROUP = "volumeGroup"; private final Timestamp startTimeStamp = new Timestamp(System.currentTimeMillis()); private final Action action = Action.createInstance; private final Boolean aLaCarte = false; @@ -91,15 +106,18 @@ public class ResumeOrchestrationRequestTest { "http:localhost:6746/onap/so/infra/orchestrationRequests/v7/00032ab7-na18-42e5-965d-8ea592502019/resume"; private final RecipeLookupResult lookupResult = new RecipeLookupResult("/mso/async/services/WorkflowActionBB", 80); private RequestClientParameter requestClientParameter = null; + private RequestClientParameter requestClientParameterVfModule = null; private ObjectMapper mapper = new ObjectMapper(); private InfraActiveRequests infraActiveRequest = new InfraActiveRequests(); private InfraActiveRequests currentActiveRequest = new InfraActiveRequests(); + private InfraActiveRequests infraActiveRequestVfModule = new InfraActiveRequests(); private ServiceInstancesRequest sir = new ServiceInstancesRequest(); private ServiceInstancesRequest sirNullALaCarte = new ServiceInstancesRequest(); private String requestBody = null; private String requestBodyNullALaCarte = null; private ContainerRequestContext requestContext = null; private HashMap<String, String> instanceIdMap = new HashMap<>(); + ModelInfo modelInfo; @Before @@ -110,13 +128,16 @@ public class ResumeOrchestrationRequestTest { // Setup InfraActiveRequests setInfraActiveRequest(); setCurrentActiveRequest(); + setInfraActiveRequestVfModule(); requestBody = infraActiveRequest.getRequestBody(); sir = mapper.readValue(requestBody, ServiceInstancesRequest.class); requestBodyNullALaCarte = getRequestBody("/ALaCarteNull.json"); - sirNullALaCarte = sir = mapper.readValue(requestBodyNullALaCarte, ServiceInstancesRequest.class); + sirNullALaCarte = mapper.readValue(requestBodyNullALaCarte, ServiceInstancesRequest.class); setRequestClientParameter(); + setRequestClientParameterVfModule(); instanceIdMap.put("serviceInstanceId", SERVICE_INSTANCE_ID); + modelInfo = sir.getRequestDetails().getModelInfo(); } public String getRequestBody(String request) throws IOException { @@ -128,12 +149,21 @@ public class ResumeOrchestrationRequestTest { infraActiveRequest.setTenantId("tenant-id"); infraActiveRequest.setRequestBody(getRequestBody("/RequestBody.json")); infraActiveRequest.setAicCloudRegion("cloudRegion"); - infraActiveRequest.setRequestScope(REQUEST_SCOPE); + infraActiveRequest.setRequestScope(SERVICE); infraActiveRequest.setServiceInstanceId(SERVICE_INSTANCE_ID); infraActiveRequest.setServiceInstanceName(SERVICE_INSTANCE_NAME); infraActiveRequest.setRequestStatus(Status.IN_PROGRESS.toString()); infraActiveRequest.setRequestAction(Action.createInstance.toString()); infraActiveRequest.setServiceType("serviceType"); + infraActiveRequest.setVnfId(VNF_ID); + infraActiveRequest.setVfModuleId(VFMODULE_ID); + infraActiveRequest.setNetworkId(NETWORK_ID); + infraActiveRequest.setVolumeGroupId(VOLUME_GROUP_ID); + infraActiveRequest.setVnfName(VNF_NAME); + infraActiveRequest.setVfModuleName(VFMODULE_NAME); + infraActiveRequest.setNetworkName(NETWORK_NAME); + infraActiveRequest.setVolumeGroupName(VOLUME_GROUP_NAME); + infraActiveRequest.setRequestId(REQUEST_ID); } private void setCurrentActiveRequest() throws IOException { @@ -143,7 +173,7 @@ public class ResumeOrchestrationRequestTest { currentActiveRequest.setTenantId("tenant-id"); currentActiveRequest.setRequestBody(getRequestBody("/RequestBody.json")); currentActiveRequest.setAicCloudRegion("cloudRegion"); - currentActiveRequest.setRequestScope(REQUEST_SCOPE); + currentActiveRequest.setRequestScope(SERVICE); currentActiveRequest.setServiceInstanceId(SERVICE_INSTANCE_ID); currentActiveRequest.setServiceInstanceName(SERVICE_INSTANCE_NAME); currentActiveRequest.setRequestStatus(Status.IN_PROGRESS.toString()); @@ -154,13 +184,33 @@ public class ResumeOrchestrationRequestTest { currentActiveRequest.setProgress(new Long(5)); } + private void setInfraActiveRequestVfModule() throws IOException { + infraActiveRequestVfModule.setRequestBody(getRequestBody("/RequestBody.json")); + infraActiveRequestVfModule.setRequestScope(VFMODULE); + infraActiveRequestVfModule.setRequestStatus(Status.IN_PROGRESS.toString()); + infraActiveRequestVfModule.setRequestAction(Action.createInstance.toString()); + infraActiveRequestVfModule.setVnfId(VNF_ID); + infraActiveRequestVfModule.setVfModuleId(VFMODULE_ID); + infraActiveRequestVfModule.setVnfName(VNF_NAME); + infraActiveRequestVfModule.setVfModuleName(VFMODULE_NAME); + } + private void setRequestClientParameter() { - requestClientParameter = new RequestClientParameter.Builder().setRequestId(CURRENT_REQUEST_ID) - .setRecipeTimeout(80).setRequestAction(Action.createInstance.toString()) - .setServiceInstanceId(SERVICE_INSTANCE_ID).setPnfCorrelationId("pnfCorrelationId").setVnfId(null) - .setVfModuleId(null).setVolumeGroupId(null).setNetworkId(null).setServiceType("serviceType") - .setVnfType(null).setNetworkType(null).setRequestDetails(requestBody).setApiVersion(version) - .setALaCarte(aLaCarte).setRequestUri(requestUri).setInstanceGroupId(null).build(); + requestClientParameter = + new RequestClientParameter.Builder().setRequestId(CURRENT_REQUEST_ID).setRecipeTimeout(80) + .setRequestAction(Action.createInstance.toString()).setServiceInstanceId(SERVICE_INSTANCE_ID) + .setPnfCorrelationId("pnfCorrelationId").setVnfId(VNF_ID).setVfModuleId(VFMODULE_ID) + .setVolumeGroupId(VOLUME_GROUP_ID).setNetworkId(NETWORK_ID).setServiceType("serviceType") + .setVnfType(null).setNetworkType(null).setRequestDetails(requestBody).setApiVersion(version) + .setALaCarte(aLaCarte).setRequestUri(requestUri).setInstanceGroupId(null).build(); + } + + private void setRequestClientParameterVfModule() { + requestClientParameterVfModule = + new RequestClientParameter.Builder().setRequestId(CURRENT_REQUEST_ID).setRecipeTimeout(80) + .setRequestAction(Action.createInstance.toString()).setPnfCorrelationId("pnfCorrelationId") + .setVnfId(VNF_ID).setVfModuleId(VFMODULE_ID).setRequestDetails(requestBody) + .setApiVersion(version).setALaCarte(aLaCarte).setRequestUri(requestUri).build(); } @Test @@ -201,16 +251,20 @@ public class ResumeOrchestrationRequestTest { @Test public void resumeRequestTest() throws ApiException, IOException { Response response = null; + doReturn(instanceIdMap).when(resumeReq).setInstanceIdMap(infraActiveRequest, ModelType.service.toString()); + doReturn(SERVICE_INSTANCE_NAME).when(resumeReq).getInstanceName(infraActiveRequest, + ModelType.service.toString(), currentActiveRequest); when(requestHandler.convertJsonToServiceInstanceRequest(anyString(), any(Actions.class), anyString(), anyString())).thenReturn(sir); when(serviceInstances.getPnfCorrelationId(any(ServiceInstancesRequest.class))).thenReturn("pnfCorrelationId"); - doReturn(lookupResult).when(resumeReq).serviceRecipeLookup(currentActiveRequest, sir, action, aLaCarte); + doReturn(lookupResult).when(serviceInstances).getServiceInstanceOrchestrationURI(sir, action, aLaCarte, + currentActiveRequest); doReturn(requestClientParameter).when(resumeReq).setRequestClientParameter(lookupResult, version, infraActiveRequest, currentActiveRequest, "pnfCorrelationId", aLaCarte, sir); doNothing().when(resumeReq).requestDbSave(currentActiveRequest); when(requestHandler.postBPELRequest(any(InfraActiveRequests.class), any(RequestClientParameter.class), anyString(), anyString())).thenReturn(response); - doNothing().when(resumeReq).checkForInProgressRequest(currentActiveRequest, SERVICE_INSTANCE_ID, REQUEST_SCOPE, + doNothing().when(resumeReq).checkForInProgressRequest(currentActiveRequest, instanceIdMap, SERVICE, SERVICE_INSTANCE_NAME, action); resumeReq.resumeRequest(infraActiveRequest, currentActiveRequest, version, @@ -220,15 +274,8 @@ public class ResumeOrchestrationRequestTest { } @Test - public void serviceRecipeLookupTest() throws ApiException, IOException { - when(serviceInstances.getServiceURI(any(ServiceInstancesRequest.class), any(Action.class), anyBoolean())) - .thenReturn(lookupResult); - RecipeLookupResult result = resumeReq.serviceRecipeLookup(currentActiveRequest, sir, action, aLaCarte); - assertThat(result, sameBeanAs(lookupResult)); - } - - @Test public void setRequestClientParameterTest() throws ApiException, IOException { + doReturn(ModelType.service).when(requestHandler).getModelType(action, modelInfo); when(requestHandler.mapJSONtoMSOStyle(anyString(), any(ServiceInstancesRequest.class), anyBoolean(), any(Action.class))).thenReturn(requestBody); RequestClientParameter result = resumeReq.setRequestClientParameter(lookupResult, version, infraActiveRequest, @@ -237,6 +284,16 @@ public class ResumeOrchestrationRequestTest { } @Test + public void setRequestClientParameterVfModuleTest() throws ApiException, IOException { + when(requestHandler.mapJSONtoMSOStyle(anyString(), any(ServiceInstancesRequest.class), anyBoolean(), + any(Action.class))).thenReturn(requestBody); + doReturn(ModelType.vfModule).when(requestHandler).getModelType(action, modelInfo); + RequestClientParameter result = resumeReq.setRequestClientParameter(lookupResult, version, + infraActiveRequestVfModule, currentActiveRequest, "pnfCorrelationId", aLaCarte, sir); + assertThat(requestClientParameterVfModule, sameBeanAs(result)); + } + + @Test public void requestDbSaveTest() throws RequestDbFailureException { doNothing().when(requestDbClient).save(currentActiveRequest); resumeReq.requestDbSave(currentActiveRequest); @@ -246,17 +303,22 @@ public class ResumeOrchestrationRequestTest { @Test public void resumeRequestTestALaCarteNull() throws ApiException, IOException { Response response = null; - + doReturn(instanceIdMap).when(resumeReq).setInstanceIdMap(infraActiveRequest, ModelType.service.toString()); + doReturn(SERVICE_INSTANCE_NAME).when(resumeReq).getInstanceName(infraActiveRequest, + ModelType.service.toString(), currentActiveRequest); when(requestHandler.convertJsonToServiceInstanceRequest(anyString(), any(Actions.class), anyString(), anyString())).thenReturn(sirNullALaCarte); when(serviceInstances.getPnfCorrelationId(any(ServiceInstancesRequest.class))).thenReturn("pnfCorrelationId"); - doReturn(lookupResult).when(resumeReq).serviceRecipeLookup(currentActiveRequest, sir, action, aLaCarte); + doReturn(false).when(msoRequest).getAlacarteFlag(sirNullALaCarte); + doReturn(lookupResult).when(serviceInstances).getServiceInstanceOrchestrationURI(sirNullALaCarte, action, false, + currentActiveRequest); doReturn(requestClientParameter).when(resumeReq).setRequestClientParameter(lookupResult, version, - infraActiveRequest, currentActiveRequest, "pnfCorrelationId", aLaCarte, sir); + infraActiveRequest, currentActiveRequest, "pnfCorrelationId", aLaCarte, sirNullALaCarte); + doReturn(false).when(resumeReq).setALaCarteFlagIfNull(SERVICE, action); doNothing().when(resumeReq).requestDbSave(currentActiveRequest); when(requestHandler.postBPELRequest(any(InfraActiveRequests.class), any(RequestClientParameter.class), anyString(), anyString())).thenReturn(response); - doNothing().when(resumeReq).checkForInProgressRequest(currentActiveRequest, SERVICE_INSTANCE_ID, REQUEST_SCOPE, + doNothing().when(resumeReq).checkForInProgressRequest(currentActiveRequest, instanceIdMap, SERVICE, SERVICE_INSTANCE_NAME, action); resumeReq.resumeRequest(infraActiveRequest, currentActiveRequest, version, @@ -266,18 +328,8 @@ public class ResumeOrchestrationRequestTest { } @Test - public void serviceRecipeLookupErrorTest() throws IOException, ApiException { - when(serviceInstances.getServiceURI(sir, action, aLaCarte)) - .thenThrow(new IOException("Error occurred on recipe lookup")); - doNothing().when(requestHandler).updateStatus(any(InfraActiveRequests.class), any(Status.class), anyString()); - - thrown.expect(ValidateException.class); - thrown.expectMessage("Error occurred on recipe lookup"); - resumeReq.serviceRecipeLookup(currentActiveRequest, sir, action, aLaCarte); - } - - @Test public void setRequestClientParameterErrorTest() throws ApiException, IOException { + doReturn(ModelType.service).when(requestHandler).getModelType(action, modelInfo); when(requestHandler.mapJSONtoMSOStyle(anyString(), any(ServiceInstancesRequest.class), anyBoolean(), any(Action.class))).thenThrow(new IOException("IOException")); @@ -290,39 +342,141 @@ public class ResumeOrchestrationRequestTest { @Test public void checkForInProgressRequest() throws ApiException { doReturn(infraActiveRequest).when(requestHandler).duplicateCheck(action, instanceIdMap, SERVICE_INSTANCE_NAME, - REQUEST_SCOPE, currentActiveRequest); + SERVICE, currentActiveRequest); doReturn(true).when(requestHandler).camundaHistoryCheck(infraActiveRequest, currentActiveRequest); doThrow(DuplicateRequestException.class).when(requestHandler).buildErrorOnDuplicateRecord(currentActiveRequest, - action, instanceIdMap, SERVICE_INSTANCE_NAME, REQUEST_SCOPE, infraActiveRequest); + action, instanceIdMap, SERVICE_INSTANCE_NAME, SERVICE, infraActiveRequest); thrown.expect(DuplicateRequestException.class); - resumeReq.checkForInProgressRequest(currentActiveRequest, SERVICE_INSTANCE_ID, REQUEST_SCOPE, - SERVICE_INSTANCE_NAME, action); + resumeReq.checkForInProgressRequest(currentActiveRequest, instanceIdMap, SERVICE, SERVICE_INSTANCE_NAME, + action); } @Test public void checkForInProgressRequestNoInProgressRequests() throws ApiException { - doReturn(null).when(requestHandler).duplicateCheck(action, instanceIdMap, SERVICE_INSTANCE_NAME, REQUEST_SCOPE, + doReturn(null).when(requestHandler).duplicateCheck(action, instanceIdMap, SERVICE_INSTANCE_NAME, SERVICE, currentActiveRequest); - resumeReq.checkForInProgressRequest(currentActiveRequest, SERVICE_INSTANCE_ID, REQUEST_SCOPE, - SERVICE_INSTANCE_NAME, action); - verify(requestHandler).duplicateCheck(action, instanceIdMap, SERVICE_INSTANCE_NAME, REQUEST_SCOPE, + resumeReq.checkForInProgressRequest(currentActiveRequest, instanceIdMap, SERVICE, SERVICE_INSTANCE_NAME, + action); + verify(requestHandler).duplicateCheck(action, instanceIdMap, SERVICE_INSTANCE_NAME, SERVICE, currentActiveRequest); } @Test public void checkForInProgressRequestCamundaHistoryCheckReturnsNoInProgress() throws ApiException { doReturn(infraActiveRequest).when(requestHandler).duplicateCheck(action, instanceIdMap, SERVICE_INSTANCE_NAME, - REQUEST_SCOPE, currentActiveRequest); + SERVICE, currentActiveRequest); doReturn(false).when(requestHandler).camundaHistoryCheck(infraActiveRequest, currentActiveRequest); - resumeReq.checkForInProgressRequest(currentActiveRequest, SERVICE_INSTANCE_ID, REQUEST_SCOPE, - SERVICE_INSTANCE_NAME, action); - verify(requestHandler).duplicateCheck(action, instanceIdMap, SERVICE_INSTANCE_NAME, REQUEST_SCOPE, + resumeReq.checkForInProgressRequest(currentActiveRequest, instanceIdMap, SERVICE, SERVICE_INSTANCE_NAME, + action); + verify(requestHandler).duplicateCheck(action, instanceIdMap, SERVICE_INSTANCE_NAME, SERVICE, currentActiveRequest); verify(requestHandler).camundaHistoryCheck(infraActiveRequest, currentActiveRequest); } + @Test + public void setInstanceIdMapServiceTest() { + HashMap<String, String> expected = new HashMap<>(); + expected.put("serviceInstanceId", SERVICE_INSTANCE_ID); + HashMap<String, String> result = resumeReq.setInstanceIdMap(infraActiveRequest, SERVICE); + assertEquals(result, expected); + } + + @Test + public void setInstanceIdMapRequestScopeNotValidTest() { + HashMap<String, String> expected = new HashMap<>(); + HashMap<String, String> result = resumeReq.setInstanceIdMap(infraActiveRequest, "test"); + assertEquals(result, expected); + } + + @Test + public void setInstanceIdMapVnfTest() { + HashMap<String, String> expected = new HashMap<>(); + expected.put("vnfInstanceId", VNF_ID); + HashMap<String, String> result = resumeReq.setInstanceIdMap(infraActiveRequest, VNF); + assertEquals(result, expected); + } + + @Test + public void setInstanceIdMapVfModuleTest() { + HashMap<String, String> expected = new HashMap<>(); + expected.put("vfModuleInstanceId", VFMODULE_ID); + HashMap<String, String> result = resumeReq.setInstanceIdMap(infraActiveRequest, VFMODULE); + assertEquals(result, expected); + } + + @Test + public void setInstanceIdMapNetworkTest() { + HashMap<String, String> expected = new HashMap<>(); + expected.put("networkInstanceId", NETWORK_ID); + HashMap<String, String> result = resumeReq.setInstanceIdMap(infraActiveRequest, NETWORK); + assertEquals(result, expected); + } + + @Test + public void setInstanceIdMapVolumeGroupTest() { + HashMap<String, String> expected = new HashMap<>(); + expected.put("volumeGroupInstanceId", VOLUME_GROUP_ID); + HashMap<String, String> result = resumeReq.setInstanceIdMap(infraActiveRequest, VOLUME_GROUP); + assertEquals(result, expected); + } + + @Test + public void setInstanceNameServiceTest() throws ValidateException, RequestDbFailureException { + String result = resumeReq.getInstanceName(infraActiveRequest, SERVICE, currentActiveRequest); + assertEquals(result, SERVICE_INSTANCE_NAME); + } + + @Test + public void setInstanceNameRequestScopeNotValidTest() throws ValidateException, RequestDbFailureException { + thrown.expect(ValidateException.class); + thrown.expectMessage( + "requestScope: \"test\" from request: 00032ab7-na18-42e5-965d-8ea592502019 does not match a ModelType enum."); + + resumeReq.getInstanceName(infraActiveRequest, "test", currentActiveRequest); + } + + @Test + public void setInstanceNameVnfTest() throws ValidateException, RequestDbFailureException { + String result = resumeReq.getInstanceName(infraActiveRequest, VNF, currentActiveRequest); + assertEquals(result, VNF_NAME); + } + @Test + public void setInstanceNameVfModuleTest() throws ValidateException, RequestDbFailureException { + String result = resumeReq.getInstanceName(infraActiveRequest, VFMODULE, currentActiveRequest); + assertEquals(result, VFMODULE_NAME); + } + + @Test + public void setInstanceNameNetworkTest() throws ValidateException, RequestDbFailureException { + String result = resumeReq.getInstanceName(infraActiveRequest, NETWORK, currentActiveRequest); + assertEquals(result, NETWORK_NAME); + } + + @Test + public void setInstanceNameVolumeGroupTest() throws ValidateException, RequestDbFailureException { + String result = resumeReq.getInstanceName(infraActiveRequest, VOLUME_GROUP, currentActiveRequest); + assertEquals(result, VOLUME_GROUP_NAME); + } + + @Test + public void setALaCarteFlagIfNullTest() { + Boolean aLaCarteFlag = resumeReq.setALaCarteFlagIfNull(SERVICE, action); + assertEquals(aLaCarteFlag, false); + } + + @Test + public void setALaCarteFlagIfNullVnfTest() { + Boolean aLaCarteFlag = resumeReq.setALaCarteFlagIfNull(VNF, action); + assertEquals(aLaCarteFlag, true); + } + + @Test + public void setALaCarteFlagIfNullRecreateTest() { + Boolean aLaCarteFlag = resumeReq.setALaCarteFlagIfNull(VNF, Action.recreateInstance); + assertEquals(aLaCarteFlag, false); + } } diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/ResumeOrchestrationRequest/RequestBody.json b/mso-api-handlers/mso-api-handler-infra/src/test/resources/ResumeOrchestrationRequest/RequestBody.json index 5cd31427a0..7e8ed4dee1 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/resources/ResumeOrchestrationRequest/RequestBody.json +++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/ResumeOrchestrationRequest/RequestBody.json @@ -8,6 +8,12 @@ }, "requestParameters":{ "aLaCarte":"false" - } + }, + "modelInfo":{ + "modelInvariantId": "f7ce78bb-423b-11e7-93f8-0050569a7965", + "modelVersion": "1.0", + "modelType":"service", + "modelName":"serviceModel" + } } }
\ No newline at end of file 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) diff --git a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/client/CatalogDbClient.java b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/client/CatalogDbClient.java index a1f926e25f..e5f2758be7 100644 --- a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/client/CatalogDbClient.java +++ b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/client/CatalogDbClient.java @@ -73,6 +73,7 @@ import org.springframework.http.client.ClientHttpRequestFactory; import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; import org.springframework.stereotype.Component; import org.springframework.web.client.RestTemplate; +import org.springframework.web.util.UriComponentsBuilder; import uk.co.blackpepper.bowman.Client; import uk.co.blackpepper.bowman.ClientFactory; import uk.co.blackpepper.bowman.Configuration; @@ -639,10 +640,10 @@ public class CatalogDbClient { "Get Rainy Day Status - Flow Name {}, Service Type: {} , vnfType {} , errorCode {}, workStep {}, errorMessage {}", flowName, serviceType, vnfType, errorCode, workStep, errorMessage); return this.getSingleResource(rainyDayHandlerStatusClient, - getUri(UriBuilder.fromUri(endpoint + RAINY_DAY_HANDLER_MACRO + SEARCH + findRainyDayHandler) + UriComponentsBuilder.fromUriString(endpoint + RAINY_DAY_HANDLER_MACRO + SEARCH + findRainyDayHandler) .queryParam(FLOW_NAME, flowName).queryParam(SERVICE_TYPE, serviceType) .queryParam(VNF_TYPE, vnfType).queryParam(ERROR_CODE, errorCode).queryParam(WORK_STEP, workStep) - .queryParam(ERROR_MESSAGE, errorMessage).build().toString())); + .queryParam(ERROR_MESSAGE, errorMessage).build().encode().toUri()); } public ServiceRecipe getFirstByServiceModelUUIDAndAction(String modelUUID, String action) { @@ -880,4 +881,12 @@ public class CatalogDbClient { return this.getMultipleResources(workflowClient, getUri(UriBuilder.fromUri(findWorkflowByModelUUID) .queryParam(VNF_RESOURCE_MODEL_UUID, vnfResourceModelUUID).build().toString())); } + + public String getEndpoint() { + return endpoint; + } + + public void setEndpoint(String endpoint) { + this.endpoint = endpoint; + } } |