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 com.fasterxml.jackson.databind.ObjectMapper;
\r
25 import org.glassfish.jersey.client.ClientResponse;
\r
26 import org.json.simple.JSONArray;
\r
27 import org.json.simple.JSONObject;
\r
28 import org.json.simple.parser.JSONParser;
\r
29 import org.openecomp.portalsdk.core.controller.RestrictedBaseController;
\r
30 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
\r
31 import org.openecomp.portalsdk.core.util.SystemProperties;
\r
32 import org.openecomp.vid.model.ExceptionResponse;
\r
33 import org.openecomp.vid.mso.*;
\r
34 import org.openecomp.vid.mso.rest.RequestDetails;
\r
35 import org.openecomp.vid.roles.RoleProvider;
\r
36 import org.openecomp.vid.roles.RoleValidator;
\r
37 import org.springframework.http.HttpStatus;
\r
38 import org.springframework.http.ResponseEntity;
\r
39 import org.springframework.web.bind.annotation.*;
\r
41 import javax.servlet.http.HttpServletRequest;
\r
42 import javax.servlet.http.HttpServletResponse;
\r
43 import javax.servlet.http.HttpSession;
\r
44 import java.io.IOException;
\r
45 import java.io.PrintWriter;
\r
46 import java.io.StringWriter;
\r
47 import java.text.DateFormat;
\r
48 import java.text.SimpleDateFormat;
\r
49 import java.util.ArrayList;
\r
50 import java.util.Date;
\r
51 import java.util.List;
\r
52 import java.util.Map;
\r
55 * The Class MsoController.
\r
58 @RequestMapping("mso")
\r
59 public class MsoController extends RestrictedBaseController {
\r
62 * The Constant SVC_INSTANCE_ID.
\r
64 public final static String SVC_INSTANCE_ID = "<service_instance_id>";
\r
66 * The Constant VNF_INSTANCE_ID.
\r
68 public final static String VNF_INSTANCE_ID = "<vnf_instance_id>";
\r
70 * The Constant dateFormat.
\r
72 final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS");
\r
80 EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MsoController.class);
\r
85 * @param request the request
\r
86 * @return the model and view
\r
88 public ModelAndView welcome(HttpServletRequest request) {
\r
89 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== MsoController welcome start");
\r
90 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + " MSO_SERVER_URL=" +
\r
91 SystemProperties.getProperty(MsoProperties.MSO_SERVER_URL) );
\r
92 return new ModelAndView(getViewName());
\r
97 * @see org.openecomp.portalsdk.core.controller.RestrictedBaseController#getViewName()
\r
99 public String getViewName() {
\r
105 * @see org.openecomp.portalsdk.core.controller.RestrictedBaseController#setViewName(java.lang.String)
\r
107 public void setViewName(String viewName) {
\r
108 this.viewName = viewName;
\r
113 * Creates the svc instance.
\r
115 * @param request the request
\r
116 * @return the response entity
\r
117 * @throws Exception the exception
\r
119 @RequestMapping(value = "/mso_create_svc_instance", method = RequestMethod.POST)
\r
120 public ResponseEntity<String> createSvcInstance(HttpServletRequest request, @RequestBody RequestDetails mso_request) throws Exception {
\r
123 String methodName = "createSvcInstance";
\r
125 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
\r
127 if (!userIsPermmited(request, mso_request)) {
\r
128 return new ResponseEntity<String>(HttpStatus.FORBIDDEN);
\r
130 // mso_request = retrieveRequestObject (request, mso_request);
\r
132 String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_SVC_INSTANCE);
\r
133 String userId = "";
\r
134 HttpSession session = request.getSession();
\r
135 System.out.println((new ObjectMapper().writeValueAsString(session.getAttribute("roles"))));
\r
136 MsoResponseWrapper w = createInstance(mso_request, p);
\r
137 return (new ResponseEntity<String>(w.getResponse(), HttpStatus.OK));
\r
138 // always return OK, the MSO status code is embedded in the body
\r
143 private boolean userIsPermmited(HttpServletRequest request, RequestDetails mso_request) {
\r
145 RoleValidator roleValidator = new RoleValidator(new RoleProvider().getUserRoles(request));
\r
146 boolean isPermitted = roleValidator.isMsoRequestValid(mso_request);
\r
147 if (!isPermitted) {
\r
157 * @param serviceInstanceId the service instance id
\r
158 * @param request the request
\r
159 * @return the response entity
\r
160 * @throws Exception the exception
\r
162 @RequestMapping(value = "/mso_create_vnf_instance/{serviceInstanceId}", method = RequestMethod.POST)
\r
163 public ResponseEntity<String> createVnf(@PathVariable("serviceInstanceId") String serviceInstanceId, HttpServletRequest request, @RequestBody RequestDetails mso_request) throws Exception {
\r
164 // if (!userIsPermmited(request, mso_request)) {
\r
165 String instanceId = (String) ((Map)((Map)((ArrayList)((Map) mso_request.getAdditionalProperties().get("requestDetails")).get("relatedInstanceList")).get(0)).get("relatedInstance")).get("instanceId");
\r
166 ResponseEntity<String> a = new AaiController(request.getServletContext()).doGetServiceInstance(instanceId,"Service Instance id");
\r
167 // return new ResponseEntity<String>(HttpStatus.FORBIDDEN);
\r
169 String methodName = "createVnf";
\r
170 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
\r
172 //RequestDetails mso_request = retrieveRequestObject (request);
\r
173 String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_VNF_INSTANCE);
\r
175 if (p == null || p.isEmpty()) {
\r
176 throw new Exception("Vnf instance path is not defined");
\r
178 // /serviceInstances/v2/<service_instance_id>/vnfs
\r
179 String vnf_path = p.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
\r
180 MsoResponseWrapper w = createInstance(mso_request, vnf_path);
\r
182 // always return OK, the MSO status code is embedded in the body
\r
184 return (new ResponseEntity<String>(w.getResponse(), HttpStatus.OK));
\r
189 * Creates the nw instance.
\r
191 * @param serviceInstanceId the service instance id
\r
192 * @param request the request
\r
193 * @return the response entity
\r
194 * @throws Exception the exception
\r
196 @RequestMapping(value = "/mso_create_nw_instance/{serviceInstanceId}", method = RequestMethod.POST)
\r
197 public ResponseEntity<String> createNwInstance(@PathVariable("serviceInstanceId") String serviceInstanceId, HttpServletRequest request, @RequestBody RequestDetails mso_request) throws Exception {
\r
199 String methodName = "createNwInstance";
\r
200 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start, serviceInstanceId = " + serviceInstanceId);
\r
202 //RequestDetails mso_request = retrieveRequestObject (request);
\r
204 String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_NETWORK_INSTANCE);
\r
206 if (p == null || p.isEmpty()) {
\r
207 throw new Exception("Network instance path is not defined");
\r
209 // /serviceInstances/v2/<serviceInstanceId>/networks/
\r
211 String nw_path = p.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
\r
212 MsoResponseWrapper w = createInstance(mso_request, nw_path);
\r
214 // always return OK, the MSO status code is embedded in the body
\r
216 return (new ResponseEntity<String>(w.getResponse(), HttpStatus.OK));
\r
221 * Creates the volume group instance.
\r
223 * @param serviceInstanceId the service instance id
\r
224 * @param vnfInstanceId the vnf instance id
\r
225 * @param request the request
\r
226 * @return the response entity
\r
227 * @throws Exception the exception
\r
229 @RequestMapping(value = "/mso_create_volumegroup_instance/{serviceInstanceId}/vnfs/{vnfInstanceId}", method = RequestMethod.POST)
\r
230 public ResponseEntity<String> createVolumeGroupInstance(@PathVariable("serviceInstanceId") String serviceInstanceId, @PathVariable("vnfInstanceId") String vnfInstanceId,
\r
231 HttpServletRequest request, @RequestBody RequestDetails mso_request) throws Exception {
\r
232 String methodName = "createVolumeGroupInstance";
\r
233 if (!userIsPermmited(request, mso_request)) {
\r
234 return new ResponseEntity<String>(HttpStatus.FORBIDDEN);
\r
236 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
\r
238 //RequestDetails mso_request = retrieveRequestObject (request);
\r
239 String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_VOLUME_GROUP_INSTANCE);
\r
241 if (p == null || p.isEmpty()) {
\r
242 throw new Exception("Volume group instance path is not defined");
\r
244 String path = p.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
\r
245 path = path.replaceFirst(VNF_INSTANCE_ID, vnfInstanceId);
\r
247 MsoResponseWrapper w = createInstance(mso_request, path);
\r
249 // always return OK, the MSO status code is embedded in the body
\r
250 return (new ResponseEntity<String>(w.getResponse(), HttpStatus.OK));
\r
254 * Creates the vf module instance.
\r
256 * @param serviceInstanceId the service instance id
\r
257 * @param vnfInstanceId the vnf instance id
\r
258 * @param request the request
\r
259 * @return the response entity
\r
260 * @throws Exception the exception
\r
262 @RequestMapping(value = "/mso_create_vfmodule_instance/{serviceInstanceId}/vnfs/{vnfInstanceId}", method = RequestMethod.POST)
\r
263 public ResponseEntity<String> createVfModuleInstance(@PathVariable("serviceInstanceId") String serviceInstanceId,
\r
264 @PathVariable("vnfInstanceId") String vnfInstanceId, HttpServletRequest request, @RequestBody RequestDetails mso_request) throws Exception {
\r
265 String methodName = "createVfModuleInstance";
\r
267 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
\r
268 if (!userIsPermmited(request, mso_request)) {
\r
269 return new ResponseEntity<String>(HttpStatus.FORBIDDEN);
\r
271 //RequestDetails mso_request = retrieveRequestObject (request);
\r
272 String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_VF_MODULE_INSTANCE);
\r
274 if (p == null || p.isEmpty()) {
\r
275 throw new Exception("VF module instance path is not defined");
\r
277 // /serviceInstances/v2/<serviceInstanceId>/vnfs/<vnfInstanceId>/vfmodules
\r
278 String path = p.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
\r
279 path = path.replaceFirst(VNF_INSTANCE_ID, vnfInstanceId);
\r
281 MsoResponseWrapper w = createInstance(mso_request, path);
\r
283 // always return OK, the MSO status code is embedded in the body
\r
285 return (new ResponseEntity<String>(w.getResponse(), HttpStatus.OK));
\r
289 * Creates the instance.
\r
291 * @param request the request
\r
292 * @param path the path
\r
293 * @return the mso response wrapper
\r
294 * @throws Exception the exception
\r
296 protected MsoResponseWrapper createInstance(RequestDetails request, String path) throws Exception {
\r
297 String methodName = "createInstance";
\r
298 logger.debug(dateFormat.format(new Date()) + "<== " + methodName + " start");
\r
301 MsoRestInterfaceIfc restController = MsoRestInterfaceFactory.getInstance();
\r
302 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " calling Post, request = (" + request + ")");
\r
304 RestObject<String> restObjStr = new RestObject<String>();
\r
305 String str = new String();
\r
306 restObjStr.set(str);
\r
307 restController.<String>Post(str, request, "", path, restObjStr);
\r
308 MsoResponseWrapper w = MsoUtil.wrapResponse(restObjStr);
\r
310 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " w=" + w.getResponse());
\r
312 } catch (Exception e) {
\r
313 logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
\r
314 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
\r
320 * Delete svc instance.
\r
322 * @param serviceInstanceId the service instance id
\r
323 * @param request the request
\r
324 * @return the response entity
\r
325 * @throws Exception the exception
\r
327 @RequestMapping(value = "/mso_delete_svc_instance/{serviceInstanceId}", method = RequestMethod.POST)
\r
328 public ResponseEntity<String> deleteSvcInstance(@PathVariable("serviceInstanceId") String serviceInstanceId,
\r
329 HttpServletRequest request, @RequestBody RequestDetails mso_request) throws Exception {
\r
331 String methodName = "deleteSvcInstance";
\r
332 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
\r
334 //RequestDetails mso_request = retrieveRequestObject (request);
\r
335 String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_SVC_INSTANCE);
\r
336 String path = p + "/" + serviceInstanceId;
\r
337 MsoResponseWrapper w = deleteInstance(mso_request, path);
\r
339 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " w=" + w.getResponse());
\r
340 // always return OK, the MSO status code is embedded in the body
\r
342 return (new ResponseEntity<String>(w.getResponse(), HttpStatus.OK));
\r
349 * @param serviceInstanceId the service instance id
\r
350 * @param vnfInstanceId the vnf instance id
\r
351 * @param request the request
\r
352 * @return the response entity
\r
353 * @throws Exception the exception
\r
355 @RequestMapping(value = "/mso_delete_vnf_instance/{serviceInstanceId}/vnfs/{vnfInstanceId}", method = RequestMethod.POST)
\r
357 public ResponseEntity<String> deleteVnf(@PathVariable("serviceInstanceId") String serviceInstanceId, @PathVariable("vnfInstanceId") String vnfInstanceId,
\r
358 HttpServletRequest request, @RequestBody RequestDetails mso_request) throws Exception {
\r
359 String methodName = "deleteVnf";
\r
361 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
\r
362 if (!userIsPermmited(request, mso_request)) {
\r
363 return new ResponseEntity<String>(HttpStatus.FORBIDDEN);
\r
365 //RequestDetails mso_request = retrieveRequestObject (request);
\r
366 String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_VNF_INSTANCE);
\r
367 if (p == null || p.isEmpty()) {
\r
368 throw new Exception("Vnf instance path is not defined");
\r
370 // /serviceInstances/v2/<service_instance_id>/vnfs/
\r
371 String vnf_path = p.replaceFirst(SVC_INSTANCE_ID, vnfInstanceId);
\r
372 MsoResponseWrapper w = deleteInstance(mso_request, vnf_path + "/" + vnfInstanceId);
\r
374 // always return OK, the MSO status code is embedded in the body
\r
375 return (new ResponseEntity<String>(w.getResponse(), HttpStatus.OK));
\r
380 * Delete vf module.
\r
382 * @param serviceInstanceId the service instance id
\r
383 * @param vnfInstanceId the vnf instance id
\r
384 * @param vfModuleId the vf module id
\r
385 * @param request the request
\r
386 * @return the response entity
\r
387 * @throws Exception the exception
\r
389 //mso_delete_vf_module/bc305d54-75b4-431b-adb2-eb6b9e546014/vnfs/fe9000-0009-9999/vfmodules/abeeee-abeeee-abeeee
\r
390 @RequestMapping(value = "/mso_delete_vfmodule_instance/{serviceInstanceId}/vnfs/{vnfInstanceId}/vfModules/{vfModuleId}", method = RequestMethod.POST)
\r
391 public ResponseEntity<String> deleteVfModule(
\r
392 @PathVariable("serviceInstanceId") String serviceInstanceId, @PathVariable("vnfInstanceId") String vnfInstanceId,
\r
393 @PathVariable("vfModuleId") String vfModuleId, HttpServletRequest request, @RequestBody RequestDetails mso_request) throws Exception {
\r
395 String methodName = "deleteVfModule";
\r
397 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
\r
398 if (!userIsPermmited(request, mso_request)) {
\r
399 return new ResponseEntity<String>(HttpStatus.FORBIDDEN);
\r
401 //RequestDetails mso_request = new RequestDetails();
\r
402 //mso_request = retrieveRequestObject (request);
\r
403 String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_VF_MODULE_INSTANCE);
\r
404 if (p == null || p.isEmpty()) {
\r
405 throw new Exception("VF Module instance path is not defined");
\r
407 // /serviceInstances/v2/<serviceInstanceId>/vnfs/<vnfInstanceId>/vfmodules
\r
408 String path = p.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
\r
409 path = path.replaceFirst(VNF_INSTANCE_ID, vnfInstanceId);
\r
410 MsoResponseWrapper w = deleteInstance(mso_request, path + "/" + vfModuleId);
\r
412 // always return OK, the MSO status code is embedded in the body
\r
413 return (new ResponseEntity<String>(w.getResponse(), HttpStatus.OK));
\r
418 * Delete volume group instance.
\r
420 * @param serviceInstanceId the service instance id
\r
421 * @param vnfInstanceId the vnf instance id
\r
422 * @param volumeGroupId the volume group id
\r
423 * @param request the request
\r
424 * @return the response entity
\r
425 * @throws Exception the exception
\r
427 @RequestMapping(value = "/mso_delete_volumegroup_instance/{serviceInstanceId}/vnfs/{vnfInstanceId}/volumeGroups/{volumeGroupId}", method = RequestMethod.POST)
\r
428 public ResponseEntity<String> deleteVolumeGroupInstance(
\r
429 @PathVariable("serviceInstanceId") String serviceInstanceId, @PathVariable("vnfInstanceId") String vnfInstanceId, @PathVariable("volumeGroupId") String volumeGroupId,
\r
430 HttpServletRequest request, @RequestBody RequestDetails mso_request) throws Exception {
\r
432 String methodName = "deleteVolumeGroupInstance";
\r
434 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
\r
435 if (!userIsPermmited(request, mso_request)) {
\r
436 return new ResponseEntity<String>(HttpStatus.FORBIDDEN);
\r
438 String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_VOLUME_GROUP_INSTANCE);
\r
439 if (p == null || p.isEmpty()) {
\r
440 throw new Exception("Volume group instance path is not defined");
\r
442 // /serviceInstances/v2/{serviceInstanceId}/volumeGroups
\r
443 String path = p.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
\r
444 path = path.replaceFirst(VNF_INSTANCE_ID, vnfInstanceId);
\r
445 MsoResponseWrapper w = deleteInstance(mso_request, path + "/" + volumeGroupId);
\r
447 // always return OK, the MSO status code is embedded in the body
\r
448 return (new ResponseEntity<String>(w.getResponse(), HttpStatus.OK));
\r
452 * Delete nw instance.
\r
454 * @param serviceInstanceId the service instance id
\r
455 * @param networkInstanceId the network instance id
\r
456 * @param request the request
\r
457 * @return the response entity
\r
458 * @throws Exception the exception
\r
460 @RequestMapping(value = "/mso_delete_nw_instance/{serviceInstanceId}/networks/{networkInstanceId}", method = RequestMethod.POST)
\r
461 public ResponseEntity<String> deleteNwInstance(@PathVariable("serviceInstanceId") String serviceInstanceId,
\r
462 @PathVariable("networkInstanceId") String networkInstanceId, HttpServletRequest request, @RequestBody RequestDetails mso_request) throws Exception {
\r
464 String methodName = "deleteNwInstance";
\r
465 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
\r
467 //RequestDetails mso_request = retrieveRequestObject (request);
\r
468 if (!userIsPermmited(request, mso_request)) {
\r
469 return new ResponseEntity<String>(HttpStatus.FORBIDDEN);
\r
471 String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_NETWORK_INSTANCE);
\r
472 if (p == null || p.isEmpty()) {
\r
473 throw new Exception("Network instance path is not defined");
\r
475 // /serviceInstances/v2/<service_instance_id>/networks
\r
476 String path = p.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
\r
477 MsoResponseWrapper w = deleteInstance(mso_request, path + "/" + networkInstanceId);
\r
479 // always return OK, the MSO status code is embedded in the body
\r
480 return (new ResponseEntity<String>(w.getResponse(), HttpStatus.OK));
\r
487 * @param request the request
\r
488 * @param path the path
\r
489 * @return the mso response wrapper
\r
490 * @throws Exception the exception
\r
492 protected MsoResponseWrapper deleteInstance(RequestDetails request, String path) throws Exception {
\r
493 String methodName = "deleteInstance";
\r
494 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
\r
497 MsoRestInterfaceIfc restController = MsoRestInterfaceFactory.getInstance();
\r
498 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " calling Delete, path =[" + path + "]");
\r
500 RestObject<String> restObjStr = new RestObject<String>();
\r
501 String str = new String();
\r
502 restObjStr.set(str);
\r
503 restController.<String>Delete(str, request, "", path, restObjStr);
\r
504 MsoResponseWrapper w = MsoUtil.wrapResponse(restObjStr);
\r
506 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " w=" + w.getResponse());
\r
509 } catch (Exception e) {
\r
510 logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
\r
511 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
\r
518 * Gets the orchestration request.
\r
520 * @param requestId the request id
\r
521 * @param request the request
\r
522 * @return the orchestration request
\r
523 * @throws Exception the exception
\r
525 @RequestMapping(value = "/mso_get_orch_req/{requestId}", method = RequestMethod.GET)
\r
526 public ResponseEntity<String> getOrchestrationRequest(@PathVariable("requestId") String requestId,
\r
527 HttpServletRequest request) throws Exception {
\r
529 String methodName = "getOrchestrationRequest";
\r
530 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
\r
531 MsoResponseWrapper w = null;
\r
533 MsoRestInterfaceIfc restController = MsoRestInterfaceFactory.getInstance();
\r
534 String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQ);
\r
535 String path = p + "/" + requestId;
\r
537 RestObject<String> restObjStr = new RestObject<String>();
\r
538 String str = new String();
\r
539 restObjStr.set(str);
\r
541 restController.<String>Get(str, "", path, restObjStr);
\r
543 w = MsoUtil.wrapResponse(restObjStr);
\r
544 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " w=" + w.getResponse());
\r
545 // always return OK, the MSO status code is embedded in the body
\r
547 } catch (Exception e) {
\r
548 logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
\r
549 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
\r
552 // always return OK, the MSO status code is embedded in the body
\r
553 return (new ResponseEntity<String>(w.getResponse(), HttpStatus.OK));
\r
558 * Gets the orchestration requests.
\r
560 * @param filterString the filter string
\r
561 * @param request the request
\r
562 * @return the orchestration requests
\r
563 * @throws Exception the exception
\r
565 @RequestMapping(value = "/mso_get_orch_reqs/{filterString}", method = RequestMethod.GET)
\r
566 public ResponseEntity<String> getOrchestrationRequests(@PathVariable("filterString") String filterString,
\r
567 HttpServletRequest request) throws Exception {
\r
569 String methodName = "getOrchestrationRequests";
\r
570 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
\r
571 MsoResponseWrapper w = null;
\r
573 MsoRestInterfaceIfc restController = MsoRestInterfaceFactory.getInstance();
\r
574 String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQS);
\r
575 String path = p + filterString;
\r
577 RestObject<String> restObjStr = new RestObject<String>();
\r
578 String str = new String();
\r
579 restObjStr.set(str);
\r
581 restController.<String>Get(str, "", path, restObjStr);
\r
583 w = MsoUtil.wrapResponse(restObjStr);
\r
584 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " w=" + w.getResponse());
\r
585 } catch (Exception e) {
\r
586 logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
\r
587 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
\r
590 // always return OK, the MSO status code is embedded in the body
\r
591 return (new ResponseEntity<String>(w.getResponse(), HttpStatus.OK));
\r
595 * Gets the orchestration requests for svc instance.
\r
597 * @param svc_instance_id the svc instance id
\r
598 * @return the orchestration requests for svc instance
\r
599 * @throws Exception the exception
\r
601 public MsoResponseWrapper getOrchestrationRequestsForSvcInstance(String svc_instance_id) throws Exception {
\r
603 String methodName = "getOrchestrationRequestsForSvcInstance";
\r
604 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
\r
605 MsoResponseWrapper w = null;
\r
608 MsoRestInterfaceIfc restController = MsoRestInterfaceFactory.getInstance();
\r
609 String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQS);
\r
610 String path = p + svc_instance_id;
\r
612 RestObject<String> restObjStr = new RestObject<String>();
\r
613 String str = new String();
\r
614 restObjStr.set(str);
\r
616 restController.<String>Get(str, "", path, restObjStr);
\r
617 w = MsoUtil.wrapResponse(restObjStr);
\r
618 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " w=" + w.getResponse());
\r
620 } catch (Exception e) {
\r
621 logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
\r
622 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
\r
629 * Exception handler.
\r
632 * @param response the response
\r
633 * @throws IOException Signals that an I/O exception has occurred.
\r
635 @ExceptionHandler(Exception.class)
\r
636 private void exceptionHandler(Exception e, HttpServletResponse response) throws IOException {
\r
639 * The following "logger.error" lines "should" be sufficient for logging the exception.
\r
640 * However, the console output in my Eclipse environment is NOT showing ANY of the
\r
641 * logger statements in this class. Thus the temporary "e.printStackTrace" statement
\r
642 * is also included.
\r
645 String methodName = "exceptionHandler";
\r
646 logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
\r
647 StringWriter sw = new StringWriter();
\r
648 e.printStackTrace(new PrintWriter(sw));
\r
649 logger.error(EELFLoggerDelegate.errorLogger, sw.toString());
\r
652 * Temporary - IF the above mentioned "logger.error" glitch is resolved ...
\r
653 * this statement could be removed since it would then likely result in duplicate
\r
656 e.printStackTrace(System.err);
\r
658 response.setContentType("application/json; charset=UTF-8");
\r
659 response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
\r
661 ExceptionResponse exceptionResponse = new ExceptionResponse();
\r
662 exceptionResponse.setException(e.getClass().toString().replaceFirst("^.*\\.", ""));
\r
663 exceptionResponse.setMessage(e.getMessage());
\r
665 response.getWriter().write(new ObjectMapper().writeValueAsString(exceptionResponse));
\r
667 response.flushBuffer();
\r
672 * Parses the orchestration requests for svc instance.
\r
674 * @param resp the resp
\r
676 * @throws Exception the exception
\r
678 @SuppressWarnings("unchecked")
\r
679 public List<JSONObject> parseOrchestrationRequestsForSvcInstance(ClientResponse resp) throws org.json.simple.parser.ParseException, Exception {
\r
681 String methodName = "parseOrchestrationRequestsForSvcInstance";
\r
683 ArrayList<JSONObject> json_list = new ArrayList<JSONObject>();
\r
685 String rlist_str = resp.readEntity(String.class);
\r
686 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + " Response string: " + rlist_str);
\r
688 JSONParser parser = new JSONParser();
\r
690 Object obj = parser.parse(rlist_str);
\r
692 JSONObject jsonObject = (JSONObject) obj;
\r
694 JSONArray requestList = (JSONArray) jsonObject.get("requestList");
\r
696 if (requestList != null && !(requestList.isEmpty()))
\r
697 for (Object container : requestList) {
\r
699 JSONObject containerJsonObj = (JSONObject) container;
\r
700 //logger.debug(dateFormat.format(new Date()) + "<== " + "." + methodName + " reqJsonObj: " + containerJsonObj.toJSONString());
\r
701 JSONObject reqJsonObj = (JSONObject) containerJsonObj.get("request");
\r
703 //logger.debug(dateFormat.format(new Date()) + "<== " + "." + methodName + " reqJsonObj.requestId: " +
\r
704 // reqJsonObj.get("requestId") );
\r
705 JSONObject result = new JSONObject();
\r
707 result.put("requestId", reqJsonObj.get("requestId"));
\r
708 if (reqJsonObj.get("requestType") != null) {
\r
709 result.put("requestType", (reqJsonObj.get("requestType").toString()));
\r
711 JSONObject req_status = (JSONObject) reqJsonObj.get("requestStatus");
\r
712 if (req_status != null) {
\r
713 result.put("timestamp", (req_status.get("timestamp")));
\r
714 result.put("requestState", (req_status.get("requestState")));
\r
715 result.put("statusMessage", (req_status.get("statusMessage")));
\r
716 result.put("percentProgress", (req_status.get("percentProgress")));
\r
718 json_list.add(result);
\r
720 } catch (org.json.simple.parser.ParseException pe) {
\r
721 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + " Parse exception: " + pe.toString());
\r
723 } catch (Exception e) {
\r
724 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + " Exception: " + e.toString());
\r
727 return (json_list);
\r
731 * Retrieve request object.
\r
733 * @param request the request
\r
734 * @return the request details
\r
735 * @throws Exception the exception
\r
737 public RequestDetails retrieveRequestObject(HttpServletRequest request, @RequestBody RequestDetails mso_request) throws Exception {
\r
739 String methodName = "retrieveRequestObject";
\r
740 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
\r
742 ObjectMapper mapper = new ObjectMapper();
\r
743 //JSON from String to Object
\r
744 //RequestDetails mso_request;
\r
747 //mso_request = new RequestDetails();
\r
748 //mso_request = mapper.readValue(request.getInputStream(), RequestDetails.class);
\r
749 } catch (Exception e) {
\r
750 logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + methodName + " Unable to read json object RequestDetails e=" + e.getMessage());
\r
753 if (mso_request == null) {
\r
754 logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + methodName + " mso_request is null");
\r
755 throw new Exception("RequestDetails is missing");
\r
758 String json_req = mapper.writeValueAsString(mso_request);
\r
759 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " request=[" + json_req + "]");
\r
760 } catch (Exception e) {
\r
761 logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + methodName + " Unable to convert RequestDetails to json string e=" + e.getMessage());
\r
764 return (mso_request);
\r