aboutsummaryrefslogtreecommitdiffstats
path: root/mso-api-handlers
diff options
context:
space:
mode:
Diffstat (limited to 'mso-api-handlers')
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationRequests.java26
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/RequestHandlerUtils.java19
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/OrchestrationRequestsUnitTest.java115
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/RequestHandlerUtilsUnitTest.java60
4 files changed, 194 insertions, 26 deletions
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationRequests.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationRequests.java
index e14b01792a..b4a3128de8 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationRequests.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationRequests.java
@@ -94,8 +94,8 @@ public class OrchestrationRequests {
@Produces(MediaType.APPLICATION_JSON)
@Transactional
public Response getOrchestrationRequest(@PathParam("requestId") String requestId,
- @PathParam("version") String version, @QueryParam("includeCloudRequest") boolean includeCloudRequest)
- throws ApiException {
+ @PathParam("version") String version, @QueryParam("includeCloudRequest") boolean includeCloudRequest,
+ @QueryParam("extSystemErrorSource") boolean extSystemErrorSource) throws ApiException {
String apiVersion = version.substring(1);
GetOrchestrationResponse orchestrationResponse = new GetOrchestrationResponse();
@@ -142,7 +142,8 @@ public class OrchestrationRequests {
throw validateException;
}
- Request request = mapInfraActiveRequestToRequest(infraActiveRequest, includeCloudRequest);
+ Request request = mapInfraActiveRequestToRequest(infraActiveRequest, includeCloudRequest, extSystemErrorSource);
+
if (!requestProcessingData.isEmpty()) {
request.setRequestProcessingData(mapRequestProcessingData(requestProcessingData));
}
@@ -158,7 +159,8 @@ public class OrchestrationRequests {
@Produces(MediaType.APPLICATION_JSON)
@Transactional
public Response getOrchestrationRequest(@Context UriInfo ui, @PathParam("version") String version,
- @QueryParam("includeCloudRequest") boolean includeCloudRequest) throws ApiException {
+ @QueryParam("includeCloudRequest") boolean includeCloudRequest,
+ @QueryParam("extSystemErrorSource") boolean extSystemErrorSource) throws ApiException {
long startTime = System.currentTimeMillis();
@@ -195,7 +197,8 @@ public class OrchestrationRequests {
List<RequestProcessingData> requestProcessingData =
requestsDbClient.getRequestProcessingDataBySoRequestId(infraActive.getRequestId());
RequestList requestList = new RequestList();
- Request request = mapInfraActiveRequestToRequest(infraActive, includeCloudRequest);
+ Request request = mapInfraActiveRequestToRequest(infraActive, includeCloudRequest, extSystemErrorSource);
+
if (!requestProcessingData.isEmpty()) {
request.setRequestProcessingData(mapRequestProcessingData(requestProcessingData));
}
@@ -290,8 +293,8 @@ public class OrchestrationRequests {
return Response.status(HttpStatus.SC_NO_CONTENT).entity("").build();
}
- protected Request mapInfraActiveRequestToRequest(InfraActiveRequests iar, boolean includeCloudRequest)
- throws ApiException {
+ protected Request mapInfraActiveRequestToRequest(InfraActiveRequests iar, boolean includeCloudRequest,
+ boolean extSystemErrorSource) throws ApiException {
String requestBody = iar.getRequestBody();
Request request = new Request();
@@ -427,10 +430,19 @@ public class OrchestrationRequests {
});
}
+ mapExtSystemErrorSourceToRequest(iar, status, extSystemErrorSource);
+
request.setRequestStatus(status);
return request;
}
+ protected void mapExtSystemErrorSourceToRequest(InfraActiveRequests iar, RequestStatus status,
+ boolean extSystemErrorSource) {
+ if (extSystemErrorSource) {
+ status.setExtSystemErrorSource(iar.getExtSystemErrorSource());
+ }
+ }
+
public List<org.onap.so.serviceinstancebeans.RequestProcessingData> mapRequestProcessingData(
List<org.onap.so.db.request.beans.RequestProcessingData> processingData) {
List<org.onap.so.serviceinstancebeans.RequestProcessingData> addedRequestProcessingData = new ArrayList<>();
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 c46e27b844..86e2f5ce93 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
@@ -626,7 +626,7 @@ public class RequestHandlerUtils extends AbstractRestHandler {
protected InfraActiveRequests createNewRecordCopyFromInfraActiveRequest(InfraActiveRequests infraActiveRequest,
String requestId, Timestamp startTimeStamp, String source, String requestUri, String requestorId,
- String originalRequestId) {
+ String originalRequestId) throws ApiException {
InfraActiveRequests request = new InfraActiveRequests();
request.setRequestId(requestId);
request.setStartTime(startTimeStamp);
@@ -649,11 +649,24 @@ public class RequestHandlerUtils extends AbstractRestHandler {
}
protected void setInstanceIdAndName(InfraActiveRequests infraActiveRequest,
- InfraActiveRequests currentActiveRequest) {
+ InfraActiveRequests currentActiveRequest) throws ApiException {
String requestScope = infraActiveRequest.getRequestScope();
try {
ModelType type = ModelType.valueOf(requestScope);
- type.setName(currentActiveRequest, type.getName(infraActiveRequest));
+ String instanceName = type.getName(infraActiveRequest);
+ if (instanceName == null && type.equals(ModelType.vfModule)) {
+ logger.error("vfModule for requestId: {} being resumed does not have an instanceName.",
+ infraActiveRequest.getRequestId());
+ ValidateException validateException = new ValidateException.Builder(
+ "vfModule for requestId: " + infraActiveRequest.getRequestId()
+ + " being resumed does not have an instanceName.",
+ HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_BAD_PARAMETER).build();
+ updateStatus(currentActiveRequest, Status.FAILED, validateException.getMessage());
+ throw validateException;
+ }
+ if (instanceName != null) {
+ type.setName(currentActiveRequest, instanceName);
+ }
type.setId(currentActiveRequest, type.getId(infraActiveRequest));
} catch (IllegalArgumentException e) {
logger.error(
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/OrchestrationRequestsUnitTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/OrchestrationRequestsUnitTest.java
index 19b9d7ea1e..a400caeae2 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/OrchestrationRequestsUnitTest.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/OrchestrationRequestsUnitTest.java
@@ -21,21 +21,51 @@
package org.onap.so.apihandlerinfra;
import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.List;
+import javax.ws.rs.core.Response;
+import org.apache.http.HttpStatus;
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.Mockito;
import org.mockito.Spy;
import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.so.apihandler.common.ResponseBuilder;
import org.onap.so.apihandlerinfra.exceptions.ApiException;
import org.onap.so.db.request.beans.InfraActiveRequests;
+import org.onap.so.db.request.client.RequestsDbClient;
import org.onap.so.serviceinstancebeans.InstanceReferences;
import org.onap.so.serviceinstancebeans.Request;
import org.onap.so.serviceinstancebeans.RequestStatus;
@RunWith(MockitoJUnitRunner.class)
public class OrchestrationRequestsUnitTest {
-
+ @Mock
+ private RequestsDbClient requestDbClient;
+ @Mock
+ private MsoRequest msoRequest;
+ @Mock
+ private ResponseBuilder builder;
+ @Mock
+ private Response response;
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+ @InjectMocks
@Spy
private OrchestrationRequests orchestrationRequests;
@@ -43,8 +73,21 @@ public class OrchestrationRequestsUnitTest {
private static final String SERVICE_INSTANCE_ID = "7cb9aa56-dd31-41e5-828e-d93027d4ebbb";
private static final String ORIGINAL_REQUEST_ID = "8f2d38a6-7c20-465a-bd7e-075645f1394b";
private static final String SERVICE = "service";
+ private static final String EXT_SYSTEM_ERROR_SOURCE = "external system error source";
private InfraActiveRequests iar;
boolean includeCloudRequest = false;
+ boolean extSystemErrorSource = false;
+ 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 VERSION = "v7";
+ List<org.onap.so.db.request.beans.RequestProcessingData> requestProcessingData = new ArrayList<>();
@Before
public void setup() {
@@ -52,6 +95,12 @@ public class OrchestrationRequestsUnitTest {
iar.setRequestScope(SERVICE);
iar.setRequestId(REQUEST_ID);
iar.setServiceInstanceId(SERVICE_INSTANCE_ID);
+ when(requestDbClient.getInfraActiveRequestbyRequestId(Mockito.eq(REQUEST_ID))).thenReturn(iar);
+ when(requestDbClient.getRequestProcessingDataBySoRequestId(Mockito.eq(REQUEST_ID)))
+ .thenReturn(requestProcessingData);
+
+ when(builder.buildResponse(Mockito.eq(HttpStatus.SC_OK), Mockito.eq(REQUEST_ID), any(Object.class),
+ any(String.class))).thenReturn(response);
}
@Test
@@ -68,7 +117,8 @@ public class OrchestrationRequestsUnitTest {
iar.setOriginalRequestId(ORIGINAL_REQUEST_ID);
- Request result = orchestrationRequests.mapInfraActiveRequestToRequest(iar, includeCloudRequest);
+ Request result =
+ orchestrationRequests.mapInfraActiveRequestToRequest(iar, includeCloudRequest, extSystemErrorSource);
assertThat(result, sameBeanAs(expected));
}
@@ -83,8 +133,67 @@ public class OrchestrationRequestsUnitTest {
expected.setRequestStatus(requestStatus);
expected.setRequestScope(SERVICE);
- Request result = orchestrationRequests.mapInfraActiveRequestToRequest(iar, includeCloudRequest);
+ Request result =
+ orchestrationRequests.mapInfraActiveRequestToRequest(iar, includeCloudRequest, extSystemErrorSource);
assertThat(result, sameBeanAs(expected));
}
+ @Test
+ public void mapExtSystemErrorSourceToRequestFalseTest() throws ApiException {
+ InstanceReferences instanceReferences = new InstanceReferences();
+ instanceReferences.setServiceInstanceId(SERVICE_INSTANCE_ID);
+ RequestStatus requestStatus = new RequestStatus();
+
+ Request expected = new Request();
+ expected.setRequestId(REQUEST_ID);
+ expected.setInstanceReferences(instanceReferences);
+ expected.setRequestStatus(requestStatus);
+ expected.setRequestScope(SERVICE);
+
+ extSystemErrorSource = false;
+ includeCloudRequest = false;
+
+ Request actual =
+ orchestrationRequests.mapInfraActiveRequestToRequest(iar, includeCloudRequest, extSystemErrorSource);
+ assertThat(actual, sameBeanAs(expected));
+ }
+
+ @Test
+ public void mapExtSystemErrorSourceToRequestTrueTest() throws ApiException {
+ InstanceReferences instanceReferences = new InstanceReferences();
+ instanceReferences.setServiceInstanceId(SERVICE_INSTANCE_ID);
+ RequestStatus requestStatus = new RequestStatus();
+ requestStatus.setExtSystemErrorSource(EXT_SYSTEM_ERROR_SOURCE);
+
+ Request expected = new Request();
+ expected.setRequestId(REQUEST_ID);
+ expected.setInstanceReferences(instanceReferences);
+ expected.setRequestStatus(requestStatus);
+ expected.setRequestScope(SERVICE);
+
+ extSystemErrorSource = true;
+ includeCloudRequest = false;
+ iar.setExtSystemErrorSource(EXT_SYSTEM_ERROR_SOURCE);
+
+ Request actual =
+ orchestrationRequests.mapInfraActiveRequestToRequest(iar, includeCloudRequest, extSystemErrorSource);
+ assertThat(actual, sameBeanAs(expected));
+ }
+
+ @Test
+ public void mapExtSystemErrorSourceToRequestMethodInvokedTest() throws ApiException, IOException {
+ extSystemErrorSource = true;
+ includeCloudRequest = false;
+ orchestrationRequests.getOrchestrationRequest(REQUEST_ID, VERSION, includeCloudRequest, extSystemErrorSource);
+
+ verify(orchestrationRequests, times(1)).mapExtSystemErrorSourceToRequest(Mockito.eq(iar), Mockito.any(),
+ Mockito.eq(extSystemErrorSource));
+ }
+
+ @Test
+ public void requestStatusExtSystemErrorSourceTest() {
+ RequestStatus requestStatus = new RequestStatus();
+ requestStatus.setExtSystemErrorSource(EXT_SYSTEM_ERROR_SOURCE);
+ assertThat(requestStatus.getExtSystemErrorSource(), is(equalTo(EXT_SYSTEM_ERROR_SOURCE)));
+ }
}
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 3cb4e0c9c2..91ca756a51 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
@@ -39,6 +39,7 @@ 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.ValidateException;
import org.onap.so.apihandlerinfra.exceptions.VfModuleNotFoundException;
import org.onap.so.db.catalog.beans.VfModule;
import org.onap.so.db.catalog.client.CatalogDbClient;
@@ -140,7 +141,7 @@ public class RequestHandlerUtilsUnitTest {
@Test
- public void createNewRecordCopyFromInfraActiveRequestTest() throws IOException {
+ public void createNewRecordCopyFromInfraActiveRequestTest() throws IOException, ApiException {
doNothing().when(requestHandler).setInstanceIdAndName(infraActiveRequest, currentActiveRequest);
doReturn(getRequestBody("/RequestBodyNewRequestorId.json")).when(requestHandler)
.updateRequestorIdInRequestBody(infraActiveRequest, "yyyyyy");
@@ -150,14 +151,14 @@ public class RequestHandlerUtilsUnitTest {
}
@Test
- public void createNewRecordCopyFromInfraActiveRequestNullIARTest() {
+ public void createNewRecordCopyFromInfraActiveRequestNullIARTest() throws ApiException {
InfraActiveRequests result = requestHandler.createNewRecordCopyFromInfraActiveRequest(null, CURRENT_REQUEST_ID,
startTimeStamp, "VID", requestUri, "xxxxxx", RESUMED_REQUEST_ID);
assertThat(currentActiveRequestIARNull, sameBeanAs(result));
}
@Test
- public void setInstanceIdAndNameServiceTest() {
+ public void setInstanceIdAndNameServiceTest() throws ApiException {
InfraActiveRequests serviceRequest = new InfraActiveRequests();
InfraActiveRequests expected = new InfraActiveRequests();
@@ -169,7 +170,40 @@ public class RequestHandlerUtilsUnitTest {
}
@Test
- public void setInstanceIdAndNameRequestScopeNotValidTest() {
+ public void setInstanceIdAndNameServiceNullInstanceNameTest() throws ApiException {
+ InfraActiveRequests serviceRequest = new InfraActiveRequests();
+
+ InfraActiveRequests request = new InfraActiveRequests();
+ request.setServiceInstanceId(SERVICE_INSTANCE_ID);
+ request.setRequestScope(ModelType.service.toString());
+
+ InfraActiveRequests expected = new InfraActiveRequests();
+ expected.setServiceInstanceId(SERVICE_INSTANCE_ID);
+
+ requestHandler.setInstanceIdAndName(request, serviceRequest);
+ assertThat(serviceRequest, sameBeanAs(expected));
+ }
+
+ @Test
+ public void setInstanceIdAndNameServiceNullInstanceNameVfModuleTest() throws ApiException {
+ InfraActiveRequests vfModuleRequest = new InfraActiveRequests();
+ String errorMessage =
+ "vfModule for requestId: 59c7247f-839f-4923-90c3-05faa3ab354d being resumed does not have an instanceName.";
+ doNothing().when(requestHandler).updateStatus(vfModuleRequest, Status.FAILED, errorMessage);
+
+ InfraActiveRequests request = new InfraActiveRequests();
+ request.setServiceInstanceId(VFMODULE_ID);
+ request.setRequestScope(ModelType.vfModule.toString());
+ request.setRequestId(RESUMED_REQUEST_ID);
+
+ thrown.expect(ValidateException.class);
+ thrown.expectMessage(errorMessage);
+
+ requestHandler.setInstanceIdAndName(request, vfModuleRequest);
+ }
+
+ @Test
+ public void setInstanceIdAndNameRequestScopeNotValidTest() throws ApiException {
InfraActiveRequests originalServiceRequest = new InfraActiveRequests();
originalServiceRequest.setRequestScope("test");
InfraActiveRequests serviceRequest = new InfraActiveRequests();
@@ -181,7 +215,7 @@ public class RequestHandlerUtilsUnitTest {
}
@Test
- public void setInstanceIdAndNameVnfTest() {
+ public void setInstanceIdAndNameVnfTest() throws ApiException {
InfraActiveRequests vnfRequestOriginal = new InfraActiveRequests();
vnfRequestOriginal.setRequestScope("vnf");
vnfRequestOriginal.setVnfId(VNF_ID);
@@ -197,7 +231,7 @@ public class RequestHandlerUtilsUnitTest {
}
@Test
- public void setInstanceIdAndNameVfModuleTest() {
+ public void setInstanceIdAndNameVfModuleTest() throws ApiException {
InfraActiveRequests vfModuleRequestOriginal = new InfraActiveRequests();
vfModuleRequestOriginal.setRequestScope("vfModule");
vfModuleRequestOriginal.setVfModuleId(VFMODULE_ID);
@@ -213,7 +247,7 @@ public class RequestHandlerUtilsUnitTest {
}
@Test
- public void setInstanceIdAndNameNetworkTest() {
+ public void setInstanceIdAndNameNetworkTest() throws ApiException {
InfraActiveRequests networkRequestOriginal = new InfraActiveRequests();
networkRequestOriginal.setRequestScope("network");
networkRequestOriginal.setNetworkId(NETWORK_ID);
@@ -229,7 +263,7 @@ public class RequestHandlerUtilsUnitTest {
}
@Test
- public void setInstanceIdAndNameVolumeGroupTest() {
+ public void setInstanceIdAndNameVolumeGroupTest() throws ApiException {
InfraActiveRequests volumeGroupRequestOriginal = new InfraActiveRequests();
volumeGroupRequestOriginal.setRequestScope("volumeGroup");
volumeGroupRequestOriginal.setVolumeGroupId(VOLUME_GROUP_ID);
@@ -357,7 +391,7 @@ public class RequestHandlerUtilsUnitTest {
}
@Test
- public void getModelTypeApplyUpdatedConfigTest() {
+ public void getModelTypeApplyUpdatedConfigTest() throws ApiException {
ModelType modelTypeExpected = ModelType.vnf;
ModelType modelTypeResult = requestHandler.getModelType(Action.applyUpdatedConfig, null);
@@ -365,7 +399,7 @@ public class RequestHandlerUtilsUnitTest {
}
@Test
- public void getModelTypeInPlaceSoftwareUpdateTest() {
+ public void getModelTypeInPlaceSoftwareUpdateTest() throws ApiException {
ModelType modelTypeExpected = ModelType.vnf;
ModelType modelTypeResult = requestHandler.getModelType(Action.inPlaceSoftwareUpdate, null);
@@ -373,7 +407,7 @@ public class RequestHandlerUtilsUnitTest {
}
@Test
- public void getModelTypeAddMembersTest() {
+ public void getModelTypeAddMembersTest() throws ApiException {
ModelType modelTypeExpected = ModelType.instanceGroup;
ModelType modelTypeResult = requestHandler.getModelType(Action.addMembers, null);
@@ -381,7 +415,7 @@ public class RequestHandlerUtilsUnitTest {
}
@Test
- public void getModelTypeRemoveMembersTest() {
+ public void getModelTypeRemoveMembersTest() throws ApiException {
ModelType modelTypeExpected = ModelType.instanceGroup;
ModelType modelTypeResult = requestHandler.getModelType(Action.removeMembers, null);
@@ -389,7 +423,7 @@ public class RequestHandlerUtilsUnitTest {
}
@Test
- public void getModelTypeTest() {
+ public void getModelTypeTest() throws ApiException {
ModelType modelTypeExpected = ModelType.service;
ModelInfo modelInfo = new ModelInfo();
modelInfo.setModelType(ModelType.service);