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.core.WorkflowException
\r
29 import org.openecomp.mso.bpmn.core.json.JsonUtils
\r
30 import org.openecomp.mso.rest.APIResponse
\r
32 import java.util.UUID;
\r
34 import org.camunda.bpm.engine.delegate.BpmnError
\r
35 import org.camunda.bpm.engine.runtime.Execution
\r
36 import org.apache.commons.lang3.*
\r
37 import org.apache.commons.codec.binary.Base64;
\r
38 import org.springframework.web.util.UriUtils
\r
39 import org.openecomp.mso.rest.RESTClient
\r
40 import org.openecomp.mso.rest.RESTConfig
\r
41 import org.openecomp.mso.rest.APIResponse;
\r
44 * This groovy class supports the <class>CreateSDNCCNetworkResource.bpmn</class> process.
\r
45 * flow for SDNC Network Resource Create
\r
47 public class CreateSDNCCNetworkResource extends AbstractServiceTaskProcessor {
\r
49 String vfcUrl = "/vfc/rest/v1/vfcadapter"
\r
51 String host = "http://mso.mso.testlab.openecomp.org:8080"
\r
53 ExceptionUtil exceptionUtil = new ExceptionUtil()
\r
55 JsonUtils jsonUtil = new JsonUtils()
\r
58 * Pre Process the BPMN Flow Request
\r
60 * generate the nsOperationKey
\r
61 * generate the nsParameters
\r
63 public void preProcessRequest (Execution execution) {
\r
64 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
66 utils.log("INFO", " *** preProcessRequest() *** ", isDebugEnabled)
\r
68 //deal with nsName and Description
\r
69 String nsServiceName = execution.getVariable("nsServiceName")
\r
70 String nsServiceDescription = execution.getVariable("nsServiceDescription")
\r
71 utils.log("INFO", "nsServiceName:" + nsServiceName + " nsServiceDescription:" + nsServiceDescription, isDebugEnabled)
\r
72 //deal with operation key
\r
73 String globalSubscriberId = execution.getVariable("globalSubscriberId")
\r
74 utils.log("INFO", "globalSubscriberId:" + globalSubscriberId, isDebugEnabled)
\r
75 String serviceType = execution.getVariable("serviceType")
\r
76 utils.log("INFO", "serviceType:" + serviceType, isDebugEnabled)
\r
77 String serviceId = execution.getVariable("serviceId")
\r
78 utils.log("INFO", "serviceId:" + serviceId, isDebugEnabled)
\r
79 String operationId = execution.getVariable("operationId")
\r
80 utils.log("INFO", "serviceType:" + serviceType, isDebugEnabled)
\r
81 String nodeTemplateUUID = execution.getVariable("resourceUUID")
\r
82 utils.log("INFO", "nodeTemplateUUID:" + nodeTemplateUUID, isDebugEnabled)
\r
84 * segmentInformation needed as a object of segment
\r
87 * "nodeTemplateName":"",
\r
90 * //this is the nsParameters sent to VF-C
\r
94 String nsParameters = execution.getVariable("resourceParameters")
\r
95 utils.log("INFO", "nsParameters:" + nsParameters, isDebugEnabled)
\r
96 String nsOperationKey = """{
\r
97 "globalSubscriberId":"${globalSubscriberId}",
\r
98 "serviceType":"${serviceType}",
\r
99 "serviceId":"${serviceId}",
\r
100 "operationId":"${operationId}",
\r
101 "nodeTemplateUUID":"${nodeTemplateUUID}"
\r
103 execution.setVariable("nsOperationKey", nsOperationKey);
\r
104 execution.setVariable("nsParameters", nsParameters)
\r
107 } catch (BpmnError e) {
\r
109 } catch (Exception ex){
\r
110 msg = "Exception in preProcessRequest " + ex.getMessage()
\r
111 utils.log("INFO", msg, isDebugEnabled)
\r
112 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
\r
114 utils.log("INFO"," ***** Exit preProcessRequest *****", isDebugEnabled)
\r
120 * url: the url of the request
\r
121 * requestBody: the body of the request
\r
123 private APIResponse postRequest(Execution execution, String url, String requestBody){
\r
124 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
\r
125 utils.log("INFO"," ***** Started Execute VFC adapter Post Process *****", isDebugEnabled)
\r
126 utils.log("INFO","url:"+url +"\nrequestBody:"+ requestBody, isDebugEnabled)
\r
127 APIResponse apiResponse = null
\r
129 RESTConfig config = new RESTConfig(url);
\r
130 RESTClient client = new RESTClient(config).addHeader("Content-Type", "application/json").addHeader("Accept","application/json").addHeader("Authorization","Basic QlBFTENsaWVudDpwYXNzd29yZDEk");
\r
131 apiResponse = client.httpPost(requestBody)
\r
132 utils.log("INFO","response code:"+ apiResponse.getStatusCode() +"\nresponse body:"+ apiResponse.getResponseBodyAsString(), isDebugEnabled)
\r
133 utils.log("INFO","======== Completed Execute VF-C adapter Post Process ======== ", isDebugEnabled)
\r
134 }catch(Exception e){
\r
135 utils.log("ERROR","Exception occured while executing AAI Post Call. Exception is: \n" + e, isDebugEnabled)
\r
136 throw new BpmnError("MSOWorkflowException")
\r
141 public void postCreateSDNCCall(Execution execution){
\r