2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved.
\r
6 * ================================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ============LICENSE_END=========================================================
\r
21 package org.openecomp.mso.bpmn.infrastructure.scripts;
\r
23 import static org.apache.commons.lang3.StringUtils.*;
\r
24 import groovy.xml.XmlUtil
\r
25 import groovy.json.*
\r
26 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
\r
27 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
\r
28 import org.openecomp.mso.bpmn.common.recipe.ResourceInput;
\r
29 import org.openecomp.mso.bpmn.common.resource.ResourceRequestBuilder
\r
30 import org.openecomp.mso.bpmn.core.WorkflowException
\r
31 import org.openecomp.mso.bpmn.core.json.JsonUtils
\r
32 import org.openecomp.mso.bpmn.infrastructure.workflow.serviceTask.client.builder.AbstractBuilder
\r
33 import org.openecomp.mso.rest.APIResponse
\r
35 import java.util.UUID;
\r
37 import org.camunda.bpm.engine.delegate.BpmnError
\r
38 import org.camunda.bpm.engine.delegate.DelegateExecution
\r
39 import org.apache.commons.lang3.*
\r
40 import org.apache.commons.codec.binary.Base64;
\r
41 import org.springframework.web.util.UriUtils
\r
42 import org.openecomp.mso.rest.RESTClient
\r
43 import org.openecomp.mso.rest.RESTConfig
\r
44 import org.openecomp.mso.rest.APIResponse;
\r
47 * This groovy class supports the <class>CreateSDNCCNetworkResource.bpmn</class> process.
\r
48 * flow for SDNC Network Resource Create
\r
50 public class CreateSDNCCNetworkResource extends AbstractServiceTaskProcessor {
\r
52 String Prefix="CRESDNCRES_"
\r
54 ExceptionUtil exceptionUtil = new ExceptionUtil()
\r
56 JsonUtils jsonUtil = new JsonUtils()
\r
58 public void preProcessRequest(DelegateExecution execution){
\r
59 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
\r
60 utils.log("INFO"," ***** Started preProcessRequest *****", isDebugEnabled)
\r
63 //get bpmn inputs from resource request.
\r
64 String requestId = execution.getVariable("requestId")
\r
65 String requestAction = execution.getVariable("requestAction")
\r
66 utils.log("INFO","The requestAction is: " + requestAction, isDebugEnabled)
\r
67 String recipeParamsFromRequest = execution.getVariable("recipeParams")
\r
68 utils.log("INFO","The recipeParams is: " + recipeParams, isDebugEnabled)
\r
69 String resourceInput = execution.getVariable("requestInput")
\r
70 utils.log("INFO","The resourceInput is: " + resourceInput, isDebugEnabled)
\r
71 //Get ResourceInput Object
\r
72 ResourceInput resourceInputObj = ResourceRequestBuilder.getJsonObject(resourceInput, resourceInputObj)
\r
73 execution.setVariable(Prefix + "resourceInput", resourceInputObj)
\r
75 //Deal with recipeParams
\r
76 String recipeParamsFromWf = execution.getVariable("recipeParamXsd")
\r
77 String resourceName = resourceInputObj.getResourceInstanceName()
\r
78 //For sdnc requestAction default is "createNetworkInstance"
\r
79 String operationType = "Network"
\r
80 if(!StringUtils.isBlank(recipeParamsFromRequest)){
\r
81 //the operationType from worflow(first node) is second priority.
\r
82 operationType = jsonUtil.getJsonValue(recipeParamsFromRequest, "operationType")
\r
84 if(!StringUtils.isBlank(recipeParamsFromWf)){
\r
85 //the operationType from worflow(first node) is highest priority.
\r
86 operationType = jsonUtil.getJsonValue(recipeParamsFromWf, "operationType")
\r
90 //For sdnc, generate svc_action and request_action
\r
91 String sdnc_svcAction = "create"
\r
92 if(StringUtils.containsIgnoreCase(resourceInputObj.getResourceInstanceName(), "overlay")){
\r
93 //This will be resolved in R3.
\r
94 sdnc_svcAction ="activate"
\r
95 operationType = "NCINetwork"
\r
97 if(StringUtils.containsIgnoreCase(resourceInputObj.getResourceInstanceName(), "underlay")){
\r
98 //This will be resolved in R3.
\r
99 operationType ="Network"
\r
101 String sdnc_requestAction = StringUtils.capitalize(sdnc_svcAction) + operationType +"Instance"
\r
102 execution.setVariable(Prefix + "svcAction", sdnc_svcAction)
\r
103 execution.setVariable(Prefix + "requestAction", sdnc_requestAction)
\r
104 execution.setVariable(Prefix + "serviceInstanceId", resourceInputObj.getServiceInstanceId())
\r
105 execution.setVariable("mso-request-id", requestId)
\r
106 execution.setVariable("mso-service-instance-id", resourceInputObj.getServiceInstanceId())
\r
107 //TODO Here build networkrequest
\r
109 } catch (BpmnError e) {
\r
111 } catch (Exception ex){
\r
112 msg = "Exception in preProcessRequest " + ex.getMessage()
\r
113 utils.log("DEBUG", msg, isDebugEnabled)
\r
114 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
\r
120 * Pre Process the BPMN Flow Request
\r
122 * generate the nsOperationKey
\r
123 * generate the nsParameters
\r
125 public void prepareSDNCRequest (DelegateExecution execution) {
\r
126 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
\r
127 utils.log("INFO"," ***** Started prepareSDNCRequest *****", isDebugEnabled)
\r
131 String sdnc_svcAction = execution.getVariable(Prefix + "svcAction")
\r
132 String sdnc_requestAction = execution.getVariable(Prefix + "requestAction")
\r
133 String sdncCallback = execution.getVariable("URN_mso_workflow_sdncadapter_callback")
\r
134 String createNetworkInput = execution.getVariable(Prefix + "networkRequest")
\r
136 String serviceInstanceId = execution.getVariable(Prefix + "serviceInstanceId")
\r
138 // 1. prepare assign topology via SDNC Adapter SUBFLOW call
\r
139 String sndcTopologyCreateRequest = sdncAdapterUtils.sdncTopologyRequestRsrc(execution, createNetworkInput, serviceInstanceId, sdncCallback, sdnc_svcAction, sdnc_requestAction, null, null, null)
\r
141 String sndcTopologyCreateRequesAsString = utils.formatXml(sndcTopologyCreateRequest)
\r
142 utils.logAudit(sndcTopologyCreateRequesAsString)
\r
143 execution.setVariable(Prefix + "createSDNCRequest", sndcTopologyCreateRequesAsString)
\r
144 utils.log("DEBUG", Prefix + "createSDNCRequest - " + "\n" + sndcTopologyCreateRequesAsString, isDebugEnabled)
\r
146 } catch (Exception ex) {
\r
147 String exceptionMessage = " Bpmn error encountered in CreateSDNCCNetworkResource flow. prepareSDNCRequest() - " + ex.getMessage()
\r
148 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
\r
149 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
\r
152 utils.log("INFO"," ***** Exit prepareSDNCRequest *****", isDebugEnabled)
\r
155 public void postCreateSDNCCall(DelegateExecution execution){
\r
156 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
\r
157 utils.log("INFO"," ***** Started prepareSDNCRequest *****", isDebugEnabled)
\r
158 String responseCode = execution.getVariable(Prefix + "sdncCreateReturnCode")
\r
159 String responseObj = execution.getVariable(Prefix + "SuccessIndicator")
\r
161 utils.log("INFO","response from sdnc, response code :" + responseCode + " response object :" + responseObj, isDebugEnabled)
\r
162 utils.log("INFO"," ***** Exit prepareSDNCRequest *****", isDebugEnabled)
\r