Search in sources :

Example 1 with ServicePortBuilder

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

the class ServiceDiscovererKubernetesTestCase method createMalformedServiceList.

/**
 * Create ServiceList with the given port type, but without a loadBalancer ingress
 *
 * @param portType http or https or a wrong port to check behavior
 * @return ServiceList containing one service of LoadBalancer type
 */
private ServiceList createMalformedServiceList(String portType) {
    ServicePort port = new ServicePortBuilder().withName(portType).withPort(80).withNodePort(30005).build();
    Service malformedService5 = new ServiceBuilder().withNewMetadata().withName("service5").withNamespace("prod").and().withNewSpec().withType("LoadBalancer").withClusterIP("1.1.1.5").withPorts(port).and().withNewStatus().withNewLoadBalancer().endLoadBalancer().and().build();
    List<Service> servicesList = new ArrayList<>();
    servicesList.add(malformedService5);
    return new ServiceListBuilder().withItems(servicesList).build();
}
Also used : ServicePort(io.fabric8.kubernetes.api.model.ServicePort) ServiceListBuilder(io.fabric8.kubernetes.api.model.ServiceListBuilder) ServicePortBuilder(io.fabric8.kubernetes.api.model.ServicePortBuilder) ArrayList(java.util.ArrayList) Service(io.fabric8.kubernetes.api.model.Service) ServiceBuilder(io.fabric8.kubernetes.api.model.ServiceBuilder)

Example 2 with ServicePortBuilder

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

Example 3 with ServicePortBuilder

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

the class ServiceDiscovererKubernetesTestCase method init.

/**
 *  ServiceName  Namespace   Criteria  Type          Ports  LoadBalancer  ExternalIP
 *
 *  service0     dev         app=web   ClusterIP     http       -         included
 *  service1     dev         -         ExternalName  http       -             -
 *  service2     dev         -         LoadBalancer  https      IP            -
 *  service3     prod        app=web   ClusterIP     http       -             -
 *  service4     prod        -         LoadBalancer  http     hostname        -
 */
@BeforeTest(description = "Create a list of services with all combinations included")
void init() {
    Map<String, String> oneLabel = createOneLabelHashMap();
    ServicePortBuilder httpPortBuilder = new ServicePortBuilder().withName("http").withPort(80);
    ServicePort httpPort = httpPortBuilder.build();
    ServicePort nodePort2 = new ServicePortBuilder().withName("https").withPort(443).withNodePort(30002).build();
    ServicePort nodePort4 = httpPortBuilder.withNodePort(30004).build();
    List<LoadBalancerIngress> ipIngresses = new ArrayList<>();
    LoadBalancerIngress ingressWithIP = new LoadBalancerIngressBuilder().withIp("100.1.1.2").build();
    ipIngresses.add(ingressWithIP);
    List<LoadBalancerIngress> hostnameIngresses = new ArrayList<>();
    LoadBalancerIngress ingressWithHostname = new LoadBalancerIngressBuilder().withHostname("abc.com").build();
    hostnameIngresses.add(ingressWithHostname);
    Service service0 = new ServiceBuilder().withNewMetadata().withName("service0").withNamespace("dev").withLabels(oneLabel).and().withNewSpec().withType("ClusterIP").withClusterIP("1.1.1.0").withPorts(httpPort).withExternalIPs("100.2.1.0").and().build();
    Service service1 = new ServiceBuilder().withNewMetadata().withName("service1").withNamespace("dev").and().withNewSpec().withType("ExternalName").withExternalName("aaa.com").withPorts(httpPort).and().build();
    Service service2 = new ServiceBuilder().withNewMetadata().withName("service2").withNamespace("dev").and().withNewSpec().withType("LoadBalancer").withClusterIP("1.1.1.2").withPorts(nodePort2).and().withNewStatus().withNewLoadBalancer().withIngress(ipIngresses).endLoadBalancer().and().build();
    Service service3 = new ServiceBuilder().withNewMetadata().withName("service3").withNamespace("prod").withLabels(oneLabel).and().withNewSpec().withType("ClusterIP").withClusterIP("1.1.1.3").withPorts(httpPort).and().build();
    Service service4 = new ServiceBuilder().withNewMetadata().withName("service4").withNamespace("prod").and().withNewSpec().withType("LoadBalancer").withClusterIP("1.1.1.4").withPorts(nodePort4).and().withNewStatus().withNewLoadBalancer().withIngress(hostnameIngresses).endLoadBalancer().and().build();
    List<Service> servicesList = new ArrayList<>();
    servicesList.add(service0);
    servicesList.add(service1);
    servicesList.add(service2);
    servicesList.add(service3);
    servicesList.add(service4);
    this.listOfServices = servicesList;
}
Also used : ServicePort(io.fabric8.kubernetes.api.model.ServicePort) LoadBalancerIngress(io.fabric8.kubernetes.api.model.LoadBalancerIngress) ServicePortBuilder(io.fabric8.kubernetes.api.model.ServicePortBuilder) ArrayList(java.util.ArrayList) LoadBalancerIngressBuilder(io.fabric8.kubernetes.api.model.LoadBalancerIngressBuilder) Service(io.fabric8.kubernetes.api.model.Service) ServiceBuilder(io.fabric8.kubernetes.api.model.ServiceBuilder) BeforeTest(org.testng.annotations.BeforeTest)

Aggregations

ServicePortBuilder (io.fabric8.kubernetes.api.model.ServicePortBuilder)3 Service (io.fabric8.kubernetes.api.model.Service)2 ServiceBuilder (io.fabric8.kubernetes.api.model.ServiceBuilder)2 ServicePort (io.fabric8.kubernetes.api.model.ServicePort)2 ArrayList (java.util.ArrayList)2 ContainerPort (io.fabric8.kubernetes.api.model.ContainerPort)1 ContainerPortBuilder (io.fabric8.kubernetes.api.model.ContainerPortBuilder)1 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)1 LoadBalancerIngress (io.fabric8.kubernetes.api.model.LoadBalancerIngress)1 LoadBalancerIngressBuilder (io.fabric8.kubernetes.api.model.LoadBalancerIngressBuilder)1 ServiceListBuilder (io.fabric8.kubernetes.api.model.ServiceListBuilder)1 ServiceSpecBuilder (io.fabric8.kubernetes.api.model.ServiceSpecBuilder)1 Account (io.syndesis.qe.accounts.Account)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 TimeoutException (java.util.concurrent.TimeoutException)1 BeforeTest (org.testng.annotations.BeforeTest)1