Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 14B73200BD4 for ; Fri, 16 Dec 2016 14:17:31 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 13572160AF6; Fri, 16 Dec 2016 13:17:31 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 668D6160B24 for ; Fri, 16 Dec 2016 14:17:29 +0100 (CET) Received: (qmail 11993 invoked by uid 500); 16 Dec 2016 13:17:28 -0000 Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list commits@activemq.apache.org Received: (qmail 11940 invoked by uid 99); 16 Dec 2016 13:17:28 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 16 Dec 2016 13:17:28 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 6D308E040F; Fri, 16 Dec 2016 13:17:28 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: andytaylor@apache.org To: commits@activemq.apache.org Date: Fri, 16 Dec 2016 13:17:29 -0000 Message-Id: In-Reply-To: <3209894be74e4eaaab1ad51e24dee032@git.apache.org> References: <3209894be74e4eaaab1ad51e24dee032@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [2/3] activemq-artemis git commit: ARTEMIS-878 Improving CLI experience around create queue and address archived-at: Fri, 16 Dec 2016 13:17:31 -0000 ARTEMIS-878 Improving CLI experience around create queue and address I reckon the CLI is not the best UX, but this will at least make it consistent with other CLI commands for the new Queue and Address commands Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/6ec7efc9 Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/6ec7efc9 Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/6ec7efc9 Branch: refs/heads/master Commit: 6ec7efc99532945730123f1ee0fccf2b41ef3517 Parents: 6e4388f Author: Clebert Suconic Authored: Thu Dec 15 15:16:59 2016 -0500 Committer: Andy Taylor Committed: Fri Dec 16 13:15:28 2016 +0000 ---------------------------------------------------------------------- .../apache/activemq/artemis/boot/Artemis.java | 4 +- .../apache/activemq/artemis/cli/Artemis.java | 10 +- .../artemis/cli/commands/InputAbstract.java | 41 +++- .../cli/commands/address/AddressAbstract.java | 107 ++++++++++ .../cli/commands/address/CreateAddress.java | 29 +-- .../cli/commands/address/DeleteAddress.java | 15 +- .../cli/commands/address/ShowAddress.java | 13 +- .../cli/commands/address/UpdateAddress.java | 29 +-- .../artemis/cli/commands/queue/CreateQueue.java | 77 +------ .../cli/commands/queue/QueueAbstract.java | 207 +++++++++++++++++++ .../artemis/cli/commands/queue/UpdateQueue.java | 52 +---- .../integration/cli/AddressCommandTest.java | 9 +- .../tests/integration/cli/QueueCommandTest.java | 27 ++- 13 files changed, 396 insertions(+), 224 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6ec7efc9/artemis-boot/src/main/java/org/apache/activemq/artemis/boot/Artemis.java ---------------------------------------------------------------------- diff --git a/artemis-boot/src/main/java/org/apache/activemq/artemis/boot/Artemis.java b/artemis-boot/src/main/java/org/apache/activemq/artemis/boot/Artemis.java index bbe1574..5cf374f 100644 --- a/artemis-boot/src/main/java/org/apache/activemq/artemis/boot/Artemis.java +++ b/artemis-boot/src/main/java/org/apache/activemq/artemis/boot/Artemis.java @@ -123,10 +123,10 @@ public class Artemis { URLClassLoader loader = new URLClassLoader(urls.toArray(new URL[urls.size()])); Thread.currentThread().setContextClassLoader(loader); Class clazz = loader.loadClass("org.apache.activemq.artemis.cli.Artemis"); - Method method = clazz.getMethod("execute", File.class, File.class, args.getClass()); + Method method = clazz.getMethod("execute", Boolean.TYPE, File.class, File.class, args.getClass()); try { - return method.invoke(null, fileHome, fileInstance, args); + return method.invoke(null, true, fileHome, fileInstance, args); } catch (InvocationTargetException e) { throw e.getTargetException(); } finally { http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6ec7efc9/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/Artemis.java ---------------------------------------------------------------------- diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/Artemis.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/Artemis.java index 8edf871..0f320ec 100644 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/Artemis.java +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/Artemis.java @@ -26,6 +26,7 @@ import org.apache.activemq.artemis.cli.commands.Action; import org.apache.activemq.artemis.cli.commands.ActionContext; import org.apache.activemq.artemis.cli.commands.Create; import org.apache.activemq.artemis.cli.commands.HelpAction; +import org.apache.activemq.artemis.cli.commands.InputAbstract; import org.apache.activemq.artemis.cli.commands.Kill; import org.apache.activemq.artemis.cli.commands.Mask; import org.apache.activemq.artemis.cli.commands.Run; @@ -71,7 +72,7 @@ public class Artemis { String instance = System.getProperty("artemis.instance"); File fileInstance = instance != null ? new File(instance) : null; - execute(fileHome, fileInstance, args); + execute(true, fileHome, fileInstance, args); } public static Object internalExecute(String... args) throws Exception { @@ -79,10 +80,13 @@ public class Artemis { } public static Object execute(File artemisHome, File artemisInstance, List args) throws Exception { - return execute(artemisHome, artemisInstance, args.toArray(new String[args.size()])); + return execute(false, artemisHome, artemisInstance, args.toArray(new String[args.size()])); } - public static Object execute(File artemisHome, File artemisInstance, String... args) throws Exception { + public static Object execute(boolean inputEnabled, File artemisHome, File artemisInstance, String... args) throws Exception { + if (inputEnabled) { + InputAbstract.enableInput(); + } try { return internalExecute(artemisHome, artemisInstance, args); } catch (ConfigurationException configException) { http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6ec7efc9/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/InputAbstract.java ---------------------------------------------------------------------- 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 5625c9d..1b8cd21 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 @@ -25,19 +25,52 @@ public class InputAbstract extends ActionAbstract { private Scanner scanner; + private static boolean inputEnabled = false; + + /** + * Test cases validating or using the CLI cannot deal with inputs, + * so they are generally disabled, however the main method from the CLI will enable it back. */ + public static void enableInput() { + inputEnabled = true; + } + @Option(name = "--silent", 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; + return silentInput || !inputEnabled; } public void setSilentInput(boolean silentInput) { this.silentInput = silentInput; } + + protected boolean inputBoolean(String propertyName, String prompt, boolean silentDefault) { + if (isSilentInput()) { + return silentDefault; + } + + Boolean booleanValue = null; + do { + String value = input(propertyName, prompt + ", valid values are Y,N,True,False", Boolean.toString(silentDefault)); + + switch (value.toUpperCase().trim()) { + case "TRUE": + case "Y": + booleanValue = Boolean.TRUE; break; + + case "FALSE": + case "N": + booleanValue = Boolean.FALSE; break; + } + } while (booleanValue == null); + + return booleanValue.booleanValue(); + } + protected String input(String propertyName, String prompt, String silentDefault) { - if (silentInput) { + if (isSilentInput()) { return silentDefault; } @@ -45,7 +78,7 @@ public class InputAbstract extends ActionAbstract { boolean valid = false; System.out.println(); do { - context.out.println(propertyName + ": mandatory:"); + context.out.println(propertyName + ": is a mandatory property!"); context.out.println(prompt); inputStr = scanner.nextLine(); if (inputStr.trim().equals("")) { @@ -59,7 +92,7 @@ public class InputAbstract extends ActionAbstract { } protected String inputPassword(String propertyName, String prompt, String silentDefault) { - if (silentInput) { + if (isSilentInput()) { return silentDefault; } http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6ec7efc9/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/address/AddressAbstract.java ---------------------------------------------------------------------- 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 new file mode 100644 index 0000000..274b4ff --- /dev/null +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/address/AddressAbstract.java @@ -0,0 +1,107 @@ +/** + * 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.address; + +import io.airlift.airline.Option; +import org.apache.activemq.artemis.cli.commands.AbstractAction; + +public abstract class AddressAbstract extends AbstractAction { + + @Option(name = "--name", description = "The name of this address") + private String name; + + @Option(name = "--anycast", description = "It will determine this address as anycast") + private Boolean anycast; + + @Option(name = "--no-anycast", description = "It will determine this address as anycast") + private Boolean noAnycast; + + @Option(name = "--multicast", description = "It will determine this address as multicast") + private Boolean multicast; + + @Option(name = "--no-multicast", description = "It will determine this address as multicast") + private Boolean noMulticast; + + + public void setName(String name) { + this.name = name; + } + + public String getName() { + if (name == null) { + name = input("--name", "Provide the name of the address", null); + } + return name; + } + + public String getRoutingTypes(boolean useDefault) { + StringBuffer buffer = new StringBuffer(); + + if (isAnycast()) { + buffer.append("ANYCAST"); + } + + if (isMulticast()) { + if (isAnycast()) { + buffer.append(","); + } + buffer.append("MULTICAST"); + } + + if (!isAnycast() && !isMulticast()) { + if (useDefault) { + return "MULTICAST"; // the default; + } else { + return null; + } + + } + + return buffer.toString(); + } + + public boolean isAnycast() { + if (noAnycast != null) { + anycast = !noAnycast.booleanValue(); + } + if (anycast == null) { + anycast = inputBoolean("--anycast", "Will this address support anycast queues", false); + } + return anycast; + } + + public AddressAbstract setAnycast(boolean anycast) { + this.anycast = anycast; + return this; + } + + public boolean isMulticast() { + if (noMulticast != null) { + multicast = !noMulticast.booleanValue(); + } + if (multicast == null) { + multicast = inputBoolean("--multicast", "Will this address support multicast queues", true); + } + return multicast; + } + + public AddressAbstract setMulticast(boolean multicast) { + this.multicast = multicast; + return this; + } +} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6ec7efc9/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/address/CreateAddress.java ---------------------------------------------------------------------- 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 ab8e69f..bb742e9 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 @@ -18,21 +18,12 @@ package org.apache.activemq.artemis.cli.commands.address; import io.airlift.airline.Command; -import io.airlift.airline.Option; -import org.apache.activemq.artemis.api.config.ActiveMQDefaultConfiguration; import org.apache.activemq.artemis.api.core.client.ClientMessage; import org.apache.activemq.artemis.api.core.management.ManagementHelper; -import org.apache.activemq.artemis.cli.commands.AbstractAction; import org.apache.activemq.artemis.cli.commands.ActionContext; @Command(name = "create", description = "create an address") -public class CreateAddress extends AbstractAction { - - @Option(name = "--name", description = "The name of this address") - String name; - - @Option(name = "--routingTypes", description = "The routing types supported by this address, options are 'anycast' or 'multicast', enter comma separated list, defaults to 'multicast' only") - String routingTypes = ActiveMQDefaultConfiguration.getDefaultRoutingType().name(); +public class CreateAddress extends AddressAbstract { @Override public Object execute(ActionContext context) throws Exception { @@ -45,7 +36,7 @@ public class CreateAddress extends AbstractAction { performCoreManagement(new ManagementCallback() { @Override public void setUpInvocation(ClientMessage message) throws Exception { - ManagementHelper.putOperationInvocation(message, "broker", "createAddress", getName(), routingTypes); + ManagementHelper.putOperationInvocation(message, "broker", "createAddress", getName(), getRoutingTypes(true)); } @Override @@ -62,20 +53,4 @@ public class CreateAddress extends AbstractAction { }); } - public void setName(String name) { - this.name = name; - } - - public String getName() { - return name; - } - - public String getRoutingTypes() { - return routingTypes; - } - - public void setRoutingTypes(String routingTypes) { - this.routingTypes = routingTypes; - } - } http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6ec7efc9/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/address/DeleteAddress.java ---------------------------------------------------------------------- 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 c63d4f9..76cd22a 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 @@ -18,17 +18,12 @@ package org.apache.activemq.artemis.cli.commands.address; import io.airlift.airline.Command; -import io.airlift.airline.Option; import org.apache.activemq.artemis.api.core.client.ClientMessage; import org.apache.activemq.artemis.api.core.management.ManagementHelper; -import org.apache.activemq.artemis.cli.commands.AbstractAction; import org.apache.activemq.artemis.cli.commands.ActionContext; @Command(name = "delete", description = "delete an address") -public class DeleteAddress extends AbstractAction { - - @Option(name = "--name", description = "The name of this address") - String name; +public class DeleteAddress extends AddressAbstract { @Override public Object execute(ActionContext context) throws Exception { @@ -56,12 +51,4 @@ public class DeleteAddress extends AbstractAction { } }); } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } } http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6ec7efc9/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/address/ShowAddress.java ---------------------------------------------------------------------- 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 a736cf2..7a85848 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 @@ -21,14 +21,11 @@ import io.airlift.airline.Command; import io.airlift.airline.Option; import org.apache.activemq.artemis.api.core.client.ClientMessage; import org.apache.activemq.artemis.api.core.management.ManagementHelper; -import org.apache.activemq.artemis.cli.commands.AbstractAction; import org.apache.activemq.artemis.cli.commands.ActionContext; @Command(name = "show", description = "Get the selected address") -public class ShowAddress extends AbstractAction { +public class ShowAddress extends AddressAbstract { - @Option(name = "--name", description = "The name of this address") - String name; @Option(name = "--bindings", description = "Shows the bindings for this address") boolean bindings; @@ -65,14 +62,6 @@ public class ShowAddress extends AbstractAction { }); } - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - public boolean isBindings() { return bindings; } http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6ec7efc9/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/address/UpdateAddress.java ---------------------------------------------------------------------- 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 1a9c247..f20ba8d 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 @@ -18,20 +18,13 @@ package org.apache.activemq.artemis.cli.commands.address; import io.airlift.airline.Command; -import io.airlift.airline.Option; import org.apache.activemq.artemis.api.core.client.ClientMessage; import org.apache.activemq.artemis.api.core.management.ManagementHelper; import org.apache.activemq.artemis.cli.commands.AbstractAction; import org.apache.activemq.artemis.cli.commands.ActionContext; @Command(name = "update", description = "update an address") -public class UpdateAddress extends AbstractAction { - - @Option(name = "--name", description = "The name of this address", required = true) - String name; - - @Option(name = "--routingTypes", description = "The routing types supported by this address, options are 'anycast' or 'multicast', enter comma separated list") - String routingTypes = null; +public class UpdateAddress extends AddressAbstract { @Override public Object execute(ActionContext context) throws Exception { @@ -44,7 +37,7 @@ public class UpdateAddress extends AbstractAction { performCoreManagement(new AbstractAction.ManagementCallback() { @Override public void setUpInvocation(ClientMessage message) throws Exception { - ManagementHelper.putOperationInvocation(message, "broker", "updateAddress", name, routingTypes); + ManagementHelper.putOperationInvocation(message, "broker", "updateAddress", getName(), getRoutingTypes(false)); } @Override @@ -56,24 +49,8 @@ public class UpdateAddress extends AbstractAction { @Override public void requestFailed(ClientMessage reply) throws Exception { String errMsg = (String) ManagementHelper.getResult(reply, String.class); - context.err.println("Failed to update address " + name + ". Reason: " + errMsg); + context.err.println("Failed to update address " + getName() + ". Reason: " + errMsg); } }); } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getRoutingTypes() { - return routingTypes; - } - - public void setRoutingTypes(String routingTypes) { - this.routingTypes = routingTypes; - } } http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6ec7efc9/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/queue/CreateQueue.java ---------------------------------------------------------------------- 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 78a6d33..a76b3c6 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 @@ -18,38 +18,12 @@ package org.apache.activemq.artemis.cli.commands.queue; import io.airlift.airline.Command; -import io.airlift.airline.Option; import org.apache.activemq.artemis.api.core.client.ClientMessage; import org.apache.activemq.artemis.api.core.management.ManagementHelper; import org.apache.activemq.artemis.cli.commands.ActionContext; -import org.apache.activemq.artemis.cli.commands.AbstractAction; @Command(name = "create", description = "create a queue or topic") -public class CreateQueue extends AbstractAction { - - @Option(name = "--name", description = "queue name") - String name; - - @Option(name = "--filter", description = "queue's filter string (default null)") - String filter = null; - - @Option(name = "--address", description = "address of the queue (default queue's name)") - String address; - - @Option(name = "--durable", description = "whether the queue is durable or not (default false)") - boolean durable = false; - - @Option(name = "--deleteOnNoConsumers", description = "whether to delete this queue when it's last consumers disconnects)") - boolean deleteOnNoConsumers = false; - - @Option(name = "--maxConsumers", description = "Maximum number of consumers allowed on this queue at any one time (default no limit)") - int maxConsumers = -1; - - @Option(name = "--autoCreateAddress", description = "Auto create the address (if it doesn't exist) with default values") - boolean autoCreateAddress = false; - - @Option(name = "--routingType", description = "The routing type supported by this queue, options are 'anycast' or 'multicast'", required = true) - String routingType; +public class CreateQueue extends QueueAbstract { @Override public Object execute(ActionContext context) throws Exception { @@ -58,19 +32,12 @@ public class CreateQueue extends AbstractAction { return null; } - public String getAddress() { - if (address == null || "".equals(address.trim())) { - address = getName(); - } - return address.trim(); - } - 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, routingType, getName(), filter, durable, maxConsumers, deleteOnNoConsumers, autoCreateAddress); + ManagementHelper.putOperationInvocation(message, "broker", "createQueue", address, getRoutingType(), getName(), getFilter(), isDurable(), getMaxConsumers(), treatNoConsumers(true), isAutoCreateAddress()); } @Override @@ -86,44 +53,4 @@ public class CreateQueue extends AbstractAction { } }); } - - public void setFilter(String filter) { - this.filter = filter; - } - - public void setAutoCreateAddress(boolean autoCreateAddress) { - this.autoCreateAddress = autoCreateAddress; - } - - public void setMaxConsumers(int maxConsumers) { - this.maxConsumers = maxConsumers; - } - - public void setDeleteOnNoConsumers(boolean deleteOnNoConsumers) { - this.deleteOnNoConsumers = deleteOnNoConsumers; - } - - public void setAddress(String address) { - this.address = address; - } - - public void setName(String name) { - this.name = name; - } - - public String getName() { - if (name == null) { - name = input("--name", "Please provide the destination name:", ""); - } - - return name; - } - - public void setRoutingType(String routingType) { - this.routingType = routingType; - } - - public String getRoutingType() { - return routingType; - } } http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6ec7efc9/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/queue/QueueAbstract.java ---------------------------------------------------------------------- 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 new file mode 100644 index 0000000..beeb179 --- /dev/null +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/queue/QueueAbstract.java @@ -0,0 +1,207 @@ +/** + * 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.queue; + +import io.airlift.airline.Option; +import org.apache.activemq.artemis.cli.commands.AbstractAction; + +public class QueueAbstract extends AbstractAction { + + @Option(name = "--name", description = "queue name") + private String name; + + @Option(name = "--filter", description = "queue's filter string (default null)") + private String filter = null; + + @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 = "--delete-on-no-consumers", description = "whether to delete this queue when it's last consumers disconnects)") + private boolean deleteOnNoConsumers = false; + + @Option(name = "--keep-on-no-consumers", description = "whether to queue this queue when it's last consumers disconnects)") + private boolean keepOnNoConsumers = false; + + @Option(name = "--max-consumers", description = "Maximum number of consumers allowed on this queue at any one time (default no limit)") + private int maxConsumers = -1; + + @Option(name = "--auto-create-ddress", description = "Auto create the address (if it doesn't exist) with default values") + private Boolean autoCreateAddress = false; + + @Option(name = "--anycast", description = "It will determine this queue as anycast") + private Boolean anycast; + + @Option(name = "--multicast", description = "It will determine this queue as multicast") + private Boolean multicast; + + public void setFilter(String filter) { + this.filter = filter; + } + + public String getFilter() { + return filter; + } + + public String getAddress() { + if (address == null || "".equals(address.trim())) { + address = getName(); + } + return address; + } + + public boolean isDurable() { + return durable; + } + + public QueueAbstract setDurable(boolean durable) { + this.durable = durable; + return this; + } + + public boolean isDeleteOnNoConsumers() { + return deleteOnNoConsumers; + } + + public boolean isKeepOnNoConsumers() { + return keepOnNoConsumers; + } + + public QueueAbstract setKeepOnNoConsumers(boolean keepOnNoConsumers) { + this.keepOnNoConsumers = keepOnNoConsumers; + return this; + } + + public int getMaxConsumers() { + return maxConsumers; + } + + public boolean isAutoCreateAddress() { + if (autoCreateAddress == null) { + autoCreateAddress = inputBoolean("--auto-create-address", "should auto create the address if it doesn't exist", false); + } + return autoCreateAddress; + } + + public QueueAbstract setAutoCreateAddress(boolean autoCreateAddress) { + this.autoCreateAddress = autoCreateAddress; + return this; + } + + public boolean isAnycast() { + if (anycast == null) { + if (multicast != null) { + // if multicast is not null, it should be the opposite + anycast = !multicast.booleanValue(); + } + + if (anycast == null) { + // if it is still null + anycast = inputBoolean("--anycast", "is this an anycast queue", false); + } + } + return anycast; + } + + public QueueAbstract setAnycast(boolean anycast) { + this.anycast = anycast; + return this; + } + + public boolean isMulticast() { + if (multicast == null) { + if (anycast != null) { + // if anycast is not null, it should be the opposite + multicast = !anycast.booleanValue(); + } + + if (multicast == null) { + // if it is still null + multicast = inputBoolean("--multicast", "is this a multicast queue", false); + } + } + return multicast; + } + + public QueueAbstract setMulticast(boolean multicast) { + this.multicast = multicast; + return this; + } + + public Boolean treatNoConsumers(boolean mandatory) { + + Boolean value = null; + + if (deleteOnNoConsumers) { + value = Boolean.TRUE; + } else if (keepOnNoConsumers) { + value = Boolean.FALSE; + } + + + if (value == null && mandatory) { + value = Boolean.FALSE; + deleteOnNoConsumers = false; + keepOnNoConsumers = true; + } + + return value; + } + + public void setMaxConsumers(int maxConsumers) { + this.maxConsumers = maxConsumers; + } + + public void setDeleteOnNoConsumers(boolean deleteOnNoConsumers) { + this.deleteOnNoConsumers = deleteOnNoConsumers; + } + + public void setAddress(String address) { + this.address = address; + } + + public void setName(String name) { + this.name = name; + } + + public String getName() { + if (name == null) { + name = input("--name", "Please provide the destination name:", ""); + } + + return name; + } + + public String getRoutingType() { + if (isAnycast() && isMulticast()) { + throw new IllegalArgumentException("--multicast and --anycast are exclusive options for a Queue"); + } + + if (isMulticast()) { + return "MULTICAST"; + } else if (anycast) { + return "ANYCAST"; + } else { + return null; + } + } + + +} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6ec7efc9/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/queue/UpdateQueue.java ---------------------------------------------------------------------- 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 d457771..b134269 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 @@ -18,26 +18,12 @@ package org.apache.activemq.artemis.cli.commands.queue; import io.airlift.airline.Command; -import io.airlift.airline.Option; import org.apache.activemq.artemis.api.core.client.ClientMessage; import org.apache.activemq.artemis.api.core.management.ManagementHelper; -import org.apache.activemq.artemis.cli.commands.AbstractAction; import org.apache.activemq.artemis.cli.commands.ActionContext; @Command(name = "update", description = "update a core queue") -public class UpdateQueue extends AbstractAction { - - @Option(name = "--name", description = "name", required = true) - String name; - - @Option(name = "--deleteOnNoConsumers", description = "whether to delete when it's last consumers disconnects)") - Boolean deleteOnNoConsumers = null; - - @Option(name = "--maxConsumers", description = "Maximum number of consumers allowed at any one time") - Integer maxConsumers = null; - - @Option(name = "--routingType", description = "The routing type supported by this queue, options are 'anycast' or 'multicast'") - String routingType = null; +public class UpdateQueue extends QueueAbstract { @Override public Object execute(ActionContext context) throws Exception { @@ -50,7 +36,7 @@ public class UpdateQueue extends AbstractAction { performCoreManagement(new ManagementCallback() { @Override public void setUpInvocation(ClientMessage message) throws Exception { - ManagementHelper.putOperationInvocation(message, "broker", "updateQueue", name, routingType, maxConsumers, deleteOnNoConsumers); + ManagementHelper.putOperationInvocation(message, "broker", "updateQueue", getName(), getRoutingType(), getMaxConsumers(), isDeleteOnNoConsumers()); } @Override @@ -62,41 +48,9 @@ public class UpdateQueue extends AbstractAction { @Override public void requestFailed(ClientMessage reply) throws Exception { String errMsg = (String) ManagementHelper.getResult(reply, String.class); - context.err.println("Failed to update " + name + ". Reason: " + errMsg); + context.err.println("Failed to update " + getName() + ". Reason: " + errMsg); } }); } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public Boolean getDeleteOnNoConsumers() { - return deleteOnNoConsumers; - } - - public void setDeleteOnNoConsumers(boolean deleteOnNoConsumers) { - this.deleteOnNoConsumers = deleteOnNoConsumers; - } - - public Integer getMaxConsumers() { - return maxConsumers; - } - - public void setMaxConsumers(int maxConsumers) { - this.maxConsumers = maxConsumers; - } - - public String getRoutingType() { - return routingType; - } - - public void setRoutingType(String routingType) { - this.routingType = routingType; - } } http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6ec7efc9/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cli/AddressCommandTest.java ---------------------------------------------------------------------- diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cli/AddressCommandTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cli/AddressCommandTest.java index c44dba2..9b86f01 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cli/AddressCommandTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cli/AddressCommandTest.java @@ -54,7 +54,8 @@ public class AddressCommandTest extends JMSTestBase { String address = "address"; CreateAddress command = new CreateAddress(); command.setName(address); - command.setRoutingTypes(RoutingType.ANYCAST.toString() + "," + RoutingType.MULTICAST.toString()); + command.setAnycast(true); + command.setMulticast(true); command.execute(new ActionContext(System.in, new PrintStream(output), new PrintStream(error))); checkExecutionPassed(command); AddressInfo addressInfo = server.getAddressInfo(new SimpleString(address)); @@ -167,7 +168,8 @@ public class AddressCommandTest extends JMSTestBase { final UpdateAddress updateAddress = new UpdateAddress(); updateAddress.setName(addressName); - updateAddress.setRoutingTypes(RoutingType.MULTICAST.toString() + ',' + RoutingType.ANYCAST.toString()); + updateAddress.setAnycast(true); + updateAddress.setMulticast(true); updateAddress.execute(new ActionContext(System.in, new PrintStream(output), new PrintStream(error))); checkExecutionPassed(updateAddress); @@ -195,7 +197,8 @@ public class AddressCommandTest extends JMSTestBase { final UpdateAddress updateAddress = new UpdateAddress(); updateAddress.setName(addressName); - updateAddress.setRoutingTypes(RoutingType.ANYCAST.toString()); + updateAddress.setAnycast(true); + updateAddress.setMulticast(false); updateAddress.execute(new ActionContext(System.in, new PrintStream(output), new PrintStream(error))); final String expectedErrorMessage = MessageFormat.format("Can''t remove routing type {0}, queues exists for address: {1}. Please delete queues before removing this routing type.", RoutingType.MULTICAST, addressName); http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6ec7efc9/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cli/QueueCommandTest.java ---------------------------------------------------------------------- diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cli/QueueCommandTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cli/QueueCommandTest.java index 58f0019..c254eed 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cli/QueueCommandTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cli/QueueCommandTest.java @@ -56,7 +56,8 @@ public class QueueCommandTest extends JMSTestBase { String queueName = "queue1"; CreateQueue command = new CreateQueue(); command.setName(queueName); - command.setRoutingType(RoutingType.MULTICAST.name()); + command.setMulticast(true); + command.setAnycast(false); command.execute(new ActionContext(System.in, new PrintStream(output), new PrintStream(error))); checkExecutionFailure(command, "AMQ119203: Address Does Not Exist:"); assertFalse(server.queueQuery(new SimpleString(queueName)).isExists()); @@ -68,7 +69,8 @@ public class QueueCommandTest extends JMSTestBase { CreateQueue command = new CreateQueue(); command.setName(queueName); command.setAutoCreateAddress(true); - command.setRoutingType(RoutingType.MULTICAST.name()); + command.setMulticast(true); + command.setAnycast(false); command.execute(new ActionContext(System.in, new PrintStream(output), new PrintStream(error))); checkExecutionPassed(command); assertNotNull(server.getAddressInfo(new SimpleString(queueName))); @@ -87,7 +89,8 @@ public class QueueCommandTest extends JMSTestBase { CreateQueue command = new CreateQueue(); command.setName(queueName); command.setAutoCreateAddress(false); - command.setRoutingType(RoutingType.MULTICAST.name()); + command.setMulticast(true); + command.setAnycast(false); command.setAddress(address); server.createOrUpdateAddressInfo(new AddressInfo(new SimpleString(address), RoutingType.MULTICAST)); @@ -111,7 +114,8 @@ public class QueueCommandTest extends JMSTestBase { command.setName(queueName); command.setFilter("color='green'"); command.setAutoCreateAddress(true); - command.setRoutingType(RoutingType.MULTICAST.name()); + command.setMulticast(true); + command.setAnycast(false); command.execute(new ActionContext(System.in, new PrintStream(output), new PrintStream(error))); checkExecutionPassed(command); @@ -129,7 +133,8 @@ public class QueueCommandTest extends JMSTestBase { command.setName(queueName); command.setFilter("color='green'"); command.setAutoCreateAddress(true); - command.setRoutingType(RoutingType.MULTICAST.name()); + command.setMulticast(true); + command.setAnycast(false); command.execute(new ActionContext()); command.execute(new ActionContext(System.in, new PrintStream(output), new PrintStream(error))); checkExecutionFailure(command, "AMQ119019: Queue already exists " + queueName); @@ -143,7 +148,8 @@ public class QueueCommandTest extends JMSTestBase { command.setName(queueName.toString()); command.setFilter("color='green'"); command.setAutoCreateAddress(true); - command.setRoutingType(RoutingType.MULTICAST.name()); + command.setMulticast(true); + command.setAnycast(false); command.execute(new ActionContext()); DeleteQueue delete = new DeleteQueue(); @@ -174,7 +180,8 @@ public class QueueCommandTest extends JMSTestBase { command.setName(queueName.toString()); command.setFilter("color='green'"); command.setAutoCreateAddress(true); - command.setRoutingType(RoutingType.MULTICAST.name()); + command.setMulticast(true); + command.setAnycast(false); command.execute(new ActionContext()); server.locateQueue(queueName).addConsumer(new DummyServerConsumer()); @@ -193,7 +200,8 @@ public class QueueCommandTest extends JMSTestBase { command.setName(queueName.toString()); command.setFilter("color='green'"); command.setAutoCreateAddress(true); - command.setRoutingType(RoutingType.MULTICAST.name()); + command.setMulticast(true); + command.setAnycast(false); command.execute(new ActionContext()); server.locateQueue(queueName).addConsumer(new DummyServerConsumer()); @@ -213,7 +221,8 @@ public class QueueCommandTest extends JMSTestBase { command.setName(queueName.toString()); command.setFilter("color='green'"); command.setAutoCreateAddress(true); - command.setRoutingType(RoutingType.MULTICAST.name()); + command.setMulticast(true); + command.setAnycast(false); command.execute(new ActionContext()); assertNotNull(server.getAddressInfo(queueName));