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