43a2731eb66086f9046ebc3f34132513a20b3916
[so.git] /
1 /*-\r
2  * ============LICENSE_START=======================================================\r
3  * OPENECOMP - SO\r
4  * ================================================================================\r
5  * Copyright (C) 2017 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>CreateGenericE2EServiceInstance.bpmn</class> process.\r
45  * flow for E2E ServiceInstance Create\r
46  */\r
47 public class CreateGenericE2EServiceInstance extends AbstractServiceTaskProcessor {\r
48 \r
49     String createUrl = "/vfc/vfcadapters/v1/ns"\r
50             \r
51     String instantiateUrl = "/vfcvfcadatpers/v1/ns/{nsInstanceId}/instantiate"\r
52     \r
53     String queryJobUrl = "/vfc/vfcadatpers/v1/jobs/{jobId}"\r
54     \r
55     ExceptionUtil exceptionUtil = new ExceptionUtil()\r
56 \r
57     JsonUtils jsonUtil = new JsonUtils()\r
58 \r
59     /**\r
60      * Pre Process the BPMN Flow Request\r
61      * Inclouds:\r
62      * generate the nsOperationKey\r
63      * generate the nsParameters\r
64      */\r
65     public void preProcessRequest (Execution execution) {\r
66            def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
67        String msg = ""\r
68        utils.log("DEBUG", " *** preProcessRequest() *** ", isDebugEnabled)\r
69        try {                    \r
70            String globalSubscriberId = execution.getVariable("globalSubscriberId")\r
71            utils.log("DEBUG", "globalSubscriberId:" + globalSubscriberId, isDebugEnabled)\r
72            String serviceType = execution.getVariable("serviceType")\r
73            utils.log("DEBUG", "serviceType:" + serviceType, isDebugEnabled)\r
74            String serviceId = execution.getVariable("serviceId")\r
75            utils.log("DEBUG", "serviceId:" + serviceId, isDebugEnabled)\r
76            String operationId = execution.getVariable("operationId")\r
77            utils.log("DEBUG", "serviceType:" + serviceType, isDebugEnabled)\r
78            String nodeTemplateUUID = execution.getVariable("nodeTemplateUUID")\r
79            utils.log("DEBUG", "globalSubscriberId:" + globalSubscriberId, isDebugEnabled)\r
80            /*\r
81             * segmentInformation needed as a object of segment\r
82             * {\r
83             *     "domain":"",\r
84             *     "nodeTemplateName":"",\r
85             *     "nodeType":"",\r
86             *     "nsParameters":{\r
87             *       //this is the nsParameters sent to VF-C\r
88             *     }\r
89             * }\r
90             */\r
91            String siRequest = execution.getVariable("segmentInformation")\r
92            utils.log("DEBUG", "Input Request:" + siRequest, isDebugEnabled)\r
93            String nsOperationKey = "{\"globalSubscriberId\":" + globalSubscriberId + ",\"serviceType:\""\r
94                  + serviceType + ",\"serviceId\":" + serviceId + ",\"operationId\":" + operationId\r
95                  +",\"nodeTemplateUUID\":" + nodeTemplateUUID + "}";\r
96            execution.setVariable("nsOperationKey", nsOperationKey);\r
97            execution.setVariable("nsParameters", jsonUtil.getJsonValue(siRequest, "nsParameters"))\r
98 \r
99        } catch (BpmnError e) {\r
100            throw e;\r
101        } catch (Exception ex){\r
102            msg = "Exception in preProcessRequest " + ex.getMessage()\r
103            utils.log("DEBUG", msg, isDebugEnabled)\r
104            exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)\r
105        }\r
106        utils.log("DEBUG"," ***** Exit preProcessRequest *****",  isDebugEnabled)\r
107         }\r
108 \r
109     public void createNetworkService(Execution execution) {\r
110 \r
111     }\r
112 \r
113     public void instantiateNetworkService(Execution execution) {\r
114     }\r
115 \r
116     public void queryNSProgress(Execution execution) {\r
117     }\r
118 \r
119     public void timeDelay(Execution execution) {\r
120     }\r
121 \r
122     public void finishNSCreate(Execution execution) {\r
123     }\r
124 \r
125     /**\r
126      * post request\r
127      * url: the url of the request\r
128      * requestBody: the body of the request\r
129      */\r
130     private APIResponse postRequest(String url, String requestBody){\r
131         def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
132         taskProcessor.logDebug( " ======== Started Execute VFC adapter Post Process ======== ", isDebugEnabled)\r
133         taskProcessor.logDebug( "url:"+url +"\nrequestBody:"+ requestBody, isDebugEnabled)\r
134         APIResponse apiResponse = null\r
135         try{\r
136             RESTConfig config = new RESTConfig(url);\r
137             RESTClient client = new RESTClient(config).addHeader("X-FromAppId", "MSO").addHeader("X-TransactionId", uuid).addHeader("Accept","application/json");\r
138             apiResponse = client.httpPost(requestBody)\r
139             taskProcessor.logDebug( "======== Completed Execute VF-C adapter Post Process ======== ", isDebugEnabled)\r
140         }catch(Exception e){\r
141             taskProcessor.utils.log("ERROR", "Exception occured while executing AAI Post Call. Exception is: \n" + e, isDebugEnabled)\r
142             throw new BpmnError("MSOWorkflowException")\r
143         }\r
144         return apiResponse\r
145     }\r
146 }\r