use of io.fabric8.annotations.Protocol in project fabric8 by fabric8io.
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);
}
}
use of io.fabric8.annotations.Protocol in project fabric8 by fabric8io.
the class AbstractServiceRegistar method createServiceDefinition.
private BeanDefinitionHolder createServiceDefinition(Service service, String alias, String protocol, String port, Class type) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(KubernetesServiceFactoryBean.class);
builder.addPropertyValue("name", alias);
builder.addPropertyValue("service", service);
builder.addPropertyValue("port", port);
builder.addPropertyValue("type", type.getCanonicalName());
builder.setAutowireMode(Autowire.BY_TYPE.value());
// Add protocol qualifier
builder.getBeanDefinition().addQualifier(new AutowireCandidateQualifier(ServiceName.class, KubernetesHelper.getName(service)));
builder.getBeanDefinition().addQualifier(new AutowireCandidateQualifier(Protocol.class, protocol));
builder.getBeanDefinition().addQualifier(new AutowireCandidateQualifier(PortName.class, port != null ? port : ""));
return new BeanDefinitionHolder(builder.getBeanDefinition(), alias);
}
use of io.fabric8.annotations.Protocol in project fabric8 by fabric8io.
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);
}
}
use of io.fabric8.annotations.Protocol in project che by eclipse.
the class KubernetesContainer method getContainerPortsFrom.
/**
* Retrieves list of ({@link ContainerPort} based on ports defined in
* {@link ContainerConfig} and {@link ImageConfig}
*
* @param exposedPorts
* @return list of {@link ContainerPort}
*/
public static List<ContainerPort> getContainerPortsFrom(Set<String> exposedPorts) {
List<ContainerPort> containerPorts = new ArrayList<>(exposedPorts.size());
for (String exposedPort : exposedPorts) {
String[] portAndProtocol = exposedPort.split("/", 2);
String port = portAndProtocol[0];
String protocol = portAndProtocol[1].toUpperCase();
int portNumber = Integer.parseInt(port);
String portName = CheServicePorts.get().get(portNumber);
portName = isNullOrEmpty(portName) ? exposedPort.replace("/", "-") : portName;
ContainerPort containerPort = new ContainerPortBuilder().withName(portName).withProtocol(protocol).withContainerPort(portNumber).build();
containerPorts.add(containerPort);
}
return containerPorts;
}
use of io.fabric8.annotations.Protocol in project che by eclipse.
the class KubernetesService method getServicePortsFrom.
/**
* Retrieves list of {@link ServicePort} based on ports defined in
* {@link ContainerConfig} and {@link ImageConfig}
*
* @param exposedPorts
* @return list of {@link ServicePort}
*/
public static List<ServicePort> getServicePortsFrom(Set<String> exposedPorts) {
List<ServicePort> servicePorts = new ArrayList<>(exposedPorts.size());
for (String exposedPort : exposedPorts) {
String[] portAndProtocol = exposedPort.split("/", 2);
String port = portAndProtocol[0];
String protocol = portAndProtocol[1];
int portNumber = Integer.parseInt(port);
String portName = CheServicePorts.get().get(portNumber);
portName = isNullOrEmpty(portName) ? exposedPort.replace("/", "-") : portName;
int targetPortNumber = portNumber;
ServicePort servicePort = new ServicePort();
servicePort.setName(portName);
servicePort.setProtocol(protocol.toUpperCase());
servicePort.setPort(portNumber);
servicePort.setTargetPort(new IntOrString(targetPortNumber));
servicePorts.add(servicePort);
}
return servicePorts;
}
Aggregations