Search in sources :

Example 36 with Endpoint

use of io.fabric8.annotations.Endpoint in project flink by apache.

the class Fabric8FlinkKubeClient method getRestEndpoint.

@Override
public Optional<Endpoint> getRestEndpoint(String clusterId) {
    Optional<KubernetesService> restService = getService(KubernetesService.ServiceType.REST_SERVICE, clusterId);
    if (!restService.isPresent()) {
        return Optional.empty();
    }
    final Service service = restService.get().getInternalResource();
    final int restPort = getRestPortFromExternalService(service);
    final KubernetesConfigOptions.ServiceExposedType serviceExposedType = ServiceType.classify(service);
    // Return the external service.namespace directly when using ClusterIP.
    if (serviceExposedType.isClusterIP()) {
        return Optional.of(new Endpoint(ExternalServiceDecorator.getNamespacedExternalServiceName(clusterId, namespace), restPort));
    }
    return getRestEndPointFromService(service, restPort);
}
Also used : KubernetesService(org.apache.flink.kubernetes.kubeclient.resources.KubernetesService) Service(io.fabric8.kubernetes.api.model.Service) ExecutorService(java.util.concurrent.ExecutorService) KubernetesConfigOptions(org.apache.flink.kubernetes.configuration.KubernetesConfigOptions) KubernetesService(org.apache.flink.kubernetes.kubeclient.resources.KubernetesService)

Example 37 with Endpoint

use of io.fabric8.annotations.Endpoint in project fabric8 by fabric8io.

the class SessionServicesAreReady method isEndpointAvailable.

/**
 * Checks if there is an endpoint for the service available.
 * @param s The target service.
 * @return  Returns true if a connection to at least one of the endpoints is possible.
 */
private boolean isEndpointAvailable(Service s) {
    String serviceStatus = null;
    boolean result = false;
    String sid = getName(s);
    String namespace = session.getNamespace();
    Endpoints endpoints = kubernetesClient.endpoints().inNamespace(namespace).withName(sid).get();
    ServiceSpec spec = s.getSpec();
    if (endpoints != null && spec != null) {
        List<EndpointSubset> subsets = endpoints.getSubsets();
        if (subsets != null) {
            for (EndpointSubset subset : subsets) {
                List<EndpointAddress> addresses = subset.getAddresses();
                if (addresses != null) {
                    for (EndpointAddress address : addresses) {
                        String ip = address.getIp();
                        String addr = ip;
                        /*
    TODO v1beta2...
                            String addr = endpoit.substring(0, endpoit.indexOf(":"));
                            Integer port = Integer.parseInt(endpoit.substring(endpoit.indexOf(":") + 1));
*/
                        List<ServicePort> ports = spec.getPorts();
                        for (ServicePort port : ports) {
                            Integer portNumber = port.getPort();
                            if (portNumber != null && portNumber > 0) {
                                if (configuration.isWaitForServiceConnectionEnabled()) {
                                    try (Socket socket = new Socket()) {
                                        socket.connect(new InetSocketAddress(ip, portNumber), (int) configuration.getWaitForServiceConnectionTimeout());
                                        serviceStatus = "Service: " + sid + " is ready. Provider:" + addr + ".";
                                        return true;
                                    } catch (Exception e) {
                                        serviceStatus = "Service: " + sid + " is not ready! in namespace " + namespace + ". Error: " + e.getMessage();
                                    } finally {
                                        session.getLogger().warn(serviceStatus);
                                    }
                                } else {
                                    serviceStatus = "Service: " + sid + " is ready. Not testing connecting to it!. Provider:" + addr + ".";
                                    session.getLogger().warn(serviceStatus);
                                    return true;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    session.getLogger().warn("Service: " + sid + " has no valid endpoints");
    return result;
}
Also used : ServicePort(io.fabric8.kubernetes.api.model.ServicePort) InetSocketAddress(java.net.InetSocketAddress) ServiceSpec(io.fabric8.kubernetes.api.model.ServiceSpec) Endpoints(io.fabric8.kubernetes.api.model.Endpoints) EndpointSubset(io.fabric8.kubernetes.api.model.EndpointSubset) Socket(java.net.Socket) EndpointAddress(io.fabric8.kubernetes.api.model.EndpointAddress)

Example 38 with Endpoint

use of io.fabric8.annotations.Endpoint in project fabric8 by fabric8io.

the class ServicePodsAssert method hasEndpointOrReadyPod.

/**
 * Asserts that either this service has a valid Endpoint or that a pod is Ready for a period of time
 */
public ServicePodsAssert hasEndpointOrReadyPod(long notReadyTimeoutMS, long readyPeriodMS) {
    EndpointsList list = client.endpoints().withLabels(getLabels(actual)).list();
    if (list != null) {
        List<Endpoints> items = list.getItems();
        if (items.size() > 0) {
            return this;
        }
    }
    pods().isPodReadyForPeriod(notReadyTimeoutMS, readyPeriodMS);
    return this;
}
Also used : EndpointsList(io.fabric8.kubernetes.api.model.EndpointsList) Endpoints(io.fabric8.kubernetes.api.model.Endpoints)

Example 39 with Endpoint

use of io.fabric8.annotations.Endpoint in project fabric8 by jboss-fuse.

the class RestJsonSchemaJMXTest method setUp.

@Before
public void setUp() {
    SpringBusFactory bf = new SpringBusFactory();
    Bus bus = bf.createBus("/io/fabric8/cxf/endpoint/jaxrs/jmx-enable.xml");
    BusFactory.setDefaultBus(bus);
    JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setResourceClasses(BookStore.class, BookStoreSpring.class);
    sf.setResourceProvider(BookStore.class, new SingletonResourceProvider(new BookStore(), true));
    sf.setResourceProvider(BookStoreSpring.class, new SingletonResourceProvider(new BookStoreSpring(), true));
    sf.setTransportId(LocalTransportFactory.TRANSPORT_ID);
    sf.setAddress("local://books");
    sf.getFeatures().add(new ManagedApiFeature());
    localServer = sf.create();
}
Also used : Bus(org.apache.cxf.Bus) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) ManagedApiFeature(io.fabric8.cxf.endpoint.ManagedApiFeature) JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean) SingletonResourceProvider(org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider) Before(org.junit.Before)

Example 40 with Endpoint

use of io.fabric8.annotations.Endpoint in project fabric8 by jboss-fuse.

the class Fabric8Extension method onInjectionPoint.

public <T, X> void onInjectionPoint(@Observes ProcessInjectionPoint<T, X> event, BeanManager beanManager) {
    final InjectionPoint injectionPoint = event.getInjectionPoint();
    if (isServiceInjectionPoint(injectionPoint)) {
        Annotated annotated = injectionPoint.getAnnotated();
        ServiceName name = annotated.getAnnotation(ServiceName.class);
        Protocol protocol = annotated.getAnnotation(Protocol.class);
        PortName port = annotated.getAnnotation(PortName.class);
        Path path = annotated.getAnnotation(Path.class);
        Alias alias = annotated.getAnnotation(Alias.class);
        Endpoint endpoint = annotated.getAnnotation(Endpoint.class);
        External external = annotated.getAnnotation(External.class);
        String serviceName = name.value();
        String serviceProtocol = protocol != null ? protocol.value() : null;
        String servicePort = port != null ? port.value() : null;
        String servicePath = path != null ? path.value() : null;
        String serviceAlias = alias != null ? alias.value() : null;
        Boolean serviceExternal = external != null ? external.value() : false;
        Boolean serviceEndpoint = endpoint != null ? endpoint.value() : false;
        Type type = annotated.getBaseType();
        if (type instanceof ParameterizedType && Instance.class.equals(((ParameterizedType) type).getRawType())) {
            type = ((ParameterizedType) type).getActualTypeArguments()[0];
        }
        if (type.equals(String.class)) {
            ServiceUrlBean.getBean(serviceName, serviceProtocol, servicePort, servicePath, serviceAlias, serviceEndpoint, serviceExternal);
        } else if (isGenericOf(type, List.class, String.class)) {
            ServiceUrlCollectionBean.getBean(serviceName, serviceProtocol, servicePort, servicePath, serviceAlias, serviceEndpoint, serviceExternal, Types.LIST_OF_STRINGS);
        } else if (isGenericOf(type, List.class, null)) {
        // TODO: Integrate with Factories(?)
        } else if (isGenericOf(type, Set.class, String.class)) {
            ServiceUrlCollectionBean.getBean(serviceName, serviceProtocol, servicePort, servicePath, serviceAlias, serviceEndpoint, serviceExternal, Types.SET_OF_STRINGS);
        } else if (isGenericOf(type, Set.class, null)) {
        // TODO: Integrate with Factories(?)
        } else if (type instanceof Class) {
            ServiceBean.getBean(serviceName, serviceProtocol, servicePort, servicePath, serviceAlias, serviceEndpoint, serviceExternal, type);
        } else {
            throw new RuntimeException(String.format(INJECTION_POINT_UNKNOWN_TYPE, injectionPoint.getBean().getBeanClass(), type));
        }
        if (protocol == null) {
            setDefaultProtocol(event);
        }
        if (port == null) {
            setDefaultPort(event);
        }
        if (path == null) {
            setDefaultPath(event);
        }
        if (endpoint == null) {
            setDefaultEndpoint(event);
        }
        if (external == null) {
            setDefaultExternal(event);
        }
    } else if (isConfigurationInjectionPoint(injectionPoint)) {
        Annotated annotated = injectionPoint.getAnnotated();
        Configuration configuration = annotated.getAnnotation(Configuration.class);
        Type type = injectionPoint.getType();
        String configurationId = configuration.value();
        ConfigurationBean.getBean(configurationId, type);
    }
}
Also used : Path(io.fabric8.annotations.Path) Utils.getFactoryMethodPath(io.fabric8.cdi.Utils.getFactoryMethodPath) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) Configuration(io.fabric8.annotations.Configuration) ProcessInjectionPoint(javax.enterprise.inject.spi.ProcessInjectionPoint) InjectionPoint(javax.enterprise.inject.spi.InjectionPoint) Instance(javax.enterprise.inject.Instance) PortName(io.fabric8.annotations.PortName) ParameterizedType(java.lang.reflect.ParameterizedType) Annotated(javax.enterprise.inject.spi.Annotated) AnnotatedType(javax.enterprise.inject.spi.AnnotatedType) ProcessAnnotatedType(javax.enterprise.inject.spi.ProcessAnnotatedType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) Endpoint(io.fabric8.annotations.Endpoint) ServiceName(io.fabric8.annotations.ServiceName) Alias(io.fabric8.annotations.Alias) External(io.fabric8.annotations.External) ArrayList(java.util.ArrayList) List(java.util.List) Utils.getFactoryMethodProtocol(io.fabric8.cdi.Utils.getFactoryMethodProtocol) Protocol(io.fabric8.annotations.Protocol)

Aggregations

Endpoint (org.wso2.carbon.apimgt.core.models.Endpoint)12 ArrayList (java.util.ArrayList)11 Service (io.fabric8.kubernetes.api.model.Service)9 Endpoints (io.fabric8.kubernetes.api.model.Endpoints)8 NonNamespaceOperation (io.fabric8.kubernetes.client.dsl.NonNamespaceOperation)7 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)7 URL (java.net.URL)7 BeforeTest (org.testng.annotations.BeforeTest)7 Test (org.testng.annotations.Test)7 EndpointsList (io.fabric8.kubernetes.api.model.EndpointsList)5 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)5 IOException (java.io.IOException)5 MalformedURLException (java.net.MalformedURLException)5 List (java.util.List)5 Set (java.util.Set)5 Configuration (io.fabric8.annotations.Configuration)4 Endpoint (io.fabric8.annotations.Endpoint)4 External (io.fabric8.annotations.External)4 Path (io.fabric8.annotations.Path)4 PortName (io.fabric8.annotations.PortName)4