This closes #928 merging #928 - ARTEMIS-878 Improving CLI experience around create queue and address
This commit is contained in:
commit
4a00e5c1e3
|
@ -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 {
|
||||
|
|
|
@ -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<String> 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) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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<ClientMessage>() {
|
||||
@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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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<ClientMessage>() {
|
||||
@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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<ClientMessage>() {
|
||||
@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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -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<ClientMessage>() {
|
||||
@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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -78,6 +78,8 @@ import static org.apache.activemq.artemis.core.persistence.impl.journal.JournalR
|
|||
import static org.apache.activemq.artemis.core.persistence.impl.journal.JournalRecordIds.SECURITY_RECORD;
|
||||
import static org.apache.activemq.artemis.core.persistence.impl.journal.JournalRecordIds.SET_SCHEDULED_DELIVERY_TIME;
|
||||
import static org.apache.activemq.artemis.core.persistence.impl.journal.JournalRecordIds.UPDATE_DELIVERY_COUNT;
|
||||
import static org.apache.activemq.artemis.core.persistence.impl.journal.JournalRecordIds.ADDRESS_BINDING_RECORD;
|
||||
|
||||
|
||||
/**
|
||||
* Outputs a String description of the Journals contents.
|
||||
|
@ -572,6 +574,9 @@ public final class DescribeJournal {
|
|||
case SECURITY_RECORD:
|
||||
return AbstractJournalStorageManager.newSecurityRecord(id, buffer);
|
||||
|
||||
case ADDRESS_BINDING_RECORD:
|
||||
return AbstractJournalStorageManager.newAddressBindingEncoding(id, buffer);
|
||||
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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));
|
||||
|
||||
|
|
Loading…
Reference in New Issue