2 * ============LICENSE_START=======================================================
\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
11 * http://www.apache.org/licenses/LICENSE-2.0
\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
21 package org.openecomp.vid.controller;
\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
41 import javax.servlet.http.HttpServletRequest;
\r
42 import javax.servlet.http.HttpServletResponse;
\r
44 import org.codehaus.jackson.JsonEncoding;
\r
45 import org.codehaus.jackson.JsonFactory;
\r
46 import org.codehaus.jackson.JsonGenerator;
\r
47 import org.codehaus.jackson.JsonParser;
\r
48 import org.codehaus.jackson.JsonToken;
\r
49 import org.glassfish.jersey.client.ClientResponse;
\r
50 import org.json.simple.JSONArray;
\r
51 import org.json.simple.JSONObject;
\r
52 import org.json.simple.parser.JSONParser;
\r
53 import org.openecomp.vid.domain.mso.CloudConfiguration;
\r
54 import org.openecomp.vid.domain.mso.ModelInfo;
\r
55 import org.openecomp.vid.domain.mso.ModelInfo.ModelType;
\r
56 import org.openecomp.vid.domain.mso.RequestInfo;
\r
57 import org.openecomp.vid.domain.mso.RequestParameters;
\r
58 import org.openecomp.vid.model.ExceptionResponse;
\r
59 import org.openecomp.vid.mso.MsoProperties;
\r
60 import org.openecomp.vid.mso.MsoResponseWrapper;
\r
61 import org.openecomp.vid.mso.MsoRestInterfaceFactory;
\r
62 import org.openecomp.vid.mso.MsoRestInterfaceIfc;
\r
63 import org.openecomp.vid.mso.MsoUtil;
\r
64 import org.openecomp.vid.mso.RestObject;
\r
65 import org.openecomp.vid.mso.rest.RelatedModel;
\r
66 import org.openecomp.vid.mso.rest.RequestDetails;
\r
67 import org.springframework.http.HttpStatus;
\r
68 //import org.springframework.http.ResponseEntity;
\r
69 //import org.springframework.http.RequestEntity;
\r
70 import org.springframework.http.ResponseEntity;
\r
71 import org.springframework.web.bind.annotation.ExceptionHandler;
\r
72 import org.springframework.web.bind.annotation.PathVariable;
\r
73 import org.springframework.web.bind.annotation.RequestBody;
\r
74 import org.springframework.web.bind.annotation.RequestMapping;
\r
75 import org.springframework.web.bind.annotation.RequestMethod;
\r
76 import org.springframework.web.bind.annotation.RestController;
\r
77 import org.springframework.web.servlet.ModelAndView;
\r
79 import org.openecomp.portalsdk.core.controller.RestrictedBaseController;
\r
80 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
\r
81 import org.openecomp.portalsdk.core.util.SystemProperties;
\r
82 import com.fasterxml.jackson.databind.ObjectMapper;
\r
83 import com.fasterxml.jackson.databind.ObjectReader;
\r
84 import com.fasterxml.jackson.databind.DeserializationFeature;
\r
87 * The Class MsoController.
\r
90 @RequestMapping("mso")
\r
91 public class MsoController extends RestrictedBaseController{
\r
93 /** The view name. */
\r
97 EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MsoController.class);
\r
99 /** The Constant dateFormat. */
\r
100 final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS");
\r
102 /** The Constant SVC_INSTANCE_ID. */
\r
103 public final static String SVC_INSTANCE_ID = "<service_instance_id>";
\r
105 /** The Constant VNF_INSTANCE_ID. */
\r
106 public final static String VNF_INSTANCE_ID = "<vnf_instance_id>";
\r
111 * @param request the request
\r
112 * @return the model and view
\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
123 * @see org.openecomp.portalsdk.core.controller.RestrictedBaseController#getViewName()
\r
125 public String getViewName() {
\r
131 * @see org.openecomp.portalsdk.core.controller.RestrictedBaseController#setViewName(java.lang.String)
\r
133 public void setViewName(String viewName) {
\r
134 this.viewName = viewName;
\r
139 * Creates the svc instance.
\r
141 * @param request the request
\r
142 * @return the response entity
\r
143 * @throws Exception the exception
\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
149 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start" );
\r
151 // mso_request = retrieveRequestObject (request, mso_request);
\r
153 String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_SVC_INSTANCE);
\r
155 MsoResponseWrapper w = createInstance(mso_request, p);
\r
156 // always return OK, the MSO status code is embedded in the body
\r
158 return ( new ResponseEntity<String>(w.getResponse(), HttpStatus.OK) );
\r
165 * @param serviceInstanceId the service instance id
\r
166 * @param request the request
\r
167 * @return the response entity
\r
168 * @throws Exception the exception
\r
170 @RequestMapping(value="/mso_create_vnf_instance/{serviceInstanceId}", method = RequestMethod.POST)
\r
171 public ResponseEntity<String> createVnf(@PathVariable("serviceInstanceId") String serviceInstanceId, HttpServletRequest request, @RequestBody RequestDetails mso_request) throws Exception {
\r
173 String methodName = "createVnf";
\r
174 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
\r
176 //RequestDetails mso_request = retrieveRequestObject (request);
\r
177 String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_VNF_INSTANCE);
\r
179 if ( p == null || p.isEmpty()) {
\r
180 throw new Exception ( "Vnf instance path is not defined");
\r
182 // /serviceInstances/v2/<service_instance_id>/vnfs
\r
183 String vnf_path = p.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId );
\r
184 MsoResponseWrapper w = createInstance(mso_request, vnf_path);
\r
186 // always return OK, the MSO status code is embedded in the body
\r
188 return ( new ResponseEntity<String>(w.getResponse(), HttpStatus.OK) );
\r
193 * Creates the nw instance.
\r
195 * @param serviceInstanceId the service instance id
\r
196 * @param request the request
\r
197 * @return the response entity
\r
198 * @throws Exception the exception
\r
200 @RequestMapping(value = "/mso_create_nw_instance/{serviceInstanceId}", method = RequestMethod.POST)
\r
201 public ResponseEntity<String> createNwInstance(@PathVariable("serviceInstanceId") String serviceInstanceId, HttpServletRequest request, @RequestBody RequestDetails mso_request) throws Exception {
\r
203 String methodName = "createNwInstance";
\r
204 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start, serviceInstanceId = " + serviceInstanceId );
\r
206 //RequestDetails mso_request = retrieveRequestObject (request);
\r
208 String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_NETWORK_INSTANCE);
\r
210 if ( p == null || p.isEmpty()) {
\r
211 throw new Exception ( "Network instance path is not defined");
\r
213 // /serviceInstances/v2/<serviceInstanceId>/networks/
\r
215 String nw_path = p.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId );
\r
216 MsoResponseWrapper w = createInstance(mso_request, nw_path);
\r
218 // always return OK, the MSO status code is embedded in the body
\r
220 return ( new ResponseEntity<String>(w.getResponse(), HttpStatus.OK) );
\r
225 * Creates the volume group instance.
\r
227 * @param serviceInstanceId the service instance id
\r
228 * @param vnfInstanceId the vnf instance id
\r
229 * @param request the request
\r
230 * @return the response entity
\r
231 * @throws Exception the exception
\r
233 @RequestMapping(value = "/mso_create_volumegroup_instance/{serviceInstanceId}/vnfs/{vnfInstanceId}", method = RequestMethod.POST)
\r
234 public ResponseEntity<String> createVolumeGroupInstance(@PathVariable("serviceInstanceId") String serviceInstanceId, @PathVariable("vnfInstanceId") String vnfInstanceId,
\r
235 HttpServletRequest request, @RequestBody RequestDetails mso_request) throws Exception {
\r
236 String methodName = "createVolumeGroupInstance";
\r
237 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
\r
239 //RequestDetails mso_request = retrieveRequestObject (request);
\r
240 String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_VOLUME_GROUP_INSTANCE);
\r
242 if ( p == null || p.isEmpty()) {
\r
243 throw new Exception ( "Volume group instance path is not defined");
\r
245 String path = p.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
\r
246 path = path.replaceFirst(VNF_INSTANCE_ID, vnfInstanceId);
\r
248 MsoResponseWrapper w = createInstance(mso_request, path);
\r
250 // always return OK, the MSO status code is embedded in the body
\r
251 return ( new ResponseEntity<String>(w.getResponse(), HttpStatus.OK) );
\r
255 * Creates the vf module instance.
\r
257 * @param serviceInstanceId the service instance id
\r
258 * @param vnfInstanceId the vnf instance id
\r
259 * @param request the request
\r
260 * @return the response entity
\r
261 * @throws Exception the exception
\r
263 @RequestMapping(value = "/mso_create_vfmodule_instance/{serviceInstanceId}/vnfs/{vnfInstanceId}", method = RequestMethod.POST)
\r
264 public ResponseEntity<String> createVfModuleInstance(@PathVariable("serviceInstanceId") String serviceInstanceId,
\r
265 @PathVariable("vnfInstanceId") String vnfInstanceId, HttpServletRequest request, @RequestBody RequestDetails mso_request) throws Exception {
\r
266 String methodName = "createVfModuleInstance";
\r
268 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
\r
269 //RequestDetails mso_request = retrieveRequestObject (request);
\r
270 String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_VF_MODULE_INSTANCE);
\r
272 if ( p == null || p.isEmpty()) {
\r
273 throw new Exception ( "VF module instance path is not defined");
\r
275 // /serviceInstances/v2/<serviceInstanceId>/vnfs/<vnfInstanceId>/vfmodules
\r
276 String path = p.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
\r
277 path = path.replaceFirst(VNF_INSTANCE_ID, vnfInstanceId);
\r
279 MsoResponseWrapper w = createInstance(mso_request, path);
\r
281 // always return OK, the MSO status code is embedded in the body
\r
283 return ( new ResponseEntity<String>(w.getResponse(), HttpStatus.OK) );
\r
287 * Creates the instance.
\r
289 * @param request the request
\r
290 * @param path the path
\r
291 * @return the mso response wrapper
\r
292 * @throws ClientHandlerException the client handler exception
\r
293 * @throws Exception the exception
\r
295 protected MsoResponseWrapper createInstance(RequestDetails request, String path) throws Exception {
\r
296 String methodName = "createInstance";
\r
297 logger.debug(dateFormat.format(new Date()) + "<== " + methodName + " start");
\r
300 MsoRestInterfaceIfc restController = MsoRestInterfaceFactory.getInstance();
\r
301 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " calling Post, request = (" + request + ")");
\r
303 RestObject<String> restObjStr = new RestObject<String>();
\r
304 String str = new String();
\r
305 restObjStr.set(str);
\r
306 restController.<String>Post(str, request, "", path, restObjStr );
\r
307 MsoResponseWrapper w = MsoUtil.wrapResponse (restObjStr);
\r
309 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " w=" + w.getResponse());
\r
311 } catch (Exception e) {
\r
312 logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
\r
313 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
\r
319 * Delete svc instance.
\r
321 * @param serviceInstanceId the service instance id
\r
322 * @param request the request
\r
323 * @return the response entity
\r
324 * @throws Exception the exception
\r
326 @RequestMapping(value = "/mso_delete_svc_instance/{serviceInstanceId}", method = RequestMethod.POST)
\r
327 public ResponseEntity<String> deleteSvcInstance(@PathVariable("serviceInstanceId") String serviceInstanceId,
\r
328 HttpServletRequest request, @RequestBody RequestDetails mso_request) throws Exception {
\r
330 String methodName = "deleteSvcInstance";
\r
331 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
\r
333 //RequestDetails mso_request = retrieveRequestObject (request);
\r
334 String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_SVC_INSTANCE);
\r
335 String path = p + "/" + serviceInstanceId;
\r
336 MsoResponseWrapper w = deleteInstance ( mso_request, path );
\r
338 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " w=" + w.getResponse());
\r
339 // always return OK, the MSO status code is embedded in the body
\r
341 return ( new ResponseEntity<String>(w.getResponse(), HttpStatus.OK) );
\r
348 * @param serviceInstanceId the service instance id
\r
349 * @param vnfInstanceId the vnf instance id
\r
350 * @param request the request
\r
351 * @return the response entity
\r
352 * @throws Exception the exception
\r
354 @RequestMapping(value = "/mso_delete_vnf_instance/{serviceInstanceId}/vnfs/{vnfInstanceId}", method = RequestMethod.POST)
\r
356 public ResponseEntity<String> deleteVnf(@PathVariable("serviceInstanceId") String serviceInstanceId, @PathVariable("vnfInstanceId") String vnfInstanceId,
\r
357 HttpServletRequest request, @RequestBody RequestDetails mso_request) throws Exception {
\r
358 String methodName = "deleteVnf";
\r
360 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
\r
362 //RequestDetails mso_request = retrieveRequestObject (request);
\r
363 String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_VNF_INSTANCE);
\r
364 if ( p == null || p.isEmpty()) {
\r
365 throw new Exception ( "Vnf instance path is not defined");
\r
367 // /serviceInstances/v2/<service_instance_id>/vnfs/
\r
368 String vnf_path = p.replaceFirst(SVC_INSTANCE_ID, vnfInstanceId );
\r
369 MsoResponseWrapper w = deleteInstance ( mso_request, vnf_path + "/" + vnfInstanceId );
\r
371 // always return OK, the MSO status code is embedded in the body
\r
372 return ( new ResponseEntity<String>(w.getResponse(), HttpStatus.OK) );
\r
377 * Delete vf module.
\r
379 * @param serviceInstanceId the service instance id
\r
380 * @param vnfInstanceId the vnf instance id
\r
381 * @param vfModuleId the vf module id
\r
382 * @param request the request
\r
383 * @return the response entity
\r
384 * @throws Exception the exception
\r
386 //mso_delete_vf_module/bc305d54-75b4-431b-adb2-eb6b9e546014/vnfs/fe9000-0009-9999/vfmodules/abeeee-abeeee-abeeee
\r
387 @RequestMapping(value = "/mso_delete_vfmodule_instance/{serviceInstanceId}/vnfs/{vnfInstanceId}/vfModules/{vfModuleId}", method = RequestMethod.POST)
\r
388 public ResponseEntity<String> deleteVfModule (
\r
389 @PathVariable("serviceInstanceId") String serviceInstanceId, @PathVariable("vnfInstanceId") String vnfInstanceId,
\r
390 @PathVariable("vfModuleId") String vfModuleId, HttpServletRequest request, @RequestBody RequestDetails mso_request) throws Exception {
\r
392 String methodName = "deleteVfModule";
\r
394 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
\r
396 //RequestDetails mso_request = new RequestDetails();
\r
397 //mso_request = retrieveRequestObject (request);
\r
398 String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_VF_MODULE_INSTANCE);
\r
399 if ( p == null || p.isEmpty()) {
\r
400 throw new Exception ( "VF Module instance path is not defined");
\r
402 // /serviceInstances/v2/<serviceInstanceId>/vnfs/<vnfInstanceId>/vfmodules
\r
403 String path = p.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId );
\r
404 path = path.replaceFirst(VNF_INSTANCE_ID, vnfInstanceId );
\r
405 MsoResponseWrapper w = deleteInstance ( mso_request, path + "/" + vfModuleId);
\r
407 // always return OK, the MSO status code is embedded in the body
\r
408 return ( new ResponseEntity<String>(w.getResponse(), HttpStatus.OK) );
\r
413 * Delete volume group instance.
\r
415 * @param serviceInstanceId the service instance id
\r
416 * @param vnfInstanceId the vnf instance id
\r
417 * @param volumeGroupId the volume group id
\r
418 * @param request the request
\r
419 * @return the response entity
\r
420 * @throws Exception the exception
\r
422 @RequestMapping(value = "/mso_delete_volumegroup_instance/{serviceInstanceId}/vnfs/{vnfInstanceId}/volumeGroups/{volumeGroupId}", method = RequestMethod.POST)
\r
423 public ResponseEntity<String> deleteVolumeGroupInstance (
\r
424 @PathVariable("serviceInstanceId") String serviceInstanceId, @PathVariable("vnfInstanceId") String vnfInstanceId, @PathVariable("volumeGroupId") String volumeGroupId,
\r
425 HttpServletRequest request, @RequestBody RequestDetails mso_request) throws Exception {
\r
427 String methodName = "deleteVolumeGroupInstance";
\r
429 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
\r
430 //RequestDetails mso_request = retrieveRequestObject (request);
\r
432 String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_VOLUME_GROUP_INSTANCE);
\r
433 if ( p == null || p.isEmpty()) {
\r
434 throw new Exception ( "Volume group instance path is not defined");
\r
436 // /serviceInstances/v2/{serviceInstanceId}/volumeGroups
\r
437 String path = p.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId );
\r
438 path = path.replaceFirst(VNF_INSTANCE_ID, vnfInstanceId );
\r
439 MsoResponseWrapper w = deleteInstance ( mso_request, path + "/" + volumeGroupId);
\r
441 // always return OK, the MSO status code is embedded in the body
\r
442 return ( new ResponseEntity<String>(w.getResponse(), HttpStatus.OK) );
\r
446 * Delete nw instance.
\r
448 * @param serviceInstanceId the service instance id
\r
449 * @param networkInstanceId the network instance id
\r
450 * @param request the request
\r
451 * @return the response entity
\r
452 * @throws Exception the exception
\r
454 @RequestMapping(value = "/mso_delete_nw_instance/{serviceInstanceId}/networks/{networkInstanceId}", method = RequestMethod.POST)
\r
455 public ResponseEntity<String> deleteNwInstance(@PathVariable("serviceInstanceId") String serviceInstanceId,
\r
456 @PathVariable("networkInstanceId") String networkInstanceId, HttpServletRequest request, @RequestBody RequestDetails mso_request) throws Exception {
\r
458 String methodName = "deleteNwInstance";
\r
459 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
\r
461 //RequestDetails mso_request = retrieveRequestObject (request);
\r
463 String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_NETWORK_INSTANCE);
\r
464 if ( p == null || p.isEmpty()) {
\r
465 throw new Exception ( "Network instance path is not defined");
\r
467 // /serviceInstances/v2/<service_instance_id>/networks
\r
468 String path = p.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId );
\r
469 MsoResponseWrapper w = deleteInstance ( mso_request, path + "/" + networkInstanceId);
\r
471 // always return OK, the MSO status code is embedded in the body
\r
472 return ( new ResponseEntity<String>(w.getResponse(), HttpStatus.OK) );
\r
479 * @param request the request
\r
480 * @param path the path
\r
481 * @return the mso response wrapper
\r
482 * @throws Exception the exception
\r
484 protected MsoResponseWrapper deleteInstance(RequestDetails request, String path) throws Exception {
\r
485 String methodName = "deleteInstance";
\r
486 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
\r
489 MsoRestInterfaceIfc restController = MsoRestInterfaceFactory.getInstance();
\r
490 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " calling Delete, path =[" + path + "]");
\r
492 RestObject<String> restObjStr = new RestObject<String>();
\r
493 String str = new String();
\r
494 restObjStr.set(str);
\r
495 restController.<String>Delete(str, request, "", path, restObjStr );
\r
496 MsoResponseWrapper w = MsoUtil.wrapResponse (restObjStr);
\r
498 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " w=" + w.getResponse());
\r
501 } catch (Exception e) {
\r
502 logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
\r
503 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
\r
510 * Gets the orchestration request.
\r
512 * @param requestId the request id
\r
513 * @param request the request
\r
514 * @return the orchestration request
\r
515 * @throws Exception the exception
\r
517 @RequestMapping(value = "/mso_get_orch_req/{requestId}", method = RequestMethod.GET)
\r
518 public ResponseEntity<String> getOrchestrationRequest(@PathVariable("requestId") String requestId,
\r
519 HttpServletRequest request) throws Exception {
\r
521 String methodName = "getOrchestrationRequest";
\r
522 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
\r
523 MsoResponseWrapper w = null;
\r
525 MsoRestInterfaceIfc restController = MsoRestInterfaceFactory.getInstance();
\r
526 String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQ);
\r
527 String path = p + "/" + requestId;
\r
529 RestObject<String> restObjStr = new RestObject<String>();
\r
530 String str = new String();
\r
531 restObjStr.set(str);
\r
533 restController.<String>Get(str, "", path, restObjStr);
\r
535 w = MsoUtil.wrapResponse (restObjStr);
\r
536 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " w=" + w.getResponse());
\r
537 // always return OK, the MSO status code is embedded in the body
\r
539 } catch (Exception e) {
\r
540 logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
\r
541 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
\r
544 // always return OK, the MSO status code is embedded in the body
\r
545 return ( new ResponseEntity<String>(w.getResponse(), HttpStatus.OK) );
\r
550 * Gets the orchestration requests.
\r
552 * @param filterString the filter string
\r
553 * @param request the request
\r
554 * @return the orchestration requests
\r
555 * @throws Exception the exception
\r
557 @RequestMapping(value = "/mso_get_orch_reqs/{filterString}", method = RequestMethod.GET)
\r
558 public ResponseEntity<String> getOrchestrationRequests(@PathVariable("filterString") String filterString,
\r
559 HttpServletRequest request) throws Exception {
\r
561 String methodName = "getOrchestrationRequests";
\r
562 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
\r
563 MsoResponseWrapper w = null;
\r
565 MsoRestInterfaceIfc restController = MsoRestInterfaceFactory.getInstance();
\r
566 String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQS);
\r
567 String path = p + filterString;
\r
569 RestObject<String> restObjStr = new RestObject<String>();
\r
570 String str = new String();
\r
571 restObjStr.set(str);
\r
573 restController.<String>Get(str, "", path, restObjStr);
\r
575 w = MsoUtil.wrapResponse (restObjStr);
\r
576 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " w=" + w.getResponse());
\r
577 } catch (Exception e) {
\r
578 logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
\r
579 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
\r
582 // always return OK, the MSO status code is embedded in the body
\r
583 return ( new ResponseEntity<String>(w.getResponse(), HttpStatus.OK) );
\r
587 * Gets the orchestration requests for svc instance.
\r
589 * @param svc_instance_id the svc instance id
\r
590 * @return the orchestration requests for svc instance
\r
591 * @throws Exception the exception
\r
593 public MsoResponseWrapper getOrchestrationRequestsForSvcInstance (String svc_instance_id) throws Exception {
\r
595 String methodName = "getOrchestrationRequestsForSvcInstance";
\r
596 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
\r
597 MsoResponseWrapper w = null;
\r
600 MsoRestInterfaceIfc restController = MsoRestInterfaceFactory.getInstance();
\r
601 String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQS);
\r
602 String path = p + svc_instance_id;
\r
604 RestObject<String> restObjStr = new RestObject<String>();
\r
605 String str = new String();
\r
606 restObjStr.set(str);
\r
608 restController.<String>Get(str, "", path, restObjStr);
\r
609 w = MsoUtil.wrapResponse (restObjStr);
\r
610 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " w=" + w.getResponse());
\r
612 } catch (Exception e) {
\r
613 logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
\r
614 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
\r
621 * Exception handler.
\r
624 * @param response the response
\r
625 * @throws IOException Signals that an I/O exception has occurred.
\r
627 @ExceptionHandler(Exception.class)
\r
628 private void exceptionHandler(Exception e, HttpServletResponse response) throws IOException {
\r
631 * The following "logger.error" lines "should" be sufficient for logging the exception.
\r
632 * However, the console output in my Eclipse environment is NOT showing ANY of the
\r
633 * logger statements in this class. Thus the temporary "e.printStackTrace" statement
\r
634 * is also included.
\r
637 String methodName = "exceptionHandler";
\r
638 logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
\r
639 StringWriter sw = new StringWriter();
\r
640 e.printStackTrace(new PrintWriter(sw));
\r
641 logger.error(EELFLoggerDelegate.errorLogger, sw.toString());
\r
644 * Temporary - IF the above mentioned "logger.error" glitch is resolved ...
\r
645 * this statement could be removed since it would then likely result in duplicate
\r
648 e.printStackTrace(System.err);
\r
650 response.setContentType("application/json; charset=UTF-8");
\r
651 response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
\r
653 ExceptionResponse exceptionResponse = new ExceptionResponse();
\r
654 exceptionResponse.setException(e.getClass().toString().replaceFirst("^.*\\.", ""));
\r
655 exceptionResponse.setMessage(e.getMessage());
\r
657 response.getWriter().write(new ObjectMapper().writeValueAsString(exceptionResponse));
\r
659 response.flushBuffer();
\r
664 * Parses the orchestration requests for svc instance.
\r
666 * @param resp the resp
\r
668 * @throws ParseException the parse exception
\r
669 * @throws Exception the exception
\r
671 @SuppressWarnings("unchecked")
\r
672 public List<JSONObject> parseOrchestrationRequestsForSvcInstance ( ClientResponse resp ) throws org.json.simple.parser.ParseException, Exception {
\r
674 String methodName = "parseOrchestrationRequestsForSvcInstance";
\r
676 ArrayList<JSONObject> json_list = new ArrayList<JSONObject>();
\r
678 String rlist_str = resp.readEntity (String.class);
\r
679 logger.debug (EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + " Response string: " + rlist_str);
\r
681 JSONParser parser = new JSONParser();
\r
683 Object obj = parser.parse(rlist_str);
\r
685 JSONObject jsonObject = (JSONObject) obj;
\r
687 JSONArray requestList = (JSONArray) jsonObject.get("requestList");
\r
689 if ( requestList != null && ! (requestList.isEmpty()) )
\r
690 for ( Object container : requestList) {
\r
692 JSONObject containerJsonObj = (JSONObject) container;
\r
693 //logger.debug(dateFormat.format(new Date()) + "<== " + "." + methodName + " reqJsonObj: " + containerJsonObj.toJSONString());
\r
694 JSONObject reqJsonObj = (JSONObject) containerJsonObj.get("request");
\r
696 //logger.debug(dateFormat.format(new Date()) + "<== " + "." + methodName + " reqJsonObj.requestId: " +
\r
697 // reqJsonObj.get("requestId") );
\r
698 JSONObject result = new JSONObject();
\r
700 result.put("requestId", reqJsonObj.get ("requestId"));
\r
701 if ( reqJsonObj.get("requestType") != null ) {
\r
702 result.put("requestType", (reqJsonObj.get("requestType").toString()));
\r
704 JSONObject req_status = (JSONObject)reqJsonObj.get("requestStatus");
\r
705 if ( req_status != null ) {
\r
706 result.put("timestamp", (req_status.get("timestamp")));
\r
707 result.put("requestState", (req_status.get("requestState")));
\r
708 result.put("statusMessage", (req_status.get("statusMessage")));
\r
709 result.put("percentProgress", (req_status.get("percentProgress")));
\r
711 json_list.add (result);
\r
713 } catch (org.json.simple.parser.ParseException pe) {
\r
714 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + " Parse exception: " + pe.toString());
\r
716 } catch (Exception e) {
\r
717 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + " Exception: " + e.toString());
\r
720 return ( json_list );
\r
724 * Retrieve request object.
\r
726 * @param request the request
\r
727 * @return the request details
\r
728 * @throws Exception the exception
\r
730 public RequestDetails retrieveRequestObject ( HttpServletRequest request, @RequestBody RequestDetails mso_request ) throws Exception {
\r
732 String methodName = "retrieveRequestObject";
\r
733 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start" );
\r
735 ObjectMapper mapper = new ObjectMapper();
\r
736 //JSON from String to Object
\r
737 //RequestDetails mso_request;
\r
740 //mso_request = new RequestDetails();
\r
741 //mso_request = mapper.readValue(request.getInputStream(), RequestDetails.class);
\r
743 catch ( Exception e ) {
\r
744 logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + methodName + " Unable to read json object RequestDetails e=" + e.getMessage());
\r
747 if ( mso_request == null) {
\r
748 logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + methodName + " mso_request is null");
\r
749 throw new Exception ("RequestDetails is missing");
\r
752 String json_req = mapper.writeValueAsString(mso_request);
\r
753 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " request=[" + json_req + "]");
\r
755 catch ( Exception e ) {
\r
756 logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + methodName + " Unable to convert RequestDetails to json string e=" + e.getMessage());
\r
759 return (mso_request);
\r