ARTEMIS-670 Adjusting package names on CLI and adding input for destination create name

This commit is contained in:
Clebert Suconic 2016-08-10 19:08:45 -04:00
parent 1f9ca74f01
commit 7d684956e2
11 changed files with 67 additions and 61 deletions

View File

@ -24,15 +24,15 @@ import java.util.List;
import io.airlift.airline.Cli;
import org.apache.activemq.artemis.cli.commands.Action;
import org.apache.activemq.artemis.cli.commands.ActionContext;
import org.apache.activemq.artemis.cli.commands.Browse;
import org.apache.activemq.artemis.cli.commands.Consumer;
import org.apache.activemq.artemis.cli.commands.messages.Browse;
import org.apache.activemq.artemis.cli.commands.messages.Consumer;
import org.apache.activemq.artemis.cli.commands.Create;
import org.apache.activemq.artemis.cli.commands.CreateDestination;
import org.apache.activemq.artemis.cli.commands.DeleteDestination;
import org.apache.activemq.artemis.cli.commands.destination.CreateDestination;
import org.apache.activemq.artemis.cli.commands.destination.DeleteDestination;
import org.apache.activemq.artemis.cli.commands.HelpAction;
import org.apache.activemq.artemis.cli.commands.HelpDestination;
import org.apache.activemq.artemis.cli.commands.destination.HelpDestination;
import org.apache.activemq.artemis.cli.commands.Kill;
import org.apache.activemq.artemis.cli.commands.Producer;
import org.apache.activemq.artemis.cli.commands.messages.Producer;
import org.apache.activemq.artemis.cli.commands.Run;
import org.apache.activemq.artemis.cli.commands.Stop;
import org.apache.activemq.artemis.cli.commands.tools.CompactJournal;
@ -124,6 +124,7 @@ public class Artemis {
builder.withGroup("destination").withDescription("Destination tools group (create|delete) (example ./artemis destination create)").
withDefaultCommand(HelpDestination.class).withCommands(CreateDestination.class, DeleteDestination.class);
if (instance != null) {
builder.withGroup("data").withDescription("data tools group (print|exp|imp|exp|encode|decode|compact) (example ./artemis data print)").
withDefaultCommand(HelpData.class).withCommands(PrintData.class, XmlDataExporter.class, XmlDataImporter.class, DecodeJournal.class, EncodeJournal.class, CompactJournal.class);

View File

@ -23,7 +23,7 @@ import io.airlift.airline.Option;
public abstract class ActionAbstract implements Action {
@Option(name = "--verbose", description = "Adds more information on the execution")
boolean verbose;
public boolean verbose;
private String brokerInstance;

View File

@ -15,13 +15,14 @@
* limitations under the License.
*/
package org.apache.activemq.artemis.cli.commands;
package org.apache.activemq.artemis.cli.commands.destination;
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.api.jms.management.JMSManagementHelper;
import org.apache.activemq.artemis.cli.commands.ActionContext;
import javax.jms.Message;
@ -63,31 +64,31 @@ public class CreateDestination extends DestinationAction {
performJmsManagement(brokerURL, user, password, new ManagementCallback<Message>() {
@Override
public void setUpInvocation(Message message) throws Exception {
JMSManagementHelper.putOperationInvocation(message, "jms.server", "createTopic", name, bindings);
JMSManagementHelper.putOperationInvocation(message, "jms.server", "createTopic", getName(), bindings);
}
@Override
public void requestSuccessful(Message reply) throws Exception {
boolean result = (boolean) JMSManagementHelper.getResult(reply, Boolean.class);
if (result) {
context.out.println("Topic " + name + " created successfully.");
context.out.println("Topic " + getName() + " created successfully.");
}
else {
context.err.println("Failed to create topic " + name + ".");
context.err.println("Failed to create topic " + getName() + ".");
}
}
@Override
public void requestFailed(Message reply) throws Exception {
String errorMsg = (String) JMSManagementHelper.getResult(reply, String.class);
context.err.println("Failed to create topic " + name + ". Reason: " + errorMsg);
context.err.println("Failed to create topic " + getName() + ". Reason: " + errorMsg);
}
});
}
public String getAddress() {
if (address == null || "".equals(address.trim())) {
address = name;
address = getName();
}
return address.trim();
}
@ -97,18 +98,18 @@ public class CreateDestination extends DestinationAction {
@Override
public void setUpInvocation(ClientMessage message) throws Exception {
String address = getAddress();
ManagementHelper.putOperationInvocation(message, "core.server", "createQueue", address, name, filter, durable);
ManagementHelper.putOperationInvocation(message, "core.server", "createQueue", address, getName(), filter, durable);
}
@Override
public void requestSuccessful(ClientMessage reply) throws Exception {
context.out.println("Core queue " + name + " created successfully.");
context.out.println("Core queue " + getName() + " created successfully.");
}
@Override
public void requestFailed(ClientMessage reply) throws Exception {
String errMsg = (String) ManagementHelper.getResult(reply, String.class);
context.err.println("Failed to create queue " + name + ". Reason: " + errMsg);
context.err.println("Failed to create queue " + getName() + ". Reason: " + errMsg);
}
});
}
@ -119,24 +120,24 @@ public class CreateDestination extends DestinationAction {
@Override
public void setUpInvocation(Message message) throws Exception {
JMSManagementHelper.putOperationInvocation(message, "jms.server", "createQueue", name, bindings, filter, durable);
JMSManagementHelper.putOperationInvocation(message, "jms.server", "createQueue", getName(), bindings, filter, durable);
}
@Override
public void requestSuccessful(Message reply) throws Exception {
boolean result = (boolean) JMSManagementHelper.getResult(reply, Boolean.class);
if (result) {
context.out.println("Jms queue " + name + " created successfully.");
context.out.println("Jms queue " + getName() + " created successfully.");
}
else {
context.err.println("Failed to create jms queue " + name + ".");
context.err.println("Failed to create jms queue " + getName() + ".");
}
}
@Override
public void requestFailed(Message reply) throws Exception {
String errorMsg = (String) JMSManagementHelper.getResult(reply, String.class);
context.err.println("Failed to create jms queue " + name + ". Reason: " + errorMsg);
context.err.println("Failed to create jms queue " + getName() + ". Reason: " + errorMsg);
}
});
}

View File

@ -15,13 +15,14 @@
* limitations under the License.
*/
package org.apache.activemq.artemis.cli.commands;
package org.apache.activemq.artemis.cli.commands.destination;
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.api.jms.management.JMSManagementHelper;
import org.apache.activemq.artemis.cli.commands.ActionContext;
import javax.jms.Message;
@ -54,24 +55,24 @@ public class DeleteDestination extends DestinationAction {
performJmsManagement(brokerURL, user, password, new ManagementCallback<Message>() {
@Override
public void setUpInvocation(Message message) throws Exception {
JMSManagementHelper.putOperationInvocation(message, "jms.server", "destroyTopic", name, removeConsumers);
JMSManagementHelper.putOperationInvocation(message, "jms.server", "destroyTopic", getName(), removeConsumers);
}
@Override
public void requestSuccessful(Message reply) throws Exception {
boolean result = (boolean) JMSManagementHelper.getResult(reply, Boolean.class);
if (result) {
context.out.println("Topic " + name + " deleted successfully.");
context.out.println("Topic " + getName() + " deleted successfully.");
}
else {
context.err.println("Failed to delete topic " + name);
context.err.println("Failed to delete topic " + getName());
}
}
@Override
public void requestFailed(Message reply) throws Exception {
String errorMsg = (String) JMSManagementHelper.getResult(reply, String.class);
context.err.println("Failed to delete topic " + name + ". Reason: " + errorMsg);
context.err.println("Failed to delete topic " + getName() + ". Reason: " + errorMsg);
}
});
}
@ -80,24 +81,24 @@ public class DeleteDestination extends DestinationAction {
performJmsManagement(brokerURL, user, password, new ManagementCallback<Message>() {
@Override
public void setUpInvocation(Message message) throws Exception {
JMSManagementHelper.putOperationInvocation(message, "jms.server", "destroyQueue", name, removeConsumers);
JMSManagementHelper.putOperationInvocation(message, "jms.server", "destroyQueue", getName(), removeConsumers);
}
@Override
public void requestSuccessful(Message reply) throws Exception {
boolean result = (boolean) JMSManagementHelper.getResult(reply, Boolean.class);
if (result) {
context.out.println("Jms queue " + name + " deleted successfully.");
context.out.println("Jms queue " + getName() + " deleted successfully.");
}
else {
context.err.println("Failed to delete queue " + name);
context.err.println("Failed to delete queue " + getName());
}
}
@Override
public void requestFailed(Message reply) throws Exception {
String errorMsg = (String) JMSManagementHelper.getResult(reply, String.class);
context.err.println("Failed to create " + name + " with reason: " + errorMsg);
context.err.println("Failed to create " + getName() + " with reason: " + errorMsg);
}
});
}
@ -106,18 +107,18 @@ public class DeleteDestination extends DestinationAction {
performCoreManagement(brokerURL, user, password, new ManagementCallback<ClientMessage>() {
@Override
public void setUpInvocation(ClientMessage message) throws Exception {
ManagementHelper.putOperationInvocation(message, "core.server", "destroyQueue", name);
ManagementHelper.putOperationInvocation(message, "core.server", "destroyQueue", getName());
}
@Override
public void requestSuccessful(ClientMessage reply) throws Exception {
context.out.println("Queue " + name + " deleted successfully.");
context.out.println("Queue " + getName() + " deleted successfully.");
}
@Override
public void requestFailed(ClientMessage reply) throws Exception {
String errMsg = (String) ManagementHelper.getResult(reply, String.class);
context.err.println("Failed to delete queue " + name + ". Reason: " + errMsg);
context.err.println("Failed to delete queue " + getName() + ". Reason: " + errMsg);
}
});
}

View File

@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.activemq.artemis.cli.commands;
package org.apache.activemq.artemis.cli.commands.destination;
import io.airlift.airline.Option;
import org.apache.activemq.artemis.api.core.client.ActiveMQClient;
@ -26,6 +26,7 @@ import org.apache.activemq.artemis.api.core.client.ServerLocator;
import org.apache.activemq.artemis.api.core.management.ManagementHelper;
import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient;
import org.apache.activemq.artemis.api.jms.management.JMSManagementHelper;
import org.apache.activemq.artemis.cli.commands.InputAbstract;
import org.apache.activemq.artemis.core.client.impl.ServerLocatorImpl;
import org.apache.activemq.artemis.jms.client.ActiveMQConnection;
import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
@ -36,7 +37,7 @@ import javax.jms.Queue;
import javax.jms.QueueRequestor;
import javax.jms.Session;
public abstract class DestinationAction extends ActionAbstract {
public abstract class DestinationAction extends InputAbstract {
public static final String JMS_QUEUE = "jms-queue";
public static final String JMS_TOPIC = "topic";
@ -54,18 +55,18 @@ public abstract class DestinationAction extends ActionAbstract {
@Option(name = "--password", description = "Password used to connect")
String password;
@Option(name = "--name", description = "destination name", required = true)
@Option(name = "--name", description = "destination name")
String name;
public static void performJmsManagement(String brokerURL, String user, String password, ManagementCallback<Message> cb) throws Exception {
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(brokerURL, user, password);
ActiveMQConnection connection = (ActiveMQConnection) factory.createConnection();
ActiveMQSession session = (ActiveMQSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue managementQueue = ActiveMQJMSClient.createQueue("activemq.management");
QueueRequestor requestor = new QueueRequestor(session, managementQueue);
try (ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(brokerURL, user, password);
ActiveMQConnection connection = (ActiveMQConnection) factory.createConnection();
ActiveMQSession session = (ActiveMQSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE)) {
Queue managementQueue = ActiveMQJMSClient.createQueue("activemq.management");
QueueRequestor requestor = new QueueRequestor(session, managementQueue);
try {
connection.start();
Message message = session.createMessage();
@ -83,18 +84,14 @@ public abstract class DestinationAction extends ActionAbstract {
cb.requestFailed(reply);
}
}
finally {
connection.close();
}
}
public static void performCoreManagement(String brokerURL, String user, String password, ManagementCallback<ClientMessage> cb) throws Exception {
ServerLocator locator = ServerLocatorImpl.newLocator(brokerURL);
ClientSessionFactory sessionFactory = locator.createSessionFactory();
ClientSession session = sessionFactory.createSession(user, password, false, true, true, false, ActiveMQClient.DEFAULT_ACK_BATCH_SIZE);
try {
try (ServerLocator locator = ServerLocatorImpl.newLocator(brokerURL);
ClientSessionFactory sessionFactory = locator.createSessionFactory();
ClientSession session = sessionFactory.createSession(user, password, false, true, true, false, ActiveMQClient.DEFAULT_ACK_BATCH_SIZE)) {
session.start();
ClientRequestor requestor = new ClientRequestor(session, "jms.queue.activemq.management");
ClientMessage message = session.createMessage(false);
@ -110,10 +107,6 @@ public abstract class DestinationAction extends ActionAbstract {
cb.requestFailed(reply);
}
}
finally {
session.close();
sessionFactory.close();
}
}
public void setName(String name) {
@ -121,6 +114,10 @@ public abstract class DestinationAction extends ActionAbstract {
}
public String getName() {
if (name == null) {
name = input("--name", "Please provide the destination name:", "");
}
return name;
}

View File

@ -15,15 +15,17 @@
* limitations under the License.
*/
package org.apache.activemq.artemis.cli.commands;
package org.apache.activemq.artemis.cli.commands.destination;
import io.airlift.airline.Help;
import org.apache.activemq.artemis.cli.commands.Action;
import org.apache.activemq.artemis.cli.commands.ActionContext;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
public class HelpDestination extends Help implements Action {
public class HelpDestination extends Help implements Action {
@Override
public boolean isVerbose() {

View File

@ -15,10 +15,11 @@
* limitations under the License.
*/
package org.apache.activemq.artemis.cli.commands;
package org.apache.activemq.artemis.cli.commands.messages;
import io.airlift.airline.Command;
import io.airlift.airline.Option;
import org.apache.activemq.artemis.cli.commands.ActionContext;
import org.apache.activemq.artemis.cli.commands.util.ConsumerThread;
import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
import org.apache.activemq.artemis.jms.client.ActiveMQDestination;

View File

@ -15,7 +15,7 @@
* limitations under the License.
*/
package org.apache.activemq.artemis.cli.commands;
package org.apache.activemq.artemis.cli.commands.messages;
import javax.jms.Connection;
import javax.jms.Destination;
@ -23,6 +23,7 @@ import javax.jms.Session;
import io.airlift.airline.Command;
import io.airlift.airline.Option;
import org.apache.activemq.artemis.cli.commands.ActionContext;
import org.apache.activemq.artemis.cli.commands.util.ConsumerThread;
import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
import org.apache.activemq.artemis.jms.client.ActiveMQDestination;

View File

@ -15,9 +15,10 @@
* limitations under the License.
*/
package org.apache.activemq.artemis.cli.commands;
package org.apache.activemq.artemis.cli.commands.messages;
import io.airlift.airline.Option;
import org.apache.activemq.artemis.cli.commands.ActionAbstract;
public class DestAbstract extends ActionAbstract {

View File

@ -15,7 +15,7 @@
* limitations under the License.
*/
package org.apache.activemq.artemis.cli.commands;
package org.apache.activemq.artemis.cli.commands.messages;
import javax.jms.Connection;
import javax.jms.Destination;
@ -23,6 +23,7 @@ import javax.jms.Session;
import io.airlift.airline.Command;
import io.airlift.airline.Option;
import org.apache.activemq.artemis.cli.commands.ActionContext;
import org.apache.activemq.artemis.cli.commands.util.ProducerThread;
import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
import org.apache.activemq.artemis.jms.client.ActiveMQDestination;

View File

@ -18,9 +18,9 @@ package org.apache.activemq.artemis.tests.integration.cli;
import org.apache.activemq.artemis.api.core.SimpleString;
import org.apache.activemq.artemis.cli.commands.ActionContext;
import org.apache.activemq.artemis.cli.commands.CreateDestination;
import org.apache.activemq.artemis.cli.commands.DeleteDestination;
import org.apache.activemq.artemis.cli.commands.DestinationAction;
import org.apache.activemq.artemis.cli.commands.destination.CreateDestination;
import org.apache.activemq.artemis.cli.commands.destination.DeleteDestination;
import org.apache.activemq.artemis.cli.commands.destination.DestinationAction;
import org.apache.activemq.artemis.core.filter.Filter;
import org.apache.activemq.artemis.core.postoffice.Binding;
import org.apache.activemq.artemis.tests.util.JMSTestBase;