http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/359d3e4a/modules/integration/consul/src/main/java/org/apache/tamaya/consul/ConsulPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/integration/consul/src/main/java/org/apache/tamaya/consul/ConsulPropertySource.java b/modules/integration/consul/src/main/java/org/apache/tamaya/consul/ConsulPropertySource.java
deleted file mode 100644
index 89c903b..0000000
--- a/modules/integration/consul/src/main/java/org/apache/tamaya/consul/ConsulPropertySource.java
+++ /dev/null
@@ -1,198 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.consul;
-
-import com.fasterxml.jackson.databind.deser.Deserializers;
-import com.google.common.base.Optional;
-import com.google.common.net.HostAndPort;
-import com.orbitz.consul.Consul;
-import com.orbitz.consul.KeyValueClient;
-import com.orbitz.consul.model.kv.Value;
-import org.apache.tamaya.mutableconfig.spi.ConfigChangeRequest;
-import org.apache.tamaya.mutableconfig.spi.MutablePropertySource;
-import org.apache.tamaya.spi.PropertyValue;
-import org.apache.tamaya.spi.PropertyValueBuilder;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * Propertysource that is reading configuration from a configured consul endpoint. Setting
- * {@code consul.prefix} as system property maps the consul based onfiguration
- * to this prefix namespace. Consul servers are configured as {@code consul.urls} system or environment property.
- */
-public class ConsulPropertySource extends Deserializers.Base
-implements MutablePropertySource{
- private static final Logger LOG = Logger.getLogger(ConsulPropertySource.class.getName());
-
- private String prefix = System.getProperty("tamaya.consul.prefix", "");
-
-
- @Override
- public int getOrdinal() {
- PropertyValue configuredOrdinal = get(TAMAYA_ORDINAL);
- if(configuredOrdinal!=null){
- try{
- return Integer.parseInt(configuredOrdinal.getValue());
- } catch(Exception e){
- Logger.getLogger(getClass().getName()).log(Level.WARNING,
- "Configured Ordinal is not an int number: " + configuredOrdinal, e);
- }
- }
- return getDefaultOrdinal();
- }
-
- /**
- * Returns the default ordinal used, when no ordinal is set, or the ordinal was not parseable to an int value.
- * @return the default ordinal used, by default 1000.
- */
- public int getDefaultOrdinal(){
- return 1000;
- }
-
- @Override
- public String getName() {
- return "consul";
- }
-
- @Override
- public PropertyValue get(String key) {
- // check prefix, if key does not start with it, it is not part of our name space
- // if so, the prefix part must be removedProperties, so etcd can resolve without it
- if(!key.startsWith(prefix)){
- return null;
- } else{
- key = key.substring(prefix.length());
- }
- String reqKey = key;
- if(key.startsWith("_")){
- reqKey = key.substring(1);
- if(reqKey.endsWith(".createdIndex")){
- reqKey = reqKey.substring(0,reqKey.length()-".createdIndex".length());
- } else if(reqKey.endsWith(".modifiedIndex")){
- reqKey = reqKey.substring(0,reqKey.length()-".modifiedIndex".length());
- } else if(reqKey.endsWith(".ttl")){
- reqKey = reqKey.substring(0,reqKey.length()-".ttl".length());
- } else if(reqKey.endsWith(".expiration")){
- reqKey = reqKey.substring(0,reqKey.length()-".expiration".length());
- } else if(reqKey.endsWith(".source")){
- reqKey = reqKey.substring(0,reqKey.length()-".source".length());
- }
- }
- for(HostAndPort hostAndPort: ConsulBackends.getConsulBackends()){
- try{
- Consul consul = Consul.builder().withHostAndPort(hostAndPort).build();
- KeyValueClient kvClient = consul.keyValueClient();
- Optional<Value> valueOpt = kvClient.getValue(reqKey);
- if(!valueOpt.isPresent()) {
- LOG.log(Level.FINE, "key not found in consul: " + reqKey);
- }else{
- // No repfix mapping necessary here, since we only access/return the value...
- Value value = valueOpt.get();
- Map<String,String> props = new HashMap<>();
- props.put(reqKey+".createIndex", String.valueOf(value.getCreateIndex()));
- props.put(reqKey+".modifyIndex", String.valueOf(value.getModifyIndex()));
- props.put(reqKey+".lockIndex", String.valueOf(value.getLockIndex()));
- props.put(reqKey+".flags", String.valueOf(value.getFlags()));
- return new PropertyValueBuilder(key, value.getValue().get(), getName()).setContextData(props).build();
- }
- } catch(Exception e){
- LOG.log(Level.FINE, "etcd access failed on " + hostAndPort + ", trying next...", e);
- }
- }
- return null;
- }
-
- @Override
- public Map<String, String> getProperties() {
-// for(HostAndPort hostAndPort: ConsulBackends.getConsulBackends()){
-// try{
-// Consul consul = Consul.builder().withHostAndPort(hostAndPort).build();
-// KeyValueClient kvClient = consul.keyValueClient();
-// Optional<Value> valueOpt = kvClient.getValue(reqKey);
-// try{
-// Map<String, String> props = kvClient.getProperties("");
-// if(!props.containsKey("_ERROR")) {
-// return mapPrefix(props);
-// } else{
-// LOG.log(Level.FINE, "consul error on " + hostAndPort + ": " + props.get("_ERROR"));
-// }
-// } catch(Exception e){
-// LOG.log(Level.FINE, "consul access failed on " + hostAndPort + ", trying next...", e);
-// }
-// } catch(Exception e){
-// LOG.log(Level.FINE, "etcd access failed on " + hostAndPort + ", trying next...", e);
-// }
-// }
- return Collections.emptyMap();
- }
-
- private Map<String, String> mapPrefix(Map<String, String> props) {
- if(prefix.isEmpty()){
- return props;
- }
- Map<String,String> map = new HashMap<>();
- for(Map.Entry<String,String> entry:props.entrySet()){
- if(entry.getKey().startsWith("_")){
- map.put("_" + prefix + entry.getKey().substring(1), entry.getValue());
- } else{
- map.put(prefix+ entry.getKey(), entry.getValue());
- }
- }
- return map;
- }
-
- @Override
- public boolean isScannable() {
- return false;
- }
-
- @Override
- public void applyChange(ConfigChangeRequest configChange) {
- for(HostAndPort hostAndPort: ConsulBackends.getConsulBackends()){
- try{
- Consul consul = Consul.builder().withHostAndPort(hostAndPort).build();
- KeyValueClient kvClient = consul.keyValueClient();
-
- for(String k: configChange.getRemovedProperties()){
- try{
- kvClient.deleteKey(k);
- } catch(Exception e){
- LOG.info("Failed to remove key from consul: " + k);
- }
- }
- for(Map.Entry<String,String> en:configChange.getAddedProperties().entrySet()){
- String key = en.getKey();
- try{
- kvClient.putValue(key,en.getValue());
- }catch(Exception e) {
- LOG.info("Failed to add key to consul: " + en.getKey() + "=" + en.getValue());
- }
- }
- // success: stop here
- break;
- } catch(Exception e){
- LOG.log(Level.FINE, "consul access failed on " + hostAndPort + ", trying next...", e);
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/359d3e4a/modules/integration/consul/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySource
----------------------------------------------------------------------
diff --git a/modules/integration/consul/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySource b/modules/integration/consul/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySource
deleted file mode 100644
index 4996059..0000000
--- a/modules/integration/consul/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySource
+++ /dev/null
@@ -1,19 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy current the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-#
-org.apache.tamaya.consul.ConsulPropertySource
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/359d3e4a/modules/integration/consul/src/test/java/org/apache/tamaya/etcd/ConsulPropertySourceTest.java
----------------------------------------------------------------------
diff --git a/modules/integration/consul/src/test/java/org/apache/tamaya/etcd/ConsulPropertySourceTest.java b/modules/integration/consul/src/test/java/org/apache/tamaya/etcd/ConsulPropertySourceTest.java
deleted file mode 100644
index 415fb38..0000000
--- a/modules/integration/consul/src/test/java/org/apache/tamaya/etcd/ConsulPropertySourceTest.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.etcd;
-
-import org.apache.tamaya.consul.ConsulPropertySource;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-import java.util.Map;
-
-import static org.junit.Assert.*;
-import static org.junit.Assert.assertEquals;
-
-/**
- * Created by atsticks on 07.01.16.
- */
-public class ConsulPropertySourceTest {
-
- private final ConsulPropertySource propertySource = new ConsulPropertySource();
-
- @BeforeClass
- public static void setup(){
- System.setProperty("consul.urls", "http://127.0.0.1:8300");
- }
-
- @Test
- public void testGetOrdinal() throws Exception {
- assertEquals(propertySource.getOrdinal(), 1000);
- }
-
- @Test
- public void testGetDefaultOrdinal() throws Exception {
- assertEquals(propertySource.getDefaultOrdinal(), 1000);
- }
-
- @Test
- public void testGetName() throws Exception {
- assertEquals("consul", propertySource.getName());
- }
-
- @Test
- public void testGet() throws Exception {
- Map<String,String> props = propertySource.getProperties();
- for(Map.Entry<String,String> en:props.entrySet()){
- assertNotNull("Key not found: " + en.getKey(), propertySource.get(en.getKey()));
- }
- }
-
- @Test
- public void testGetProperties() throws Exception {
- Map<String,String> props = propertySource.getProperties();
- assertNotNull(props);
- }
-
- @Test
- public void testIsScannable() throws Exception {
- assertFalse(propertySource.isScannable());
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/359d3e4a/modules/integration/consul/src/test/java/org/apache/tamaya/etcd/ConsulWriteTest.java
----------------------------------------------------------------------
diff --git a/modules/integration/consul/src/test/java/org/apache/tamaya/etcd/ConsulWriteTest.java b/modules/integration/consul/src/test/java/org/apache/tamaya/etcd/ConsulWriteTest.java
deleted file mode 100644
index ec930b9..0000000
--- a/modules/integration/consul/src/test/java/org/apache/tamaya/etcd/ConsulWriteTest.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.etcd;
-
-import com.google.common.net.HostAndPort;
-import org.apache.tamaya.consul.ConsulPropertySource;
-import org.apache.tamaya.mutableconfig.spi.ConfigChangeRequest;
-import org.junit.BeforeClass;
-
-import java.net.MalformedURLException;
-import java.net.URISyntaxException;
-import java.util.Map;
-import java.util.UUID;
-
-import static org.junit.Assert.*;
-
-/**
- * Tests for th consul backend integration for writing to the consul backend.
- */
-public class ConsulWriteTest {
-
- private static HostAndPort accessor;
- static boolean execute = false;
- private static ConsulPropertySource propertySource;
-
- @BeforeClass
- public static void setup() throws MalformedURLException, URISyntaxException {
- System.setProperty("consul.urls", "http://127.0.0.1:8300");
- accessor = HostAndPort.fromString("127.0.0.1:8500");
- propertySource = new ConsulPropertySource();
- }
-
- @org.junit.Test
- public void testSetNormal() throws Exception {
- if (!execute) return;
- String taID = UUID.randomUUID().toString();
- ConfigChangeRequest request = new ConfigChangeRequest("testSetNormal");
- request.put(taID, "testSetNormal");
- propertySource.applyChange(request);
- }
-
-
- @org.junit.Test
- public void testDelete() throws Exception {
- if(!execute)return;
- String taID = UUID.randomUUID().toString();
- ConfigChangeRequest request = new ConfigChangeRequest("testDelete");
- request.put(taID, "testDelete");
- propertySource.applyChange(request);
- assertEquals(propertySource.get("testDelete").getValue(), taID.toString());
- assertNotNull(propertySource.get("_testDelete.createdIndex"));
- request = new ConfigChangeRequest("testDelete2");
- request.remove("testDelete");
- propertySource.applyChange(request);
- assertNull(propertySource.get("testDelete"));
- }
-
- @org.junit.Test
- public void testGetProperties() throws Exception {
- if(!execute)return;
- Map<String,String> result = propertySource.getProperties();
- assertTrue(result.isEmpty());
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/359d3e4a/modules/integration/etcd/pom.xml
----------------------------------------------------------------------
diff --git a/modules/integration/etcd/pom.xml b/modules/integration/etcd/pom.xml
deleted file mode 100644
index 7520822..0000000
--- a/modules/integration/etcd/pom.xml
+++ /dev/null
@@ -1,110 +0,0 @@
-<!--
-Licensed to the Apache Software Foundation (ASF) under one
-or more contributor license agreements. See the NOTICE file
-distributed with this work for additional information
-regarding copyright ownership. The ASF licenses this file
-to you under the Apache License, Version 2.0 (the
-"License"); you may not use this file except in compliance
-with the License. You may obtain a copy current the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing,
-software distributed under the License is distributed on an
-"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-KIND, either express or implied. See the License for the
-specific language governing permissions and limitations
-under the License.
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
-
- <parent>
- <groupId>org.apache.tamaya.ext</groupId>
- <artifactId>tamaya-integration</artifactId>
- <version>0.3-incubating-SNAPSHOT</version>
- </parent>
-
- <artifactId>tamaya-etcd</artifactId>
- <name>Apache Tamaya Integration - etcd</name>
- <packaging>bundle</packaging>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.jacoco</groupId>
- <artifactId>jacoco-maven-plugin</artifactId>
- <executions>
- <execution>
- <id>prepare-agent</id>
- <goals>
- <goal>prepare-agent</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-bundle-plugin</artifactId>
- <extensions>true</extensions>
- <configuration>
- <instructions>
- <Export-Package>
- org.apache.tamaya.etcd
- </Export-Package>
- </instructions>
- </configuration>
- </plugin>
- </plugins>
- </build>
- <dependencies>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.hamcrest</groupId>
- <artifactId>java-hamcrest</artifactId>
- <scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>org.apache.tamaya</groupId>
- <artifactId>tamaya-core</artifactId>
- <version>${project.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.tamaya</groupId>
- <artifactId>tamaya-api</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.tamaya.ext</groupId>
- <artifactId>tamaya-functions</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.httpcomponents</groupId>
- <artifactId>httpclient-osgi</artifactId>
- <version>4.5.1</version>
- </dependency>
- <dependency>
- <groupId>org.apache.geronimo.specs</groupId>
- <artifactId>geronimo-json_1.0_spec</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.johnzon</groupId>
- <artifactId>johnzon-core</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.tamaya.ext</groupId>
- <artifactId>tamaya-mutable-config</artifactId>
- <version>${project.version}</version>
- <scope>provided</scope>
- <optional>true</optional>
- </dependency>
- </dependencies>
-
-</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/359d3e4a/modules/integration/etcd/src/main/java/org/apache/tamaya/etcd/EtcdAccessor.java
----------------------------------------------------------------------
diff --git a/modules/integration/etcd/src/main/java/org/apache/tamaya/etcd/EtcdAccessor.java b/modules/integration/etcd/src/main/java/org/apache/tamaya/etcd/EtcdAccessor.java
deleted file mode 100644
index 4feccfa..0000000
--- a/modules/integration/etcd/src/main/java/org/apache/tamaya/etcd/EtcdAccessor.java
+++ /dev/null
@@ -1,520 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.etcd;
-
-import java.io.StringReader;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import javax.json.Json;
-import javax.json.JsonArray;
-import javax.json.JsonObject;
-import javax.json.JsonReader;
-import javax.json.JsonReaderFactory;
-
-import org.apache.http.HttpEntity;
-import org.apache.http.HttpStatus;
-import org.apache.http.NameValuePair;
-import org.apache.http.client.config.RequestConfig;
-import org.apache.http.client.entity.UrlEncodedFormEntity;
-import org.apache.http.client.methods.CloseableHttpResponse;
-import org.apache.http.client.methods.HttpDelete;
-import org.apache.http.client.methods.HttpGet;
-import org.apache.http.client.methods.HttpPut;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.HttpClients;
-import org.apache.http.message.BasicNameValuePair;
-import org.apache.http.util.EntityUtils;
-
-/**
- * Accessor for reading to or writing from an etcd endpoint.
- */
-public class EtcdAccessor {
-
- private static final Logger LOG = Logger.getLogger(EtcdAccessor.class.getName());
-
- /**
- * Timeout in seconds.
- */
- private int timeout = 2;
- /**
- * Timeout in seconds.
- */
- private final int socketTimeout = 1000;
- /**
- * Timeout in seconds.
- */
- private final int connectTimeout = 1000;
-
- /**
- * Property that make Johnzon accept commentc.
- */
- public static final String JOHNZON_SUPPORTS_COMMENTS_PROP = "org.apache.johnzon.supports-comments";
- /**
- * The JSON reader factory used.
- */
- private final JsonReaderFactory readerFactory = initReaderFactory();
-
- /**
- * Initializes the factory to be used for creating readers.
- */
- private JsonReaderFactory initReaderFactory() {
- final Map<String, Object> config = new HashMap<>();
- config.put(JOHNZON_SUPPORTS_COMMENTS_PROP, true);
- return Json.createReaderFactory(config);
- }
-
- /**
- * The base server url.
- */
- private final String serverURL;
- /**
- * The http client.
- */
- private final CloseableHttpClient httpclient = HttpClients.createDefault();
-
- /**
- * Creates a new instance with the basic access url.
- *
- * @param server server url, e.g. {@code http://127.0.0.1:4001}, not null.
- */
- public EtcdAccessor(String server) {
- this(server, 2);
- }
-
- public EtcdAccessor(String server, int timeout) {
- this.timeout = timeout;
- if (server.endsWith("/")) {
- serverURL = server.substring(0, server.length() - 1);
- } else {
- serverURL = server;
- }
-
- }
-
- /**
- * Get the etcd server version.
- *
- * @return the etcd server version, never null.
- */
- public String getVersion() {
- String version = "<ERROR>";
- try {
- final CloseableHttpClient httpclient = HttpClients.createDefault();
- final HttpGet httpGet = new HttpGet(serverURL + "/version");
- httpGet.setConfig(RequestConfig.copy(RequestConfig.DEFAULT).setSocketTimeout(socketTimeout)
- .setConnectTimeout(timeout).build());
- try (CloseableHttpResponse response = httpclient.execute(httpGet)) {
- if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
- final HttpEntity entity = response.getEntity();
- // and ensure it is fully consumed
- version = EntityUtils.toString(entity);
- EntityUtils.consume(entity);
- }
- }
- return version;
- } catch (final Exception e) {
- LOG.log(Level.INFO, "Error getting etcd version from: " + serverURL, e);
- }
- return version;
- }
-
- /**
- * Ask etcd for a single key, value pair. Hereby the response returned from
- * etcd:
- *
- * <pre>
- * {
- * "action": "get",
- * "node": {
- * "createdIndex": 2,
- * "key": "/message",
- * "modifiedIndex": 2,
- * "value": "Hello world"
- * }
- * }
- * </pre>
- *
- * is mapped to:
- *
- * <pre>
- * key=value
- * _key.source=[etcd]http://127.0.0.1:4001
- * _key.createdIndex=12
- * _key.modifiedIndex=34
- * _key.ttl=300
- * _key.expiration=...
- * </pre>
- *
- * @param key the requested key
- * @return the mapped result, including meta-entries.
- */
- public Map<String, String> get(String key) {
- final Map<String, String> result = new HashMap<>();
- try {
- final HttpGet httpGet = new HttpGet(serverURL + "/v2/keys/" + key);
- httpGet.setConfig(RequestConfig.copy(RequestConfig.DEFAULT).setSocketTimeout(socketTimeout)
- .setConnectionRequestTimeout(timeout).setConnectTimeout(connectTimeout).build());
- try (CloseableHttpResponse response = httpclient.execute(httpGet)) {
- if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
- final HttpEntity entity = response.getEntity();
- final JsonReader reader = readerFactory
- .createReader(new StringReader(EntityUtils.toString(entity)));
- final JsonObject o = reader.readObject();
- final JsonObject node = o.getJsonObject("node");
- if (node.containsKey("value")) {
- result.put(key, node.getString("value"));
- result.put("_" + key + ".source", "[etcd]" + serverURL);
- }
- if (node.containsKey("createdIndex")) {
- result.put("_" + key + ".createdIndex", String.valueOf(node.getInt("createdIndex")));
- }
- if (node.containsKey("modifiedIndex")) {
- result.put("_" + key + ".modifiedIndex", String.valueOf(node.getInt("modifiedIndex")));
- }
- if (node.containsKey("expiration")) {
- result.put("_" + key + ".expiration", String.valueOf(node.getString("expiration")));
- }
- if (node.containsKey("ttl")) {
- result.put("_" + key + ".ttl", String.valueOf(node.getInt("ttl")));
- }
- EntityUtils.consume(entity);
- } else {
- result.put("_" + key + ".NOT_FOUND.target", "[etcd]" + serverURL);
- }
- }
- } catch (final Exception e) {
- LOG.log(Level.INFO, "Error reading key '" + key + "' from etcd: " + serverURL, e);
- result.put("_ERROR", "Error reading key '" + key + "' from etcd: " + serverURL + ": " + e.toString());
- }
- return result;
- }
-
- /**
- * Creates/updates an entry in etcd without any ttl set.
- *
- * @param key the property key, not null
- * @param value the value to be set
- * @return the result map as described above.
- * @see #set(String, String, Integer)
- */
- public Map<String, String> set(String key, String value) {
- return set(key, value, null);
- }
-
- /**
- * Creates/updates an entry in etcd. The response as follows:
- *
- * <pre>
- * {
- * "action": "set",
- * "node": {
- * "createdIndex": 3,
- * "key": "/message",
- * "modifiedIndex": 3,
- * "value": "Hello etcd"
- * },
- * "prevNode": {
- * "createdIndex": 2,
- * "key": "/message",
- * "value": "Hello world",
- * "modifiedIndex": 2
- * }
- * }
- * </pre>
- *
- * is mapped to:
- *
- * <pre>
- * key=value
- * _key.source=[etcd]http://127.0.0.1:4001
- * _key.createdIndex=12
- * _key.modifiedIndex=34
- * _key.ttl=300
- * _key.expiry=...
- * // optional
- * _key.prevNode.createdIndex=12
- * _key.prevNode.modifiedIndex=34
- * _key.prevNode.ttl=300
- * _key.prevNode.expiration=...
- * </pre>
- *
- * @param key the property key, not null
- * @param value the value to be set
- * @param ttlSeconds the ttl in seconds (optional)
- * @return the result map as described above.
- */
- public Map<String, String> set(String key, String value, Integer ttlSeconds) {
- final Map<String, String> result = new HashMap<>();
- try {
- final HttpPut put = new HttpPut(serverURL + "/v2/keys/" + key);
- put.setConfig(RequestConfig.copy(RequestConfig.DEFAULT).setSocketTimeout(socketTimeout)
- .setConnectionRequestTimeout(timeout).setConnectTimeout(connectTimeout).build());
- final List<NameValuePair> nvps = new ArrayList<>();
- nvps.add(new BasicNameValuePair("value", value));
- if (ttlSeconds != null) {
- nvps.add(new BasicNameValuePair("ttl", ttlSeconds.toString()));
- }
- put.setEntity(new UrlEncodedFormEntity(nvps));
- try (CloseableHttpResponse response = httpclient.execute(put)) {
- if (response.getStatusLine().getStatusCode() == HttpStatus.SC_CREATED
- || response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
- final HttpEntity entity = response.getEntity();
- final JsonReader reader = readerFactory
- .createReader(new StringReader(EntityUtils.toString(entity)));
- final JsonObject o = reader.readObject();
- final JsonObject node = o.getJsonObject("node");
- if (node.containsKey("createdIndex")) {
- result.put("_" + key + ".createdIndex", String.valueOf(node.getInt("createdIndex")));
- }
- if (node.containsKey("modifiedIndex")) {
- result.put("_" + key + ".modifiedIndex", String.valueOf(node.getInt("modifiedIndex")));
- }
- if (node.containsKey("expiration")) {
- result.put("_" + key + ".expiration", String.valueOf(node.getString("expiration")));
- }
- if (node.containsKey("ttl")) {
- result.put("_" + key + ".ttl", String.valueOf(node.getInt("ttl")));
- }
- result.put(key, node.getString("value"));
- result.put("_" + key + ".source", "[etcd]" + serverURL);
- parsePrevNode(key, result, node);
- EntityUtils.consume(entity);
- }
- }
- } catch (final Exception e) {
- LOG.log(Level.INFO, "Error writing to etcd: " + serverURL, e);
- result.put("_ERROR", "Error writing '" + key + "' to etcd: " + serverURL + ": " + e.toString());
- }
- return result;
- }
-
- /**
- * Deletes a given key. The response is as follows:
- *
- * <pre>
- * _key.source=[etcd]http://127.0.0.1:4001
- * _key.createdIndex=12
- * _key.modifiedIndex=34
- * _key.ttl=300
- * _key.expiry=...
- * // optional
- * _key.prevNode.createdIndex=12
- * _key.prevNode.modifiedIndex=34
- * _key.prevNode.ttl=300
- * _key.prevNode.expiration=...
- * _key.prevNode.value=...
- * </pre>
- *
- * @param key the key to be deleted.
- * @return the response mpas as described above.
- */
- public Map<String, String> delete(String key) {
- final Map<String, String> result = new HashMap<>();
- try {
- final HttpDelete delete = new HttpDelete(serverURL + "/v2/keys/" + key);
- delete.setConfig(RequestConfig.copy(RequestConfig.DEFAULT).setSocketTimeout(socketTimeout)
- .setConnectionRequestTimeout(timeout).setConnectTimeout(connectTimeout).build());
- try (CloseableHttpResponse response = httpclient.execute(delete)) {
- if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
- final HttpEntity entity = response.getEntity();
- final JsonReader reader = readerFactory
- .createReader(new StringReader(EntityUtils.toString(entity)));
- final JsonObject o = reader.readObject();
- final JsonObject node = o.getJsonObject("node");
- if (node.containsKey("createdIndex")) {
- result.put("_" + key + ".createdIndex", String.valueOf(node.getInt("createdIndex")));
- }
- if (node.containsKey("modifiedIndex")) {
- result.put("_" + key + ".modifiedIndex", String.valueOf(node.getInt("modifiedIndex")));
- }
- if (node.containsKey("expiration")) {
- result.put("_" + key + ".expiration", String.valueOf(node.getString("expiration")));
- }
- if (node.containsKey("ttl")) {
- result.put("_" + key + ".ttl", String.valueOf(node.getInt("ttl")));
- }
- parsePrevNode(key, result, o);
- EntityUtils.consume(entity);
- }
- }
- } catch (final Exception e) {
- LOG.log(Level.INFO, "Error deleting key '" + key + "' from etcd: " + serverURL, e);
- result.put("_ERROR", "Error deleting '" + key + "' from etcd: " + serverURL + ": " + e.toString());
- }
- return result;
- }
-
- private static void parsePrevNode(String key, Map<String, String> result, JsonObject o) {
- if (o.containsKey("prevNode")) {
- final JsonObject prevNode = o.getJsonObject("prevNode");
- if (prevNode.containsKey("createdIndex")) {
- result.put("_" + key + ".prevNode.createdIndex",
- String.valueOf(prevNode.getInt("createdIndex")));
- }
- if (prevNode.containsKey("modifiedIndex")) {
- result.put("_" + key + ".prevNode.modifiedIndex",
- String.valueOf(prevNode.getInt("modifiedIndex")));
- }
- if (prevNode.containsKey("expiration")) {
- result.put("_" + key + ".prevNode.expiration",
- String.valueOf(prevNode.getString("expiration")));
- }
- if (prevNode.containsKey("ttl")) {
- result.put("_" + key + ".prevNode.ttl", String.valueOf(prevNode.getInt("ttl")));
- }
- result.put("_" + key + ".prevNode.value", prevNode.getString("value"));
- }
- }
-
- /**
- * Get all properties for the given directory key recursively.
- *
- * @param directory the directory entry
- * @return the properties and its metadata
- * @see #getProperties(String, boolean)
- */
- public Map<String, String> getProperties(String directory) {
- return getProperties(directory, true);
- }
-
- /**
- * Access all properties. The response of:
- *
- * <pre>
- * {
- * "action": "get",
- * "node": {
- * "key": "/",
- * "dir": true,
- * "nodes": [
- * {
- * "key": "/foo_dir",
- * "dir": true,
- * "modifiedIndex": 2,
- * "createdIndex": 2
- * },
- * {
- * "key": "/foo",
- * "value": "two",
- * "modifiedIndex": 1,
- * "createdIndex": 1
- * }
- * ]
- * }
- * }
- * </pre>
- *
- * is mapped to a regular Tamaya properties map as follows:
- *
- * <pre>
- * key1=myvalue
- * _key1.source=[etcd]http://127.0.0.1:4001
- * _key1.createdIndex=12
- * _key1.modifiedIndex=34
- * _key1.ttl=300
- * _key1.expiration=...
- *
- * key2=myvaluexxx
- * _key2.source=[etcd]http://127.0.0.1:4001
- * _key2.createdIndex=12
- *
- * key3=val3
- * _key3.source=[etcd]http://127.0.0.1:4001
- * _key3.createdIndex=12
- * _key3.modifiedIndex=2
- * </pre>
- *
- * @param directory remote directory to query.
- * @param recursive allows to set if querying is performed recursively
- * @return all properties read from the remote server.
- */
- public Map<String, String> getProperties(String directory, boolean recursive) {
- final Map<String, String> result = new HashMap<>();
- try {
- final HttpGet get = new HttpGet(serverURL + "/v2/keys/" + directory + "?recursive=" + recursive);
- get.setConfig(RequestConfig.copy(RequestConfig.DEFAULT).setSocketTimeout(socketTimeout)
- .setConnectionRequestTimeout(timeout).setConnectTimeout(connectTimeout).build());
- try (CloseableHttpResponse response = httpclient.execute(get)) {
-
- if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
- final HttpEntity entity = response.getEntity();
- final JsonReader reader = readerFactory.createReader(new StringReader(EntityUtils.toString(entity)));
- final JsonObject o = reader.readObject();
- final JsonObject node = o.getJsonObject("node");
- if (node != null) {
- addNodes(result, node);
- }
- EntityUtils.consume(entity);
- }
- }
- } catch (final Exception e) {
- LOG.log(Level.INFO, "Error reading properties for '" + directory + "' from etcd: " + serverURL, e);
- result.put("_ERROR",
- "Error reading properties for '" + directory + "' from etcd: " + serverURL + ": " + e.toString());
- }
- return result;
- }
-
- /**
- * Recursively read out all key/values from this etcd JSON array.
- *
- * @param result map with key, values and metadata.
- * @param node the node to parse.
- */
- private void addNodes(Map<String, String> result, JsonObject node) {
- if (!node.containsKey("dir") || "false".equals(node.get("dir").toString())) {
- final String key = node.getString("key").substring(1);
- result.put(key, node.getString("value"));
- if (node.containsKey("createdIndex")) {
- result.put("_" + key + ".createdIndex", String.valueOf(node.getInt("createdIndex")));
- }
- if (node.containsKey("modifiedIndex")) {
- result.put("_" + key + ".modifiedIndex", String.valueOf(node.getInt("modifiedIndex")));
- }
- if (node.containsKey("expiration")) {
- result.put("_" + key + ".expiration", String.valueOf(node.getString("expiration")));
- }
- if (node.containsKey("ttl")) {
- result.put("_" + key + ".ttl", String.valueOf(node.getInt("ttl")));
- }
- result.put("_" + key + ".source", "[etcd]" + serverURL);
- } else {
- final JsonArray nodes = node.getJsonArray("nodes");
- if (nodes != null) {
- for (int i = 0; i < nodes.size(); i++) {
- addNodes(result, nodes.getJsonObject(i));
- }
- }
- }
- }
-
- /**
- * Access the server root URL used by this accessor.
- *
- * @return the server root URL.
- */
- public String getUrl() {
- return serverURL;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/359d3e4a/modules/integration/etcd/src/main/java/org/apache/tamaya/etcd/EtcdBackends.java
----------------------------------------------------------------------
diff --git a/modules/integration/etcd/src/main/java/org/apache/tamaya/etcd/EtcdBackends.java b/modules/integration/etcd/src/main/java/org/apache/tamaya/etcd/EtcdBackends.java
deleted file mode 100644
index a0c0703..0000000
--- a/modules/integration/etcd/src/main/java/org/apache/tamaya/etcd/EtcdBackends.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.etcd;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * Singleton that reads and stores the current etcd setup, especially the possible URLs to be used.
- */
-public final class EtcdBackends {
-
- private static final Logger LOG = Logger.getLogger(EtcdBackends.class.getName());
- private static List<EtcdAccessor> etcdBackends = new ArrayList<>();
-
- static{
- int timeout = 2;
- String val = System.getProperty("tamaya.etcd.timeout");
- if(val == null){
- val = System.getenv("tamaya.etcd.timeout");
- }
- if(val!=null){
- timeout = Integer.parseInt(val);
- }
- String serverURLs = System.getProperty("tamaya.etcd.server.urls");
- if(serverURLs==null){
- serverURLs = System.getenv("tamaya.etcd.server.urls");
- }
- if(serverURLs==null){
- serverURLs = "http://127.0.0.1:4001";
- }
- for(String url:serverURLs.split("\\,")) {
- try{
- etcdBackends.add(new EtcdAccessor(url.trim(), timeout));
- LOG.info("Using etcd endoint: " + url);
- } catch(Exception e){
- LOG.log(Level.SEVERE, "Error initializing etcd accessor for URL: " + url, e);
- }
- }
- }
-
- private EtcdBackends(){}
-
- public static List<EtcdAccessor> getEtcdBackends(){
- return etcdBackends;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/359d3e4a/modules/integration/etcd/src/main/java/org/apache/tamaya/etcd/EtcdPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/integration/etcd/src/main/java/org/apache/tamaya/etcd/EtcdPropertySource.java b/modules/integration/etcd/src/main/java/org/apache/tamaya/etcd/EtcdPropertySource.java
deleted file mode 100644
index 5e129f7..0000000
--- a/modules/integration/etcd/src/main/java/org/apache/tamaya/etcd/EtcdPropertySource.java
+++ /dev/null
@@ -1,209 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.etcd;
-
-import org.apache.tamaya.mutableconfig.spi.ConfigChangeRequest;
-import org.apache.tamaya.mutableconfig.spi.MutablePropertySource;
-import org.apache.tamaya.spi.PropertyValue;
-import org.apache.tamaya.spi.PropertyValueBuilder;
-import org.apache.tamaya.spisupport.BasePropertySource;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * Propertysource that is reading configuration from a configured etcd endpoint. Setting
- * {@code etcd.prefix} as system property maps the etcd based onfiguration
- * to this prefix namespace. Etcd servers are configured as {@code etcd.server.urls} system or environment property.
- * ETcd can be disabled by setting {@code tamaya.etcdprops.disable} either as env or system property.
- */
-public class EtcdPropertySource extends BasePropertySource
- implements MutablePropertySource{
- private static final Logger LOG = Logger.getLogger(EtcdPropertySource.class.getName());
-
- private String prefix = System.getProperty("tamaya.etcd.prefix", "");
-
- private final boolean disabled = evaluateDisabled();
-
- private boolean evaluateDisabled() {
- String value = System.getProperty("tamaya.etcdprops.disable");
- if(value==null){
- value = System.getenv("tamaya.etcdprops.disable");
- }
- if(value==null){
- return false;
- }
- return value.isEmpty() || Boolean.parseBoolean(value);
- }
-
- @Override
- public int getOrdinal() {
- PropertyValue configuredOrdinal = get(TAMAYA_ORDINAL);
- if(configuredOrdinal!=null){
- try{
- return Integer.parseInt(configuredOrdinal.getValue());
- } catch(Exception e){
- Logger.getLogger(getClass().getName()).log(Level.WARNING,
- "Configured Ordinal is not an int number: " + configuredOrdinal, e);
- }
- }
- return getDefaultOrdinal();
- }
-
- /**
- * Returns the default ordinal used, when no ordinal is set, or the ordinal was not parseable to an int value.
- * @return the default ordinal used, by default 0.
- */
- public int getDefaultOrdinal(){
- return 1000;
- }
-
- @Override
- public String getName() {
- return "etcd";
- }
-
- @Override
- public PropertyValue get(String key) {
- if(disabled){
- return null;
- }
- // check prefix, if key does not start with it, it is not part of our name space
- // if so, the prefix part must be removedProperties, so etcd can resolve without it
- if(!key.startsWith(prefix)){
- return null;
- } else{
- key = key.substring(prefix.length());
- }
- Map<String,String> props;
- String reqKey = key;
- if(key.startsWith("_")){
- reqKey = key.substring(1);
- if(reqKey.endsWith(".createdIndex")){
- reqKey = reqKey.substring(0,reqKey.length()-".createdIndex".length());
- } else if(reqKey.endsWith(".modifiedIndex")){
- reqKey = reqKey.substring(0,reqKey.length()-".modifiedIndex".length());
- } else if(reqKey.endsWith(".ttl")){
- reqKey = reqKey.substring(0,reqKey.length()-".ttl".length());
- } else if(reqKey.endsWith(".expiration")){
- reqKey = reqKey.substring(0,reqKey.length()-".expiration".length());
- } else if(reqKey.endsWith(".source")){
- reqKey = reqKey.substring(0,reqKey.length()-".source".length());
- }
- }
- for(EtcdAccessor accessor: EtcdBackends.getEtcdBackends()){
- try{
- props = accessor.get(reqKey);
- if(!props.containsKey("_ERROR")) {
- // No repfix mapping necessary here, since we only access/return the value...
- return new PropertyValueBuilder(key, props.get(reqKey), getName()).setContextData(props).build();
- } else{
- LOG.log(Level.FINE, "etcd error on " + accessor.getUrl() + ": " + props.get("_ERROR"));
- }
- } catch(Exception e){
- LOG.log(Level.FINE, "etcd access failed on " + accessor.getUrl() + ", trying next...", e);
- }
- }
- return null;
- }
-
- @Override
- public Map<String, String> getProperties() {
- if(disabled){
- return Collections.emptyMap();
- }
- if(!EtcdBackends.getEtcdBackends().isEmpty()){
- for(EtcdAccessor accessor: EtcdBackends.getEtcdBackends()){
- try{
- Map<String, String> props = accessor.getProperties("");
- if(!props.containsKey("_ERROR")) {
- return mapPrefix(props);
- } else{
- LOG.log(Level.FINE, "etcd error on " + accessor.getUrl() + ": " + props.get("_ERROR"));
- }
- } catch(Exception e){
- LOG.log(Level.FINE, "etcd access failed on " + accessor.getUrl() + ", trying next...", e);
- }
- }
- }
- return Collections.emptyMap();
- }
-
- private Map<String, String> mapPrefix(Map<String, String> props) {
- if(prefix.isEmpty()){
- return props;
- }
- Map<String,String> map = new HashMap<>();
- for(Map.Entry<String,String> entry:props.entrySet()){
- if(entry.getKey().startsWith("_")){
- map.put("_" + prefix + entry.getKey().substring(1), entry.getValue());
- } else{
- map.put(prefix+ entry.getKey(), entry.getValue());
- }
- }
- return map;
- }
-
- @Override
- public boolean isScannable() {
- return true;
- }
-
- @Override
- public void applyChange(ConfigChangeRequest configChange) {
- for(EtcdAccessor accessor: EtcdBackends.getEtcdBackends()){
- try{
- for(String k: configChange.getRemovedProperties()){
- Map<String,String> res = accessor.delete(k);
- if(res.get("_ERROR")!=null){
- LOG.info("Failed to remove key from etcd: " + k);
- }
- }
- for(Map.Entry<String,String> en:configChange.getAddedProperties().entrySet()){
- String key = en.getKey();
- Integer ttl = null;
- int index = en.getKey().indexOf('?');
- if(index>0){
- key = en.getKey().substring(0, index);
- String rawQuery = en.getKey().substring(index+1);
- String[] queries = rawQuery.split("&");
- for(String query:queries){
- if(query.contains("ttl")){
- int qIdx = query.indexOf('=');
- ttl = qIdx>0?Integer.parseInt(query.substring(qIdx+1).trim()):null;
- }
- }
- }
- Map<String,String> res = accessor.set(key, en.getValue(), ttl);
- if(res.get("_ERROR")!=null){
- LOG.info("Failed to add key to etcd: " + en.getKey() + "=" + en.getValue());
- }
- }
- // success, stop here
- break;
- } catch(Exception e){
- LOG.log(Level.FINE, "etcd access failed on " + accessor.getUrl() + ", trying next...", e);
- }
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/359d3e4a/modules/integration/etcd/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySource
----------------------------------------------------------------------
diff --git a/modules/integration/etcd/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySource b/modules/integration/etcd/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySource
deleted file mode 100644
index eb7958e..0000000
--- a/modules/integration/etcd/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySource
+++ /dev/null
@@ -1,19 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy current the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-#
-org.apache.tamaya.etcd.EtcdPropertySource
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/359d3e4a/modules/integration/etcd/src/test/java/org/apache/tamaya/etcd/EtcdAccessorTest.java
----------------------------------------------------------------------
diff --git a/modules/integration/etcd/src/test/java/org/apache/tamaya/etcd/EtcdAccessorTest.java b/modules/integration/etcd/src/test/java/org/apache/tamaya/etcd/EtcdAccessorTest.java
deleted file mode 100644
index 80bd716..0000000
--- a/modules/integration/etcd/src/test/java/org/apache/tamaya/etcd/EtcdAccessorTest.java
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.etcd;
-
-import org.junit.BeforeClass;
-
-import java.net.MalformedURLException;
-import java.util.Map;
-import java.util.UUID;
-
-import static org.junit.Assert.*;
-
-/**
- * Tests for th etcd backend integration. You must have set a system property so, theses tests are executed, e.g.
- * {@code -Detcd.url=http://127.0.0.1:4001}.
- */
-public class EtcdAccessorTest {
-
- private static EtcdAccessor accessor;
- static boolean execute = false;
-
- @BeforeClass
- public static void setup() throws MalformedURLException {
- accessor = new EtcdAccessor("http://192.168.99.105:4001");
- if(!accessor.getVersion().contains("etcd")){
- System.out.println("Disabling etcd tests, etcd not accessible at: " + System.getProperty("etcd.server.urls"));
- System.out.println("Configure etcd with -Detcd.server.urls=http://<IP>:<PORT>");
- }
- else{
- execute = true;
- }
- }
-
- @org.junit.Test
- public void testGetVersion() throws Exception {
- if(!execute)return;
- assertEquals(accessor.getVersion(), "etcd 0.4.9");
- }
-
- @org.junit.Test
- public void testGet() throws Exception {
- if(!execute)return;
- Map<String,String> result = accessor.get("test1");
- assertNotNull(result);
- }
-
- @org.junit.Test
- public void testSetNormal() throws Exception {
- if(!execute)return;
- String value = UUID.randomUUID().toString();
- Map<String,String> result = accessor.set("testSetNormal", value);
- assertNull(result.get("_testSetNormal.ttl"));
- assertEquals(accessor.get("testSetNormal").get("testSetNormal"), value);
- }
-
- @org.junit.Test
- public void testSetNormal2() throws Exception {
- if(!execute)return;
- String value = UUID.randomUUID().toString();
- Map<String,String> result = accessor.set("testSetNormal2", value, null);
- assertNull(result.get("_testSetNormal2.ttl"));
- assertEquals(accessor.get("testSetNormal2").get("testSetNormal2"), value);
- }
-
- @org.junit.Test
- public void testSetWithTTL() throws Exception {
- if(!execute)return;
- String value = UUID.randomUUID().toString();
- Map<String,String> result = accessor.set("testSetWithTTL", value, 1);
- assertNotNull(result.get("_testSetWithTTL.ttl"));
- assertEquals(accessor.get("testSetWithTTL").get("testSetWithTTL"), value);
- Thread.sleep(2000L);
- result = accessor.get("testSetWithTTL");
- assertNull(result.get("testSetWithTTL"));
- }
-
-
- @org.junit.Test
- public void testDelete() throws Exception {
- if(!execute)return;
- String value = UUID.randomUUID().toString();
- Map<String,String> result = accessor.set("testDelete", value, null);
- assertEquals(accessor.get("testDelete").get("testDelete"), value);
- assertNotNull(result.get("_testDelete.createdIndex"));
- result = accessor.delete("testDelete");
- assertEquals(result.get("_testDelete.prevNode.value"),value);
- assertNull(accessor.get("testDelete").get("testDelete"));
- }
-
- @org.junit.Test
- public void testGetProperties() throws Exception {
- if(!execute)return;
- String value = UUID.randomUUID().toString();
- accessor.set("testGetProperties1", value);
- Map<String,String> result = accessor.getProperties("");
- assertNotNull(result);
- assertEquals(result.get("testGetProperties1"), value);
- assertNotNull(result.get("_testGetProperties1.createdIndex"));
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/359d3e4a/modules/integration/etcd/src/test/java/org/apache/tamaya/etcd/EtcdPropertySourceTest.java
----------------------------------------------------------------------
diff --git a/modules/integration/etcd/src/test/java/org/apache/tamaya/etcd/EtcdPropertySourceTest.java b/modules/integration/etcd/src/test/java/org/apache/tamaya/etcd/EtcdPropertySourceTest.java
deleted file mode 100644
index 898a963..0000000
--- a/modules/integration/etcd/src/test/java/org/apache/tamaya/etcd/EtcdPropertySourceTest.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.etcd;
-
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-import java.util.Map;
-
-import static org.junit.Assert.*;
-import static org.junit.Assert.assertEquals;
-
-/**
- * Created by atsticks on 07.01.16.
- */
-public class EtcdPropertySourceTest {
-
- private final EtcdPropertySource propertySource = new EtcdPropertySource();
-
- @BeforeClass
- public static void setup(){
- System.setProperty("etcd.server.urls", "http://8.8.8.8:4001,http://192.168.99.105:4001");
- }
-
- @Test
- public void testGetOrdinal() throws Exception {
- assertEquals(propertySource.getOrdinal(), 1000);
- }
-
- @Test
- public void testGetDefaultOrdinal() throws Exception {
- assertEquals(propertySource.getDefaultOrdinal(), 1000);
- }
-
- @Test
- public void testGetName() throws Exception {
- assertEquals("etcd", propertySource.getName());
- }
-
- @Test
- public void testGet() throws Exception {
- Map<String,String> props = propertySource.getProperties();
- for(Map.Entry<String,String> en:props.entrySet()){
- assertNotNull("Key not found: " + en.getKey(), propertySource.get(en.getKey()));
- }
- }
-
- @Test
- public void testGetProperties() throws Exception {
- Map<String,String> props = propertySource.getProperties();
- assertNotNull(props);
- }
-
- @Test
- public void testIsScannable() throws Exception {
- assertTrue(propertySource.isScannable());
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/359d3e4a/modules/integration/osgi/pom.xml
----------------------------------------------------------------------
diff --git a/modules/integration/osgi/pom.xml b/modules/integration/osgi/pom.xml
deleted file mode 100644
index e57f395..0000000
--- a/modules/integration/osgi/pom.xml
+++ /dev/null
@@ -1,102 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-
- <!--
-
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- -->
-
- <modelVersion>4.0.0</modelVersion>
-
- <parent>
- <groupId>org.apache.tamaya.ext</groupId>
- <artifactId>tamaya-integration</artifactId>
- <version>0.3-incubating-SNAPSHOT</version>
- </parent>
-
- <artifactId>tamaya-osgi</artifactId>
- <packaging>bundle</packaging>
- <name>Apache Tamaya Integration - OSGi Services :: Tamaya Config</name>
- <description>Tamaya Based OSGI Implementation of ConfigAdmin and Config Injection</description>
-
- <properties>
- <felix.plugin.version>2.5.4</felix.plugin.version>
- </properties>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-bundle-plugin</artifactId>
- <version>${felix.plugin.version}</version>
- <inherited>true</inherited>
- <extensions>true</extensions>
- <configuration>
- <instructions>
- <Bundle-Activator>
- org.apache.tamaya.integration.osgi.Activator
- </Bundle-Activator>
- <Export-Service>
- org.osgi.service.cm.ConfigurationAdmin
- </Export-Service>
- </instructions>
- </configuration>
- </plugin>
- </plugins>
- </build>
-
- <dependencies>
- <dependency>
- <groupId>org.apache.felix</groupId>
- <artifactId>org.apache.felix.configadmin</artifactId>
- <version>1.8.8</version>
- </dependency>
- <dependency>
- <groupId>org.osgi</groupId>
- <artifactId>org.osgi.core</artifactId>
- <version>6.0.0</version>
- </dependency>
- <dependency>
- <groupId>org.apache.tamaya</groupId>
- <artifactId>tamaya-api</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.tamaya.ext</groupId>
- <artifactId>tamaya-functions</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.tamaya.ext</groupId>
- <artifactId>tamaya-spisupport</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.tamaya.ext</groupId>
- <artifactId>tamaya-injection</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.hamcrest</groupId>
- <artifactId>java-hamcrest</artifactId>
- </dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- </dependency>
- </dependencies>
-
-</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/359d3e4a/modules/integration/osgi/src/main/java/org/apache/tamaya/integration/osgi/Activator.java
----------------------------------------------------------------------
diff --git a/modules/integration/osgi/src/main/java/org/apache/tamaya/integration/osgi/Activator.java b/modules/integration/osgi/src/main/java/org/apache/tamaya/integration/osgi/Activator.java
deleted file mode 100644
index 7425dfb..0000000
--- a/modules/integration/osgi/src/main/java/org/apache/tamaya/integration/osgi/Activator.java
+++ /dev/null
@@ -1,134 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.integration.osgi;
-
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.ConfigurationProvider;
-import org.apache.tamaya.inject.ConfigurationInjection;
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceReference;
-import org.osgi.framework.ServiceRegistration;
-import org.osgi.service.cm.ConfigurationAdmin;
-import org.osgi.util.tracker.ServiceTracker;
-
-import java.util.Dictionary;
-import java.util.Hashtable;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * Activator that registers the Tamaya based Service Class for {@link ConfigurationAdmin},
- * using a default service priority of {@code 0}. This behaviour is configurable based on OSGI properties:
- * <ul>
- * <li><p><b>org.tamaya.integration.osgi.cm.ranking, type: int</b> allows to configure the OSGI service ranking for
- * Tamaya based ConfigurationAdmin instance. The default ranking used is 10.</p></li>
- * <li><p><b>org.tamaya.integration.osgi.cm.override, type: boolean</b> allows to configure if Tamaya should
- * register its ConfigAdmin service. Default is true.</p></li>
- * </ul>
- */
-public class Activator implements BundleActivator {
-
- private static final String SERVICE_RANKING_PROP = "org.tamaya.integration.osgi.cm.ranking";
-
- private static final String SERVICE_OVERRIDE_PROP = "org.tamaya.integration.osgi.cm.override";
-
- private static final String SERVICE_INJECT_PROP = "org.tamaya.integration.osgi.cm.inject";
-
- private static final Integer DEFAULT_RANKING = 10;
-
- private static final Logger LOG = Logger.getLogger(Activator.class.getName());
-
- private ServiceRegistration<ConfigurationAdmin> registration;
-
- private ServiceTracker<Object, Object> injectionTracker;
-
- @Override
- public void start(BundleContext context) throws Exception {
- String val = context.getProperty(SERVICE_OVERRIDE_PROP);
- if(val == null || Boolean.parseBoolean(val)){
- Dictionary<String, Object> props = new Hashtable<>();
- String ranking = context.getProperty(SERVICE_RANKING_PROP);
- if (ranking == null) {
- props.put(Constants.SERVICE_RANKING, DEFAULT_RANKING);
- } else {
- props.put(Constants.SERVICE_RANKING, Integer.valueOf(ranking));
- }
- TamayaConfigAdminImpl cm = new TamayaConfigAdminImpl(context);
- registration = context.registerService(ConfigurationAdmin.class, cm, props);
- }
-
- // register injection mechanisms, if not configured otherwise
- val = context.getProperty(SERVICE_INJECT_PROP);
- if(val == null || Boolean.parseBoolean(val)){
- injectionTracker = new ServiceTracker<Object, Object>(context, Object.class, null) {
- @Override
- public Object addingService(ServiceReference<Object> reference) {
- Object service = context.getService(reference);
- Object pidObj = reference.getProperty(Constants.SERVICE_PID);
- if (pidObj instanceof String) {
- String pid = (String) pidObj;
- ConfigurationAdmin configAdmin = null;
- ServiceReference<ConfigurationAdmin> adminRef =
- context.getServiceReference(ConfigurationAdmin.class);
- if(adminRef!=null){
- configAdmin = context.getService(adminRef);
- }
- try {
- Configuration targetConfig = null;
- if(configAdmin != null){
- org.osgi.service.cm.Configuration osgiConfig = configAdmin.getConfiguration(pid);
- if(osgiConfig!=null){
- targetConfig = new OSGIEnhancedConfiguration(osgiConfig);
- }
- }
- if(targetConfig==null){
- targetConfig = ConfigurationProvider.getConfiguration();
- }
- ConfigurationInjection.getConfigurationInjector().configure(service, targetConfig);
- } catch (Exception e) {
- LOG.log(Level.WARNING, "Error configuring Service: " + service, e);
- }
- } else {
- LOG.log(Level.SEVERE, "Unsupported pid: " + pidObj);
- }
- return service;
- }
-
- @Override
- public void removedService(ServiceReference<Object> reference, Object service) {
- context.ungetService(reference);
- }
- };
- injectionTracker.open();
- }
- }
-
- @Override
- public void stop(BundleContext context) throws Exception {
- if (registration != null) {
- registration.unregister();
- }
- if(injectionTracker!=null){
- injectionTracker.close();
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/359d3e4a/modules/integration/osgi/src/main/java/org/apache/tamaya/integration/osgi/OSGIConfigRootMapper.java
----------------------------------------------------------------------
diff --git a/modules/integration/osgi/src/main/java/org/apache/tamaya/integration/osgi/OSGIConfigRootMapper.java b/modules/integration/osgi/src/main/java/org/apache/tamaya/integration/osgi/OSGIConfigRootMapper.java
deleted file mode 100644
index 836df8b..0000000
--- a/modules/integration/osgi/src/main/java/org/apache/tamaya/integration/osgi/OSGIConfigRootMapper.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.integration.osgi;
-
-/**
- * Mapping function for mapping Tamaya configuration sections to OSGI pids.
- */
-public interface OSGIConfigRootMapper {
-
- /**
- * Map the given OSGI pid to a corresponding configuration section in Tamaya. Es an example (and this is also the
- * default implemented) a configuration mapping for {@code pid/factoryPid==myBundle} could be {@code [bundle:myBundle]}.
- * This mapping is used as a prefix when collecting the corresponding entries for the OSGI configuration.
- * @param pid the OSGI pid, or null
- * @param factoryPid the OSGI factoryPid, or null
- * @return return the corresponding config root section. For ommitting any root section simply return an empty
- * String.
- */
- String getTamayaConfigRoot(String pid, String factoryPid);
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/359d3e4a/modules/integration/osgi/src/main/java/org/apache/tamaya/integration/osgi/OSGIEnhancedConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/integration/osgi/src/main/java/org/apache/tamaya/integration/osgi/OSGIEnhancedConfiguration.java b/modules/integration/osgi/src/main/java/org/apache/tamaya/integration/osgi/OSGIEnhancedConfiguration.java
deleted file mode 100644
index 5e813af..0000000
--- a/modules/integration/osgi/src/main/java/org/apache/tamaya/integration/osgi/OSGIEnhancedConfiguration.java
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.integration.osgi;
-
-import org.apache.tamaya.spi.PropertySource;
-import org.apache.tamaya.spisupport.BasePropertySource;
-import org.apache.tamaya.spisupport.DefaultConfiguration;
-import org.apache.tamaya.spisupport.DefaultConfigurationContext;
-
-import java.util.Dictionary;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-
-/**
- * Configuration object that also reflects the values provided by the OSGI ConfigAdmin Configuration.
- * Similar to other tamaya areas adding a tamaya.ordinal into the corresponding OSGI configuration for
- * a pif/factoryPid allows to control the ordinal/priority of the OSGI configuration related to other
- * configured Tamaya Property Sources. Overall the configuration evaluation for Tamaya follows the
- * same rules, with the difference that each bunldle owns its own ConfigAdmin based part. From
- * Tamaya, the granularity depends on the implementation of the ConfigurationProviderSpi. By default
- * Tamaya configuration is managed as a global resource/config tree, wheres bundle specific sections are
- * selected only.
- */
-public class OSGIEnhancedConfiguration extends DefaultConfiguration{
- /** The default ordinal used for the OSGI config, */
- private static final int OSGI_DEFAULT_ORDINAL = 0;
-
- /**
- * Constructor.
- *
- * @param osgiConfiguration The OSGI configuration found.
- */
- public OSGIEnhancedConfiguration(org.osgi.service.cm.Configuration osgiConfiguration) {
- super(new OSGIConfigurationContext(osgiConfiguration));
- }
-
- /**
- * Class that models a Tamaya ConfigurationContext, which implicitly contains the bundle specific
- * Configuration wrapped into a Tamaya PropertySource.
- */
- private static final class OSGIConfigurationContext extends DefaultConfigurationContext{
- private OSGIPropertySource osgiPropertySource;
-
- public OSGIConfigurationContext(org.osgi.service.cm.Configuration osgiConfiguration){
- if(osgiConfiguration!=null) {
- this.osgiPropertySource = new OSGIPropertySource(osgiConfiguration);
- }
- }
-
- @Override
- public List<PropertySource> getPropertySources() {
- List<PropertySource> sources = super.getPropertySources();
- if(osgiPropertySource!=null){
- sources.add(osgiPropertySource);
- }
- return sources;
- }
- }
-
- /**
- * Tamaya PropertySource providing the values from an OSGI Configuration.
- */
- private static final class OSGIPropertySource extends BasePropertySource{
-
- private final org.osgi.service.cm.Configuration osgiConfiguration;
-
- public OSGIPropertySource(org.osgi.service.cm.Configuration osgiConfiguration){
- this.osgiConfiguration = Objects.requireNonNull(osgiConfiguration);
- }
-
- @Override
- public int getDefaultOrdinal() {
- String val = System.getProperty("osgi.defaultOrdinal");
- if(val!=null){
- return Integer.parseInt(val.trim());
- }
- return OSGI_DEFAULT_ORDINAL;
- }
-
- @Override
- public String getName() {
- return "OSGIConfig:pid="+
- (osgiConfiguration.getPid()!=null?osgiConfiguration.getPid():osgiConfiguration.getFactoryPid());
- }
-
- @Override
- public Map<String, String> getProperties() {
- Map<String, String> map = new HashMap<>();
- Dictionary<String,Object> dict = osgiConfiguration.getProperties();
- Enumeration<String> keys = dict.keys();
- while(keys.hasMoreElements()){
- String key = keys.nextElement();
- map.put(key,String.valueOf(dict.get(key)));
- }
- return map;
- }
- }
-}
|