Skip to content
Prev Previous commit
Next Next commit
Added functionality to get the broker version in RabbitBrokerAdmin.
Added new version converter to RabbitControlErlangConverter.
Added handling of broker control actions by version - per 2.3.0 internal rabbit api changes.
  • Loading branch information
Helena Edelson committed Feb 22, 2011
commit 741eff6ca8f7309ac6c4ae027a166ffd26ef011a
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ public void forceResetNode() {
@ManagedOperation
public RabbitStatus getStatus() {
try {
return (RabbitStatus) getErlangTemplate().executeAndConvertRpc(ListStatus.create());
return (RabbitStatus) getErlangTemplate().executeAndConvertRpc(getControlAction(ListStatus.class));
} catch (OtpAuthException e) {
throw new RabbitAdminAuthException(
"Could not authorise connection to Erlang process. This can happen if the broker is running, "
Expand Down Expand Up @@ -633,22 +633,18 @@ protected void createErlangTemplate(ConnectionFactory otpConnectionFactory) {
String version = getVersion();

ControlAction[] controlActions = version != null ? erlangConverter.refreshMappings(version) : erlangConverter.getControlActions();

for (ControlAction action : controlActions) {
controlActionMap.put(action.getKey(), action);
}
}

/**
* Returns the version of the broker.
* Returns the version of the broker based on running nodes.
* @return the broker version
*/
public String getVersion() {
String input = getStatus().getRunningApplications().get(0).getVersion().substring(1);
return input.substring(0, input.length() - 1);
/*Pattern p = Pattern.compile("([^@]+)@");
Matcher m = p.matcher(input);
return m.find() ? m.group(1) : input;*/
public String getVersion() {
return (String) erlangTemplate.executeAndConvertRpc(RabbitControlErlangConverter.BrokerVersion.create());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
Expand Down Expand Up @@ -89,11 +91,14 @@ protected void initializeMappings(boolean isLatestVersion) {

/**
* Initializes a map of ControlActions by function.
* Tests whether the broker is the latest version, for internal
* API changes. Current changes are as of Rabbit 2.3.0.
* @param version The broker version
* @return ControlAction array
*/
public ControlAction[] refreshMappings(String version) {
initializeMappings(version.startsWith("2.3"));
boolean isLatestVersion = version.startsWith("2.3");
initializeMappings(isLatestVersion);

return getControlActions();
}
Expand Down Expand Up @@ -192,6 +197,39 @@ public static ControlAction create() {
}
}

public static class BrokerVersion extends RabbitControlAction {
public static ControlAction create() {
return new RabbitControlAction(BrokerVersion.class, "rabbit", "status", new VersionConverter());
}
}

public static class VersionConverter extends SimpleErlangConverter {

public Object fromErlang(OtpErlangObject erlangObject) throws ErlangConversionException {
String version = null;
long items = ((OtpErlangList) erlangObject).elements().length;
if (items > 0) {
if (erlangObject instanceof OtpErlangList) {
for (OtpErlangObject outerList : ((OtpErlangList) erlangObject).elements()) {
if (outerList instanceof OtpErlangTuple) {
OtpErlangTuple entry = (OtpErlangTuple) outerList;
String key = entry.elementAt(0).toString();
if (key.equals("running_applications") && entry.elementAt(1) instanceof OtpErlangList) {
OtpErlangList value = (OtpErlangList) entry.elementAt(1);

Pattern p = Pattern.compile("\"(\\d+\\.\\d+(?:\\.\\d+)?)\"}$");
Matcher m = p.matcher(value.elementAt(0).toString());
version = m.find() ? m.group(1) : null;
}
}
}
}
}

return version;
}
}

public static class ListUsersConverter extends SimpleErlangConverter {

public Object fromErlang(OtpErlangObject erlangObject) throws ErlangConversionException {
Expand Down