Search in sources :

Example 1 with ContainerPortBuilder

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

the class KubernetesContainer method getContainerPortsFrom.

/**
     * Retrieves list of ({@link ContainerPort} based on ports defined in
     * {@link ContainerConfig} and {@link ImageConfig}
     *
     * @param exposedPorts
     * @return list of {@link ContainerPort}
     */
public static List<ContainerPort> getContainerPortsFrom(Set<String> exposedPorts) {
    List<ContainerPort> containerPorts = new ArrayList<>(exposedPorts.size());
    for (String exposedPort : exposedPorts) {
        String[] portAndProtocol = exposedPort.split("/", 2);
        String port = portAndProtocol[0];
        String protocol = portAndProtocol[1].toUpperCase();
        int portNumber = Integer.parseInt(port);
        String portName = CheServicePorts.get().get(portNumber);
        portName = isNullOrEmpty(portName) ? exposedPort.replace("/", "-") : portName;
        ContainerPort containerPort = new ContainerPortBuilder().withName(portName).withProtocol(protocol).withContainerPort(portNumber).build();
        containerPorts.add(containerPort);
    }
    return containerPorts;
}
Also used : ContainerPortBuilder(io.fabric8.kubernetes.api.model.ContainerPortBuilder) ArrayList(java.util.ArrayList) ContainerPort(io.fabric8.kubernetes.api.model.ContainerPort)

Example 2 with ContainerPortBuilder

use of io.fabric8.kubernetes.api.model.ContainerPortBuilder 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

ContainerPort (io.fabric8.kubernetes.api.model.ContainerPort)2 ContainerPortBuilder (io.fabric8.kubernetes.api.model.ContainerPortBuilder)2 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)1 ServicePortBuilder (io.fabric8.kubernetes.api.model.ServicePortBuilder)1 ServiceSpecBuilder (io.fabric8.kubernetes.api.model.ServiceSpecBuilder)1 Account (io.syndesis.qe.accounts.Account)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 TimeoutException (java.util.concurrent.TimeoutException)1