http://git-wip-us.apache.org/repos/asf/stratos/blob/3414e7ce/components/org.apache.stratos.kubernetes.client/src/main/java/org/apache/stratos/kubernetes/client/KubernetesApiClient.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.kubernetes.client/src/main/java/org/apache/stratos/kubernetes/client/KubernetesApiClient.java b/components/org.apache.stratos.kubernetes.client/src/main/java/org/apache/stratos/kubernetes/client/KubernetesApiClient.java index 9a8eb46..112f843 100644 --- a/components/org.apache.stratos.kubernetes.client/src/main/java/org/apache/stratos/kubernetes/client/KubernetesApiClient.java +++ b/components/org.apache.stratos.kubernetes.client/src/main/java/org/apache/stratos/kubernetes/client/KubernetesApiClient.java @@ -20,32 +20,28 @@ */ package org.apache.stratos.kubernetes.client; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; +import io.fabric8.kubernetes.api.KubernetesClient; +import io.fabric8.kubernetes.api.model.*; +import io.fabric8.kubernetes.api.model.resource.Quantity; +import io.fabric8.kubernetes.api.model.util.IntOrString; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.http.HttpStatus; -import org.apache.http.client.utils.URIBuilder; import org.apache.stratos.kubernetes.client.exceptions.KubernetesClientException; import org.apache.stratos.kubernetes.client.interfaces.KubernetesAPIClientInterface; -import org.apache.stratos.kubernetes.client.model.*; -import org.apache.stratos.kubernetes.client.rest.HttpResponse; -import org.apache.stratos.kubernetes.client.rest.RestClient; -import java.net.URI; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; public class KubernetesApiClient implements KubernetesAPIClientInterface { private static final Log log = LogFactory.getLog(KubernetesApiClient.class); - public static final String CONTEXT_PODS = "pods"; - private RestClient restClient; - private String baseURL; + + private KubernetesClient kubernetesClient; public KubernetesApiClient(String endpointUrl) { - restClient = new RestClient(); - baseURL = endpointUrl; + kubernetesClient = new KubernetesClient(endpointUrl); } /** @@ -61,446 +57,96 @@ public class KubernetesApiClient implements KubernetesAPIClientInterface { * @throws KubernetesClientException */ @Override - public void createPod(String podId, String podLabel, String dockerImage, int cpu, int memory, List<Port> ports, - EnvironmentVariable[] environmentVariables) + public void createPod(String podId, String podLabel, String dockerImage, int cpu, int memory, List<ContainerPort> ports, + List<EnvVar> environmentVariables) throws KubernetesClientException { - int memoryInMB = 1024 * 1024 * memory; - if (log.isDebugEnabled()) { - log.debug(String.format("Creating kubernetes pod: [pod-id] %s [pod-name] %s [docker-image] %s " + - "[cpu] %d [memory] %d MB [ports] %s", - podId, podLabel, dockerImage, cpu, memoryInMB, ports)); - } - - // Create pod definition - Pod pod = new Pod(); - pod.setApiVersion(KubernetesConstants.KUBERNETES_API_VERSION); - pod.setId(podId); - pod.setKind(KubernetesConstants.KIND_POD); - - // Set pod labels - Labels podLabels = new Labels(); - podLabels.setName(podLabel); - pod.setLabels(podLabels); - - State desiredState = new State(); - Manifest manifest = new Manifest(); - manifest.setId(podId); - manifest.setVersion(KubernetesConstants.KUBERNETES_API_VERSION); - - // Set container template - Container containerTemplate = new Container(); - containerTemplate.setName(podLabel); - containerTemplate.setImage(dockerImage); - containerTemplate.setCpu(cpu); - containerTemplate.setMemory(memoryInMB); - containerTemplate.setPorts(ports); - containerTemplate.setImagePullPolicy(KubernetesConstants.POLICY_PULL_IF_NOT_PRESENT); - if (environmentVariables != null) { - containerTemplate.setEnv(environmentVariables); - } - - manifest.addContainer(containerTemplate); - desiredState.setManifest(manifest); - pod.setDesiredState(desiredState); - - // Invoke the api to create the pod - createPod(pod); - - if (log.isDebugEnabled()) { - log.debug(String.format("Kubernetes pod created successfully: [pod-id] %s", podId)); - } - } - - @Override - public Pod getPod(String podId) throws KubernetesClientException { - try { - URI uri = new URIBuilder(baseURL + "pods/" + podId).build(); - HttpResponse response = restClient.doGet(uri); - - handleNullResponse(String.format("Could not retrieve kubernetes pod: [pod-id] %s", podId), response); - - if (response.getStatusCode() == HttpStatus.SC_NOT_FOUND) { - return null; - } - - String content = response.getContent(); - - GsonBuilder gsonBuilder = new GsonBuilder(); - Gson gson = gsonBuilder.create(); - return gson.fromJson(content, Pod.class); - } catch (KubernetesClientException e) { - throw e; - } catch (Exception e) { - String msg = String.format("Could not retrieve kubernetes pod: [pod-id] %s", podId); - log.error(msg, e); - throw new KubernetesClientException(msg, e); - } - } - - @Override - public List<Pod> getPods() throws KubernetesClientException { - try { - URI uri = new URIBuilder(baseURL + "pods").build(); - HttpResponse response = restClient.doGet(uri); - - handleNullResponse("Kubernetes pod retrieval failed.", response); - - if (response.getStatusCode() == HttpStatus.SC_NOT_FOUND) { - return null; - } - - String content = response.getContent(); - - GsonBuilder gsonBuilder = new GsonBuilder(); - Gson gson = gsonBuilder.create(); - PodList result = gson.fromJson(content, PodList.class); - - List<Pod> podList = new ArrayList<Pod>(); - if ((result != null) && (result.getItems() != null)) { - for (Pod pod : result.getItems()) { - if (pod != null) { - podList.add(pod); - } - } - } - return podList; - } catch (Exception e) { - String msg = "Error while retrieving kubernetes pods."; - log.error(msg, e); - throw new KubernetesClientException(msg, e); - } - } - - private void createPod(Pod pod) throws KubernetesClientException { - try { - GsonBuilder gsonBuilder = new GsonBuilder(); - Gson gson = gsonBuilder.create(); - String content = gson.toJson(pod); + int memoryInMB = 1024 * 1024 * memory; if (log.isDebugEnabled()) { - log.debug("Create kubernetes pod request body: " + content); + log.debug(String.format("Creating kubernetes pod: [pod-id] %s [pod-name] %s [docker-image] %s " + + "[cpu] %d [memory] %d MB [ports] %s", + podId, podLabel, dockerImage, cpu, memoryInMB, ports)); } - URI uri = new URIBuilder(baseURL + CONTEXT_PODS).build(); - HttpResponse response = restClient.doPost(uri, content); - handleNullResponse(String.format("Could not create kubernetes pod: [pod-id] %s", pod.getId()), response); - if (response.getStatusCode() == HttpStatus.SC_CONFLICT) { - log.warn(String.format("Kubernetes pod already created: [pod-id] %s", pod.getId())); - return; - } + // Create pod definition + Pod pod = new Pod(); + pod.setApiVersion(Pod.ApiVersion.V_1_BETA_3); + pod.setKind(KubernetesConstants.KIND_POD); - if ((response.getStatusCode() < 200) || (response.getStatusCode() >= 300)) { - String msg = String.format("Could not create kubernetes pod: [pod-id] %s [message] %s", pod.getId(), - extractMessageInResponse(response)); - log.error(msg); - throw new KubernetesClientException(msg); - } - } catch (KubernetesClientException e) { - throw e; - } catch (Exception e) { - String msg = String.format("Could not create kubernetes pod: [pod-id] %s", pod.getId()); - log.error(msg, e); - throw new KubernetesClientException(msg, e); - } - } + pod.setSpec(new PodSpec()); + pod.setMetadata(new ObjectMeta()); - @Override - public void deletePod(String podId) throws KubernetesClientException { - try { - if (log.isDebugEnabled()) { - log.debug(String.format("Deleting kubernetes pod: [pod-id] %s", podId)); - } + pod.getMetadata().setName(podId); - URI uri = new URIBuilder(baseURL + "pods/" + podId).build(); - HttpResponse response = restClient.doDelete(uri); + Map<String, String> labels = new HashMap<String, String>(); + labels.put(KubernetesConstants.LABEL_NAME, podLabel); + pod.getMetadata().setLabels(labels); - handleNullResponse("Pod [" + podId + "] deletion failed.", response); + // Set container template + Container containerTemplate = new Container(); + containerTemplate.setName(podLabel); + containerTemplate.setImage(dockerImage); + containerTemplate.setEnv(environmentVariables); + List<Container> containerTemplates = new ArrayList<Container>(); + containerTemplates.add(containerTemplate); + pod.getSpec().setContainers(containerTemplates); + + // Set resource limits + ResourceRequirements resources = new ResourceRequirements(); + Map<String, Quantity> limits = new HashMap<String, Quantity>(); + limits.put(KubernetesConstants.RESOURCE_CPU, new Quantity(String.valueOf(cpu))); + limits.put(KubernetesConstants.RESOURCE_MEMORY, new Quantity(String.valueOf(memoryInMB))); + resources.setLimits(limits); + containerTemplate.setResources(resources); - if (response.getStatusCode() == HttpStatus.SC_NOT_FOUND) { - String message = String.format("Kubernetes pod not found: [pod-id] %s", podId); - log.warn(message); - return; + containerTemplate.setPorts(ports); + containerTemplate.setImagePullPolicy(KubernetesConstants.POLICY_PULL_IF_NOT_PRESENT); + if (environmentVariables != null) { + containerTemplate.setEnv(environmentVariables); } - if ((response.getStatusCode() < 200) || (response.getStatusCode() >= 300)) { - String message = String.format("Could not delete kubernetes pod: [pod-id] %s [message] %s", - podId, extractMessageInResponse(response)); - log.error(message); - throw new KubernetesClientException(message); - } + // Invoke the api to create the pod + kubernetesClient.createPod(pod); if (log.isDebugEnabled()) { - log.debug(String.format("Kubernetes pod deleted successfully: [pod-id] %s", podId)); + log.debug(String.format("Kubernetes pod created successfully: [pod-id] %s", podId)); } - } catch (KubernetesClientException e) { - throw e; } catch (Exception e) { - String message = String.format("Could not delete kubernetes pod: [pod-id] %s", podId); - log.error(message, e); - throw new KubernetesClientException(message, e); - } - } - - @Override - public ReplicationController getReplicationController(String replicationControllerId) - throws KubernetesClientException { - - try { - URI uri = new URIBuilder(baseURL + "replicationControllers/" + replicationControllerId).build(); - HttpResponse response = restClient.doGet(uri); - - handleNullResponse(String.format("Could not retrieve kubernetes replication controller: " + - "[replication-controller-id] %s", replicationControllerId), response); - - if (response.getStatusCode() == HttpStatus.SC_NOT_FOUND) { - return null; - } - - String content = response.getContent(); - - GsonBuilder gsonBuilder = new GsonBuilder(); - Gson gson = gsonBuilder.create(); - return gson.fromJson(content, ReplicationController.class); - } catch (KubernetesClientException e) { - throw e; - } catch (Exception e) { - String msg = "Error while retrieving kubernetes replication controller: " + replicationControllerId; + String msg = String.format("Could not create kubernetes pod: [pod-id] %s", podId); log.error(msg, e); throw new KubernetesClientException(msg, e); } } @Override - public List<ReplicationController> getReplicationControllers() throws KubernetesClientException { - + public Pod getPod(String podId) throws KubernetesClientException { try { - URI uri = new URIBuilder(baseURL + "replicationControllers").build(); - HttpResponse response = restClient.doGet(uri); - - handleNullResponse("Could not retrieve kubernetes replication controllers", response); - - if (response.getStatusCode() == HttpStatus.SC_NOT_FOUND) { - return null; - } - - String content = response.getContent(); - - GsonBuilder gsonBuilder = new GsonBuilder(); - Gson gson = gsonBuilder.create(); - ReplicationControllerList controllerList = gson.fromJson(content, ReplicationControllerList.class); - - List<ReplicationController> replicationControllers = new ArrayList<ReplicationController>(); - if ((controllerList != null) && (controllerList.getItems() != null)) { - for (ReplicationController replicationController : controllerList.getItems()) { - if (replicationController != null) { - replicationControllers.add(replicationController); - } - } - } - return replicationControllers; + return kubernetesClient.getPod(podId); } catch (Exception e) { - String msg = "Error while retrieving kubernetes replication controllers"; + String msg = String.format("Could not retrieve kubernetes pod: [pod-id] %s", podId); log.error(msg, e); throw new KubernetesClientException(msg, e); } } @Override - public void createReplicationController(String replicationControllerId, String replicationControllerName, - String dockerImage, List<Port> ports, - EnvironmentVariable[] environmentVariables, int replicas) throws KubernetesClientException { - try { - if (log.isDebugEnabled()) { - log.debug(String.format("Creating kubernetes replication controller: [replication-controller] %s [name] %s " + - "[docker-image] %s [ports] %s [replicas] %d", replicationControllerId, replicationControllerName, - dockerImage, ports, replicas)); - } - - // Create replication controller - ReplicationController replicationController = new ReplicationController(); - replicationController.setId(replicationControllerId); - replicationController.setKind(KubernetesConstants.KIND_REPLICATION_CONTROLLER); - replicationController.setApiVersion(KubernetesConstants.KUBERNETES_API_VERSION); - - // Set replication controller state - State replicationControllerDesiredState = new State(); - replicationControllerDesiredState.setReplicas(replicas); - Selector replicationControllerSelector = new Selector(); - replicationControllerSelector.setName(replicationControllerName); - replicationControllerDesiredState.setReplicaSelector(replicationControllerSelector); - - // Create pod template - Pod podTemplate = new Pod(); - State desiredPodState = new State(); - - Manifest manifest = new Manifest(); - manifest.setVersion(KubernetesConstants.KUBERNETES_API_VERSION); - manifest.setId(replicationControllerId); - - // Create container template - Container containerTemplate = new Container(); - containerTemplate.setName(replicationControllerName); - containerTemplate.setImage(dockerImage); - containerTemplate.setImagePullPolicy(KubernetesConstants.POLICY_PULL_IF_NOT_PRESENT); - if (environmentVariables != null) { - containerTemplate.setEnv(environmentVariables); - } - - // Set container ports - containerTemplate.setPorts(ports); - manifest.addContainer(containerTemplate); - - desiredPodState.setManifest(manifest); - podTemplate.setDesiredState(desiredPodState); - - // Set pod template labels - Labels podTemplateLabels = new Labels(); - podTemplateLabels.setName(replicationControllerName); - podTemplate.setLabels(podTemplateLabels); - - replicationControllerDesiredState.setPodTemplate(podTemplate); - replicationController.setDesiredState(replicationControllerDesiredState); - - Labels replicationControllerLabels = new Labels(); - replicationControllerLabels.setName(replicationControllerName); - replicationController.setLabels(replicationControllerLabels); - - // Invoke the api to create the replicate controller - createReplicationController(replicationController); - - if (log.isDebugEnabled()) { - log.debug(String.format("Kubernetes replication controller created successfully: [replication-controller-id] " + - "%s [name] %s [docker-image] %s [port-mappings] %s [replicas] %d", - replicationControllerId, replicationControllerName, dockerImage, ports, replicas)); - } - } catch (Exception e) { - String message = "Could not create kubernetes replication controller: [replication-controller-id] " + replicationControllerId; - log.error(message, e); - throw new KubernetesClientException(message, e); - } - } - - private void createReplicationController(ReplicationController replicationController) - throws KubernetesClientException { - + public List<Pod> getPods() throws KubernetesClientException { try { - GsonBuilder gsonBuilder = new GsonBuilder(); - Gson gson = gsonBuilder.create(); - String content = gson.toJson(replicationController); - if (log.isDebugEnabled()) { - log.debug("CreateReplicationController request body : " + content); - } - - URI uri = new URIBuilder(baseURL + "replicationControllers").build(); - HttpResponse response = restClient.doPost(uri, content); - - handleNullResponse("Could not create kubernetes replication controller: [replication-controller-id] " + - replicationController.getId(), response); - - if (response.getStatusCode() == HttpStatus.SC_CONFLICT) { - log.warn("Kubernetes replication controller already created: [replication-controller-id] " + replicationController.getId()); - return; - } - - if ((response.getStatusCode() < 200) || (response.getStatusCode() >= 300)) { - String message = "Could not create kubernetes replication controller: [replication-controller-id] " + - replicationController.getId() + " [message] " + extractMessageInResponse(response); - log.error(message); - throw new KubernetesClientException(message); - } - - } catch (KubernetesClientException e) { - throw e; + return kubernetesClient.getPods().getItems(); } catch (Exception e) { - String msg = "Error while creating kubernetes replication controller: " - + replicationController; + String msg = "Error while retrieving kubernetes pods."; log.error(msg, e); throw new KubernetesClientException(msg, e); } } @Override - public void updateReplicationController(ReplicationController replicationController) - throws KubernetesClientException { - - try { - GsonBuilder gsonBuilder = new GsonBuilder(); - Gson gson = gsonBuilder.create(); - String content = gson.toJson(replicationController); - if (log.isDebugEnabled()) { - log.debug("Update kubernetes replication controller request body: " - + content); - } - - URI uri = new URIBuilder(baseURL + "replicationControllers/" + replicationController.getId()).build(); - HttpResponse response = restClient.doPut(uri, content); - - handleNullResponse("Could not update kubernetes replication controller: [replication-controller-id] " + - replicationController.getId(), response); - - if ((response.getStatusCode() < 200) || (response.getStatusCode() >= 300)) { - String message = "Could not update kubernetes replication controller: [replication-controller-id] " + - replicationController.getId() + ": " + response.getReason(); - log.error(message); - throw new KubernetesClientException(message); - } - - } catch (KubernetesClientException e) { - String message = "Could not update kubernetes replication controller: [replication-controller-id] " + - replicationController.getId(); - log.error(message, e); - throw e; - } catch (Exception e) { - String message = "Could not update kubernetes replication controller: [replication-controller-id] " + - replicationController.getId(); - log.error(message, e); - throw new KubernetesClientException(message, e); - } - } - - @Override - public void deleteReplicationController(String replicationControllerId) - throws KubernetesClientException { - + public void deletePod(String podId) throws KubernetesClientException { try { - if (log.isDebugEnabled()) { - log.debug("Deleting replication controller: [replication-controller-id] " + - replicationControllerId); - } - - URI uri = new URIBuilder(baseURL + "replicationControllers/" + replicationControllerId).build(); - HttpResponse response = restClient.doDelete(uri); - - handleNullResponse("Could not delete kubernetes replication controller: [replication-controller-id] " + - replicationControllerId, response); - - if (response.getStatusCode() == HttpStatus.SC_NOT_FOUND) { - String message = "Kubernetes replication controller does not exist: [replication-controller-id] " - + replicationControllerId; - log.warn(message); - return; - } - - if ((response.getStatusCode() < 200) || (response.getStatusCode() >= 300)) { - String message = "Could not delete kubernetes replication controller: [replication-controller-id] " + - replicationControllerId + ": " + response.getReason(); - log.error(message); - throw new KubernetesClientException(message); - } - - if (log.isDebugEnabled()) { - log.debug("Kubernetes replication controller deleted successfully: [replication-controller-id] " + - replicationControllerId); - } - } catch (KubernetesClientException e) { - String message = "Could not delete kubernetes replication controller: [replication-controller-id] " + - replicationControllerId; - log.error(message, e); - throw e; + kubernetesClient.deletePod(podId); } catch (Exception e) { - String message = "Could not delete kubernetes replication controller: [replication-controller-id] " + - replicationControllerId; + String message = String.format("Could not delete kubernetes pod: [pod-id] %s", podId); log.error(message, e); throw new KubernetesClientException(message, e); } @@ -513,14 +159,17 @@ public class KubernetesApiClient implements KubernetesAPIClientInterface { * @param serviceLabel Service name to be used by the label name * @param servicePort Port to be exposed by the service * @param containerPortName Container port name defined in the port label + * @param containerPort Container port * @param publicIPs Public IP addresses of the minions * @param sessionAffinity Session affinity configuration * @throws KubernetesClientException */ @Override public void createService(String serviceId, String serviceLabel, int servicePort, - String containerPortName, String[] publicIPs, String sessionAffinity) + String containerPortName, int containerPort, List<String> publicIPs, + String sessionAffinity) throws KubernetesClientException { + try { if (log.isDebugEnabled()) { log.debug(String.format("Creating kubernetes service: [service-id] %s [service-name] %s [service-port] %d " + @@ -530,27 +179,37 @@ public class KubernetesApiClient implements KubernetesAPIClientInterface { // Create service definition Service service = new Service(); - service.setApiVersion(KubernetesConstants.KUBERNETES_API_VERSION); + service.setSpec(new ServiceSpec()); + service.setMetadata(new ObjectMeta()); + + service.setApiVersion(Service.ApiVersion.V_1_BETA_3); service.setKind(KubernetesConstants.KIND_SERVICE); - service.setId(serviceId); - service.setPort(servicePort); - service.setPublicIPs(publicIPs); - service.setContainerPort(containerPortName); - service.setSessionAffinity(sessionAffinity); - - // Set service labels - Labels serviceLabels = new Labels(); - serviceLabels.setName(serviceLabel); - service.setLabels(serviceLabels); - service.setName(serviceLabel); + + service.getMetadata().setName(serviceId); + service.getSpec().setPublicIPs(publicIPs); + service.getSpec().setSessionAffinity(sessionAffinity); + + // Set port + List<ServicePort> ports = new ArrayList<ServicePort>(); + ServicePort port = new ServicePort(); + port.setName(containerPortName); + port.setPort(servicePort); + port.setTargetPort(new IntOrString(containerPort)); + ports.add(port); + service.getSpec().setPorts(ports); + + // Set label + Map<String, String> labels = new HashMap<String, String>(); + labels.put(KubernetesConstants.LABEL_NAME, serviceLabel); + service.getMetadata().setLabels(labels); // Set service selector - Selector selector = new Selector(); - selector.setName(serviceLabels.getName()); - service.setSelector(selector); + Map<String, String> selector = new HashMap<String, String>(); + selector.put(KubernetesConstants.LABEL_NAME, serviceLabel); + service.getSpec().setSelector(selector); // Invoke the api to create the service - createService(service); + kubernetesClient.createService(service); if (log.isDebugEnabled()) { log.debug(String.format("Kubernetes service created successfully: [service-id] %s [service-name] %s [service-port] %d " + @@ -568,22 +227,7 @@ public class KubernetesApiClient implements KubernetesAPIClientInterface { public Service getService(String serviceId) throws KubernetesClientException { try { - URI uri = new URIBuilder(baseURL + "services/" + serviceId).build(); - HttpResponse response = restClient.doGet(uri); - - handleNullResponse(String.format("Could not retrieve kubernetes service: [service-id] %s", serviceId), response); - - if (response.getStatusCode() == HttpStatus.SC_NOT_FOUND) { - return null; - } - - String content = response.getContent(); - - GsonBuilder gsonBuilder = new GsonBuilder(); - Gson gson = gsonBuilder.create(); - return gson.fromJson(content, Service.class); - } catch (KubernetesClientException e) { - throw e; + return kubernetesClient.getService(serviceId); } catch (Exception e) { String msg = String.format("Could not retrieve kubernetes service: [service-id] %s", serviceId); log.error(msg, e); @@ -594,31 +238,7 @@ public class KubernetesApiClient implements KubernetesAPIClientInterface { @Override public List<Service> getServices() throws KubernetesClientException { try { - - URI uri = new URIBuilder(baseURL + "services").build(); - HttpResponse response = restClient.doGet(uri); - - handleNullResponse("Service retrieval failed.", response); - - if (response.getStatusCode() == HttpStatus.SC_NOT_FOUND) { - return null; - } - - String content = response.getContent(); - - GsonBuilder gsonBuilder = new GsonBuilder(); - Gson gson = gsonBuilder.create(); - ServiceList result = gson.fromJson(content, ServiceList.class); - - List<Service> serviceList = new ArrayList<Service>(); - if ((result != null) && (result.getItems() != null)) { - for (Service pod : result.getItems()) { - if (pod != null) { - serviceList.add(pod); - } - } - } - return serviceList; + return kubernetesClient.getServices().getItems(); } catch (Exception e) { String msg = "Could not retrieve kubernetes services"; log.error(msg, e); @@ -626,42 +246,6 @@ public class KubernetesApiClient implements KubernetesAPIClientInterface { } } - private void createService(Service service) throws KubernetesClientException { - - try { - GsonBuilder gsonBuilder = new GsonBuilder(); - Gson gson = gsonBuilder.create(); - String content = gson.toJson(service); - if (log.isDebugEnabled()) { - log.debug("CreateService Request Body : " + content); - } - - URI uri = new URIBuilder(baseURL + "services").build(); - HttpResponse response = restClient.doPost(uri, content); - - handleNullResponse(String.format("Could not create kubernetes service: [service-id] %s", service.getId()), response); - - if (response.getStatusCode() == HttpStatus.SC_CONFLICT) { - log.warn("Service already created: [service-id] " + service.getId()); - return; - } - - if ((response.getStatusCode() < 200) || (response.getStatusCode() >= 300)) { - String msg = String.format("Could not create kubernetes service: [service-id] %s [message] %s", service.getId(), - extractMessageInResponse(response)); - log.error(msg); - throw new KubernetesClientException(msg); - } - } catch (KubernetesClientException e) { - throw e; - - } catch (Exception e) { - String msg = "Could not create kubernetes service: [service-id] " + service.getId(); - log.error(msg, e); - throw new KubernetesClientException(msg, e); - } - } - @Override public void deleteService(String serviceId) throws KubernetesClientException { @@ -671,93 +255,15 @@ public class KubernetesApiClient implements KubernetesAPIClientInterface { log.debug(String.format("Deleting kubernetes service: [service-id] %s", serviceId)); } - URI uri = new URIBuilder(baseURL + "services/" + serviceId).build(); - HttpResponse response = restClient.doDelete(uri); - - handleNullResponse(String.format("Could not delete kubernetes service: [service-id] %s", serviceId), response); - - if (response.getStatusCode() == HttpStatus.SC_NOT_FOUND) { - String msg = String.format("Service not found: [service-id] %s", serviceId); - log.warn(msg); - return; - } - - if ((response.getStatusCode() < 200) || (response.getStatusCode() >= 300)) { - String msg = String.format("Could not delete kubernetes service: [service-id] %s [message] %s", serviceId, - extractMessageInResponse(response)); - log.error(msg); - throw new KubernetesClientException(msg); - } + kubernetesClient.deleteService(serviceId); if (log.isDebugEnabled()) { log.debug(String.format("Kubernetes service deleted successfully: [service-id] %s", serviceId)); } - } catch (KubernetesClientException e) { - throw e; - } catch (Exception e) { String msg = String.format("Could not delete kubernetes service: [service-id] %s", serviceId); log.error(msg, e); throw new KubernetesClientException(msg, e); } } - - @Override - public List<Pod> queryPods(Labels[] labels) throws KubernetesClientException { - - try { - String labelQuery = getLabelQuery(labels); - URI uri = new URIBuilder(baseURL + "pods").addParameter("labels", labelQuery).build(); - HttpResponse response = restClient.doGet(uri); - - handleNullResponse(String.format("Could not retrieve kubernetes pods: [labels] %s", labels), response); - - if (response.getStatusCode() == HttpStatus.SC_NOT_FOUND) { - return null; - } - - String content = response.getContent(); - GsonBuilder gsonBuilder = new GsonBuilder(); - Gson gson = gsonBuilder.create(); - PodList result = gson.fromJson(content, PodList.class); - - List<Pod> podList = new ArrayList<Pod>(); - if ((result != null) && (result.getItems() != null)) { - for (Pod pod : result.getItems()) { - if (pod != null) { - podList.add(pod); - } - } - } - return podList; - } catch (Exception e) { - String msg = String.format("Could not retrieve kubernetes pods: [labels] %s", labels); - log.error(msg, e); - throw new KubernetesClientException(msg, e); - } - } - - private String getLabelQuery(Labels[] labels) { - String query = ""; - for (Labels l : labels) { - query = query.concat("name=" + l.getName() + ","); - } - return query.endsWith(",") ? query.substring(0, query.length() - 1) : query; - } - - private void handleNullResponse(String message, HttpResponse response) - throws KubernetesClientException { - if (response == null) { - log.error(message + ", a null response received"); - throw new KubernetesClientException(message); - } - } - - private String extractMessageInResponse(HttpResponse response) { - if ((response != null) && (response.getKubernetesResponse() != null)) { - return response.getKubernetesResponse().getMessage(); - } else { - return ""; - } - } }
http://git-wip-us.apache.org/repos/asf/stratos/blob/3414e7ce/components/org.apache.stratos.kubernetes.client/src/main/java/org/apache/stratos/kubernetes/client/KubernetesConstants.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.kubernetes.client/src/main/java/org/apache/stratos/kubernetes/client/KubernetesConstants.java b/components/org.apache.stratos.kubernetes.client/src/main/java/org/apache/stratos/kubernetes/client/KubernetesConstants.java index 422a9f2..4b5210a 100644 --- a/components/org.apache.stratos.kubernetes.client/src/main/java/org/apache/stratos/kubernetes/client/KubernetesConstants.java +++ b/components/org.apache.stratos.kubernetes.client/src/main/java/org/apache/stratos/kubernetes/client/KubernetesConstants.java @@ -25,10 +25,11 @@ package org.apache.stratos.kubernetes.client; public class KubernetesConstants { public static final String POD_STATUS_RUNNING = "Running"; - public static final String KUBERNETES_API_VERSION = "v1beta1"; - public static final String KIND_SERVICE = "Service"; - public static final String KIND_REPLICATION_CONTROLLER = "ReplicationController"; - public static final String KIND_POD = "Pod"; - public static final String POLICY_PULL_IF_NOT_PRESENT = "PullIfNotPresent"; + public static final String POLICY_PULL_IF_NOT_PRESENT = "IfNotPresent"; public static final String SESSION_AFFINITY_CLIENT_IP = "ClientIP"; + public static final String KIND_POD = "Pod"; + public static final String KIND_SERVICE = "Service"; + public static final String LABEL_NAME = "name"; + public static final String RESOURCE_CPU = "cpu"; + public static final String RESOURCE_MEMORY = "memory"; } http://git-wip-us.apache.org/repos/asf/stratos/blob/3414e7ce/components/org.apache.stratos.kubernetes.client/src/main/java/org/apache/stratos/kubernetes/client/interfaces/KubernetesAPIClientInterface.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.kubernetes.client/src/main/java/org/apache/stratos/kubernetes/client/interfaces/KubernetesAPIClientInterface.java b/components/org.apache.stratos.kubernetes.client/src/main/java/org/apache/stratos/kubernetes/client/interfaces/KubernetesAPIClientInterface.java index efcc239..26772fc 100644 --- a/components/org.apache.stratos.kubernetes.client/src/main/java/org/apache/stratos/kubernetes/client/interfaces/KubernetesAPIClientInterface.java +++ b/components/org.apache.stratos.kubernetes.client/src/main/java/org/apache/stratos/kubernetes/client/interfaces/KubernetesAPIClientInterface.java @@ -20,9 +20,11 @@ */ package org.apache.stratos.kubernetes.client.interfaces; +import io.fabric8.kubernetes.api.model.ContainerPort; +import io.fabric8.kubernetes.api.model.EnvVar; +import io.fabric8.kubernetes.api.model.Pod; +import io.fabric8.kubernetes.api.model.Service; import org.apache.stratos.kubernetes.client.exceptions.KubernetesClientException; -import org.apache.stratos.kubernetes.client.model.*; - import java.util.List; @@ -37,10 +39,11 @@ public interface KubernetesAPIClientInterface { * @param cpu number of cpu cores * @param memory memory allocation in mega bytes * @param ports ports to be opened + * @param environmentVariables environment variables * @throws KubernetesClientException */ - public void createPod(String podId, String podLabel, String dockerImage, int cpu, int memory, List<Port> ports, - EnvironmentVariable[] environmentVariables) + public void createPod(String podId, String podLabel, String dockerImage, int cpu, int memory, + List<ContainerPort> ports, List<EnvVar> environmentVariables) throws KubernetesClientException; /** @@ -61,15 +64,6 @@ public interface KubernetesAPIClientInterface { public List<Pod> getPods() throws KubernetesClientException; /** - * Run a label query and retrieve a sub set of Pods. - * - * @param labels of labels for the label query - * @return Pods selected Pods by executing the label query. - * @throws KubernetesClientException - */ - public List<Pod> queryPods(Labels[] labels) throws KubernetesClientException; - - /** * Delete a Pod * * @param podId Id of the Pod to be deleted @@ -78,68 +72,21 @@ public interface KubernetesAPIClientInterface { public void deletePod(String podId) throws KubernetesClientException; /** - * Create replication controller. - * - * @param replicationControllerId - * @param replicationControllerName - * @param dockerImage - * @param ports - * @param replicas - * @throws KubernetesClientException - */ - public void createReplicationController(String replicationControllerId, - String replicationControllerName, - String dockerImage, - List<Port> ports, - EnvironmentVariable[] environmentVariables, - int replicas) throws KubernetesClientException; - - /** - * Get a Replication Controller Info - * - * @param controllerId id of the Replication Controller - * @return {@link ReplicationController} - * @throws KubernetesClientException - */ - public ReplicationController getReplicationController(String controllerId) throws KubernetesClientException; - - /** - * Get all Replication Controllers. - * - * @return {@link ReplicationController}s - * @throws KubernetesClientException - */ - public List<ReplicationController> getReplicationControllers() throws KubernetesClientException; - - /** - * Update a Replication Controller (update the number of replicas). - * - * @param replicationController replication controller to be updated - * @throws KubernetesClientException - */ - public void updateReplicationController(ReplicationController replicationController) throws KubernetesClientException; - - /** - * Delete a Replication Controller. - * - * @param replicationControllerId controller id controller id to be deleted. - * @throws KubernetesClientException - */ - public void deleteReplicationController(String replicationControllerId) throws KubernetesClientException; - - /** * Create service. * * @param serviceId * @param serviceLabel * @param servicePort * @param containerPortName + * @param containerPort * @param publicIPs * @param sessionAffinity * @throws KubernetesClientException */ public void createService(String serviceId, String serviceLabel, int servicePort, - String containerPortName, String[] publicIPs, String sessionAffinity) throws KubernetesClientException; + String containerPortName, int containerPort, List<String> publicIPs, + String sessionAffinity) + throws KubernetesClientException; /** * Get the Service with the given id. http://git-wip-us.apache.org/repos/asf/stratos/blob/3414e7ce/components/org.apache.stratos.kubernetes.client/src/main/java/org/apache/stratos/kubernetes/client/model/Container.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.kubernetes.client/src/main/java/org/apache/stratos/kubernetes/client/model/Container.java b/components/org.apache.stratos.kubernetes.client/src/main/java/org/apache/stratos/kubernetes/client/model/Container.java deleted file mode 100644 index fd8d591..0000000 --- a/components/org.apache.stratos.kubernetes.client/src/main/java/org/apache/stratos/kubernetes/client/model/Container.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.apache.stratos.kubernetes.client.model; - -import org.apache.commons.lang3.ArrayUtils; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -public class Container { - - private String name; - private String image; - private int cpu; - private int memory; - private String workingDir; - private String[] command; - private VolumeMount[] volumeMounts; - private List<Port> ports; - private String imagePullPolicy; - private EnvironmentVariable[] env; - - public Container() { - ports = new ArrayList<Port>(); - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getImage() { - return image; - } - - public void setImage(String image) { - this.image = image; - } - - - public int getCpu() { - return cpu; - } - - public void setCpu(int cpu) { - this.cpu = cpu; - } - - public int getMemory() { - return memory; - } - - public void setMemory(int memory) { - this.memory = memory; - } - - public String getWorkingDir() { - return workingDir; - } - - public void setWorkingDir(String workingDir) { - this.workingDir = workingDir; - } - - public String[] getCommand() { - return command; - } - - public void setCommand(String[] command) { - this.command = ArrayUtils.clone(command); - } - - public VolumeMount[] getVolumeMounts() { - return volumeMounts; - } - - public void setVolumeMounts(VolumeMount[] volumeMounts) { - this.volumeMounts = ArrayUtils.clone(volumeMounts); - } - - public List<Port> getPorts() { - return ports; - } - - public void addPort(Port port) { - this.ports.add(port); - } - - public void setPorts(List<Port> ports) { - this.ports = ports; - } - - public EnvironmentVariable[] getEnv() { - return env; - } - - public void setEnv(EnvironmentVariable[] env) { - this.env = ArrayUtils.clone(env); - } - - @Override - public String toString() { - return "Container [name=" + name + - ", image=" + image + - ", cpu=" + cpu + - ", memory=" + memory + - ", workingDir=" + workingDir + - ", command=" + Arrays.toString(command) + - ", volumeMounts=" + Arrays.toString(volumeMounts) + - ", ports=" + ports + - ", env=" + Arrays.toString(env) + "]"; - } - - public String getImagePullPolicy() { - return imagePullPolicy; - } - - public void setImagePullPolicy(String imagePullPolicy) { - this.imagePullPolicy = imagePullPolicy; - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/3414e7ce/components/org.apache.stratos.kubernetes.client/src/main/java/org/apache/stratos/kubernetes/client/model/EnvironmentVariable.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.kubernetes.client/src/main/java/org/apache/stratos/kubernetes/client/model/EnvironmentVariable.java b/components/org.apache.stratos.kubernetes.client/src/main/java/org/apache/stratos/kubernetes/client/model/EnvironmentVariable.java deleted file mode 100644 index 0515b5e..0000000 --- a/components/org.apache.stratos.kubernetes.client/src/main/java/org/apache/stratos/kubernetes/client/model/EnvironmentVariable.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.apache.stratos.kubernetes.client.model; - -public class EnvironmentVariable { - - private String name; - private String value; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getValue() { - return value; - } - - public void setValue(String value) { - this.value = value; - } - - @Override - public String toString() { - return "EnvironmentVariable [name=" + name + ", value=" + value + "]"; - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/3414e7ce/components/org.apache.stratos.kubernetes.client/src/main/java/org/apache/stratos/kubernetes/client/model/Labels.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.kubernetes.client/src/main/java/org/apache/stratos/kubernetes/client/model/Labels.java b/components/org.apache.stratos.kubernetes.client/src/main/java/org/apache/stratos/kubernetes/client/model/Labels.java deleted file mode 100644 index 4ced7d1..0000000 --- a/components/org.apache.stratos.kubernetes.client/src/main/java/org/apache/stratos/kubernetes/client/model/Labels.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.apache.stratos.kubernetes.client.model; - -import java.io.Serializable; - -/** - * Labels can contain a list of key/value pairs. Currently we are only using one key/value pair: name/value. - */ -public class Labels implements Serializable { - - private static final long serialVersionUID = -9019445613544931617L; - - private String name; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - @Override - public String toString() { - return "Label [name=" + name + "]"; - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/3414e7ce/components/org.apache.stratos.kubernetes.client/src/main/java/org/apache/stratos/kubernetes/client/model/Manifest.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.kubernetes.client/src/main/java/org/apache/stratos/kubernetes/client/model/Manifest.java b/components/org.apache.stratos.kubernetes.client/src/main/java/org/apache/stratos/kubernetes/client/model/Manifest.java deleted file mode 100644 index 7a3161e..0000000 --- a/components/org.apache.stratos.kubernetes.client/src/main/java/org/apache/stratos/kubernetes/client/model/Manifest.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.apache.stratos.kubernetes.client.model; - -import java.util.ArrayList; -import java.util.List; - -/** - * https://github.com/GoogleCloudPlatform/kubernetes/blob/master/api/doc/manifest-schema.json - */ -public class Manifest { - - private String version; - private String id; - private List<Container> containers; - private List<Volume> volumes; - - public Manifest() { - containers = new ArrayList<Container>(); - volumes = new ArrayList<Volume>(); - } - - public String getVersion() { - return version; - } - - public void setVersion(String version) { - this.version = version; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public List<Container> getContainers() { - return containers; - } - - public void addContainer(Container container) { - containers.add(container); - } - - public List<Volume> getVolumes() { - return volumes; - } - - public void addVolume(Volume volume) { - volumes.add(volume); - } - - @Override - public String toString() { - return "Manifest [version=" + version + ", id=" + id + ", containers=" - + containers + ", volumes=" - + volumes + "]"; - } - -} http://git-wip-us.apache.org/repos/asf/stratos/blob/3414e7ce/components/org.apache.stratos.kubernetes.client/src/main/java/org/apache/stratos/kubernetes/client/model/Pod.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.kubernetes.client/src/main/java/org/apache/stratos/kubernetes/client/model/Pod.java b/components/org.apache.stratos.kubernetes.client/src/main/java/org/apache/stratos/kubernetes/client/model/Pod.java deleted file mode 100644 index 9292b4f..0000000 --- a/components/org.apache.stratos.kubernetes.client/src/main/java/org/apache/stratos/kubernetes/client/model/Pod.java +++ /dev/null @@ -1,175 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.apache.stratos.kubernetes.client.model; - -import javax.xml.bind.annotation.XmlRootElement; - -/** - * https://github.com/GoogleCloudPlatform/kubernetes/blob/master/api/doc/pod-schema.json - */ -@XmlRootElement -public class Pod { - - private String kind; - private String id; - private String creationTimestamp; - private String selfLink; - private String resourceVersion; - private String apiVersion; - private State desiredState; - private State currentState; - private String status; - private String message; - private String code; - private Labels labels; - - public String getKind() { - return kind; - } - - public void setKind(String kind) { - this.kind = kind; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getCreationTimestamp() { - return creationTimestamp; - } - - public void setCreationTimestamp(String creationTimestamp) { - this.creationTimestamp = creationTimestamp; - } - - public String getSelfLink() { - return selfLink; - } - - public void setSelfLink(String selfLink) { - this.selfLink = selfLink; - } - - public State getDesiredState() { - return desiredState; - } - - public void setDesiredState(State desiredState) { - this.desiredState = desiredState; - } - - public State getCurrentState() { - return currentState; - } - - public void setCurrentState(State currentState) { - this.currentState = currentState; - } - - public String getResourceVersion() { - return resourceVersion; - } - - public void setResourceVersion(String resourceVersion) { - this.resourceVersion = resourceVersion; - } - - public String getApiVersion() { - return apiVersion; - } - - public void setApiVersion(String apiVersion) { - this.apiVersion = apiVersion; - } - - public Labels getLabels() { - return labels; - } - - public void setLabels(Labels labels) { - this.labels = labels; - } - - public String getStatus() { - return status; - } - - public void setStatus(String status) { - this.status = status; - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - public String getCode() { - return code; - } - - public void setCode(String code) { - this.code = code; - } - - @Override - public String toString() { - return "Pod [kind=" + kind + ", id=" + id + ", creationTimestamp=" - + creationTimestamp + ", selfLink=" + selfLink - + ", resourceVersion=" + resourceVersion + ", apiVersion=" - + apiVersion + ", desiredState=" + desiredState - + ", currentState=" + currentState + ", status=" + status - + ", message=" + message + ", code=" + code + ", labels=" - + labels + "]"; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((id == null) ? 0 : id.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - Pod other = (Pod) obj; - if (id == null) { - if (other.id != null) - return false; - } else if (!id.equals(other.id)) - return false; - return true; - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/3414e7ce/components/org.apache.stratos.kubernetes.client/src/main/java/org/apache/stratos/kubernetes/client/model/PodList.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.kubernetes.client/src/main/java/org/apache/stratos/kubernetes/client/model/PodList.java b/components/org.apache.stratos.kubernetes.client/src/main/java/org/apache/stratos/kubernetes/client/model/PodList.java deleted file mode 100644 index 128fc72..0000000 --- a/components/org.apache.stratos.kubernetes.client/src/main/java/org/apache/stratos/kubernetes/client/model/PodList.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.apache.stratos.kubernetes.client.model; - -import org.apache.commons.lang3.ArrayUtils; - -import javax.xml.bind.annotation.XmlRootElement; -import java.util.Arrays; - -@XmlRootElement -public class PodList { - - private String kind; - private String apiVersion; - private Pod[] items; - - public String getKind() { - return kind; - } - - public void setKind(String kind) { - this.kind = kind; - } - - public String getApiVersion() { - return apiVersion; - } - - public void setApiVersion(String apiVersion) { - this.apiVersion = apiVersion; - } - - public Pod[] getItems() { - return items; - } - - public void setItems(Pod[] items) { - this.items = ArrayUtils.clone(items); - } - - @Override - public String toString() { - return "PodList [kind=" + kind + ", apiVersion=" + apiVersion - + ", items=" + Arrays.toString(items) + "]"; - } - -} http://git-wip-us.apache.org/repos/asf/stratos/blob/3414e7ce/components/org.apache.stratos.kubernetes.client/src/main/java/org/apache/stratos/kubernetes/client/model/Policy.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.kubernetes.client/src/main/java/org/apache/stratos/kubernetes/client/model/Policy.java b/components/org.apache.stratos.kubernetes.client/src/main/java/org/apache/stratos/kubernetes/client/model/Policy.java deleted file mode 100644 index 9e0f951..0000000 --- a/components/org.apache.stratos.kubernetes.client/src/main/java/org/apache/stratos/kubernetes/client/model/Policy.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.apache.stratos.kubernetes.client.model; - -public class Policy { - - private String type; - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - @Override - public String toString() { - return "Policy [type=" + type + "]"; - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/3414e7ce/components/org.apache.stratos.kubernetes.client/src/main/java/org/apache/stratos/kubernetes/client/model/Port.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.kubernetes.client/src/main/java/org/apache/stratos/kubernetes/client/model/Port.java b/components/org.apache.stratos.kubernetes.client/src/main/java/org/apache/stratos/kubernetes/client/model/Port.java deleted file mode 100644 index 616da09..0000000 --- a/components/org.apache.stratos.kubernetes.client/src/main/java/org/apache/stratos/kubernetes/client/model/Port.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.apache.stratos.kubernetes.client.model; - -public class Port { - - private String name; - private String protocol; - private int containerPort; - private int hostPort; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getProtocol() { - return protocol; - } - - public void setProtocol(String protocol) { - this.protocol = protocol; - } - - public int getContainerPort() { - return containerPort; - } - - public void setContainerPort(int containerPort) { - this.containerPort = containerPort; - } - - public int getHostPort() { - return hostPort; - } - - public void setHostPort(int hostPort) { - this.hostPort = hostPort; - } - - @Override - public String toString() { - return "Port [name=" + name + ", protocol=" + protocol - + ", containerPort=" + containerPort + ", hostPort=" + hostPort - + "]"; - } - - -} http://git-wip-us.apache.org/repos/asf/stratos/blob/3414e7ce/components/org.apache.stratos.kubernetes.client/src/main/java/org/apache/stratos/kubernetes/client/model/ReplicationController.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.kubernetes.client/src/main/java/org/apache/stratos/kubernetes/client/model/ReplicationController.java b/components/org.apache.stratos.kubernetes.client/src/main/java/org/apache/stratos/kubernetes/client/model/ReplicationController.java deleted file mode 100644 index f2d8539..0000000 --- a/components/org.apache.stratos.kubernetes.client/src/main/java/org/apache/stratos/kubernetes/client/model/ReplicationController.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.apache.stratos.kubernetes.client.model; - -import javax.xml.bind.annotation.XmlRootElement; - -/** - * - * - */ -@XmlRootElement -public class ReplicationController { - - private String kind; - private String id; - private int resourceVersion; - private String creationTimestamp; - private String selfLink; - private String apiVersion; - private Labels labels; - private State desiredState; - - public String getKind() { - return kind; - } - - public void setKind(String kind) { - this.kind = kind; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getCreationTimestamp() { - return creationTimestamp; - } - - public void setCreationTimestamp(String creationTimestamp) { - this.creationTimestamp = creationTimestamp; - } - - public String getSelfLink() { - return selfLink; - } - - public void setSelfLink(String selfLink) { - this.selfLink = selfLink; - } - - public Labels getLabels() { - return labels; - } - - public void setLabels(Labels labels) { - this.labels = labels; - } - - public State getDesiredState() { - return desiredState; - } - - public void setDesiredState(State desiredState) { - this.desiredState = desiredState; - } - - public String getApiVersion() { - return apiVersion; - } - - public void setApiVersion(String apiVersion) { - this.apiVersion = apiVersion; - } - - public int getResourceVersion() { - return resourceVersion; - } - - public void setResourceVersion(int resourceVersion) { - this.resourceVersion = resourceVersion; - } - - @Override - public String toString() { - return "ReplicationController [kind=" + kind + ", id=" + id - + ", resourceVersion=" + resourceVersion - + ", creationTimestamp=" + creationTimestamp + ", selfLink=" - + selfLink + ", apiVersion=" + apiVersion + ", labels=" - + labels + ", desiredState=" + desiredState + "]"; - } - -} http://git-wip-us.apache.org/repos/asf/stratos/blob/3414e7ce/components/org.apache.stratos.kubernetes.client/src/main/java/org/apache/stratos/kubernetes/client/model/ReplicationControllerList.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.kubernetes.client/src/main/java/org/apache/stratos/kubernetes/client/model/ReplicationControllerList.java b/components/org.apache.stratos.kubernetes.client/src/main/java/org/apache/stratos/kubernetes/client/model/ReplicationControllerList.java deleted file mode 100644 index 12c615a..0000000 --- a/components/org.apache.stratos.kubernetes.client/src/main/java/org/apache/stratos/kubernetes/client/model/ReplicationControllerList.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.apache.stratos.kubernetes.client.model; - -import org.apache.commons.lang3.ArrayUtils; - -import javax.xml.bind.annotation.XmlRootElement; -import java.util.Arrays; - -@XmlRootElement -public class ReplicationControllerList { - - private String kind; - private String apiVersion; - private ReplicationController[] items; - - public String getKind() { - return kind; - } - - public void setKind(String kind) { - this.kind = kind; - } - - public String getApiVersion() { - return apiVersion; - } - - public void setApiVersion(String apiVersion) { - this.apiVersion = apiVersion; - } - - public ReplicationController[] getItems() { - return items; - } - - public void setItems(ReplicationController[] items) { - this.items = ArrayUtils.clone(items); - } - - @Override - public String toString() { - return "ReplicationControllerList [kind=" + kind + ", apiVersion=" - + apiVersion + ", items=" + Arrays.toString(items) + "]"; - } - -} http://git-wip-us.apache.org/repos/asf/stratos/blob/3414e7ce/components/org.apache.stratos.kubernetes.client/src/main/java/org/apache/stratos/kubernetes/client/model/Selector.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.kubernetes.client/src/main/java/org/apache/stratos/kubernetes/client/model/Selector.java b/components/org.apache.stratos.kubernetes.client/src/main/java/org/apache/stratos/kubernetes/client/model/Selector.java deleted file mode 100644 index 7d82556..0000000 --- a/components/org.apache.stratos.kubernetes.client/src/main/java/org/apache/stratos/kubernetes/client/model/Selector.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.apache.stratos.kubernetes.client.model; - -import java.io.Serializable; - -public class Selector implements Serializable { - - private static final long serialVersionUID = 8384843252305848574L; - - private String name; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - @Override - public String toString() { - return "Selector [name=" + name + "]"; - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/3414e7ce/components/org.apache.stratos.kubernetes.client/src/main/java/org/apache/stratos/kubernetes/client/model/Service.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.kubernetes.client/src/main/java/org/apache/stratos/kubernetes/client/model/Service.java b/components/org.apache.stratos.kubernetes.client/src/main/java/org/apache/stratos/kubernetes/client/model/Service.java deleted file mode 100644 index 6d04544..0000000 --- a/components/org.apache.stratos.kubernetes.client/src/main/java/org/apache/stratos/kubernetes/client/model/Service.java +++ /dev/null @@ -1,160 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.apache.stratos.kubernetes.client.model; - -import javax.xml.bind.annotation.XmlRootElement; -import java.io.Serializable; -import java.util.Arrays; - -/** - * https://github.com/GoogleCloudPlatform/kubernetes/blob/master/api/doc/service-schema.json - */ -@XmlRootElement -public class Service implements Serializable { - - private static final long serialVersionUID = 7766915353839414993L; - - private String kind; - private String id; - private String creationTimestamp; - private String selfLink; - private String name; - private int port; - private String containerPort; - private Selector selector; - private String apiVersion; - private Labels labels; - private String[] publicIPs; - private String portalIP; - private String sessionAffinity; - - public String getKind() { - return kind; - } - - public void setKind(String kind) { - this.kind = kind; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getCreationTimestamp() { - return creationTimestamp; - } - - public void setCreationTimestamp(String creationTimestamp) { - this.creationTimestamp = creationTimestamp; - } - - public String getSelfLink() { - return selfLink; - } - - public void setSelfLink(String selfLink) { - this.selfLink = selfLink; - } - - public String getApiVersion() { - return apiVersion; - } - - public void setApiVersion(String apiVersion) { - this.apiVersion = apiVersion; - } - - public Labels getLabels() { - return labels; - } - - public void setLabels(Labels labels) { - this.labels = labels; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public int getPort() { - return port; - } - - public void setPort(int port) { - this.port = port; - } - - public String getContainerPort() { - return containerPort; - } - - public void setContainerPort(String containerPort) { - this.containerPort = containerPort; - } - - public Selector getSelector() { - return selector; - } - - public void setSelector(Selector selector) { - this.selector = selector; - } - - public String[] getPublicIPs() { - return publicIPs; - } - - public void setPublicIPs(String[] publicIPs) { - this.publicIPs = publicIPs; - } - - public String getPortalIP() { - return portalIP; - } - - public void setPortalIP(String portalIP) { - this.portalIP = portalIP; - } - - public void setSessionAffinity(String sessionAffinity) { - this.sessionAffinity = sessionAffinity; - } - - public String getSessionAffinity() { - return sessionAffinity; - } - - @Override - public String toString() { - return "Service [kind=" + kind + ", id=" + id + ", creationTimestamp=" + creationTimestamp + ", selfLink=" - + selfLink + ", name=" + name + ", port=" + port + ", containerPort=" + containerPort + ", selector=" - + selector + ", apiVersion=" + apiVersion + ", labels=" + labels + ", publicIPs=" - + Arrays.toString(publicIPs) + "portalIP=" + portalIP + ", sessionAffinity=" + sessionAffinity + "]"; - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/3414e7ce/components/org.apache.stratos.kubernetes.client/src/main/java/org/apache/stratos/kubernetes/client/model/ServiceList.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.kubernetes.client/src/main/java/org/apache/stratos/kubernetes/client/model/ServiceList.java b/components/org.apache.stratos.kubernetes.client/src/main/java/org/apache/stratos/kubernetes/client/model/ServiceList.java deleted file mode 100644 index ecf396a..0000000 --- a/components/org.apache.stratos.kubernetes.client/src/main/java/org/apache/stratos/kubernetes/client/model/ServiceList.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.apache.stratos.kubernetes.client.model; - -import org.apache.commons.lang3.ArrayUtils; - -import javax.xml.bind.annotation.XmlRootElement; -import java.util.Arrays; - -@XmlRootElement -public class ServiceList { - - private String kind; - private String apiVersion; - private Service[] items; - - public String getKind() { - return kind; - } - - public void setKind(String kind) { - this.kind = kind; - } - - public String getApiVersion() { - return apiVersion; - } - - public void setApiVersion(String apiVersion) { - this.apiVersion = apiVersion; - } - - public Service[] getItems() { - return items; - } - - public void setItems(Service[] items) { - this.items = ArrayUtils.clone(items); - } - - @Override - public String toString() { - return "ServiceList [kind=" + kind + ", apiVersion=" + apiVersion - + ", items=" + Arrays.toString(items) + "]"; - } - -} http://git-wip-us.apache.org/repos/asf/stratos/blob/3414e7ce/components/org.apache.stratos.kubernetes.client/src/main/java/org/apache/stratos/kubernetes/client/model/State.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.kubernetes.client/src/main/java/org/apache/stratos/kubernetes/client/model/State.java b/components/org.apache.stratos.kubernetes.client/src/main/java/org/apache/stratos/kubernetes/client/model/State.java deleted file mode 100644 index e4bd8b6..0000000 --- a/components/org.apache.stratos.kubernetes.client/src/main/java/org/apache/stratos/kubernetes/client/model/State.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.apache.stratos.kubernetes.client.model; - -public class State { - - private Manifest manifest; - private String status; - private String host; - private String hostIP; - private String podIP; - private int replicas; - private Selector replicaSelector; - private Pod podTemplate; - private Policy restartPolicy; - private Object info; - - public Manifest getManifest() { - return manifest; - } - - public void setManifest(Manifest manifest) { - this.manifest = manifest; - } - - public String getStatus() { - return status; - } - - public void setStatus(String status) { - this.status = status; - } - - public String getHost() { - return host; - } - - public void setHost(String host) { - this.host = host; - } - - public String getHostIP() { - return hostIP; - } - - public void setHostIP(String hostIP) { - this.hostIP = hostIP; - } - - public Policy getRestartPolicy() { - return restartPolicy; - } - - public void setRestartPolicy(Policy restartPolicy) { - this.restartPolicy = restartPolicy; - } - - public String getPodIP() { - return podIP; - } - - public void setPodIP(String podIP) { - this.podIP = podIP; - } - - public int getReplicas() { - return replicas; - } - - public void setReplicas(int replicas) { - this.replicas = replicas; - } - - public Selector getReplicaSelector() { - return replicaSelector; - } - - public void setReplicaSelector(Selector replicaSelector) { - this.replicaSelector = replicaSelector; - } - - public Pod getPodTemplate() { - return podTemplate; - } - - public void setPodTemplate(Pod podTemplate) { - this.podTemplate = podTemplate; - } - - public Object getInfo() { - return info; - } - - public void setInfo(Object info) { - this.info = info; - } - - @Override - public String toString() { - return "State [manifest=" + manifest + ", status=" + status + ", host=" - + host + ", hostIP=" + hostIP + ", podIP=" + podIP - + ", replicas=" + replicas + ", replicaSelector=" - + replicaSelector + ", podTemplate=" + podTemplate - + ", restartPolicy=" + restartPolicy + ", info=" + info + "]"; - } -}
