Search in sources :

Example 86 with Deployment

use of io.fabric8.kubernetes.api.model.extensions.Deployment in project iobserve-analysis by research-iobserve.

the class DeallocationExecutor method execute.

@Override
public void execute(final DeallocateNodeAction action) {
    final KubernetesClient client = new DefaultKubernetesClient();
    final String rcName = this.normalizeComponentName(action.getTargetResourceContainer().getEntityName());
    client.extensions().deployments().inNamespace(this.namespace).withName(rcName).delete();
    client.close();
    if (DeallocationExecutor.LOGGER.isDebugEnabled()) {
        DeallocationExecutor.LOGGER.debug("Successfully deleted pod deployment with name " + rcName);
    }
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient)

Example 87 with Deployment

use of io.fabric8.kubernetes.api.model.extensions.Deployment in project iobserve-analysis by research-iobserve.

the class UndeploymentExecutor method execute.

@Override
public void execute(final UndeployComponentAction action) {
    final KubernetesClient client = new DefaultKubernetesClient();
    final String rcName = this.normalizeComponentName(action.getTargetAllocationContext().getResourceContainer_AllocationContext().getEntityName());
    final Deployment deployment = client.extensions().deployments().inNamespace(this.namespace).withName(rcName).get();
    final int replicas = deployment.getSpec().getReplicas();
    // deployment is deleted in the DeallocationExecutor.
    if (replicas > 0) {
        deployment.getSpec().setReplicas(replicas - 1);
        client.extensions().deployments().inNamespace(this.namespace).withName(rcName).replace(deployment);
    }
    client.close();
    if (UndeploymentExecutor.LOGGER.isDebugEnabled()) {
        UndeploymentExecutor.LOGGER.debug("Scaled pod deployment of " + deployment.getMetadata().getName() + " to " + (replicas - 1));
    }
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) Deployment(io.fabric8.kubernetes.api.model.extensions.Deployment) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient)

Example 88 with Deployment

use of io.fabric8.kubernetes.api.model.extensions.Deployment in project che by eclipse.

the class OpenShiftConnector method waitAndRetrieveContainerID.

private String waitAndRetrieveContainerID(String deploymentName) throws IOException {
    for (int i = 0; i < OPENSHIFT_WAIT_POD_TIMEOUT; i++) {
        try {
            Thread.sleep(OPENSHIFT_WAIT_POD_DELAY);
        } catch (InterruptedException ex) {
            Thread.currentThread().interrupt();
        }
        List<Pod> pods = openShiftClient.pods().inNamespace(this.openShiftCheProjectName).withLabel(OPENSHIFT_DEPLOYMENT_LABEL, deploymentName).list().getItems();
        if (pods.size() < 1) {
            throw new OpenShiftException(String.format("Pod with deployment name %s not found", deploymentName));
        } else if (pods.size() > 1) {
            throw new OpenShiftException(String.format("Multiple pods with deployment name %s found", deploymentName));
        }
        Pod pod = pods.get(0);
        String status = pod.getStatus().getPhase();
        if (OPENSHIFT_POD_STATUS_RUNNING.equals(status)) {
            String containerID = pod.getStatus().getContainerStatuses().get(0).getContainerID();
            String normalizedID = KubernetesStringUtils.normalizeContainerID(containerID);
            openShiftClient.pods().inNamespace(openShiftCheProjectName).withName(pod.getMetadata().getName()).edit().editMetadata().addToLabels(CHE_CONTAINER_IDENTIFIER_LABEL_KEY, KubernetesStringUtils.getLabelFromContainerID(normalizedID)).endMetadata().done();
            return normalizedID;
        }
    }
    return null;
}
Also used : Pod(io.fabric8.kubernetes.api.model.Pod) OpenShiftException(org.eclipse.che.plugin.openshift.client.exception.OpenShiftException)

Example 89 with Deployment

use of io.fabric8.kubernetes.api.model.extensions.Deployment in project syndesis-qe by syndesisio.

the class AmqTemplate method deploy.

public static void deploy() {
    Template template = null;
    try (InputStream is = ClassLoader.getSystemResourceAsStream("templates/syndesis-amq.yml")) {
        template = OpenShiftUtils.client().templates().load(is).get();
    } catch (IOException ex) {
        throw new IllegalArgumentException("Unable to read template ", ex);
    }
    Map<String, String> templateParams = new HashMap<>();
    templateParams.put("MQ_USERNAME", "amq");
    templateParams.put("MQ_PASSWORD", "topSecret");
    // try to clean previous broker
    cleanUp();
    OpenShiftUtils.client().templates().withName("syndesis-amq").delete();
    KubernetesList processedTemplate = OpenShiftUtils.getInstance().recreateAndProcessTemplate(template, templateParams);
    OpenShiftUtils.getInstance().createResources(processedTemplate);
    try {
        OpenShiftWaitUtils.waitFor(OpenShiftWaitUtils.isAPodReady("application", "broker"));
    } catch (InterruptedException | TimeoutException e) {
        log.error("Wait for syndesis-server failed ", e);
    }
    // this is not part of deployment, but let's have it the same method:
    AmqTemplate.addAccounts();
}
Also used : HashMap(java.util.HashMap) InputStream(java.io.InputStream) IOException(java.io.IOException) KubernetesList(io.fabric8.kubernetes.api.model.KubernetesList) Template(io.fabric8.openshift.api.model.Template) TimeoutException(java.util.concurrent.TimeoutException)

Example 90 with Deployment

use of io.fabric8.kubernetes.api.model.extensions.Deployment in project syndesis-qe by syndesisio.

the class FtpTemplate method deploy.

public static void deploy() {
    List<ContainerPort> ports = new LinkedList<>();
    ports.add(new ContainerPortBuilder().withName("ftp-cmd").withContainerPort(2121).withProtocol("TCP").build());
    for (int i = 0; i < 10; i++) {
        ContainerPort dataPort = new ContainerPortBuilder().withName("ftp-data-" + i).withContainerPort(2300 + i).withProtocol("TCP").build();
        ports.add(dataPort);
    }
    OpenShiftUtils.client().deploymentConfigs().createOrReplaceWithNew().editOrNewMetadata().withName(APP_NAME).addToLabels(LABEL_NAME, APP_NAME).endMetadata().editOrNewSpec().addToSelector(LABEL_NAME, APP_NAME).withReplicas(1).editOrNewTemplate().editOrNewMetadata().addToLabels(LABEL_NAME, APP_NAME).endMetadata().editOrNewSpec().addNewContainer().withName(APP_NAME).withImage("dsimansk/ftpd:latest").addAllToPorts(ports).endContainer().endSpec().endTemplate().addNewTrigger().withType("ConfigChange").endTrigger().endSpec().done();
    ServiceSpecBuilder serviceSpecBuilder = new ServiceSpecBuilder().addToSelector(LABEL_NAME, APP_NAME);
    serviceSpecBuilder.addToPorts(new ServicePortBuilder().withName("ftp-cmd").withPort(2121).withTargetPort(new IntOrString(2121)).build());
    for (int i = 0; i < 10; i++) {
        serviceSpecBuilder.addToPorts(new ServicePortBuilder().withName("ftp-data-" + i).withPort(2300 + i).withTargetPort(new IntOrString(2300 + i)).build());
    }
    OpenShiftUtils.getInstance().client().services().createOrReplaceWithNew().editOrNewMetadata().withName(APP_NAME).addToLabels(LABEL_NAME, APP_NAME).endMetadata().editOrNewSpecLike(serviceSpecBuilder.build()).endSpec().done();
    try {
        OpenShiftWaitUtils.waitFor(OpenShiftWaitUtils.areExactlyNPodsReady(LABEL_NAME, APP_NAME, 1));
        Thread.sleep(20 * 1000);
    } catch (InterruptedException | TimeoutException e) {
        log.error("Wait for {} deployment failed ", APP_NAME, e);
    }
    Account ftpAccount = new Account();
    ftpAccount.setService("ftp");
    Map<String, String> accountParameters = new HashMap<>();
    accountParameters.put("host", "ftpd");
    accountParameters.put("port", "2121");
    ftpAccount.setProperties(accountParameters);
    AccountsDirectory.getInstance().addAccount("FTP", ftpAccount);
}
Also used : Account(io.syndesis.qe.accounts.Account) HashMap(java.util.HashMap) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) LinkedList(java.util.LinkedList) ServiceSpecBuilder(io.fabric8.kubernetes.api.model.ServiceSpecBuilder) ServicePortBuilder(io.fabric8.kubernetes.api.model.ServicePortBuilder) ContainerPortBuilder(io.fabric8.kubernetes.api.model.ContainerPortBuilder) ContainerPort(io.fabric8.kubernetes.api.model.ContainerPort) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)52 Test (org.junit.Test)28 DeploymentConfig (io.fabric8.openshift.api.model.DeploymentConfig)27 InputStream (java.io.InputStream)26 Service (io.fabric8.kubernetes.api.model.Service)24 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)22 Deployment (org.jboss.arquillian.container.test.api.Deployment)21 OSGiManifestBuilder (org.jboss.osgi.metadata.OSGiManifestBuilder)21 Asset (org.jboss.shrinkwrap.api.asset.Asset)21 JavaArchive (org.jboss.shrinkwrap.api.spec.JavaArchive)21 ServiceTracker (org.osgi.util.tracker.ServiceTracker)20 CommandSupport (io.fabric8.itests.support.CommandSupport)18 Logger (org.slf4j.Logger)18 Pod (io.fabric8.kubernetes.api.model.Pod)17 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)17 IOException (java.io.IOException)17 FabricService (io.fabric8.api.FabricService)16 ServiceLocator (io.fabric8.api.gravia.ServiceLocator)16 ArrayList (java.util.ArrayList)16 StartLevelAware (org.jboss.arquillian.osgi.StartLevelAware)16