Search in sources :

Example 1 with HasMetadata

use of io.fabric8.kubernetes.api.model.HasMetadata in project carbon-apimgt by wso2.

the class KubernetesGatewayImpl method createDeploymentResource.

/**
 * Create a deployment in cms
 *
 * @param deploymentTemplate Deployment template as a String
 * @param deploymentName     Name of the deployment
 * @throws ContainerBasedGatewayException if failed to create a deployment
 */
private void createDeploymentResource(String deploymentTemplate, String deploymentName) throws ContainerBasedGatewayException {
    HasMetadata resource = getResourcesFromTemplate(deploymentTemplate);
    try {
        if (resource instanceof Deployment) {
            // check whether there are existing service already
            if (client.extensions().deployments().inNamespace(namespace).withName(deploymentName).get() == null) {
                log.debug("Deploying in CMS type: {} and the Deployment resource definition: {} ", cmsType, deploymentTemplate);
                Deployment deployment = (Deployment) resource;
                Deployment result = client.extensions().deployments().inNamespace(namespace).create(deployment);
                log.info("Created Deployment : " + result.getMetadata().getName() + " in Namespace : " + result.getMetadata().getNamespace() + " in " + cmsType);
            } else {
                log.info("There exist a deployment with the same name in " + cmsType + ". Deployment name : " + deploymentName);
            }
        } else {
            throw new ContainerBasedGatewayException("Loaded Resource is not a Deployment in " + cmsType + "! " + resource, ExceptionCodes.LOADED_RESOURCE_DEFINITION_IS_NOT_VALID);
        }
    } catch (KubernetesClientException e) {
        throw new ContainerBasedGatewayException("Error while creating container based gateway deployment in " + cmsType + "!", e, ExceptionCodes.DEDICATED_CONTAINER_GATEWAY_CREATION_FAILED);
    }
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Deployment(io.fabric8.kubernetes.api.model.extensions.Deployment) ContainerBasedGatewayException(org.wso2.carbon.apimgt.core.exception.ContainerBasedGatewayException) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException)

Example 2 with HasMetadata

use of io.fabric8.kubernetes.api.model.HasMetadata in project carbon-apimgt by wso2.

the class KubernetesGatewayImpl method createIngressResource.

/**
 * Create an Ingress resource in cms
 *
 * @param ingressTemplate Ingress template as a String
 * @param ingressName     Name of the ingress
 * @throws ContainerBasedGatewayException if failed to create a service
 */
private void createIngressResource(String ingressTemplate, String ingressName) throws ContainerBasedGatewayException {
    HasMetadata resource = getResourcesFromTemplate(ingressTemplate);
    try {
        if (resource instanceof Ingress) {
            // check whether there are existing service already
            if (client.extensions().ingresses().inNamespace(namespace).withName(ingressName).get() == null) {
                log.debug("Deploying in CMS type: {} and the Ingress resource definition: {} ", cmsType, ingressTemplate);
                Ingress ingress = (Ingress) resource;
                Ingress result = client.extensions().ingresses().inNamespace(namespace).create(ingress);
                log.info("Created Ingress : " + result.getMetadata().getName() + " in Namespace : " + result.getMetadata().getNamespace() + " in " + cmsType);
            } else {
                log.info("There exist an ingress with the same name in " + cmsType + ". Ingress name : " + ingressName);
            }
        } else {
            throw new ContainerBasedGatewayException("Loaded Resource is not a Service in " + cmsType + "! " + resource, ExceptionCodes.LOADED_RESOURCE_DEFINITION_IS_NOT_VALID);
        }
    } catch (KubernetesClientException e) {
        throw new ContainerBasedGatewayException("Error while creating container based gateway ingress in " + cmsType + "!", e, ExceptionCodes.DEDICATED_CONTAINER_GATEWAY_CREATION_FAILED);
    }
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Ingress(io.fabric8.kubernetes.api.model.extensions.Ingress) ContainerBasedGatewayException(org.wso2.carbon.apimgt.core.exception.ContainerBasedGatewayException) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException)

Example 3 with HasMetadata

use of io.fabric8.kubernetes.api.model.HasMetadata in project carbon-apimgt by wso2.

the class KubernetesGatewayImpl method createServiceResource.

/**
 * Create a service in cms
 *
 * @param serviceTemplate Service template as a String
 * @param serviceName     Name of the service
 * @throws ContainerBasedGatewayException if failed to create a service
 */
private void createServiceResource(String serviceTemplate, String serviceName) throws ContainerBasedGatewayException {
    HasMetadata resource = getResourcesFromTemplate(serviceTemplate);
    try {
        if (resource instanceof Service) {
            // check whether there are existing service already
            if (client.services().inNamespace(namespace).withName(serviceName).get() == null) {
                log.debug("Deploying in CMS type: {} and the Service resource definition: {} ", cmsType, serviceTemplate);
                Service service = (Service) resource;
                Service result = client.services().inNamespace(namespace).create(service);
                log.info("Created Service : " + result.getMetadata().getName() + " in Namespace : " + result.getMetadata().getNamespace() + " in " + cmsType);
            } else {
                log.info("There exist a service with the same name in " + cmsType + ". Service name : " + serviceName);
            }
        } else {
            throw new ContainerBasedGatewayException("Loaded Resource is not a Service in " + cmsType + "! " + resource, ExceptionCodes.LOADED_RESOURCE_DEFINITION_IS_NOT_VALID);
        }
    } catch (KubernetesClientException e) {
        throw new ContainerBasedGatewayException("Error while creating container based gateway service in " + cmsType + "!", e, ExceptionCodes.DEDICATED_CONTAINER_GATEWAY_CREATION_FAILED);
    }
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Service(io.fabric8.kubernetes.api.model.Service) ContainerBasedGatewayException(org.wso2.carbon.apimgt.core.exception.ContainerBasedGatewayException) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException)

Example 4 with HasMetadata

use of io.fabric8.kubernetes.api.model.HasMetadata in project carbon-apimgt by wso2.

the class KubernetesGatewayImplTestCase method getServiceResources.

/**
 * Get service resources
 *
 * @return List<HasMetadata> list of service resources
 */
private List<HasMetadata> getServiceResources() {
    HasMetadata serviceMetadata = Mockito.mock(Service.class);
    List<HasMetadata> serviceResources = new ArrayList<>();
    serviceResources.add(serviceMetadata);
    return serviceResources;
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) ArrayList(java.util.ArrayList)

Example 5 with HasMetadata

use of io.fabric8.kubernetes.api.model.HasMetadata in project carbon-apimgt by wso2.

the class KubernetesGatewayImplTestCase method getDeploymentResources.

/**
 * Get deployment resources
 *
 * @return List<HasMetadata> list of deployment resources
 */
private List<HasMetadata> getDeploymentResources() {
    HasMetadata deploymentMetadata = Mockito.mock(Deployment.class);
    List<HasMetadata> deploymentResources = new ArrayList<>();
    deploymentResources.add(deploymentMetadata);
    return deploymentResources;
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) ArrayList(java.util.ArrayList)

Aggregations

HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)82 Test (org.junit.Test)25 File (java.io.File)22 ArrayList (java.util.ArrayList)22 IOException (java.io.IOException)18 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)16 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)15 Template (io.fabric8.openshift.api.model.Template)15 DeploymentConfig (io.fabric8.openshift.api.model.DeploymentConfig)14 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)14 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)13 KubernetesList (io.fabric8.kubernetes.api.model.KubernetesList)13 Service (io.fabric8.kubernetes.api.model.Service)13 ReplicationController (io.fabric8.kubernetes.api.model.ReplicationController)11 HashMap (java.util.HashMap)10 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)10 URL (java.net.URL)9 Map (java.util.Map)9 ConfigMapBuilder (io.fabric8.kubernetes.api.model.ConfigMapBuilder)8 ReplicaSet (io.fabric8.kubernetes.api.model.extensions.ReplicaSet)8