Upgrade client API versions to R3 latest
[portal/ric-dashboard.git] / webapp-backend / src / main / java / org / oransc / ric / portal / dashboard / controller / CaasIngressController.java
index c796018..7d91f17 100644 (file)
@@ -2,7 +2,7 @@
  * ========================LICENSE_START=================================
  * O-RAN-SC
  * %%
- * Copyright (C) 2019 AT&T Intellectual Property and Nokia
+ * Copyright (C) 2019 AT&T Intellectual Property
  * %%
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 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());