Search in sources :

Example 1 with ServiceUrlCollectionBean

use of io.fabric8.cdi.bean.ServiceUrlCollectionBean in project fabric8 by fabric8io.

the class Fabric8Extension method afterDiscovery.

public void afterDiscovery(@Observes final AfterBeanDiscovery event, BeanManager beanManager) {
    KubernetesHolder.useBeanManager(beanManager);
    // Only add the bean if no other bean is found.
    if (beanManager.getBeans(KubernetesClient.class).isEmpty()) {
        event.addBean(new KubernetesClientBean());
    }
    // We need to process factories in reverse order so that we make feasible forwarding for service id etc.
    List<FactoryMethodContext> reverseFactories = new ArrayList<>(FactoryMethodContext.sort(factories));
    Collections.reverse(reverseFactories);
    for (final FactoryMethodContext factoryMethodContext : reverseFactories) {
        ServiceBean.doWith(factoryMethodContext.getReturnType(), new ServiceBean.Callback() {

            @Override
            public ServiceBean apply(ServiceBean bean) {
                String serviceId = bean.getServiceName();
                String serviceProtocol = or(bean.getServiceProtocol(), getFactoryMethodProtocol(factoryMethodContext.getFactoryMethod().getJavaMember()));
                String servicePort = or(bean.getServicePort(), getFactoryMethodPort(factoryMethodContext.getFactoryMethod().getJavaMember()));
                String servicePath = or(bean.getServicePath(), getFactoryMethodPath(factoryMethodContext.getFactoryMethod().getJavaMember()));
                Boolean serviceExternal = bean.getServiceExternal();
                Boolean serviceEndpoint = bean.getServiceEndpoint();
                // Ensure that there is a factory String -> sourceType before adding producer.
                if (!String.class.equals(factoryMethodContext.getSourceType())) {
                    ServiceBean.getBean(serviceId, serviceProtocol, servicePort, servicePath, null, serviceEndpoint, serviceExternal, factoryMethodContext.getSourceType());
                }
                return bean.withProducer(new FactoryMethodProducer(factoryMethodContext.getBean(), factoryMethodContext.getFactoryMethod(), serviceId, serviceProtocol, servicePort, servicePath));
            }
        });
    }
    for (ServiceUrlBean bean : ServiceUrlBean.getBeans()) {
        event.addBean(bean);
    }
    for (ServiceUrlCollectionBean bean : ServiceUrlCollectionBean.getBeans()) {
        event.addBean(bean);
    }
    for (ServiceBean bean : ServiceBean.getBeans()) {
        if (bean.getProducer() != null) {
            event.addBean(bean);
        }
    }
    for (ConfigurationBean b : ConfigurationBean.getBeans()) {
        event.addBean(b);
    }
}
Also used : FactoryMethodProducer(io.fabric8.cdi.producers.FactoryMethodProducer) ConfigurationBean(io.fabric8.cdi.bean.ConfigurationBean) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) ArrayList(java.util.ArrayList) ServiceUrlCollectionBean(io.fabric8.cdi.bean.ServiceUrlCollectionBean) KubernetesClientBean(io.fabric8.cdi.bean.KubernetesClientBean) ServiceUrlBean(io.fabric8.cdi.bean.ServiceUrlBean) ServiceBean(io.fabric8.cdi.bean.ServiceBean)

Aggregations

ConfigurationBean (io.fabric8.cdi.bean.ConfigurationBean)1 KubernetesClientBean (io.fabric8.cdi.bean.KubernetesClientBean)1 ServiceBean (io.fabric8.cdi.bean.ServiceBean)1 ServiceUrlBean (io.fabric8.cdi.bean.ServiceUrlBean)1 ServiceUrlCollectionBean (io.fabric8.cdi.bean.ServiceUrlCollectionBean)1 FactoryMethodProducer (io.fabric8.cdi.producers.FactoryMethodProducer)1 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)1 ArrayList (java.util.ArrayList)1