From e2918124516ed5c0b05d93402378e3547e925daf Mon Sep 17 00:00:00 2001 From: Clebert Suconic Date: Fri, 16 Dec 2016 13:05:20 -0500 Subject: [PATCH] NO-JIRA cli improvements --- .../activemq/artemis/cli/commands/Create.java | 41 ++++++++++ .../artemis/cli/commands/InputAbstract.java | 6 +- .../cli/commands/address/AddressAbstract.java | 4 +- .../cli/commands/address/CreateAddress.java | 4 +- .../cli/commands/address/DeleteAddress.java | 6 +- .../cli/commands/address/ShowAddress.java | 11 ++- .../cli/commands/address/UpdateAddress.java | 4 +- .../cli/commands/queue/CreateQueue.java | 3 +- .../cli/commands/queue/QueueAbstract.java | 77 +++++++++++++------ .../cli/commands/queue/UpdateQueue.java | 4 +- .../artemis/cli/commands/etc/broker.xml | 18 +++++ .../management/ActiveMQServerControl.java | 3 + .../impl/ActiveMQServerControlImpl.java | 32 ++++++++ .../ActiveMQServerControlUsingCoreTest.java | 5 ++ 14 files changed, 175 insertions(+), 43 deletions(-) diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Create.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Create.java index 5faa7a73387..6d8a6543cda 100644 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Create.java +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Create.java @@ -185,6 +185,12 @@ public class Create extends InputAbstract { @Option(name = "--no-autotune", description = "Disable auto tuning on the journal.") 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)") String user; @@ -263,6 +269,38 @@ public void setMessageLoadBalancing(MessageLoadBalancingType messageLoadBalancin 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() { return javaOptions; } @@ -720,6 +758,9 @@ public Object run(ActionContext context) throws Exception { filters.put("${full-policy}", "PAGE"); } + + filters.put("${auto-create}", isAutoCreate() ? "true" : "false"); + performAutoTune(filters, aio, dataFolder); write(ETC_BROKER_XML, filters, false); diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/InputAbstract.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/InputAbstract.java index 1b8cd216ef6..9e788f72493 100644 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/InputAbstract.java +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/InputAbstract.java @@ -70,6 +70,10 @@ protected boolean inputBoolean(String propertyName, String prompt, boolean silen } 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()) { return silentDefault; } @@ -81,7 +85,7 @@ protected String input(String propertyName, String prompt, String silentDefault) context.out.println(propertyName + ": is a mandatory property!"); context.out.println(prompt); inputStr = scanner.nextLine(); - if (inputStr.trim().equals("")) { + if (!acceptNull && inputStr.trim().equals("")) { System.out.println("Invalid Entry!"); } else { valid = true; diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/address/AddressAbstract.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/address/AddressAbstract.java index 274b4ffc35c..3eceb034ebb 100644 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/address/AddressAbstract.java +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/address/AddressAbstract.java @@ -42,8 +42,8 @@ public void setName(String name) { this.name = name; } - public String getName() { - if (name == null) { + public String getName(boolean requireInput) { + if (name == null && requireInput) { name = input("--name", "Provide the name of the address", null); } return name; diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/address/CreateAddress.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/address/CreateAddress.java index bb742e9051f..9852d432bd3 100644 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/address/CreateAddress.java +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/address/CreateAddress.java @@ -36,7 +36,7 @@ private void createAddress(final ActionContext context) throws Exception { performCoreManagement(new ManagementCallback() { @Override 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 @@ -48,7 +48,7 @@ public void requestSuccessful(ClientMessage reply) throws Exception { @Override public void requestFailed(ClientMessage reply) throws Exception { 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); } }); } diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/address/DeleteAddress.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/address/DeleteAddress.java index 76cd22afadd..e5ef73198d0 100644 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/address/DeleteAddress.java +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/address/DeleteAddress.java @@ -36,18 +36,18 @@ private void deleteAddress(final ActionContext context) throws Exception { performCoreManagement(new ManagementCallback() { @Override public void setUpInvocation(ClientMessage message) throws Exception { - ManagementHelper.putOperationInvocation(message, "broker", "deleteAddress", getName()); + ManagementHelper.putOperationInvocation(message, "broker", "deleteAddress", getName(true)); } @Override public void requestSuccessful(ClientMessage reply) throws Exception { - context.out.println("Address " + getName() + " deleted successfully."); + context.out.println("Address " + getName(true) + " deleted successfully."); } @Override public void requestFailed(ClientMessage reply) throws Exception { 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); } }); } diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/address/ShowAddress.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/address/ShowAddress.java index 7a858486cea..2b79b021b6d 100644 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/address/ShowAddress.java +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/address/ShowAddress.java @@ -41,10 +41,13 @@ private void showAddress(final ActionContext context) throws Exception { performCoreManagement(new ManagementCallback() { @Override 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 { - ManagementHelper.putOperationInvocation(message, "broker", "getAddressInfo", getName()); + ManagementHelper.putOperationInvocation(message, "broker", "getAddressInfo", getName(false)); } } @@ -57,7 +60,7 @@ public void requestSuccessful(ClientMessage reply) throws Exception { @Override public void requestFailed(ClientMessage reply) throws Exception { 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); } }); } diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/address/UpdateAddress.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/address/UpdateAddress.java index f20ba8d7734..4f56bd99f9c 100644 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/address/UpdateAddress.java +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/address/UpdateAddress.java @@ -37,7 +37,7 @@ private void updateAddress(final ActionContext context) throws Exception { performCoreManagement(new AbstractAction.ManagementCallback() { @Override 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 @@ -49,7 +49,7 @@ public void requestSuccessful(ClientMessage reply) throws Exception { @Override public void requestFailed(ClientMessage reply) throws Exception { 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); } }); } diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/queue/CreateQueue.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/queue/CreateQueue.java index 93c8e786160..ba3756d474b 100644 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/queue/CreateQueue.java +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/queue/CreateQueue.java @@ -36,8 +36,7 @@ private void createQueue(final ActionContext context) throws Exception { performCoreManagement(new ManagementCallback() { @Override public void setUpInvocation(ClientMessage message) throws Exception { - String address = getAddress(); - ManagementHelper.putOperationInvocation(message, "broker", "createQueue", address, getRoutingType(), getName(), getFilter(), isDurable(), getMaxConsumers(-1), treatNoConsumers(true), isAutoCreateAddress()); + ManagementHelper.putOperationInvocation(message, "broker", "createQueue", getAddress(true), getRoutingType(), getName(), getFilter(), isDurable(), getMaxConsumers(-1), isDeleteOnNoConsumers(true), isAutoCreateAddress()); } @Override diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/queue/QueueAbstract.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/queue/QueueAbstract.java index 21947965d89..626064886cd 100644 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/queue/QueueAbstract.java +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/queue/QueueAbstract.java @@ -31,25 +31,28 @@ public class QueueAbstract extends AbstractAction { @Option(name = "--address", description = "address of the queue (default queue's name)") private String address; - @Option(name = "--durable", description = "whether the queue is durable or not (default false)") - private boolean durable = false; + @Option(name = "--durable", description = "whether the queue is durable or not (default input)") + private Boolean durable; - @Option(name = "--delete-on-no-consumers", description = "whether to delete this queue when it's last consumers disconnects)") - private boolean deleteOnNoConsumers = false; + @Option(name = "--no-durable", description = "whether the queue is durable or not (default input)") + private Boolean noDurable; - @Option(name = "--keep-on-no-consumers", description = "whether to queue this queue when it's last consumers disconnects)") - private boolean keepOnNoConsumers = false; + @Option(name = "--delete-on-no-consumers", description = "whether to delete this queue when it's last consumers disconnects (default input)") + 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)") private Integer maxConsumers; - @Option(name = "--auto-create-address", description = "Auto create the address (if it doesn't exist) with default values") - private Boolean autoCreateAddress = false; + @Option(name = "--auto-create-address", description = "Auto create the address (if it doesn't exist) with default values (default input)") + 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; - @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; public void setFilter(String filter) { @@ -60,14 +63,32 @@ public String getFilter() { 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. ", null, true); + } + if (address == null || "".equals(address.trim())) { - address = getName(); + // if still null, it will use the queueName + address = queueName; } return address; } 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; } @@ -76,10 +97,6 @@ public QueueAbstract setDurable(boolean durable) { return this; } - public boolean isDeleteOnNoConsumers() { - return deleteOnNoConsumers; - } - public boolean isKeepOnNoConsumers() { return keepOnNoConsumers; } @@ -148,23 +165,33 @@ public QueueAbstract setMulticast(boolean multicast) { return this; } - public Boolean treatNoConsumers(boolean mandatory) { + public Boolean isDeleteOnNoConsumers() { + return isDeleteOnNoConsumers(false); + } + + public Boolean isDeleteOnNoConsumers(boolean useInput) { Boolean value = null; - if (deleteOnNoConsumers) { - value = Boolean.TRUE; - } else if (keepOnNoConsumers) { - value = Boolean.FALSE; + if (deleteOnNoConsumers != null) { + value = deleteOnNoConsumers.booleanValue(); + } else if (keepOnNoConsumers != null) { + value = !keepOnNoConsumers.booleanValue(); } - if (value == null && mandatory) { - value = Boolean.FALSE; - deleteOnNoConsumers = false; - keepOnNoConsumers = true; + if (value == null && useInput) { + value = inputBoolean("--delete-on-no-consumers", "Delete on non consumers", false); } + if (value == null) { + // return null if still null + return null; + } + + deleteOnNoConsumers = value.booleanValue(); + keepOnNoConsumers = !value.booleanValue(); + return value; } diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/queue/UpdateQueue.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/queue/UpdateQueue.java index cb4d89fdb2a..23a92a48fc6 100644 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/queue/UpdateQueue.java +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/queue/UpdateQueue.java @@ -28,11 +28,11 @@ public class UpdateQueue extends QueueAbstract { @Override public Object execute(ActionContext context) throws Exception { super.execute(context); - createQueue(context); + updateQueue(context); return null; } - private void createQueue(final ActionContext context) throws Exception { + private void updateQueue(final ActionContext context) throws Exception { performCoreManagement(new ManagementCallback() { @Override public void setUpInvocation(ClientMessage message) throws Exception { diff --git a/artemis-cli/src/main/resources/org/apache/activemq/artemis/cli/commands/etc/broker.xml b/artemis-cli/src/main/resources/org/apache/activemq/artemis/cli/commands/etc/broker.xml index 3e0d4e16143..51f10c5fff1 100644 --- a/artemis-cli/src/main/resources/org/apache/activemq/artemis/cli/commands/etc/broker.xml +++ b/artemis-cli/src/main/resources/org/apache/activemq/artemis/cli/commands/etc/broker.xml @@ -85,6 +85,20 @@ ${cluster-security.settings}${cluster.settings}${replicated.settings}${shared-st + + + DLQ + ExpiryQueue + 0 + + -1 + 10 + ${full-policy} + true + true + true + true + DLQ @@ -94,6 +108,10 @@ ${cluster-security.settings}${cluster.settings}${replicated.settings}${shared-st -1 10 ${full-policy} + ${auto-create} + ${auto-create} + ${auto-create} + ${auto-create} diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/ActiveMQServerControl.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/ActiveMQServerControl.java index 55dcb5755ed..bc68469400d 100644 --- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/ActiveMQServerControl.java +++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/ActiveMQServerControl.java @@ -1064,5 +1064,8 @@ void createConnectorService(@Parameter(name = "name", desc = "Name of the connec @Operation(desc = "Get a list of bindings associated with an address", impact = MBeanOperationInfo.INFO) 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; } diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/ActiveMQServerControlImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/ActiveMQServerControlImpl.java index e5e01d02bab..828971f64b3 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/ActiveMQServerControlImpl.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/ActiveMQServerControlImpl.java @@ -41,6 +41,7 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Set; +import java.util.TreeSet; import java.util.concurrent.atomic.AtomicLong; import java.util.stream.Collectors; @@ -901,6 +902,37 @@ public String listBindingsForAddress(String address) throws Exception { } } + + @Override + public String listAddresses(String separator) throws Exception { + checkStarted(); + + clearIO(); + try { + final Set addresses = server.getPostOffice().getAddresses(); + TreeSet sortAddress = new TreeSet<>(new Comparator() { + @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 public int getConnectionCount() { checkStarted(); diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ActiveMQServerControlUsingCoreTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ActiveMQServerControlUsingCoreTest.java index f74b0905834..f6060350804 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ActiveMQServerControlUsingCoreTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ActiveMQServerControlUsingCoreTest.java @@ -868,6 +868,11 @@ public String listConnectionsAsJSON() throws Exception { public String listSessionsAsJSON(@Parameter(desc = "a connection ID", name = "connectionID") String connectionID) throws Exception { 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); + } }; }