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