Search in sources :

Example 86 with Configuration

use of io.fabric8.maven.core.model.Configuration in project fabric8 by fabric8io.

the class ConfigurationTest method testNamespaceFoundFromConfigMap.

@Test
public void testNamespaceFoundFromConfigMap() {
    String devNamespace = "myproject";
    String environmentKey = "testing";
    String testNamespace = "myproject-testing";
    Map<String, String> data = new HashMap<>();
    data.put(environmentKey, "    name: Testing\n" + "    namespace: " + testNamespace + "\n" + "    order: 0");
    server.expect().withPath("/api/v1/namespaces/" + devNamespace + "/configmaps/fabric8-environments").andReturn(200, new ConfigMapBuilder().withNewMetadata().withName("fabric8-environments").endMetadata().withData(data).build()).once();
    Map<String, String> map = new HashMap<>();
    map.put(FABRIC8_ENVIRONMENT, environmentKey);
    map.put(DEVELOPMENT_NAMESPACE, devNamespace);
    Configuration configuration = Configuration.fromMap(map, getKubernetesClient());
    assertEquals(testNamespace, configuration.getNamespace());
    assertTrue(configuration.isAnsiLoggerEnabled());
    assertTrue(configuration.isEnvironmentInitEnabled());
    assertTrue(configuration.isNamespaceLazyCreateEnabled());
    assertFalse(configuration.isNamespaceCleanupEnabled());
    assertFalse(configuration.isCreateNamespaceForTest());
}
Also used : HashMap(java.util.HashMap) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) Test(org.junit.Test)

Example 87 with Configuration

use of io.fabric8.maven.core.model.Configuration in project fabric8 by fabric8io.

the class ConfigurationTest method testEnvironmentKeyButNoConfigMap.

@Test
public void testEnvironmentKeyButNoConfigMap() {
    String devNamespace = "myproject";
    String environmentKey = "testing";
    String testNamespace = devNamespace;
    Map<String, String> data = new HashMap<>();
    data.put("staging", "    name: Staging\n" + "    namespace: myproject-staging\n" + "    order: 0");
    server.expect().withPath("/api/v1/namespaces/" + devNamespace + "/configmaps/fabric8-environments").andReturn(404, "Not found").once();
    Map<String, String> map = new HashMap<>();
    map.put(FABRIC8_ENVIRONMENT, environmentKey);
    map.put(DEVELOPMENT_NAMESPACE, devNamespace);
    KubernetesClient kubernetesClient = getKubernetesClient();
    Config config = new Config();
    config.setNamespace(devNamespace);
    config.setMasterUrl(kubernetesClient.getMasterUrl().toString());
    DefaultKubernetesClient clientWithDefaultNamespace = new DefaultKubernetesClient(config);
    Configuration configuration = Configuration.fromMap(map, clientWithDefaultNamespace);
    assertEquals(testNamespace, configuration.getNamespace());
    assertTrue(configuration.isAnsiLoggerEnabled());
    assertTrue(configuration.isEnvironmentInitEnabled());
    assertTrue(configuration.isNamespaceLazyCreateEnabled());
    assertFalse(configuration.isNamespaceCleanupEnabled());
    assertFalse(configuration.isCreateNamespaceForTest());
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) HashMap(java.util.HashMap) Config(io.fabric8.kubernetes.client.Config) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) Test(org.junit.Test)

Example 88 with Configuration

use of io.fabric8.maven.core.model.Configuration in project fabric8 by fabric8io.

the class ConfigurationTest method testNamespaceNotFoundFromConfigMap.

@Ignore
public void testNamespaceNotFoundFromConfigMap() {
    String devNamespace = "myproject";
    String environmentKey = "testing";
    String testNamespace = devNamespace;
    Map<String, String> data = new HashMap<>();
    data.put("staging", "    name: Staging\n" + "    namespace: myproject-staging\n" + "    order: 0");
    server.expect().withPath("/api/v1/namespaces/" + devNamespace + "/configmaps/fabric8-environments").andReturn(200, new ConfigMapBuilder().withNewMetadata().withName("fabric8-environments").endMetadata().withData(data).build()).once();
    Map<String, String> map = new HashMap<>();
    map.put(FABRIC8_ENVIRONMENT, environmentKey);
    map.put(DEVELOPMENT_NAMESPACE, devNamespace);
    Configuration configuration = Configuration.fromMap(map, kubernetesClient);
    assertEquals(testNamespace, configuration.getNamespace());
    assertTrue(configuration.isAnsiLoggerEnabled());
    assertTrue(configuration.isEnvironmentInitEnabled());
    assertTrue(configuration.isNamespaceLazyCreateEnabled());
    assertFalse(configuration.isNamespaceCleanupEnabled());
    assertFalse(configuration.isCreateNamespaceForTest());
}
Also used : HashMap(java.util.HashMap) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) Ignore(org.junit.Ignore)

Example 89 with Configuration

use of io.fabric8.maven.core.model.Configuration 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);
    }
}
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)

Example 90 with Configuration

use of io.fabric8.maven.core.model.Configuration in project fabric8 by fabric8io.

the class SessionListener method loadDependency.

public void loadDependency(Logger log, List<KubernetesList> kubeConfigs, String dependency, Controller controller, Configuration configuration, String namespace) throws Exception {
    // lets test if the dependency is a local string
    String baseDir = System.getProperty("basedir", ".");
    String path = baseDir + "/" + dependency;
    File file = new File(path);
    if (file.exists()) {
        loadDependency(log, kubeConfigs, file, controller, configuration, log, namespace);
    } else {
        String text = readAsString(createURL(dependency));
        Object resources;
        if (text.trim().startsWith("---") || dependency.endsWith(".yml") || dependency.endsWith(".yaml")) {
            resources = loadYaml(text);
        } else {
            resources = loadJson(text);
        }
        addConfig(kubeConfigs, resources, controller, configuration, log, namespace, dependency);
    }
}
Also used : Util.readAsString(io.fabric8.arquillian.utils.Util.readAsString) File(java.io.File)

Aggregations

ParallelTest (io.strimzi.test.annotations.ParallelTest)142 Kafka (io.strimzi.api.kafka.model.Kafka)138 KafkaBuilder (io.strimzi.api.kafka.model.KafkaBuilder)132 HashMap (java.util.HashMap)97 IOException (java.io.IOException)86 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)83 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)80 Map (java.util.Map)79 StatefulSet (io.fabric8.kubernetes.api.model.apps.StatefulSet)76 ArrayList (java.util.ArrayList)76 List (java.util.List)70 TopologySpreadConstraint (io.fabric8.kubernetes.api.model.TopologySpreadConstraint)66 GenericKafkaListenerBuilder (io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder)66 Matchers.containsString (org.hamcrest.Matchers.containsString)58 Service (io.fabric8.kubernetes.api.model.Service)55 Collectors (java.util.stream.Collectors)55 Container (io.fabric8.kubernetes.api.model.Container)54 PersistentVolumeClaim (io.fabric8.kubernetes.api.model.PersistentVolumeClaim)50 Quantity (io.fabric8.kubernetes.api.model.Quantity)48 File (java.io.File)47