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 2c96e7d..0e6cb64 100644 (file)
 
 package org.onap.so.bpmn.common.scripts
 
+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
@@ -42,7 +49,8 @@ import org.onap.so.db.catalog.beans.CloudSite
 import org.onap.so.db.catalog.beans.HomingInstance
 import org.slf4j.Logger
 import org.slf4j.LoggerFactory
-
+import com.google.gson.JsonObject
+import com.google.gson.JsonParser
 import com.fasterxml.jackson.databind.ObjectMapper
 
 class OofUtils {
@@ -533,14 +541,36 @@ class OofUtils {
                         "    \"timeout\": 600,\n" +
                         "    \"callbackUrl\": \"${callbackUrl}\"\n" +
                         "    },\n")
-        response.append(" \"serviceProfile\": {\n" +
-                "   \"serviceProfileParameters\": ")
-        response.append(json);
-        response.append("\n }\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
@@ -571,5 +601,145 @@ class OofUtils {
         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)
+    }
 }