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 2016/02/27 22:02:20 UTC
[01/10] incubator-tamaya git commit: TAMAYA-71: Adding yaml support
using snakeyaml. TAMAYA-143: Added support for consul in read and write mode.
Repository: incubator-tamaya
Updated Branches:
refs/heads/master 4ba269045 -> 63d222140
TAMAYA-71: Adding yaml support using snakeyaml.
TAMAYA-143: Added support for consul in read and write mode.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/bb1e1e9d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/bb1e1e9d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/bb1e1e9d
Branch: refs/heads/master
Commit: bb1e1e9d11d6e36bdebb7f508513492dfd9ee0c4
Parents: 4ba2690
Author: anatole <an...@apache.org>
Authored: Sat Feb 27 21:46:23 2016 +0100
Committer: anatole <an...@apache.org>
Committed: Sat Feb 27 21:46:23 2016 +0100
----------------------------------------------------------------------
modules/integration/consul/pom.xml | 113 ++++++++++
.../apache/tamaya/consul/ConsulBackends.java | 65 ++++++
.../tamaya/consul/ConsulPropertySource.java | 148 ++++++++++++
.../ConsulMutableConfigurationBackend.java | 96 ++++++++
.../consul/internal/MutableConfigSupport.java | 44 ++++
...g.spi.MutableConfigurationBackendProviderSpi | 19 ++
.../org.apache.tamaya.spi.PropertySource | 19 ++
.../tamaya/etcd/ConsulPropertySourceTest.java | 75 +++++++
.../org/apache/tamaya/etcd/ConsulWriteTest.java | 117 ++++++++++
.../etcd/internal/EtcdConfigChangeRequest.java | 97 --------
.../EtcdMutableConfigurationBackend.java | 97 ++++++++
modules/yaml/pom.xml | 147 ++++++++++++
.../java/org/apache/tamaya/json/YAMLFormat.java | 85 +++++++
.../apache/tamaya/json/YAMLPropertySource.java | 149 +++++++++++++
.../org/apache/tamaya/json/YAMLFormatTest.java | 75 +++++++
.../tamaya/json/YAMLPropertySourceTest.java | 56 +++++
.../test/resources/configs/valid/contact.yaml | 29 +++
.../resources/configs/valid/test-with-prio.yaml | 35 +++
.../src/test/resources/configs/valid/test.yaml | 35 +++
src/site/asciidoc/extensions/mod_consul.adoc | 223 +++++++++++++++++++
src/site/asciidoc/extensions/mod_yaml.adoc | 115 ++++++++++
21 files changed, 1742 insertions(+), 97 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bb1e1e9d/modules/integration/consul/pom.xml
----------------------------------------------------------------------
diff --git a/modules/integration/consul/pom.xml b/modules/integration/consul/pom.xml
new file mode 100644
index 0000000..2795597
--- /dev/null
+++ b/modules/integration/consul/pom.xml
@@ -0,0 +1,113 @@
+<!--
+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.2-incubating-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>tamaya-etcd</artifactId>
+ <name>Apache Tamaya Integration - consul</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.consul
+ </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.tamaya.ext</groupId>
+ <artifactId>tamaya-mutable-config</artifactId>
+ <version>${project.version}</version>
+ <scope>provided</scope>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>com.orbitz.consul</groupId>
+ <artifactId>consul-client</artifactId>
+ <version>0.9.16</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-rs-client</artifactId>
+ <version>3.0.3</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-transports-http-hc</artifactId>
+ <version>3.0.3</version>
+ </dependency>
+ </dependencies>
+
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bb1e1e9d/modules/integration/consul/src/main/java/org/apache/tamaya/consul/ConsulBackends.java
----------------------------------------------------------------------
diff --git a/modules/integration/consul/src/main/java/org/apache/tamaya/consul/ConsulBackends.java b/modules/integration/consul/src/main/java/org/apache/tamaya/consul/ConsulBackends.java
new file mode 100644
index 0000000..cab9656
--- /dev/null
+++ b/modules/integration/consul/src/main/java/org/apache/tamaya/consul/ConsulBackends.java
@@ -0,0 +1,65 @@
+/*
+ * 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 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 ConsulBackends {
+
+ private static final Logger LOG = Logger.getLogger(ConsulBackends.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 ConsulBackends(){}
+
+ public static List<EtcdAccessor> getEtcdBackends(){
+ return etcdBackends;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bb1e1e9d/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
new file mode 100644
index 0000000..03db401
--- /dev/null
+++ b/modules/integration/consul/src/main/java/org/apache/tamaya/consul/ConsulPropertySource.java
@@ -0,0 +1,148 @@
+/*
+ * 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.spi.PropertySource;
+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 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.
+ */
+public class ConsulPropertySource implements PropertySource{
+ private static final Logger LOG = Logger.getLogger(ConsulPropertySource.class.getName());
+
+ private String prefix = System.getProperty("tamaya.etcd.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 0.
+ */
+ public int getDefaultOrdinal(){
+ return 100;
+ }
+
+ @Override
+ public String getName() {
+ return "etcd";
+ }
+
+ @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;
+ 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(!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;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bb1e1e9d/modules/integration/consul/src/main/java/org/apache/tamaya/consul/internal/ConsulMutableConfigurationBackend.java
----------------------------------------------------------------------
diff --git a/modules/integration/consul/src/main/java/org/apache/tamaya/consul/internal/ConsulMutableConfigurationBackend.java b/modules/integration/consul/src/main/java/org/apache/tamaya/consul/internal/ConsulMutableConfigurationBackend.java
new file mode 100644
index 0000000..6594b2c
--- /dev/null
+++ b/modules/integration/consul/src/main/java/org/apache/tamaya/consul/internal/ConsulMutableConfigurationBackend.java
@@ -0,0 +1,96 @@
+/*
+ * 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.internal;
+
+import org.apache.tamaya.consul.ConsulBackends;
+import org.apache.tamaya.mutableconfig.spi.AbstractMutableConfigurationBackendSpiSpi;
+
+import java.net.URI;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Change Request implementation based on etcd services. Etcd also supports a ttl to set values only for a defined
+ * number of seconds {@code ttl}. This is also supported by this component by adding ttl as a key parameter, e.g.
+ * {@code changeRequest.set("myTimedKey?ttl=30", "myValue");} will set a key {@code myTimedKey} valid only for
+ * 30 seconds.
+ */
+class ConsulMutableConfigurationBackend extends AbstractMutableConfigurationBackendSpiSpi {
+
+ private static final Logger LOG = Logger.getLogger(ConsulMutableConfigurationBackend.class.getName());
+
+ ConsulMutableConfigurationBackend(URI uri){
+ super(uri);
+ }
+
+ @Override
+ public boolean isExisting(String keyExpression) {
+ for(EtcdAccessor accessor: ConsulBackends.getEtcdBackends()){
+ try{
+ Map<String,String> props = accessor.get(keyExpression);
+ if(!props.containsKey("_ERROR")) {
+ // No repfix mapping necessary here, since we only access/return the value...
+ return props.get(keyExpression)!=null;
+ }
+ } catch(Exception e){
+ LOG.log(Level.FINE, "etcd access failed on " + accessor.getUrl() + ", trying next...", e);
+ }
+ }
+ return false;
+ }
+
+
+ @Override
+ protected void commitInternal() {
+ for(EtcdAccessor accessor: ConsulBackends.getEtcdBackends()){
+ try{
+ for(String k: 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: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 key from etcd: " + en.getKey() + "=" + en.getValue());
+ }
+ }
+ } 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/bb1e1e9d/modules/integration/consul/src/main/java/org/apache/tamaya/consul/internal/MutableConfigSupport.java
----------------------------------------------------------------------
diff --git a/modules/integration/consul/src/main/java/org/apache/tamaya/consul/internal/MutableConfigSupport.java b/modules/integration/consul/src/main/java/org/apache/tamaya/consul/internal/MutableConfigSupport.java
new file mode 100644
index 0000000..43dfb75
--- /dev/null
+++ b/modules/integration/consul/src/main/java/org/apache/tamaya/consul/internal/MutableConfigSupport.java
@@ -0,0 +1,44 @@
+/*
+ * 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.internal;
+
+import org.apache.tamaya.mutableconfig.spi.MutableConfigurationBackendSpi;
+import org.apache.tamaya.mutableconfig.spi.MutableConfigurationBackendProviderSpi;
+
+import java.net.URI;
+
+/**
+ * Created by atsticks on 15.01.16.
+ */
+public class MutableConfigSupport implements MutableConfigurationBackendProviderSpi {
+
+ private URI backendURI;
+
+ public MutableConfigSupport(){
+ backendURI = URI.create("config:etcd");
+ }
+
+ @Override
+ public MutableConfigurationBackendSpi getBackend(URI uri) {
+ if(backendURI.equals(uri)) {
+ return new EtcdConfigChangeRequest(backendURI);
+ }
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bb1e1e9d/modules/integration/consul/src/main/resources/META-INF/services/org.apache.tamaya.mutableconfig.spi.MutableConfigurationBackendProviderSpi
----------------------------------------------------------------------
diff --git a/modules/integration/consul/src/main/resources/META-INF/services/org.apache.tamaya.mutableconfig.spi.MutableConfigurationBackendProviderSpi b/modules/integration/consul/src/main/resources/META-INF/services/org.apache.tamaya.mutableconfig.spi.MutableConfigurationBackendProviderSpi
new file mode 100644
index 0000000..2189807
--- /dev/null
+++ b/modules/integration/consul/src/main/resources/META-INF/services/org.apache.tamaya.mutableconfig.spi.MutableConfigurationBackendProviderSpi
@@ -0,0 +1,19 @@
+#
+# 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.internal.MutableConfigSupport
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bb1e1e9d/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
new file mode 100644
index 0000000..eb7958e
--- /dev/null
+++ b/modules/integration/consul/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySource
@@ -0,0 +1,19 @@
+#
+# 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/bb1e1e9d/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
new file mode 100644
index 0000000..5d47738
--- /dev/null
+++ b/modules/integration/consul/src/test/java/org/apache/tamaya/etcd/ConsulPropertySourceTest.java
@@ -0,0 +1,75 @@
+/*
+ * 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("etcd.server.urls", "http://8.8.8.8:4001,http://192.168.99.105:4001");
+ }
+
+ @Test
+ public void testGetOrdinal() throws Exception {
+ assertEquals(propertySource.getOrdinal(), 100);
+ }
+
+ @Test
+ public void testGetDefaultOrdinal() throws Exception {
+ assertEquals(propertySource.getDefaultOrdinal(), 100);
+ }
+
+ @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/bb1e1e9d/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
new file mode 100644
index 0000000..4d94fe5
--- /dev/null
+++ b/modules/integration/consul/src/test/java/org/apache/tamaya/etcd/ConsulWriteTest.java
@@ -0,0 +1,117 @@
+/*
+ * 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.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 ConsulWriteTest {
+
+ private static HostAndPort accessor;
+ static boolean execute = false;
+
+ @BeforeClass
+ public static void setup() throws MalformedURLException {
+ accessor = new HostAndPort("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/bb1e1e9d/modules/integration/etcd/src/main/java/org/apache/tamaya/etcd/internal/EtcdConfigChangeRequest.java
----------------------------------------------------------------------
diff --git a/modules/integration/etcd/src/main/java/org/apache/tamaya/etcd/internal/EtcdConfigChangeRequest.java b/modules/integration/etcd/src/main/java/org/apache/tamaya/etcd/internal/EtcdConfigChangeRequest.java
deleted file mode 100644
index edd140b..0000000
--- a/modules/integration/etcd/src/main/java/org/apache/tamaya/etcd/internal/EtcdConfigChangeRequest.java
+++ /dev/null
@@ -1,97 +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.internal;
-
-import org.apache.tamaya.etcd.EtcdAccessor;
-import org.apache.tamaya.etcd.EtcdBackends;
-import org.apache.tamaya.mutableconfig.spi.AbstractMutableConfigurationBackendSpiSpi;
-
-import java.net.URI;
-import java.util.Map;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * Change Request implementation based on etcd services. Etcd also supports a ttl to set values only for a defined
- * number of seconds {@code ttl}. This is also supported by this component by adding ttl as a key parameter, e.g.
- * {@code changeRequest.set("myTimedKey?ttl=30", "myValue");} will set a key {@code myTimedKey} valid only for
- * 30 seconds.
- */
-class EtcdConfigChangeRequest extends AbstractMutableConfigurationBackendSpiSpi {
-
- private static final Logger LOG = Logger.getLogger(EtcdConfigChangeRequest.class.getName());
-
- EtcdConfigChangeRequest(URI uri){
- super(uri);
- }
-
- @Override
- public boolean isExisting(String keyExpression) {
- for(EtcdAccessor accessor: EtcdBackends.getEtcdBackends()){
- try{
- Map<String,String> props = accessor.get(keyExpression);
- if(!props.containsKey("_ERROR")) {
- // No repfix mapping necessary here, since we only access/return the value...
- return props.get(keyExpression)!=null;
- }
- } catch(Exception e){
- LOG.log(Level.FINE, "etcd access failed on " + accessor.getUrl() + ", trying next...", e);
- }
- }
- return false;
- }
-
-
- @Override
- protected void commitInternal() {
- for(EtcdAccessor accessor: EtcdBackends.getEtcdBackends()){
- try{
- for(String k: 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: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 key from etcd: " + en.getKey() + "=" + en.getValue());
- }
- }
- } 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/bb1e1e9d/modules/integration/etcd/src/main/java/org/apache/tamaya/etcd/internal/EtcdMutableConfigurationBackend.java
----------------------------------------------------------------------
diff --git a/modules/integration/etcd/src/main/java/org/apache/tamaya/etcd/internal/EtcdMutableConfigurationBackend.java b/modules/integration/etcd/src/main/java/org/apache/tamaya/etcd/internal/EtcdMutableConfigurationBackend.java
new file mode 100644
index 0000000..b384074
--- /dev/null
+++ b/modules/integration/etcd/src/main/java/org/apache/tamaya/etcd/internal/EtcdMutableConfigurationBackend.java
@@ -0,0 +1,97 @@
+/*
+ * 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.internal;
+
+import org.apache.tamaya.etcd.EtcdAccessor;
+import org.apache.tamaya.etcd.EtcdBackends;
+import org.apache.tamaya.mutableconfig.spi.AbstractMutableConfigurationBackendSpiSpi;
+
+import java.net.URI;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Change Request implementation based on etcd services. Etcd also supports a ttl to set values only for a defined
+ * number of seconds {@code ttl}. This is also supported by this component by adding ttl as a key parameter, e.g.
+ * {@code changeRequest.set("myTimedKey?ttl=30", "myValue");} will set a key {@code myTimedKey} valid only for
+ * 30 seconds.
+ */
+class EtcdMutableConfigurationBackend extends AbstractMutableConfigurationBackendSpiSpi {
+
+ private static final Logger LOG = Logger.getLogger(EtcdMutableConfigurationBackend.class.getName());
+
+ EtcdMutableConfigurationBackend(URI uri){
+ super(uri);
+ }
+
+ @Override
+ public boolean isExisting(String keyExpression) {
+ for(EtcdAccessor accessor: EtcdBackends.getEtcdBackends()){
+ try{
+ Map<String,String> props = accessor.get(keyExpression);
+ if(!props.containsKey("_ERROR")) {
+ // No repfix mapping necessary here, since we only access/return the value...
+ return props.get(keyExpression)!=null;
+ }
+ } catch(Exception e){
+ LOG.log(Level.FINE, "etcd access failed on " + accessor.getUrl() + ", trying next...", e);
+ }
+ }
+ return false;
+ }
+
+
+ @Override
+ protected void commitInternal() {
+ for(EtcdAccessor accessor: EtcdBackends.getEtcdBackends()){
+ try{
+ for(String k: 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: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 key from etcd: " + en.getKey() + "=" + en.getValue());
+ }
+ }
+ } 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/bb1e1e9d/modules/yaml/pom.xml
----------------------------------------------------------------------
diff --git a/modules/yaml/pom.xml b/modules/yaml/pom.xml
new file mode 100644
index 0000000..670516c
--- /dev/null
+++ b/modules/yaml/pom.xml
@@ -0,0 +1,147 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+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.
+-->
+<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-extensions</artifactId>
+ <version>0.2-incubating-SNAPSHOT</version>
+ <relativePath>..</relativePath>
+ </parent>
+ <artifactId>tamaya-json</artifactId>
+ <name>Apache Tamaya Modules - JSON Support</name>
+ <packaging>bundle</packaging>
+ <inceptionYear>2015</inceptionYear>
+
+ <properties>
+ <jdkVersion>1.7</jdkVersion>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tamaya</groupId>
+ <artifactId>tamaya-api</artifactId>
+ <version>${project.version}</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tamaya</groupId>
+ <artifactId>tamaya-core</artifactId>
+ <version>${project.version}</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-formats</artifactId>
+ <version>${project.version}</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>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.arquillian.daemon</groupId>
+ <artifactId>arquillian-daemon-container-managed</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.arquillian.daemon</groupId>
+ <artifactId>arquillian-daemon-container-common</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.arquillian.daemon</groupId>
+ <artifactId>arquillian-daemon-main</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.arquillian.daemon</groupId>
+ <artifactId>arquillian-daemon-protocol-arquillian</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.arquillian.daemon</groupId>
+ <artifactId>arquillian-daemon-protocol-wire</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.arquillian.daemon</groupId>
+ <artifactId>arquillian-daemon-server</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.arquillian.junit</groupId>
+ <artifactId>arquillian-junit-container</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>java-hamcrest</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>copyMain</id>
+ <phase>process-test-sources</phase>
+ <goals>
+ <goal>copy</goal>
+ </goals>
+ <configuration>
+ <outputDirectory>${project.build.directory}</outputDirectory>
+ <overWriteReleases>false</overWriteReleases>
+ <overWriteSnapshots>false</overWriteSnapshots>
+ <overWriteIfNewer>true</overWriteIfNewer>
+ <stripVersion>true</stripVersion>
+ <artifactItems>
+ <artifactItem>
+ <groupId>org.jboss.arquillian.daemon</groupId>
+ <artifactId>arquillian-daemon-main</artifactId>
+ </artifactItem>
+ </artifactItems>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Export-Package>
+ org.apache.tamaya.json
+ </Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bb1e1e9d/modules/yaml/src/main/java/org/apache/tamaya/json/YAMLFormat.java
----------------------------------------------------------------------
diff --git a/modules/yaml/src/main/java/org/apache/tamaya/json/YAMLFormat.java b/modules/yaml/src/main/java/org/apache/tamaya/json/YAMLFormat.java
new file mode 100644
index 0000000..8bdd414
--- /dev/null
+++ b/modules/yaml/src/main/java/org/apache/tamaya/json/YAMLFormat.java
@@ -0,0 +1,85 @@
+/*
+ * 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.json;
+
+import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.format.ConfigurationData;
+import org.apache.tamaya.format.ConfigurationDataBuilder;
+import org.apache.tamaya.format.ConfigurationFormat;
+
+import java.io.InputStream;
+import java.net.URL;
+import java.nio.charset.Charset;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+
+import javax.json.Json;
+import javax.json.JsonException;
+import javax.json.JsonObject;
+import javax.json.JsonReader;
+import javax.json.JsonReaderFactory;
+
+/**
+ * Implementation of the {@link org.apache.tamaya.format.ConfigurationFormat}
+ * able to read configuration properties represented in JSON
+ *
+ * @see <a href="http://www.json.org">JSON format specification</a>
+ */
+public class JSONFormat implements ConfigurationFormat {
+ /** Property that make Johnzon accept commentc. */
+ public static final String JOHNZON_SUPPORTS_COMMENTS_PROP = "org.apache.johnzon.supports-comments";
+ /** The reader factory used. */
+ private final JsonReaderFactory readerFactory;
+
+ /**
+ * Constructor, itniaitlizing zhe JSON reader factory.
+ */
+ public JSONFormat(){
+ Map<String, Object> config = new HashMap<>();
+ config.put(JOHNZON_SUPPORTS_COMMENTS_PROP, true);
+ this.readerFactory = Json.createReaderFactory(config);
+ }
+
+ @Override
+ public String getName() {
+ return "json";
+ }
+
+ @Override
+ public boolean accepts(URL url) {
+ return Objects.requireNonNull(url).getPath().endsWith(".json");
+ }
+
+ @Override
+ public ConfigurationData readConfiguration(String resource, InputStream inputStream) {
+
+ try {
+ final JsonReader reader = this.readerFactory.createReader(inputStream, Charset.forName("UTF-8"));
+ JsonObject root = reader.readObject();
+ HashMap<String, String> values = new HashMap<>();
+ JSONVisitor visitor = new JSONVisitor(root, values);
+ visitor.run();
+ return ConfigurationDataBuilder.of(resource, this).addProperties(values)
+ .build();
+ } catch (JsonException e) {
+ throw new ConfigException("Failed to read data from " + resource, e);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bb1e1e9d/modules/yaml/src/main/java/org/apache/tamaya/json/YAMLPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/yaml/src/main/java/org/apache/tamaya/json/YAMLPropertySource.java b/modules/yaml/src/main/java/org/apache/tamaya/json/YAMLPropertySource.java
new file mode 100644
index 0000000..43cfa73
--- /dev/null
+++ b/modules/yaml/src/main/java/org/apache/tamaya/json/YAMLPropertySource.java
@@ -0,0 +1,149 @@
+/*
+ * 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.json;
+
+import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.PropertyValue;
+
+import java.io.InputStream;
+import java.net.URL;
+import java.nio.charset.Charset;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.json.Json;
+import javax.json.JsonObject;
+import javax.json.JsonReaderFactory;
+import javax.json.JsonStructure;
+
+import static java.lang.String.format;
+
+/**
+ * Property source based on a JSON file.
+ */
+public class JSONPropertySource implements PropertySource {
+ /** Constant for enabling comments in Johnzon. */
+ public static final String JOHNZON_SUPPORTS_COMMENTS_PROP = "org.apache.johnzon.supports-comments";
+
+ /** The underlying resource. */
+ private final URL urlResource;
+ /** The values read. */
+ private final Map<String, String> values;
+ /** The evaluated ordinal. */
+ private int ordinal;
+ /** The JSON reader factory used. */
+ private JsonReaderFactory readerFactory = initReaderFactory();
+
+ /** Initializes the factory to be used for creating readers. */
+ private JsonReaderFactory initReaderFactory() {
+ Map<String, Object> config = new HashMap<>();
+ config.put(JOHNZON_SUPPORTS_COMMENTS_PROP, true);
+ return Json.createReaderFactory(config);
+ }
+
+ /**
+ * Constructor, hereby using 0 as the default ordinal.
+ * @param resource the resource modelled as URL, not null.
+ */
+ public JSONPropertySource(URL resource) {
+ this(resource, 0);
+ }
+
+ /**
+ * Constructor.
+ * @param resource the resource modelled as URL, not null.
+ * @param defaultOrdinal the defaultOrdinal to be used.
+ */
+ public JSONPropertySource(URL resource, int defaultOrdinal) {
+ urlResource = Objects.requireNonNull(resource);
+ this.ordinal = defaultOrdinal; // may be overriden by read...
+ this.values = readConfig(urlResource);
+ if (this.values.containsKey(TAMAYA_ORDINAL)) {
+ this.ordinal = Integer.parseInt(this.values.get(TAMAYA_ORDINAL));
+ }
+ Map<String, Object> config = new HashMap<>();
+ config.put(JOHNZON_SUPPORTS_COMMENTS_PROP, true);
+ this.readerFactory = Json.createReaderFactory(config);
+ }
+
+
+ @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 ordinal;
+ }
+
+ @Override
+ public String getName() {
+ return urlResource.toExternalForm();
+ }
+
+ @Override
+ public PropertyValue get(String key) {
+ return PropertyValue.of(key, getProperties().get(key), getName());
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ return Collections.unmodifiableMap(values);
+ }
+
+ /**
+ * Reads the configuration.
+ * @param urlResource soure of the configuration.
+ * @return the configuration read from the given resource URL.
+ * @throws ConfigException if resource URL cannot be read.
+ */
+ protected Map<String, String> readConfig(URL urlResource) {
+ try (InputStream is = urlResource.openStream()) {
+ JsonStructure root = this.readerFactory.createReader(is, Charset.forName("UTF-8")).read();
+
+ // Test added. H. Saly, 15. Aug. 2015
+ if (!(root instanceof JsonObject)) {
+ throw new ConfigException("Currently only JSON objects are supported");
+ }
+
+ Map<String, String> values = new HashMap<>();
+ JSONVisitor visitor = new JSONVisitor((JsonObject)root, values);
+ visitor.run();
+ return values;
+ }
+ catch (Throwable t) {
+ throw new ConfigException(format("Failed to read properties from %s", urlResource.toExternalForm()), t);
+ }
+ }
+
+ @Override
+ public boolean isScannable() {
+ return true;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bb1e1e9d/modules/yaml/src/test/java/org/apache/tamaya/json/YAMLFormatTest.java
----------------------------------------------------------------------
diff --git a/modules/yaml/src/test/java/org/apache/tamaya/json/YAMLFormatTest.java b/modules/yaml/src/test/java/org/apache/tamaya/json/YAMLFormatTest.java
new file mode 100644
index 0000000..dc24048
--- /dev/null
+++ b/modules/yaml/src/test/java/org/apache/tamaya/json/YAMLFormatTest.java
@@ -0,0 +1,75 @@
+/*
+ * 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.json;
+
+
+import org.apache.tamaya.format.ConfigurationData;
+import org.apache.tamaya.format.FlattenedDefaultPropertySource;
+import org.apache.tamaya.spi.PropertySource;
+import org.junit.Test;
+
+import java.io.InputStream;
+import java.net.URL;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+
+public class YAMLFormatTest extends CommonJSONTestCaseCollection {
+ private final JSONFormat format = new JSONFormat();
+
+ @Test(expected = NullPointerException.class)
+ public void acceptsNeedsNonNullParameter() throws Exception {
+ format.accepts(null);
+ }
+
+ @Test
+ public void aNonJSONFileBasedURLIsNotAccepted() throws Exception {
+ URL url = new URL("file:///etc/service/conf.conf");
+
+ assertThat(format.accepts(url), is(false));
+ }
+
+ @Test
+ public void aJSONFileBasedURLIsAccepted() throws Exception {
+ URL url = new URL("file:///etc/service/conf.json");
+
+ assertThat(format.accepts(url), is(true));
+ }
+
+ @Test
+ public void aHTTPBasedURLIsNotAccepted() throws Exception {
+ URL url = new URL("http://nowhere.somewhere/conf.json");
+ assertThat(format.accepts(url), is(true));
+ }
+
+ @Test
+ public void aFTPBasedURLIsNotAccepted() throws Exception {
+ URL url = new URL("ftp://nowhere.somewhere/a/b/c/d/conf.json");
+
+ assertThat(format.accepts(url), is(true));
+ }
+
+ @Override
+ PropertySource getPropertiesFrom(URL source) throws Exception {
+ try (InputStream is = source.openStream()) {
+ ConfigurationData data = format.readConfiguration(source.toString(), is);
+ return new FlattenedDefaultPropertySource(data);
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bb1e1e9d/modules/yaml/src/test/java/org/apache/tamaya/json/YAMLPropertySourceTest.java
----------------------------------------------------------------------
diff --git a/modules/yaml/src/test/java/org/apache/tamaya/json/YAMLPropertySourceTest.java b/modules/yaml/src/test/java/org/apache/tamaya/json/YAMLPropertySourceTest.java
new file mode 100644
index 0000000..a15f553
--- /dev/null
+++ b/modules/yaml/src/test/java/org/apache/tamaya/json/YAMLPropertySourceTest.java
@@ -0,0 +1,56 @@
+/*
+ * 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.json;
+
+import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.spi.PropertySource;
+import org.hamcrest.CoreMatchers;
+import org.junit.Test;
+
+import java.net.URL;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertEquals;
+
+public class YAMLPropertySourceTest extends CommonJSONTestCaseCollection {
+
+ @Test
+ public void tamayaOrdinalKeywordIsNotPropagatedAsNormalProperty() throws Exception {
+ URL configURL = YAMLPropertySourceTest.class.getResource("/configs/valid/with-explicit-priority.json");
+
+ assertThat(configURL, CoreMatchers.notNullValue());
+
+ JSONPropertySource source = new JSONPropertySource(configURL, 4);
+ assertEquals(source.get(PropertySource.TAMAYA_ORDINAL).getValue(), "16784");
+ }
+
+ @Test(expected=ConfigException.class)
+ public void testDoNotAcceptJsonArrays() throws Exception {
+ URL configURL = YAMLPropertySourceTest.class.getResource("/configs/invalid/array.json");
+
+ assertThat(configURL, CoreMatchers.notNullValue());
+
+ new JSONPropertySource(configURL);
+ }
+
+ @Override
+ PropertySource getPropertiesFrom(URL source) throws Exception {
+ return new JSONPropertySource(source);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bb1e1e9d/modules/yaml/src/test/resources/configs/valid/contact.yaml
----------------------------------------------------------------------
diff --git a/modules/yaml/src/test/resources/configs/valid/contact.yaml b/modules/yaml/src/test/resources/configs/valid/contact.yaml
new file mode 100644
index 0000000..32eca23
--- /dev/null
+++ b/modules/yaml/src/test/resources/configs/valid/contact.yaml
@@ -0,0 +1,29 @@
+-- !clarkevans.com/^invoice
+invoice: 34843
+date : 2001-01-23
+bill-to: &id001
+ given : Chris
+ family : Dumars
+ address:
+ lines: |
+ 458 Walkman Dr.
+ Suite #292
+ city : Royal Oak
+ state : MI
+ postal : 48046
+ship-to: *id001
+product:
+ - sku : BL394D
+ quantity : 4
+ description : Basketball
+ price : 450.00
+ - sku : BL4438H
+ quantity : 1
+ description : Super Hoop
+ price : 2392.00
+tax : 251.42
+total: 4443.52
+comments: >
+ Late afternoon is best.
+ Backup contact is Nancy
+ Billsmer @ 338-4338.
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bb1e1e9d/modules/yaml/src/test/resources/configs/valid/test-with-prio.yaml
----------------------------------------------------------------------
diff --git a/modules/yaml/src/test/resources/configs/valid/test-with-prio.yaml b/modules/yaml/src/test/resources/configs/valid/test-with-prio.yaml
new file mode 100644
index 0000000..697e9f3
--- /dev/null
+++ b/modules/yaml/src/test/resources/configs/valid/test-with-prio.yaml
@@ -0,0 +1,35 @@
+#
+# 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.
+#
+version: 1.0
+released: 2012-11-30
+
+# Connection parameters
+connection:
+ url: jdbc:mysql://localhost:3306/db
+ poolSize: 5
+
+# Protocols
+protocols:
+ - http
+ - https
+
+# Users
+users:
+ tom: passwd
+ bob: passwd
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bb1e1e9d/modules/yaml/src/test/resources/configs/valid/test.yaml
----------------------------------------------------------------------
diff --git a/modules/yaml/src/test/resources/configs/valid/test.yaml b/modules/yaml/src/test/resources/configs/valid/test.yaml
new file mode 100644
index 0000000..697e9f3
--- /dev/null
+++ b/modules/yaml/src/test/resources/configs/valid/test.yaml
@@ -0,0 +1,35 @@
+#
+# 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.
+#
+version: 1.0
+released: 2012-11-30
+
+# Connection parameters
+connection:
+ url: jdbc:mysql://localhost:3306/db
+ poolSize: 5
+
+# Protocols
+protocols:
+ - http
+ - https
+
+# Users
+users:
+ tom: passwd
+ bob: passwd
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bb1e1e9d/src/site/asciidoc/extensions/mod_consul.adoc
----------------------------------------------------------------------
diff --git a/src/site/asciidoc/extensions/mod_consul.adoc b/src/site/asciidoc/extensions/mod_consul.adoc
new file mode 100644
index 0000000..1a0d1f6
--- /dev/null
+++ b/src/site/asciidoc/extensions/mod_consul.adoc
@@ -0,0 +1,223 @@
+// 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.
+
+= Apache Tamaya -- Extension: Integration with etcd (Core OS)
+
+:name: Tamaya
+:rootpackage: org.apache.tamaya.integration.etcd
+:title: Apache Tamaya Extension: Integration with etcd service
+:revdate: January 2016
+:authorinitials: ATR
+:author: Anatole Tresch
+:email: <an...@apache.org>
+:source-highlighter: coderay
+:website: http://tamaya.incubator.apache.org/
+:toc:
+:toc-placement: manual
+:encoding: UTF-8
+:numbered:
+
+'''
+
+<<<
+
+toc::[]
+
+<<<
+:numbered!:
+<<<
+[[Optional]]
+== Integration with etcd (Extension Module)
+=== Overview
+
+The Tamaya etcd integration module provides different artifacts which allows integration of Apachae Tamaya
+configuration with etcd. Basically the module supports read-only integration (as a +EtcdPropertySource+ as well
+as a support for +MutableConfiguration+ as defined by the +tamaya-mutable-config+ extension module.
+
+
+=== Compatibility
+
+The module is based on Java 7, so it will not run on Java 7 and beyond.
+
+
+=== Installation
+
+To benefit from configuration builder support you only must add the corresponding dependency to your module:
+
+[source, xml]
+-----------------------------------------------
+<dependency>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-etcd</artifactId>
+ <version>{tamayaVersion}</version>
+</dependency>
+-----------------------------------------------
+
+
+=== The Extensions Provided
+
+ETcd integration comes basically with 2 artifacts:
+
+* The +org.apache.tamaya.etcd.EtcdAccessor+ can be configured with a an url targeting an etcd server's REST endpoint root.
+ (+org.apache.tamaya.etcd.EtcdAccessor+). The accessor basically provides a simple Java API for communicating
+ with etcd server. The accessor hereby allows reading of single properties, or whole subtrees. Also the basic non
+ atomic write methods are implemented.
+* The +org.apache.tamaya.etcd.EtcdPropertySource+ is a +PropertySource+ with a default ordinal of 100 and the name
+ 'etcd', which is automatically registered.
+* If the +tamaya-mutable-config+ module is loaded it is possible to write property values back into the etcd cluster,
+ by accessing a +MutableConfiguration+ using the URI +config:etcd+.
+
+=== The EtcdAccessor
+
+The accessor mentioned implements the basic read and write API for communicating with an etcd configuration cluster.
+Hereby the accessor also provides etcd specific data such as +createdIndex, modifiedIndex, ttl+ in the +Map+
+returned. Hereby the concept of etcd is used where keys starting with an '_' will be hidden from the overall
+properties map, being only directly/explicitly accessible:
+
+[source, java]
+-----------------------------------------------
+public class EtcdAccessor {
+
+ /**
+ * Creates a new instance with the basic access url.
+ * @param server server url, e.g. {@code http://127.0.0.1:4001}.
+ * @throws MalformedURLException
+ */
+ public EtcdAccessor(String server) throws MalformedURLException;
+
+ /**
+ * Get the etcd server version.
+ * @return the etcd server version, never null.
+ */
+ public String getVersion();
+
+ /**
+ * Ask etcd for s aingle key, value pair. Hereby the response returned from etcd:
+ * <pre>
+ * key=value
+ * _key.source=[etcd]http://127.0.0.1:4001
+ * _key.createdIndex=12
+ * _key.modifiedIndex=34 // optional
+ * _key.ttl=300 // optional
+ * _key.expiration=... // optional
+ * </pre>
+ * @param key the requested key
+ * @return the mapped result, including meta-entries.
+ */
+ public Map<String,String> get(String key);
+
+ /**
+ * Creates/updates an entry in etcd without any ttl set.
+ * The response is as follows:
+ * <pre>
+ * key=value
+ * _key.source=[etcd]http://127.0.0.1:4001
+ * _key.createdIndex=12
+ * _key.modifiedIndex=34 // optional
+ * _key.prevNode.createdIndex=12 // optional
+ * _key.prevNode.modifiedIndex=34 // optional
+ * </pre>
+ * @param key the property key, not null
+ * @param value the value to be set
+ * @return the result map as described above.
+ */
+ public Map<String,String> set(String key, String value);
+
+ /**
+ * Creates/updates an entry in etcd. The response is as follows:
+ * <pre>
+ * key=value
+ * _key.source=[etcd]http://127.0.0.1:4001
+ * _key.createdIndex=12
+ * _key.modifiedIndex=34 // optional
+ * _key.ttl=300 // optional
+ * _key.expiry=... // optional
+ * _key.prevNode.createdIndex=12 // optional
+ * _key.prevNode.modifiedIndex=34 // optional
+ * _key.prevNode.ttl=300 // optional
+ * _key.prevNode.expiration=... // optional
+ * </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);
+
+
+ /**
+ * 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 // optional
+ * _key.expiry=... // optional
+ * _key.prevNode.createdIndex=12 // optional
+ * _key.prevNode.modifiedIndex=34 // optional
+ * _key.prevNode.ttl=300 // optional
+ * _key.prevNode.expiration=... // optional
+ * _key.prevNode.value=... // optional
+ * </pre>
+ * @param key the key to be deleted.
+ * @return the response mpas as described above.
+ */
+ public Map<String,String> delete(String key);
+
+
+ /**
+ * Access regular Tamaya properties map as follows:
+ * <pre>
+ * key1=myvalue
+ * _key1.source=[etcd]http://127.0.0.1:4001
+ * _key1.createdIndex=12
+ * _key1.modifiedIndex=34 // optional
+ * _key1.ttl=300 // optional
+ * _key1.expiration=... // optional
+ *
+ * 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>
+ */
+ public Map<String,String> getProperties(String directory, boolean recursive);
+
+}
+-----------------------------------------------
+
+
+=== The EtcdPropertySource
+
+The +EtcdPropertySource+ is automatically registered and requires the etcd servers to be used to be configured. This
+enables to use e.g. in Docker environments the docker environment configuration mechanisms to configure Tamaya running
+in microservice containers to connect with the according etcd container cluster:
+
+* The property source reads the +tamaya.etcd.server.urls+ system property to evaluate possible etcd servers
+ (comma separated), which can be connected to. On error the API just performs a Round-Robin through the list of
+ configured servers. Without any configuration +http://127.0.0.1:4001+ is used. If no connection to any etcd
+ server can be established a warning will be logged, but deployment will not fail.
+* Additinoally also the
+ accessor allows to configure the socket/connection timeouts by setting +tamaya.etcd.timeout+ in seconds either as
+ system or environment property.
+* The +EtcdPropertySource+ finally also allows the values read from the etcd cluster to be mapped to prefixed
+ context. This can be activated by setting the +-Dtamaya.etcd.prefix=<PREFIX>+ system property. E.g. when the prefix is
+ set to +cluster-config.+ a etcd key of +host:known/all+ is mapped to +cluster-config.host:known/all+.
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bb1e1e9d/src/site/asciidoc/extensions/mod_yaml.adoc
----------------------------------------------------------------------
diff --git a/src/site/asciidoc/extensions/mod_yaml.adoc b/src/site/asciidoc/extensions/mod_yaml.adoc
new file mode 100644
index 0000000..edb66ad
--- /dev/null
+++ b/src/site/asciidoc/extensions/mod_yaml.adoc
@@ -0,0 +1,115 @@
+// 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.
+
+= Apache Tamaya -- Extension: Builder
+
+:name: Tamaya
+:rootpackage: org.apache.tamaya.builder
+:title: Apache Tamaya Extension: JSON
+:revnumber: 0.1.1
+:revremark: Incubator
+:revdate: March 2015
+:longversion: {revnumber} ({revremark}) {revdate}
+:authorinitials: ATR
+:author: Anatole Tresch
+:email: <an...@apache.org>
+:source-highlighter: coderay
+:website: http://tamaya.incubator.apache.org/
+:toc:
+:toc-placement: manual
+:encoding: UTF-8
+:numbered:
+// 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.
+'''
+
+<<<
+
+toc::[]
+
+<<<
+:numbered!:
+<<<
+[[BuilderCore]]
+== Tamaya JSON (Extension Module)
+=== Overview
+
+The Tamaya json module provides support for reading configuration using the JSON format:
+
+
+=== Compatibility
+
+The module is based on Java 7, so it will not run on Java 7 and beyond.
+
+
+=== Installation
+
+To benefit from configuration builder support you only must add the corresponding dependency to your module:
+
+[source, xml]
+-----------------------------------------------
+<dependency>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-json</artifactId>
+ <version>{tamayaVersion}</version>
+</dependency>
+-----------------------------------------------
+
+
+=== Reading configuration in JSON
+
+For reading JSON based onfiguration most easily a +JSONFormat+ can be provided:
+
+[source, java]
+-----------------------------------------------
+ConfigurationData dataRead = ConfigurationFormats.readConfig(
+ getClassLoader().getResource("myFileConfig.json"), new JSonFOrmat()));
+-----------------------------------------------
+
+=== Examples
+
+The JSON module adds instances of +ConfigurationFormat+ so JSON configuration can be read and mapped to the
+according property maps. E.g. the following file is a simple and correct JSON configuration:
+
+[source,listing]
+----------------------------------------------------------------
+{
+ "a" : "A",
+ "b" : "B",
+ "c" : "C",
+ "d" : {
+ "o" : "O",
+ "p" : "P"
+ }
+}
+----------------------------------------------------------------
+
+
[07/10] incubator-tamaya git commit: Adapted etcd integration.
Posted by an...@apache.org.
Adapted etcd integration.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/2dfa4d8e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/2dfa4d8e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/2dfa4d8e
Branch: refs/heads/master
Commit: 2dfa4d8e4a70d9b16721613dccb5a890abac481c
Parents: e82b26c
Author: anatole <an...@apache.org>
Authored: Sat Feb 27 21:58:51 2016 +0100
Committer: anatole <an...@apache.org>
Committed: Sat Feb 27 21:58:51 2016 +0100
----------------------------------------------------------------------
.../tamaya/etcd/internal/EtcdMutableConfigurationBackend.java | 2 +-
.../java/org/apache/tamaya/etcd/internal/MutableConfigSupport.java | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/2dfa4d8e/modules/integration/etcd/src/main/java/org/apache/tamaya/etcd/internal/EtcdMutableConfigurationBackend.java
----------------------------------------------------------------------
diff --git a/modules/integration/etcd/src/main/java/org/apache/tamaya/etcd/internal/EtcdMutableConfigurationBackend.java b/modules/integration/etcd/src/main/java/org/apache/tamaya/etcd/internal/EtcdMutableConfigurationBackend.java
index b384074..d2a186f 100644
--- a/modules/integration/etcd/src/main/java/org/apache/tamaya/etcd/internal/EtcdMutableConfigurationBackend.java
+++ b/modules/integration/etcd/src/main/java/org/apache/tamaya/etcd/internal/EtcdMutableConfigurationBackend.java
@@ -85,7 +85,7 @@ class EtcdMutableConfigurationBackend extends AbstractMutableConfigurationBacken
}
Map<String,String> res = accessor.set(key, en.getValue(), ttl);
if(res.get("_ERROR")!=null){
- LOG.info("Failed key from etcd: " + en.getKey() + "=" + en.getValue());
+ LOG.info("Failed to add key to etcd: " + en.getKey() + "=" + en.getValue());
}
}
} catch(Exception e){
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/2dfa4d8e/modules/integration/etcd/src/main/java/org/apache/tamaya/etcd/internal/MutableConfigSupport.java
----------------------------------------------------------------------
diff --git a/modules/integration/etcd/src/main/java/org/apache/tamaya/etcd/internal/MutableConfigSupport.java b/modules/integration/etcd/src/main/java/org/apache/tamaya/etcd/internal/MutableConfigSupport.java
index eb445e3..ba734cd 100644
--- a/modules/integration/etcd/src/main/java/org/apache/tamaya/etcd/internal/MutableConfigSupport.java
+++ b/modules/integration/etcd/src/main/java/org/apache/tamaya/etcd/internal/MutableConfigSupport.java
@@ -37,7 +37,7 @@ public class MutableConfigSupport implements MutableConfigurationBackendProvider
@Override
public MutableConfigurationBackendSpi getBackend(URI uri) {
if(backendURI.equals(uri)) {
- return new EtcdConfigChangeRequest(backendURI);
+ return new EtcdMutableConfigurationBackend(backendURI);
}
return null;
}
[04/10] incubator-tamaya git commit: TAMAYA-143: Finished/tested
consul support.
Posted by an...@apache.org.
TAMAYA-143: Finished/tested consul support.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/ffc59e03
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/ffc59e03
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/ffc59e03
Branch: refs/heads/master
Commit: ffc59e03bc5a0390144297f74250af386b89535a
Parents: 60e8827
Author: anatole <an...@apache.org>
Authored: Sat Feb 27 21:56:02 2016 +0100
Committer: anatole <an...@apache.org>
Committed: Sat Feb 27 21:56:02 2016 +0100
----------------------------------------------------------------------
modules/integration/consul/pom.xml | 2 +-
.../apache/tamaya/consul/ConsulBackends.java | 30 +++-----
.../tamaya/consul/ConsulPropertySource.java | 73 +++++++++++-------
.../ConsulMutableConfigurationBackend.java | 56 ++++++--------
.../consul/internal/MutableConfigSupport.java | 4 +-
...g.spi.MutableConfigurationBackendProviderSpi | 2 +-
.../org.apache.tamaya.spi.PropertySource | 2 +-
.../tamaya/etcd/ConsulPropertySourceTest.java | 6 +-
.../org/apache/tamaya/etcd/ConsulWriteTest.java | 80 +++++---------------
modules/integration/pom.xml | 1 +
10 files changed, 111 insertions(+), 145 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ffc59e03/modules/integration/consul/pom.xml
----------------------------------------------------------------------
diff --git a/modules/integration/consul/pom.xml b/modules/integration/consul/pom.xml
index 2795597..add1089 100644
--- a/modules/integration/consul/pom.xml
+++ b/modules/integration/consul/pom.xml
@@ -26,7 +26,7 @@ under the License.
<version>0.2-incubating-SNAPSHOT</version>
</parent>
- <artifactId>tamaya-etcd</artifactId>
+ <artifactId>tamaya-consul</artifactId>
<name>Apache Tamaya Integration - consul</name>
<packaging>bundle</packaging>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ffc59e03/modules/integration/consul/src/main/java/org/apache/tamaya/consul/ConsulBackends.java
----------------------------------------------------------------------
diff --git a/modules/integration/consul/src/main/java/org/apache/tamaya/consul/ConsulBackends.java b/modules/integration/consul/src/main/java/org/apache/tamaya/consul/ConsulBackends.java
index cab9656..4eab141 100644
--- a/modules/integration/consul/src/main/java/org/apache/tamaya/consul/ConsulBackends.java
+++ b/modules/integration/consul/src/main/java/org/apache/tamaya/consul/ConsulBackends.java
@@ -18,48 +18,42 @@
*/
package org.apache.tamaya.consul;
+import com.google.common.net.HostAndPort;
+
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.
+ * Singleton that reads and stores the current consul setup, especially the possible host:ports to be used.
*/
public final class ConsulBackends {
private static final Logger LOG = Logger.getLogger(ConsulBackends.class.getName());
- private static List<EtcdAccessor> etcdBackends = new ArrayList<>();
+ private static List<HostAndPort> consulBackends = 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");
+ String serverURLs = System.getProperty("tamaya.consul.urls");
if(serverURLs==null){
- serverURLs = System.getenv("tamaya.etcd.server.urls");
+ serverURLs = System.getenv("tamaya.consul.urls");
}
if(serverURLs==null){
- serverURLs = "http://127.0.0.1:4001";
+ serverURLs = "127.0.0.1:8300";
}
for(String url:serverURLs.split("\\,")) {
try{
- etcdBackends.add(new EtcdAccessor(url.trim(), timeout));
- LOG.info("Using etcd endoint: " + url);
+ consulBackends.add(HostAndPort.fromString(url.trim()));
+ LOG.info("Using consul endoint: " + url);
} catch(Exception e){
- LOG.log(Level.SEVERE, "Error initializing etcd accessor for URL: " + url, e);
+ LOG.log(Level.SEVERE, "Error initializing consul accessor for URL: " + url, e);
}
}
}
private ConsulBackends(){}
- public static List<EtcdAccessor> getEtcdBackends(){
- return etcdBackends;
+ public static List<HostAndPort> getConsulBackends(){
+ return consulBackends;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ffc59e03/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
index 03db401..65ba6cd 100644
--- 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
@@ -18,6 +18,11 @@
*/
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.spi.PropertySource;
import org.apache.tamaya.spi.PropertyValue;
import org.apache.tamaya.spi.PropertyValueBuilder;
@@ -29,14 +34,14 @@ 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.
+ * 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 implements PropertySource{
private static final Logger LOG = Logger.getLogger(ConsulPropertySource.class.getName());
- private String prefix = System.getProperty("tamaya.etcd.prefix", "");
+ private String prefix = System.getProperty("tamaya.consul.prefix", "");
@Override
@@ -63,7 +68,7 @@ public class ConsulPropertySource implements PropertySource{
@Override
public String getName() {
- return "etcd";
+ return "consul";
}
@Override
@@ -75,7 +80,6 @@ public class ConsulPropertySource implements PropertySource{
} else{
key = key.substring(prefix.length());
}
- Map<String,String> props;
String reqKey = key;
if(key.startsWith("_")){
reqKey = key.substring(1);
@@ -91,17 +95,25 @@ public class ConsulPropertySource implements PropertySource{
reqKey = reqKey.substring(0,reqKey.length()-".source".length());
}
}
- for(EtcdAccessor accessor: EtcdBackends.getEtcdBackends()){
+ for(HostAndPort hostAndPort: ConsulBackends.getConsulBackends()){
try{
- props = accessor.get(reqKey);
- if(!props.containsKey("_ERROR")) {
+ 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...
- return new PropertyValueBuilder(key, props.get(reqKey), getName()).setContextData(props).build();
- } else{
- LOG.log(Level.FINE, "etcd error on " + accessor.getUrl() + ": " + props.get("_ERROR"));
+ 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 " + accessor.getUrl() + ", trying next...", e);
+ LOG.log(Level.FINE, "etcd access failed on " + hostAndPort + ", trying next...", e);
}
}
return null;
@@ -109,20 +121,25 @@ public class ConsulPropertySource implements PropertySource{
@Override
public Map<String, String> getProperties() {
- 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);
- }
- }
- }
+// 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();
}
@@ -143,6 +160,6 @@ public class ConsulPropertySource implements PropertySource{
@Override
public boolean isScannable() {
- return true;
+ return false;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ffc59e03/modules/integration/consul/src/main/java/org/apache/tamaya/consul/internal/ConsulMutableConfigurationBackend.java
----------------------------------------------------------------------
diff --git a/modules/integration/consul/src/main/java/org/apache/tamaya/consul/internal/ConsulMutableConfigurationBackend.java b/modules/integration/consul/src/main/java/org/apache/tamaya/consul/internal/ConsulMutableConfigurationBackend.java
index 6594b2c..b43c442 100644
--- a/modules/integration/consul/src/main/java/org/apache/tamaya/consul/internal/ConsulMutableConfigurationBackend.java
+++ b/modules/integration/consul/src/main/java/org/apache/tamaya/consul/internal/ConsulMutableConfigurationBackend.java
@@ -18,19 +18,20 @@
*/
package org.apache.tamaya.consul.internal;
+import com.google.common.net.HostAndPort;
+import com.orbitz.consul.Consul;
+import com.orbitz.consul.KeyValueClient;
import org.apache.tamaya.consul.ConsulBackends;
import org.apache.tamaya.mutableconfig.spi.AbstractMutableConfigurationBackendSpiSpi;
import java.net.URI;
+import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
- * Change Request implementation based on etcd services. Etcd also supports a ttl to set values only for a defined
- * number of seconds {@code ttl}. This is also supported by this component by adding ttl as a key parameter, e.g.
- * {@code changeRequest.set("myTimedKey?ttl=30", "myValue");} will set a key {@code myTimedKey} valid only for
- * 30 seconds.
+ * Change Request implementation based on consul services.
*/
class ConsulMutableConfigurationBackend extends AbstractMutableConfigurationBackendSpiSpi {
@@ -42,15 +43,14 @@ class ConsulMutableConfigurationBackend extends AbstractMutableConfigurationBack
@Override
public boolean isExisting(String keyExpression) {
- for(EtcdAccessor accessor: ConsulBackends.getEtcdBackends()){
+ for(HostAndPort hostAndPort: ConsulBackends.getConsulBackends()){
try{
- Map<String,String> props = accessor.get(keyExpression);
- if(!props.containsKey("_ERROR")) {
- // No repfix mapping necessary here, since we only access/return the value...
- return props.get(keyExpression)!=null;
- }
+ Consul consul = Consul.builder().withHostAndPort(hostAndPort).build();
+ KeyValueClient kvClient = consul.keyValueClient();
+ List<String> keys = kvClient.getKeys(keyExpression);
+ return !keys.isEmpty();
} catch(Exception e){
- LOG.log(Level.FINE, "etcd access failed on " + accessor.getUrl() + ", trying next...", e);
+ LOG.log(Level.FINE, "consul access failed on " + hostAndPort + ", trying next...", e);
}
}
return false;
@@ -59,36 +59,28 @@ class ConsulMutableConfigurationBackend extends AbstractMutableConfigurationBack
@Override
protected void commitInternal() {
- for(EtcdAccessor accessor: ConsulBackends.getEtcdBackends()){
+ for(HostAndPort hostAndPort: ConsulBackends.getConsulBackends()){
try{
+ Consul consul = Consul.builder().withHostAndPort(hostAndPort).build();
+ KeyValueClient kvClient = consul.keyValueClient();
+
for(String k: getRemovedProperties()){
- Map<String,String> res = accessor.delete(k);
- if(res.get("_ERROR")!=null){
- LOG.info("Failed to remove key from etcd: " + k);
+ try{
+ kvClient.deleteKey(k);
+ } catch(Exception e){
+ LOG.info("Failed to remove key from consul: " + k);
}
}
for(Map.Entry<String,String> en: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 key from etcd: " + en.getKey() + "=" + en.getValue());
+ try{
+ kvClient.putValue(key,en.getValue());
+ }catch(Exception e) {
+ LOG.info("Failed to add key to consul: " + en.getKey() + "=" + en.getValue());
}
}
} catch(Exception e){
- LOG.log(Level.FINE, "etcd access failed on " + accessor.getUrl() + ", trying next...", e);
+ LOG.log(Level.FINE, "consul access failed on " + hostAndPort + ", trying next...", e);
}
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ffc59e03/modules/integration/consul/src/main/java/org/apache/tamaya/consul/internal/MutableConfigSupport.java
----------------------------------------------------------------------
diff --git a/modules/integration/consul/src/main/java/org/apache/tamaya/consul/internal/MutableConfigSupport.java b/modules/integration/consul/src/main/java/org/apache/tamaya/consul/internal/MutableConfigSupport.java
index 43dfb75..bc0fbf4 100644
--- a/modules/integration/consul/src/main/java/org/apache/tamaya/consul/internal/MutableConfigSupport.java
+++ b/modules/integration/consul/src/main/java/org/apache/tamaya/consul/internal/MutableConfigSupport.java
@@ -31,13 +31,13 @@ public class MutableConfigSupport implements MutableConfigurationBackendProvider
private URI backendURI;
public MutableConfigSupport(){
- backendURI = URI.create("config:etcd");
+ backendURI = URI.create("config:consul");
}
@Override
public MutableConfigurationBackendSpi getBackend(URI uri) {
if(backendURI.equals(uri)) {
- return new EtcdConfigChangeRequest(backendURI);
+ return new ConsulMutableConfigurationBackend(backendURI);
}
return null;
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ffc59e03/modules/integration/consul/src/main/resources/META-INF/services/org.apache.tamaya.mutableconfig.spi.MutableConfigurationBackendProviderSpi
----------------------------------------------------------------------
diff --git a/modules/integration/consul/src/main/resources/META-INF/services/org.apache.tamaya.mutableconfig.spi.MutableConfigurationBackendProviderSpi b/modules/integration/consul/src/main/resources/META-INF/services/org.apache.tamaya.mutableconfig.spi.MutableConfigurationBackendProviderSpi
index 2189807..9174018 100644
--- a/modules/integration/consul/src/main/resources/META-INF/services/org.apache.tamaya.mutableconfig.spi.MutableConfigurationBackendProviderSpi
+++ b/modules/integration/consul/src/main/resources/META-INF/services/org.apache.tamaya.mutableconfig.spi.MutableConfigurationBackendProviderSpi
@@ -16,4 +16,4 @@
# specific language governing permissions and limitations
# under the License.
#
-org.apache.tamaya.etcd.internal.MutableConfigSupport
\ No newline at end of file
+org.apache.tamaya.consul.internal.MutableConfigSupport
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ffc59e03/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
index eb7958e..4996059 100644
--- 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
@@ -16,4 +16,4 @@
# specific language governing permissions and limitations
# under the License.
#
-org.apache.tamaya.etcd.EtcdPropertySource
\ No newline at end of file
+org.apache.tamaya.consul.ConsulPropertySource
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ffc59e03/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
index 5d47738..8946a3c 100644
--- 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
@@ -36,7 +36,7 @@ public class ConsulPropertySourceTest {
@BeforeClass
public static void setup(){
- System.setProperty("etcd.server.urls", "http://8.8.8.8:4001,http://192.168.99.105:4001");
+ System.setProperty("consul.urls", "http://127.0.0.1:8300");
}
@Test
@@ -51,7 +51,7 @@ public class ConsulPropertySourceTest {
@Test
public void testGetName() throws Exception {
- assertEquals("etcd", propertySource.getName());
+ assertEquals("consul", propertySource.getName());
}
@Test
@@ -70,6 +70,6 @@ public class ConsulPropertySourceTest {
@Test
public void testIsScannable() throws Exception {
- assertTrue(propertySource.isScannable());
+ assertFalse(propertySource.isScannable());
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ffc59e03/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
index 4d94fe5..8901461 100644
--- 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
@@ -19,9 +19,14 @@
package org.apache.tamaya.etcd;
import com.google.common.net.HostAndPort;
+import org.apache.tamaya.consul.ConsulPropertySource;
+import org.apache.tamaya.consul.internal.MutableConfigSupport;
+import org.apache.tamaya.mutableconfig.spi.MutableConfigurationBackendSpi;
import org.junit.BeforeClass;
import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.util.Map;
import java.util.UUID;
@@ -35,60 +40,22 @@ public class ConsulWriteTest {
private static HostAndPort accessor;
static boolean execute = false;
+ private static ConsulPropertySource readingSource;
+ private static MutableConfigurationBackendSpi writer;
@BeforeClass
- public static void setup() throws MalformedURLException {
- accessor = new HostAndPort("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);
+ 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");
+ readingSource = new ConsulPropertySource();
+ writer = new MutableConfigSupport().getBackend(new URI("config:consul"));
}
@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;
+ 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"));
+ writer.put("testSetNormal", value);
}
@@ -96,22 +63,17 @@ public class ConsulWriteTest {
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"));
+ writer.put("testDelete", value);
+ assertEquals(readingSource.get("testDelete").get("testDelete"), value);
+ assertNotNull(readingSource.get("_testDelete.createdIndex"));
+ writer.remove("testDelete");
+ assertNull(readingSource.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"));
+ Map<String,String> result = readingSource.getProperties();
+ assertTrue(result.isEmpty());
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ffc59e03/modules/integration/pom.xml
----------------------------------------------------------------------
diff --git a/modules/integration/pom.xml b/modules/integration/pom.xml
index 4469452..08e38e5 100644
--- a/modules/integration/pom.xml
+++ b/modules/integration/pom.xml
@@ -39,6 +39,7 @@ under the License.
<module>osgi</module>
<module>camel</module>
<module>etcd</module>
+ <module>consul</module>
</modules>
</project>
\ No newline at end of file
[03/10] incubator-tamaya git commit: TAMAYA-71: Finished yaml support,
including tests.
Posted by an...@apache.org.
TAMAYA-71: Finished yaml support, including tests.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/60e8827f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/60e8827f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/60e8827f
Branch: refs/heads/master
Commit: 60e8827f2b332da68bbab26f1d325f44456d195d
Parents: 264a5f4
Author: anatole <an...@apache.org>
Authored: Sat Feb 27 21:53:31 2016 +0100
Committer: anatole <an...@apache.org>
Committed: Sat Feb 27 21:53:31 2016 +0100
----------------------------------------------------------------------
.../java/org/apache/tamaya/json/YAMLFormat.java | 122 +++++++++++++++----
.../apache/tamaya/json/YAMLPropertySource.java | 63 ++--------
.../org/apache/tamaya/json/YAMLFormatTest.java | 54 ++++----
.../tamaya/json/YAMLPropertySourceTest.java | 24 ++--
.../test/resources/configs/valid/contact.yaml | 19 ++-
.../resources/configs/valid/test-with-prio.yaml | 4 +
6 files changed, 162 insertions(+), 124 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/60e8827f/modules/yaml/src/main/java/org/apache/tamaya/json/YAMLFormat.java
----------------------------------------------------------------------
diff --git a/modules/yaml/src/main/java/org/apache/tamaya/json/YAMLFormat.java b/modules/yaml/src/main/java/org/apache/tamaya/json/YAMLFormat.java
index 8bdd414..20d52d1 100644
--- a/modules/yaml/src/main/java/org/apache/tamaya/json/YAMLFormat.java
+++ b/modules/yaml/src/main/java/org/apache/tamaya/json/YAMLFormat.java
@@ -22,19 +22,19 @@ import org.apache.tamaya.ConfigException;
import org.apache.tamaya.format.ConfigurationData;
import org.apache.tamaya.format.ConfigurationDataBuilder;
import org.apache.tamaya.format.ConfigurationFormat;
+import org.yaml.snakeyaml.Yaml;
import java.io.InputStream;
import java.net.URL;
-import java.nio.charset.Charset;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.Objects;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import static java.lang.String.format;
-import javax.json.Json;
-import javax.json.JsonException;
-import javax.json.JsonObject;
-import javax.json.JsonReader;
-import javax.json.JsonReaderFactory;
/**
* Implementation of the {@link org.apache.tamaya.format.ConfigurationFormat}
@@ -42,44 +42,114 @@ import javax.json.JsonReaderFactory;
*
* @see <a href="http://www.json.org">JSON format specification</a>
*/
-public class JSONFormat implements ConfigurationFormat {
- /** Property that make Johnzon accept commentc. */
- public static final String JOHNZON_SUPPORTS_COMMENTS_PROP = "org.apache.johnzon.supports-comments";
- /** The reader factory used. */
- private final JsonReaderFactory readerFactory;
+public class YAMLFormat implements ConfigurationFormat {
+ /**
+ * THe logger.
+ */
+ private static final Logger LOG = Logger.getLogger(YAMLFormat.class.getName());
/**
* Constructor, itniaitlizing zhe JSON reader factory.
*/
- public JSONFormat(){
- Map<String, Object> config = new HashMap<>();
- config.put(JOHNZON_SUPPORTS_COMMENTS_PROP, true);
- this.readerFactory = Json.createReaderFactory(config);
+ public YAMLFormat(){
}
@Override
public String getName() {
- return "json";
+ return "yaml";
}
@Override
public boolean accepts(URL url) {
- return Objects.requireNonNull(url).getPath().endsWith(".json");
+ return Objects.requireNonNull(url).getPath().endsWith(".yaml");
}
@Override
public ConfigurationData readConfiguration(String resource, InputStream inputStream) {
-
- try {
- final JsonReader reader = this.readerFactory.createReader(inputStream, Charset.forName("UTF-8"));
- JsonObject root = reader.readObject();
- HashMap<String, String> values = new HashMap<>();
- JSONVisitor visitor = new JSONVisitor(root, values);
- visitor.run();
+ try( InputStream in = inputStream;) {
+ Map<String, String> values = readConfig(resource, inputStream);
return ConfigurationDataBuilder.of(resource, this).addProperties(values)
- .build();
- } catch (JsonException e) {
+ .build();
+ } catch (Exception e) {
throw new ConfigException("Failed to read data from " + resource, e);
}
}
+
+ /**
+ * Reads the configuration.
+ * @param inputStream the input stream, not null.
+ * @return the configuration read from the given resource URL.
+ * @throws ConfigException if resource URL cannot be read.
+ */
+ protected Map<String, String> readConfig(String resource, InputStream inputStream) {
+ try{
+ Yaml yaml = new Yaml();
+ HashMap<String, String> values = new HashMap<>();
+ Object config = yaml.load(inputStream);
+ mapYamlIntoProperties(config, values);
+ if(LOG.isLoggable(Level.FINEST)){
+ LOG.finest("Read data from " + resource + " : " + values);
+ }
+ return values;
+ }catch (Throwable t) {
+ throw new ConfigException(format("Failed to read properties from %s", resource), t);
+ }
+ }
+ /**
+ * Reads the configuration.
+ * @param urlResource soure of the configuration.
+ * @return the configuration read from the given resource URL.
+ * @throws ConfigException if resource URL cannot be read.
+ */
+ protected Map<String, String> readConfig(URL urlResource) {
+ try (InputStream is = urlResource.openStream()) {
+ return readConfig(urlResource.toExternalForm(), is);
+ }
+ catch (Throwable t) {
+ throw new ConfigException(format("Failed to read properties from %s", urlResource.toExternalForm()), t);
+ }
+ }
+
+ private void mapYamlIntoProperties(Object config, HashMap<String, String> values) {
+ mapYamlIntoProperties("", config, values);
+ }
+
+ /**
+ * Maps the given config item (could be a String, a collection type or something else returned by the yaml parser
+ * to a key/value pair and adds it to {@code values} (hereby honoring the prefix as a key to be used.).
+ * Collection types are recursively to remapped hereby extending the given prefix as needed and recursively
+ * delegate mapping of values contained.
+ * @param prefix the prefix or key evaluated so far, never null (but can be empty for root entries).
+ * @param config the config value. Could be a single value or a collection type.
+ * @param values the properties where items identified must be written into. These properties are going to be
+ * returned as result of the format reading operation ans integrated into the overall configuration
+ * map.
+ */
+ protected void mapYamlIntoProperties(String prefix, Object config, HashMap<String, String> values) {
+ // add further data types supported by yaml, e.g. date, ...
+ if(config instanceof List){
+ StringBuilder b = new StringBuilder();
+ for(Object val:((List<Object>)config)){
+ b.append(mapValueToString(val));
+ b.append(",");
+ }
+ if(b.length()>0){
+ b.setLength(b.length()-1);
+ }
+ values.put(prefix, b.toString());
+ values.put("_"+prefix+".collection-type", "List");
+ } else if(config instanceof Map){
+ for(Map.Entry<String,Object> en:((Map<String,Object>)config).entrySet()){
+ String newPrefix = prefix.isEmpty()?en.getKey():prefix +"."+en.getKey();
+ mapYamlIntoProperties(newPrefix, en.getValue(), values);
+ }
+ } else{
+ values.put(prefix, mapValueToString(config));
+ }
+ }
+
+ protected String mapValueToString(Object val) {
+ return String.valueOf(val);
+ }
+
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/60e8827f/modules/yaml/src/main/java/org/apache/tamaya/json/YAMLPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/yaml/src/main/java/org/apache/tamaya/json/YAMLPropertySource.java b/modules/yaml/src/main/java/org/apache/tamaya/json/YAMLPropertySource.java
index 43cfa73..e29d2e7 100644
--- a/modules/yaml/src/main/java/org/apache/tamaya/json/YAMLPropertySource.java
+++ b/modules/yaml/src/main/java/org/apache/tamaya/json/YAMLPropertySource.java
@@ -18,55 +18,34 @@
*/
package org.apache.tamaya.json;
-import org.apache.tamaya.ConfigException;
import org.apache.tamaya.spi.PropertySource;
import org.apache.tamaya.spi.PropertyValue;
-import java.io.InputStream;
import java.net.URL;
-import java.nio.charset.Charset;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Objects;
+import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
-import javax.json.Json;
-import javax.json.JsonObject;
-import javax.json.JsonReaderFactory;
-import javax.json.JsonStructure;
-import static java.lang.String.format;
/**
* Property source based on a JSON file.
*/
-public class JSONPropertySource implements PropertySource {
- /** Constant for enabling comments in Johnzon. */
- public static final String JOHNZON_SUPPORTS_COMMENTS_PROP = "org.apache.johnzon.supports-comments";
-
+public class YAMLPropertySource implements PropertySource {
/** The underlying resource. */
private final URL urlResource;
/** The values read. */
private final Map<String, String> values;
/** The evaluated ordinal. */
private int ordinal;
- /** The JSON reader factory used. */
- private JsonReaderFactory readerFactory = initReaderFactory();
-
- /** Initializes the factory to be used for creating readers. */
- private JsonReaderFactory initReaderFactory() {
- Map<String, Object> config = new HashMap<>();
- config.put(JOHNZON_SUPPORTS_COMMENTS_PROP, true);
- return Json.createReaderFactory(config);
- }
+ /** The format implementation used for parsing. */
+ private YAMLFormat format = new YAMLFormat();
/**
* Constructor, hereby using 0 as the default ordinal.
* @param resource the resource modelled as URL, not null.
*/
- public JSONPropertySource(URL resource) {
+ public YAMLPropertySource(URL resource) {
this(resource, 0);
}
@@ -75,19 +54,15 @@ public class JSONPropertySource implements PropertySource {
* @param resource the resource modelled as URL, not null.
* @param defaultOrdinal the defaultOrdinal to be used.
*/
- public JSONPropertySource(URL resource, int defaultOrdinal) {
+ public YAMLPropertySource(URL resource, int defaultOrdinal) {
urlResource = Objects.requireNonNull(resource);
this.ordinal = defaultOrdinal; // may be overriden by read...
- this.values = readConfig(urlResource);
+ this.values = format.readConfig(urlResource);
if (this.values.containsKey(TAMAYA_ORDINAL)) {
this.ordinal = Integer.parseInt(this.values.get(TAMAYA_ORDINAL));
}
- Map<String, Object> config = new HashMap<>();
- config.put(JOHNZON_SUPPORTS_COMMENTS_PROP, true);
- this.readerFactory = Json.createReaderFactory(config);
}
-
@Override
public int getOrdinal() {
PropertyValue configuredOrdinal = get(TAMAYA_ORDINAL);
@@ -117,30 +92,6 @@ public class JSONPropertySource implements PropertySource {
return Collections.unmodifiableMap(values);
}
- /**
- * Reads the configuration.
- * @param urlResource soure of the configuration.
- * @return the configuration read from the given resource URL.
- * @throws ConfigException if resource URL cannot be read.
- */
- protected Map<String, String> readConfig(URL urlResource) {
- try (InputStream is = urlResource.openStream()) {
- JsonStructure root = this.readerFactory.createReader(is, Charset.forName("UTF-8")).read();
-
- // Test added. H. Saly, 15. Aug. 2015
- if (!(root instanceof JsonObject)) {
- throw new ConfigException("Currently only JSON objects are supported");
- }
-
- Map<String, String> values = new HashMap<>();
- JSONVisitor visitor = new JSONVisitor((JsonObject)root, values);
- visitor.run();
- return values;
- }
- catch (Throwable t) {
- throw new ConfigException(format("Failed to read properties from %s", urlResource.toExternalForm()), t);
- }
- }
@Override
public boolean isScannable() {
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/60e8827f/modules/yaml/src/test/java/org/apache/tamaya/json/YAMLFormatTest.java
----------------------------------------------------------------------
diff --git a/modules/yaml/src/test/java/org/apache/tamaya/json/YAMLFormatTest.java b/modules/yaml/src/test/java/org/apache/tamaya/json/YAMLFormatTest.java
index dc24048..0f0e589 100644
--- a/modules/yaml/src/test/java/org/apache/tamaya/json/YAMLFormatTest.java
+++ b/modules/yaml/src/test/java/org/apache/tamaya/json/YAMLFormatTest.java
@@ -24,52 +24,50 @@ import org.apache.tamaya.format.FlattenedDefaultPropertySource;
import org.apache.tamaya.spi.PropertySource;
import org.junit.Test;
+import java.io.IOException;
import java.io.InputStream;
+import java.net.MalformedURLException;
import java.net.URL;
+import java.util.Map;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
-public class YAMLFormatTest extends CommonJSONTestCaseCollection {
- private final JSONFormat format = new JSONFormat();
-
- @Test(expected = NullPointerException.class)
- public void acceptsNeedsNonNullParameter() throws Exception {
- format.accepts(null);
- }
+public class YAMLFormatTest {
+ private final YAMLFormat format = new YAMLFormat();
@Test
- public void aNonJSONFileBasedURLIsNotAccepted() throws Exception {
- URL url = new URL("file:///etc/service/conf.conf");
-
- assertThat(format.accepts(url), is(false));
+ public void testAcceptURL() throws MalformedURLException {
+ assertTrue(format.accepts(new URL("http://127.0.0.1/anyfile.yaml")));
}
@Test
- public void aJSONFileBasedURLIsAccepted() throws Exception {
- URL url = new URL("file:///etc/service/conf.json");
-
- assertThat(format.accepts(url), is(true));
+ public void testAcceptURL_BC1() throws MalformedURLException {
+ assertFalse(format.accepts(new URL("http://127.0.0.1/anyfile.YAML")));
}
- @Test
- public void aHTTPBasedURLIsNotAccepted() throws Exception {
- URL url = new URL("http://nowhere.somewhere/conf.json");
- assertThat(format.accepts(url), is(true));
+ @Test(expected = NullPointerException.class)
+ public void testAcceptURL_BC2() throws MalformedURLException {
+ assertFalse(format.accepts(null));
}
@Test
- public void aFTPBasedURLIsNotAccepted() throws Exception {
- URL url = new URL("ftp://nowhere.somewhere/a/b/c/d/conf.json");
-
- assertThat(format.accepts(url), is(true));
+ public void testAcceptURL_BC3() throws MalformedURLException {
+ assertFalse(format.accepts(new URL("http://127.0.0.1/anyfile.docx")));
}
- @Override
- PropertySource getPropertiesFrom(URL source) throws Exception {
- try (InputStream is = source.openStream()) {
- ConfigurationData data = format.readConfiguration(source.toString(), is);
- return new FlattenedDefaultPropertySource(data);
+ @Test
+ public void testRead() throws IOException {
+ URL configURL = YAMLPropertySourceTest.class.getResource("/configs/valid/contact.yaml");
+ assertTrue(format.accepts(configURL));
+ ConfigurationData data = format.readConfiguration(configURL.toString(), configURL.openStream());
+ assertNotNull(data);
+ for(Map.Entry<String,String> en:data.getDefaultProperties().entrySet()) {
+ System.out.println(en.getKey() + " -> " + en.getValue());
}
}
+
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/60e8827f/modules/yaml/src/test/java/org/apache/tamaya/json/YAMLPropertySourceTest.java
----------------------------------------------------------------------
diff --git a/modules/yaml/src/test/java/org/apache/tamaya/json/YAMLPropertySourceTest.java b/modules/yaml/src/test/java/org/apache/tamaya/json/YAMLPropertySourceTest.java
index a15f553..7f1c7a3 100644
--- a/modules/yaml/src/test/java/org/apache/tamaya/json/YAMLPropertySourceTest.java
+++ b/modules/yaml/src/test/java/org/apache/tamaya/json/YAMLPropertySourceTest.java
@@ -28,29 +28,27 @@ import java.net.URL;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
-public class YAMLPropertySourceTest extends CommonJSONTestCaseCollection {
+public class YAMLPropertySourceTest {
@Test
- public void tamayaOrdinalKeywordIsNotPropagatedAsNormalProperty() throws Exception {
- URL configURL = YAMLPropertySourceTest.class.getResource("/configs/valid/with-explicit-priority.json");
+ public void testYamlWithOrdinal() throws Exception {
+ URL configURL = YAMLPropertySourceTest.class.getResource("/configs/valid/test-with-prio.yaml");
assertThat(configURL, CoreMatchers.notNullValue());
- JSONPropertySource source = new JSONPropertySource(configURL, 4);
- assertEquals(source.get(PropertySource.TAMAYA_ORDINAL).getValue(), "16784");
+ YAMLPropertySource source = new YAMLPropertySource(configURL, 4);
+ assertEquals(source.getOrdinal(), 16784);
}
- @Test(expected=ConfigException.class)
- public void testDoNotAcceptJsonArrays() throws Exception {
- URL configURL = YAMLPropertySourceTest.class.getResource("/configs/invalid/array.json");
+ @Test
+ public void testYamlDefaultOrdinal() throws Exception {
+ URL configURL = YAMLPropertySourceTest.class.getResource("/configs/valid/test.yaml");
assertThat(configURL, CoreMatchers.notNullValue());
- new JSONPropertySource(configURL);
+ YAMLPropertySource source = new YAMLPropertySource(configURL, 4);
+ assertEquals(source.getOrdinal(), 4);
}
- @Override
- PropertySource getPropertiesFrom(URL source) throws Exception {
- return new JSONPropertySource(source);
- }
+
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/60e8827f/modules/yaml/src/test/resources/configs/valid/contact.yaml
----------------------------------------------------------------------
diff --git a/modules/yaml/src/test/resources/configs/valid/contact.yaml b/modules/yaml/src/test/resources/configs/valid/contact.yaml
index 32eca23..95d5a03 100644
--- a/modules/yaml/src/test/resources/configs/valid/contact.yaml
+++ b/modules/yaml/src/test/resources/configs/valid/contact.yaml
@@ -1,4 +1,21 @@
--- !clarkevans.com/^invoice
+#
+# 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.
+#
invoice: 34843
date : 2001-01-23
bill-to: &id001
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/60e8827f/modules/yaml/src/test/resources/configs/valid/test-with-prio.yaml
----------------------------------------------------------------------
diff --git a/modules/yaml/src/test/resources/configs/valid/test-with-prio.yaml b/modules/yaml/src/test/resources/configs/valid/test-with-prio.yaml
index 697e9f3..05b5dbf 100644
--- a/modules/yaml/src/test/resources/configs/valid/test-with-prio.yaml
+++ b/modules/yaml/src/test/resources/configs/valid/test-with-prio.yaml
@@ -19,6 +19,10 @@
version: 1.0
released: 2012-11-30
+# tamaya specifics...
+tamaya:
+ ordinal: 16784
+
# Connection parameters
connection:
url: jdbc:mysql://localhost:3306/db
[05/10] incubator-tamaya git commit: TAMAYA-71: Added yaml module doc
and module pom.
Posted by an...@apache.org.
TAMAYA-71: Added yaml module doc and module pom.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/efe45e5a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/efe45e5a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/efe45e5a
Branch: refs/heads/master
Commit: efe45e5a3a7a9289285e554100acd8ce2e70bc87
Parents: ffc59e0
Author: anatole <an...@apache.org>
Authored: Sat Feb 27 21:57:19 2016 +0100
Committer: anatole <an...@apache.org>
Committed: Sat Feb 27 21:57:19 2016 +0100
----------------------------------------------------------------------
modules/yaml/pom.xml | 44 ++----------
src/site/asciidoc/extensions/mod_yaml.adoc | 95 +++++++++++++++++++------
2 files changed, 79 insertions(+), 60 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/efe45e5a/modules/yaml/pom.xml
----------------------------------------------------------------------
diff --git a/modules/yaml/pom.xml b/modules/yaml/pom.xml
index 670516c..f659efb 100644
--- a/modules/yaml/pom.xml
+++ b/modules/yaml/pom.xml
@@ -26,13 +26,14 @@ under the License.
<version>0.2-incubating-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
- <artifactId>tamaya-json</artifactId>
- <name>Apache Tamaya Modules - JSON Support</name>
+ <artifactId>tamaya-yaml</artifactId>
+ <name>Apache Tamaya Modules - YAML Support</name>
<packaging>bundle</packaging>
- <inceptionYear>2015</inceptionYear>
+ <inceptionYear>2016</inceptionYear>
<properties>
<jdkVersion>1.7</jdkVersion>
+ <snakeyaml.version>1.17</snakeyaml.version>
</properties>
<dependencies>
@@ -56,46 +57,15 @@ under the License.
<version>${project.version}</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>
+ <groupId>org.yaml</groupId>
+ <artifactId>snakeyaml</artifactId>
+ <version>${snakeyaml.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
- <groupId>org.jboss.arquillian.daemon</groupId>
- <artifactId>arquillian-daemon-container-managed</artifactId>
- </dependency>
- <dependency>
- <groupId>org.jboss.arquillian.daemon</groupId>
- <artifactId>arquillian-daemon-container-common</artifactId>
- </dependency>
- <dependency>
- <groupId>org.jboss.arquillian.daemon</groupId>
- <artifactId>arquillian-daemon-main</artifactId>
- </dependency>
- <dependency>
- <groupId>org.jboss.arquillian.daemon</groupId>
- <artifactId>arquillian-daemon-protocol-arquillian</artifactId>
- </dependency>
- <dependency>
- <groupId>org.jboss.arquillian.daemon</groupId>
- <artifactId>arquillian-daemon-protocol-wire</artifactId>
- </dependency>
- <dependency>
- <groupId>org.jboss.arquillian.daemon</groupId>
- <artifactId>arquillian-daemon-server</artifactId>
- </dependency>
- <dependency>
- <groupId>org.jboss.arquillian.junit</groupId>
- <artifactId>arquillian-junit-container</artifactId>
- </dependency>
- <dependency>
<groupId>org.hamcrest</groupId>
<artifactId>java-hamcrest</artifactId>
</dependency>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/efe45e5a/src/site/asciidoc/extensions/mod_yaml.adoc
----------------------------------------------------------------------
diff --git a/src/site/asciidoc/extensions/mod_yaml.adoc b/src/site/asciidoc/extensions/mod_yaml.adoc
index edb66ad..f5560b9 100644
--- a/src/site/asciidoc/extensions/mod_yaml.adoc
+++ b/src/site/asciidoc/extensions/mod_yaml.adoc
@@ -18,11 +18,11 @@
= Apache Tamaya -- Extension: Builder
:name: Tamaya
-:rootpackage: org.apache.tamaya.builder
-:title: Apache Tamaya Extension: JSON
-:revnumber: 0.1.1
+:rootpackage: org.apache.tamaya.yaml
+:title: Apache Tamaya Extension: YAML
+:revnumber: 0.1
:revremark: Incubator
-:revdate: March 2015
+:revdate: March 2016
:longversion: {revnumber} ({revremark}) {revdate}
:authorinitials: ATR
:author: Anatole Tresch
@@ -59,15 +59,16 @@ toc::[]
:numbered!:
<<<
[[BuilderCore]]
-== Tamaya JSON (Extension Module)
+== Tamaya YAML (Extension Module)
=== Overview
-The Tamaya json module provides support for reading configuration using the JSON format:
+The Tamaya YAML module provides support for reading configuration using the YAML format (yaml.org). YAML hereby
+use intendation for expressing hierarchy, which makes yaml configuration files very easily readable and compact.
=== Compatibility
-The module is based on Java 7, so it will not run on Java 7 and beyond.
+The YAML module is based on Java 7, so it will not run on Java 7 and beyond.
=== Installation
@@ -78,38 +79,86 @@ To benefit from configuration builder support you only must add the correspondin
-----------------------------------------------
<dependency>
<groupId>org.apache.tamaya.ext</groupId>
- <artifactId>tamaya-json</artifactId>
+ <artifactId>tamaya-yaml</artifactId>
<version>{tamayaVersion}</version>
</dependency>
-----------------------------------------------
-=== Reading configuration in JSON
+=== Reading configuration in YAML
-For reading JSON based onfiguration most easily a +JSONFormat+ can be provided:
+For reading YAML based onfiguration most easily a +YAMLFormat+ can be provided:
[source, java]
-----------------------------------------------
ConfigurationData dataRead = ConfigurationFormats.readConfig(
- getClassLoader().getResource("myFileConfig.json"), new JSonFOrmat()));
+ getClassLoader().getResource("myFileConfig.yaml"), new YAMLFormat()));
-----------------------------------------------
=== Examples
-The JSON module adds instances of +ConfigurationFormat+ so JSON configuration can be read and mapped to the
-according property maps. E.g. the following file is a simple and correct JSON configuration:
+The YAML module adds instances of +ConfigurationFormat+ so YAML configuration can be read and mapped to the
+according property values. E.g. the following file is a simple and correct YAML configuration:
-[source,listing]
+[source,yaml]
----------------------------------------------------------------
-{
- "a" : "A",
- "b" : "B",
- "c" : "C",
- "d" : {
- "o" : "O",
- "p" : "P"
- }
-}
+invoice: 34843
+date : 2001-01-23
+bill-to: &id001
+ given : Chris
+ family : Dumars
+ address:
+ lines: |
+ 458 Walkman Dr.
+ Suite #292
+ city : Royal Oak
+ state : MI
+ postal : 48046
+ship-to: *id001
+product:
+ - sku : BL394D
+ quantity : 4
+ description : Basketball
+ price : 450.00
+ - sku : BL4438H
+ quantity : 1
+ description : Super Hoop
+ price : 2392.00
+tax : 251.42
+total: 4443.52
+comments:
+ Late afternoon is best.
+ Backup contact is Nancy
+ Billsmer @ 338-4338.
----------------------------------------------------------------
+Hereby the above file, by default is mapped as follows into +Map<String,String>+ typed properties:
+
+[source,listing]
+----------------------------------------------------------------
+invoice -> 34843
+date -> Tue Jan 23 01:00:00 CET 2001
+bill-to.family -> Dumars
+bill-to.given -> Chris
+bill-to.address.state -> MI
+bill-to.address.postal -> 48046
+bill-to.address.city -> Royal Oak
+bill-to.address.lines -> 458 Walkman Dr.
+Suite #292
+
+ship-to.given -> Chris
+ship-to.address.state -> MI
+ship-to.family -> Dumars
+ship-to.address.postal -> 48046
+ship-to.address.city -> Royal Oak
+ship-to.address.lines -> 458 Walkman Dr.
+Suite #292
+
+product -> {sku=BL394D, quantity=4, description=Basketball, price=450.0},{sku=BL4438H, quantity=1, description=Super Hoop, price=2392.0}
+_product.collection-type -> List
+
+tax -> 251.42
+total -> 4443.52
+comments -> Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338.
+----------------------------------------------------------------
[06/10] incubator-tamaya git commit: Fixed tests.
Posted by an...@apache.org.
Fixed tests.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/e82b26cf
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/e82b26cf
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/e82b26cf
Branch: refs/heads/master
Commit: e82b26cf523577889525d41a90f0c3aee78b9cf6
Parents: efe45e5
Author: anatole <an...@apache.org>
Authored: Sat Feb 27 21:58:16 2016 +0100
Committer: anatole <an...@apache.org>
Committed: Sat Feb 27 21:58:16 2016 +0100
----------------------------------------------------------------------
.../internal/PropertiesFileConfigBackendTest.java | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/e82b26cf/modules/mutable-config/src/test/java/org/apache/tamaya/mutableconfig/internal/PropertiesFileConfigBackendTest.java
----------------------------------------------------------------------
diff --git a/modules/mutable-config/src/test/java/org/apache/tamaya/mutableconfig/internal/PropertiesFileConfigBackendTest.java b/modules/mutable-config/src/test/java/org/apache/tamaya/mutableconfig/internal/PropertiesFileConfigBackendTest.java
index a4fe1f2..78a6379 100644
--- a/modules/mutable-config/src/test/java/org/apache/tamaya/mutableconfig/internal/PropertiesFileConfigBackendTest.java
+++ b/modules/mutable-config/src/test/java/org/apache/tamaya/mutableconfig/internal/PropertiesFileConfigBackendTest.java
@@ -50,7 +50,7 @@ public class PropertiesFileConfigBackendTest {
Map<String,String> cm = new HashMap<>();
cm.put("key2", "value2");
cm.put("key3", "value3");
- req.rollback();;
+ req.rollback();
assertFalse(f.exists());
}
@@ -70,7 +70,7 @@ public class PropertiesFileConfigBackendTest {
cm.put("key2", "value2");
cm.put("key3", "value3");
req.putAll(cm);
- req.commit();;
+ req.commit();
assertTrue(f.exists());
MutableConfiguration req2 = ConfigurationProvider.getConfiguration().query(
MutableConfigurationQuery.of(f.toURI()));
@@ -104,7 +104,7 @@ public class PropertiesFileConfigBackendTest {
cm.put("key2", "value2");
cm.put("key3", "value3");
req.putAll(cm);
- req.commit();;
+ req.commit();
assertTrue(f.exists());
MutableConfiguration req2 = ConfigurationProvider.getConfiguration().query(
MutableConfigurationQuery.of(f.toURI()));
@@ -135,7 +135,7 @@ public class PropertiesFileConfigBackendTest {
cm.put("key2", "value2");
cm.put("key3", "value3");
req.putAll(cm);
- req.commit();;
+ req.commit();
assertTrue(f1.exists());
assertTrue(f2.exists());
MutableConfiguration req2 = ConfigurationProvider.getConfiguration().query(
[08/10] incubator-tamaya git commit: TAMAYA-143: Added docs for
consul support.
Posted by an...@apache.org.
TAMAYA-143: Added docs for consul support.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/b3535cef
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/b3535cef
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/b3535cef
Branch: refs/heads/master
Commit: b3535cef3541120eac3577652bfabae25b37d469
Parents: 2dfa4d8
Author: anatole <an...@apache.org>
Authored: Sat Feb 27 21:59:54 2016 +0100
Committer: anatole <an...@apache.org>
Committed: Sat Feb 27 21:59:54 2016 +0100
----------------------------------------------------------------------
src/site/asciidoc/extensions/mod_consul.adoc | 172 +++-------------------
1 file changed, 21 insertions(+), 151 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b3535cef/src/site/asciidoc/extensions/mod_consul.adoc
----------------------------------------------------------------------
diff --git a/src/site/asciidoc/extensions/mod_consul.adoc b/src/site/asciidoc/extensions/mod_consul.adoc
index 1a0d1f6..497da89 100644
--- a/src/site/asciidoc/extensions/mod_consul.adoc
+++ b/src/site/asciidoc/extensions/mod_consul.adoc
@@ -15,12 +15,12 @@
// specific language governing permissions and limitations
// under the License.
-= Apache Tamaya -- Extension: Integration with etcd (Core OS)
+= Apache Tamaya -- Extension: Integration with consul (Hashicorp)
:name: Tamaya
-:rootpackage: org.apache.tamaya.integration.etcd
-:title: Apache Tamaya Extension: Integration with etcd service
-:revdate: January 2016
+:rootpackage: org.apache.tamaya.integration.consul
+:title: Apache Tamaya Extension: Integration with consul service
+:revdate: February 2016
:authorinitials: ATR
:author: Anatole Tresch
:email: <an...@apache.org>
@@ -41,11 +41,11 @@ toc::[]
:numbered!:
<<<
[[Optional]]
-== Integration with etcd (Extension Module)
+== Integration with consul (Extension Module)
=== Overview
-The Tamaya etcd integration module provides different artifacts which allows integration of Apachae Tamaya
-configuration with etcd. Basically the module supports read-only integration (as a +EtcdPropertySource+ as well
+The Tamaya consul integration module provides different artifacts which allows integration of Apachae Tamaya
+configuration with consul. Basically the module supports read-only integration (as a +ConsulPropertySource+ as well
as a support for +MutableConfiguration+ as defined by the +tamaya-mutable-config+ extension module.
@@ -62,7 +62,7 @@ To benefit from configuration builder support you only must add the correspondin
-----------------------------------------------
<dependency>
<groupId>org.apache.tamaya.ext</groupId>
- <artifactId>tamaya-etcd</artifactId>
+ <artifactId>tamaya-consul</artifactId>
<version>{tamayaVersion}</version>
</dependency>
-----------------------------------------------
@@ -70,154 +70,24 @@ To benefit from configuration builder support you only must add the correspondin
=== The Extensions Provided
-ETcd integration comes basically with 2 artifacts:
+Consul integration comes basically with 2 artifacts:
-* The +org.apache.tamaya.etcd.EtcdAccessor+ can be configured with a an url targeting an etcd server's REST endpoint root.
- (+org.apache.tamaya.etcd.EtcdAccessor+). The accessor basically provides a simple Java API for communicating
- with etcd server. The accessor hereby allows reading of single properties, or whole subtrees. Also the basic non
- atomic write methods are implemented.
-* The +org.apache.tamaya.etcd.EtcdPropertySource+ is a +PropertySource+ with a default ordinal of 100 and the name
- 'etcd', which is automatically registered.
-* If the +tamaya-mutable-config+ module is loaded it is possible to write property values back into the etcd cluster,
- by accessing a +MutableConfiguration+ using the URI +config:etcd+.
+* The +org.apache.tamaya.etcd.ConsulPropertySource+ is a +PropertySource+ with a default ordinal of 100 and the name
+ 'consul', which is automatically registered.
+* If the +tamaya-mutable-config+ module is loaded it is possible to write property values back into the consul cluster,
+ by accessing a +MutableConfiguration+ using the URI +config:consul+.
-=== The EtcdAccessor
-The accessor mentioned implements the basic read and write API for communicating with an etcd configuration cluster.
-Hereby the accessor also provides etcd specific data such as +createdIndex, modifiedIndex, ttl+ in the +Map+
-returned. Hereby the concept of etcd is used where keys starting with an '_' will be hidden from the overall
-properties map, being only directly/explicitly accessible:
+=== The ConsulPropertySource
-[source, java]
------------------------------------------------
-public class EtcdAccessor {
-
- /**
- * Creates a new instance with the basic access url.
- * @param server server url, e.g. {@code http://127.0.0.1:4001}.
- * @throws MalformedURLException
- */
- public EtcdAccessor(String server) throws MalformedURLException;
-
- /**
- * Get the etcd server version.
- * @return the etcd server version, never null.
- */
- public String getVersion();
-
- /**
- * Ask etcd for s aingle key, value pair. Hereby the response returned from etcd:
- * <pre>
- * key=value
- * _key.source=[etcd]http://127.0.0.1:4001
- * _key.createdIndex=12
- * _key.modifiedIndex=34 // optional
- * _key.ttl=300 // optional
- * _key.expiration=... // optional
- * </pre>
- * @param key the requested key
- * @return the mapped result, including meta-entries.
- */
- public Map<String,String> get(String key);
-
- /**
- * Creates/updates an entry in etcd without any ttl set.
- * The response is as follows:
- * <pre>
- * key=value
- * _key.source=[etcd]http://127.0.0.1:4001
- * _key.createdIndex=12
- * _key.modifiedIndex=34 // optional
- * _key.prevNode.createdIndex=12 // optional
- * _key.prevNode.modifiedIndex=34 // optional
- * </pre>
- * @param key the property key, not null
- * @param value the value to be set
- * @return the result map as described above.
- */
- public Map<String,String> set(String key, String value);
-
- /**
- * Creates/updates an entry in etcd. The response is as follows:
- * <pre>
- * key=value
- * _key.source=[etcd]http://127.0.0.1:4001
- * _key.createdIndex=12
- * _key.modifiedIndex=34 // optional
- * _key.ttl=300 // optional
- * _key.expiry=... // optional
- * _key.prevNode.createdIndex=12 // optional
- * _key.prevNode.modifiedIndex=34 // optional
- * _key.prevNode.ttl=300 // optional
- * _key.prevNode.expiration=... // optional
- * </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);
-
-
- /**
- * 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 // optional
- * _key.expiry=... // optional
- * _key.prevNode.createdIndex=12 // optional
- * _key.prevNode.modifiedIndex=34 // optional
- * _key.prevNode.ttl=300 // optional
- * _key.prevNode.expiration=... // optional
- * _key.prevNode.value=... // optional
- * </pre>
- * @param key the key to be deleted.
- * @return the response mpas as described above.
- */
- public Map<String,String> delete(String key);
-
-
- /**
- * Access regular Tamaya properties map as follows:
- * <pre>
- * key1=myvalue
- * _key1.source=[etcd]http://127.0.0.1:4001
- * _key1.createdIndex=12
- * _key1.modifiedIndex=34 // optional
- * _key1.ttl=300 // optional
- * _key1.expiration=... // optional
- *
- * 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>
- */
- public Map<String,String> getProperties(String directory, boolean recursive);
-
-}
------------------------------------------------
-
-
-=== The EtcdPropertySource
-
-The +EtcdPropertySource+ is automatically registered and requires the etcd servers to be used to be configured. This
+The +ConsulPropertySource+ is automatically registered and allows the consul servers to be used to be configured. This
enables to use e.g. in Docker environments the docker environment configuration mechanisms to configure Tamaya running
-in microservice containers to connect with the according etcd container cluster:
+in microservice containers to connect with the according consul cluster:
-* The property source reads the +tamaya.etcd.server.urls+ system property to evaluate possible etcd servers
+* The property source reads the +tamaya.consul.urls+ system and environment property to evaluate possible etcd servers
(comma separated), which can be connected to. On error the API just performs a Round-Robin through the list of
- configured servers. Without any configuration +http://127.0.0.1:4001+ is used. If no connection to any etcd
+ configured servers. Without any configuration +http://127.0.0.1:2400+ is used. If no connection to any consul
server can be established a warning will be logged, but deployment will not fail.
-* Additinoally also the
- accessor allows to configure the socket/connection timeouts by setting +tamaya.etcd.timeout+ in seconds either as
- system or environment property.
-* The +EtcdPropertySource+ finally also allows the values read from the etcd cluster to be mapped to prefixed
- context. This can be activated by setting the +-Dtamaya.etcd.prefix=<PREFIX>+ system property. E.g. when the prefix is
- set to +cluster-config.+ a etcd key of +host:known/all+ is mapped to +cluster-config.host:known/all+.
\ No newline at end of file
+* The +ConsulPropertySource+ finally also allows the values read from the consul cluster to be mapped to prefixed
+ context. This can be activated by setting the +-Dtamaya.consul.prefix=<PREFIX>+ system property. E.g. when the prefix is
+ set to +cluster-config.+ a consul key of +host:known/all+ is mapped to +cluster-config.host:known/all+.
\ No newline at end of file
[09/10] incubator-tamaya git commit: Fixed minor issues.
Posted by an...@apache.org.
Fixed minor issues.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/1c454d5e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/1c454d5e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/1c454d5e
Branch: refs/heads/master
Commit: 1c454d5e187c0acd63e0723a91de14eba0081683
Parents: b3535ce
Author: anatole <an...@apache.org>
Authored: Sat Feb 27 22:00:36 2016 +0100
Committer: anatole <an...@apache.org>
Committed: Sat Feb 27 22:00:36 2016 +0100
----------------------------------------------------------------------
src/site/asciidoc/extensions/mod_etcd.adoc | 18 ++++++--------
src/site/asciidoc/extensions/mod_json.adoc | 4 +--
.../asciidoc/extensions/mod_mutable_config.adoc | 26 ++++++++++++--------
3 files changed, 26 insertions(+), 22 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/1c454d5e/src/site/asciidoc/extensions/mod_etcd.adoc
----------------------------------------------------------------------
diff --git a/src/site/asciidoc/extensions/mod_etcd.adoc b/src/site/asciidoc/extensions/mod_etcd.adoc
index 2c8b5a6..d7fc70f 100644
--- a/src/site/asciidoc/extensions/mod_etcd.adoc
+++ b/src/site/asciidoc/extensions/mod_etcd.adoc
@@ -45,10 +45,8 @@ toc::[]
=== Overview
The Tamaya etcd integration module provides different artifacts which allows integration of Apachae Tamaya
-configuration with etcd. Basically the module supports read-only integration.
-
-NOTE: The etcd backend itself also has methods that allow writing to the etcd cluster back. Once Tamaya's writable
- feature will be ready for broader usage (currently it is in the sandbox).
+configuration with etcd. Basically the module supports read-only integration (as a +EtcdPropertySource+ as well
+as a support for +MutableConfiguration+ as defined by the +tamaya-mutable-config+ extension module.
=== Compatibility
@@ -78,10 +76,10 @@ ETcd integration comes basically with 2 artifacts:
(+org.apache.tamaya.etcd.EtcdAccessor+). The accessor basically provides a simple Java API for communicating
with etcd server. The accessor hereby allows reading of single properties, or whole subtrees. Also the basic non
atomic write methods are implemented.
-* The +org.apache.tamaya.etcd.EtcdPropertySource+ is a +PropertySource+ with a default ordinal of 100 and the name 'etcd', which is
- automatically registered.
+* The +org.apache.tamaya.etcd.EtcdPropertySource+ is a +PropertySource+ with a default ordinal of 100 and the name
+ 'etcd', which is automatically registered.
* If the +tamaya-mutable-config+ module is loaded it is possible to write property values back into the etcd cluster,
- by accessing a +ConfigChangeRequest+ using the URI +config:etcd+.
+ by accessing a +MutableConfiguration+ using the URI +config:etcd+.
=== The EtcdAccessor
@@ -209,11 +207,11 @@ public class EtcdAccessor {
=== The EtcdPropertySource
-The +EtcdPropertySource+ is automatically registered and requires the etcd servers to be used to be configured. This
+The +EtcdPropertySource+ is automatically registered and allows to configure the etcd servers to be used. This
enables to use e.g. in Docker environments the docker environment configuration mechanisms to configure Tamaya running
-in microservice containers to connect with the according etcd container cluster:
+in microservice containers to connect with the according etcd cluster:
-* The property source reads the +tamaya.etcd.server.urls+ system property to evaluate possible etcd servers
+* The property source reads the +tamaya.etcd.server.urls+ system and environment property to evaluate possible etcd servers
(comma separated), which can be connected to. On error the API just performs a Round-Robin through the list of
configured servers. Without any configuration +http://127.0.0.1:4001+ is used. If no connection to any etcd
server can be established a warning will be logged, but deployment will not fail.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/1c454d5e/src/site/asciidoc/extensions/mod_json.adoc
----------------------------------------------------------------------
diff --git a/src/site/asciidoc/extensions/mod_json.adoc b/src/site/asciidoc/extensions/mod_json.adoc
index edb66ad..a851bcf 100644
--- a/src/site/asciidoc/extensions/mod_json.adoc
+++ b/src/site/asciidoc/extensions/mod_json.adoc
@@ -18,7 +18,7 @@
= Apache Tamaya -- Extension: Builder
:name: Tamaya
-:rootpackage: org.apache.tamaya.builder
+:rootpackage: org.apache.tamaya.json
:title: Apache Tamaya Extension: JSON
:revnumber: 0.1.1
:revremark: Incubator
@@ -91,7 +91,7 @@ For reading JSON based onfiguration most easily a +JSONFormat+ can be provided:
[source, java]
-----------------------------------------------
ConfigurationData dataRead = ConfigurationFormats.readConfig(
- getClassLoader().getResource("myFileConfig.json"), new JSonFOrmat()));
+ getClassLoader().getResource("myFileConfig.json"), new JSONFormat()));
-----------------------------------------------
=== Examples
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/1c454d5e/src/site/asciidoc/extensions/mod_mutable_config.adoc
----------------------------------------------------------------------
diff --git a/src/site/asciidoc/extensions/mod_mutable_config.adoc b/src/site/asciidoc/extensions/mod_mutable_config.adoc
index 8e85f35..ba888b4 100644
--- a/src/site/asciidoc/extensions/mod_mutable_config.adoc
+++ b/src/site/asciidoc/extensions/mod_mutable_config.adoc
@@ -73,20 +73,25 @@ To benefit from configuration mutability support you only must add the correspon
The core of the module is the +MutableConfigQuery+ singleton, which is a +ConfigQuery+ that creates a new
+Mutableonfiguration+ based on a +Configuration+ and a set of target backend +URIs+. If not sure you can call
+getSupportedURIInfo()+ to see, which kind of URI's are currently supported.
-As an example writing configuration entries to an +etcd+ server can be done as follows:
+On top of this API you also must have the correponding implementations installed that provide the backend logic needed
+to write the changes back. This module by default supports writing back to files only. As an example how to write
+configuration entries back refer to the following snippet:
[source,java]
.Accessing a mutable configuration backed by etcd
--------------------------------------------
MutableConfiguration config = ConfigChangeManager.getConfiguration().query(
- MutableConfigurationQuery.of("etc:http://127.0.0.1:4441", "file:/home/etcd/backup-config.properties");
-config.set("newKey", "newValue").set("anotherKey", "updatedValue")
+ MutableConfigurationQuery.of("file:/home/etcd/backup-config.properties");
+
+config.set("newKey", "newValue")
+ .set("anotherKey", "updatedValue")
.remove("valueNotValid")
.commit();
--------------------------------------------
-The effective effect of your changes to the overall configuration changes cannot be easily predicted, since it depends
-on several aspects:
+Hereby it is also possible to provide multiple URLS that allows you to write your configuration chnges back to multiple
+backends in one go. Also be aware that the effective effect of your changes to the overall configuration changes cannot
+be easily predicted, since it depends on several aspects:
. is the corresponding configuration resource configured as part of the current system's configuration?
. what is the +PropertySource's+ ordinal? Is it overriding or overridden by other sources?
@@ -106,13 +111,14 @@ is writable at all or can be removed or updated:
.Checking for mutability
--------------------------------------------
MutableConfiguration config = ConfigChangeManager.getConfiguration().query(
- MutableConfigurationQuery.of("etc:http://127.0.0.1:4441", "file:/home/etcd/backup-config.properties");
+ MutableConfigurationQuery.of("file:/home/etcd/backup-config.properties");
+
if(config,isWritable("mycluster.shared.appKey")){
config.set("newKey", "newValue")
- .remove("valueNotValid")
- .commit();
+ .remove("valueNotValid")
+ .commit();
}else{
- config.rollbacks();
+ config.rollback();
}
--------------------------------------------
@@ -144,7 +150,7 @@ defines a fabric method +MutableConfigurationBackendSpi getBackend(URI)+ used by
accessor:
[source,java]
-.SPI: ConfigEventSpi
+.SPI: MutableConfigurationBackendProviderSpi
--------------------------------------------------
public interface MutableConfigurationBackendProviderSpi {
MutableConfigurationBackendSpi getBackend(URI backendURI);
[02/10] incubator-tamaya git commit: TAMAYA-71: Added ServiceLoader
config.
Posted by an...@apache.org.
TAMAYA-71: Added ServiceLoader config.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/264a5f48
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/264a5f48
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/264a5f48
Branch: refs/heads/master
Commit: 264a5f48cf181dec8f563ec7015de9036e30b59d
Parents: bb1e1e9
Author: anatole <an...@apache.org>
Authored: Sat Feb 27 21:49:52 2016 +0100
Committer: anatole <an...@apache.org>
Committed: Sat Feb 27 21:49:52 2016 +0100
----------------------------------------------------------------------
.../org.apache.tamaya.format.ConfigurationFormat | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/264a5f48/modules/yaml/src/main/resources/META-INF/services/org.apache.tamaya.format.ConfigurationFormat
----------------------------------------------------------------------
diff --git a/modules/yaml/src/main/resources/META-INF/services/org.apache.tamaya.format.ConfigurationFormat b/modules/yaml/src/main/resources/META-INF/services/org.apache.tamaya.format.ConfigurationFormat
new file mode 100644
index 0000000..1b5d57d
--- /dev/null
+++ b/modules/yaml/src/main/resources/META-INF/services/org.apache.tamaya.format.ConfigurationFormat
@@ -0,0 +1,19 @@
+#
+# 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.json.YAMLFormat
\ No newline at end of file
[10/10] incubator-tamaya git commit: TAMAYA-71: Added yaml module.
Posted by an...@apache.org.
TAMAYA-71: Added yaml module.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/63d22214
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/63d22214
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/63d22214
Branch: refs/heads/master
Commit: 63d222140b23499b5d4711f18f81e1720c47fc96
Parents: 1c454d5
Author: anatole <an...@apache.org>
Authored: Sat Feb 27 22:01:46 2016 +0100
Committer: anatole <an...@apache.org>
Committed: Sat Feb 27 22:01:46 2016 +0100
----------------------------------------------------------------------
modules/pom.xml | 1 +
1 file changed, 1 insertion(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/63d22214/modules/pom.xml
----------------------------------------------------------------------
diff --git a/modules/pom.xml b/modules/pom.xml
index 8b265de..33704a4 100644
--- a/modules/pom.xml
+++ b/modules/pom.xml
@@ -41,6 +41,7 @@ under the License.
<module>injection-api</module>
<module>injection</module>
<module>json</module>
+ <module>yaml</module>
<module>resolver</module>
<module>resources</module>
<module>functions</module>