Search in sources :

Example 6 with ServiceBuilder

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

the class AbstractServiceRegistar method registerBeanDefinitions.

@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
    for (Method method : REFLECTIONS.getMethodsAnnotatedWith(Factory.class)) {
        String methodName = method.getName();
        Class sourceType = getSourceType(method);
        Class targetType = method.getReturnType();
        Class beanType = method.getDeclaringClass();
        BeanDefinitionHolder holder = createConverterBean(beanType, methodName, sourceType, targetType);
        BeanDefinitionReaderUtils.registerBeanDefinition(holder, registry);
    }
    for (Field field : REFLECTIONS.getFieldsAnnotatedWith(ServiceName.class)) {
        Class targetClass = field.getType();
        Alias alias = field.getAnnotation(Alias.class);
        ServiceName name = field.getAnnotation(ServiceName.class);
        PortName port = field.getAnnotation(PortName.class);
        Protocol protocol = field.getAnnotation(Protocol.class);
        External external = field.getAnnotation(External.class);
        String serviceName = name != null ? name.value() : null;
        // We copy the service since we are going to add properties to it.
        Service serviceInstance = new ServiceBuilder(getService(serviceName)).build();
        String servicePort = port != null ? port.value() : null;
        String serviceProtocol = protocol != null ? protocol.value() : DEFAULT_PROTOCOL;
        Boolean serviceExternal = external != null && external.value();
        String serviceAlias = alias != null ? alias.value() : createAlias(serviceName, targetClass, serviceProtocol, servicePort, serviceExternal);
        // Add annotation info as additional properties
        serviceInstance.getAdditionalProperties().put(ALIAS, serviceAlias);
        serviceInstance.getAdditionalProperties().put(PROTOCOL, serviceProtocol);
        serviceInstance.getAdditionalProperties().put(EXTERNAL, serviceExternal);
        // We don't want to add a fallback value to the attributes.
        if (port != null) {
            serviceInstance.getAdditionalProperties().put(PORT, servicePort);
        }
        BeanDefinitionHolder holder = createServiceDefinition(serviceInstance, serviceAlias, serviceProtocol, servicePort, targetClass);
        BeanDefinitionReaderUtils.registerBeanDefinition(holder, registry);
    }
}
Also used : Service(io.fabric8.kubernetes.api.model.Service) Method(java.lang.reflect.Method) PortName(io.fabric8.annotations.PortName) ServiceBuilder(io.fabric8.kubernetes.api.model.ServiceBuilder) Field(java.lang.reflect.Field) ServiceName(io.fabric8.annotations.ServiceName) Alias(io.fabric8.annotations.Alias) BeanDefinitionHolder(org.springframework.beans.factory.config.BeanDefinitionHolder) External(io.fabric8.annotations.External) Protocol(io.fabric8.annotations.Protocol)

Example 7 with ServiceBuilder

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

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 8 with ServiceBuilder

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

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 9 with ServiceBuilder

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

the class ConfigCompareServiceTest method testServicesEqual.

@Test
public void testServicesEqual() 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(456).endPort().endSpec().build();
    assertCompareConfig(entity1, entity2, true);
}
Also used : Service(io.fabric8.kubernetes.api.model.Service) ServiceBuilder(io.fabric8.kubernetes.api.model.ServiceBuilder) Test(org.junit.Test)

Example 10 with ServiceBuilder

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

the class MockConfigurer method configure.

public static void configure() {
    MOCK.expect().get().withPath("/api/v1/namespaces/cdi/services/service1").andReturn(200, new ServiceBuilder().withNewMetadata().withName("service1").endMetadata().withNewSpec().addNewPort().withProtocol("TCP").withPort(80).withNewTargetPort(9090).endPort().withClusterIP("172.30.17.2").endSpec().build()).always();
    // Services
    MOCK.expect().get().withPath("/api/v1/namespaces/cdi/services/service2").andReturn(200, new ServiceBuilder().withNewMetadata().withName("service2").endMetadata().withNewSpec().addNewPort().withProtocol("TCP").withPort(80).withNewTargetPort(8080).endPort().withClusterIP("172.30.17.2").endSpec().build()).always();
    MOCK.expect().get().withPath("/api/v1/namespaces/cdi/services/service3").andReturn(200, new ServiceBuilder().withNewMetadata().withName("service3").endMetadata().withNewSpec().addNewPort().withProtocol("TCP").withPort(443).withNewTargetPort(443).endPort().withClusterIP("172.30.17.2").endSpec().build()).always();
    MOCK.expect().get().withPath("/api/v1/namespaces/cdi/services/multiport").andReturn(200, 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()).always();
    // Endpoints
    Endpoints service1Endpoints = new EndpointsBuilder().withNewMetadata().withName("service1").withNamespace("default").endMetadata().addNewSubset().addNewPort().withName("port").withPort(8080).endPort().addNewAddress().withIp("10.0.0.1").endAddress().endSubset().addNewSubset().addNewPort().withName("port").withPort(8080).endPort().addNewAddress().withIp("10.0.0.2").endAddress().endSubset().build();
    Endpoints service2EndpointsA = new EndpointsBuilder().withNewMetadata().withName("service2").withNamespace("default").endMetadata().addNewSubset().addNewPort().withName("port").withPort(8080).endPort().addNewAddress().withIp("10.0.0.1").endAddress().endSubset().addNewSubset().addNewPort().withName("port").withPort(8080).endPort().addNewAddress().withIp("10.0.0.2").endAddress().endSubset().build();
    Endpoints service2EndpointsB = new EndpointsBuilder().withNewMetadata().withName("service2").withNamespace("default").endMetadata().addNewSubset().addNewPort().withName("port").withPort(8080).endPort().addNewAddress().withIp("10.0.0.1").endAddress().endSubset().build();
    Endpoints multiPortEndpoint = new EndpointsBuilder().withNewMetadata().withName("multiport").withNamespace("default").endMetadata().addNewSubset().addNewAddress().withIp("172.30.17.2").endAddress().addNewPort("port1", 8081, "TCP").addNewPort("port2", 8082, "TCP").addNewPort("port3", 8083, "TCP").endSubset().build();
    MOCK.expect().withPath("/api/v1/namespaces/cdi/endpoints/service1").andReturn(200, service1Endpoints).always();
    MOCK.expect().withPath("/api/v1/namespaces/cdi/endpoints/service2").andReturn(200, service2EndpointsA).once();
    MOCK.expect().withPath("/api/v1/namespaces/cdi/endpoints/service2").andReturn(200, service2EndpointsB).always();
    MOCK.expect().withPath("/api/v1/namespaces/cdi/endpoints/multiport").andReturn(200, multiPortEndpoint).always();
    String masterUrl = MOCK.getServer().url("/").toString();
    System.setProperty(Config.KUBERNETES_MASTER_SYSTEM_PROPERTY, masterUrl);
    System.setProperty(Config.KUBERNETES_NAMESPACE_SYSTEM_PROPERTY, "cdi");
}
Also used : Endpoints(io.fabric8.kubernetes.api.model.Endpoints) EndpointsBuilder(io.fabric8.kubernetes.api.model.EndpointsBuilder) ServiceBuilder(io.fabric8.kubernetes.api.model.ServiceBuilder)

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