Merge "Add AC and ANR services"
[portal/ric-dashboard.git] / webapp-backend / src / main / java / org / oransc / ric / portal / dashboard / controller / AcXappController.java
1 /*-
2  * ========================LICENSE_START=================================
3  * O-RAN-SC
4  * %%
5  * Copyright (C) 2019 AT&T Intellectual Property and Nokia
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 package org.oransc.ric.portal.dashboard.controller;
21
22 import java.lang.invoke.MethodHandles;
23
24 import javax.servlet.http.HttpServletResponse;
25
26 import org.oransc.ric.a1med.client.api.A1MediatorApi;
27 import org.oransc.ric.portal.dashboard.DashboardApplication;
28 import org.oransc.ric.portal.dashboard.DashboardConstants;
29 import org.oransc.ric.portal.dashboard.model.SuccessTransport;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32 import org.springframework.beans.factory.annotation.Autowired;
33 import org.springframework.http.MediaType;
34 import org.springframework.util.Assert;
35 import org.springframework.web.bind.annotation.RequestBody;
36 import org.springframework.web.bind.annotation.RequestMapping;
37 import org.springframework.web.bind.annotation.RequestMethod;
38 import org.springframework.web.bind.annotation.RestController;
39
40 import com.fasterxml.jackson.databind.JsonNode;
41
42 import io.swagger.annotations.ApiOperation;
43 import io.swagger.annotations.ApiParam;
44
45 /**
46  * Provides methods to manage policies of the Admission Control xApp, which
47  * initially defines just one. All requests go via the A1 Mediatior.
48  */
49 @RestController
50 @RequestMapping(value = DashboardConstants.ENDPOINT_PREFIX + "/xapp/ac", produces = MediaType.APPLICATION_JSON_VALUE)
51 public class AcXappController {
52
53         private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
54
55         private static final String POLICY_CONTROL_ADMISSION_TIME = "control_admission_time";
56
57         // Populated by the autowired constructor
58         private final A1MediatorApi a1MediatorApi;
59
60         @Autowired
61         public AcXappController(final A1MediatorApi a1MediatorApi) {
62                 Assert.notNull(a1MediatorApi, "API must not be null");
63                 this.a1MediatorApi = a1MediatorApi;
64         }
65
66         @ApiOperation(value = "Gets the A1 client library MANIFEST.MF property Implementation-Version.", response = SuccessTransport.class)
67         @RequestMapping(value = DashboardConstants.VERSION_PATH, method = RequestMethod.GET)
68         public SuccessTransport getVersion() {
69                 logger.debug("getVersion enter");
70                 return new SuccessTransport(200, DashboardApplication.getImplementationVersion(A1MediatorApi.class));
71         }
72
73         /*
74          * GET policy is not supported at present by A1 Mediator. Keeping this hidden
75          * until that changes.
76          *
77          * @ApiOperation(value =
78          * "Gets the named policy for AC xApp via the A1 Mediator")
79          * 
80          * @RequestMapping(value = "policy/{" + POLICY_NAME + "}", method =
81          * RequestMethod.GET) public Object getPolicy(@PathVariable(POLICY_NAME) String
82          * policyName) { logger.debug("getPolicy: policy {}", policyName);
83          * a1MediatorApi.a1ControllerGetHandler(policyName); return null; }
84          */
85
86         /*
87          * This controller is deliberately kept ignorant of the
88          * ACAdmissionIntervalControl data structure.
89          */
90         @ApiOperation(value = "Sets the control admission time for AC xApp via the A1 Mediator")
91         @RequestMapping(value = "catime", method = RequestMethod.PUT)
92         public void setControlAdmissionTime(@ApiParam(value = "Control admission time") @RequestBody JsonNode caTime, //
93                         HttpServletResponse response) {
94                 logger.debug("setControlAdmissionTime {}", caTime);
95                 a1MediatorApi.a1ControllerPutHandler(POLICY_CONTROL_ADMISSION_TIME, caTime);
96                 response.setStatus(a1MediatorApi.getApiClient().getStatusCode().value());
97         }
98
99 }