2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 # Copyright (c) 2020, Wipro Limited.
7 # Licensed under the Apache License, Version 2.0 (the "License")
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
11 # http://www.apache.org/licenses/LICENSE-2.0
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.so.bpmn.infrastructure.scripts
23 import org.camunda.bpm.engine.delegate.BpmnError
24 import org.slf4j.Logger
25 import org.slf4j.LoggerFactory
26 import org.camunda.bpm.engine.delegate.DelegateExecution
27 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
28 import org.onap.so.bpmn.common.scripts.ExceptionUtil
29 import org.onap.so.bpmn.core.json.JsonUtils
30 import com.fasterxml.jackson.databind.ObjectMapper
31 import com.google.gson.JsonObject
32 import java.sql.Timestamp
34 import static org.apache.commons.lang3.StringUtils.isBlank
35 import org.onap.so.bpmn.core.UrnPropertiesReader
37 class DoModifyRanNfNssi extends AbstractServiceTaskProcessor {
39 String Prefix="MANNFNSS_"
40 ExceptionUtil exceptionUtil = new ExceptionUtil()
41 JsonUtils jsonUtil = new JsonUtils()
42 ObjectMapper objectMapper = new ObjectMapper();
43 AnNssmfUtils anNssmfUtils = new AnNssmfUtils()
45 private static final Logger logger = LoggerFactory.getLogger(DoModifyRanNfNssi.class)
48 void preProcessRequest(DelegateExecution execution) {
49 logger.debug(Prefix + "preProcessRequest Start")
50 execution.setVariable("prefix", Prefix)
51 execution.setVariable("startTime", System.currentTimeMillis())
55 logger.debug("input variables : msoRequestId - "+execution.getVariable("msoRequestId")+
56 " globalSubscriberId - "+execution.getVariable("globalSubscriberId")+
57 " serviceInstanceID - "+execution.getVariable("serviceInstanceID")+
58 " subscriptionServiceType - "+execution.getVariable("subscriptionServiceType")+
59 " sliceProfileId - "+execution.getVariable("sliceProfileId")+
60 " snssaiList - "+execution.getVariable("snssaiList")+
61 " modifyAction - "+execution.getVariable("modifyAction"))
63 //validate RAN NF slice subnet inputs
65 String modifyAction = execution.getVariable("modifyAction")
66 if (isBlank(modifyAction)) {
67 msg = "Input modifyAction is null"
69 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
71 execution.setVariable("modifyAction", modifyAction)
72 switch(modifyAction) {
74 String sliceProfile = execution.getVariable("additionalProperties")
75 execution.setVariable("sliceProfile", sliceProfile)
78 String resourceConfig = execution.getVariable("additionalProperties")
79 execution.setVariable("resourceConfig", resourceConfig)
82 logger.debug("Invalid modify Action")
83 exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Invalid modify Action : "+modifyAction)
86 List<String> snssaiList = objectMapper.readValue(execution.getVariable("snssaiList"), List.class)
87 String sliceProfileId = execution.getVariable("sliceProfileId")
88 if (isBlank(sliceProfileId) || (snssaiList.empty)) {
89 msg = "Mandatory fields are empty"
91 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
93 execution.setVariable("sliceProfileId", sliceProfileId)
94 execution.setVariable("snssaiList", snssaiList)
95 execution.setVariable("snssai", snssaiList.get(0))
98 } catch(BpmnError e) {
100 } catch(Exception ex) {
101 msg = "Exception in DoModifyAccessNssi.preProcessRequest " + ex.getMessage()
103 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
105 logger.debug(Prefix + "preProcessRequest Exit")
108 def createSdnrRequest = { DelegateExecution execution ->
109 logger.debug(Prefix+"createSdnrRequest method start")
110 String callbackUrl = UrnPropertiesReader.getVariable("mso.workflow.message.endpoint") + "/AsyncSdnrResponse/"+execution.getVariable("msoRequestId")
111 String modifyAction = execution.getVariable("modifyAction")
112 String sdnrRequest = buildSdnrAllocateRequest(execution, modifyAction, "InstantiateRANSlice", callbackUrl)
113 execution.setVariable("createNSSI_sdnrRequest", sdnrRequest)
114 execution.setVariable("createNSSI_timeout", "PT10M")
115 execution.setVariable("createNSSI_correlator", execution.getVariable("msoRequestId"))
116 execution.setVariable("createNSSI_messageType", "AsyncSdnrResponse");
119 def processSdnrResponse = { DelegateExecution execution ->
120 logger.debug(Prefix+"processSdnrResponse method start")
121 String SDNRResponse = execution.getVariable("SDNR_asyncCallbackResponse")
122 String status = jsonUtil.getJsonValue(SDNRResponse, "status")
123 if(status.equalsIgnoreCase("success")) {
124 String nfIds = jsonUtil.getJsonValue(SDNRResponse, "nfIds")
125 execution.setVariable("ranNfIdsJson", nfIds)
127 String reason = jsonUtil.getJsonValue(SDNRResponse, "reason")
128 logger.error("received failed status from SDNR "+ reason)
129 exceptionUtil.buildAndThrowWorkflowException(execution, 7000,"received failed status from SDNR "+ reason)
131 logger.debug("response from SDNR "+SDNRResponse)
134 private String buildSdnrAllocateRequest(DelegateExecution execution, String action, String rpcName, String callbackUrl) {
136 String requestId = execution.getVariable("msoRequestId")
137 Date date = new Date().getTime()
138 Timestamp time = new Timestamp(date)
139 String sliceProfileString
140 JsonObject response = new JsonObject()
141 JsonObject body = new JsonObject()
142 JsonObject input = new JsonObject()
143 JsonObject commonHeader = new JsonObject()
144 JsonObject payload = new JsonObject()
145 JsonObject payloadInput = new JsonObject()
146 if(action.equals("allocate")) {
147 Map<String,Object> sliceProfile = objectMapper.readValue(execution.getVariable("sliceProfile"), Map.class)
148 sliceProfile.put("sliceProfileId", execution.getVariable("sliceProfileId"))
149 sliceProfile.put("maxNumberofConns", sliceProfile.get("maxNumberofPDUSessions"))
150 sliceProfile.put("uLThptPerSlice", sliceProfile.get("expDataRateUL"))
151 sliceProfile.put("dLThptPerSlice", sliceProfile.get("expDataRateDL"))
152 sliceProfileString = objectMapper.writeValueAsString(sliceProfile)
153 action = "modify-"+action
154 payloadInput.add("additionalproperties", new JsonObject())
155 }else if(action.equals("deallocate")) {
156 action = "modify-"+action
157 Map<String,Object> sliceProfile = new HashMap<>()
158 sliceProfile.put("sliceProfileId", execution.getVariable("sliceProfileId"))
159 sliceProfile.put("sNSSAI", execution.getVariable("snssai"))
160 sliceProfileString = objectMapper.writeValueAsString(sliceProfile)
161 payloadInput.add("additionalproperties", new JsonObject())
162 }else if(action.equals("reconfigure")) {
163 Map<String,Object> sliceProfile = new HashMap<>()
164 sliceProfile.put("sliceProfileId", execution.getVariable("sliceProfileId"))
165 sliceProfile.put("sNSSAI", execution.getVariable("snssai"))
166 sliceProfileString = objectMapper.writeValueAsString(sliceProfile)
167 JsonObject resourceconfig = new JsonObject()
168 resourceconfig.addProperty("resourceConfig", execution.getVariable("resourceConfig"))
169 payloadInput.add("additionalproperties", resourceconfig)
171 commonHeader.addProperty("TimeStamp", time.toString())
172 commonHeader.addProperty("APIver", "1.0")
173 commonHeader.addProperty("RequestID", requestId)
174 commonHeader.addProperty("SubRequestID", "1")
175 commonHeader.add("RequestTrack", new JsonObject())
176 commonHeader.add("Flags", new JsonObject())
177 payloadInput.addProperty("sliceProfile", sliceProfileString)
178 payloadInput.addProperty("RANNFNSSIId", execution.getVariable("serviceInstanceID"))
179 payloadInput.addProperty("callbackURL", callbackUrl)
180 payload.add("input", payloadInput)
181 input.add("CommonHeader", commonHeader)
182 input.addProperty("Action", action)
183 input.add("Payload", payload)
184 body.add("input", input)
185 response.add("body", body)
186 response.addProperty("version", "1.0")
187 response.addProperty("rpc-name", rpcName)
188 response.addProperty("correlation-id", requestId+"-1")
189 response.addProperty("type", "request")
190 return response.toString()