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