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;
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: <blockquote>HTTP server received an
+ * invalid response from a server it consulted when acting as a proxy or
+ * gateway.</blockquote>
*/
@RestController
@RequestMapping(value = DashboardConstants.ENDPOINT_PREFIX + "/xapp/ac", produces = MediaType.APPLICATION_JSON_VALUE)
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)
*/
@ApiOperation(value = "Gets the admission control policy for AC xApp via the A1 Mediator")
@RequestMapping(value = "admctrl", method = RequestMethod.GET)
- public Object getAdmissionControlPolicy() {
+ public Object getAdmissionControlPolicy(HttpServletResponse response) {
logger.debug("getAdmissionControlPolicy");
- a1MediatorApi.a1ControllerGetHandler(AC_CONTROL_NAME);
+ response.setStatus(HttpServletResponse.SC_NOT_IMPLEMENTED);
return null;
}
/*
- * This controller is deliberately kept ignorant of the
- * ACAdmissionIntervalControl Typescript interface.
+ * 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 admission control policy for AC xApp via the A1 Mediator")
- @RequestMapping(value = "admctrl", method = RequestMethod.PUT)
- public void setAdmissionControlPolicy(@ApiParam(value = "Admission control policy") @RequestBody JsonNode acPolicy, //
+ @RequestMapping(value = "catime", method = RequestMethod.PUT)
+ public Object setAdmissionControlPolicy(
+ @ApiParam(value = "Admission control policy") @RequestBody JsonNode acPolicy, //
HttpServletResponse response) {
logger.debug("setAdmissionControlPolicy {}", acPolicy);
- a1MediatorApi.a1ControllerPutHandler(AC_CONTROL_NAME, acPolicy);
- response.setStatus(a1MediatorApi.getApiClient().getStatusCode().value());
+ 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());
+ }
}
}