merge PR #242 - A few fixes that I found from my work on examples

This commit is contained in:
Andy Taylor 2015-05-21 11:03:23 +01:00
commit 879f4a6bb3
9 changed files with 167 additions and 92 deletions

View File

@ -5,7 +5,7 @@ This file describes some minimum 'stuff one needs to know' to get started coding
## Source
For details about the modifying the code, building the project, running tests, IDE integration, etc. see
our [Hacking Guide](./docs/hacking-guide/en/README.md).
our [Hacking Guide](./docs/hacking-guide/en/SUMMARY.md).
## Examples

View File

@ -16,86 +16,15 @@
*/
package org.apache.activemq.artemis.cli.commands;
import java.util.Scanner;
public abstract class ActionAbstract implements Action
{
protected ActionContext context;
private Scanner scanner;
private boolean noInput = false;
protected void disableInputs()
{
noInput = true;
}
protected String input(String propertyName, String prompt, String silentDefault)
{
if (noInput)
{
return silentDefault;
}
String inputStr;
boolean valid = false;
System.out.println();
do
{
context.out.println(propertyName + ": is mandatory with this configuration:");
context.out.println(prompt);
inputStr = scanner.nextLine();
if (inputStr.trim().equals(""))
{
System.out.println("Invalid Entry!");
}
else
{
valid = true;
}
}
while (!valid);
return inputStr.trim();
}
protected String inputPassword(String propertyName, String prompt, String silentDefault)
{
if (noInput)
{
return silentDefault;
}
String inputStr;
boolean valid = false;
System.out.println();
do
{
context.out.println(propertyName + ": is mandatory with this configuration:");
context.out.println(prompt);
inputStr = new String(System.console().readPassword());
if (inputStr.trim().equals(""))
{
System.out.println("Invalid Entry!");
}
else
{
valid = true;
}
}
while (!valid);
return inputStr.trim();
}
public Object execute(ActionContext context) throws Exception
{
this.context = context;
scanner = new Scanner(context.in);
return null;
}

View File

@ -51,7 +51,7 @@ import static java.nio.file.attribute.PosixFilePermission.OWNER_WRITE;
* CLI action that creates a broker instance directory.
*/
@Command(name = "create", description = "creates a new broker instance")
public class Create extends ActionAbstract
public class Create extends InputAbstract
{
private static final Integer DEFAULT_PORT = 61616;
@ -80,6 +80,7 @@ public class Create extends ActionAbstract
public static final String ETC_CLUSTER_SECURITY_SETTINGS_TXT = "etc/cluster-security-settings.txt";
public static final String ETC_CLUSTER_SETTINGS_TXT = "etc/cluster-settings.txt";
public static final String ETC_CONNECTOR_SETTINGS_TXT = "etc/connector-settings.txt";
public static final String ETC_BOOTSTRAP_WEB_SETTINGS_TXT = "etc/bootstrap-web-settings.txt";
@Arguments(description = "The instance directory to hold the broker's configuration and data", required = true)
File directory;
@ -102,6 +103,9 @@ public class Create extends ActionAbstract
@Option(name = "--clustered", description = "Enable clustering")
boolean clustered = false;
@Option(name = "--max-hops", description = "Number of hops on the cluster configuration")
int maxHops = 0;
@Option(name = "--replicated", description = "Enable broker replication")
boolean replicated = false;
@ -132,13 +136,33 @@ public class Create extends ActionAbstract
@Option(name = "--role", description = "The name for the role created (Default: amq)")
String role;
@Option(name = "--silent-input", description = "It will disable all the inputs, and it would make a best guess for any required input")
boolean silentInput;
@Option(name = "--no-web", description = "This will remove the web server definition from bootstrap.xml")
boolean noWeb;
boolean IS_WINDOWS;
boolean IS_CYGWIN;
public int getMaxHops()
{
return maxHops;
}
public void setMaxHops(int maxHops)
{
this.maxHops = maxHops;
}
public boolean isNoWeb()
{
return noWeb;
}
public void setNoWeb(boolean noWeb)
{
this.noWeb = noWeb;
}
public int getPortOffset()
{
return portOffset;
@ -359,11 +383,6 @@ public class Create extends ActionAbstract
{
super.execute(context);
if (silentInput)
{
this.disableInputs();
}
try
{
return run(context);
@ -428,7 +447,7 @@ public class Create extends ActionAbstract
filters.put("${hq.port}", String.valueOf(HQ_PORT + portOffset));
filters.put("${http.port}", String.valueOf(HTTP_PORT + portOffset));
filters.put("${data.dir}", data);
filters.put("${max-hops}", String.valueOf(maxHops));
filters.put("${user}", getUser());
filters.put("${password}", getPassword());
filters.put("${role}", getRole());
@ -442,7 +461,7 @@ public class Create extends ActionAbstract
filters.put("${connector-config.settings}", connectorSettings);
filters.put("${cluster-security.settings}", readTextFile(ETC_CLUSTER_SECURITY_SETTINGS_TXT));
filters.put("${cluster.settings}", readTextFile(ETC_CLUSTER_SETTINGS_TXT));
filters.put("${cluster.settings}", applyFilters(readTextFile(ETC_CLUSTER_SETTINGS_TXT), filters));
filters.put("${cluster-user}", getClusterUser());
filters.put("${cluster-password}", getClusterPassword());
}
@ -508,6 +527,18 @@ public class Create extends ActionAbstract
filters.put("${bootstrap.guest}", "");
}
if (noWeb)
{
filters.put("${bootstrap-web-settings}", "");
}
else
{
filters.put("${bootstrap-web-settings}", applyFilters(readTextFile(ETC_BOOTSTRAP_WEB_SETTINGS_TXT), filters));
}
write(ETC_BOOTSTRAP_XML, filters, false);
write(ETC_BROKER_XML, filters, false);
write(ETC_ARTEMIS_ROLES_PROPERTIES, filters, false);

View File

@ -0,0 +1,111 @@
/**
* 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.activemq.artemis.cli.commands;
import java.util.Scanner;
import io.airlift.airline.Option;
public class InputAbstract extends ActionAbstract
{
private Scanner scanner;
@Option(name = "--silent-input", description = "It will disable all the inputs, and it would make a best guess for any required input")
private boolean silentInput = false;
public boolean isSilentInput()
{
return silentInput;
}
public void setSilentInput(boolean silentInput)
{
this.silentInput = silentInput;
}
protected String input(String propertyName, String prompt, String silentDefault)
{
if (silentInput)
{
return silentDefault;
}
String inputStr;
boolean valid = false;
System.out.println();
do
{
context.out.println(propertyName + ": is mandatory with this configuration:");
context.out.println(prompt);
inputStr = scanner.nextLine();
if (inputStr.trim().equals(""))
{
System.out.println("Invalid Entry!");
}
else
{
valid = true;
}
}
while (!valid);
return inputStr.trim();
}
protected String inputPassword(String propertyName, String prompt, String silentDefault)
{
if (silentInput)
{
return silentDefault;
}
String inputStr;
boolean valid = false;
System.out.println();
do
{
context.out.println(propertyName + ": is mandatory with this configuration:");
context.out.println(prompt);
inputStr = new String(System.console().readPassword());
if (inputStr.trim().equals(""))
{
System.out.println("Invalid Entry!");
}
else
{
valid = true;
}
}
while (!valid);
return inputStr.trim();
}
@Override
public Object execute(ActionContext context) throws Exception
{
super.execute(context);
this.scanner = new Scanner(context.in);
return null;
}
}

View File

@ -0,0 +1,4 @@
<!-- The web server is only bound to loalhost by default -->
<web bind="http://localhost:${http.port}" path="web">
<app url="jolokia" war="jolokia-war-1.2.3.war"/>
</web>

View File

@ -25,10 +25,7 @@
<server configuration="file:${artemis.instance}/etc/broker.xml"/>
<!-- The web server is only bound to loalhost by default -->
<web bind="http://localhost:${http.port}" path="web">
<app url="jolokia" war="jolokia-war-1.2.3.war"/>
</web>
${bootstrap-web-settings}
</broker>

View File

@ -19,7 +19,9 @@
<cluster-connections>
<cluster-connection name="my-cluster">
<address>jms</address>
<connector-ref>activemq</connector-ref>
<connector-ref>artemis</connector-ref>
<max-hops>${max-hops}</max-hops>
<discovery-group-ref discovery-group-name="dg-group1"/>
</cluster-connection>
</cluster-connections>

View File

@ -48,6 +48,7 @@ public class StreamClassPathTest
openStream(Create.ETC_CLUSTER_SECURITY_SETTINGS_TXT);
openStream(Create.ETC_CLUSTER_SETTINGS_TXT);
openStream(Create.ETC_CONNECTOR_SETTINGS_TXT);
openStream(Create.ETC_BOOTSTRAP_WEB_SETTINGS_TXT);
}

View File

@ -44,23 +44,23 @@ $ ./artemis create $directory </br></br>Where $directory is the folder that you'
The create process will input for any required property not specified. Example:
<PRE>
--user: is mandatory at the current context:
--user: is mandatory with this configuration:
Please provide the default username:
admin
--password: is mandatory at the current context:
--password: is mandatory with this configuration:
Please provide the default password:
--allow-anonymous: is mandatory at the current context:
--allow-anonymous: is mandatory with this configuration:
Allow anonymous access? (Y/N):
Y
y
</PRE>
For a full list of availble options for the create process you may use:
$ ./artemis help create
<PRE>
NAME
artemis create - creates a new broker instance