Code changes in BPMN infra for RAN Slice Use case
[so.git] / bpmn / MSOCommonBPMN / src / main / groovy / org / onap / so / bpmn / common / scripts / OofUtils.groovy
index 34cbb00..0e6cb64 100644 (file)
 
 package org.onap.so.bpmn.common.scripts
 
-import com.fasterxml.jackson.databind.ObjectMapper
+import com.google.gson.GsonBuilder
+import org.onap.so.beans.nsmf.oof.NsiReqBody
+import org.onap.so.beans.nsmf.oof.NssiReqBody
+import org.onap.so.beans.nsmf.oof.RequestInfo
+import org.onap.so.beans.nsmf.oof.SubnetCapability
+import org.onap.so.beans.nsmf.oof.TemplateInfo
+
+import static org.onap.so.bpmn.common.scripts.GenericUtils.*
+
+import javax.ws.rs.core.UriBuilder
+
 import org.camunda.bpm.engine.delegate.DelegateExecution
-import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
-import org.onap.so.bpmn.common.scripts.ExceptionUtil
 import org.onap.so.bpmn.common.util.OofInfraUtils
 import org.onap.so.bpmn.core.UrnPropertiesReader
+import org.onap.so.bpmn.core.domain.AllottedResource
 import org.onap.so.bpmn.core.domain.HomingSolution
 import org.onap.so.bpmn.core.domain.ModelInfo
 import org.onap.so.bpmn.core.domain.Resource
-import org.onap.so.bpmn.core.domain.AllottedResource
 import org.onap.so.bpmn.core.domain.ServiceDecomposition
 import org.onap.so.bpmn.core.domain.ServiceInstance
 import org.onap.so.bpmn.core.domain.Subscriber
 import org.onap.so.bpmn.core.domain.VnfResource
 import org.onap.so.bpmn.core.json.JsonUtils
-import org.onap.so.client.HttpClient
-import org.onap.so.client.HttpClientFactory
 import org.onap.so.db.catalog.beans.CloudSite
 import org.onap.so.db.catalog.beans.HomingInstance
-import org.onap.logging.filter.base.ONAPComponents;
-import org.springframework.http.HttpEntity
-import org.springframework.http.HttpHeaders
-import org.springframework.http.HttpMethod
-import org.springframework.http.ResponseEntity
-import org.springframework.http.client.BufferingClientHttpRequestFactory
-import org.springframework.http.client.HttpComponentsClientHttpRequestFactory
-import org.springframework.web.client.RestTemplate
-import org.springframework.web.util.UriComponentsBuilder
 import org.slf4j.Logger
 import org.slf4j.LoggerFactory
-
-import javax.ws.rs.core.MediaType
-import javax.ws.rs.core.Response
-import javax.ws.rs.core.UriBuilder
-import javax.xml.ws.http.HTTPException
-
-import static org.onap.so.bpmn.common.scripts.GenericUtils.*
+import com.google.gson.JsonObject
+import com.google.gson.JsonParser
+import com.fasterxml.jackson.databind.ObjectMapper
 
 class OofUtils {
     private static final Logger logger = LoggerFactory.getLogger( OofUtils.class);
@@ -531,9 +524,11 @@ class OofUtils {
         return UriBuilder.fromPath("").host(msbHost).port(msbPort).scheme("http").build().toString()
     }
 
-    public String buildSelectNSTRequest(String requestId, Map<String, Object> profileInfo) {
+    public String buildSelectNSTRequest(String requestId,String messageType, Map<String, Object> profileInfo) {
         def transactionId = requestId
         logger.debug( "transactionId is: " + transactionId)
+               String correlator = requestId
+        String callbackUrl = UrnPropertiesReader.getVariable("mso.adapters.oof.callback.endpoint") + "/" + messageType + "/" + correlator
         ObjectMapper objectMapper = new ObjectMapper()
         String json = objectMapper.writeValueAsString(profileInfo)
         StringBuilder response = new StringBuilder()
@@ -543,11 +538,208 @@ class OofUtils {
                         "    \"transactionId\": \"${transactionId}\",\n" +
                         "    \"requestId\": \"${requestId}\",\n" +
                         "    \"sourceId\": \"so\",\n" +
-                        "    \"timeout\": 600\n" +
+                        "    \"timeout\": 600,\n" +
+                        "    \"callbackUrl\": \"${callbackUrl}\"\n" +
                         "    },\n")
-        response.append(",\n \"serviceInfo\": \n")
+        response.append(" \"serviceProfile\":")
+        response.append(json)
+        response.append("\n}\n")
+        return response.toString()
+    }
+
+    public String buildSelectNSSTRequest(String requestId,String messageType, Map<String, Object> profileInfo) {
+        def transactionId = requestId
+        logger.debug( "transactionId is: " + transactionId)
+        String correlator = requestId
+        String callbackUrl = UrnPropertiesReader.getVariable("mso.adapters.oof.callback.endpoint") + "/" + messageType + "/" + correlator
+        ObjectMapper objectMapper = new ObjectMapper()
+        String json = objectMapper.writeValueAsString(profileInfo)
+        StringBuilder response = new StringBuilder()
+        response.append(
+                "{\n" +
+                        "  \"requestInfo\": {\n" +
+                        "    \"transactionId\": \"${transactionId}\",\n" +
+                        "    \"requestId\": \"${requestId}\",\n" +
+                        "    \"sourceId\": \"so\",\n" +
+                        "    \"timeout\": 600,\n" +
+                        "    \"callbackUrl\": \"${callbackUrl}\"\n" +
+                        "    },\n")
+        response.append(" \"SliceProfile\":")
+        response.append(json)
+        response.append("\n}\n")
+        return response.toString()
+    }
+
+
+    public String buildSelectNSIRequest(String requestId, String nstInfo,String messageType, Map<String, Object> profileInfo){
+
+        def transactionId = requestId
+        logger.debug( "transactionId is: " + transactionId)
+               String correlator = requestId
+        String callbackUrl = UrnPropertiesReader.getVariable("mso.adapters.oof.callback.endpoint") + "/" + messageType + "/" + correlator
+        ObjectMapper objectMapper = new ObjectMapper();
+        String json = objectMapper.writeValueAsString(profileInfo);
+        StringBuilder response = new StringBuilder();
+        response.append(
+                "{\n" +
+                        "  \"requestInfo\": {\n" +
+                        "    \"transactionId\": \"${transactionId}\",\n" +
+                        "    \"requestId\": \"${requestId}\",\n" +
+                        "    \"sourceId\": \"so\",\n" +
+                        "    \"timeout\": 600,\n" +
+                        "    \"callbackUrl\": \"${callbackUrl}\"\n" +
+                        "    },\n" +
+                        "  \"serviceInfo\": {\n" +
+                        "    \"serviceInstanceId\": \"\",\n" +
+                        "    \"serviceName\": \"\"\n" +
+                        "    },\n" +
+                        "  \"NSTInfoList\": [\n")
+        response.append(nstInfo);
+        response.append("\n  ],\n")
+        response.append("\n \"serviceProfile\": \n")
         response.append(json);
         response.append("\n  }\n")
         return response.toString()
     }
+/**
+* Method to create select NSSI request
+* @param requestId - mso-request-id
+* @param messageType - Message type for callback correlation
+* @param UUID - UUID of NSST
+* @param invariantUUID - Invariant UUID of NSST
+* @param name - name of the NSST model
+* @param profileInfo - A JSON object containing slice profile parameters
+* @return
+*/
+public String buildSelectNSSIRequest(String requestId, String messageType, String UUID,String invariantUUID,
+String name, Map<String, Object> profileInfo){
+
+def transactionId = requestId
+logger.debug( "transactionId is: " + transactionId)
+String correlator = requestId
+String callbackUrl = UrnPropertiesReader.getVariable("mso.adapters.oof.callback.endpoint") + "/" + messageType + "/" + correlator
+ObjectMapper objectMapper = new ObjectMapper();
+String profileJson = objectMapper.writeValueAsString(profileInfo);
+JsonParser parser = new JsonParser()
+
+//Prepare requestInfo object
+JsonObject requestInfo = new JsonObject()
+requestInfo.addProperty("transactionId", transactionId)
+requestInfo.addProperty("requestId", requestId)
+requestInfo.addProperty("callbackUrl", callbackUrl)
+requestInfo.addProperty("sourceId","SO" )
+requestInfo.addProperty("timeout", 600)
+requestInfo.addProperty("numSolutions", 1)
+
+//Prepare serviceInfo object
+JsonObject nsstInfo = new JsonObject()
+nsstInfo.addProperty("UUID", UUID)
+nsstInfo.addProperty("invariantUUID", invariantUUID)
+nsstInfo.addProperty("name", name)
+
+JsonObject json = new JsonObject()
+json.add("requestInfo", requestInfo)
+json.add("NSSTInfo", nsstInfo)
+json.add("sliceProfile", (JsonObject) parser.parse(profileJson))
+
+return json.toString()
+}
+
+/**
+* Method to create NSI/NSSI termination request
+* (OOF response will be synchronous in G-Release)
+* @param requestId - mso-request-id
+* @param nxlId        - NSI/NSSI Id to be terminated
+* @param messageType - Message type for callback correlation
+* @param serviceInstanceId - NSI/NSSI Id related to nxlId
+* @return
+*/
+public String buildTerminateNxiRequest(String requestId,String nxlId, String nxlType, String messageType, String serviceInstanceId) {
+def transactionId = requestId
+logger.debug( "transactionId is: " + transactionId)
+String correlator = requestId
+String callbackUrl = UrnPropertiesReader.getVariable("mso.adapters.oof.callback.endpoint") + "/" + messageType + "/" + correlator
+//Prepare Terminate Nxl Json
+JsonObject json = new JsonObject()
+json.addProperty("type", nxlType)
+json.addProperty("NxIId", nxlId)
+//Prepare requestInfo object
+JsonObject requestInfo = new JsonObject()
+requestInfo.addProperty("transactionId", transactionId)
+requestInfo.addProperty("requestId", requestId)
+requestInfo.addProperty("callbackUrl", callbackUrl)
+requestInfo.addProperty("sourceId","SO" )
+requestInfo.addProperty("timeout", 600)
+//Prepare addtnlArgs object
+JsonObject addtnlArgs = new JsonObject()
+addtnlArgs.addProperty("serviceInstanceId", serviceInstanceId)
+requestInfo.add("addtnlArgs", addtnlArgs)
+json.add("requestInfo", requestInfo)
+return json.toString()
+}
+
+    public String buildSelectNSIRequest(String requestId, TemplateInfo nstInfo, List<TemplateInfo> nsstInfo,
+                                        String messageType, Map<String, Object> serviceProfile,
+                                        List<SubnetCapability> subnetCapabilities, Integer timeOut, boolean preferReuse){
+
+        def transactionId = requestId
+        String correlator = requestId
+        logger.debug( "transactionId is: " + transactionId)
+
+        String callbackUrl = UrnPropertiesReader.getVariable("mso.adapters.oof.callback.endpoint") + "/" + messageType + "/" + correlator
+
+        NsiReqBody nsiReqBody = new NsiReqBody()
+
+        RequestInfo requestInfo = new RequestInfo()
+        requestInfo.setRequestId(requestId)
+        requestInfo.setTransactionId(transactionId)
+        requestInfo.setCallbackUrl(callbackUrl)
+        requestInfo.setSourceId("so")
+        requestInfo.setTimeout(timeOut)
+        requestInfo.setNumSolutions(1)
+
+        nsiReqBody.setRequestInfo(requestInfo)
+        nsiReqBody.setNSTInfo(nstInfo)
+        nsiReqBody.setServiceProfile(serviceProfile)
+        nsiReqBody.setSubnetCapabilities(subnetCapabilities)
+        nsiReqBody.setNSSTInfo(nsstInfo)
+        nsiReqBody.setPreferReuse(preferReuse)
+
+        return bean2JsonStr(nsiReqBody)
+    }
+
+    public <T> String buildSelectNSSIRequest(String requestId, TemplateInfo nsstInfo, String messageType,
+                                             T sliceProfile, Integer timeOut){
+
+        def transactionId = requestId
+        String correlator = requestId
+        logger.debug( "transactionId is: " + transactionId)
+
+        String callbackUrl = UrnPropertiesReader.getVariable("mso.adapters.oof.callback.endpoint") + "/" + messageType + "/" + correlator
+
+        NssiReqBody nssiReqBody = new NssiReqBody()
+
+        RequestInfo requestInfo = new RequestInfo()
+        requestInfo.setRequestId(requestId)
+        requestInfo.setTransactionId(transactionId)
+        requestInfo.setCallbackUrl(callbackUrl)
+        requestInfo.setSourceId("so")
+        requestInfo.setTimeout(timeOut)
+        requestInfo.setNumSolutions(100)
+
+        nssiReqBody.setRequestInfo(requestInfo)
+        nssiReqBody.setSliceProfile(sliceProfile)
+        nssiReqBody.setNSSTInfo(nsstInfo)
+
+        return bean2JsonStr(nssiReqBody)
+    }
+
+    private static <T> String bean2JsonStr(T t) {
+        return new GsonBuilder().setPrettyPrinting().create().toJson(t)
+    }
 }