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);
}
}
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));
}
}
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;
}
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();
}
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);
}
Aggregations