Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@
import org.slf4j.LoggerFactory;

import javax.management.AttributeNotFoundException;
import javax.management.InstanceNotFoundException;
import javax.management.MBeanAttributeInfo;
import javax.management.MBeanException;
import javax.management.MBeanInfo;
import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
import javax.management.ReflectionException;
import java.io.IOException;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
Expand Down Expand Up @@ -100,7 +108,10 @@ private Map<String, Object> extractMethodProperty(Method method, Object object,
throw new DestinationException(
String.format("Unable to access '%s' of '%s' object!", object.getClass(), method.getName()));
} catch (Throwable e) {
logger.debug(e.getCause().toString());
logger.debug(e.toString());
if (e.getCause() != null) {
logger.debug(e.getCause().toString());
}
}
return methodPropertyMap;
}
Expand Down Expand Up @@ -169,6 +180,37 @@ public Map<String, Object> getObjectProperties(Object object, List<String> exclu
}
return propertiesMap;
}

public Map<String, Object> getRawObjectProperties(MBeanServerConnection mBeanServerConnection, ObjectName objectName, List<String> excludeMethodList) throws DestinationException {
Map<String, Object> propertiesMap = new HashMap<>();

MBeanInfo info;
try {
info = mBeanServerConnection.getMBeanInfo(objectName);
} catch (Throwable e) {
throw new RuntimeException(e);
}
for (MBeanAttributeInfo attributeInfo : info.getAttributes()) {
String attributeName = attributeInfo.getName();

// get rid of get/is+lowercase first letter
String propertyName = getPropertyNameByMethod(attributeName, 0);

Object value = null;
try {
value = mBeanServerConnection.getAttribute(objectName, attributeName);
propertiesMap.put(propertyName, value);
} catch (MBeanException | AttributeNotFoundException | InstanceNotFoundException | ReflectionException |
IOException e) {

e.printStackTrace();
} catch (Throwable e) {
logger.debug(e.toString());
}
}

return propertiesMap;
}
}

class ProxyHandler implements InvocationHandler {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.redhat.amqx.management;

import javax.management.ObjectName;

/**
* Interface for resolving view management
* objects like queues, topics, broker information.
Expand All @@ -18,6 +20,8 @@ public interface Resolver<T, R, S, U, V> {

U getAddressView(String addressName) throws Exception;

public ObjectName getAddressObjectName(String addressName) throws Exception;

V getDivertView(String addressName, String divertName) throws Exception;

}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ public QueueViewMBean getAddressView(String queueName) throws Exception {
return null;
}

@Override
public ObjectName getAddressObjectName(String addressName) throws Exception {
System.err.println("Does not exist for AMQ!");
return null;
}

@Override
public QueueViewMBean getDivertView(String addressName, String divertName) throws Exception {
System.err.println("Does not exist for AMQ!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.redhat.amqx.management.AbstractConnectionManager;
import com.redhat.amqx.management.Credentials;
import com.redhat.amqx.management.Resolver;
import org.apache.activemq.artemis.api.core.ActiveMQAddressDoesNotExistException;
import org.apache.activemq.artemis.api.core.management.ActiveMQServerControl;
import org.apache.activemq.artemis.api.core.management.AddressControl;
import org.apache.activemq.artemis.api.core.management.DivertControl;
Expand All @@ -20,6 +19,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.management.ObjectName;
import java.io.IOException;
import java.util.*;

Expand Down Expand Up @@ -176,8 +176,8 @@ public Map<String, Object> getDestinationProperties(String addressName, String d
}
}

AddressControl addressControl = (AddressControl) getResolver().getAddressView(addressName);
propertiesMap.putAll(objectReader.getObjectProperties(addressControl, excludeMethods));
ObjectName addressObjectName = getResolver().getAddressObjectName(addressName);
propertiesMap.putAll(objectReader.getRawObjectProperties(mBeanServerConnection, addressObjectName, excludeMethods));
propertiesMap.put("address-settings", new JSONObject(getServerControlMBean().getAddressSettingsAsJSON(addressName)));
return propertiesMap;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.apache.activemq.artemis.api.core.SimpleString;
import org.apache.activemq.artemis.api.core.management.*;
import org.apache.activemq.artemis.api.core.RoutingType;
import org.jetbrains.annotations.NotNull;

import javax.management.MBeanServerConnection;
import javax.management.MBeanServerInvocationHandler;
Expand All @@ -16,10 +17,12 @@ public class ArtemisResolver implements Resolver<ActiveMQServerControl, QueueCon
private final String DEFAULT_DOMAIN = "org.apache.activemq.artemis";
private MBeanServerConnection mBeanServerConnection;
private String brokerName;
private ObjectNameBuilder objectNameBuilder;

public ArtemisResolver(MBeanServerConnection mBeanServerConnection, String brokerName) {
this.mBeanServerConnection = mBeanServerConnection;
this.brokerName = brokerName;
this.objectNameBuilder = ObjectNameBuilder.create(DEFAULT_DOMAIN, brokerName, true);
}

@Override
Expand All @@ -29,40 +32,44 @@ public String getBrokerName() {

@Override
public ActiveMQServerControl getBrokerView() throws Exception {
ObjectName objectName = ObjectNameBuilder.create(DEFAULT_DOMAIN, brokerName, true).getActiveMQServerObjectName();
// 1.0 org.apache.activemq.artemis:module=Core,type=Server
// 1.2 org.apache.activemq.artemis:type=Broker,brokerName="<broker-name>",module=Core,ServerType=Server";
// 1.5.1 org.apache.activemq.artemis:type=Broker,brokerName="amq",serviceType=Address,name="queue-anycast2"
// 2.0 org.apache.activemq.artemis:broker="<brokerName>",component=addresses,address="<addressName>",subcomponent=queues,routing-type="<routingType>",queue="<queueName>"
objectName = ObjectNameBuilder.create(DEFAULT_DOMAIN, brokerName, true).getActiveMQServerObjectName();
ObjectName objectName = objectNameBuilder.getActiveMQServerObjectName();
return MBeanServerInvocationHandler.newProxyInstance(mBeanServerConnection, objectName, ActiveMQServerControl.class, false);
}

@Override
public QueueControl getQueueView(String addressName, String queueName) throws Exception {
ObjectName objectName = ObjectNameBuilder.create(DEFAULT_DOMAIN, brokerName, true).getQueueObjectName(new SimpleString(addressName), new SimpleString(queueName), RoutingType.ANYCAST);
ObjectName objectName = objectNameBuilder.getQueueObjectName(new SimpleString(addressName), new SimpleString(queueName), RoutingType.ANYCAST);
return MBeanServerInvocationHandler.newProxyInstance(mBeanServerConnection, objectName, QueueControl.class, false);
}

@Override
public QueueControl getTopicView(String addressName, String topicName) throws Exception {
// if address doesn't add RoutingType.MULTICAST, it does not have any type
ObjectName objectName = ObjectNameBuilder.create(DEFAULT_DOMAIN, brokerName, true).getQueueObjectName(new SimpleString(addressName), new SimpleString(topicName), RoutingType.MULTICAST);
ObjectName objectName = objectNameBuilder.getQueueObjectName(new SimpleString(addressName), new SimpleString(topicName), RoutingType.MULTICAST);
return MBeanServerInvocationHandler.newProxyInstance(mBeanServerConnection, objectName, QueueControl.class, false);
}

public AcceptorControl getAcceptorView(String acceptorName) throws Exception {
ObjectName objectname = ObjectNameBuilder.create(DEFAULT_DOMAIN, brokerName, true).getAcceptorObjectName(acceptorName);
ObjectName objectname = objectNameBuilder.getAcceptorObjectName(acceptorName);
return MBeanServerInvocationHandler.newProxyInstance(mBeanServerConnection, objectname, AcceptorControl.class, false);
}

public AddressControl getAddressView(String addressName) throws Exception {
ObjectName objectname = ObjectNameBuilder.create(DEFAULT_DOMAIN, brokerName, true).getAddressObjectName(new SimpleString(addressName));
ObjectName objectname = getAddressObjectName(addressName);
return MBeanServerInvocationHandler.newProxyInstance(mBeanServerConnection, objectname, AddressControl.class, false);
}

@NotNull
public ObjectName getAddressObjectName(String addressName) throws Exception {
return objectNameBuilder.getAddressObjectName(new SimpleString(addressName));
}

public DivertControl getDivertView(String addressName, String divertName) throws Exception {
ObjectName objectname = ObjectNameBuilder.create(DEFAULT_DOMAIN, brokerName, true).getDivertObjectName(divertName, addressName);
ObjectName objectname = objectNameBuilder.getDivertObjectName(divertName, addressName);
return MBeanServerInvocationHandler.newProxyInstance(mBeanServerConnection, objectname, DivertControl.class, false);
}

Expand Down