TAMAYA-241: Removed ScopeManager et al.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/commit/7a67cc36 Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/7a67cc36 Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/7a67cc36 Branch: refs/heads/master Commit: 7a67cc36219a36c0cfa10ceb14fcc593064c8086 Parents: 1598ccd Author: anatole <[email protected]> Authored: Thu Feb 23 01:18:21 2017 +0100 Committer: anatole <[email protected]> Committed: Mon Feb 27 00:05:00 2017 +0100 ---------------------------------------------------------------------- .../apache/tamaya/server/ConfigServiceApp.java | 77 ----- .../tamaya/server/ConfigurationResource.java | 310 ------------------- .../tamaya/server/ConfigurationServices.java | 310 +++++++++++++++++++ .../java/org/apache/tamaya/server/Server.java | 92 ++++++ .../apache/tamaya/server/VersionProperties.java | 68 ---- .../apache/tamaya/server/spi/ScopeManager.java | 84 ----- .../apache/tamaya/server/spi/ScopeProvider.java | 40 --- .../META-INF/tamaya-server-version.properties | 22 -- server/src/main/resources/banner.txt | 14 - server/src/main/resources/config-server.yml | 31 -- 10 files changed, 402 insertions(+), 646 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/7a67cc36/server/src/main/java/org/apache/tamaya/server/ConfigServiceApp.java ---------------------------------------------------------------------- diff --git a/server/src/main/java/org/apache/tamaya/server/ConfigServiceApp.java b/server/src/main/java/org/apache/tamaya/server/ConfigServiceApp.java deleted file mode 100644 index 1db06f3..0000000 --- a/server/src/main/java/org/apache/tamaya/server/ConfigServiceApp.java +++ /dev/null @@ -1,77 +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.server; - -import org.apache.catalina.Context; -import org.apache.catalina.Wrapper; -import org.apache.catalina.startup.Tomcat; -import org.apache.tamaya.Configuration; -import org.apache.tamaya.ConfigurationProvider; - -import javax.ws.rs.core.Application; -import java.io.File; -import java.util.HashSet; -import java.util.Set; - -/** - * Main Application for the Tamaya Configuration Server. - */ -public class ConfigServiceApp { - - /** - * Utility class. - */ - private ConfigServiceApp(){} - - /** - * JAX RS Application. - */ - public static class ResourceLoader extends Application{ - - @Override - public Set<Class<?>> getClasses() { - final Set<Class<?>> classes = new HashSet<>(); - // register root resource - classes.add(ConfigurationResource.class); - return classes; - } - } - - public static void main(String... args) throws Exception { - Configuration config = ConfigurationProvider.getConfiguration(); - String contextPath = config.getOrDefault("tamaya.server.contextPath", "/"); - String appBase = "."; - Tomcat tomcat = new Tomcat(); - tomcat.setPort(config.getOrDefault("tamaya.server.port", Integer.class, 8085)); - - // Define a web application context. - Context context = tomcat.addWebapp(contextPath, new File( - appBase).getAbsolutePath()); - // Add servlet that will register Jersey REST resources - String servletName = "cxf-servlet"; - Wrapper wrapper = tomcat.addServlet(context, servletName, - org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet.class.getName()); - wrapper.addInitParameter("javax.ws.rs.Application", ResourceLoader.class.getName()); - context.addServletMapping("/*", servletName); - tomcat.start(); - tomcat.getServer().await(); - } - - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/7a67cc36/server/src/main/java/org/apache/tamaya/server/ConfigurationResource.java ---------------------------------------------------------------------- diff --git a/server/src/main/java/org/apache/tamaya/server/ConfigurationResource.java b/server/src/main/java/org/apache/tamaya/server/ConfigurationResource.java deleted file mode 100644 index f13446a..0000000 --- a/server/src/main/java/org/apache/tamaya/server/ConfigurationResource.java +++ /dev/null @@ -1,310 +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.server; - -import java.io.StringWriter; -import java.util.Map; -import java.util.Objects; -import java.util.concurrent.atomic.AtomicLong; - -import javax.json.Json; -import javax.json.JsonArray; -import javax.json.JsonArrayBuilder; -import javax.json.JsonObject; -import javax.json.JsonObjectBuilder; -import javax.json.JsonWriter; -import javax.json.stream.JsonGenerator; -import javax.ws.rs.DELETE; -import javax.ws.rs.FormParam; -import javax.ws.rs.GET; -import javax.ws.rs.PUT; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.MediaType; - -import org.apache.tamaya.Configuration; -import org.apache.tamaya.ConfigurationProvider; -import org.apache.tamaya.functions.ConfigurationFunctions; - -/** - * Configuration resource with an etcd compatible REST API - * (excluding the blocking API calls). - */ -@Path("/") -@Produces({MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN}) -public class ConfigurationResource { - private final AtomicLong readCounter = new AtomicLong(); - private final AtomicLong writeCounter = new AtomicLong(); - private final AtomicLong deleteCounter = new AtomicLong(); - - - @GET - @Path("/version") - @Produces({MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN}) - public String version() { - String product = VersionProperties.getProduct().replace("\"", "\\\""); - String version = VersionProperties.getVersion().replace("\"", "\\\""); - - return String.format("{ \"version\" : \"%s: %s\" }", product, version); - } - - @GET - @Path("/v2/keys") - public String readEtcdConfig(@QueryParam("recursive") Boolean recursive) { - return readConfig(recursive); - } - - /** - * This models a etcd2 compliant access point for getting a property value. - * - * @param recursive NOT YET IMPLEMENTED! - * @return all configuration property values. - */ - @GET - @Path("/keys") - public String readConfig(@QueryParam("recursive") Boolean recursive) { - readCounter.incrementAndGet(); - final Configuration config = ConfigurationProvider.getConfiguration(); - final Map<String, String> children = config.getProperties(); - final JsonArrayBuilder ab = Json.createArrayBuilder(); - for (final Map.Entry<String, String> en : children.entrySet()) { - final Node node = new Node(config, en.getKey(), "node"); - ab.add(node.createJsonObject()); - } - final Node node = new Node(config, null, "node", ab.build()); - final JsonObjectBuilder root = Json.createObjectBuilder().add("action", "get") - .add("node", node.createJsonObject()); - final StringWriter writer = new StringWriter(); - final JsonWriter jwriter = Json.createWriter(writer); - jwriter.writeObject(root.build()); - return writer.toString(); - } - - /** - * This models a etcd2 compliant access point for getting a property value. - * - * @param key name of the key to show - * @param recursive NOT YET IMPLEMENTED! - * @return specific configuration key derived from the given key name. - */ - @GET - @Path("/v2/keys/{key}") - public String readEtcdConfig(@PathParam("key") String key, @QueryParam("recursive") Boolean recursive) { - return readConfig(key, recursive); - } - - /** - * This models a etcd2 compliant access point for getting a property value. - * - * @param key name of the key to show - * @param recursive NOT YET IMPLEMENTED! - * @return configuration value of the given key. - */ - @GET - @Path("/keys/{key}") - public String readConfig(@PathParam("key") String key, @QueryParam("recursive") Boolean recursive) { - readCounter.incrementAndGet(); - final Configuration config = ConfigurationProvider.getConfiguration(); - if (key != null) { - if (key.startsWith("/")) { - key = key.substring(1); - } - if (config.get(key) != null && !recursive) { - final Node node = new Node(config, key, "node"); - final JsonObjectBuilder root = Json.createObjectBuilder().add("action", "get") - .add("node", node.createJsonObject()); - final StringWriter writer = new StringWriter(); - final JsonGenerator gen = Json.createGenerator(writer); - gen.write(root.build()); - return writer.toString(); - } - } - Map<String, String> children = null; - if (key == null) { - children = config.getProperties(); - } else { - children = config.with(ConfigurationFunctions.section(key)).getProperties(); - } - final JsonArrayBuilder ab = Json.createArrayBuilder(); - for (final Map.Entry<String, String> en : children.entrySet()) { - final Node node = new Node(config, en.getKey(), "node"); - ab.add(node.createJsonObject()); - } - final Node node = new Node(config, key, "node", ab.build()); - final JsonObjectBuilder root = Json.createObjectBuilder().add("action", "get") - .add("node", node.createJsonObject()); - final StringWriter writer = new StringWriter(); - final JsonWriter jwriter = Json.createWriter(writer); - jwriter.writeObject(root.build()); - return writer.toString(); - } - - @PUT - @Path("/v2/keys/{key}") - public String writeEtcdConfig(@PathParam("key") String key, @javax.ws.rs.FormParam("value") String value, - @FormParam("ttl") Integer ttl) { - return writeConfig(key, value, ttl); - } - - /** - * This models a etcd2 compliant access point for setting a property value: - * <pre> - * { - * "action": "set", - * "node": { - * "createdIndex": 3, - * "key": "/message", - * "modifiedIndex": 3, - * "value": "Hello etcd" - * }, - * "prevNode": { - * "createdIndex": 2, - * "key": "/message", - * "value": "Hello world", - * "modifiedIndex": 2 - * } - * } - * </pre> - * - * @param key name of the key to show - * @param value configuration value for the given key - * @param ttl time to live - * @return written configuration value. - */ - @PUT - @Path("/keys/{key}") - public String writeConfig(@PathParam("key") String key, @javax.ws.rs.FormParam("value") String value, - @FormParam("ttl") Integer ttl) { - writeCounter.incrementAndGet(); - final Configuration config = ConfigurationProvider.getConfiguration(); - if (key.startsWith("/")) { - key = key.substring(1); - } - final Node prevNode = new Node(config, key, "prevNode"); - // TODO implement write! value and ttl as input - final Node node = new Node(config, key, "node"); - final JsonObjectBuilder root = Json.createObjectBuilder().add("action", "set") - .add("node", node.createJsonObject()) - .add("prevNode", prevNode.createJsonObject()); - final StringWriter writer = new StringWriter(); - final JsonWriter jwriter = Json.createWriter(writer); - jwriter.writeObject(root.build()); - return writer.toString(); - } - - @DELETE - @Path("/v2/keys/{key}") - public String deleteEtcdConfig(@PathParam("key") String key) { - return deleteConfig(key); - } - - @DELETE - @Path("/keys/{key}") - public String deleteConfig(@PathParam("key") String key) { - deleteCounter.incrementAndGet(); - final Configuration config = ConfigurationProvider.getConfiguration(); - if (key.startsWith("/")) { - key = key.substring(1); - } - final Node prevNode = new Node(config, key, "prevNode"); - // TODO implement write! value and ttl as input - final Node node = new Node(config, key, "node"); - final JsonObjectBuilder root = Json.createObjectBuilder().add("action", "delete") - .add("node", node.createJsonObject()) - .add("prevNode", prevNode.createJsonObject()); - final StringWriter writer = new StringWriter(); - final JsonWriter jwriter = Json.createWriter(writer); - jwriter.writeObject(root.build()); - return writer.toString(); - } - - public long getDeleteCounter() { - return deleteCounter.get(); - } - - public long getReadCounter() { - return readCounter.get(); - } - - public long getWriteCounter() { - return writeCounter.get(); - } - - /** - * Internal representation of a configuration node as modeled by etc. - */ - private static final class Node { - private Integer createdIndex; - private Integer modifiedIndex; - private final String key; - private String value; - private final String nodeId; - private Integer ttl; - private String expiration; - private final JsonArray nodes; - - Node(Configuration config, String key, String nodeId) { - this(config, key, nodeId, null); - } - - Node(Configuration config, String key, String nodeId, JsonArray nodes) { - this.key = key; - this.nodeId = Objects.requireNonNull(nodeId); - if (key != null) { - value = config.get(key); - createdIndex = config.getOrDefault("_" + key + ".createdIndex", Integer.class, null); - modifiedIndex = config.getOrDefault("_" + key + ".modifiedIndex", Integer.class, null); - ttl = config.getOrDefault("_" + key + ".ttl", Integer.class, null); - expiration = config.getOrDefault("_" + key + ".expiration", null); - } - this.nodes = nodes; - } - - JsonObject createJsonObject() { - final JsonObjectBuilder nodeBuilder = Json.createObjectBuilder(); - if (key != null) { - nodeBuilder.add("key", '/' + key); - } else { - nodeBuilder.add("dir", true); - } - if (value != null) { - nodeBuilder.add("value", value); - } - if (createdIndex != null) { - nodeBuilder.add("createdIndex", createdIndex.intValue()); - } - if (modifiedIndex != null) { - nodeBuilder.add("modifiedIndex", modifiedIndex.intValue()); - } - if (ttl != null) { - nodeBuilder.add("ttl", ttl.intValue()); - } - if (expiration != null) { - nodeBuilder.add("expiration", value); - } - if (nodes != null) { - nodeBuilder.add("nodes", nodes); - } - return nodeBuilder.build(); - } - } - -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/7a67cc36/server/src/main/java/org/apache/tamaya/server/ConfigurationServices.java ---------------------------------------------------------------------- diff --git a/server/src/main/java/org/apache/tamaya/server/ConfigurationServices.java b/server/src/main/java/org/apache/tamaya/server/ConfigurationServices.java new file mode 100644 index 0000000..f13446a --- /dev/null +++ b/server/src/main/java/org/apache/tamaya/server/ConfigurationServices.java @@ -0,0 +1,310 @@ +/* + * 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.server; + +import java.io.StringWriter; +import java.util.Map; +import java.util.Objects; +import java.util.concurrent.atomic.AtomicLong; + +import javax.json.Json; +import javax.json.JsonArray; +import javax.json.JsonArrayBuilder; +import javax.json.JsonObject; +import javax.json.JsonObjectBuilder; +import javax.json.JsonWriter; +import javax.json.stream.JsonGenerator; +import javax.ws.rs.DELETE; +import javax.ws.rs.FormParam; +import javax.ws.rs.GET; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; + +import org.apache.tamaya.Configuration; +import org.apache.tamaya.ConfigurationProvider; +import org.apache.tamaya.functions.ConfigurationFunctions; + +/** + * Configuration resource with an etcd compatible REST API + * (excluding the blocking API calls). + */ +@Path("/") +@Produces({MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN}) +public class ConfigurationResource { + private final AtomicLong readCounter = new AtomicLong(); + private final AtomicLong writeCounter = new AtomicLong(); + private final AtomicLong deleteCounter = new AtomicLong(); + + + @GET + @Path("/version") + @Produces({MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN}) + public String version() { + String product = VersionProperties.getProduct().replace("\"", "\\\""); + String version = VersionProperties.getVersion().replace("\"", "\\\""); + + return String.format("{ \"version\" : \"%s: %s\" }", product, version); + } + + @GET + @Path("/v2/keys") + public String readEtcdConfig(@QueryParam("recursive") Boolean recursive) { + return readConfig(recursive); + } + + /** + * This models a etcd2 compliant access point for getting a property value. + * + * @param recursive NOT YET IMPLEMENTED! + * @return all configuration property values. + */ + @GET + @Path("/keys") + public String readConfig(@QueryParam("recursive") Boolean recursive) { + readCounter.incrementAndGet(); + final Configuration config = ConfigurationProvider.getConfiguration(); + final Map<String, String> children = config.getProperties(); + final JsonArrayBuilder ab = Json.createArrayBuilder(); + for (final Map.Entry<String, String> en : children.entrySet()) { + final Node node = new Node(config, en.getKey(), "node"); + ab.add(node.createJsonObject()); + } + final Node node = new Node(config, null, "node", ab.build()); + final JsonObjectBuilder root = Json.createObjectBuilder().add("action", "get") + .add("node", node.createJsonObject()); + final StringWriter writer = new StringWriter(); + final JsonWriter jwriter = Json.createWriter(writer); + jwriter.writeObject(root.build()); + return writer.toString(); + } + + /** + * This models a etcd2 compliant access point for getting a property value. + * + * @param key name of the key to show + * @param recursive NOT YET IMPLEMENTED! + * @return specific configuration key derived from the given key name. + */ + @GET + @Path("/v2/keys/{key}") + public String readEtcdConfig(@PathParam("key") String key, @QueryParam("recursive") Boolean recursive) { + return readConfig(key, recursive); + } + + /** + * This models a etcd2 compliant access point for getting a property value. + * + * @param key name of the key to show + * @param recursive NOT YET IMPLEMENTED! + * @return configuration value of the given key. + */ + @GET + @Path("/keys/{key}") + public String readConfig(@PathParam("key") String key, @QueryParam("recursive") Boolean recursive) { + readCounter.incrementAndGet(); + final Configuration config = ConfigurationProvider.getConfiguration(); + if (key != null) { + if (key.startsWith("/")) { + key = key.substring(1); + } + if (config.get(key) != null && !recursive) { + final Node node = new Node(config, key, "node"); + final JsonObjectBuilder root = Json.createObjectBuilder().add("action", "get") + .add("node", node.createJsonObject()); + final StringWriter writer = new StringWriter(); + final JsonGenerator gen = Json.createGenerator(writer); + gen.write(root.build()); + return writer.toString(); + } + } + Map<String, String> children = null; + if (key == null) { + children = config.getProperties(); + } else { + children = config.with(ConfigurationFunctions.section(key)).getProperties(); + } + final JsonArrayBuilder ab = Json.createArrayBuilder(); + for (final Map.Entry<String, String> en : children.entrySet()) { + final Node node = new Node(config, en.getKey(), "node"); + ab.add(node.createJsonObject()); + } + final Node node = new Node(config, key, "node", ab.build()); + final JsonObjectBuilder root = Json.createObjectBuilder().add("action", "get") + .add("node", node.createJsonObject()); + final StringWriter writer = new StringWriter(); + final JsonWriter jwriter = Json.createWriter(writer); + jwriter.writeObject(root.build()); + return writer.toString(); + } + + @PUT + @Path("/v2/keys/{key}") + public String writeEtcdConfig(@PathParam("key") String key, @javax.ws.rs.FormParam("value") String value, + @FormParam("ttl") Integer ttl) { + return writeConfig(key, value, ttl); + } + + /** + * This models a etcd2 compliant access point for setting a property value: + * <pre> + * { + * "action": "set", + * "node": { + * "createdIndex": 3, + * "key": "/message", + * "modifiedIndex": 3, + * "value": "Hello etcd" + * }, + * "prevNode": { + * "createdIndex": 2, + * "key": "/message", + * "value": "Hello world", + * "modifiedIndex": 2 + * } + * } + * </pre> + * + * @param key name of the key to show + * @param value configuration value for the given key + * @param ttl time to live + * @return written configuration value. + */ + @PUT + @Path("/keys/{key}") + public String writeConfig(@PathParam("key") String key, @javax.ws.rs.FormParam("value") String value, + @FormParam("ttl") Integer ttl) { + writeCounter.incrementAndGet(); + final Configuration config = ConfigurationProvider.getConfiguration(); + if (key.startsWith("/")) { + key = key.substring(1); + } + final Node prevNode = new Node(config, key, "prevNode"); + // TODO implement write! value and ttl as input + final Node node = new Node(config, key, "node"); + final JsonObjectBuilder root = Json.createObjectBuilder().add("action", "set") + .add("node", node.createJsonObject()) + .add("prevNode", prevNode.createJsonObject()); + final StringWriter writer = new StringWriter(); + final JsonWriter jwriter = Json.createWriter(writer); + jwriter.writeObject(root.build()); + return writer.toString(); + } + + @DELETE + @Path("/v2/keys/{key}") + public String deleteEtcdConfig(@PathParam("key") String key) { + return deleteConfig(key); + } + + @DELETE + @Path("/keys/{key}") + public String deleteConfig(@PathParam("key") String key) { + deleteCounter.incrementAndGet(); + final Configuration config = ConfigurationProvider.getConfiguration(); + if (key.startsWith("/")) { + key = key.substring(1); + } + final Node prevNode = new Node(config, key, "prevNode"); + // TODO implement write! value and ttl as input + final Node node = new Node(config, key, "node"); + final JsonObjectBuilder root = Json.createObjectBuilder().add("action", "delete") + .add("node", node.createJsonObject()) + .add("prevNode", prevNode.createJsonObject()); + final StringWriter writer = new StringWriter(); + final JsonWriter jwriter = Json.createWriter(writer); + jwriter.writeObject(root.build()); + return writer.toString(); + } + + public long getDeleteCounter() { + return deleteCounter.get(); + } + + public long getReadCounter() { + return readCounter.get(); + } + + public long getWriteCounter() { + return writeCounter.get(); + } + + /** + * Internal representation of a configuration node as modeled by etc. + */ + private static final class Node { + private Integer createdIndex; + private Integer modifiedIndex; + private final String key; + private String value; + private final String nodeId; + private Integer ttl; + private String expiration; + private final JsonArray nodes; + + Node(Configuration config, String key, String nodeId) { + this(config, key, nodeId, null); + } + + Node(Configuration config, String key, String nodeId, JsonArray nodes) { + this.key = key; + this.nodeId = Objects.requireNonNull(nodeId); + if (key != null) { + value = config.get(key); + createdIndex = config.getOrDefault("_" + key + ".createdIndex", Integer.class, null); + modifiedIndex = config.getOrDefault("_" + key + ".modifiedIndex", Integer.class, null); + ttl = config.getOrDefault("_" + key + ".ttl", Integer.class, null); + expiration = config.getOrDefault("_" + key + ".expiration", null); + } + this.nodes = nodes; + } + + JsonObject createJsonObject() { + final JsonObjectBuilder nodeBuilder = Json.createObjectBuilder(); + if (key != null) { + nodeBuilder.add("key", '/' + key); + } else { + nodeBuilder.add("dir", true); + } + if (value != null) { + nodeBuilder.add("value", value); + } + if (createdIndex != null) { + nodeBuilder.add("createdIndex", createdIndex.intValue()); + } + if (modifiedIndex != null) { + nodeBuilder.add("modifiedIndex", modifiedIndex.intValue()); + } + if (ttl != null) { + nodeBuilder.add("ttl", ttl.intValue()); + } + if (expiration != null) { + nodeBuilder.add("expiration", value); + } + if (nodes != null) { + nodeBuilder.add("nodes", nodes); + } + return nodeBuilder.build(); + } + } + +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/7a67cc36/server/src/main/java/org/apache/tamaya/server/Server.java ---------------------------------------------------------------------- diff --git a/server/src/main/java/org/apache/tamaya/server/Server.java b/server/src/main/java/org/apache/tamaya/server/Server.java new file mode 100644 index 0000000..3a5a7cf --- /dev/null +++ b/server/src/main/java/org/apache/tamaya/server/Server.java @@ -0,0 +1,92 @@ +/* + * 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.server; + +import org.apache.catalina.Context; +import org.apache.catalina.Wrapper; +import org.apache.catalina.startup.Tomcat; +import org.apache.tamaya.Configuration; +import org.apache.tamaya.ConfigurationProvider; + +import javax.ws.rs.core.Application; +import java.io.File; +import java.util.HashSet; +import java.util.Set; + +/** + * Main Application for the Tamaya Configuration Server. + */ +public class Server { + + /** + * Utility class. + */ + private Server(){} + + + public static void start() throws Exception { + start("/", 8085); + } + + public static void start(int port) throws Exception { + start("/", port); + } + + public static void start(String contextPath, int port) throws Exception { + Objects.requireNonNull(contextPath); + String appBase = "."; + Tomcat tomcat = new Tomcat(); + tomcat.setPort(port); + + // Define a web application context. + Context context = tomcat.addWebapp(contextPath, new File( + appBase).getAbsolutePath()); + // Add servlet that will register Jersey REST resources + String servletName = "cxf-servlet"; + Wrapper wrapper = tomcat.addServlet(context, servletName, + org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet.class.getName()); + wrapper.addInitParameter("javax.ws.rs.Application", ResourceLoader.class.getName()); + context.addServletMapping("/*", servletName); + tomcat.start(); + tomcat.getServer().await(); + } + + + public static void main(String... args) throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + String contextPath = config.getOrDefault("tamaya.server.contextPath", "/"); + int port = config.getOrDefault("tamaya.server.port", Integer.class, 8085); + start(contextPath, port); + } + + /** + * JAX RS Application. + */ + public final static class ResourceLoader extends Application{ + + @Override + public Set<Class<?>> getClasses() { + final Set<Class<?>> classes = new HashSet<>(); + // register root resource + classes.add(ConfigurationServices.class); + return classes; + } + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/7a67cc36/server/src/main/java/org/apache/tamaya/server/VersionProperties.java ---------------------------------------------------------------------- diff --git a/server/src/main/java/org/apache/tamaya/server/VersionProperties.java b/server/src/main/java/org/apache/tamaya/server/VersionProperties.java deleted file mode 100644 index e271694..0000000 --- a/server/src/main/java/org/apache/tamaya/server/VersionProperties.java +++ /dev/null @@ -1,68 +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.server; - -import java.io.IOException; -import java.io.InputStream; -import java.util.Properties; - -/** - * <p>This class gives access to the current name and the current version information - * at runtime.</p> - * - * <p>All information offered by this is loaded from a properties file at - * {@link VersionProperties#VERSION_PROPERTY_FILE}.</p> - */ -public class VersionProperties { - private static final String VERSION_PROPERTY_FILE = "/META-INF/tamaya-server-version.properties"; - - static { - try (InputStream resource = VersionProperties.class.getResourceAsStream(VERSION_PROPERTY_FILE)) { - if (null == resource) { - throw new ExceptionInInitializerError("Failed to version information resource. " + - VERSION_PROPERTY_FILE + " not found."); - } - - Properties properties = new Properties(); - properties.load(resource); - - product = properties.getProperty("server.product", "n/a"); - version = properties.getProperty("server.version", "n/a"); - - } catch (IOException e) { - throw new ExceptionInInitializerError(e); - } - } - - private static String product; - private static String version; - - private VersionProperties() { - } - - public static String getProduct() { - return product; - } - - public static String getVersion() { - return version; - } - - -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/7a67cc36/server/src/main/java/org/apache/tamaya/server/spi/ScopeManager.java ---------------------------------------------------------------------- diff --git a/server/src/main/java/org/apache/tamaya/server/spi/ScopeManager.java b/server/src/main/java/org/apache/tamaya/server/spi/ScopeManager.java deleted file mode 100644 index 3d2757a..0000000 --- a/server/src/main/java/org/apache/tamaya/server/spi/ScopeManager.java +++ /dev/null @@ -1,84 +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.server.spi; - -import java.util.Map; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import java.util.logging.Level; -import java.util.logging.Logger; - -import org.apache.tamaya.ConfigException; -import org.apache.tamaya.ConfigOperator; -import org.apache.tamaya.spi.ServiceContextManager; - -/** - * Singleton manager for scopes, used by the server component to filtering returned configurations. - */ -public final class ScopeManager { - /** The logger used. */ - private static final Logger LOG = Logger.getLogger(ScopeManager.class.getName()); - - private static Map<String, ScopeProvider> scopeProviders = initProviders(); - - /** - * Singleton constructor. - */ - private static Map<String, ScopeProvider> initProviders(){ - final Map<String, ScopeProvider> result = new ConcurrentHashMap<>(); - for(final ScopeProvider prov: ServiceContextManager.getServiceContext().getServices(ScopeProvider.class)){ - try{ - result.put(prov.getScopeType(), prov); - } catch(final Exception e){ - LOG.log(Level.WARNING, "Error loading scopes from " + prov, e); - } - } - return result; - } - - /** - * Singleton constructor. - */ - private ScopeManager(){} - - /** - * Get the scope given its id and provider. - * - * @param scopeId the scope name - * @param targetScope name of the targetScope - * @return the scope matching - * @throws ConfigException if no such scope is defined - */ - public static ConfigOperator getScope(String scopeId, String targetScope) - throws ConfigException { - final ScopeProvider prov = scopeProviders.get(scopeId); - if(prov==null){ - throw new ConfigException("No such scope: " + scopeId); - } - return prov.getScope(targetScope); - } - - /** - * Get the defined scope names. - * @return the defined scope names, never null. - */ - public static Set<String> getScopes(){ - return scopeProviders.keySet(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/7a67cc36/server/src/main/java/org/apache/tamaya/server/spi/ScopeProvider.java ---------------------------------------------------------------------- diff --git a/server/src/main/java/org/apache/tamaya/server/spi/ScopeProvider.java b/server/src/main/java/org/apache/tamaya/server/spi/ScopeProvider.java deleted file mode 100644 index 5c247d8..0000000 --- a/server/src/main/java/org/apache/tamaya/server/spi/ScopeProvider.java +++ /dev/null @@ -1,40 +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.server.spi; - -import org.apache.tamaya.ConfigOperator; - -/** - * Simple registrable provider class to register scopes for the server extension. - */ -public interface ScopeProvider { - - /** - * Access the unique scope name. - * @return the unique scope name. - */ - String getScopeType(); - - /** - * Return the scope operator that implements the scope for the given scope id. - * @param scopeId target scope id. - * @return the scope operator, never null. - */ - ConfigOperator getScope(String scopeId); -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/7a67cc36/server/src/main/resources/META-INF/tamaya-server-version.properties ---------------------------------------------------------------------- diff --git a/server/src/main/resources/META-INF/tamaya-server-version.properties b/server/src/main/resources/META-INF/tamaya-server-version.properties deleted file mode 100644 index ef0ca70..0000000 --- a/server/src/main/resources/META-INF/tamaya-server-version.properties +++ /dev/null @@ -1,22 +0,0 @@ - -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy current the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# - -server.product=Apache Tamaya -server.version=${project.version} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/7a67cc36/server/src/main/resources/banner.txt ---------------------------------------------------------------------- diff --git a/server/src/main/resources/banner.txt b/server/src/main/resources/banner.txt deleted file mode 100644 index 4e2714b..0000000 --- a/server/src/main/resources/banner.txt +++ /dev/null @@ -1,14 +0,0 @@ - - ââââââ âââââââ ââââââ ââââââââââ âââââââââââ âââââââââ ââââââ ââââ ââââ ââââââ âââ âââ ââââââ -âââââââââââââââââââââââââââââââââââ âââââââââââ ââââââââââââââââââââââ âââââââââââââââââ ââââââââââââ -âââââââââââââââââââââââââââ ââââââââââââââ âââ âââââââââââââââââââââââââââ âââââââ ââââââââ -âââââââââââââââ âââââââââââ ââââââââââââââ âââ âââââââââââââââââââââââââââ âââââ ââââââââ -âââ ââââââ âââ ââââââââââââââ âââââââââââ âââ âââ ââââââ âââ ââââââ âââ âââ âââ âââ -âââ ââââââ âââ âââ ââââââââââ âââââââââââ âââ âââ ââââââ ââââââ âââ âââ âââ âââ - âââââââââââââââââââââââ âââ ââââââââââââââââââ - âââââââââââââââââââââââââââ âââââââââââââââââââ - ââââââââââââââ âââââââââââ âââââââââ ââââââââ - ââââââââââââââ ââââââââââââ ââââââââââ ââââââââ - âââââââââââââââââââ âââ âââââââ âââââââââââ âââ - âââââââââââââââââââ âââ âââââ âââââââââââ âââ - http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/7a67cc36/server/src/main/resources/config-server.yml ---------------------------------------------------------------------- diff --git a/server/src/main/resources/config-server.yml b/server/src/main/resources/config-server.yml deleted file mode 100644 index 2e210a6..0000000 --- a/server/src/main/resources/config-server.yml +++ /dev/null @@ -1,31 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy current the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# - -scope: java - -server: - applicationConnectors: - - type: http - port: 4001 - adminConnectors: - - type: http - port: 4099 - - # ${project.version} -
