[DCAEGEN2] Calculate slice utilization data
[dcaegen2/services.git] / components / slice-analysis-ms / src / main / java / org / onap / slice / analysis / ms / controller / SliceConfiguraton.java
1 /*******************************************************************************
2  *  ============LICENSE_START=======================================================
3  *  slice-analysis-ms
4  *  ================================================================================
5  *   Copyright (C) 2022 Wipro Limited.
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
22 package org.onap.slice.analysis.ms.controller;
23
24 import org.onap.slice.analysis.ms.models.SliceConfigRequest;
25 import org.onap.slice.analysis.ms.models.SliceConfigResponse;
26 import org.onap.slice.analysis.ms.service.SliceUtilization;
27 import org.springframework.beans.factory.annotation.Autowired;
28 import org.springframework.http.HttpStatus;
29 import org.springframework.http.ResponseEntity;
30 import org.springframework.web.bind.annotation.GetMapping;
31 import org.springframework.web.bind.annotation.RequestBody;
32 import org.springframework.web.bind.annotation.RestController;
33
34 /**
35  * This Controller provides slice configuration details
36  */
37 @RestController
38 public class SliceConfiguraton {
39
40     @Autowired
41     SliceUtilization sliceUtilization;
42
43     /**
44      * This method provides the slice utilization details for requested slices.
45      *
46      * @param sliceConfigRequest contains sliceInstanceId
47      * @return sliceConfigResponse contains slice configuration details
48      */
49     @GetMapping(value = "/api/v1/slices-config")
50     public ResponseEntity<SliceConfigResponse> sliceConfigRequest(@RequestBody SliceConfigRequest sliceConfigRequest) {
51         try {
52             SliceConfigResponse sliceConfigResponse = sliceUtilization.getSliceUtilizationData(sliceConfigRequest);
53             return new ResponseEntity<SliceConfigResponse>(sliceConfigResponse, HttpStatus.OK);
54         } catch (Exception e) {
55             return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
56         }
57     }
58 }