Skip to content

Commit

Permalink
NO-JIRA Moving CLI Management to use ManagementHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
clebertsuconic committed Jul 20, 2023
1 parent 9ffe062 commit 6b61e9e
Show file tree
Hide file tree
Showing 22 changed files with 138 additions and 311 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
package org.apache.activemq.artemis.cli.commands.address;

import com.github.rvesse.airline.annotations.Option;
import org.apache.activemq.artemis.cli.commands.AbstractAction;
import org.apache.activemq.artemis.cli.commands.messages.ConnectionAbstract;

public abstract class AddressAbstract extends AbstractAction {
public abstract class AddressAbstract extends ConnectionAbstract {

@Option(name = "--name", description = "The address's name.")
private String name;
Expand All @@ -37,7 +37,7 @@ public abstract class AddressAbstract extends AbstractAction {
private Boolean noMulticast;


public AbstractAction setName(String name) {
public AddressAbstract setName(String name) {
this.name = name;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package org.apache.activemq.artemis.cli.commands.address;

import com.github.rvesse.airline.annotations.Command;
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;

Expand All @@ -33,23 +32,14 @@ public Object execute(ActionContext context) throws Exception {
}

private void createAddress(final ActionContext context) throws Exception {
performCoreManagement(new ManagementCallback<ClientMessage>() {
@Override
public void setUpInvocation(ClientMessage message) throws Exception {
ManagementHelper.putOperationInvocation(message, "broker", "createAddress", getName(true), getRoutingTypes(true));
}

@Override
public void requestSuccessful(ClientMessage reply) throws Exception {
final String result = ManagementHelper.getResult(reply, String.class) + " created successfully.";
context.out.println(result);
}

@Override
public void requestFailed(ClientMessage reply) throws Exception {
String errMsg = (String) ManagementHelper.getResult(reply, String.class);
context.err.println("Failed to create address " + getName(true) + ". Reason: " + errMsg);
}
performCoreManagement(message -> {
ManagementHelper.putOperationInvocation(message, "broker", "createAddress", getName(true), getRoutingTypes(true));
}, reply -> {
final String result = ManagementHelper.getResult(reply, String.class) + " created successfully.";
context.out.println(result);
}, reply -> {
String errMsg = (String) ManagementHelper.getResult(reply, String.class);
context.err.println("Failed to create address " + getName(true) + ". Reason: " + errMsg);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import com.github.rvesse.airline.annotations.Command;
import com.github.rvesse.airline.annotations.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;

Expand All @@ -37,22 +36,13 @@ public Object execute(ActionContext context) throws Exception {
}

private void deleteAddress(final ActionContext context) throws Exception {
performCoreManagement(new ManagementCallback<ClientMessage>() {
@Override
public void setUpInvocation(ClientMessage message) throws Exception {
ManagementHelper.putOperationInvocation(message, "broker", "deleteAddress", getName(true), force);
}

@Override
public void requestSuccessful(ClientMessage reply) throws Exception {
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(true) + ". Reason: " + errMsg);
}
performCoreManagement(message -> {
ManagementHelper.putOperationInvocation(message, "broker", "deleteAddress", getName(true), force);
}, reply -> {
context.out.println("Address " + getName(true) + " deleted successfully.");
}, reply -> {
String errMsg = (String) ManagementHelper.getResult(reply, String.class);
context.err.println("Failed to delete address " + getName(true) + ". Reason: " + errMsg);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@

import com.github.rvesse.airline.annotations.Command;
import com.github.rvesse.airline.annotations.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;

@Command(name = "show", description = "Show the selected address.")
public class ShowAddress extends AddressAbstract {


@Option(name = "--bindings", description = "Show the bindings for this address.")
boolean bindings;

Expand All @@ -38,30 +36,20 @@ public Object execute(ActionContext context) throws Exception {
}

private void showAddress(final ActionContext context) throws Exception {
performCoreManagement(new ManagementCallback<ClientMessage>() {
@Override
public void setUpInvocation(ClientMessage message) throws Exception {

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(false));
}
}

@Override
public void requestSuccessful(ClientMessage reply) throws Exception {
final String result = (String) ManagementHelper.getResult(reply, String.class);
context.out.println(result);
}

@Override
public void requestFailed(ClientMessage reply) throws Exception {
String errMsg = (String) ManagementHelper.getResult(reply, String.class);
context.err.println("Failed to show address " + getName(false) + ". Reason: " + errMsg);
performCoreManagement(message -> {
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(false));
}
}, reply -> {
final String result = (String) ManagementHelper.getResult(reply, String.class);
context.out.println(result);
}, reply -> {
String errMsg = (String) ManagementHelper.getResult(reply, String.class);
context.err.println("Failed to show address " + getName(false) + ". Reason: " + errMsg);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
package org.apache.activemq.artemis.cli.commands.address;

import com.github.rvesse.airline.annotations.Command;
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.")
Expand All @@ -33,23 +31,14 @@ public Object execute(ActionContext context) throws Exception {
}

private void updateAddress(final ActionContext context) throws Exception {
performCoreManagement(new AbstractAction.ManagementCallback<ClientMessage>() {
@Override
public void setUpInvocation(ClientMessage message) throws Exception {
ManagementHelper.putOperationInvocation(message, "broker", "updateAddress", getName(true), getRoutingTypes(false));
}

@Override
public void requestSuccessful(ClientMessage reply) throws Exception {
final String result = ManagementHelper.getResult(reply, String.class) + " updated successfully.";
context.out.println(result);
}

@Override
public void requestFailed(ClientMessage reply) throws Exception {
String errMsg = (String) ManagementHelper.getResult(reply, String.class);
context.err.println("Failed to update address " + getName(true) + ". Reason: " + errMsg);
}
performCoreManagement(message -> {
ManagementHelper.putOperationInvocation(message, "broker", "updateAddress", getName(true), getRoutingTypes(false));
}, reply -> {
final String result = ManagementHelper.getResult(reply, String.class) + " updated successfully.";
context.out.println(result);
}, reply -> {
String errMsg = (String) ManagementHelper.getResult(reply, String.class);
context.err.println("Failed to update address " + getName(true) + ". Reason: " + errMsg);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
import com.github.rvesse.airline.annotations.Option;
import org.apache.activemq.artemis.api.core.management.ActiveMQManagementProxy;
import org.apache.activemq.artemis.cli.CLIException;
import org.apache.activemq.artemis.cli.commands.AbstractAction;
import org.apache.activemq.artemis.cli.commands.ActionContext;
import org.apache.activemq.artemis.cli.commands.messages.ConnectionAbstract;
import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
import org.apache.commons.lang3.time.StopWatch;

public abstract class CheckAbstract extends AbstractAction {
public abstract class CheckAbstract extends ConnectionAbstract {

@Option(name = "--name", description = "Name of the target to check.")
protected String name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import javax.jms.JMSSecurityException;

import com.github.rvesse.airline.annotations.Option;
import org.apache.activemq.artemis.api.core.management.ManagementHelper;
import org.apache.activemq.artemis.cli.commands.ActionContext;
import org.apache.activemq.artemis.cli.commands.InputAbstract;
import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
Expand Down Expand Up @@ -237,4 +238,11 @@ private String inputPassword(String password) {
}
return password;
}

protected void performCoreManagement(ManagementHelper.MessageAcceptor setup, ManagementHelper.MessageAcceptor ok, ManagementHelper.MessageAcceptor failed) throws Exception {
try (ActiveMQConnectionFactory factory = createCoreConnectionFactory()) {
ManagementHelper.doManagement(factory.getServerLocator(), user, password, setup, ok, failed);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package org.apache.activemq.artemis.cli.commands.queue;

import com.github.rvesse.airline.annotations.Command;
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;

Expand All @@ -33,23 +32,14 @@ public Object execute(ActionContext context) throws Exception {
}

private void createQueue(final ActionContext context) throws Exception {
performCoreManagement(new ManagementCallback<ClientMessage>() {
@Override
public void setUpInvocation(ClientMessage message) throws Exception {
ManagementHelper.putOperationInvocation(message, "broker", "createQueue", getAddress(true), getRoutingType(), getName(), getFilter(), isDurable(), getMaxConsumers(-1), isPurgeOnNoConsumers(true), isAutoCreateAddress());
}

@Override
public void requestSuccessful(ClientMessage reply) throws Exception {
final String result = ManagementHelper.getResult(reply, String.class) + " created successfully.";
context.out.println(result);
}

@Override
public void requestFailed(ClientMessage reply) throws Exception {
String errMsg = (String) ManagementHelper.getResult(reply, String.class);
context.err.println("Failed to create queue " + getName() + ". Reason: " + errMsg);
}
performCoreManagement(message -> {
ManagementHelper.putOperationInvocation(message, "broker", "createQueue", getAddress(true), getRoutingType(), getName(), getFilter(), isDurable(), getMaxConsumers(-1), isPurgeOnNoConsumers(true), isAutoCreateAddress());
}, reply -> {
final String result = ManagementHelper.getResult(reply, String.class) + " created successfully.";
context.out.println(result);
}, reply -> {
String errMsg = (String) ManagementHelper.getResult(reply, String.class);
context.err.println("Failed to create queue " + getName() + ". Reason: " + errMsg);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@

import com.github.rvesse.airline.annotations.Command;
import com.github.rvesse.airline.annotations.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;
import org.apache.activemq.artemis.cli.commands.messages.ConnectionAbstract;

@Command(name = "delete", description = "Delete a queue.")
public class DeleteQueue extends AbstractAction {
public class DeleteQueue extends ConnectionAbstract {

@Option(name = "--name", description = "The queue's name")
String name;
Expand All @@ -44,22 +43,13 @@ public Object execute(ActionContext context) throws Exception {
}

private void deleteQueue(final ActionContext context) throws Exception {
performCoreManagement(new ManagementCallback<ClientMessage>() {
@Override
public void setUpInvocation(ClientMessage message) throws Exception {
ManagementHelper.putOperationInvocation(message, "broker", "destroyQueue", getName(), removeConsumers, autoDeleteAddress);
}

@Override
public void requestSuccessful(ClientMessage reply) throws Exception {
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 " + getName() + ". Reason: " + errMsg);
}
performCoreManagement(message -> {
ManagementHelper.putOperationInvocation(message, "broker", "destroyQueue", getName(), removeConsumers, autoDeleteAddress);
}, reply -> {
context.out.println("Queue " + getName() + " deleted successfully.");
}, reply -> {
String errMsg = (String) ManagementHelper.getResult(reply, String.class);
context.err.println("Failed to delete queue " + getName() + ". Reason: " + errMsg);
});
}

Expand Down
Loading

0 comments on commit 6b61e9e

Please sign in to comment.