NO-JIRA cli improvements

This commit is contained in:
Clebert Suconic 2016-12-16 13:05:20 -05:00 committed by Justin Bertram
parent df1ec5bc49
commit 1bed2c9512
14 changed files with 175 additions and 43 deletions

View File

@ -185,6 +185,12 @@ public class Create extends InputAbstract {
@Option(name = "--no-autotune", description = "Disable auto tuning on the journal.") @Option(name = "--no-autotune", description = "Disable auto tuning on the journal.")
boolean noAutoTune; boolean noAutoTune;
@Option(name = "--no-autocreate", description = "Disable Auto create addresses.")
Boolean noAutoCreate;
@Option(name = "--autocreate", description = "Auto create addresses. (default: true)")
Boolean autoCreate;
@Option(name = "--user", description = "The username (Default: input)") @Option(name = "--user", description = "The username (Default: input)")
String user; String user;
@ -263,6 +269,38 @@ public class Create extends InputAbstract {
this.messageLoadBalancing = messageLoadBalancing; this.messageLoadBalancing = messageLoadBalancing;
} }
public Boolean getAutoCreate() {
return autoCreate;
}
public Create setAutoCreate(Boolean autoCreate) {
this.autoCreate = autoCreate;
return this;
}
public Boolean getNoAutoCreate() {
return noAutoCreate;
}
public Create setNoAutoCreate(Boolean noAutoCreate) {
this.noAutoCreate = noAutoCreate;
return this;
}
public boolean isAutoCreate() {
if (autoCreate == null) {
if (noAutoCreate != null) {
autoCreate = !noAutoCreate.booleanValue();
}
}
if (autoCreate == null) {
autoCreate = true;
}
return autoCreate;
}
public String getJavaOptions() { public String getJavaOptions() {
return javaOptions; return javaOptions;
} }
@ -720,6 +758,9 @@ public class Create extends InputAbstract {
filters.put("${full-policy}", "PAGE"); filters.put("${full-policy}", "PAGE");
} }
filters.put("${auto-create}", isAutoCreate() ? "true" : "false");
performAutoTune(filters, aio, dataFolder); performAutoTune(filters, aio, dataFolder);
write(ETC_BROKER_XML, filters, false); write(ETC_BROKER_XML, filters, false);

View File

@ -70,6 +70,10 @@ public class InputAbstract extends ActionAbstract {
} }
protected String input(String propertyName, String prompt, String silentDefault) { protected String input(String propertyName, String prompt, String silentDefault) {
return input(propertyName, prompt, silentDefault, false);
}
protected String input(String propertyName, String prompt, String silentDefault, boolean acceptNull) {
if (isSilentInput()) { if (isSilentInput()) {
return silentDefault; return silentDefault;
} }
@ -81,7 +85,7 @@ public class InputAbstract extends ActionAbstract {
context.out.println(propertyName + ": is a mandatory property!"); context.out.println(propertyName + ": is a mandatory property!");
context.out.println(prompt); context.out.println(prompt);
inputStr = scanner.nextLine(); inputStr = scanner.nextLine();
if (inputStr.trim().equals("")) { if (!acceptNull && inputStr.trim().equals("")) {
System.out.println("Invalid Entry!"); System.out.println("Invalid Entry!");
} else { } else {
valid = true; valid = true;

View File

@ -42,8 +42,8 @@ public abstract class AddressAbstract extends AbstractAction {
this.name = name; this.name = name;
} }
public String getName() { public String getName(boolean requireInput) {
if (name == null) { if (name == null && requireInput) {
name = input("--name", "Provide the name of the address", null); name = input("--name", "Provide the name of the address", null);
} }
return name; return name;

View File

@ -36,7 +36,7 @@ public class CreateAddress extends AddressAbstract {
performCoreManagement(new ManagementCallback<ClientMessage>() { performCoreManagement(new ManagementCallback<ClientMessage>() {
@Override @Override
public void setUpInvocation(ClientMessage message) throws Exception { public void setUpInvocation(ClientMessage message) throws Exception {
ManagementHelper.putOperationInvocation(message, "broker", "createAddress", getName(), getRoutingTypes(true)); ManagementHelper.putOperationInvocation(message, "broker", "createAddress", getName(true), getRoutingTypes(true));
} }
@Override @Override
@ -48,7 +48,7 @@ public class CreateAddress extends AddressAbstract {
@Override @Override
public void requestFailed(ClientMessage reply) throws Exception { public void requestFailed(ClientMessage reply) throws Exception {
String errMsg = (String) ManagementHelper.getResult(reply, String.class); String errMsg = (String) ManagementHelper.getResult(reply, String.class);
context.err.println("Failed to create address " + getName() + ". Reason: " + errMsg); context.err.println("Failed to create address " + getName(true) + ". Reason: " + errMsg);
} }
}); });
} }

View File

@ -36,18 +36,18 @@ public class DeleteAddress extends AddressAbstract {
performCoreManagement(new ManagementCallback<ClientMessage>() { performCoreManagement(new ManagementCallback<ClientMessage>() {
@Override @Override
public void setUpInvocation(ClientMessage message) throws Exception { public void setUpInvocation(ClientMessage message) throws Exception {
ManagementHelper.putOperationInvocation(message, "broker", "deleteAddress", getName()); ManagementHelper.putOperationInvocation(message, "broker", "deleteAddress", getName(true));
} }
@Override @Override
public void requestSuccessful(ClientMessage reply) throws Exception { public void requestSuccessful(ClientMessage reply) throws Exception {
context.out.println("Address " + getName() + " deleted successfully."); context.out.println("Address " + getName(true) + " deleted successfully.");
} }
@Override @Override
public void requestFailed(ClientMessage reply) throws Exception { public void requestFailed(ClientMessage reply) throws Exception {
String errMsg = (String) ManagementHelper.getResult(reply, String.class); String errMsg = (String) ManagementHelper.getResult(reply, String.class);
context.err.println("Failed to delete address " + getName() + ". Reason: " + errMsg); context.err.println("Failed to delete address " + getName(true) + ". Reason: " + errMsg);
} }
}); });
} }

View File

@ -41,10 +41,13 @@ public class ShowAddress extends AddressAbstract {
performCoreManagement(new ManagementCallback<ClientMessage>() { performCoreManagement(new ManagementCallback<ClientMessage>() {
@Override @Override
public void setUpInvocation(ClientMessage message) throws Exception { public void setUpInvocation(ClientMessage message) throws Exception {
if (bindings) {
ManagementHelper.putOperationInvocation(message, "broker", "listBindingsForAddress", getName()); if (getName(false) == null) {
ManagementHelper.putOperationInvocation(message, "broker", "listAddresses", "\n");
} else if (bindings) {
ManagementHelper.putOperationInvocation(message, "broker", "listBindingsForAddress", getName(false));
} else { } else {
ManagementHelper.putOperationInvocation(message, "broker", "getAddressInfo", getName()); ManagementHelper.putOperationInvocation(message, "broker", "getAddressInfo", getName(false));
} }
} }
@ -57,7 +60,7 @@ public class ShowAddress extends AddressAbstract {
@Override @Override
public void requestFailed(ClientMessage reply) throws Exception { public void requestFailed(ClientMessage reply) throws Exception {
String errMsg = (String) ManagementHelper.getResult(reply, String.class); String errMsg = (String) ManagementHelper.getResult(reply, String.class);
context.err.println("Failed to show address " + getName() + ". Reason: " + errMsg); context.err.println("Failed to show address " + getName(false) + ". Reason: " + errMsg);
} }
}); });
} }

View File

@ -37,7 +37,7 @@ public class UpdateAddress extends AddressAbstract {
performCoreManagement(new AbstractAction.ManagementCallback<ClientMessage>() { performCoreManagement(new AbstractAction.ManagementCallback<ClientMessage>() {
@Override @Override
public void setUpInvocation(ClientMessage message) throws Exception { public void setUpInvocation(ClientMessage message) throws Exception {
ManagementHelper.putOperationInvocation(message, "broker", "updateAddress", getName(), getRoutingTypes(false)); ManagementHelper.putOperationInvocation(message, "broker", "updateAddress", getName(true), getRoutingTypes(false));
} }
@Override @Override
@ -49,7 +49,7 @@ public class UpdateAddress extends AddressAbstract {
@Override @Override
public void requestFailed(ClientMessage reply) throws Exception { public void requestFailed(ClientMessage reply) throws Exception {
String errMsg = (String) ManagementHelper.getResult(reply, String.class); String errMsg = (String) ManagementHelper.getResult(reply, String.class);
context.err.println("Failed to update address " + getName() + ". Reason: " + errMsg); context.err.println("Failed to update address " + getName(true) + ". Reason: " + errMsg);
} }
}); });
} }

View File

@ -36,8 +36,7 @@ public class CreateQueue extends QueueAbstract {
performCoreManagement(new ManagementCallback<ClientMessage>() { performCoreManagement(new ManagementCallback<ClientMessage>() {
@Override @Override
public void setUpInvocation(ClientMessage message) throws Exception { public void setUpInvocation(ClientMessage message) throws Exception {
String address = getAddress(); ManagementHelper.putOperationInvocation(message, "broker", "createQueue", getAddress(true), getRoutingType(), getName(), getFilter(), isDurable(), getMaxConsumers(-1), isDeleteOnNoConsumers(true), isAutoCreateAddress());
ManagementHelper.putOperationInvocation(message, "broker", "createQueue", address, getRoutingType(), getName(), getFilter(), isDurable(), getMaxConsumers(-1), treatNoConsumers(true), isAutoCreateAddress());
} }
@Override @Override

View File

@ -31,25 +31,28 @@ public class QueueAbstract extends AbstractAction {
@Option(name = "--address", description = "address of the queue (default queue's name)") @Option(name = "--address", description = "address of the queue (default queue's name)")
private String address; private String address;
@Option(name = "--durable", description = "whether the queue is durable or not (default false)") @Option(name = "--durable", description = "whether the queue is durable or not (default input)")
private boolean durable = false; private Boolean durable;
@Option(name = "--delete-on-no-consumers", description = "whether to delete this queue when it's last consumers disconnects)") @Option(name = "--no-durable", description = "whether the queue is durable or not (default input)")
private boolean deleteOnNoConsumers = false; private Boolean noDurable;
@Option(name = "--keep-on-no-consumers", description = "whether to queue this queue when it's last consumers disconnects)") @Option(name = "--delete-on-no-consumers", description = "whether to delete this queue when it's last consumers disconnects (default input)")
private boolean keepOnNoConsumers = false; private Boolean deleteOnNoConsumers;
@Option(name = "--keep-on-no-consumers", description = "whether to queue this queue when it's last consumers disconnects (default input)")
private Boolean keepOnNoConsumers;
@Option(name = "--max-consumers", description = "Maximum number of consumers allowed on this queue at any one time (default no limit)") @Option(name = "--max-consumers", description = "Maximum number of consumers allowed on this queue at any one time (default no limit)")
private Integer maxConsumers; private Integer maxConsumers;
@Option(name = "--auto-create-address", description = "Auto create the address (if it doesn't exist) with default values") @Option(name = "--auto-create-address", description = "Auto create the address (if it doesn't exist) with default values (default input)")
private Boolean autoCreateAddress = false; private Boolean autoCreateAddress;
@Option(name = "--anycast", description = "It will determine this queue as anycast") @Option(name = "--anycast", description = "It will determine this queue as anycast (default input)")
private Boolean anycast; private Boolean anycast;
@Option(name = "--multicast", description = "It will determine this queue as multicast") @Option(name = "--multicast", description = "It will determine this queue as multicast (default input)")
private Boolean multicast; private Boolean multicast;
public void setFilter(String filter) { public void setFilter(String filter) {
@ -60,14 +63,32 @@ public class QueueAbstract extends AbstractAction {
return filter; return filter;
} }
public String getAddress() { public String getAddress(boolean requireInput) {
// just to force asking the queue name first
String queueName = getName();
if (requireInput && (address == null || "".equals(address.trim()))) {
address = input("--address", "Enter the address name. <Enter for " + queueName + ">", null, true);
}
if (address == null || "".equals(address.trim())) { if (address == null || "".equals(address.trim())) {
address = getName(); // if still null, it will use the queueName
address = queueName;
} }
return address; return address;
} }
public boolean isDurable() { public boolean isDurable() {
if (durable == null) {
if (noDurable != null) {
durable = !noDurable.booleanValue();
}
}
if (durable == null) {
durable = inputBoolean("--durable", "Is this a durable queue", false);
}
return durable; return durable;
} }
@ -76,10 +97,6 @@ public class QueueAbstract extends AbstractAction {
return this; return this;
} }
public boolean isDeleteOnNoConsumers() {
return deleteOnNoConsumers;
}
public boolean isKeepOnNoConsumers() { public boolean isKeepOnNoConsumers() {
return keepOnNoConsumers; return keepOnNoConsumers;
} }
@ -148,23 +165,33 @@ public class QueueAbstract extends AbstractAction {
return this; return this;
} }
public Boolean treatNoConsumers(boolean mandatory) { public Boolean isDeleteOnNoConsumers() {
return isDeleteOnNoConsumers(false);
}
public Boolean isDeleteOnNoConsumers(boolean useInput) {
Boolean value = null; Boolean value = null;
if (deleteOnNoConsumers) { if (deleteOnNoConsumers != null) {
value = Boolean.TRUE; value = deleteOnNoConsumers.booleanValue();
} else if (keepOnNoConsumers) { } else if (keepOnNoConsumers != null) {
value = Boolean.FALSE; value = !keepOnNoConsumers.booleanValue();
} }
if (value == null && mandatory) { if (value == null && useInput) {
value = Boolean.FALSE; value = inputBoolean("--delete-on-no-consumers", "Delete on non consumers", false);
deleteOnNoConsumers = false;
keepOnNoConsumers = true;
} }
if (value == null) {
// return null if still null
return null;
}
deleteOnNoConsumers = value.booleanValue();
keepOnNoConsumers = !value.booleanValue();
return value; return value;
} }

View File

@ -28,11 +28,11 @@ public class UpdateQueue extends QueueAbstract {
@Override @Override
public Object execute(ActionContext context) throws Exception { public Object execute(ActionContext context) throws Exception {
super.execute(context); super.execute(context);
createQueue(context); updateQueue(context);
return null; return null;
} }
private void createQueue(final ActionContext context) throws Exception { private void updateQueue(final ActionContext context) throws Exception {
performCoreManagement(new ManagementCallback<ClientMessage>() { performCoreManagement(new ManagementCallback<ClientMessage>() {
@Override @Override
public void setUpInvocation(ClientMessage message) throws Exception { public void setUpInvocation(ClientMessage message) throws Exception {

View File

@ -85,6 +85,20 @@ ${cluster-security.settings}${cluster.settings}${replicated.settings}${shared-st
</security-settings> </security-settings>
<address-settings> <address-settings>
<!-- if you define auto-create on certain queues, management has to be auto-create -->
<address-setting match="activemq.management#">
<dead-letter-address>DLQ</dead-letter-address>
<expiry-address>ExpiryQueue</expiry-address>
<redelivery-delay>0</redelivery-delay>
<!-- with -1 only the global-max-size is in use for limiting -->
<max-size-bytes>-1</max-size-bytes>
<message-counter-history-day-limit>10</message-counter-history-day-limit>
<address-full-policy>${full-policy}</address-full-policy>
<auto-create-queues>true</auto-create-queues>
<auto-create-addresses>true</auto-create-addresses>
<auto-create-jms-queues>true</auto-create-jms-queues>
<auto-create-jms-topics>true</auto-create-jms-topics>
</address-setting>
<!--default for catch all--> <!--default for catch all-->
<address-setting match="#"> <address-setting match="#">
<dead-letter-address>DLQ</dead-letter-address> <dead-letter-address>DLQ</dead-letter-address>
@ -94,6 +108,10 @@ ${cluster-security.settings}${cluster.settings}${replicated.settings}${shared-st
<max-size-bytes>-1</max-size-bytes> <max-size-bytes>-1</max-size-bytes>
<message-counter-history-day-limit>10</message-counter-history-day-limit> <message-counter-history-day-limit>10</message-counter-history-day-limit>
<address-full-policy>${full-policy}</address-full-policy> <address-full-policy>${full-policy}</address-full-policy>
<auto-create-queues>${auto-create}</auto-create-queues>
<auto-create-addresses>${auto-create}</auto-create-addresses>
<auto-create-jms-queues>${auto-create}</auto-create-jms-queues>
<auto-create-jms-topics>${auto-create}</auto-create-jms-topics>
</address-setting> </address-setting>
</address-settings> </address-settings>

View File

@ -1064,5 +1064,8 @@ public interface ActiveMQServerControl {
@Operation(desc = "Get a list of bindings associated with an address", impact = MBeanOperationInfo.INFO) @Operation(desc = "Get a list of bindings associated with an address", impact = MBeanOperationInfo.INFO)
String listBindingsForAddress(String address) throws Exception; String listBindingsForAddress(String address) throws Exception;
@Operation(desc = "List Addresses on the broker", impact = MBeanOperationInfo.INFO)
String listAddresses(@Parameter(name = "separator", desc = "Separator used on the string listing") String separator) throws Exception;
} }

View File

@ -41,6 +41,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -901,6 +902,37 @@ public class ActiveMQServerControlImpl extends AbstractControl implements Active
} }
} }
@Override
public String listAddresses(String separator) throws Exception {
checkStarted();
clearIO();
try {
final Set<SimpleString> addresses = server.getPostOffice().getAddresses();
TreeSet<SimpleString> sortAddress = new TreeSet<>(new Comparator<SimpleString>() {
@Override
public int compare(SimpleString o1, SimpleString o2) {
return o1.toString().compareToIgnoreCase(o2.toString());
}
});
sortAddress.addAll(addresses);
StringBuilder result = new StringBuilder();
for (SimpleString string : sortAddress) {
if (result.length() > 0) {
result.append(separator);
}
result.append(string);
}
return result.toString();
} finally {
blockOnIO();
}
}
@Override @Override
public int getConnectionCount() { public int getConnectionCount() {
checkStarted(); checkStarted();

View File

@ -868,6 +868,11 @@ public class ActiveMQServerControlUsingCoreTest extends ActiveMQServerControlTes
public String listSessionsAsJSON(@Parameter(desc = "a connection ID", name = "connectionID") String connectionID) throws Exception { public String listSessionsAsJSON(@Parameter(desc = "a connection ID", name = "connectionID") String connectionID) throws Exception {
return (String) proxy.invokeOperation("listSessionsAsJSON", connectionID); return (String) proxy.invokeOperation("listSessionsAsJSON", connectionID);
} }
@Override
public String listAddresses(@Parameter(name = "separator", desc = "Separator used on the string listing") String separator) throws Exception {
return (String) proxy.invokeOperation("listAddresses", separator);
}
}; };
} }