diff options
Diffstat (limited to 'mso-api-handlers')
8 files changed, 99 insertions, 27 deletions
diff --git a/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/common/CommonConstants.java b/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/common/CommonConstants.java index 24fb0e0d20..1dece5c341 100644 --- a/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/common/CommonConstants.java +++ b/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/common/CommonConstants.java @@ -80,6 +80,7 @@ public final class CommonConstants { public static final String X_PATCH_VERSION = "X-PatchVersion"; public static final String X_LATEST_VERSION = "X-LatestVersion"; public static final String INSTANCE_GROUP_ID = "instanceGroupId"; + public static final String INSTANCE_GROUP_INSTANCE_ID = "instanceGroupInstanceId"; private CommonConstants () { // prevent creating an instance of this class diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/GlobalHealthcheckHandler.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/GlobalHealthcheckHandler.java index b002aa9f54..07c98c19b9 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/GlobalHealthcheckHandler.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/GlobalHealthcheckHandler.java @@ -114,8 +114,6 @@ public class GlobalHealthcheckHandler { HealthcheckResponse rsp = new HealthcheckResponse(); try{ - long startTime = System.currentTimeMillis (); - MsoLogger.setServiceName ("GlobalHealthcheck"); // Generated RequestId String requestId = requestContext.getProperty("requestId").toString(); MsoLogger.setLogContext(requestId, null); diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/NodeHealthcheckHandler.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/NodeHealthcheckHandler.java index cb458a7420..351a35826d 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/NodeHealthcheckHandler.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/NodeHealthcheckHandler.java @@ -34,7 +34,6 @@ import javax.ws.rs.core.Response; import org.apache.http.HttpStatus; import org.onap.so.logger.MessageEnum; -import org.onap.so.logger.MsoLogger; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; @@ -60,8 +59,6 @@ public class NodeHealthcheckHandler { @ApiOperation(value="Performing node health check",response=Response.class) @Transactional public Response nodeHealthcheck (@Context ContainerRequestContext requestContext) throws UnknownHostException { - long startTime = System.currentTimeMillis (); - MsoLogger.setServiceName ("NodeHealthcheck"); // Generated RequestId String requestId = requestContext.getProperty("requestId").toString(); logger.info("{} {}", MessageEnum.APIH_GENERATED_REQUEST_ID.toString(), requestId); 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 0b2b1e73b4..2dab494b07 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 @@ -657,7 +657,7 @@ public class ServiceInstances { public Response deleteInstanceGroups(@PathParam("version") String version, @PathParam("instanceGroupId") String instanceGroupId, @Context ContainerRequestContext requestContext) throws ApiException { String requestId = getRequestId(requestContext); HashMap<String, String> instanceIdMap = new HashMap<>(); - instanceIdMap.put(CommonConstants.INSTANCE_GROUP_ID, instanceGroupId); + instanceIdMap.put(CommonConstants.INSTANCE_GROUP_INSTANCE_ID, instanceGroupId); return deleteInstanceGroups(Action.deleteInstance, instanceIdMap, version, requestId, getRequestUri(requestContext), requestContext); } @@ -670,7 +670,7 @@ public class ServiceInstances { public Response addInstanceGroupMembers(String request, @PathParam("version") String version, @PathParam("instanceGroupId") String instanceGroupId, @Context ContainerRequestContext requestContext) throws ApiException { String requestId = getRequestId(requestContext); HashMap<String, String> instanceIdMap = new HashMap<>(); - instanceIdMap.put(CommonConstants.INSTANCE_GROUP_ID, instanceGroupId); + instanceIdMap.put(CommonConstants.INSTANCE_GROUP_INSTANCE_ID, instanceGroupId); return serviceInstances(request, Action.addMembers, instanceIdMap, version, requestId, getRequestUri(requestContext)); } @@ -683,7 +683,7 @@ public class ServiceInstances { public Response removeInstanceGroupMembers(String request, @PathParam("version") String version, @PathParam("instanceGroupId") String instanceGroupId, @Context ContainerRequestContext requestContext) throws ApiException { String requestId = getRequestId(requestContext); HashMap<String, String> instanceIdMap = new HashMap<>(); - instanceIdMap.put(CommonConstants.INSTANCE_GROUP_ID, instanceGroupId); + instanceIdMap.put(CommonConstants.INSTANCE_GROUP_INSTANCE_ID, instanceGroupId); return serviceInstances(request, Action.removeMembers, instanceIdMap, version, requestId, getRequestUri(requestContext)); } @@ -808,16 +808,13 @@ public class ServiceInstances { } - serviceInstanceId = ""; + serviceInstanceId = setServiceInstanceId(requestScope, sir); String vnfId = ""; String vfModuleId = ""; String volumeGroupId = ""; String networkId = ""; String pnfCorrelationId = ""; String instanceGroupId = null; - if(sir.getServiceInstanceId () != null){ - serviceInstanceId = sir.getServiceInstanceId (); - } if(sir.getVnfInstanceId () != null){ vnfId = sir.getVnfInstanceId (); @@ -884,7 +881,7 @@ public class ServiceInstances { return postBPELRequest(currentActiveReq, requestClientParameter, recipeLookupResult.getOrchestrationURI(), requestScope); } public Response deleteInstanceGroups(Actions action, HashMap<String, String> instanceIdMap, String version, String requestId, String requestUri, ContainerRequestContext requestContext) throws ApiException { - String instanceGroupId = instanceIdMap.get(CommonConstants.INSTANCE_GROUP_ID); + String instanceGroupId = instanceIdMap.get(CommonConstants.INSTANCE_GROUP_INSTANCE_ID); Boolean aLaCarte = true; long startTime = System.currentTimeMillis (); String apiVersion = version.substring(1); @@ -1117,8 +1114,8 @@ public class ServiceInstances { if(instanceIdMap.get("configurationInstanceId") != null){ currentActiveReq.setConfigurationId(instanceIdMap.get("configurationInstanceId")); } - if(instanceIdMap.get("InstanceGroupInstanceId") != null){ - currentActiveReq.setInstanceGroupId(instanceIdMap.get("InstanceGroupInstanceId")); + if(instanceIdMap.get(CommonConstants.INSTANCE_GROUP_INSTANCE_ID) != null){ + currentActiveReq.setInstanceGroupId(instanceIdMap.get(CommonConstants.INSTANCE_GROUP_INSTANCE_ID)); } } } @@ -1970,4 +1967,20 @@ public class ServiceInstances { } return serviceType; } + protected String setServiceInstanceId(String requestScope, ServiceInstancesRequest sir){ + if(sir.getServiceInstanceId () != null){ + return sir.getServiceInstanceId (); + }else if(requestScope.equalsIgnoreCase(ModelType.instanceGroup.toString())){ + RelatedInstanceList[] relatedInstances = sir.getRequestDetails().getRelatedInstanceList(); + if(relatedInstances != null){ + for(RelatedInstanceList relatedInstanceList : relatedInstances){ + RelatedInstance relatedInstance = relatedInstanceList.getRelatedInstance(); + if(relatedInstance.getModelInfo().getModelType() == ModelType.service){ + return relatedInstance.getInstanceId(); + } + } + } + } + return null; + } } diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/CloudResourcesOrchestration.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/CloudResourcesOrchestration.java index 377b03c4ab..9305b80c13 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/CloudResourcesOrchestration.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/CloudResourcesOrchestration.java @@ -158,7 +158,6 @@ public class CloudResourcesOrchestration { @ApiOperation(value="Get status of an Operational Environment based on filter criteria",response=Response.class) @Transactional public Response getOperationEnvironmentStatusFilter(@Context UriInfo ui, @PathParam("version") String version ) throws ApiException{ - MsoLogger.setServiceName ("getOperationEnvironmentStatusFilter"); MultivaluedMap<String, String> queryParams = ui.getQueryParameters(); List<String> requestIdKey = queryParams.get("requestId"); diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/validation/InstanceIdMapValidation.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/validation/InstanceIdMapValidation.java index f1985e9fcf..fad11a5cc6 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/validation/InstanceIdMapValidation.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/validation/InstanceIdMapValidation.java @@ -77,11 +77,11 @@ public class InstanceIdMapValidation implements ValidationRule{ sir.setConfigurationId(instanceIdMap.get("configurationInstanceId")); } - if(instanceIdMap.get(CommonConstants.INSTANCE_GROUP_ID) != null){ - if (!UUIDChecker.isValidUUID (instanceIdMap.get (CommonConstants.INSTANCE_GROUP_ID))) { - throw new ValidationException (CommonConstants.INSTANCE_GROUP_ID, true); + if(instanceIdMap.get(CommonConstants.INSTANCE_GROUP_INSTANCE_ID) != null){ + if (!UUIDChecker.isValidUUID (instanceIdMap.get (CommonConstants.INSTANCE_GROUP_INSTANCE_ID))) { + throw new ValidationException (CommonConstants.INSTANCE_GROUP_INSTANCE_ID, true); } - sir.setInstanceGroupId(instanceIdMap.get(CommonConstants.INSTANCE_GROUP_ID)); + sir.setInstanceGroupId(instanceIdMap.get(CommonConstants.INSTANCE_GROUP_INSTANCE_ID)); } } return info; diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/MsoRequestTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/MsoRequestTest.java index 145213fc6c..ee98accfdc 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/MsoRequestTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/MsoRequestTest.java @@ -430,12 +430,12 @@ public class MsoRequestTest extends BaseTest { @Test public void instanceGroupIdHashMapFailureTest() throws JsonParseException, JsonMappingException, IOException, ValidationException{ this.sir = mapper.readValue(inputStream("/SuccessfulValidation/InstanceIdHashMap.json"), ServiceInstancesRequest.class); - this.instanceIdMapTest.put("instanceGroupId", "test"); + this.instanceIdMapTest.put("instanceGroupInstanceId", "test"); this.action = Action.createInstance; thrown.expect(ValidationException.class); this.reqVersion = 7; this.version = "v" + reqVersion; - thrown.expectMessage("No valid instanceGroupId is specified"); + thrown.expectMessage("No valid instanceGroupInstanceId is specified"); this.msoRequest = new MsoRequest(); this.msoRequest.parse(sir, instanceIdMapTest, action, version, originalRequestJSON, reqVersion, false); } diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ServiceInstancesTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ServiceInstancesTest.java index 83b5a49e8c..23974ef1fa 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ServiceInstancesTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ServiceInstancesTest.java @@ -31,6 +31,7 @@ import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; @@ -79,8 +80,10 @@ import org.springframework.util.ResourceUtils; import org.springframework.web.util.UriComponentsBuilder; import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.github.tomakehurst.wiremock.http.Fault; @@ -114,9 +117,12 @@ public class ServiceInstancesTest extends BaseTest{ // set headers headers = new HttpHeaders(); headers.set(ONAPLogConstants.Headers.PARTNER_NAME, "test_name"); - headers.set(ONAPLogConstants.Headers.REQUEST_ID, "32807a28-1a14-4b88-b7b3-2950918aa76d"); - headers.set(MsoLogger.REQUESTOR_ID, "xxxxxx"); - try { // generate one-time port number to avoid RANDOM port number later. + headers.set(MsoLogger.TRANSACTION_ID, "32807a28-1a14-4b88-b7b3-2950918aa76d"); + headers.set(MsoLogger.ONAP_REQUEST_ID, "32807a28-1a14-4b88-b7b3-2950918aa76d"); + headers.set(ONAPLogConstants.MDCs.REQUEST_ID, "32807a28-1a14-4b88-b7b3-2950918aa76d"); + headers.set(MsoLogger.CLIENT_ID, "VID"); + headers.set(MsoLogger.REQUESTOR_ID, "xxxxxx"); + try { // generate one-time port number to avoid RANDOM port number later. initialUrl = new URL(createURLWithPort(Constants.ORCHESTRATION_REQUESTS_PATH)); initialPort = initialUrl.getPort(); } catch (MalformedURLException e) { @@ -391,9 +397,10 @@ public class ServiceInstancesTest extends BaseTest{ } @Test public void activateServiceInstanceNoRecipeALaCarte() throws IOException{ + TestAppender.events.clear(); uri = servInstanceuri + "v5" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/activate"; HttpHeaders requestIDheaders = new HttpHeaders(); - requestIDheaders.set("X-ECOMP-RequestID", "32807a28-1a14-4b88-b7b3-2950918aa76d"); + requestIDheaders.set(ONAPLogConstants.Headers.REQUEST_ID, "32807a28-1a14-4b88-b7b3-2950918aa76d"); ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceALaCarteTrueNoRecipe.json"), uri, HttpMethod.POST, requestIDheaders); Service defaultService = new Service(); @@ -2368,7 +2375,8 @@ public class ServiceInstancesTest extends BaseTest{ if(logEvent.getLoggerName().equals("org.onap.so.logging.jaxrs.filter.JaxRsFilterLogging") && logEvent.getMarker() != null && logEvent.getMarker().getName().equals("ENTRY")){ Map<String,String> mdc = logEvent.getMDCPropertyMap(); - assertEquals("32807a28-1a14-4b88-b7b3-2950918aa76d", mdc.get(ONAPLogConstants.MDCs.REQUEST_ID)); + assertEquals("32807a28-1a14-4b88-b7b3-2950918aa76d", mdc.get(ONAPLogConstants.MDCs.REQUEST_ID)); + assertEquals("VID",mdc.get(MsoLogger.PARTNERNAME)); } } } @@ -2425,6 +2433,7 @@ public class ServiceInstancesTest extends BaseTest{ public void deleteInstanceGroupNoPartnerNameHeader() throws IOException{ HttpHeaders noPartnerHeaders = new HttpHeaders(); noPartnerHeaders.set(ONAPLogConstants.Headers.REQUEST_ID, "eca3a1b1-43ab-457e-ab1c-367263d148b4"); + noPartnerHeaders.set(MsoLogger.REQUESTOR_ID, "xxxxxx"); uri = servInstanceuri + "/v7/instanceGroups/e05864f0-ab35-47d0-8be4-56fd9619ba3c"; ResponseEntity<String> response = sendRequest(null, uri, HttpMethod.DELETE, noPartnerHeaders); //then @@ -2621,6 +2630,61 @@ public class ServiceInstancesTest extends BaseTest{ assertEquals(serviceType, "networkModelName"); } @Test + public void setServiceInstanceIdInstanceGroupTest() throws JsonParseException, JsonMappingException, IOException{ + String requestScope = "instanceGroup"; + ServiceInstancesRequest sir = mapper.readValue(inputStream("/CreateInstanceGroup.json"), ServiceInstancesRequest.class); + assertEquals("ddcbbf3d-f2c1-4ca0-8852-76a807285efc", servInstances.setServiceInstanceId(requestScope, sir)); + } + @Test + public void setServiceInstanceIdTest(){ + String requestScope = "vnf"; + ServiceInstancesRequest sir = new ServiceInstancesRequest(); + sir.setServiceInstanceId("f0a35706-efc4-4e27-80ea-a995d7a2a40f"); + assertEquals("f0a35706-efc4-4e27-80ea-a995d7a2a40f", servInstances.setServiceInstanceId(requestScope, sir)); + } + @Test + public void setServiceInstanceIdReturnNullTest(){ + String requestScope = "vnf"; + ServiceInstancesRequest sir = new ServiceInstancesRequest(); + assertNull(servInstances.setServiceInstanceId(requestScope, sir)); + } + @Test + public void camundaHistoryCheckTest() throws ContactCamundaException, RequestDbFailureException{ + stubFor(get(("/sobpmnengine/history/process-instance?variables=mso-request-id_eq_f0a35706-efc4-4e27-80ea-a995d7a2a40f")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBodyFile("Camunda/HistoryCheckResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK))); + + InfraActiveRequests duplicateRecord = new InfraActiveRequests(); + duplicateRecord.setRequestId("f0a35706-efc4-4e27-80ea-a995d7a2a40f"); + boolean inProgress = false; + inProgress = servInstances.camundaHistoryCheck(duplicateRecord, null); + assertTrue(inProgress); + } + @Test + public void camundaHistoryCheckNoneFoundTest() throws ContactCamundaException, RequestDbFailureException{ + stubFor(get(("/sobpmnengine/history/process-instance?variables=mso-request-id_eq_f0a35706-efc4-4e27-80ea-a995d7a2a40f")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody("[]").withStatus(org.apache.http.HttpStatus.SC_OK))); + + InfraActiveRequests duplicateRecord = new InfraActiveRequests(); + duplicateRecord.setRequestId("f0a35706-efc4-4e27-80ea-a995d7a2a40f"); + boolean inProgress = false; + inProgress = servInstances.camundaHistoryCheck(duplicateRecord, null); + assertFalse(inProgress); + } + @Test + public void camundaHistoryCheckNotInProgressTest()throws ContactCamundaException, RequestDbFailureException{ + stubFor(get(("/sobpmnengine/history/process-instance?variables=mso-request-id_eq_f0a35706-efc4-4e27-80ea-a995d7a2a40f")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBodyFile("Camunda/HistoryCheckResponseCompleted.json").withStatus(org.apache.http.HttpStatus.SC_OK))); + + InfraActiveRequests duplicateRecord = new InfraActiveRequests(); + duplicateRecord.setRequestId("f0a35706-efc4-4e27-80ea-a995d7a2a40f"); + boolean inProgress = false; + inProgress = servInstances.camundaHistoryCheck(duplicateRecord, null); + assertFalse(inProgress); + } + @Test public void setCamundaHeadersTest()throws ContactCamundaException, RequestDbFailureException{ String encryptedAuth = "015E7ACF706C6BBF85F2079378BDD2896E226E09D13DC2784BA309E27D59AB9FAD3A5E039DF0BB8408"; // user:password String key = "07a7159d3bf51a0e53be7a8f89699be7"; |