NO-JIRA cli improvements
This commit is contained in:
parent
df1ec5bc49
commit
1bed2c9512
|
@ -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 class Create extends InputAbstract {
|
|||
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 class Create extends InputAbstract {
|
|||
filters.put("${full-policy}", "PAGE");
|
||||
}
|
||||
|
||||
|
||||
filters.put("${auto-create}", isAutoCreate() ? "true" : "false");
|
||||
|
||||
performAutoTune(filters, aio, dataFolder);
|
||||
|
||||
write(ETC_BROKER_XML, filters, false);
|
||||
|
|
|
@ -70,6 +70,10 @@ public class InputAbstract extends ActionAbstract {
|
|||
}
|
||||
|
||||
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 @@ public class InputAbstract extends ActionAbstract {
|
|||
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;
|
||||
|
|
|
@ -42,8 +42,8 @@ public abstract class AddressAbstract extends AbstractAction {
|
|||
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;
|
||||
|
|
|
@ -36,7 +36,7 @@ public class CreateAddress extends AddressAbstract {
|
|||
performCoreManagement(new ManagementCallback<ClientMessage>() {
|
||||
@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 class CreateAddress extends AddressAbstract {
|
|||
@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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -36,18 +36,18 @@ public class DeleteAddress extends AddressAbstract {
|
|||
performCoreManagement(new ManagementCallback<ClientMessage>() {
|
||||
@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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -41,10 +41,13 @@ public class ShowAddress extends AddressAbstract {
|
|||
performCoreManagement(new ManagementCallback<ClientMessage>() {
|
||||
@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 class ShowAddress extends AddressAbstract {
|
|||
@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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ public class UpdateAddress extends AddressAbstract {
|
|||
performCoreManagement(new AbstractAction.ManagementCallback<ClientMessage>() {
|
||||
@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 class UpdateAddress extends AddressAbstract {
|
|||
@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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -36,8 +36,7 @@ public class CreateQueue extends QueueAbstract {
|
|||
performCoreManagement(new ManagementCallback<ClientMessage>() {
|
||||
@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
|
||||
|
|
|
@ -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 class QueueAbstract extends AbstractAction {
|
|||
return filter;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
public String getAddress(boolean requireInput) {
|
||||
// just to force asking the queue name first
|
||||
String queueName = getName();
|
||||
|
||||
if (requireInput && (address == null || "".equals(address.trim()))) {
|
||||
address = input("--address", "Enter the address name. <Enter for " + queueName + ">", null, true);
|
||||
}
|
||||
|
||||
if (address == null || "".equals(address.trim())) {
|
||||
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 class QueueAbstract extends AbstractAction {
|
|||
return this;
|
||||
}
|
||||
|
||||
public boolean isDeleteOnNoConsumers() {
|
||||
return deleteOnNoConsumers;
|
||||
}
|
||||
|
||||
public boolean isKeepOnNoConsumers() {
|
||||
return keepOnNoConsumers;
|
||||
}
|
||||
|
@ -148,23 +165,33 @@ public class QueueAbstract extends AbstractAction {
|
|||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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<ClientMessage>() {
|
||||
@Override
|
||||
public void setUpInvocation(ClientMessage message) throws Exception {
|
||||
|
|
|
@ -85,6 +85,20 @@ ${cluster-security.settings}${cluster.settings}${replicated.settings}${shared-st
|
|||
</security-settings>
|
||||
|
||||
<address-settings>
|
||||
<!-- if you define auto-create on certain queues, management has to be auto-create -->
|
||||
<address-setting match="activemq.management#">
|
||||
<dead-letter-address>DLQ</dead-letter-address>
|
||||
<expiry-address>ExpiryQueue</expiry-address>
|
||||
<redelivery-delay>0</redelivery-delay>
|
||||
<!-- with -1 only the global-max-size is in use for limiting -->
|
||||
<max-size-bytes>-1</max-size-bytes>
|
||||
<message-counter-history-day-limit>10</message-counter-history-day-limit>
|
||||
<address-full-policy>${full-policy}</address-full-policy>
|
||||
<auto-create-queues>true</auto-create-queues>
|
||||
<auto-create-addresses>true</auto-create-addresses>
|
||||
<auto-create-jms-queues>true</auto-create-jms-queues>
|
||||
<auto-create-jms-topics>true</auto-create-jms-topics>
|
||||
</address-setting>
|
||||
<!--default for catch all-->
|
||||
<address-setting match="#">
|
||||
<dead-letter-address>DLQ</dead-letter-address>
|
||||
|
@ -94,6 +108,10 @@ ${cluster-security.settings}${cluster.settings}${replicated.settings}${shared-st
|
|||
<max-size-bytes>-1</max-size-bytes>
|
||||
<message-counter-history-day-limit>10</message-counter-history-day-limit>
|
||||
<address-full-policy>${full-policy}</address-full-policy>
|
||||
<auto-create-queues>${auto-create}</auto-create-queues>
|
||||
<auto-create-addresses>${auto-create}</auto-create-addresses>
|
||||
<auto-create-jms-queues>${auto-create}</auto-create-jms-queues>
|
||||
<auto-create-jms-topics>${auto-create}</auto-create-jms-topics>
|
||||
</address-setting>
|
||||
</address-settings>
|
||||
|
||||
|
|
|
@ -1064,5 +1064,8 @@ public interface ActiveMQServerControl {
|
|||
|
||||
@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;
|
||||
}
|
||||
|
||||
|
|
|
@ -41,6 +41,7 @@ import java.util.List;
|
|||
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 class ActiveMQServerControlImpl extends AbstractControl implements Active
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String listAddresses(String separator) throws Exception {
|
||||
checkStarted();
|
||||
|
||||
clearIO();
|
||||
try {
|
||||
final Set<SimpleString> addresses = server.getPostOffice().getAddresses();
|
||||
TreeSet<SimpleString> sortAddress = new TreeSet<>(new Comparator<SimpleString>() {
|
||||
@Override
|
||||
public int compare(SimpleString o1, SimpleString o2) {
|
||||
return o1.toString().compareToIgnoreCase(o2.toString());
|
||||
}
|
||||
});
|
||||
|
||||
sortAddress.addAll(addresses);
|
||||
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (SimpleString string : sortAddress) {
|
||||
if (result.length() > 0) {
|
||||
result.append(separator);
|
||||
}
|
||||
result.append(string);
|
||||
}
|
||||
|
||||
return result.toString();
|
||||
} finally {
|
||||
blockOnIO();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getConnectionCount() {
|
||||
checkStarted();
|
||||
|
|
|
@ -868,6 +868,11 @@ public class ActiveMQServerControlUsingCoreTest extends ActiveMQServerControlTes
|
|||
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);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue