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());
}
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());
}
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());
}
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);
}
}
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);
}
}
Aggregations