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%2FCaasIngressController.java;h=7d91f17b2a50b5fe8cc87f557845dd1fef90633e;hb=e020df304f6faa1d90f64ddea14407aec1c15dcb;hp=f7224f36bea7f2d6a5c18e2b0dbdcfacd8f8efd9;hpb=44203c43bb16a87eb54cc97431a026e111842c97;p=portal%2Fric-dashboard.git diff --git a/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/controller/CaasIngressController.java b/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/controller/CaasIngressController.java index f7224f36..7d91f17b 100644 --- a/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/controller/CaasIngressController.java +++ b/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/controller/CaasIngressController.java @@ -20,12 +20,11 @@ package org.oransc.ric.portal.dashboard.controller; import java.lang.invoke.MethodHandles; -import java.security.KeyManagementException; -import java.security.NoSuchAlgorithmException; import javax.servlet.http.HttpServletResponse; import org.oransc.ric.portal.dashboard.DashboardConstants; +import org.oransc.ric.portal.dashboard.config.SimpleKubernetesClientBuilder; import org.oransc.ric.portal.dashboard.k8sapi.SimpleKubernetesClient; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -61,44 +60,39 @@ public class CaasIngressController { // Publish constants so tests are easy to write public static final String CONTROLLER_PATH = DashboardConstants.ENDPOINT_PREFIX + "/caas-ingress"; // Endpoints - public static final String PODS_METHOD = "/pods"; + public static final String PODS_METHOD = "pods"; // Path parameters public static final String PP_CLUSTER = "cluster"; public static final String PP_NAMESPACE = "namespace"; // Parameter values - public static final String CLUSTER_AUX = "aux"; public static final String CLUSTER_PLT = "plt"; public static final String CLUSTER_RIC = "ric"; // alternate for PLT - private final SimpleKubernetesClient ciAuxClient; - private final SimpleKubernetesClient ciPltClient; + // Populated by the autowired constructor + private final SimpleKubernetesClientBuilder simpleKubernetesClientBuilder; @Autowired - public CaasIngressController(final SimpleKubernetesClient ciAuxApi, final SimpleKubernetesClient ciPltApi) - throws KeyManagementException, NoSuchAlgorithmException { - Assert.notNull(ciAuxApi, "auxApi must not be null"); - Assert.notNull(ciPltApi, "pltApi must not be null"); - this.ciAuxClient = ciAuxApi; - this.ciPltClient = ciPltApi; + public CaasIngressController(final SimpleKubernetesClientBuilder simpleKubernetesClientBuilder) { + Assert.notNull(simpleKubernetesClientBuilder, "builder must not be null"); + this.simpleKubernetesClientBuilder = simpleKubernetesClientBuilder; if (logger.isDebugEnabled()) - logger.debug("ctor: configured with aux api {}, plt api {}", ciAuxClient.getClass().getName(), - ciPltClient.getClass().getName()); + logger.debug("ctor: configured with builder type {}", simpleKubernetesClientBuilder.getClass().getName()); } /* * No need to parse the V1PodList, just pass thru as a string. */ @ApiOperation(value = "Gets list of pods in the specified cluster for the specified namespace", response = String.class) - @GetMapping(PODS_METHOD + "/" + PP_CLUSTER + "/{" + PP_CLUSTER + "}" + "/" + PP_NAMESPACE + "/{" + PP_NAMESPACE - + "}") + @GetMapping(DashboardConstants.RIC_INSTANCE_KEY + "/{" + DashboardConstants.RIC_INSTANCE_KEY + "}/" + PODS_METHOD + + "/" + PP_CLUSTER + "/{" + PP_CLUSTER + "}" + "/" + PP_NAMESPACE + "/{" + PP_NAMESPACE + "}") @Secured({ DashboardConstants.ROLE_ADMIN, DashboardConstants.ROLE_STANDARD }) - public String listPods(@PathVariable(PP_CLUSTER) String cluster, @PathVariable(PP_NAMESPACE) String namespace, - HttpServletResponse response) { - logger.debug("listPods: cluster {}, namespace {}", cluster, namespace); - if (CLUSTER_AUX.equalsIgnoreCase(cluster)) { - return ciAuxClient.listPods(namespace); - } else if (CLUSTER_PLT.equalsIgnoreCase(cluster) || CLUSTER_RIC.equalsIgnoreCase(cluster)) { - return ciPltClient.listPods(namespace); + public String listPods(@PathVariable(DashboardConstants.RIC_INSTANCE_KEY) String instanceKey, // + @PathVariable(PP_CLUSTER) String cluster, // + @PathVariable(PP_NAMESPACE) String namespace, HttpServletResponse response) { + logger.debug("listPods: instance {} cluster {} namespace {}", instanceKey, cluster, namespace); + SimpleKubernetesClient client = simpleKubernetesClientBuilder.getSimpleKubernetesClient(instanceKey); + if (CLUSTER_PLT.equalsIgnoreCase(cluster) || CLUSTER_RIC.equalsIgnoreCase(cluster)) { + return client.listPods(namespace); } else { logger.warn("listPods: unknown cluster {}", cluster); response.setStatus(HttpStatus.BAD_REQUEST.value());