You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tamaya.apache.org by an...@apache.org on 2018/11/18 21:20:46 UTC
[13/16] incubator-tamaya-sandbox git commit: Moved collections, consul,
etcd and hazelcast modules into extensions. Updated docs to match
code.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/e0d15cb2/collections/src/test/java/org/apache/tamaya/collections/CollectionsTypedTests.java
----------------------------------------------------------------------
diff --git a/collections/src/test/java/org/apache/tamaya/collections/CollectionsTypedTests.java b/collections/src/test/java/org/apache/tamaya/collections/CollectionsTypedTests.java
deleted file mode 100644
index 92c592e..0000000
--- a/collections/src/test/java/org/apache/tamaya/collections/CollectionsTypedTests.java
+++ /dev/null
@@ -1,207 +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.collections;
-
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.TypeLiteral;
-import org.junit.Test;
-
-import java.util.*;
-
-import static junit.framework.TestCase.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-/**
- * Basic tests for Tamaya collection support. Relevant configs for this tests:
- * <pre>base.items=1,2,3,4,5,6,7,8,9,0
- * base.map=1::a, 2::b, 3::c, [4:: ]
- * </pre>
- */
-public class CollectionsTypedTests {
-
- @Test
- public void testArrayListList_String(){
- Configuration config = Configuration.current();
- List<String> items = config.get("typed2.arraylist", new TypeLiteral<List<String>>(){});
- assertNotNull(items);
- assertFalse(items.isEmpty());
- assertEquals(10, items.size());
- assertTrue(items instanceof ArrayList);
- items = (List<String>) config.get("typed2.arraylist", List.class);
- assertNotNull(items);
- assertFalse(items.isEmpty());
- assertEquals(10, items.size());
- assertTrue(items instanceof ArrayList);
- }
-
- @Test
- public void testLinkedListList_String(){
- Configuration config = Configuration.current();
- List<String> items = config.get("typed2.linkedlist", new TypeLiteral<List<String>>(){});
- assertNotNull(items);
- assertFalse(items.isEmpty());
- assertEquals(10, items.size());
- assertTrue(items instanceof LinkedList);
- items = (List<String>) config.get("typed2.linkedlist", List.class);
- assertNotNull(items);
- assertFalse(items.isEmpty());
- assertEquals(10, items.size());
- assertTrue(items instanceof LinkedList);
- }
-
-
- @Test
- public void testHashSet_String(){
- Configuration config = Configuration.current();
- Set<String> items = config.get("typed2.hashset", new TypeLiteral<Set<String>>(){});
- assertNotNull(items);
- assertFalse(items.isEmpty());
- assertEquals(10, items.size());
- assertTrue(items instanceof HashSet);
- items = (Set<String>) config.get("typed2.hashset", Set.class);
- assertNotNull(items);
- assertFalse(items.isEmpty());
- assertEquals(10, items.size());
- assertTrue(items instanceof HashSet);
- }
-
- @Test
- public void testTreeSet_String(){
- Configuration config = Configuration.current();
- Set<String> items = config.get("typed2.treeset", new TypeLiteral<Set<String>>(){});
- assertNotNull(items);
- assertFalse(items.isEmpty());
- assertEquals(10, items.size());
- assertTrue(items instanceof TreeSet);
- items = (Set<String>) config.get("typed2.treeset", Set.class);
- assertNotNull(items);
- assertFalse(items.isEmpty());
- assertEquals(10, items.size());
- assertTrue(items instanceof TreeSet);
- }
-
- @Test
- public void testHashMap_String(){
- Configuration config = Configuration.current();
- Map<String,String> items = config.get("typed2.hashmap", new TypeLiteral<Map<String,String>>(){});
- assertNotNull(items);
- assertFalse(items.isEmpty());
- assertEquals(4, items.size());
- assertEquals("a", items.get("1"));
- assertEquals("b", items.get("2"));
- assertEquals("c", items.get("3"));
- assertEquals(" ", items.get("4"));
- assertTrue(items instanceof HashMap);
- items = (Map<String,String>) config.get("typed2.hashmap", Map.class);
- assertNotNull(items);
- assertFalse(items.isEmpty());
- assertEquals(4, items.size());
- assertEquals("a", items.get("1"));
- assertEquals("b", items.get("2"));
- assertEquals("c", items.get("3"));
- assertEquals(" ", items.get("4"));
- assertTrue(items instanceof HashMap);
- }
-
- @Test
- public void testTreeMap_String(){
- Configuration config = Configuration.current();
- Map<String,String> items = config.get("typed2.treemap", new TypeLiteral<Map<String,String>>(){});
- assertNotNull(items);
- assertFalse(items.isEmpty());
- assertEquals(4, items.size());
- assertEquals("a", items.get("1"));
- assertEquals("b", items.get("2"));
- assertEquals("c", items.get("3"));
- assertEquals(" ", items.get("4"));
- assertTrue(items instanceof TreeMap);
- items = (Map<String,String>) config.get("typed2.treemap", Map.class);
- assertNotNull(items);
- assertFalse(items.isEmpty());
- assertEquals(4, items.size());
- assertEquals("a", items.get("1"));
- assertEquals("b", items.get("2"));
- assertEquals("c", items.get("3"));
- assertEquals(" ", items.get("4"));
- assertTrue(items instanceof TreeMap);
- }
-
- @Test
- public void testCollection_HashSet(){
- Configuration config = Configuration.current();
- Collection<String> items = config.get("typed2.hashset", new TypeLiteral<Collection<String>>(){});
- assertNotNull(items);
- assertFalse(items.isEmpty());
- assertEquals(10, items.size());
- assertTrue(items instanceof HashSet);
- items = (Collection<String>) config.get("typed2.hashset", Collection.class);
- assertNotNull(items);
- assertFalse(items.isEmpty());
- assertEquals(10, items.size());
- assertTrue(items instanceof HashSet);
- }
-
- @Test
- public void testCollection_TreeSet(){
- Configuration config = Configuration.current();
- Collection<String> items = config.get("typed2.treeset", new TypeLiteral<Collection<String>>(){});
- assertNotNull(items);
- assertFalse(items.isEmpty());
- assertEquals(10, items.size());
- assertTrue(items instanceof TreeSet);
- items = (Collection<String>) config.get("typed2.treeset", Collection.class);
- assertNotNull(items);
- assertFalse(items.isEmpty());
- assertEquals(10, items.size());
- assertTrue(items instanceof TreeSet);
- }
-
- @Test
- public void testCollection_ArrayList(){
- Configuration config = Configuration.current();
- Collection<String> items = config.get("typed2.arraylist", new TypeLiteral<Collection<String>>(){});
- assertNotNull(items);
- assertFalse(items.isEmpty());
- assertEquals(10, items.size());
- assertTrue(items instanceof ArrayList);
- items = (Collection<String>) config.get("typed2.arraylist", Collection.class);
- assertNotNull(items);
- assertFalse(items.isEmpty());
- assertEquals(10, items.size());
- assertTrue(items instanceof ArrayList);
- }
-
- @Test
- public void testCollection_LinkedList(){
- Configuration config = Configuration.current();
- Collection<String> items = config.get("typed2.linkedlist", new TypeLiteral<Collection<String>>(){});
- assertNotNull(items);
- assertFalse(items.isEmpty());
- assertEquals(10, items.size());
- assertTrue(items instanceof LinkedList);
- items = (Collection<String>) config.get("typed2.linkedlist", Collection.class);
- assertNotNull(items);
- assertFalse(items.isEmpty());
- assertEquals(10, items.size());
- assertTrue(items instanceof LinkedList);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/e0d15cb2/collections/src/test/java/org/apache/tamaya/collections/MyUpperCaseConverter.java
----------------------------------------------------------------------
diff --git a/collections/src/test/java/org/apache/tamaya/collections/MyUpperCaseConverter.java b/collections/src/test/java/org/apache/tamaya/collections/MyUpperCaseConverter.java
deleted file mode 100644
index 1c95261..0000000
--- a/collections/src/test/java/org/apache/tamaya/collections/MyUpperCaseConverter.java
+++ /dev/null
@@ -1,33 +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.collections;
-
-import org.apache.tamaya.spi.ConversionContext;
-import org.apache.tamaya.spi.PropertyConverter;
-
-/**
- * Example converter that is used for testing the custom parsing functionality. It sorrounds values with () and
- * converts them to uppercase.
- */
-public class MyUpperCaseConverter implements PropertyConverter<String>{
- @Override
- public String convert(String value, ConversionContext context) {
- return "("+value.toUpperCase()+")";
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/e0d15cb2/collections/src/test/resources/META-INF/javaconfiguration.properties
----------------------------------------------------------------------
diff --git a/collections/src/test/resources/META-INF/javaconfiguration.properties b/collections/src/test/resources/META-INF/javaconfiguration.properties
deleted file mode 100644
index 3764840..0000000
--- a/collections/src/test/resources/META-INF/javaconfiguration.properties
+++ /dev/null
@@ -1,69 +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.
-#
-# Similar to etcd all keys starting with a _ are hidden by default (only directly accessible).
-
-# Config for base tests (no combination policy)
-base.items=1,2,3,4,5,6,7,8,9,0
-base.map=1=a, 2=b, 3=c, [4= ]
-
-# Config for tests with explcit implementation types
-typed2.arraylist=1,2,3,4,5,6,7,8,9,0
-[META]typed2.arraylist.collection-type=ArrayList
-typed2.linkedlist=1,2,3,4,5,6,7,8,9,0
-[META]typed2.linkedlist.collection-type=java.util.LinkedList
-typed2.hashset=1,2,3,4,5,6,7,8,9,0
-[META]typed2.hashset.collection-type=HashSet
-typed2.treeset=1,2,3,4,5,6,7,8,9,0
-[META]typed2.treeset.collection-type=TreeSet
-typed2.hashmap=1=a, 2=b, 3=c, [4= ]
-[META]typed2.hashmap.collection-type=java.util.HashMap
-typed2.treemap=1=a, 2=b, 3=c, [4= ]
-[META]typed2.treemap.collection-type=TreeMap
-
-# Config for tests with combination policy, writable
-typed.arraylist=1,2,3,4,5,6,7,8,9,0
-[META]typed.arraylist.collection-type=ArrayList
-[META]typed.arraylist.read-only=true
-typed.linkedlist=1,2,3,4,5,6,7,8,9,0
-[META]typed.linkedlist.collection-type=java.util.LinkedList
-typed.hashset=1,2,3,4,5,6,7,8,9,0
-[META]typed.hashset.collection-type=HashSet
-typed.treeset=1,2,3,4,5,6,7,8,9,0
-[META]typed.treeset.collection-type=TreeSet
-typed.hashmap=1=a, 2=b, 3=c, [4= ]
-[META]typed.hashmap.collection-type=java.util.HashMap
-[META]typed.hashmap.read-only=true
-typed.treemap=1=a, 2=b, 3=c, [4= ]
-[META]typed.treemap.collection-type=TreeMap
-
-# Config for advanced tests
-sep-list=a,b,c|d,e,f|g,h,i
-[META]sep-list.collection-type=List
-[META]sep-list.item-separator=|
-currency-list=CHF,USD,USS
-[META]currency-list.collection-type=List
-
-parser-list=a,b,c
-[META]parser-list.collection-type=List
-[META]parser-list.item-converter=org.apache.tamaya.collections.MyUpperCaseConverter
-
-redefined-map=0==none | 1==single | 2==any
-[META]redefined-map.map-entry-separator===
-[META]redefined-map.item-separator=|
-
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/e0d15cb2/consul/bnd.bnd
----------------------------------------------------------------------
diff --git a/consul/bnd.bnd b/consul/bnd.bnd
deleted file mode 100644
index 9928592..0000000
--- a/consul/bnd.bnd
+++ /dev/null
@@ -1,32 +0,0 @@
--buildpath: \
- osgi.annotation; version=6.0.0,\
- osgi.core; version=6.0,\
- osgi.cmpn; version=6.0
-
--testpath: \
- ${junit}
-
-javac.source: 1.8
-javac.target: 1.8
-
-Automatic-Module-Name: org.apache.tamaya.consul
-Bundle-Version: ${version}.${tstamp}
-Bundle-Name: Apache Tamaya - Consul
-Bundle-SymbolicName: org.apache.tamaya.consul
-Bundle-Description: Apacha Tamaya Config - Consul PropertySource
-Bundle-Category: Implementation
-Bundle-Copyright: (C) Apache Foundation
-Bundle-License: Apache Licence version 2
-Bundle-Vendor: Apache Software Foundation
-Bundle-ContactAddress: dev-tamaya@incubator.apache.org
-Bundle-DocURL: http://tamaya.apache.org
-Export-Package: \
- org.apache.tamaya.consul
-Import-Package: \
- org.apache.tamaya,\
- org.apache.tamaya.spi,\
- org.apache.tamaya.mutableconfig,\
- org.apache.tamaya.mutableconfig.spi
-Export-Service: \
- org.apache.tamaya.spi.PropertySource
-
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/e0d15cb2/consul/pom.xml
----------------------------------------------------------------------
diff --git a/consul/pom.xml b/consul/pom.xml
deleted file mode 100644
index c48c7ae..0000000
--- a/consul/pom.xml
+++ /dev/null
@@ -1,83 +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-sandbox</artifactId>
- <version>0.4-incubating-SNAPSHOT</version>
- <relativePath>..</relativePath>
- </parent>
-
- <artifactId>tamaya-consul_beta</artifactId>
- <name>Apache Tamaya Modules - Consul</name>
- <packaging>jar</packaging>
-
- <dependencies>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- </dependency>
- <dependency>
- <groupId>org.hamcrest</groupId>
- <artifactId>java-hamcrest</artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.apache.tamaya</groupId>
- <artifactId>tamaya-core</artifactId>
- <version>${project.parent.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.tamaya</groupId>
- <artifactId>tamaya-api</artifactId>
- <version>${project.parent.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.tamaya.ext</groupId>
- <artifactId>tamaya-functions</artifactId>
- <version>${project.parent.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.tamaya.ext</groupId>
- <artifactId>tamaya-mutable-config</artifactId>
- <version>${project.parent.version}</version>
- <scope>provided</scope>
- <optional>true</optional>
- </dependency>
- <dependency>
- <groupId>com.orbitz.consul</groupId>
- <artifactId>consul-client</artifactId>
- <version>0.17.0</version>
- </dependency>
- <dependency>
- <groupId>org.apache.cxf</groupId>
- <artifactId>cxf-rt-rs-client</artifactId>
- <version>3.2.1</version>
- </dependency>
- <dependency>
- <groupId>org.apache.cxf</groupId>
- <artifactId>cxf-rt-transports-http-hc</artifactId>
- <version>3.2.1</version>
- </dependency>
- </dependencies>
-
-</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/e0d15cb2/consul/src/main/java/org/apache/tamaya/consul/ConsulBackendConfig.java
----------------------------------------------------------------------
diff --git a/consul/src/main/java/org/apache/tamaya/consul/ConsulBackendConfig.java b/consul/src/main/java/org/apache/tamaya/consul/ConsulBackendConfig.java
deleted file mode 100644
index 61be0ba..0000000
--- a/consul/src/main/java/org/apache/tamaya/consul/ConsulBackendConfig.java
+++ /dev/null
@@ -1,76 +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.google.common.net.HostAndPort;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * Singleton that reads and stores the current consul setup, especially the possible host:ports to be used.
- */
-public final class ConsulBackendConfig {
-
- private static final String TAMAYA_CONSUL_DISABLE = "tamaya.consul.disable";
- private static final String TAMAYA_CONSUL_URLS = "tamaya.consul.urls";
- private static final Logger LOG = Logger.getLogger(ConsulBackendConfig.class.getName());
- private static List<HostAndPort> consulBackends = new ArrayList<>();
-
- static{
- String serverURLs = System.getProperty(TAMAYA_CONSUL_URLS);
- if(serverURLs==null){
- serverURLs = System.getenv(TAMAYA_CONSUL_URLS);
- }
- if(serverURLs==null){
- serverURLs = "127.0.0.1:8300";
- }
- for(String url:serverURLs.split("\\,")) {
- try{
- consulBackends.add(HostAndPort.fromString(url.trim()));
- LOG.info("Using consul endoint: " + url);
- } catch(Exception e){
- LOG.log(Level.SEVERE, "Error initializing consul accessor for URL: " + url, e);
- }
- }
- }
-
- private ConsulBackendConfig(){}
-
- private static boolean isConsulDisabled() {
- String value = System.getProperty(TAMAYA_CONSUL_DISABLE);
- if(value==null){
- value = System.getenv(TAMAYA_CONSUL_DISABLE);
- }
- if(value==null){
- return false;
- }
- return value.isEmpty() || Boolean.parseBoolean(value);
- }
-
- public static List<HostAndPort> getConsulBackends(){
- if(isConsulDisabled()){
- return Collections.emptyList();
- }
- return consulBackends;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/e0d15cb2/consul/src/main/java/org/apache/tamaya/consul/ConsulPropertySource.java
----------------------------------------------------------------------
diff --git a/consul/src/main/java/org/apache/tamaya/consul/ConsulPropertySource.java b/consul/src/main/java/org/apache/tamaya/consul/ConsulPropertySource.java
deleted file mode 100644
index a456708..0000000
--- a/consul/src/main/java/org/apache/tamaya/consul/ConsulPropertySource.java
+++ /dev/null
@@ -1,247 +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.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.ConfigChangeRequest;
-import org.apache.tamaya.mutableconfig.spi.MutablePropertySource;
-import org.apache.tamaya.spi.PropertyValue;
-import org.apache.tamaya.spisupport.propertysource.BasePropertySource;
-
-import java.util.*;
-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 configuration
- * to this prefix namespace. Consul servers are configured as {@code consul.urls} system or environment property.
- */
-public class ConsulPropertySource extends BasePropertySource
-implements MutablePropertySource{
- private static final Logger LOG = Logger.getLogger(ConsulPropertySource.class.getName());
-
- private String prefix = "";
-
- private List<HostAndPort> consulBackends;
-
-
- public ConsulPropertySource(String prefix, Collection<String> backends){
- this.prefix = prefix==null?"":prefix;
- consulBackends = new ArrayList<>();
- for(String s:backends){
- consulBackends.add(HostAndPort.fromString(s));
- }
- }
-
- public ConsulPropertySource(Collection<String> backends){
- consulBackends = new ArrayList<>();
- for(String s:backends){
- consulBackends.add(HostAndPort.fromString(s));
- }
- }
-
- public ConsulPropertySource(){
- prefix = System.getProperty("tamaya.consul.prefix", "");
- }
-
- public ConsulPropertySource(String... backends){
- consulBackends = new ArrayList<>();
- for (String s : backends) {
- consulBackends.add(HostAndPort.fromString(s));
- }
- }
-
- public String getPrefix() {
- return prefix;
- }
-
- public ConsulPropertySource setPrefix(String prefix) {
- this.prefix = prefix;
- return this;
- }
-
- 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 setCurrent, or the ordinal was not parseable to an int createValue.
- * @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: 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 prefix mapping necessary here, since we only access/return the createValue...
- 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 PropertyValue.of(key, value.getValue().get(), getName()).setMeta(props);
- }
- } catch(Exception e){
- LOG.log(Level.FINE, "etcd access failed on " + hostAndPort + ", trying next...", e);
- }
- }
- return null;
- }
-
- @Override
- public Map<String, PropertyValue> getProperties() {
-// for(HostAndPort hostAndPort: getConsulBackends()){
-// try{
-// Consul consul = Consul.builder().withHostAndPort(hostAndPort).build();
-// KeyValueClient kvClient = consul.keyValueClient();
-// Optional<Value> valueOpt = kvClient.getProperty(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.current("_ERROR"));
-// }
-// } catch(Exception e){
-// LOG.log(Level.FINE, "consul access failed on " + hostAndPort + ", trying next...", e);
-// }
-// } catch(Exception e){
-// LOG.log(Level.FINE, "consul 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: ConsulBackendConfig.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);
- }
- }
- }
-
- private List<HostAndPort> getConsulBackends(){
- if(consulBackends==null){
- consulBackends = ConsulBackendConfig.getConsulBackends();
- LOG.info("Using consul backends: " + consulBackends);
- }
- return consulBackends;
- }
-
- @Override
- protected String toStringValues() {
- return super.toStringValues() +
- " prefix=" + prefix + '\n' +
- " backends=" + this.consulBackends + '\n';
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/e0d15cb2/consul/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySource
----------------------------------------------------------------------
diff --git a/consul/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySource b/consul/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySource
deleted file mode 100644
index 4996059..0000000
--- a/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-sandbox/blob/e0d15cb2/consul/src/test/java/org/apache/tamaya/consul/ConsulPropertySourceTest.java
----------------------------------------------------------------------
diff --git a/consul/src/test/java/org/apache/tamaya/consul/ConsulPropertySourceTest.java b/consul/src/test/java/org/apache/tamaya/consul/ConsulPropertySourceTest.java
deleted file mode 100644
index 0366b2b..0000000
--- a/consul/src/test/java/org/apache/tamaya/consul/ConsulPropertySourceTest.java
+++ /dev/null
@@ -1,76 +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 org.apache.tamaya.consul.ConsulPropertySource;
-import org.apache.tamaya.spi.PropertyValue;
-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(1000, propertySource.getOrdinal());
- }
-
- @Test
- public void testGetDefaultOrdinal() throws Exception {
- assertEquals(1000, propertySource.getDefaultOrdinal());
- }
-
- @Test
- public void testGetName() throws Exception {
- assertEquals("consul", propertySource.getName());
- }
-
- @Test
- public void testGet() throws Exception {
- Map<String,PropertyValue> props = propertySource.getProperties();
- for(Map.Entry<String,PropertyValue> en:props.entrySet()){
- assertNotNull("Key not found: " + en.getKey(), propertySource.get(en.getKey()));
- }
- }
-
- @Test
- public void testGetProperties() throws Exception {
- Map<String,PropertyValue> 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-sandbox/blob/e0d15cb2/consul/src/test/java/org/apache/tamaya/consul/ConsulWriteTest.java
----------------------------------------------------------------------
diff --git a/consul/src/test/java/org/apache/tamaya/consul/ConsulWriteTest.java b/consul/src/test/java/org/apache/tamaya/consul/ConsulWriteTest.java
deleted file mode 100644
index 1746030..0000000
--- a/consul/src/test/java/org/apache/tamaya/consul/ConsulWriteTest.java
+++ /dev/null
@@ -1,86 +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 static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
-import java.net.MalformedURLException;
-import java.net.URISyntaxException;
-import java.util.Map;
-import java.util.UUID;
-
-import org.apache.tamaya.mutableconfig.ConfigChangeRequest;
-import org.apache.tamaya.spi.PropertyValue;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-/**
- * Tests for the consul backend integration for writing to the consul backend.
- */
-public class ConsulWriteTest {
-
- /**
- * Needs to be enabled manually in case you want to do integration tests.
- */
- 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");
- propertySource = new ConsulPropertySource();
-
- System.out.println("At the moment no write-tests can be executed to verify the Consul integration. You can manually edit this test class.");
- }
-
- @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);
- }
-
-
- @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(taID.toString(), propertySource.get("testDelete").getValue());
- assertNotNull(propertySource.get("_testDelete.createdIndex"));
- request = new ConfigChangeRequest("testDelete2");
- request.remove("testDelete");
- propertySource.applyChange(request);
- assertNull(propertySource.get("testDelete"));
- }
-
- @Test
- public void testGetProperties() throws Exception {
- if(!execute)return;
- Map<String,PropertyValue> result = propertySource.getProperties();
- assertTrue(result.isEmpty());
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/e0d15cb2/etcd/bnd.bnd
----------------------------------------------------------------------
diff --git a/etcd/bnd.bnd b/etcd/bnd.bnd
deleted file mode 100644
index 129f3ec..0000000
--- a/etcd/bnd.bnd
+++ /dev/null
@@ -1,32 +0,0 @@
--buildpath: \
- osgi.annotation; version=6.0.0,\
- osgi.core; version=6.0,\
- osgi.cmpn; version=6.0
-
--testpath: \
- ${junit}
-
-javac.source: 1.8
-javac.target: 1.8
-
-Automatic-Module-Name: org.apache.tamaya.etcd
-Bundle-Version: ${version}.${tstamp}
-Bundle-Name: Apache Tamaya - Etcd Config
-Bundle-SymbolicName: org.apache.tamaya.etcd
-Bundle-Description: Apacha Tamaya Config - Etcd PropertySource
-Bundle-Category: Implementation
-Bundle-Copyright: (C) Apache Foundation
-Bundle-License: Apache Licence version 2
-Bundle-Vendor: Apache Software Foundation
-Bundle-ContactAddress: dev-tamaya@incubator.apache.org
-Bundle-DocURL: http://tamaya.apache.org
-Export-Package: \
- org.apache.tamaya.etcd
-Import-Package: \
- org.apache.tamaya,\
- org.apache.tamaya.spi,\
- org.apache.tamaya.mutableconfig\
- org.apache.tamaya.mutableconfig.spi
-Export-Service: \
- org.apache.tamaya.spi.PropertySource
-
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/e0d15cb2/etcd/pom.xml
----------------------------------------------------------------------
diff --git a/etcd/pom.xml b/etcd/pom.xml
deleted file mode 100644
index ef818a1..0000000
--- a/etcd/pom.xml
+++ /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 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-sandbox</artifactId>
- <version>0.4-incubating-SNAPSHOT</version>
- <relativePath>..</relativePath>
- </parent>
-
- <artifactId>tamaya-etcd_beta</artifactId>
- <name>Apache Tamaya Modules - etcd PropertySource</name>
- <packaging>jar</packaging>
-
- <dependencies>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- </dependency>
- <dependency>
- <groupId>org.hamcrest</groupId>
- <artifactId>java-hamcrest</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.tamaya</groupId>
- <artifactId>tamaya-core</artifactId>
- <version>${project.parent.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.tamaya</groupId>
- <artifactId>tamaya-api</artifactId>
- <version>${project.parent.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.tamaya.ext</groupId>
- <artifactId>tamaya-functions</artifactId>
- <version>${project.parent.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.httpcomponents</groupId>
- <artifactId>httpclient-osgi</artifactId>
- <version>4.5.3</version>
- </dependency>
- <dependency>
- <groupId>org.apache.geronimo.specs</groupId>
- <artifactId>geronimo-json_1.1_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.parent.version}</version>
- <scope>provided</scope>
- <optional>true</optional>
- </dependency>
- </dependencies>
-
-</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/e0d15cb2/etcd/src/main/java/org/apache/tamaya/etcd/EtcdAccessor.java
----------------------------------------------------------------------
diff --git a/etcd/src/main/java/org/apache/tamaya/etcd/EtcdAccessor.java b/etcd/src/main/java/org/apache/tamaya/etcd/EtcdAccessor.java
deleted file mode 100644
index 4ceb7b2..0000000
--- a/etcd/src/main/java/org/apache/tamaya/etcd/EtcdAccessor.java
+++ /dev/null
@@ -1,519 +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 makes Johnzon accept comments.
- */
- 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, createValue pair. Hereby the response returned from
- * etcd:
- *
- * <pre>
- * {
- * "action": "current",
- * "getField": {
- * "createdIndex": 2,
- * "key": "/message",
- * "modifiedIndex": 2,
- * "createValue": "Hello world"
- * }
- * }
- * </pre>
- *
- * is mapped to:
- *
- * <pre>
- * key=createValue
- * _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 getMeta-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("getField");
- if (node.containsKey("createValue")) {
- result.put(key, node.getString("createValue"));
- 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 setCurrent.
- *
- * @param key the property key, not null
- * @param value the createValue to be setCurrent
- * @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": "setCurrent",
- * "getField": {
- * "createdIndex": 3,
- * "key": "/message",
- * "modifiedIndex": 3,
- * "createValue": "Hello etcd"
- * },
- * "prevNode": {
- * "createdIndex": 2,
- * "key": "/message",
- * "createValue": "Hello world",
- * "modifiedIndex": 2
- * }
- * }
- * </pre>
- *
- * is mapped to:
- *
- * <pre>
- * key=createValue
- * _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 createValue to be setCurrent
- * @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("createValue", 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("getField");
- 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("createValue"));
- 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.createValue=...
- * </pre>
- *
- * @param key the key to be deleted.
- * @return the response maps 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("getField");
- 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.createValue", prevNode.getString("createValue"));
- }
- }
-
- /**
- * 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": "current",
- * "getField": {
- * "key": "/",
- * "dir": true,
- * "getList": [
- * {
- * "key": "/foo_dir",
- * "dir": true,
- * "modifiedIndex": 2,
- * "createdIndex": 2
- * },
- * {
- * "key": "/foo",
- * "createValue": "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 setCurrent 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("getField");
- 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 getField 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("createValue"));
- 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("getList");
- 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-sandbox/blob/e0d15cb2/etcd/src/main/java/org/apache/tamaya/etcd/EtcdBackendConfig.java
----------------------------------------------------------------------
diff --git a/etcd/src/main/java/org/apache/tamaya/etcd/EtcdBackendConfig.java b/etcd/src/main/java/org/apache/tamaya/etcd/EtcdBackendConfig.java
deleted file mode 100644
index 123313a..0000000
--- a/etcd/src/main/java/org/apache/tamaya/etcd/EtcdBackendConfig.java
+++ /dev/null
@@ -1,83 +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.Collections;
-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 EtcdBackendConfig {
-
- private static final Logger LOG = Logger.getLogger(EtcdBackendConfig.class.getName());
- private static final String TAMAYA_ETCD_SERVER_URLS = "tamaya.etcd.server.urls";
- private static final String TAMAYA_ETCD_TIMEOUT = "tamaya.etcd.timeout";
- private static final String TAMAYA_ETCD_DISABLE = "tamaya.etcd.disable";
- 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 EtcdBackendConfig(){}
-
- private static boolean isEtcdDisabled() {
- String value = System.getProperty(TAMAYA_ETCD_DISABLE);
- if(value==null){
- value = System.getenv(TAMAYA_ETCD_DISABLE);
- }
- if(value==null){
- return false;
- }
- return value.isEmpty() || Boolean.parseBoolean(value);
- }
-
- public static List<EtcdAccessor> getEtcdBackends(){
- if(isEtcdDisabled()){
- return Collections.emptyList();
- }
- return etcdBackends;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/e0d15cb2/etcd/src/main/java/org/apache/tamaya/etcd/EtcdPropertySource.java
----------------------------------------------------------------------
diff --git a/etcd/src/main/java/org/apache/tamaya/etcd/EtcdPropertySource.java b/etcd/src/main/java/org/apache/tamaya/etcd/EtcdPropertySource.java
deleted file mode 100644
index bae780c..0000000
--- a/etcd/src/main/java/org/apache/tamaya/etcd/EtcdPropertySource.java
+++ /dev/null
@@ -1,276 +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.ConfigChangeRequest;
-import org.apache.tamaya.mutableconfig.spi.MutablePropertySource;
-import org.apache.tamaya.spi.PropertyValue;
-import org.apache.tamaya.spisupport.propertysource.BasePropertySource;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-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 configuration
- * 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 environment 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 List<EtcdAccessor> etcdBackends;
-
- private Map<String,Object> metaData = new HashMap<>();
-
- public EtcdPropertySource(String prefix, Collection<String> backends){
- this.prefix = prefix==null?"":prefix;
- etcdBackends = new ArrayList<>();
- for(String s:backends){
- etcdBackends.add(new EtcdAccessor(s));
- }
- setDefaultOrdinal(1000);
- setName("etcd");
- if(!prefix.isEmpty()){
- metaData.put("prefix", prefix);
- }
- metaData.put("backend", "etcd");
- metaData.put("backends", backends.toString());
- }
-
- public EtcdPropertySource(Collection<String> backends){
- etcdBackends = new ArrayList<>();
- for(String s:backends){
- etcdBackends.add(new EtcdAccessor(s));
- }
- setDefaultOrdinal(1000);
- setName("etcd");
- metaData.put("backend", "etcd");
- metaData.put("backends", backends.toString());
- }
-
- public EtcdPropertySource(){
- prefix = System.getProperty("tamaya.etcd.prefix", "");
- setDefaultOrdinal(1000);
- setName("etcd");
- if(!prefix.isEmpty()){
- metaData.put("prefix", prefix);
- }
- metaData.put("backend", "etcd");
- String backendProp = "";
- for(EtcdAccessor acc:getEtcdBackends()){
- if(backendProp.isEmpty()){
- backendProp += acc.getUrl();
- }else{
- backendProp += ", " + acc.getUrl();
- }
- }
- metaData.put("backends", backendProp);
- }
-
- public EtcdPropertySource(String... backends){
- etcdBackends = new ArrayList<>();
- for (String s : backends) {
- etcdBackends.add(new EtcdAccessor(s));
- }
- setDefaultOrdinal(1000);
- setName("etcd");
- if(!prefix.isEmpty()){
- metaData.put("prefix", prefix);
- }
- metaData.put("backend", "etcd");
- metaData.put("backends", backends.toString());
- }
-
- public String getPrefix() {
- return prefix;
- }
-
- public EtcdPropertySource setPrefix(String prefix) {
- this.prefix = prefix==null?"":prefix;
- if(!prefix.isEmpty()){
- metaData.put("prefix", prefix);
- }else{
- metaData.remove("prefix");
- }
- return this;
- }
-
- @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();
- }
-
- @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());
- }
- Map<String,String> props;
- for(EtcdAccessor accessor: EtcdBackendConfig.getEtcdBackends()){
- try{
- props = accessor.get(key);
- if(!props.containsKey("_ERROR")) {
- // No prefix mapping necessary here, since we only access/return the createValue...
- metaData.putAll(props);
- metaData.remove(key);
- return PropertyValue.createValue(key, props.get(key)).setMeta("source", getName()).setMeta(metaData);
- } 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, PropertyValue> getProperties() {
- for(EtcdAccessor accessor: 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, PropertyValue> mapPrefix(Map<String, String> props) {
-
- Map<String, PropertyValue> values = new HashMap<>();
- // Evaluate keys
- for(Map.Entry<String,String> entry:props.entrySet()) {
- if (!entry.getKey().startsWith("_")) {
- PropertyValue val = values.get(entry.getKey());
- if (val == null) {
- val = PropertyValue.createValue(entry.getKey(), "").setMeta("source", getName()).setMeta(metaData);
- values.put(entry.getKey(), val);
- }
- }
- }
- // add getMeta entries
- for(Map.Entry<String,String> entry:props.entrySet()) {
- if (entry.getKey().startsWith("_")) {
- String key = entry.getKey().substring(1);
- for(String field:new String[]{".createdIndex", ".modifiedIndex", ".ttl",
- ".expiration", ".source"}) {
- if (key.endsWith(field)) {
- key = key.substring(0, key.length() - field.length());
- PropertyValue val = values.get(key);
- if (val != null) {
- val.setMeta(field, entry.getValue());
- }
- }
- }
- }
- }
- // Map to createValue map.
-// Map<String, PropertyValue> values = new HashMap<>();
- for(Map.Entry<String,PropertyValue> en:values.entrySet()) {
- if(prefix.isEmpty()){
- values.put(en.getKey(), en.getValue());
- }else{
- values.put(prefix + en.getKey(), en.getValue().mutable().setKey(prefix + en.getKey()));
- }
- }
- return values;
- }
-
- @Override
- public void applyChange(ConfigChangeRequest configChange) {
- for(EtcdAccessor accessor: EtcdBackendConfig.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);
- }
- }
- }
-
- private List<EtcdAccessor> getEtcdBackends(){
- if(etcdBackends==null){
- etcdBackends = EtcdBackendConfig.getEtcdBackends();
- LOG.info("Using etcd backends: " + etcdBackends);
- }
- return etcdBackends;
- }
-
- @Override
- protected String toStringValues() {
- return super.toStringValues() +
- " prefix=" + prefix + '\n' +
- " backends=" + this.etcdBackends + '\n';
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/e0d15cb2/etcd/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySource
----------------------------------------------------------------------
diff --git a/etcd/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySource b/etcd/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySource
deleted file mode 100644
index eb7958e..0000000
--- a/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-sandbox/blob/e0d15cb2/etcd/src/test/java/org/apache/tamaya/etcd/EtcdAccessorTest.java
----------------------------------------------------------------------
diff --git a/etcd/src/test/java/org/apache/tamaya/etcd/EtcdAccessorTest.java b/etcd/src/test/java/org/apache/tamaya/etcd/EtcdAccessorTest.java
deleted file mode 100644
index 630a028..0000000
--- a/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 org.junit.Test;
-
-import java.net.MalformedURLException;
-import java.util.Map;
-import java.util.UUID;
-
-import static org.junit.Assert.*;
-
-/**
- * Tests for the etcd backend integration. You must have setCurrent 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;
- }
- }
-
- @Test
- public void testGetVersion() throws Exception {
- if(!execute)return;
- assertEquals(accessor.getVersion(), "etcd 0.4.9");
- }
-
- @Test
- public void testGet() throws Exception {
- if(!execute)return;
- Map<String,String> result = accessor.get("test1");
- assertNotNull(result);
- }
-
- @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(value, accessor.get("testSetNormal").get("testSetNormal"));
- }
-
- @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(value, accessor.get("testSetNormal2").get("testSetNormal2"));
- }
-
- @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(value, accessor.get("testSetWithTTL").get("testSetWithTTL"));
- Thread.sleep(2000L);
- result = accessor.get("testSetWithTTL");
- assertNull(result.get("testSetWithTTL"));
- }
-
- @Test
- public void testDelete() throws Exception {
- if(!execute)return;
- String value = UUID.randomUUID().toString();
- Map<String,String> result = accessor.set("testDelete", value, null);
- assertEquals(value, accessor.get("testDelete").get("testDelete"));
- assertNotNull(result.get("_testDelete.createdIndex"));
- result = accessor.delete("testDelete");
- assertEquals(value, result.get("_testDelete.prevNode.createValue"));
- assertNull(accessor.get("testDelete").get("testDelete"));
- }
-
- @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(value, result.get("testGetProperties1"));
- assertNotNull(result.get("_testGetProperties1.createdIndex"));
- }
-}
\ No newline at end of file