X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=webapp-backend%2Fsrc%2Fmain%2Fjava%2Forg%2Foransc%2Fric%2Fportal%2Fdashboard%2Fcontroller%2FAcXappController.java;h=279d504a50a074651a52d8e59827d21eb46e7446;hb=81c5a43871449332f9a9560c7cf25d07cf714d8e;hp=87a783cbbfa30de8a35899fc74010949517de9b9;hpb=a4c7cdd075d372de0ab352abc46359d88a570d90;p=portal%2Fric-dashboard.git diff --git a/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/controller/AcXappController.java b/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/controller/AcXappController.java index 87a783cb..279d504a 100644 --- a/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/controller/AcXappController.java +++ b/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/controller/AcXappController.java @@ -31,11 +31,13 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; import org.springframework.util.Assert; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.client.HttpStatusCodeException; import com.fasterxml.jackson.databind.JsonNode; @@ -43,8 +45,10 @@ import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; /** - * Provides methods to manage policies of the Admission Control xApp, which - * initially defines just one. All requests go via the A1 Mediatior. + * * Proxies calls from the front end to the AC xApp via the A1 Mediator API. + * All methods answer 502 on failure:
HTTP server received an + * invalid response from a server it consulted when acting as a proxy or + * gateway.
*/ @RestController @RequestMapping(value = DashboardConstants.ENDPOINT_PREFIX + "/xapp/ac", produces = MediaType.APPLICATION_JSON_VALUE) @@ -52,7 +56,8 @@ public class AcXappController { private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); - private static final String POLICY_CONTROL_ADMISSION_TIME = "control_admission_time"; + // A "control" is an element in the XApp descriptor + private static final String AC_CONTROL_NAME = "admission_control_policy"; // Populated by the autowired constructor private final A1MediatorApi a1MediatorApi; @@ -61,39 +66,45 @@ public class AcXappController { public AcXappController(final A1MediatorApi a1MediatorApi) { Assert.notNull(a1MediatorApi, "API must not be null"); this.a1MediatorApi = a1MediatorApi; + if (logger.isDebugEnabled()) + logger.debug("ctor: configured with client type {}", a1MediatorApi.getClass().getName()); } @ApiOperation(value = "Gets the A1 client library MANIFEST.MF property Implementation-Version.", response = SuccessTransport.class) @RequestMapping(value = DashboardConstants.VERSION_PATH, method = RequestMethod.GET) - public SuccessTransport getVersion() { - logger.debug("getVersion enter"); + public SuccessTransport getA1MediatorClientVersion() { return new SuccessTransport(200, DashboardApplication.getImplementationVersion(A1MediatorApi.class)); } /* - * GET policy is not supported at present by A1 Mediator. Keeping this hidden - * until that changes. - * - * @ApiOperation(value = - * "Gets the named policy for AC xApp via the A1 Mediator") - * - * @RequestMapping(value = "policy/{" + POLICY_NAME + "}", method = - * RequestMethod.GET) public Object getPolicy(@PathVariable(POLICY_NAME) String - * policyName) { logger.debug("getPolicy: policy {}", policyName); - * a1MediatorApi.a1ControllerGetHandler(policyName); return null; } + * GET policy is not supported at present by A1 Mediator! Always returns 501. */ + @ApiOperation(value = "Gets the admission control policy for AC xApp via the A1 Mediator") + @RequestMapping(value = "admctrl", method = RequestMethod.GET) + public Object getAdmissionControlPolicy(HttpServletResponse response) { + logger.debug("getAdmissionControlPolicy"); + response.setStatus(HttpServletResponse.SC_NOT_IMPLEMENTED); + return null; + } /* - * This controller is deliberately kept ignorant of the - * ACAdmissionIntervalControl data structure. + * This controller is deliberately kept ignorant of the data expected by AC. The + * fields are defined in the ACAdmissionIntervalControl Typescript interface. */ - @ApiOperation(value = "Sets the control admission time for AC xApp via the A1 Mediator") + @ApiOperation(value = "Sets the admission control policy for AC xApp via the A1 Mediator") @RequestMapping(value = "catime", method = RequestMethod.PUT) - public void setControlAdmissionTime(@ApiParam(value = "Control admission time") @RequestBody JsonNode caTime, // + public Object setAdmissionControlPolicy( + @ApiParam(value = "Admission control policy") @RequestBody JsonNode acPolicy, // HttpServletResponse response) { - logger.debug("setControlAdmissionTime {}", caTime); - a1MediatorApi.a1ControllerPutHandler(POLICY_CONTROL_ADMISSION_TIME, caTime); - response.setStatus(a1MediatorApi.getApiClient().getStatusCode().value()); + logger.debug("setAdmissionControlPolicy {}", acPolicy); + try { + a1MediatorApi.a1ControllerPutHandler(AC_CONTROL_NAME, acPolicy); + response.setStatus(a1MediatorApi.getApiClient().getStatusCode().value()); + return null; + } catch (HttpStatusCodeException ex) { + logger.warn("setAdmissionControlPolicy failed: {}", ex.toString()); + return ResponseEntity.status(HttpServletResponse.SC_BAD_GATEWAY).body(ex.getResponseBodyAsString()); + } } }