aboutsummaryrefslogtreecommitdiffstats
path: root/mso-api-handlers
diff options
context:
space:
mode:
authorBenjamin, Max (mb388a) <mb388a@us.att.com>2019-03-10 10:56:41 -0400
committerBenjamin, Max (mb388a) <mb388a@us.att.com>2019-03-12 09:54:12 -0400
commitf99e4a56e6b9ec09ece48a7b111c9ec286220264 (patch)
treeaa6b58ca16295b592cb4343da52c3ac6465a0351 /mso-api-handlers
parent308c3c2085864e04848e53a589773ff2e6e2c76a (diff)
add instance group support to SO
add create support add delete support added naming service support Change-Id: Iaf4f2bdae8ea55aca71d6e9b818a76e90db0b012 Issue-ID: SO-1616 Signed-off-by: Benjamin, Max (mb388a) <mb388a@us.att.com>
Diffstat (limited to 'mso-api-handlers')
-rw-r--r--mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/common/CommonConstants.java1
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java33
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/validation/InstanceIdMapValidation.java8
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/MsoRequestTest.java4
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ServiceInstancesTest.java74
5 files changed, 99 insertions, 21 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/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/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";