400b0d40d5483aef48b3056c9e8141a2eed329a3
[so.git] /
1 /*-\r
2  * ============LICENSE_START=======================================================\r
3  * OPENECOMP - SO\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
10  * \r
11  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  * \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
19  */\r
20 \r
21 package org.openecomp.mso.bpmn.infrastructure.scripts;\r
22 \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
31 \r
32 import java.util.UUID;\r
33 \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
42 \r
43 /**\r
44  * This groovy class supports the <class>CreateSDNCCNetworkResource.bpmn</class> process.\r
45  * flow for SDNC Network Resource Create\r
46  */\r
47 public class CreateSDNCCNetworkResource extends AbstractServiceTaskProcessor {\r
48 \r
49     String vfcUrl = "/vfc/rest/v1/vfcadapter"\r
50     \r
51     String host = "http://mso.mso.testlab.openecomp.org:8080"\r
52     \r
53     ExceptionUtil exceptionUtil = new ExceptionUtil()\r
54 \r
55     JsonUtils jsonUtil = new JsonUtils()\r
56     \r
57     /**\r
58      * Pre Process the BPMN Flow Request\r
59      * Inclouds:\r
60      * generate the nsOperationKey\r
61      * generate the nsParameters\r
62      */\r
63     public void preProcessRequest (Execution execution) {\r
64            def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
65        String msg = ""\r
66        utils.log("INFO", " *** preProcessRequest() *** ", isDebugEnabled)\r
67        try {\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
83            /*\r
84             * segmentInformation needed as a object of segment\r
85             * {\r
86             *     "domain":"",\r
87             *     "nodeTemplateName":"",\r
88             *     "nodeType":"",\r
89             *     "nsParameters":{\r
90             *       //this is the nsParameters sent to VF-C\r
91             *     }\r
92             * }\r
93             */\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
102                     }"""\r
103            execution.setVariable("nsOperationKey", nsOperationKey);\r
104            execution.setVariable("nsParameters", nsParameters)\r
105            \r
106 \r
107        } catch (BpmnError e) {\r
108            throw 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
113        }\r
114        utils.log("INFO"," ***** Exit preProcessRequest *****",  isDebugEnabled)\r
115         }\r
116 \r
117     \r
118     /**\r
119      * post request\r
120      * url: the url of the request\r
121      * requestBody: the body of the request\r
122      */\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
128         try{\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
137         }        \r
138         return apiResponse\r
139     }\r
140     \r
141     public void postCreateSDNCCall(Execution execution){\r
142         \r
143     }\r
144 }\r