2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.vid.controller;
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;
34 import javax.servlet.http.HttpServletRequest;
35 import javax.servlet.http.HttpServletResponse;
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;
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;
66 * The Class MsoController.
69 @RequestMapping("mso")
70 public class MsoController extends RestrictedBaseController{
76 EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MsoController.class);
78 /** The Constant dateFormat. */
79 final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS");
81 /** The Constant SVC_INSTANCE_ID. */
82 public final static String SVC_INSTANCE_ID = "<service_instance_id>";
84 /** The Constant VNF_INSTANCE_ID. */
85 public final static String VNF_INSTANCE_ID = "<vnf_instance_id>";
90 * @param request the request
91 * @return the model and view
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());
101 * @see org.openecomp.portalsdk.core.controller.RestrictedBaseController#getViewName()
103 public String getViewName() {
108 * @see org.openecomp.portalsdk.core.controller.RestrictedBaseController#setViewName(java.lang.String)
110 public void setViewName(String viewName) {
111 this.viewName = viewName;
115 * Creates the svc instance.
117 * @param request the request
118 * @return the response entity
119 * @throws Exception the exception
121 @RequestMapping(value = "/mso_create_svc_instance", method = RequestMethod.POST)
122 public ResponseEntity<String> createSvcInstance(HttpServletRequest request) throws Exception {
123 String methodName = "createSvcInstance";
125 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start" );
127 RequestDetails mso_request = retrieveRequestObject (request);
128 String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_SVC_INSTANCE);
130 MsoResponseWrapper w = createInstance(mso_request, p);
131 // always return OK, the MSO status code is embedded in the body
133 return ( new ResponseEntity<String>(w.getResponse(), HttpStatus.OK) );
140 * @param serviceInstanceId the service instance id
141 * @param request the request
142 * @return the response entity
143 * @throws Exception the exception
145 @RequestMapping(value="/mso_create_vnf_instance/{serviceInstanceId}", method = RequestMethod.POST)
146 public ResponseEntity<String> createVnf(@PathVariable("serviceInstanceId") String serviceInstanceId, HttpServletRequest request) throws Exception {
148 String methodName = "createVnf";
149 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
151 RequestDetails mso_request = retrieveRequestObject (request);
152 String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_VNF_INSTANCE);
154 if ( p == null || p.isEmpty()) {
155 throw new Exception ( "Vnf instance path is not defined");
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);
161 // always return OK, the MSO status code is embedded in the body
163 return ( new ResponseEntity<String>(w.getResponse(), HttpStatus.OK) );
168 * Creates the nw instance.
170 * @param serviceInstanceId the service instance id
171 * @param request the request
172 * @return the response entity
173 * @throws Exception the exception
175 @RequestMapping(value = "/mso_create_nw_instance/{serviceInstanceId}", method = RequestMethod.POST)
176 public ResponseEntity<String> createNwInstance(@PathVariable("serviceInstanceId") String serviceInstanceId, HttpServletRequest request) throws Exception {
178 String methodName = "createNwInstance";
179 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start, serviceInstanceId = " + serviceInstanceId );
181 RequestDetails mso_request = retrieveRequestObject (request);
183 String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_NETWORK_INSTANCE);
185 if ( p == null || p.isEmpty()) {
186 throw new Exception ( "Network instance path is not defined");
188 // /serviceInstances/v2/<serviceInstanceId>/networks/
190 String nw_path = p.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId );
191 MsoResponseWrapper w = createInstance(mso_request, nw_path);
193 // always return OK, the MSO status code is embedded in the body
195 return ( new ResponseEntity<String>(w.getResponse(), HttpStatus.OK) );
200 * Creates the volume group instance.
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
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");
214 RequestDetails mso_request = retrieveRequestObject (request);
215 String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_VOLUME_GROUP_INSTANCE);
217 if ( p == null || p.isEmpty()) {
218 throw new Exception ( "Volume group instance path is not defined");
220 String path = p.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
221 path = path.replaceFirst(VNF_INSTANCE_ID, vnfInstanceId);
223 MsoResponseWrapper w = createInstance(mso_request, path);
225 // always return OK, the MSO status code is embedded in the body
226 return ( new ResponseEntity<String>(w.getResponse(), HttpStatus.OK) );
230 * Creates the vf module instance.
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
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";
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);
247 if ( p == null || p.isEmpty()) {
248 throw new Exception ( "VF module instance path is not defined");
250 // /serviceInstances/v2/<serviceInstanceId>/vnfs/<vnfInstanceId>/vfmodules
251 String path = p.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
252 path = path.replaceFirst(VNF_INSTANCE_ID, vnfInstanceId);
254 MsoResponseWrapper w = createInstance(mso_request, path);
256 // always return OK, the MSO status code is embedded in the body
258 return ( new ResponseEntity<String>(w.getResponse(), HttpStatus.OK) );
262 * Creates the instance.
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
270 protected MsoResponseWrapper createInstance(RequestDetails request, String path) throws Exception {
271 String methodName = "createInstance";
272 logger.debug(dateFormat.format(new Date()) + "<== " + methodName + " start");
275 MsoRestInterfaceIfc restController = MsoRestInterfaceFactory.getInstance();
276 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " calling Post, request = (" + request + ")");
278 RestObject<String> restObjStr = new RestObject<String>();
279 String str = new String();
281 restController.<String>Post(str, request, "", path, restObjStr );
282 MsoResponseWrapper w = MsoUtil.wrapResponse (restObjStr);
284 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " w=" + w.getResponse());
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());
294 * Delete svc instance.
296 * @param serviceInstanceId the service instance id
297 * @param request the request
298 * @return the response entity
299 * @throws Exception the exception
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 {
305 String methodName = "deleteSvcInstance";
306 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
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 );
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
316 return ( new ResponseEntity<String>(w.getResponse(), HttpStatus.OK) );
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
329 @RequestMapping(value = "/mso_delete_vnf_instance/{serviceInstanceId}/vnfs/{vnfInstanceId}", method = RequestMethod.POST)
331 public ResponseEntity<String> deleteVnf(@PathVariable("serviceInstanceId") String serviceInstanceId, @PathVariable("vnfInstanceId") String vnfInstanceId,
332 HttpServletRequest request) throws Exception {
333 String methodName = "deleteVnf";
335 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
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");
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 );
346 // always return OK, the MSO status code is embedded in the body
347 return ( new ResponseEntity<String>(w.getResponse(), HttpStatus.OK) );
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
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 {
367 String methodName = "deleteVfModule";
369 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
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");
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);
381 // always return OK, the MSO status code is embedded in the body
382 return ( new ResponseEntity<String>(w.getResponse(), HttpStatus.OK) );
387 * Delete volume group instance.
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
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 {
401 String methodName = "deleteVolumeGroupInstance";
403 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
404 RequestDetails mso_request = retrieveRequestObject (request);
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");
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);
415 // always return OK, the MSO status code is embedded in the body
416 return ( new ResponseEntity<String>(w.getResponse(), HttpStatus.OK) );
420 * Delete nw instance.
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
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 {
432 String methodName = "deleteNwInstance";
433 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
435 RequestDetails mso_request = retrieveRequestObject (request);
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");
441 // /serviceInstances/v2/<service_instance_id>/networks
442 String path = p.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId );
443 MsoResponseWrapper w = deleteInstance ( mso_request, path + "/" + networkInstanceId);
445 // always return OK, the MSO status code is embedded in the body
446 return ( new ResponseEntity<String>(w.getResponse(), HttpStatus.OK) );
453 * @param request the request
454 * @param path the path
455 * @return the mso response wrapper
456 * @throws Exception the exception
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");
463 MsoRestInterfaceIfc restController = MsoRestInterfaceFactory.getInstance();
464 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " calling Delete, path =[" + path + "]");
466 RestObject<String> restObjStr = new RestObject<String>();
467 String str = new String();
469 restController.<String>Delete(str, request, "", path, restObjStr );
470 MsoResponseWrapper w = MsoUtil.wrapResponse (restObjStr);
472 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " w=" + w.getResponse());
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());
484 * Gets the orchestration request.
486 * @param requestId the request id
487 * @param request the request
488 * @return the orchestration request
489 * @throws Exception the exception
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 {
495 String methodName = "getOrchestrationRequest";
496 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
497 MsoResponseWrapper w = null;
499 MsoRestInterfaceIfc restController = MsoRestInterfaceFactory.getInstance();
500 String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQ);
501 String path = p + "/" + requestId;
503 RestObject<String> restObjStr = new RestObject<String>();
504 String str = new String();
507 restController.<String>Get(str, "", path, restObjStr);
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
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());
519 // always return OK, the MSO status code is embedded in the body
520 return ( new ResponseEntity<String>(w.getResponse(), HttpStatus.OK) );
525 * Gets the orchestration requests.
527 * @param filterString the filter string
528 * @param request the request
529 * @return the orchestration requests
530 * @throws Exception the exception
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 {
536 String methodName = "getOrchestrationRequests";
537 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
538 MsoResponseWrapper w = null;
540 MsoRestInterfaceIfc restController = MsoRestInterfaceFactory.getInstance();
541 String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQS);
542 String path = p + filterString;
544 RestObject<String> restObjStr = new RestObject<String>();
545 String str = new String();
548 restController.<String>Get(str, "", path, restObjStr);
550 w = MsoUtil.wrapResponse (restObjStr);
551 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " w=" + w.getResponse());
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());
558 // always return OK, the MSO status code is embedded in the body
559 return ( new ResponseEntity<String>(w.getResponse(), HttpStatus.OK) );
563 * Gets the orchestration requests for svc instance.
565 * @param svc_instance_id the svc instance id
566 * @return the orchestration requests for svc instance
567 * @throws Exception the exception
569 public MsoResponseWrapper getOrchestrationRequestsForSvcInstance (String svc_instance_id) throws Exception {
571 String methodName = "getOrchestrationRequestsForSvcInstance";
572 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
573 MsoResponseWrapper w = null;
576 MsoRestInterfaceIfc restController = MsoRestInterfaceFactory.getInstance();
577 String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQS);
578 String path = p + svc_instance_id;
580 RestObject<String> restObjStr = new RestObject<String>();
581 String str = new String();
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());
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());
601 * @param response the response
602 * @throws IOException Signals that an I/O exception has occurred.
604 @ExceptionHandler(Exception.class)
605 private void exceptionHandler(Exception e, HttpServletResponse response) throws IOException {
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
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());
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
625 e.printStackTrace(System.err);
627 response.setContentType("application/json; charset=UTF-8");
628 response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
630 ExceptionResponse exceptionResponse = new ExceptionResponse();
631 exceptionResponse.setException(e.getClass().toString().replaceFirst("^.*\\.", ""));
632 exceptionResponse.setMessage(e.getMessage());
634 response.getWriter().write(new ObjectMapper().writeValueAsString(exceptionResponse));
636 response.flushBuffer();
641 * Parses the orchestration requests for svc instance.
643 * @param resp the resp
645 * @throws ParseException the parse exception
646 * @throws Exception the exception
648 @SuppressWarnings("unchecked")
649 public List<JSONObject> parseOrchestrationRequestsForSvcInstance ( ClientResponse resp ) throws org.json.simple.parser.ParseException, Exception {
651 String methodName = "parseOrchestrationRequestsForSvcInstance";
653 ArrayList<JSONObject> json_list = new ArrayList<JSONObject>();
655 String rlist_str = resp.readEntity (String.class);
656 logger.debug (EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + " Response string: " + rlist_str);
658 JSONParser parser = new JSONParser();
660 Object obj = parser.parse(rlist_str);
662 JSONObject jsonObject = (JSONObject) obj;
664 JSONArray requestList = (JSONArray) jsonObject.get("requestList");
666 if ( requestList != null && ! (requestList.isEmpty()) )
667 for ( Object container : requestList) {
669 JSONObject containerJsonObj = (JSONObject) container;
670 //logger.debug(dateFormat.format(new Date()) + "<== " + "." + methodName + " reqJsonObj: " + containerJsonObj.toJSONString());
671 JSONObject reqJsonObj = (JSONObject) containerJsonObj.get("request");
673 //logger.debug(dateFormat.format(new Date()) + "<== " + "." + methodName + " reqJsonObj.requestId: " +
674 // reqJsonObj.get("requestId") );
675 JSONObject result = new JSONObject();
677 result.put("requestId", reqJsonObj.get ("requestId"));
678 if ( reqJsonObj.get("requestType") != null ) {
679 result.put("requestType", (reqJsonObj.get("requestType").toString()));
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")));
688 json_list.add (result);
690 } catch (org.json.simple.parser.ParseException pe) {
691 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + " Parse exception: " + pe.toString());
693 } catch (Exception e) {
694 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + " Exception: " + e.toString());
697 return ( json_list );
701 * Retrieve request object.
703 * @param request the request
704 * @return the request details
705 * @throws Exception the exception
707 public RequestDetails retrieveRequestObject ( HttpServletRequest request ) throws Exception {
709 String methodName = "retrieveRequestObject";
710 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start" );
712 ObjectMapper mapper = new ObjectMapper();
713 //JSON from String to Object
714 RequestDetails mso_request;
716 mso_request = mapper.readValue(request.getInputStream(), RequestDetails.class);
718 catch ( Exception e ) {
719 logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + methodName + " Unable to read json object RequestDetails e=" + e.getMessage());
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");
727 String json_req = mapper.writeValueAsString(mso_request);
728 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " request=[" + json_req + "]");
730 catch ( Exception e ) {
731 logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + methodName + " Unable to convert RequestDetails to json string e=" + e.getMessage());
734 return (mso_request);