use of io.fabric8.knative.serving.v1.Service 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.knative.serving.v1.Service 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.knative.serving.v1.Service in project fabric8 by fabric8io.
the class ConfigCompareServiceTest method testServicesSelectorNotEqual.
@Test
public void testServicesSelectorNotEqual() 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("notSame", "value2").addNewPort().withPort(123).withNewTargetPort(456).endPort().endSpec().build();
assertCompareConfig(entity1, entity2, false);
}
use of io.fabric8.knative.serving.v1.Service in project fabric8 by fabric8io.
the class ConfigCompareServiceTest method testServicesPortNotEqual.
@Test
public void testServicesPortNotEqual() 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(456).withNewTargetPort(456).endPort().endSpec().build();
assertCompareConfig(entity1, entity2, false);
}
use of io.fabric8.knative.serving.v1.Service in project fabric8 by fabric8io.
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);
}
Aggregations