Sending workflow data from UI to SO
[vid.git] / vid-app-common / src / main / java / org / onap / vid / controller / MsoController.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * VID
4  * ================================================================================
5  * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.vid.controller;
22
23
24 import com.fasterxml.jackson.databind.ObjectMapper;
25 import org.onap.portalsdk.core.controller.RestrictedBaseController;
26 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
27 import org.onap.vid.model.ExceptionResponse;
28 import org.onap.vid.model.SoftDeleteRequest;
29 import org.onap.vid.mso.MsoBusinessLogic;
30 import org.onap.vid.mso.MsoResponseWrapper;
31 import org.onap.vid.mso.MsoResponseWrapper2;
32 import org.onap.vid.mso.rest.Request;
33 import org.onap.vid.mso.rest.RequestDetails;
34 import org.onap.vid.mso.rest.RequestDetailsWrapper;
35 import org.onap.vid.mso.rest.Task;
36 import org.onap.vid.services.CloudOwnerService;
37 import org.springframework.beans.factory.annotation.Autowired;
38 import org.springframework.http.HttpStatus;
39 import org.springframework.http.ResponseEntity;
40 import org.springframework.web.bind.annotation.*;
41
42 import javax.servlet.http.HttpServletRequest;
43 import javax.servlet.http.HttpServletResponse;
44 import java.io.IOException;
45 import java.util.LinkedHashMap;
46 import java.util.List;
47
48 import static org.onap.vid.utils.Logging.getMethodName;
49
50 /**
51  * The Class MsoController.
52  */
53 @RestController
54 @RequestMapping("mso")
55 public class MsoController extends RestrictedBaseController {
56
57     /**
58      * The logger.
59      */
60     private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(MsoController.class);
61
62     /**
63      * The Constant SVC_INSTANCE_ID.
64      */
65     public static final String SVC_INSTANCE_ID = "<service_instance_id>";
66     public static final String REQUEST_TYPE = "<request_type>";
67
68     /**
69      * The Constant CONFIGURATION_ID
70      */
71     public static final String CONFIGURATION_ID = "<configuration_id>";
72
73     /**
74      * The Constant VNF_INSTANCE_ID.
75      */
76     public static final String VNF_INSTANCE_ID = "<vnf_instance_id>";
77     public static final String WORKFLOW_ID = "<workflow_UUID>";
78     public static final String START_LOG = " start";
79
80     private final MsoBusinessLogic msoBusinessLogic;
81     private final CloudOwnerService cloudOwnerService;
82
83     @Autowired
84     public MsoController(MsoBusinessLogic msoBusinessLogic, CloudOwnerService cloudOwnerService) {
85         this.msoBusinessLogic = msoBusinessLogic;
86         this.cloudOwnerService = cloudOwnerService;
87     }
88
89     /**
90      * Creates the svc instance.
91      *
92      * @param request the request
93      * @return the response entity
94      * @throws Exception the exception
95      */
96     @RequestMapping(value = "/mso_create_svc_instance", method = RequestMethod.POST)
97     public ResponseEntity<String> createSvcInstance(HttpServletRequest request, @RequestBody RequestDetails msoRequest) {
98         String methodName = "createSvcInstance";
99
100         LOGGER.debug(EELFLoggerDelegate.debugLogger, "<== " + methodName + START_LOG);
101
102         // always return OK, the MSO status code is embedded in the body
103
104         cloudOwnerService.enrichRequestWithCloudOwner(msoRequest);
105         MsoResponseWrapper w = msoBusinessLogic.createSvcInstance(msoRequest);
106
107         return (new ResponseEntity<>(w.getResponse(), HttpStatus.OK));
108
109     }
110
111     /**
112      * Creates the e2e svc instance.
113      *
114      * @param request the request
115      * @return the response entity
116      * @throws Exception the exception
117      */
118     @RequestMapping(value = "/mso_create_e2e_svc_instance", method = RequestMethod.POST)
119     public ResponseEntity<String> createE2eSvcInstance(HttpServletRequest request, @RequestBody LinkedHashMap<String, Object> msoRequest) {
120         String methodName = "createE2eSvcInstance";
121
122         LOGGER.debug(EELFLoggerDelegate.debugLogger, "<== " + methodName + START_LOG);
123
124         // always return OK, the MSO status code is embedded in the body
125
126         //cloudOwnerService.enrichRequestWithCloudOwner(msoRequest);
127         MsoResponseWrapper w = msoBusinessLogic.createE2eSvcInstance(msoRequest.get("requestDetails"));
128
129         return (new ResponseEntity<>(w.getResponse(), HttpStatus.OK));
130
131     }
132
133     /**
134      * Creates the vnf.
135      *
136      * @param serviceInstanceId the service instance id
137      * @param request           the request
138      * @return the response entity
139      * @throws Exception the exception
140      */
141     @RequestMapping(value = "/mso_create_vnf_instance/{serviceInstanceId}", method = RequestMethod.POST)
142     public ResponseEntity<String> createVnf(@PathVariable("serviceInstanceId") String serviceInstanceId, HttpServletRequest request, @RequestBody RequestDetails msoRequest) {
143
144         cloudOwnerService.enrichRequestWithCloudOwner(msoRequest);
145         MsoResponseWrapper w = msoBusinessLogic.createVnf(msoRequest, serviceInstanceId);
146
147         // always return OK, the MSO status code is embedded in the body
148
149         return (new ResponseEntity<String>(w.getResponse(), HttpStatus.OK));
150
151     }
152
153     /**
154      * Creates the nw instance.
155      *
156      * @param serviceInstanceId the service instance id
157      * @param request           the request
158      * @return the response entity
159      * @throws Exception the exception
160      */
161     @RequestMapping(value = "/mso_create_nw_instance/{serviceInstanceId}", method = RequestMethod.POST)
162     public ResponseEntity<String> createNwInstance(@PathVariable("serviceInstanceId") String serviceInstanceId, HttpServletRequest request, @RequestBody RequestDetails msoRequest) {
163         String methodName = "createNwInstance";
164         LOGGER.debug(EELFLoggerDelegate.debugLogger, "<== " + methodName + " start, serviceInstanceId = " + serviceInstanceId);
165
166         cloudOwnerService.enrichRequestWithCloudOwner(msoRequest);
167         MsoResponseWrapper w = msoBusinessLogic.createNwInstance(msoRequest, serviceInstanceId);
168
169         return (new ResponseEntity<String>(w.getResponse(), HttpStatus.OK));
170
171     }
172
173     /**
174      * Creates the volume group instance.
175      *
176      * @param serviceInstanceId the service instance id
177      * @param vnfInstanceId     the vnf instance id
178      * @param request           the request
179      * @return the response entity
180      * @throws Exception the exception
181      */
182     @RequestMapping(value = "/mso_create_volumegroup_instance/{serviceInstanceId}/vnfs/{vnfInstanceId}", method = RequestMethod.POST)
183     public ResponseEntity<String> createVolumeGroupInstance(@PathVariable("serviceInstanceId") String serviceInstanceId, @PathVariable("vnfInstanceId") String vnfInstanceId,
184                                                             HttpServletRequest request, @RequestBody RequestDetails msoRequest) {
185         String methodName = "createVolumeGroupInstance";
186         LOGGER.debug(EELFLoggerDelegate.debugLogger, "<== " + methodName + START_LOG);
187
188         cloudOwnerService.enrichRequestWithCloudOwner(msoRequest);
189         MsoResponseWrapper w = msoBusinessLogic.createVolumeGroupInstance(msoRequest, serviceInstanceId, vnfInstanceId);
190
191         // always return OK, the MSO status code is embedded in the body
192         return (new ResponseEntity<String>(w.getResponse(), HttpStatus.OK));
193     }
194
195     /**
196      * Creates the vf module instance.
197      *
198      * @param serviceInstanceId the service instance id
199      * @param vnfInstanceId     the vnf instance id
200      * @param request           the request
201      * @return the response entity
202      * @throws Exception the exception
203      */
204     @RequestMapping(value = "/mso_create_vfmodule_instance/{serviceInstanceId}/vnfs/{vnfInstanceId}", method = RequestMethod.POST)
205     public ResponseEntity<String> createVfModuleInstance(@PathVariable("serviceInstanceId") String serviceInstanceId,
206                                                          @PathVariable("vnfInstanceId") String vnfInstanceId, HttpServletRequest request, @RequestBody RequestDetails msoRequest) {
207         String methodName = "createVfModuleInstance";
208
209         LOGGER.debug(EELFLoggerDelegate.debugLogger, "<== " + methodName + START_LOG);
210
211         cloudOwnerService.enrichRequestWithCloudOwner(msoRequest);
212         MsoResponseWrapper w = msoBusinessLogic.createVfModuleInstance(msoRequest, serviceInstanceId, vnfInstanceId);
213
214         // always return OK, the MSO status code is embedded in the body
215
216         return (new ResponseEntity<String>(w.getResponse(), HttpStatus.OK));
217     }
218
219     /**
220      * Creates a configuration instance.
221      *
222      * @param serviceInstanceId the service instance id
223      * @param request           the request
224      * @return the response entity
225      * @throws Exception the exception
226      */
227     @RequestMapping(value = "/mso_create_configuration_instance/{serviceInstanceId}/configurations/", method = RequestMethod.POST)
228     public ResponseEntity<String> createConfigurationInstance(@PathVariable("serviceInstanceId") String serviceInstanceId,
229                                                               HttpServletRequest request, @RequestBody RequestDetailsWrapper msoRequest) {
230         String methodName = "createConfigurationInstance";
231         LOGGER.debug(EELFLoggerDelegate.debugLogger, "<== " + methodName + START_LOG);
232
233         cloudOwnerService.enrichRequestWithCloudOwner(msoRequest.getRequestDetails());
234         MsoResponseWrapper w = msoBusinessLogic.createConfigurationInstance(msoRequest, serviceInstanceId);
235
236         // always return OK, the MSO status code is embedded in the body
237
238         return (new ResponseEntity<>(w.getResponse(), HttpStatus.OK));
239     }
240
241     /**
242      * Delete E2e svc instance.
243      *
244      * @param serviceInstanceId the service instance id
245      * @param request           the request
246      * @return the response entity
247      * @throws Exception the exception
248      */
249     @RequestMapping(value = "/mso_delete_e2e_svc_instance/{serviceInstanceId}", method = RequestMethod.POST)
250     public ResponseEntity<String> deleteE2eSvcInstance(@PathVariable("serviceInstanceId") String serviceInstanceId,
251                                                        HttpServletRequest request, @RequestBody LinkedHashMap<String, Object> msoRequest) {
252
253         LOGGER.debug(EELFLoggerDelegate.debugLogger, "start {}({})", getMethodName(), msoRequest);
254         MsoResponseWrapper w = msoBusinessLogic.deleteE2eSvcInstance(msoRequest.get("requestDetails"), serviceInstanceId);
255         // always return OK, the MSO status code is embedded in the body
256
257         return (new ResponseEntity<String>(w.getResponse(), HttpStatus.OK));
258
259     }
260
261     /**
262      * Delete svc instance.
263      *
264      * @param serviceInstanceId the service instance id
265      * @param request           the request
266      * @return the response entity
267      * @throws Exception the exception
268      */
269
270     @RequestMapping(value = "/mso_delete_svc_instance/{serviceInstanceId}", method = RequestMethod.POST)
271     public String deleteSvcInstance(@PathVariable("serviceInstanceId") String serviceInstanceId,
272                                     HttpServletRequest request, @RequestBody RequestDetails msoRequest,
273                                     @RequestParam(value = "serviceStatus") String serviceStatus) {
274
275         LOGGER.debug(EELFLoggerDelegate.debugLogger, "start {}({})", getMethodName(), msoRequest);
276         MsoResponseWrapper w = msoBusinessLogic.deleteSvcInstance(msoRequest, serviceInstanceId, serviceStatus);
277         // always return OK, the MSO status code is embedded in the body
278
279         return w.getResponse();
280     }
281
282     /**
283      * Delete vnf.
284      *
285      * @param serviceInstanceId the service instance id
286      * @param vnfInstanceId     the vnf instance id
287      * @param request           the request
288      * @return the response entity
289      * @throws Exception the exception
290      */
291     @RequestMapping(value = "/mso_delete_vnf_instance/{serviceInstanceId}/vnfs/{vnfInstanceId}", method = RequestMethod.POST)
292
293     public ResponseEntity<String> deleteVnf(@PathVariable("serviceInstanceId") String serviceInstanceId, @PathVariable("vnfInstanceId") String vnfInstanceId,
294                                             HttpServletRequest request, @RequestBody RequestDetails msoRequest) {
295         String methodName = "deleteVnf";
296
297         LOGGER.debug(EELFLoggerDelegate.debugLogger, "<== " + methodName + START_LOG);
298         cloudOwnerService.enrichRequestWithCloudOwner(msoRequest);
299         MsoResponseWrapper w = msoBusinessLogic.deleteVnf(msoRequest, serviceInstanceId, vnfInstanceId);
300
301         // always return OK, the MSO status code is embedded in the body
302         return (new ResponseEntity<String>(w.getResponse(), HttpStatus.OK));
303
304     }
305
306     /**
307      * Delete configuration instance
308      * @param serviceInstanceId the service instance id
309      * @param configurationId the configuration id
310      * @param msoRequest the request
311      * @return the response entity
312      * @throws Exception the exception
313      */
314     @RequestMapping(value = "mso_delete_configuration/{serviceInstanceId}/configurations/{configurationId}",
315             method = RequestMethod.POST)
316     public ResponseEntity<String> deleteConfiguration(
317             @PathVariable("serviceInstanceId") String serviceInstanceId,
318             @PathVariable ("configurationId") String configurationId,
319             @RequestBody RequestDetailsWrapper msoRequest) {
320
321         String methodName = "deleteConfiguration";
322         LOGGER.debug(EELFLoggerDelegate.debugLogger,
323                 "<== " + methodName + START_LOG);
324
325         cloudOwnerService.enrichRequestWithCloudOwner(msoRequest.getRequestDetails());
326         MsoResponseWrapper w = msoBusinessLogic.deleteConfiguration(msoRequest, serviceInstanceId, configurationId);
327
328         // always return OK, the MSO status code is embedded in the body
329         return (new ResponseEntity<String>(w.getResponse(), HttpStatus.OK));
330     }
331
332     /**
333      * Activate configuration instance
334      * @param serviceInstanceId the service instace id
335      * @param configurationId the configuration id
336      * @param msoRequest the request
337      * @return the response entity
338      * @throws Exception the exception
339      */
340     @RequestMapping(value = "mso_activate_configuration/{serviceInstanceId}/configurations/{configurationId}",
341             method = RequestMethod.POST)
342     public ResponseEntity<String> activateConfiguration(
343             @PathVariable("serviceInstanceId") String serviceInstanceId,
344             @PathVariable("configurationId") String configurationId,
345             @RequestBody RequestDetails msoRequest) {
346
347         cloudOwnerService.enrichRequestWithCloudOwner(msoRequest);
348         MsoResponseWrapper w = msoBusinessLogic.setConfigurationActiveStatus(msoRequest, serviceInstanceId, configurationId, true);
349
350         // always return OK, the MSO status code is embedded in the body
351         return (new ResponseEntity<String>(w.getResponse(), HttpStatus.OK));
352     }
353
354     /**
355      * Deactivate configuration instance
356      * @param serviceInstanceId the service instace id
357      * @param configurationId the configuration id
358      * @param msoRequest the request
359      * @return the response entity
360      * @throws Exception the exception
361      */
362     @RequestMapping(value = "mso_deactivate_configuration/{serviceInstanceId}/configurations/{configurationId}",
363             method = RequestMethod.POST)
364     public ResponseEntity<String> deactivateConfiguration(
365             @PathVariable("serviceInstanceId") String serviceInstanceId,
366             @PathVariable("configurationId") String configurationId,
367             @RequestBody RequestDetails msoRequest) {
368
369         cloudOwnerService.enrichRequestWithCloudOwner(msoRequest);
370         MsoResponseWrapper w = msoBusinessLogic.setConfigurationActiveStatus(msoRequest, serviceInstanceId, configurationId, false);
371
372         // always return OK, the MSO status code is embedded in the body
373         return (new ResponseEntity<String>(w.getResponse(), HttpStatus.OK));
374     }
375
376     /**
377      * Disable port on configuration instance
378      * @param serviceInstanceId the service instance id
379      * @param configurationId the configuration instance id
380      * @param msoRequest the request
381      * @return the response entity
382      * @throws Exception the exception
383      */
384     @RequestMapping(value = "mso_disable_port_configuration/{serviceInstanceId}/configurations/{configurationId}",
385             method = RequestMethod.POST)
386     public ResponseEntity<String> disablePortOnConfiguration(
387             @PathVariable("serviceInstanceId") String serviceInstanceId,
388             @PathVariable("configurationId") String configurationId,
389             @RequestBody RequestDetails msoRequest) {
390
391         cloudOwnerService.enrichRequestWithCloudOwner(msoRequest);
392         MsoResponseWrapper w = msoBusinessLogic.setPortOnConfigurationStatus(msoRequest, serviceInstanceId, configurationId, false);
393
394         // always return OK, the MSO status code is embedded in the body
395         return (new ResponseEntity<String>(w.getResponse(), HttpStatus.OK));
396     }
397
398     /**
399      * Enable port on configuration instance
400      * @param serviceInstanceId the service instance id
401      * @param configurationId the configuration instance id
402      * @param msoRequest the request
403      * @return the response entity
404      * @throws Exception the exception
405      */
406     @RequestMapping(value = "mso_enable_port_configuration/{serviceInstanceId}/configurations/{configurationId}",
407             method = RequestMethod.POST)
408     public ResponseEntity<String> enablePortOnConfiguration(
409             @PathVariable("serviceInstanceId") String serviceInstanceId,
410             @PathVariable("configurationId") String configurationId,
411             @RequestBody RequestDetails msoRequest) {
412
413         cloudOwnerService.enrichRequestWithCloudOwner(msoRequest);
414         MsoResponseWrapper w = msoBusinessLogic.setPortOnConfigurationStatus(msoRequest, serviceInstanceId, configurationId, true);
415
416         // always return OK, the MSO status code is embedded in the body
417         return (new ResponseEntity<String>(w.getResponse(), HttpStatus.OK));
418     }
419
420     /**
421      * Delete vf module.
422      *
423      * @param serviceInstanceId the service instance id
424      * @param vnfInstanceId     the vnf instance id
425      * @param vfModuleId        the vf module id
426      * @param request           the request
427      * @return the response entity
428      * @throws Exception the exception
429      */
430     //mso_delete_vf_module/bc305d54-75b4-431b-adb2-eb6b9e546014/vnfs/fe9000-0009-9999/vfmodules/abeeee-abeeee-abeeee
431     @RequestMapping(value = "/mso_delete_vfmodule_instance/{serviceInstanceId}/vnfs/{vnfInstanceId}/vfModules/{vfModuleId}", method = RequestMethod.POST)
432     public ResponseEntity<String> deleteVfModule(
433             @PathVariable("serviceInstanceId") String serviceInstanceId, @PathVariable("vnfInstanceId") String vnfInstanceId,
434             @PathVariable("vfModuleId") String vfModuleId, HttpServletRequest request, @RequestBody RequestDetails msoRequest) {
435
436         String methodName = "deleteVfModule";
437         LOGGER.debug(EELFLoggerDelegate.debugLogger, "<== " + methodName + START_LOG);
438
439         cloudOwnerService.enrichRequestWithCloudOwner(msoRequest);
440         MsoResponseWrapper w = msoBusinessLogic.deleteVfModule(msoRequest, serviceInstanceId, vnfInstanceId, vfModuleId);
441
442         // always return OK, the MSO status code is embedded in the body
443         return (new ResponseEntity<String>(w.getResponse(), HttpStatus.OK));
444     }
445
446     /**
447      * Delete volume group instance.
448      *
449      * @param serviceInstanceId the service instance id
450      * @param vnfInstanceId     the vnf instance id
451      * @param volumeGroupId     the volume group id
452      * @param request           the request
453      * @return the response entity
454      * @throws Exception the exception
455      */
456     @RequestMapping(value = "/mso_delete_volumegroup_instance/{serviceInstanceId}/vnfs/{vnfInstanceId}/volumeGroups/{volumeGroupId}", method = RequestMethod.POST)
457     public ResponseEntity<String> deleteVolumeGroupInstance(
458             @PathVariable("serviceInstanceId") String serviceInstanceId, @PathVariable("vnfInstanceId") String vnfInstanceId, @PathVariable("volumeGroupId") String volumeGroupId,
459             HttpServletRequest request, @RequestBody RequestDetails msoRequest) {
460         String methodName = "deleteVolumeGroupInstance";
461         LOGGER.debug(EELFLoggerDelegate.debugLogger, "<== " + methodName + START_LOG);
462
463         cloudOwnerService.enrichRequestWithCloudOwner(msoRequest);
464         MsoResponseWrapper w = msoBusinessLogic.deleteVolumeGroupInstance(msoRequest, serviceInstanceId, vnfInstanceId, volumeGroupId);
465
466         // always return OK, the MSO status code is embedded in the body
467         return (new ResponseEntity<String>(w.getResponse(), HttpStatus.OK));
468     }
469
470     /**
471      * Delete nw instance.
472      *
473      * @param serviceInstanceId the service instance id
474      * @param networkInstanceId the network instance id
475      * @param request           the request
476      * @return the response entity
477      * @throws Exception the exception
478      */
479     @RequestMapping(value = "/mso_delete_nw_instance/{serviceInstanceId}/networks/{networkInstanceId}", method = RequestMethod.POST)
480     public ResponseEntity<String> deleteNwInstance(@PathVariable("serviceInstanceId") String serviceInstanceId,
481                                                    @PathVariable("networkInstanceId") String networkInstanceId, HttpServletRequest request, @RequestBody RequestDetails msoRequest) {
482         String methodName = "deleteNwInstance";
483         LOGGER.debug(EELFLoggerDelegate.debugLogger, "<== " + methodName + START_LOG);
484
485         cloudOwnerService.enrichRequestWithCloudOwner(msoRequest);
486         MsoResponseWrapper w = msoBusinessLogic.deleteNwInstance(msoRequest, serviceInstanceId, networkInstanceId);
487
488         // always return OK, the MSO status code is embedded in the body
489         return (new ResponseEntity<String>(w.getResponse(), HttpStatus.OK));
490     }
491
492     /**
493      * Gets the orchestration request.
494      *
495      * @param requestId the request id
496      * @param request   the request
497      * @return the orchestration request
498      * @throws Exception the exception
499      */
500     @RequestMapping(value = "/mso_get_orch_req/{requestId}", method = RequestMethod.GET)
501     public ResponseEntity<String> getOrchestrationRequest(@PathVariable("requestId") String requestId,
502                                                           HttpServletRequest request) {
503
504         String methodName = "getOrchestrationRequest";
505         LOGGER.debug(EELFLoggerDelegate.debugLogger, "<== " + methodName + START_LOG);
506
507
508         MsoResponseWrapper w = msoBusinessLogic.getOrchestrationRequest(requestId);
509
510         // always return OK, the MSO status code is embedded in the body
511         return (new ResponseEntity<String>(w.getResponse(), HttpStatus.OK));
512     }
513
514     /**
515      * Gets the orchestration requests.
516      *
517      * @param filterString the filter string
518      * @param request      the request
519      * @return the orchestration requests
520      * @throws Exception the exception
521      */
522     @RequestMapping(value = "/mso_get_orch_reqs/{filterString}", method = RequestMethod.GET)
523     public ResponseEntity<String> getOrchestrationRequests(@PathVariable("filterString") String filterString,
524                                                            HttpServletRequest request) {
525
526         String methodName = "getOrchestrationRequests";
527         LOGGER.debug(EELFLoggerDelegate.debugLogger, "<== " + methodName + START_LOG);
528
529
530         MsoResponseWrapper w = msoBusinessLogic.getOrchestrationRequests(filterString);
531
532         // always return OK, the MSO status code is embedded in the body
533         return (new ResponseEntity<String>(w.getResponse(), HttpStatus.OK));
534     }
535
536     /**
537      * activate to a pnf instance.
538      *
539      * @param serviceInstanceId the id of the service.
540      * @param requestDetails the body of the request.
541      * @return the response entity
542      * @throws Exception the exception
543      */
544     @RequestMapping(value = "/mso_activate_service_instance/{serviceInstanceId}", method = RequestMethod.POST)
545     public ResponseEntity<String> activateServiceInstance(@PathVariable("serviceInstanceId") String serviceInstanceId, @RequestBody RequestDetails requestDetails) {
546         String methodName = "activateServiceInstance";
547         LOGGER.debug(EELFLoggerDelegate.debugLogger, "<== " + methodName + START_LOG);
548
549         MsoResponseWrapper w = msoBusinessLogic.setServiceInstanceStatus(requestDetails, serviceInstanceId, true);
550         return new ResponseEntity<>(w.getResponse(), HttpStatus.OK);
551     }
552
553     /**
554      * deactivate a service instance.
555      *
556      * @param serviceInstanceId the id of the service.
557      * @param requestDetails the body of the request.
558      * @return the response entity
559      * @throws Exception the exception
560      */
561     @RequestMapping(value = "/mso_deactivate_service_instance/{serviceInstanceId}", method = RequestMethod.POST)
562     public ResponseEntity<String> deactivateServiceInstance(@PathVariable("serviceInstanceId") String serviceInstanceId, @RequestBody RequestDetails requestDetails) {
563         String methodName = "deactivateServiceInstance";
564         LOGGER.debug(EELFLoggerDelegate.debugLogger, "<== " + methodName + START_LOG);
565
566         MsoResponseWrapper w = msoBusinessLogic.setServiceInstanceStatus(requestDetails, serviceInstanceId, false);
567         return new ResponseEntity<>(w.getResponse(), HttpStatus.OK);
568     }
569
570     /**
571      * Gets the orchestration requests for the dashboard.
572      *  currently its all the orchestration requests with RequestType updateInstance or replaceInstance.
573      * @return the orchestration requests
574      * @throws Exception the exception
575      */
576     @RequestMapping(value = "/mso_get_orch_reqs/dashboard", method = RequestMethod.GET)
577     public List<Request> getOrchestrationRequestsForDashboard() {
578
579         String methodName = "getOrchestrationRequestsForDashboard";
580         LOGGER.debug(EELFLoggerDelegate.debugLogger, "<== " + methodName + START_LOG);
581
582
583         return msoBusinessLogic.getOrchestrationRequestsForDashboard();
584     }
585
586     /**
587      * Gets the Manual Tasks for the given request id.
588      *
589      * @param originalRequestId the id of the original request.
590      * @return the tasks
591      * @throws Exception the exception
592      */
593     @RequestMapping(value = "/mso_get_man_task/{originalRequestId}", method = RequestMethod.GET)
594     public List<Task> getManualTasksByRequestId(@PathVariable("originalRequestId") String originalRequestId) {
595
596         String methodName = "getManualTasksByRequestId";
597         LOGGER.debug(EELFLoggerDelegate.debugLogger, "<== " + methodName + START_LOG);
598
599         return  msoBusinessLogic.getManualTasksByRequestId(originalRequestId);
600     }
601
602     /**
603      * Complete the manual task.
604      *
605      * @param taskId the id of the task to complete.
606      * @param requestDetails the body of the request.
607      * @return the response entity
608      * @throws Exception the exception
609      */
610     @RequestMapping(value = "/mso_post_man_task/{taskId}", method = RequestMethod.POST)
611     public ResponseEntity<String> manualTaskComplete(@PathVariable("taskId") String taskId , @RequestBody RequestDetails requestDetails) {
612
613         String methodName = "manualTaskComplete";
614         LOGGER.debug(EELFLoggerDelegate.debugLogger, "<== " + methodName + START_LOG);
615
616         MsoResponseWrapper w = msoBusinessLogic.completeManualTask(requestDetails, taskId);
617         return new ResponseEntity<>(w.getResponse(), HttpStatus.OK);
618     }
619
620     @RequestMapping(value = "/mso_remove_relationship/{serviceInstanceId}", method = RequestMethod.POST)
621     public ResponseEntity<String> removeRelationshipFromServiceInstance(@PathVariable("serviceInstanceId") String serviceInstanceId ,
622                                                                         @RequestBody RequestDetails requestDetails) {
623
624         String methodName = "removeRelationshipFromServiceInstance";
625         LOGGER.debug(EELFLoggerDelegate.debugLogger, "<== " + methodName + START_LOG);
626
627         MsoResponseWrapper w;
628         try {
629             w = msoBusinessLogic.removeRelationshipFromServiceInstance(requestDetails, serviceInstanceId);
630         } catch (Exception e){
631             LOGGER.error("Internal error when calling MSO controller logic for {}", methodName, e);
632             return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
633         }
634         return new ResponseEntity<>(w.getResponse(), HttpStatus.OK);
635     }
636
637     @RequestMapping(value = "/mso_add_relationship/{serviceInstanceId}", method = RequestMethod.POST)
638     public ResponseEntity<String> addRelationshipToServiceInstance(@PathVariable("serviceInstanceId") String serviceInstanceId ,
639                                                                    @RequestBody RequestDetails requestDetails) {
640
641         String methodName = "addRelationshipToServiceInstance";
642         LOGGER.debug(EELFLoggerDelegate.debugLogger, "<== " + methodName + START_LOG);
643
644         MsoResponseWrapper w;
645         try {
646             w = msoBusinessLogic.addRelationshipToServiceInstance(requestDetails, serviceInstanceId);
647         } catch (Exception e){
648             LOGGER.error("Internal error when calling MSO controller logic for {}", methodName, e);
649             return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
650         }
651         return new ResponseEntity<>(w.getResponse(), HttpStatus.OK);
652     }
653
654     @RequestMapping(value = "/mso_activate_fabric_configuration/{serviceInstanceId}", method = RequestMethod.POST)
655     public MsoResponseWrapper2 activateFabricConfiguration(
656             @PathVariable("serviceInstanceId") String serviceInstanceId ,
657             @RequestBody RequestDetails requestDetails) {
658
659         String methodName = "activateFabricConfiguration";
660         LOGGER.debug(EELFLoggerDelegate.debugLogger, "<== " + methodName + START_LOG);
661
662         return msoBusinessLogic.activateFabricConfiguration(serviceInstanceId, requestDetails);
663     }
664
665     @RequestMapping(value = "/mso_vfmodule_soft_delete/{serviceInstanceId}/{vnfInstanceId}/{vfModuleInstanceId}", method = RequestMethod.POST)
666     public MsoResponseWrapper2 deactivateAndCloudDelete(
667             @PathVariable("serviceInstanceId") String serviceInstanceId,
668             @PathVariable("vnfInstanceId") String vnfInstanceId,
669             @PathVariable("vfModuleInstanceId") String vfModuleInstanceId,
670             @RequestBody SoftDeleteRequest softDeleteRequest) {
671
672         String methodName = "deactivateAndCloudDelete";
673         LOGGER.debug(EELFLoggerDelegate.debugLogger, "<== " + methodName + START_LOG);
674
675         RequestDetails requestDetails = msoBusinessLogic.buildRequestDetailsForSoftDelete(softDeleteRequest);
676
677         cloudOwnerService.enrichRequestWithCloudOwner(requestDetails);
678         return msoBusinessLogic.deactivateAndCloudDelete(serviceInstanceId, vnfInstanceId, vfModuleInstanceId, requestDetails);
679     }
680
681
682     /**
683      * Exception handler.
684      *
685      * @param e        the e
686      * @param response the response
687      * @throws IOException Signals that an I/O exception has occurred.
688      */
689     @ExceptionHandler(Exception.class)
690     private void exceptionHandler(Exception e, HttpServletResponse response) throws IOException {
691
692         ControllersUtils.handleException(e, LOGGER);
693
694         response.setContentType("application/json; charset=UTF-8");
695         response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
696
697         ExceptionResponse exceptionResponse = new ExceptionResponse();
698         exceptionResponse.setException(e.getClass().toString().replaceFirst("^.*\\.", ""));
699         exceptionResponse.setMessage(e.getMessage());
700
701         response.getWriter().write(new ObjectMapper().writeValueAsString(exceptionResponse));
702
703         response.flushBuffer();
704
705     }
706 }