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