[VID-6] Initial rebase push
[vid.git] / vid-app-common / src / main / java / org / openecomp / vid / controller / MsoController.java
1 /*-\r
2  * ============LICENSE_START=======================================================\r
3  * VID\r
4  * ================================================================================\r
5  * Copyright (C) 2017 AT&T Intellectual Property. 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.vid.controller;\r
22 \r
23 \r
24 import java.io.BufferedReader;\r
25 import java.io.IOException;\r
26 import java.io.InputStreamReader;\r
27 import java.io.OutputStream;\r
28 import java.io.PrintWriter;\r
29 import java.io.StringWriter;\r
30 import java.text.DateFormat;\r
31 import java.text.SimpleDateFormat;\r
32 import java.util.ArrayList;\r
33 //import java.util.UUID;\r
34 import java.util.Date;\r
35 import java.util.Iterator;\r
36 import java.util.List;\r
37 import java.util.Map;\r
38 import java.util.Scanner;\r
39 import java.util.stream.Collectors;\r
40 \r
41 import javax.servlet.http.HttpServletRequest;\r
42 import javax.servlet.http.HttpServletResponse;\r
43 \r
44 import org.codehaus.jackson.JsonEncoding;\r
45 import org.codehaus.jackson.JsonFactory;\r
46 import org.codehaus.jackson.JsonGenerator;\r
47 import org.codehaus.jackson.JsonParser;\r
48 import org.codehaus.jackson.JsonToken;\r
49 import org.glassfish.jersey.client.ClientResponse;\r
50 import org.json.simple.JSONArray;\r
51 import org.json.simple.JSONObject;\r
52 import org.json.simple.parser.JSONParser;\r
53 import org.openecomp.vid.domain.mso.CloudConfiguration;\r
54 import org.openecomp.vid.domain.mso.ModelInfo;\r
55 import org.openecomp.vid.domain.mso.ModelInfo.ModelType;\r
56 import org.openecomp.vid.domain.mso.RequestInfo;\r
57 import org.openecomp.vid.domain.mso.RequestParameters;\r
58 import org.openecomp.vid.model.ExceptionResponse;\r
59 import org.openecomp.vid.mso.MsoProperties;\r
60 import org.openecomp.vid.mso.MsoResponseWrapper;\r
61 import org.openecomp.vid.mso.MsoRestInterfaceFactory;\r
62 import org.openecomp.vid.mso.MsoRestInterfaceIfc;\r
63 import org.openecomp.vid.mso.MsoUtil;\r
64 import org.openecomp.vid.mso.RestObject;\r
65 import org.openecomp.vid.mso.rest.RelatedModel;\r
66 import org.openecomp.vid.mso.rest.RequestDetails;\r
67 import org.springframework.http.HttpStatus;\r
68 //import org.springframework.http.ResponseEntity;\r
69 //import org.springframework.http.RequestEntity;\r
70 import org.springframework.http.ResponseEntity;\r
71 import org.springframework.web.bind.annotation.ExceptionHandler;\r
72 import org.springframework.web.bind.annotation.PathVariable;\r
73 import org.springframework.web.bind.annotation.RequestBody;\r
74 import org.springframework.web.bind.annotation.RequestMapping;\r
75 import org.springframework.web.bind.annotation.RequestMethod;\r
76 import org.springframework.web.bind.annotation.RestController;\r
77 import org.springframework.web.servlet.ModelAndView;\r
78 \r
79 import org.openecomp.portalsdk.core.controller.RestrictedBaseController;\r
80 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;\r
81 import org.openecomp.portalsdk.core.util.SystemProperties;\r
82 import com.fasterxml.jackson.databind.ObjectMapper;\r
83 import com.fasterxml.jackson.databind.ObjectReader;\r
84 import com.fasterxml.jackson.databind.DeserializationFeature;\r
85 \r
86 /**\r
87  * The Class MsoController.\r
88  */\r
89 @RestController\r
90 @RequestMapping("mso")\r
91 public class MsoController extends RestrictedBaseController{\r
92         \r
93         /** The view name. */\r
94         String viewName;\r
95         \r
96         /** The logger. */\r
97         EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MsoController.class);\r
98         \r
99         /** The Constant dateFormat. */\r
100         final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS");\r
101         \r
102         /** The Constant SVC_INSTANCE_ID. */\r
103         public final static String SVC_INSTANCE_ID = "<service_instance_id>";\r
104         \r
105         /** The Constant VNF_INSTANCE_ID. */\r
106         public final static String VNF_INSTANCE_ID = "<vnf_instance_id>";\r
107         \r
108         /**\r
109          * Welcome.\r
110          *\r
111          * @param request the request\r
112          * @return the model and view\r
113          \r
114         public ModelAndView welcome(HttpServletRequest request) {\r
115                 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== MsoController welcome start");\r
116                 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + " MSO_SERVER_URL=" +\r
117                                  SystemProperties.getProperty(MsoProperties.MSO_SERVER_URL) );\r
118                 return new ModelAndView(getViewName());         \r
119         }\r
120         */\r
121 \r
122         /* (non-Javadoc)\r
123          * @see org.openecomp.portalsdk.core.controller.RestrictedBaseController#getViewName()\r
124          \r
125         public String getViewName() {\r
126                 return viewName;\r
127         }\r
128         */\r
129 \r
130         /* (non-Javadoc)\r
131          * @see org.openecomp.portalsdk.core.controller.RestrictedBaseController#setViewName(java.lang.String)\r
132          \r
133         public void setViewName(String viewName) {\r
134                 this.viewName = viewName;\r
135         }\r
136         */\r
137 \r
138         /**\r
139          * Creates the svc instance.\r
140          *\r
141          * @param request the request\r
142          * @return the response entity\r
143          * @throws Exception the exception\r
144          */\r
145         @RequestMapping(value = "/mso_create_svc_instance", method = RequestMethod.POST)\r
146         public ResponseEntity<String> createSvcInstance(HttpServletRequest request, @RequestBody RequestDetails mso_request) throws Exception {\r
147                 String methodName = "createSvcInstance";\r
148                 \r
149                 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start" );\r
150                 \r
151 //              mso_request = retrieveRequestObject (request, mso_request);\r
152 \r
153                 String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_SVC_INSTANCE);\r
154             \r
155                 MsoResponseWrapper w = createInstance(mso_request, p);\r
156                 // always return OK, the MSO status code is embedded in the body\r
157                 \r
158         return ( new ResponseEntity<String>(w.getResponse(), HttpStatus.OK) );\r
159         \r
160         }\r
161         \r
162         /**\r
163          * Creates the vnf.\r
164          *\r
165          * @param serviceInstanceId the service instance id\r
166          * @param request the request\r
167          * @return the response entity\r
168          * @throws Exception the exception\r
169          */\r
170         @RequestMapping(value="/mso_create_vnf_instance/{serviceInstanceId}", method = RequestMethod.POST)      \r
171         public ResponseEntity<String> createVnf(@PathVariable("serviceInstanceId") String serviceInstanceId, HttpServletRequest request, @RequestBody RequestDetails mso_request) throws Exception {\r
172                 \r
173                 String methodName = "createVnf";                \r
174                 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");\r
175                 \r
176                 //RequestDetails mso_request = retrieveRequestObject (request);\r
177             String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_VNF_INSTANCE);\r
178             \r
179             if ( p == null || p.isEmpty()) {\r
180                 throw new Exception ( "Vnf instance path is not defined");\r
181             }\r
182             // /serviceInstances/v2/<service_instance_id>/vnfs\r
183             String vnf_path = p.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId );\r
184             MsoResponseWrapper w = createInstance(mso_request, vnf_path);\r
185 \r
186                 // always return OK, the MSO status code is embedded in the body\r
187                 \r
188         return ( new ResponseEntity<String>(w.getResponse(), HttpStatus.OK) );\r
189         \r
190         }\r
191         \r
192         /**\r
193          * Creates the nw instance.\r
194          *\r
195          * @param serviceInstanceId the service instance id\r
196          * @param request the request\r
197          * @return the response entity\r
198          * @throws Exception the exception\r
199          */\r
200         @RequestMapping(value = "/mso_create_nw_instance/{serviceInstanceId}", method = RequestMethod.POST)\r
201         public ResponseEntity<String> createNwInstance(@PathVariable("serviceInstanceId") String serviceInstanceId, HttpServletRequest request, @RequestBody RequestDetails mso_request) throws Exception {\r
202         \r
203                 String methodName = "createNwInstance";         \r
204                 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start, serviceInstanceId = " + serviceInstanceId  );\r
205                 \r
206                 //RequestDetails mso_request = retrieveRequestObject (request);\r
207                 \r
208             String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_NETWORK_INSTANCE);\r
209             \r
210             if ( p == null || p.isEmpty()) {\r
211                 throw new Exception ( "Network instance path is not defined");\r
212             }\r
213             // /serviceInstances/v2/<serviceInstanceId>/networks/\r
214             \r
215             String nw_path = p.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId );\r
216             MsoResponseWrapper w = createInstance(mso_request, nw_path);\r
217            \r
218                 // always return OK, the MSO status code is embedded in the body\r
219                 \r
220         return ( new ResponseEntity<String>(w.getResponse(), HttpStatus.OK) );\r
221         \r
222         }\r
223         \r
224         /**\r
225          * Creates the volume group instance.\r
226          *\r
227          * @param serviceInstanceId the service instance id\r
228          * @param vnfInstanceId the vnf instance id\r
229          * @param request the request\r
230          * @return the response entity\r
231          * @throws Exception the exception\r
232          */\r
233         @RequestMapping(value = "/mso_create_volumegroup_instance/{serviceInstanceId}/vnfs/{vnfInstanceId}", method = RequestMethod.POST)\r
234         public ResponseEntity<String> createVolumeGroupInstance(@PathVariable("serviceInstanceId") String serviceInstanceId, @PathVariable("vnfInstanceId") String vnfInstanceId, \r
235                         HttpServletRequest request, @RequestBody RequestDetails mso_request) throws Exception {\r
236                 String methodName = "createVolumeGroupInstance";\r
237                 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");\r
238                 \r
239                 //RequestDetails mso_request = retrieveRequestObject (request);\r
240                 String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_VOLUME_GROUP_INSTANCE);\r
241             \r
242             if ( p == null || p.isEmpty()) {\r
243                 throw new Exception ( "Volume group instance path is not defined");\r
244             }\r
245             String path = p.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);\r
246             path = path.replaceFirst(VNF_INSTANCE_ID, vnfInstanceId);\r
247             \r
248             MsoResponseWrapper w = createInstance(mso_request, path);\r
249         \r
250                 // always return OK, the MSO status code is embedded in the body\r
251         return ( new ResponseEntity<String>(w.getResponse(), HttpStatus.OK) );\r
252         }\r
253         \r
254         /**\r
255          * Creates the vf module instance.\r
256          *\r
257          * @param serviceInstanceId the service instance id\r
258          * @param vnfInstanceId the vnf instance id\r
259          * @param request the request\r
260          * @return the response entity\r
261          * @throws Exception the exception\r
262          */\r
263         @RequestMapping(value = "/mso_create_vfmodule_instance/{serviceInstanceId}/vnfs/{vnfInstanceId}", method = RequestMethod.POST)\r
264         public ResponseEntity<String> createVfModuleInstance(@PathVariable("serviceInstanceId") String serviceInstanceId, \r
265                         @PathVariable("vnfInstanceId") String vnfInstanceId, HttpServletRequest request, @RequestBody RequestDetails mso_request) throws Exception {\r
266                 String methodName = "createVfModuleInstance";           \r
267                 \r
268                 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");\r
269                 //RequestDetails mso_request = retrieveRequestObject (request);\r
270             String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_VF_MODULE_INSTANCE);\r
271             \r
272             if ( p == null || p.isEmpty()) {\r
273                 throw new Exception ( "VF module instance path is not defined");\r
274             }\r
275             // /serviceInstances/v2/<serviceInstanceId>/vnfs/<vnfInstanceId>/vfmodules\r
276             String path = p.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);\r
277             path = path.replaceFirst(VNF_INSTANCE_ID, vnfInstanceId);\r
278             \r
279             MsoResponseWrapper w = createInstance(mso_request, path);\r
280                 \r
281                 // always return OK, the MSO status code is embedded in the body\r
282                 \r
283         return ( new ResponseEntity<String>(w.getResponse(), HttpStatus.OK) );\r
284         }\r
285         \r
286         /**\r
287          * Creates the instance.\r
288          *\r
289          * @param request the request\r
290          * @param path the path\r
291          * @return the mso response wrapper\r
292          * @throws ClientHandlerException the client handler exception\r
293          * @throws Exception the exception\r
294          */\r
295         protected MsoResponseWrapper createInstance(RequestDetails request, String path) throws Exception {\r
296                 String methodName = "createInstance";   \r
297                 logger.debug(dateFormat.format(new Date()) + "<== " + methodName + " start");\r
298                 \r
299                 try {\r
300                         MsoRestInterfaceIfc restController = MsoRestInterfaceFactory.getInstance();\r
301                         logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " calling Post, request = (" + request + ")");       \r
302                         \r
303                         RestObject<String> restObjStr = new RestObject<String>();\r
304                         String str = new String();\r
305                         restObjStr.set(str);\r
306                         restController.<String>Post(str, request, "", path, restObjStr );\r
307                         MsoResponseWrapper w = MsoUtil.wrapResponse (restObjStr);\r
308                         \r
309                         logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " w=" + w.getResponse());\r
310                         return w;\r
311                 } catch (Exception e) {\r
312                         logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) +  "<== " + "." + methodName + e.toString());\r
313                         logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) +  "<== " + "." + methodName + e.toString());\r
314                         throw e;\r
315                 }\r
316         }\r
317         \r
318         /**\r
319          * Delete svc instance.\r
320          *\r
321          * @param serviceInstanceId the service instance id\r
322          * @param request the request\r
323          * @return the response entity\r
324          * @throws Exception the exception\r
325          */\r
326         @RequestMapping(value = "/mso_delete_svc_instance/{serviceInstanceId}", method = RequestMethod.POST)\r
327         public ResponseEntity<String> deleteSvcInstance(@PathVariable("serviceInstanceId") String serviceInstanceId,\r
328                         HttpServletRequest request, @RequestBody RequestDetails mso_request) throws Exception {\r
329                 \r
330                 String methodName = "deleteSvcInstance";        \r
331                 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");\r
332                 \r
333                 //RequestDetails mso_request = retrieveRequestObject (request);\r
334             String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_SVC_INSTANCE);\r
335             String path = p + "/" + serviceInstanceId;\r
336             MsoResponseWrapper w = deleteInstance ( mso_request, path );\r
337           \r
338                 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " w=" + w.getResponse());\r
339                 // always return OK, the MSO status code is embedded in the body\r
340                 \r
341         return ( new ResponseEntity<String>(w.getResponse(), HttpStatus.OK) );\r
342             \r
343         }\r
344         \r
345         /**\r
346          * Delete vnf.\r
347          *\r
348          * @param serviceInstanceId the service instance id\r
349          * @param vnfInstanceId the vnf instance id\r
350          * @param request the request\r
351          * @return the response entity\r
352          * @throws Exception the exception\r
353          */\r
354         @RequestMapping(value = "/mso_delete_vnf_instance/{serviceInstanceId}/vnfs/{vnfInstanceId}", method = RequestMethod.POST)\r
355         \r
356         public ResponseEntity<String> deleteVnf(@PathVariable("serviceInstanceId") String serviceInstanceId, @PathVariable("vnfInstanceId") String vnfInstanceId, \r
357                         HttpServletRequest request, @RequestBody RequestDetails mso_request) throws Exception {\r
358                 String methodName = "deleteVnf";                \r
359                 \r
360                 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");\r
361                 \r
362                 //RequestDetails mso_request = retrieveRequestObject (request);\r
363             String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_VNF_INSTANCE);\r
364             if ( p == null || p.isEmpty()) {\r
365                 throw new Exception ( "Vnf instance path is not defined");\r
366             }\r
367             // /serviceInstances/v2/<service_instance_id>/vnfs/\r
368             String vnf_path = p.replaceFirst(SVC_INSTANCE_ID, vnfInstanceId );\r
369             MsoResponseWrapper w = deleteInstance ( mso_request, vnf_path + "/" + vnfInstanceId );\r
370             \r
371                 // always return OK, the MSO status code is embedded in the body\r
372         return ( new ResponseEntity<String>(w.getResponse(), HttpStatus.OK) );\r
373                 \r
374         }\r
375                                                           \r
376                                                         /**\r
377                                                          * Delete vf module.\r
378                                                          *\r
379                                                          * @param serviceInstanceId the service instance id\r
380                                                          * @param vnfInstanceId the vnf instance id\r
381                                                          * @param vfModuleId the vf module id\r
382                                                          * @param request the request\r
383                                                          * @return the response entity\r
384                                                          * @throws Exception the exception\r
385                                                          */\r
386                                                         //mso_delete_vf_module/bc305d54-75b4-431b-adb2-eb6b9e546014/vnfs/fe9000-0009-9999/vfmodules/abeeee-abeeee-abeeee\r
387         @RequestMapping(value = "/mso_delete_vfmodule_instance/{serviceInstanceId}/vnfs/{vnfInstanceId}/vfModules/{vfModuleId}", method = RequestMethod.POST)\r
388         public ResponseEntity<String> deleteVfModule (\r
389                         @PathVariable("serviceInstanceId") String serviceInstanceId, @PathVariable("vnfInstanceId") String vnfInstanceId,\r
390                         @PathVariable("vfModuleId") String vfModuleId, HttpServletRequest request, @RequestBody RequestDetails mso_request) throws Exception {\r
391                 \r
392                 String methodName = "deleteVfModule";\r
393                 \r
394                 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");\r
395                 \r
396                 //RequestDetails mso_request = new RequestDetails();\r
397                 //mso_request = retrieveRequestObject (request);\r
398             String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_VF_MODULE_INSTANCE);\r
399             if ( p == null || p.isEmpty()) {\r
400                 throw new Exception ( "VF Module instance path is not defined");\r
401             }\r
402             // /serviceInstances/v2/<serviceInstanceId>/vnfs/<vnfInstanceId>/vfmodules\r
403             String path = p.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId );\r
404             path = path.replaceFirst(VNF_INSTANCE_ID, vnfInstanceId );\r
405             MsoResponseWrapper w = deleteInstance ( mso_request, path + "/" + vfModuleId);\r
406             \r
407                 // always return OK, the MSO status code is embedded in the body\r
408         return ( new ResponseEntity<String>(w.getResponse(), HttpStatus.OK) );\r
409 \r
410         }\r
411 \r
412         /**\r
413          * Delete volume group instance.\r
414          *\r
415          * @param serviceInstanceId the service instance id\r
416          * @param vnfInstanceId the vnf instance id\r
417          * @param volumeGroupId the volume group id\r
418          * @param request the request\r
419          * @return the response entity\r
420          * @throws Exception the exception\r
421          */\r
422         @RequestMapping(value = "/mso_delete_volumegroup_instance/{serviceInstanceId}/vnfs/{vnfInstanceId}/volumeGroups/{volumeGroupId}", method = RequestMethod.POST)\r
423         public ResponseEntity<String> deleteVolumeGroupInstance (\r
424                         @PathVariable("serviceInstanceId") String serviceInstanceId, @PathVariable("vnfInstanceId") String vnfInstanceId, @PathVariable("volumeGroupId") String volumeGroupId,\r
425                         HttpServletRequest request, @RequestBody RequestDetails mso_request) throws Exception {\r
426                 \r
427                 String methodName = "deleteVolumeGroupInstance";                \r
428                 \r
429                 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");\r
430                 //RequestDetails mso_request = retrieveRequestObject (request);\r
431                 \r
432             String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_VOLUME_GROUP_INSTANCE);\r
433             if ( p == null || p.isEmpty()) {\r
434                 throw new Exception ( "Volume group instance path is not defined");\r
435             }\r
436             // /serviceInstances/v2/{serviceInstanceId}/volumeGroups\r
437             String path = p.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId );\r
438             path = path.replaceFirst(VNF_INSTANCE_ID, vnfInstanceId );\r
439             MsoResponseWrapper w = deleteInstance ( mso_request, path + "/" + volumeGroupId);\r
440             \r
441                 // always return OK, the MSO status code is embedded in the body\r
442         return ( new ResponseEntity<String>(w.getResponse(), HttpStatus.OK) );\r
443         }\r
444         \r
445         /**\r
446          * Delete nw instance.\r
447          *\r
448          * @param serviceInstanceId the service instance id\r
449          * @param networkInstanceId the network instance id\r
450          * @param request the request\r
451          * @return the response entity\r
452          * @throws Exception the exception\r
453          */\r
454         @RequestMapping(value = "/mso_delete_nw_instance/{serviceInstanceId}/networks/{networkInstanceId}", method = RequestMethod.POST)\r
455         public ResponseEntity<String> deleteNwInstance(@PathVariable("serviceInstanceId") String serviceInstanceId,\r
456                 @PathVariable("networkInstanceId") String networkInstanceId, HttpServletRequest request, @RequestBody RequestDetails mso_request) throws Exception {\r
457         \r
458                 String methodName = "deleteNwInstance";         \r
459                 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");\r
460                 \r
461                 //RequestDetails mso_request = retrieveRequestObject (request);\r
462                 \r
463             String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_NETWORK_INSTANCE);\r
464             if ( p == null || p.isEmpty()) {\r
465                 throw new Exception ( "Network instance path is not defined");\r
466             }\r
467             // /serviceInstances/v2/<service_instance_id>/networks\r
468             String path = p.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId );\r
469             MsoResponseWrapper w = deleteInstance ( mso_request, path + "/" + networkInstanceId);\r
470             \r
471                 // always return OK, the MSO status code is embedded in the body\r
472         return ( new ResponseEntity<String>(w.getResponse(), HttpStatus.OK) );\r
473             \r
474         }\r
475         \r
476         /**\r
477          * Delete instance.\r
478          *\r
479          * @param request the request\r
480          * @param path the path\r
481          * @return the mso response wrapper\r
482          * @throws Exception the exception\r
483          */\r
484         protected  MsoResponseWrapper deleteInstance(RequestDetails request, String path) throws Exception {\r
485                 String methodName = "deleteInstance";   \r
486                 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");\r
487                 \r
488                 try {\r
489                         MsoRestInterfaceIfc restController = MsoRestInterfaceFactory.getInstance();\r
490                         logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " calling Delete, path =[" + path + "]");\r
491                 \r
492                         RestObject<String> restObjStr = new RestObject<String>();\r
493                         String str = new String();\r
494                         restObjStr.set(str);\r
495                         restController.<String>Delete(str, request, "", path, restObjStr );\r
496                         MsoResponseWrapper w = MsoUtil.wrapResponse (restObjStr);\r
497                         \r
498                         logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " w=" + w.getResponse());\r
499                         return w;\r
500 \r
501                 } catch (Exception e) {\r
502                         logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) +  "<== " + "." + methodName + e.toString());\r
503                         logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) +  "<== " + "." + methodName + e.toString());\r
504                         throw e;\r
505                 }\r
506                 \r
507         }\r
508         \r
509         /**\r
510          * Gets the orchestration request.\r
511          *\r
512          * @param requestId the request id\r
513          * @param request the request\r
514          * @return the orchestration request\r
515          * @throws Exception the exception\r
516          */\r
517         @RequestMapping(value = "/mso_get_orch_req/{requestId}", method = RequestMethod.GET)\r
518         public ResponseEntity<String> getOrchestrationRequest(@PathVariable("requestId") String requestId,\r
519                         HttpServletRequest request) throws Exception {\r
520                 \r
521                 String methodName = "getOrchestrationRequest";          \r
522                 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");\r
523                 MsoResponseWrapper w = null;\r
524                 try {\r
525                         MsoRestInterfaceIfc restController = MsoRestInterfaceFactory.getInstance();\r
526                     String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQ);\r
527                     String path = p + "/" + requestId;\r
528                     \r
529                     RestObject<String> restObjStr = new RestObject<String>();\r
530                         String str = new String();\r
531                         restObjStr.set(str);\r
532 \r
533                     restController.<String>Get(str, "", path, restObjStr);\r
534                     \r
535                     w = MsoUtil.wrapResponse (restObjStr);\r
536                         logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " w=" + w.getResponse());\r
537                         // always return OK, the MSO status code is embedded in the body\r
538                         \r
539                 } catch (Exception e) {\r
540                         logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) +  "<== " + "." + methodName + e.toString());\r
541                         logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) +  "<== " + "." + methodName + e.toString());\r
542                         throw e;\r
543                 }\r
544                 // always return OK, the MSO status code is embedded in the body\r
545                 return ( new ResponseEntity<String>(w.getResponse(), HttpStatus.OK) );\r
546         }\r
547         \r
548         \r
549         /**\r
550          * Gets the orchestration requests.\r
551          *\r
552          * @param filterString the filter string\r
553          * @param request the request\r
554          * @return the orchestration requests\r
555          * @throws Exception the exception\r
556          */\r
557         @RequestMapping(value = "/mso_get_orch_reqs/{filterString}", method = RequestMethod.GET)\r
558         public ResponseEntity<String> getOrchestrationRequests(@PathVariable("filterString") String filterString,\r
559                         HttpServletRequest request) throws Exception {\r
560                 \r
561                 String methodName = "getOrchestrationRequests";         \r
562                 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");\r
563                 MsoResponseWrapper w = null;\r
564                 try {\r
565                         MsoRestInterfaceIfc restController = MsoRestInterfaceFactory.getInstance();\r
566                     String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQS);\r
567                     String path = p + filterString;\r
568                     \r
569                     RestObject<String> restObjStr = new RestObject<String>();\r
570                         String str = new String();\r
571                         restObjStr.set(str);\r
572 \r
573                     restController.<String>Get(str, "", path, restObjStr);\r
574                    \r
575                     w = MsoUtil.wrapResponse (restObjStr);\r
576                     logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " w=" + w.getResponse());\r
577                 } catch (Exception e) {\r
578                         logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) +  "<== " + "." + methodName + e.toString());\r
579                         logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) +  "<== " + "." + methodName + e.toString());\r
580                         throw e;\r
581                 }\r
582                 // always return OK, the MSO status code is embedded in the body\r
583                 return ( new ResponseEntity<String>(w.getResponse(), HttpStatus.OK) );\r
584         }\r
585                 \r
586         /**\r
587          * Gets the orchestration requests for svc instance.\r
588          *\r
589          * @param svc_instance_id the svc instance id\r
590          * @return the orchestration requests for svc instance\r
591          * @throws Exception the exception\r
592          */\r
593         public MsoResponseWrapper getOrchestrationRequestsForSvcInstance (String svc_instance_id) throws Exception {\r
594                 \r
595                 String methodName = "getOrchestrationRequestsForSvcInstance";           \r
596                 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");\r
597                 MsoResponseWrapper w = null;\r
598                 \r
599                 try {\r
600                         MsoRestInterfaceIfc restController = MsoRestInterfaceFactory.getInstance();\r
601                     String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQS);\r
602                     String path = p + svc_instance_id;\r
603                     \r
604                     RestObject<String> restObjStr = new RestObject<String>();\r
605                         String str = new String();\r
606                         restObjStr.set(str);\r
607                         \r
608                         restController.<String>Get(str, "", path, restObjStr);\r
609                         w = MsoUtil.wrapResponse (restObjStr);\r
610                     logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " w=" + w.getResponse());\r
611                 \r
612                 } catch (Exception e) {\r
613                         logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) +  "<== " + "." + methodName + e.toString());\r
614                         logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) +  "<== " + "." + methodName + e.toString());\r
615                         throw e;\r
616                 }\r
617                 return w;\r
618         }\r
619         \r
620         /**\r
621          * Exception handler.\r
622          *\r
623          * @param e the e\r
624          * @param response the response\r
625          * @throws IOException Signals that an I/O exception has occurred.\r
626          */\r
627         @ExceptionHandler(Exception.class)\r
628         private void exceptionHandler(Exception e, HttpServletResponse response) throws IOException {\r
629 \r
630                 /*\r
631                  * The following "logger.error" lines "should" be sufficient for logging the exception.\r
632                  * However, the console output in my Eclipse environment is NOT showing ANY of the\r
633                  * logger statements in this class. Thus the temporary "e.printStackTrace" statement\r
634                  * is also included.\r
635                  */\r
636                 \r
637                 String methodName = "exceptionHandler"; \r
638                 logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) +  "<== " + "." + methodName + e.toString());\r
639                 StringWriter sw = new StringWriter();\r
640                                 e.printStackTrace(new PrintWriter(sw));\r
641                 logger.error(EELFLoggerDelegate.errorLogger, sw.toString());\r
642 \r
643                 /*\r
644                  *  Temporary - IF the above  mentioned "logger.error" glitch is resolved ...\r
645                  *  this statement could be removed since it would then likely result in duplicate\r
646                  *  trace output. \r
647                  */\r
648                 e.printStackTrace(System.err);\r
649 \r
650                 response.setContentType("application/json; charset=UTF-8");\r
651                 response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);\r
652 \r
653                 ExceptionResponse exceptionResponse = new ExceptionResponse();\r
654                 exceptionResponse.setException(e.getClass().toString().replaceFirst("^.*\\.", ""));\r
655                 exceptionResponse.setMessage(e.getMessage());\r
656 \r
657                 response.getWriter().write(new ObjectMapper().writeValueAsString(exceptionResponse));\r
658 \r
659                 response.flushBuffer();\r
660 \r
661         }\r
662 \r
663         /**\r
664          * Parses the orchestration requests for svc instance.\r
665          *\r
666          * @param resp the resp\r
667          * @return the list\r
668          * @throws ParseException the parse exception\r
669          * @throws Exception the exception\r
670          */\r
671         @SuppressWarnings("unchecked")\r
672         public List<JSONObject> parseOrchestrationRequestsForSvcInstance ( ClientResponse resp ) throws org.json.simple.parser.ParseException, Exception {\r
673                 \r
674                 String methodName = "parseOrchestrationRequestsForSvcInstance";\r
675                 \r
676                 ArrayList<JSONObject> json_list = new ArrayList<JSONObject>();\r
677                 \r
678                 String rlist_str = resp.readEntity (String.class);\r
679                 logger.debug (EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) +  "<== " + "." + methodName + " Response string: " + rlist_str);\r
680                 \r
681                 JSONParser parser = new JSONParser();\r
682                 try {\r
683                         Object obj = parser.parse(rlist_str);\r
684                         \r
685                         JSONObject jsonObject = (JSONObject) obj;\r
686                 \r
687                         JSONArray requestList = (JSONArray) jsonObject.get("requestList");\r
688                         \r
689                         if ( requestList != null && ! (requestList.isEmpty()) )\r
690                                 for ( Object container : requestList) {\r
691                         \r
692                                         JSONObject containerJsonObj = (JSONObject) container;\r
693                                         //logger.debug(dateFormat.format(new Date()) +  "<== " + "." + methodName + " reqJsonObj: " + containerJsonObj.toJSONString());\r
694                                         JSONObject reqJsonObj = (JSONObject) containerJsonObj.get("request");\r
695                                         \r
696                                         //logger.debug(dateFormat.format(new Date()) +  "<== " + "." + methodName + " reqJsonObj.requestId: " + \r
697                                                 //      reqJsonObj.get("requestId") );\r
698                                         JSONObject result = new JSONObject();\r
699                                         \r
700                                         result.put("requestId", reqJsonObj.get ("requestId"));\r
701                                         if ( reqJsonObj.get("requestType") != null ) {\r
702                                                 result.put("requestType", (reqJsonObj.get("requestType").toString()));\r
703                                         }\r
704                                         JSONObject req_status = (JSONObject)reqJsonObj.get("requestStatus");\r
705                                         if ( req_status != null ) {\r
706                                                 result.put("timestamp", (req_status.get("timestamp")));\r
707                                                 result.put("requestState", (req_status.get("requestState")));\r
708                                                 result.put("statusMessage", (req_status.get("statusMessage")));\r
709                                                 result.put("percentProgress", (req_status.get("percentProgress")));\r
710                                         } \r
711                                         json_list.add (result);\r
712                                 }\r
713                 } catch (org.json.simple.parser.ParseException pe) {\r
714                         logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) +  "<== " + "." + methodName + " Parse exception: " + pe.toString());\r
715                         throw pe;\r
716                 } catch (Exception e) {\r
717                         logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) +  "<== " + "." + methodName + " Exception: " + e.toString());\r
718                         throw e;\r
719                 }\r
720                 return ( json_list );\r
721         } \r
722         \r
723         /**\r
724          * Retrieve request object.\r
725          *\r
726          * @param request the request\r
727          * @return the request details\r
728          * @throws Exception the exception\r
729          */\r
730         public RequestDetails retrieveRequestObject ( HttpServletRequest request, @RequestBody RequestDetails mso_request ) throws Exception {\r
731                         \r
732                 String methodName = "retrieveRequestObject";\r
733                 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start" );\r
734                 \r
735                 ObjectMapper mapper = new ObjectMapper();\r
736                 //JSON from String to Object\r
737                 //RequestDetails mso_request;\r
738                 \r
739                 try {\r
740                         //mso_request = new RequestDetails();\r
741                         //mso_request = mapper.readValue(request.getInputStream(), RequestDetails.class);\r
742                 }\r
743                 catch ( Exception e ) {\r
744                         logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + methodName + " Unable to read json object RequestDetails e=" + e.getMessage());\r
745                         throw e;\r
746                 }\r
747                 if ( mso_request == null) {\r
748                         logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + methodName + " mso_request is null");\r
749                         throw new Exception ("RequestDetails is missing");\r
750                 }\r
751                 try {\r
752                         String json_req = mapper.writeValueAsString(mso_request);\r
753                         logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " request=[" + json_req + "]");\r
754                 }\r
755                 catch ( Exception e ) {\r
756                         logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + methodName + " Unable to convert RequestDetails to json string e=" + e.getMessage());\r
757                         throw e;\r
758                 }\r
759                 return (mso_request);\r
760         }\r
761 }\r