Search in sources :

Example 31 with ServiceBuilder

use of io.fabric8.knative.serving.v1.ServiceBuilder in project fabric8 by fabric8io.

the class MockConfigurer method configure.

public static void configure() {
    Service service1 = new ServiceBuilder().withNewMetadata().withName("service1").endMetadata().withNewSpec().addNewPort().withProtocol("TCP").withPort(80).withNewTargetPort(9090).endPort().endSpec().build();
    Service service2 = new ServiceBuilder().withNewMetadata().withName("service2").endMetadata().withNewSpec().addNewPort().withProtocol("TCP").withPort(80).withNewTargetPort(8080).endPort().endSpec().build();
    Service service3 = new ServiceBuilder().withNewMetadata().withName("service3").endMetadata().withNewSpec().addNewPort().withProtocol("TCP").withPort(443).withNewTargetPort(443).endPort().withClusterIP("172.30.17.2").endSpec().build();
    Service multiport = new ServiceBuilder().withNewMetadata().withName("multiport").endMetadata().withNewSpec().addNewPort().withName("port1").withProtocol("TCP").withPort(8081).withNewTargetPort(8081).endPort().addNewPort().withName("port2").withProtocol("TCP").withPort(8082).withNewTargetPort(8082).endPort().addNewPort().withName("port3").withProtocol("TCP").withPort(8083).withNewTargetPort(8083).endPort().withClusterIP("172.30.17.2").endSpec().build();
    MOCK.expect().get().withPath("/api/v1/namespaces/default/services/service1").andReturn(200, service1).always();
    MOCK.expect().get().withPath("/api/v1/namespaces/default/services/service2").andReturn(200, service2).always();
    MOCK.expect().get().withPath("/api/v1/namespaces/default/services/service3").andReturn(200, service3).always();
    MOCK.expect().get().withPath("/api/v1/namespaces/default/services/multiport").andReturn(200, multiport).always();
    MOCK.expect().get().withPath("/api/v1/namespaces/default/services").andReturn(200, new ServiceListBuilder().withItems(service1, service2, service3, multiport).build()).always();
    MOCK.expect().get().withPath("/api/v1/namespaces/default/endpoints").andReturn(200, new EndpointsListBuilder().build()).always();
    MOCK.expect().get().withPath("/oapi/v1/namespaces/default/routes").andReturn(200, new RouteBuilder().build()).always();
    String masterUrl = MOCK.getServer().url("/").toString();
    System.setProperty(Config.KUBERNETES_MASTER_SYSTEM_PROPERTY, masterUrl);
}
Also used : ServiceListBuilder(io.fabric8.kubernetes.api.model.ServiceListBuilder) RouteBuilder(io.fabric8.openshift.api.model.RouteBuilder) Service(io.fabric8.kubernetes.api.model.Service) ServiceBuilder(io.fabric8.kubernetes.api.model.ServiceBuilder) EndpointsListBuilder(io.fabric8.kubernetes.api.model.EndpointsListBuilder)

Example 32 with ServiceBuilder

use of io.fabric8.knative.serving.v1.ServiceBuilder in project fabric8 by fabric8io.

the class MockConfigurer method configure.

public static void configure() {
    Service service1 = new ServiceBuilder().withNewMetadata().withName("service1").endMetadata().withNewSpec().addNewPort().withProtocol("TCP").withPort(80).withNewTargetPort(9090).endPort().endSpec().build();
    Service service2 = new ServiceBuilder().withNewMetadata().withName("service2").endMetadata().withNewSpec().addNewPort().withProtocol("TCP").withPort(80).withNewTargetPort(8080).endPort().endSpec().build();
    Service service3 = new ServiceBuilder().withNewMetadata().withName("service3").endMetadata().withNewSpec().addNewPort().withProtocol("TCP").withPort(443).withNewTargetPort(443).endPort().withClusterIP("172.30.17.2").endSpec().build();
    Service multiport = new ServiceBuilder().withNewMetadata().withName("multiport").endMetadata().withNewSpec().addNewPort().withName("port1").withProtocol("TCP").withPort(8081).withNewTargetPort(8081).endPort().addNewPort().withName("port2").withProtocol("TCP").withPort(8082).withNewTargetPort(8082).endPort().addNewPort().withName("port3").withProtocol("TCP").withPort(8083).withNewTargetPort(8083).endPort().withClusterIP("172.30.17.2").endSpec().build();
    MOCK.expect().get().withPath("/api/v1/namespaces/default/services/service1").andReturn(200, service1).always();
    MOCK.expect().get().withPath("/api/v1/namespaces/default/services/service2").andReturn(200, service2).always();
    MOCK.expect().get().withPath("/api/v1/namespaces/default/services/service3").andReturn(200, service3).always();
    MOCK.expect().get().withPath("/api/v1/namespaces/default/services/multiport").andReturn(200, multiport).always();
    MOCK.expect().get().withPath("/api/v1/namespaces/default/services").andReturn(200, new ServiceListBuilder().withItems(service1, service2, service3, multiport).build()).always();
    MOCK.expect().get().withPath("/api/v1/namespaces/default/endpoints").andReturn(200, new EndpointsListBuilder().build()).always();
    MOCK.expect().get().withPath("/oapi/v1/namespaces/default/routes").andReturn(200, new RouteBuilder().build()).always();
    String masterUrl = MOCK.getServer().url("/").toString();
    System.setProperty(Config.KUBERNETES_MASTER_SYSTEM_PROPERTY, masterUrl);
}
Also used : ServiceListBuilder(io.fabric8.kubernetes.api.model.ServiceListBuilder) RouteBuilder(io.fabric8.openshift.api.model.RouteBuilder) Service(io.fabric8.kubernetes.api.model.Service) ServiceBuilder(io.fabric8.kubernetes.api.model.ServiceBuilder) EndpointsListBuilder(io.fabric8.kubernetes.api.model.EndpointsListBuilder)

Example 33 with ServiceBuilder

use of io.fabric8.knative.serving.v1.ServiceBuilder in project fabric8 by fabric8io.

the class TemplatesTest method testCombineResourcesIntoTemplate.

@Test
public void testCombineResourcesIntoTemplate() throws Exception {
    Service templateService = new ServiceBuilder().withNewMetadata().withName("templateService").endMetadata().build();
    KubernetesList list = new KubernetesListBuilder().addNewServiceItem().withNewMetadata().withName("service1").endMetadata().endServiceItem().addNewTemplateItem().addNewParameter().withName("PARAM1").withValue("ABC").endParameter().addToObjects(templateService).endTemplateItem().addNewServiceItem().withNewMetadata().withName("service2").endMetadata().endServiceItem().build();
    Object result = Templates.combineTemplates(list);
    System.out.println("Combined as " + KubernetesHelper.toJson(result));
    assertThat(result).isInstanceOf(Template.class);
}
Also used : KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) Service(io.fabric8.kubernetes.api.model.Service) KubernetesList(io.fabric8.kubernetes.api.model.KubernetesList) ServiceBuilder(io.fabric8.kubernetes.api.model.ServiceBuilder) Test(org.junit.Test)

Example 34 with ServiceBuilder

use of io.fabric8.knative.serving.v1.ServiceBuilder in project TOSCAna by StuPro-TOSCAna.

the class ResourceService method build.

@Override
public ResourceService build() {
    List<ServicePort> ports = pod.getPorts().stream().map(Port::toServicePort).collect(Collectors.toList());
    service = new ServiceBuilder().withNewMetadata().withName(pod.getServiceName()).addToLabels("app", pod.getServiceName()).endMetadata().withNewSpec().addAllToPorts(ports).addToSelector("app", name).withType("NodePort").endSpec().build();
    return this;
}
Also used : ServicePort(io.fabric8.kubernetes.api.model.ServicePort) ServiceBuilder(io.fabric8.kubernetes.api.model.ServiceBuilder)

Example 35 with ServiceBuilder

use of io.fabric8.knative.serving.v1.ServiceBuilder in project fabric8 by jboss-fuse.

the class ConfigCompareServiceTest method testServicesContainerPortNotEqual.

@Test
public void testServicesContainerPortNotEqual() throws Exception {
    Service entity1 = new ServiceBuilder().withNewMetadata().withName("foo").addToLabels("label1", "value1").addToLabels("label2", "value2").endMetadata().withNewSpec().addToSelector("label1", "value1").addToSelector("label2", "value2").addNewPort().withPort(123).withNewTargetPort(456).endPort().endSpec().build();
    Service entity2 = new ServiceBuilder().withNewMetadata().withName("foo").addToLabels("label2", "value2").addToLabels("label1", "value1").endMetadata().withNewSpec().addToSelector("label1", "value1").addToSelector("label2", "value2").addNewPort().withPort(123).withNewTargetPort(555).endPort().endSpec().build();
    assertCompareConfig(entity1, entity2, false);
}
Also used : Service(io.fabric8.kubernetes.api.model.Service) ServiceBuilder(io.fabric8.kubernetes.api.model.ServiceBuilder) Test(org.junit.Test)

Aggregations

ServiceBuilder (io.fabric8.kubernetes.api.model.ServiceBuilder)39 Service (io.fabric8.kubernetes.api.model.Service)32 Test (org.junit.Test)14 ServicePortBuilder (io.fabric8.kubernetes.api.model.ServicePortBuilder)11 ServicePort (io.fabric8.kubernetes.api.model.ServicePort)7 ArrayList (java.util.ArrayList)7 ServiceListBuilder (io.fabric8.kubernetes.api.model.ServiceListBuilder)5 EndpointsListBuilder (io.fabric8.kubernetes.api.model.EndpointsListBuilder)4 Pod (io.fabric8.kubernetes.api.model.Pod)4 ServiceSpec (io.fabric8.kubernetes.api.model.ServiceSpec)4 VolumeBuilder (io.fabric8.kubernetes.api.model.VolumeBuilder)4 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)4 RouteBuilder (io.fabric8.openshift.api.model.RouteBuilder)4 Map (java.util.Map)4 Container (io.fabric8.kubernetes.api.model.Container)3 IOException (java.io.IOException)3 KubernetesPluginException (org.ballerinax.kubernetes.exceptions.KubernetesPluginException)3 Alias (io.fabric8.annotations.Alias)2 External (io.fabric8.annotations.External)2 PortName (io.fabric8.annotations.PortName)2