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%2FXappManagerController.java;h=e5249b195b03ea776a963ee50fb29fd2a1302894;hb=81c5a43871449332f9a9560c7cf25d07cf714d8e;hp=ef1a9186304fbf9920e9ac79c2eeb1104b70d83c;hpb=5577df1ec38f5810920100116ea0b4023f2649ef;p=portal%2Fric-dashboard.git diff --git a/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/controller/XappManagerController.java b/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/controller/XappManagerController.java index ef1a9186..e5249b19 100644 --- a/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/controller/XappManagerController.java +++ b/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/controller/XappManagerController.java @@ -23,8 +23,9 @@ import java.lang.invoke.MethodHandles; import javax.servlet.http.HttpServletResponse; +import org.oransc.ric.portal.dashboard.DashboardApplication; import org.oransc.ric.portal.dashboard.DashboardConstants; -import org.oransc.ric.portal.dashboard.model.ErrorTransport; +import org.oransc.ric.portal.dashboard.model.SuccessTransport; import org.oransc.ric.xappmgr.client.api.HealthApi; import org.oransc.ric.xappmgr.client.api.XappApi; import org.oransc.ric.xappmgr.client.model.AllXapps; @@ -35,19 +36,21 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; import org.springframework.util.Assert; import org.springframework.web.bind.annotation.PathVariable; 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 io.swagger.annotations.ApiOperation; /** - * Mimics the xApp Manager API. These controller methods just proxy calls from - * the front-end thru to the real back-end. - * + * Proxies calls from the front end to the xApp Manager 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.
*/ @Configuration @RestController @@ -64,58 +67,94 @@ public class XappManagerController { public XappManagerController(final HealthApi healthApi, final XappApi xappApi) { Assert.notNull(healthApi, "health API must not be null"); Assert.notNull(xappApi, "xapp API must not be null"); + this.healthApi = healthApi; + this.xappApi = xappApi; if (logger.isDebugEnabled()) logger.debug("ctor: configured with client types {} and {}", healthApi.getClass().getName(), xappApi.getClass().getName()); - this.healthApi = healthApi; - this.xappApi = xappApi; } - @ApiOperation(value = "Calls the xApp Manager health check.") - @RequestMapping(value = "/health", method = RequestMethod.GET) - public void getHealth(HttpServletResponse response) { - logger.debug("getHealt"); - healthApi.getHealth(); - response.setStatus(healthApi.getApiClient().getStatusCode().value()); + @ApiOperation(value = "Gets the XApp manager client library MANIFEST.MF property Implementation-Version.", response = SuccessTransport.class) + @RequestMapping(value = DashboardConstants.VERSION_PATH, method = RequestMethod.GET) + public SuccessTransport getXappManagerClientVersion() { + return new SuccessTransport(200, DashboardApplication.getImplementationVersion(HealthApi.class)); + } + + @ApiOperation(value = "Calls the xApp Manager liveness health check.") + @RequestMapping(value = "/health/alive", method = RequestMethod.GET) + public Object getHealth(HttpServletResponse response) { + logger.debug("getHealthAlive"); + try { + healthApi.getHealthAlive(); + response.setStatus(healthApi.getApiClient().getStatusCode().value()); + return null; + } catch (HttpStatusCodeException ex) { + logger.warn("getHealthAlive failed: {}", ex.toString()); + return ResponseEntity.status(HttpServletResponse.SC_BAD_GATEWAY).body(ex.getResponseBodyAsString()); + } + } + + @ApiOperation(value = "Calls the xApp Manager readiness health check.") + @RequestMapping(value = "/health/ready", method = RequestMethod.GET) + public Object getHealthReady(HttpServletResponse response) { + logger.debug("getHealthReady"); + try { + healthApi.getHealthReady(); + response.setStatus(healthApi.getApiClient().getStatusCode().value()); + return null; + } catch (HttpStatusCodeException ex) { + logger.warn("getHealthReady failed: {}", ex.toString()); + return ResponseEntity.status(HttpServletResponse.SC_BAD_GATEWAY).body(ex.getResponseBodyAsString()); + } } @ApiOperation(value = "Calls the xApp Manager to get the list of xApps.", response = AllXapps.class) @RequestMapping(value = "/xapps", method = RequestMethod.GET) - public AllXapps getAllXapps() { - if (logger.isDebugEnabled()) - logger.debug("getAllXapps via {}", xappApi.getApiClient().getBasePath()); - return xappApi.getAllXapps(); + public Object getAllXapps() { + logger.debug("getAllXapps"); + try { + return xappApi.getAllXapps(); + } catch (HttpStatusCodeException ex) { + logger.warn("getAllXapps failed: {}", ex.toString()); + return ResponseEntity.status(HttpServletResponse.SC_BAD_GATEWAY).body(ex.getResponseBodyAsString()); + } } @ApiOperation(value = "Calls the xApp Manager to get the named xApp.", response = Xapp.class) @RequestMapping(value = "/xapps/{xAppName}", method = RequestMethod.GET) - public Xapp getXapp(@PathVariable("xAppName") String xAppName) { + public Object getXapp(@PathVariable("xAppName") String xAppName) { logger.debug("getXapp {}", xAppName); - return xappApi.getXappByName(xAppName); + try { + return xappApi.getXappByName(xAppName); + } catch (HttpStatusCodeException ex) { + logger.warn("getXapp failed: {}", ex.toString()); + return ResponseEntity.status(HttpServletResponse.SC_BAD_GATEWAY).body(ex.getResponseBodyAsString()); + } } @ApiOperation(value = "Calls the xApp Manager to deploy the specified Xapp.", response = Xapp.class) @RequestMapping(value = "/xapps", method = RequestMethod.POST) - public Object deployXapp(@RequestBody XAppInfo xAppInfo, HttpServletResponse response) { + public Object deployXapp(@RequestBody XAppInfo xAppInfo) { logger.debug("deployXapp {}", xAppInfo); try { return xappApi.deployXapp(xAppInfo); - } catch (Exception ex) { - logger.error("deployXapp failed", ex); - response.setStatus(HttpServletResponse.SC_BAD_REQUEST); - return new ErrorTransport(500, "deployXapp failed", ex); + } catch (HttpStatusCodeException ex) { + logger.warn("deployXapp failed: {}", ex.toString()); + return ResponseEntity.status(HttpServletResponse.SC_BAD_GATEWAY).body(ex.getResponseBodyAsString()); } } @ApiOperation(value = "Calls the xApp Manager to undeploy the named Xapp.") @RequestMapping(value = "/xapps/{xAppName}", method = RequestMethod.DELETE) - public void undeployXapp(@PathVariable("xAppName") String xAppName, HttpServletResponse response) { + public Object undeployXapp(@PathVariable("xAppName") String xAppName, HttpServletResponse response) { logger.debug("undeployXapp {}", xAppName); try { xappApi.undeployXapp(xAppName); - } catch (Exception ex) { - logger.error("deployXapp failed", ex); - response.setStatus(HttpServletResponse.SC_BAD_REQUEST); + response.setStatus(healthApi.getApiClient().getStatusCode().value()); + return null; + } catch (HttpStatusCodeException ex) { + logger.warn("undeployXapp failed: {}", ex.toString()); + return ResponseEntity.status(HttpServletResponse.SC_BAD_GATEWAY).body(ex.getResponseBodyAsString()); } }