You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@juneau.apache.org by GitBox <gi...@apache.org> on 2018/11/24 17:59:30 UTC

[GitHub] jamesbognar closed pull request #19: Added config command for microservice CLI

jamesbognar closed pull request #19: Added config command for microservice CLI
URL: https://github.com/apache/juneau/pull/19
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/juneau-examples/juneau-examples-rest/examples.cfg b/juneau-examples/juneau-examples-rest/examples.cfg
index 9a9428d1b..10c6242b7 100755
--- a/juneau-examples/juneau-examples-rest/examples.cfg
+++ b/juneau-examples/juneau-examples-rest/examples.cfg
@@ -74,6 +74,7 @@ enabled = true
 commands = 
 	org.apache.juneau.microservice.console.ExitCommand,
 	org.apache.juneau.microservice.console.RestartCommand,
+	org.apache.juneau.microservice.console.ConfigCommand,
 	org.apache.juneau.microservice.console.HelpCommand,
 	org.apache.juneau.examples.rest.command.EchoCommand
 
diff --git a/juneau-microservice/juneau-microservice-server/src/main/java/org/apache/juneau/microservice/console/ConfigCommand.java b/juneau-microservice/juneau-microservice-server/src/main/java/org/apache/juneau/microservice/console/ConfigCommand.java
new file mode 100644
index 000000000..6a504a329
--- /dev/null
+++ b/juneau-microservice/juneau-microservice-server/src/main/java/org/apache/juneau/microservice/console/ConfigCommand.java
@@ -0,0 +1,76 @@
+// ***************************************************************************************************************************
+// * 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.juneau.microservice.console;
+
+import java.io.*;
+import java.util.*;
+
+import org.apache.juneau.config.*;
+import org.apache.juneau.microservice.*;
+import org.apache.juneau.utils.*;
+
+/**
+ * Implements the 'config' console command to get or set configuration.
+ */
+public class ConfigCommand extends ConsoleCommand {
+
+	private final MessageBundle mb = MessageBundle.create(ConfigCommand.class, "Messages");
+
+	@Override /* ConsoleCommand */
+	public String getName() {
+		return "config";
+	}
+	
+	@Override /* ConsoleCommand */
+	public String getSynopsis() {
+		return "config [get|set]";
+	}
+
+	@Override /* ConsoleCommand */
+	public String getInfo() {
+		return mb.getString("info");
+	}
+
+	@Override /* ConsoleCommand */
+	public String getDescription() {
+		return mb.getString("description");
+	}
+
+	@Override /* ConsoleCommand */
+	public boolean execute(Scanner in, PrintWriter out, Args args) {
+		Config conf = Microservice.getInstance().getConfig();
+		if (args.size() > 2) {
+			String key = args.getArg(2);
+			if (args.getArg(1).equals("get")) {
+				String val = conf.getString(key);
+				if (val == null)
+					out.println(mb.getString("KeyNotFound", key));
+				else
+					out.println(val);
+			}
+			else if (args.getArg(1).equals("set")) {
+				if(args.size() < 3) {
+					out.println(mb.getString("InvalidArguments"));
+				}
+				else {
+					conf.set(key, args.getArg(3));
+					out.println(mb.getString("ConfigSet"));
+				}
+			}
+		}
+		else {
+			out.println(mb.getString("InvalidArguments"));
+		}
+		return false;
+	}
+}
diff --git a/juneau-microservice/juneau-microservice-server/src/main/resources/org/apache/juneau/microservice/console/Messages.properties b/juneau-microservice/juneau-microservice-server/src/main/resources/org/apache/juneau/microservice/console/Messages.properties
index e9a484317..c447e1d34 100644
--- a/juneau-microservice/juneau-microservice-server/src/main/resources/org/apache/juneau/microservice/console/Messages.properties
+++ b/juneau-microservice/juneau-microservice-server/src/main/resources/org/apache/juneau/microservice/console/Messages.properties
@@ -33,3 +33,8 @@ HelpCommand.SYNOPSIS = SYNOPSIS
 HelpCommand.DESCRIPTION = DESCRIPTION
 HelpCommand.EXAMPLES = EXAMPLES
 HelpCommand.CommandNotFound = Command not found.
+ConfigCommand.info = Get or set configuration
+ConfigCommand.description = Get configuration value for given key and set (Restart required) for given key and value 
+ConfigCommand.InvalidArguments = Invalid or missing arguments for config command
+ConfigCommand.KeyNotFound = key ''{0}'' is not found in current configuration
+ConfigCommand.ConfigSet = Configuration updated.


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services