2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 Intel Corp. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright (c) 2019 Samsung
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
23 package org.onap.so.bpmn.common.scripts
25 import org.onap.so.beans.nsmf.oof.NsiReqBody
26 import org.onap.so.beans.nsmf.oof.RequestInfo
27 import org.onap.so.beans.nsmf.oof.SubnetCapability
28 import org.onap.so.beans.nsmf.oof.TemplateInfo
30 import static org.onap.so.bpmn.common.scripts.GenericUtils.*
32 import javax.ws.rs.core.UriBuilder
34 import org.camunda.bpm.engine.delegate.DelegateExecution
35 import org.onap.so.bpmn.common.util.OofInfraUtils
36 import org.onap.so.bpmn.core.UrnPropertiesReader
37 import org.onap.so.bpmn.core.domain.AllottedResource
38 import org.onap.so.bpmn.core.domain.HomingSolution
39 import org.onap.so.bpmn.core.domain.ModelInfo
40 import org.onap.so.bpmn.core.domain.Resource
41 import org.onap.so.bpmn.core.domain.ServiceDecomposition
42 import org.onap.so.bpmn.core.domain.ServiceInstance
43 import org.onap.so.bpmn.core.domain.Subscriber
44 import org.onap.so.bpmn.core.domain.VnfResource
45 import org.onap.so.bpmn.core.json.JsonUtils
46 import org.onap.so.db.catalog.beans.CloudSite
47 import org.onap.so.db.catalog.beans.HomingInstance
48 import org.slf4j.Logger
49 import org.slf4j.LoggerFactory
50 import com.google.gson.JsonObject
52 import com.fasterxml.jackson.databind.ObjectMapper
55 private static final Logger logger = LoggerFactory.getLogger( OofUtils.class);
57 ExceptionUtil exceptionUtil = new ExceptionUtil()
58 JsonUtils jsonUtil = new JsonUtils()
59 OofInfraUtils oofInfraUtils = new OofInfraUtils()
61 private AbstractServiceTaskProcessor utils
63 OofUtils(AbstractServiceTaskProcessor taskProcessor) {
64 this.utils = taskProcessor
68 * This method builds the service-agnostic
69 * OOF json request to get a homing solution
70 * and license solution
74 * @param decomposition - ServiceDecomposition object
75 * @param customerLocation -
76 * @param existingCandidates -
77 * @param excludedCandidates -
78 * @param requiredCandidates -
80 * @return request - OOF v1 payload - https://wiki.onap.org/pages/viewpage.action?pageId=25435066
82 String buildRequest(DelegateExecution execution,
84 ServiceDecomposition decomposition,
85 Subscriber subscriber = null,
87 ArrayList existingCandidates = null,
88 ArrayList excludedCandidates = null,
89 ArrayList requiredCandidates = null) {
90 logger.debug( "Started Building OOF Request")
91 String callbackEndpoint = UrnPropertiesReader.getVariable("mso.oof.callbackEndpoint", execution)
92 logger.debug( "mso.oof.callbackEndpoint is: " + callbackEndpoint)
94 def callbackUrl = utils.createHomingCallbackURL(callbackEndpoint, "oofResponse", requestId)
95 logger.debug( "callbackUrl is: " + callbackUrl)
98 def transactionId = requestId
99 logger.debug( "transactionId is: " + transactionId)
100 //ServiceInstance Info
101 ServiceInstance serviceInstance = decomposition.getServiceInstance()
102 def serviceInstanceId = ""
105 serviceInstanceId = execution.getVariable("serviceInstanceId")
106 logger.debug( "serviceInstanceId is: " + serviceInstanceId)
107 serviceName = execution.getVariable("subscriptionServiceType")
108 logger.debug( "serviceName is: " + serviceName)
110 if (serviceInstanceId == null || serviceInstanceId == "null") {
111 logger.debug( "Unable to obtain Service Instance Id")
112 exceptionUtil.buildAndThrowWorkflowException(execution, 400, "Internal Error - Unable to " +
113 "obtain Service Instance Id, execution.getVariable(\"serviceInstanceId\") is null")
115 if (serviceName == null || serviceName == "null") {
116 logger.debug( "Unable to obtain Service Name")
117 exceptionUtil.buildAndThrowWorkflowException(execution, 400, "Internal Error - Unable to " +
118 "obtain Service Name, execution.getVariable(\"subscriptionServiceType\") is null")
121 ModelInfo model = decomposition.getModelInfo()
122 logger.debug( "ModelInfo: " + model.toString())
123 String modelType = model.getModelType()
124 String modelInvariantId = model.getModelInvariantUuid()
125 String modelVersionId = model.getModelUuid()
126 String modelName = model.getModelName()
127 String modelVersion = model.getModelVersion()
129 String subscriberId = ""
130 String subscriberName = ""
131 String commonSiteId = ""
132 if (subscriber != null) {
133 subscriberId = subscriber.getGlobalId()
134 subscriberName = subscriber.getName()
135 commonSiteId = subscriber.getCommonSiteId()
138 //Determine RequestType
139 //TODO Figure out better way to determine this
140 String requestType = "create"
141 List<Resource> resources = decomposition.getServiceResources()
142 for (Resource r : resources) {
143 HomingSolution currentSolution = (HomingSolution) r.getCurrentHomingSolution()
144 if (currentSolution != null) {
145 requestType = "speed changed"
150 String placementDemands = ""
151 StringBuilder sb = new StringBuilder()
152 List<AllottedResource> allottedResourceList = decomposition.getAllottedResources()
153 List<VnfResource> vnfResourceList = decomposition.getVnfResources()
155 if (allottedResourceList == null || allottedResourceList.isEmpty()) {
156 logger.debug( "Allotted Resources List is empty - will try to get service VNFs instead.")
158 for (AllottedResource resource : allottedResourceList) {
159 logger.debug( "Allotted Resource: " + resource.toString())
160 def serviceResourceId = resource.getResourceId()
161 def toscaNodeType = resource.getToscaNodeType()
162 def resourceModuleName = toscaNodeType.substring(toscaNodeType.lastIndexOf(".") + 1)
163 def resourceModelInvariantId = resource.getModelInfo().getModelInvariantUuid()
164 def resourceModelVersionId = resource.getModelInfo().getModelUuid()
165 def resourceModelName = resource.getModelInfo().getModelName()
166 def resourceModelVersion = resource.getModelInfo().getModelVersion()
167 def resourceModelType = resource.getModelInfo().getModelType()
168 def tenantId = execution.getVariable("tenantId")
169 def requiredCandidatesJson = ""
171 requiredCandidatesJson = createCandidateJson(
178 " \"resourceModuleName\": \"${resourceModuleName}\",\n" +
179 " \"serviceResourceId\": \"${serviceResourceId}\",\n" +
180 " \"tenantId\": \"${tenantId}\",\n" +
181 " \"resourceModelInfo\": {\n" +
182 " \"modelInvariantId\": \"${resourceModelInvariantId}\",\n" +
183 " \"modelVersionId\": \"${resourceModelVersionId}\",\n" +
184 " \"modelName\": \"${resourceModelName}\",\n" +
185 " \"modelType\": \"${resourceModelType}\",\n" +
186 " \"modelVersion\": \"${resourceModelVersion}\",\n" +
187 " \"modelCustomizationName\": \"\"\n" +
188 " }" + requiredCandidatesJson + "\n" +
191 placementDemands = sb.append(demand)
195 if (vnfResourceList == null || vnfResourceList.isEmpty()) {
196 logger.debug( "VNF Resources List is empty")
199 for (VnfResource vnfResource : vnfResourceList) {
200 logger.debug( "VNF Resource: " + vnfResource.toString())
201 ModelInfo vnfResourceModelInfo = vnfResource.getModelInfo()
202 def toscaNodeType = vnfResource.getToscaNodeType()
203 def resourceModuleName = toscaNodeType.substring(toscaNodeType.lastIndexOf(".") + 1)
204 def serviceResourceId = vnfResource.getResourceId()
205 def resourceModelInvariantId = vnfResourceModelInfo.getModelInvariantUuid()
206 def resourceModelName = vnfResourceModelInfo.getModelName()
207 def resourceModelVersion = vnfResourceModelInfo.getModelVersion()
208 def resourceModelVersionId = vnfResourceModelInfo.getModelUuid()
209 def resourceModelType = vnfResourceModelInfo.getModelType()
210 def tenantId = execution.getVariable("tenantId")
211 def requiredCandidatesJson = ""
214 String placementDemand =
216 " \"resourceModuleName\": \"${resourceModuleName}\",\n" +
217 " \"serviceResourceId\": \"${serviceResourceId}\",\n" +
218 " \"tenantId\": \"${tenantId}\",\n" +
219 " \"resourceModelInfo\": {\n" +
220 " \"modelInvariantId\": \"${resourceModelInvariantId}\",\n" +
221 " \"modelVersionId\": \"${resourceModelVersionId}\",\n" +
222 " \"modelName\": \"${resourceModelName}\",\n" +
223 " \"modelType\": \"${resourceModelType}\",\n" +
224 " \"modelVersion\": \"${resourceModelVersion}\",\n" +
225 " \"modelCustomizationName\": \"\"\n" +
226 " }" + requiredCandidatesJson + "\n" +
229 placementDemands = sb.append(placementDemand)
231 placementDemands = placementDemands.substring(0, placementDemands.length() - 1)
234 /* Commenting Out Licensing as OOF doesn't support for Beijing
235 String licenseDemands = ""
236 sb = new StringBuilder()
237 if (vnfResourceList.isEmpty() || vnfResourceList == null) {
238 logger.debug( "Vnf Resources List is Empty")
240 for (VnfResource vnfResource : vnfResourceList) {
241 ModelInfo vnfResourceModelInfo = vnfResource.getModelInfo()
242 def resourceInstanceType = vnfResource.getResourceType()
243 def serviceResourceId = vnfResource.getResourceId()
244 def resourceModuleName = vnfResource.getResourceType()
245 def resouceModelInvariantId = vnfResourceModelInfo.getModelInvariantUuid()
246 def resouceModelName = vnfResourceModelInfo.getModelName()
247 def resouceModelVersion = vnfResourceModelInfo.getModelVersion()
248 def resouceModelVersionId = vnfResourceModelInfo.getModelUuid()
249 def resouceModelType = vnfResourceModelInfo.getModelType()
251 // TODO Add Existing Licenses to demand
252 //"existingLicenses": {
253 //"entitlementPoolUUID": ["87257b49-9602-4ca1-9817-094e52bc873b",
254 // "43257b49-9602-4fe5-9337-094e52bc9435"],
255 //"licenseKeyGroupUUID": ["87257b49-9602-4ca1-9817-094e52bc873b",
256 // "43257b49-9602-4fe5-9337-094e52bc9435"]
259 String licenseDemand =
261 "\"resourceModuleName\": \"${resourceModuleName}\",\n" +
262 "\"serviceResourceId\": \"${serviceResourceId}\",\n" +
263 "\"resourceInstanceType\": \"${resourceInstanceType}\",\n" +
264 "\"resourceModelInfo\": {\n" +
265 " \"modelInvariantId\": \"${resouceModelInvariantId}\",\n" +
266 " \"modelVersionId\": \"${resouceModelVersionId}\",\n" +
267 " \"modelName\": \"${resouceModelName}\",\n" +
268 " \"modelType\": \"${resouceModelType}\",\n" +
269 " \"modelVersion\": \"${resouceModelVersion}\",\n" +
270 " \"modelCustomizationName\": \"\"\n" +
274 licenseDemands = sb.append(licenseDemand)
276 licenseDemands = licenseDemands.substring(0, licenseDemands.length() - 1)
281 " \"requestInfo\": {\n" +
282 " \"transactionId\": \"${transactionId}\",\n" +
283 " \"requestId\": \"${requestId}\",\n" +
284 " \"callbackUrl\": \"${callbackUrl}\",\n" +
285 " \"sourceId\": \"so\",\n" +
286 " \"requestType\": \"${requestType}\"," +
287 " \"numSolutions\": 1,\n" +
288 " \"optimizers\": [\"placement\"],\n" +
289 " \"timeout\": 600\n" +
291 " \"placementInfo\": {\n" +
292 " \"requestParameters\": {\n" +
293 " \"customerLatitude\": \"${customerLocation.customerLatitude}\",\n" +
294 " \"customerLongitude\": \"${customerLocation.customerLongitude}\",\n" +
295 " \"customerName\": \"${customerLocation.customerName}\"\n" +
297 " \"subscriberInfo\": { \n" +
298 " \"globalSubscriberId\": \"${subscriberId}\",\n" +
299 " \"subscriberName\": \"${subscriberName}\",\n" +
300 " \"subscriberCommonSiteId\": \"${commonSiteId}\"\n" +
302 " \"placementDemands\": [\n" +
303 " ${placementDemands}\n" +
306 " \"serviceInfo\": {\n" +
307 " \"serviceInstanceId\": \"${serviceInstanceId}\",\n" +
308 " \"serviceName\": \"${serviceName}\",\n" +
309 " \"modelInfo\": {\n" +
310 " \"modelType\": \"${modelType}\",\n" +
311 " \"modelInvariantId\": \"${modelInvariantId}\",\n" +
312 " \"modelVersionId\": \"${modelVersionId}\",\n" +
313 " \"modelName\": \"${modelName}\",\n" +
314 " \"modelVersion\": \"${modelVersion}\",\n" +
315 " \"modelCustomizationName\": \"\"\n" +
321 logger.debug( "Completed Building OOF Request")
323 } catch (Exception ex) {
324 logger.debug( "buildRequest Exception: " + ex)
329 * This method validates the callback response
330 * from OOF. If the response contains an
331 * exception the method will build and throw
332 * a workflow exception.
335 * @param response - the async callback response from oof
337 Void validateCallbackResponse(DelegateExecution execution, String response) {
338 String placements = ""
339 if (isBlank(response)) {
340 exceptionUtil.buildAndThrowWorkflowException(execution, 5000, "OOF Async Callback Response is Empty")
342 if (JsonUtils.jsonElementExist(response, "solutions.placementSolutions")) {
343 placements = jsonUtil.getJsonValue(response, "solutions.placementSolutions")
344 if (isBlank(placements) || placements.equalsIgnoreCase("[]")) {
345 String statusMessage = jsonUtil.getJsonValue(response, "statusMessage")
346 if (isBlank(statusMessage)) {
347 logger.debug( "Error Occurred in Homing: OOF Async Callback Response does " +
348 "not contain placement solution.")
349 exceptionUtil.buildAndThrowWorkflowException(execution, 400,
350 "OOF Async Callback Response does not contain placement solution.")
352 logger.debug( "Error Occurred in Homing: " + statusMessage)
353 exceptionUtil.buildAndThrowWorkflowException(execution, 400, statusMessage)
358 } else if (response.contains("error") || response.contains("Error") ) {
359 String errorMessage = ""
360 if (response.contains("policyException")) {
361 String text = jsonUtil.getJsonValue(response, "requestError.policyException.text")
362 errorMessage = "OOF Async Callback Response contains a Request Error Policy Exception: " + text
363 } else if (response.contains("Unable to find any candidate for demand")) {
364 errorMessage = "OOF Async Callback Response contains error: Unable to find any candidate for " +
365 "demand *** Response: " + response.toString()
366 } else if (response.contains("serviceException")) {
367 String text = jsonUtil.getJsonValue(response, "requestError.serviceException.text")
368 errorMessage = "OOF Async Callback Response contains a Request Error Service Exception: " + text
370 errorMessage = "OOF Async Callback Response contains a Request Error. Unable to determine the Request Error Exception."
372 logger.debug( "Error Occurred in Homing: " + errorMessage)
373 exceptionUtil.buildAndThrowWorkflowException(execution, 400, errorMessage)
376 logger.debug( "Error Occurred in Homing: Received an Unknown Async Callback Response from OOF.")
377 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Received an Unknown Async Callback Response from OOF.")
384 * This method creates candidates json for placement Demands.
387 * @param existingCandidates -
388 * @param excludedCandidates -
389 * @param requiredCandidates -
391 * @return candidatesJson - a JSON string with candidates
393 String createCandidateJson(ArrayList existingCandidates = null,
394 ArrayList excludedCandidates = null,
395 ArrayList requiredCandidates = null) {
396 def candidatesJson = ""
398 if (existingCandidates != null && existingCandidates != {}) {
399 sb = new StringBuilder()
401 " \"existingCandidates\": [\n")
402 def existingCandidateJson = ""
403 existingCandidates.each { existingCandidate ->
404 type = existingCandidate.get('identifierType')
405 if (type == 'vimId') {
406 def cloudOwner = existingCandidate.get('cloudOwner')
407 def cloudRegionId = existingCandidate.get('identifiers')
408 existingCandidateJson = "{\n" +
409 " \"identifierType\": \"vimId\",\n" +
410 " \"cloudOwner\": \"${cloudOwner}\",\n" +
411 " \"identifiers\": [\"${cloudRegionId}\"]\n" +
413 sb.append(existingCandidateJson)
415 if (type == 'serviceInstanceId') {
416 def serviceInstanceId = existingCandidate.get('identifiers')
417 existingCandidateJson += "{\n" +
418 " \"identifierType\": \"serviceInstanceId\",\n" +
419 " \"identifiers\": [\"${serviceInstanceId}\"]\n" +
421 sb.append(existingCandidateJson)
424 if (existingCandidateJson != "") {
425 sb.setLength(sb.length() - 1)
426 candidatesJson = sb.append(",\n],")
429 if (excludedCandidates != null && excludedCandidates != {}) {
430 sb = new StringBuilder()
432 " \"excludedCandidates\": [\n")
433 def excludedCandidateJson = ""
434 excludedCandidates.each { excludedCandidate ->
435 type = excludedCandidate.get('identifierType')
436 if (type == 'vimId') {
437 def cloudOwner = excludedCandidate.get('cloudOwner')
438 def cloudRegionId = excludedCandidate.get('identifiers')
439 excludedCandidateJson = "{\n" +
440 " \"identifierType\": \"vimId\",\n" +
441 " \"cloudOwner\": \"${cloudOwner}\",\n" +
442 " \"identifiers\": [\"${cloudRegionId}\"]\n" +
444 sb.append(excludedCandidateJson)
446 if (type == 'serviceInstanceId') {
447 def serviceInstanceId = excludedCandidate.get('identifiers')
448 excludedCandidateJson += "{\n" +
449 " \"identifierType\": \"serviceInstanceId\",\n" +
450 " \"identifiers\": [\"${serviceInstanceId}\"]\n" +
452 sb.append(excludedCandidateJson)
455 if (excludedCandidateJson != "") {
456 sb.setLength(sb.length() - 1)
457 candidatesJson = sb.append(",\n],")
460 if (requiredCandidates != null && requiredCandidates != {}) {
461 sb = new StringBuilder()
463 " \"requiredCandidates\": [\n")
464 def requiredCandidatesJson = ""
465 requiredCandidates.each { requiredCandidate ->
466 type = requiredCandidate.get('identifierType')
467 if (type == 'vimId') {
468 def cloudOwner = requiredCandidate.get('cloudOwner')
469 def cloudRegionId = requiredCandidate.get('identifiers')
470 requiredCandidatesJson = "{\n" +
471 " \"identifierType\": \"vimId\",\n" +
472 " \"cloudOwner\": \"${cloudOwner}\",\n" +
473 " \"identifiers\": [\"${cloudRegionId}\"]\n" +
475 sb.append(requiredCandidatesJson)
477 if (type == 'serviceInstanceId') {
478 def serviceInstanceId = requiredCandidate.get('identifiers')
479 requiredCandidatesJson += "{\n" +
480 " \"identifierType\": \"serviceInstanceId\",\n" +
481 " \"identifiers\": [\"${serviceInstanceId}\"]\n" +
483 sb.append(requiredCandidatesJson)
486 if (requiredCandidatesJson != "") {
487 sb.setLength(sb.length() - 1)
488 candidatesJson = sb.append(",\n],")
491 if (candidatesJson != "") {candidatesJson = candidatesJson.substring(0, candidatesJson.length() - 1)}
492 return candidatesJson
496 * This method creates a cloudsite in catalog database.
498 * @param CloudSite cloudSite
502 Void createCloudSite(CloudSite cloudSite, DelegateExecution execution) {
503 oofInfraUtils.createCloudSite(cloudSite, execution)
507 * This method creates a HomingInstance in catalog database.
509 * @param HomingInstance homingInstance
513 Void createHomingInstance(HomingInstance homingInstance, DelegateExecution execution) {
514 oofInfraUtils.createHomingInstance(homingInstance, execution)
517 String getMsbHost(DelegateExecution execution) {
518 String msbHost = UrnPropertiesReader.getVariable("mso.msb.host", execution, "msb-iag.onap")
520 Integer msbPort = UrnPropertiesReader.getVariable("mso.msb.port", execution, "80").toInteger()
522 return UriBuilder.fromPath("").host(msbHost).port(msbPort).scheme("http").build().toString()
525 public String buildSelectNSTRequest(String requestId,String messageType, Map<String, Object> profileInfo) {
526 def transactionId = requestId
527 logger.debug( "transactionId is: " + transactionId)
528 String correlator = requestId
529 String callbackUrl = UrnPropertiesReader.getVariable("mso.adapters.oof.callback.endpoint") + "/" + messageType + "/" + correlator
530 ObjectMapper objectMapper = new ObjectMapper()
531 String json = objectMapper.writeValueAsString(profileInfo)
532 StringBuilder response = new StringBuilder()
535 " \"requestInfo\": {\n" +
536 " \"transactionId\": \"${transactionId}\",\n" +
537 " \"requestId\": \"${requestId}\",\n" +
538 " \"sourceId\": \"so\",\n" +
539 " \"timeout\": 600,\n" +
540 " \"callbackUrl\": \"${callbackUrl}\"\n" +
542 response.append(" \"serviceProfile\": {\n" +
543 " \"serviceProfileParameters\": ")
544 response.append(json);
545 response.append("\n }\n")
546 response.append("\n}\n")
547 return response.toString()
550 public String buildSelectNSIRequest(String requestId, String nstInfo,String messageType, Map<String, Object> profileInfo){
552 def transactionId = requestId
553 logger.debug( "transactionId is: " + transactionId)
554 String correlator = requestId
555 String callbackUrl = UrnPropertiesReader.getVariable("mso.adapters.oof.callback.endpoint") + "/" + messageType + "/" + correlator
556 ObjectMapper objectMapper = new ObjectMapper();
557 String json = objectMapper.writeValueAsString(profileInfo);
558 StringBuilder response = new StringBuilder();
561 " \"requestInfo\": {\n" +
562 " \"transactionId\": \"${transactionId}\",\n" +
563 " \"requestId\": \"${requestId}\",\n" +
564 " \"sourceId\": \"so\",\n" +
565 " \"timeout\": 600,\n" +
566 " \"callbackUrl\": \"${callbackUrl}\"\n" +
568 " \"serviceInfo\": {\n" +
569 " \"serviceInstanceId\": \"\",\n" +
570 " \"serviceName\": \"\"\n" +
572 " \"NSTInfoList\": [\n")
573 response.append(nstInfo);
574 response.append("\n ],\n")
575 response.append("\n \"serviceProfile\": \n")
576 response.append(json);
577 response.append("\n }\n")
578 return response.toString()
581 * Method to create select NSSI request
582 * @param requestId - mso-request-id
583 * @param messageType - Message type for callback correlation
584 * @param UUID - UUID of NSST
585 * @param invariantUUID - Invariant UUID of NSST
586 * @param name - name of the NSST model
587 * @param profileInfo - A JSON object containing slice profile parameters
590 public String buildSelectNSSIRequest(String requestId, String messageType, String UUID,String invariantUUID,
591 String name, Map<String, Object> profileInfo){
593 def transactionId = requestId
594 logger.debug( "transactionId is: " + transactionId)
595 String correlator = requestId
596 String callbackUrl = UrnPropertiesReader.getVariable("mso.adapters.oof.callback.endpoint") + "/" + messageType + "/" + correlator
597 ObjectMapper objectMapper = new ObjectMapper();
598 String profileJson = objectMapper.writeValueAsString(profileInfo);
600 //Prepare requestInfo object
601 JsonObject requestInfo = new JsonObject()
602 requestInfo.addProperty("transactionId", transactionId)
603 requestInfo.addProperty("requestId", requestId)
604 requestInfo.addProperty("callbackUrl", callbackUrl)
605 requestInfo.addProperty("sourceId","SO" )
606 requestInfo.addProperty("timeout", 600)
607 requestInfo.addProperty("numSolutions", 1)
609 //Prepare serviceInfo object
610 JsonObject nsstInfo = new JsonObject()
611 nsstInfo.addProperty("UUID", UUID)
612 nsstInfo.addProperty("invariantUUID", invariantUUID)
613 nsstInfo.addProperty("name", name)
615 JsonObject json = new JsonObject()
616 json.add("requestInfo", requestInfo)
617 json.add("NSSTInfo", nsstInfo)
618 json.addProperty("sliceProfile", profileJson)
619 return json.toString()
622 * Method to create NSI/NSSI termination request
623 * (OOF response will be synchronous in G-Release)
624 * @param requestId - mso-request-id
625 * @param nxlId - NSI/NSSI Id to be terminated
626 * @param messageType - Message type for callback correlation
627 * @param serviceInstanceId - NSI/NSSI Id related to nxlId
630 public String buildTerminateNxiRequest(String requestId,String nxlId, String nxlType, String messageType, String serviceInstanceId) {
631 def transactionId = requestId
632 logger.debug( "transactionId is: " + transactionId)
633 String correlator = requestId
634 String callbackUrl = UrnPropertiesReader.getVariable("mso.adapters.oof.callback.endpoint") + "/" + messageType + "/" + correlator
635 //Prepare Terminate Nxl Json
636 JsonObject json = new JsonObject()
637 json.addProperty("type", nxlType)
638 json.addProperty("NxIId", nxlId)
640 //Prepare requestInfo object
641 JsonObject requestInfo = new JsonObject()
642 requestInfo.addProperty("transactionId", transactionId)
643 requestInfo.addProperty("requestId", requestId)
644 requestInfo.addProperty("callbackUrl", callbackUrl)
645 requestInfo.addProperty("sourceId","SO" )
646 requestInfo.addProperty("timeout", 600)
648 //Prepare addtnlArgs object
649 JsonObject addtnlArgs = new JsonObject()
650 addtnlArgs.addProperty("serviceInstanceId", serviceInstanceId)
652 requestInfo.add("addtnlArgs", addtnlArgs)
653 json.add("requestInfo", requestInfo)
655 return json.toString()
659 public String buildSelectNSIRequest(String requestId, TemplateInfo nstInfo, List<TemplateInfo> nsstInfo,
660 String messageType, Map<String, Object> serviceProfile,
661 List<SubnetCapability> subnetCapabilities, Integer timeOut){
663 def transactionId = requestId
664 logger.debug( "transactionId is: " + transactionId)
666 String callbackUrl = UrnPropertiesReader.getVariable("mso.adapters.oof.callback.endpoint") + "/" + messageType + "/" + correlator
668 NsiReqBody nsiReqBody = new NsiReqBody()
670 RequestInfo requestInfo = new RequestInfo()
671 requestInfo.setRequestId(requestId)
672 requestInfo.setTransactionId(transactionId)
673 requestInfo.setCallbackUrl(callbackUrl)
674 requestInfo.setSourceId("so")
675 requestInfo.setTimeout(timeOut)
676 //requestInfo.setNumSolutions()
678 nsiReqBody.setRequestInfo(requestInfo)
679 nsiReqBody.setNSTInfo(nstInfo)
680 nsiReqBody.setServiceProfile(serviceProfile)
681 nsiReqBody.setSubnetCapabilities(subnetCapabilities)
682 nsiReqBody.setNSSTInfo(nsstInfo)
685 ObjectMapper objectMapper = new ObjectMapper()
687 return objectMapper.writeValueAsString(nsiReqBody)