use of javax.management.openmbean.TabularData in project karaf by apache.
the class ServicesMBeanImpl method getServices.
public TabularData getServices(long bundleId, boolean inUse) throws MBeanException {
try {
CompositeType serviceType = new CompositeType("Service", "OSGi Service", new String[] { "Interfaces", "Properties" }, new String[] { "Interfaces class name of the service", "Properties of the service" }, new OpenType[] { new ArrayType(1, SimpleType.STRING), new ArrayType(1, SimpleType.STRING) });
TabularType tableType = new TabularType("Services", "Table of OSGi Services", serviceType, new String[] { "Interfaces", "Properties" });
TabularData table = new TabularDataSupport(tableType);
Bundle[] bundles;
if (bundleId >= 0) {
bundles = new Bundle[] { bundleContext.getBundle(bundleId) };
} else {
bundles = bundleContext.getBundles();
}
for (Bundle bundle : bundles) {
try {
ServiceReference[] serviceReferences;
if (inUse) {
serviceReferences = bundle.getServicesInUse();
} else {
serviceReferences = bundle.getRegisteredServices();
}
if (serviceReferences != null) {
for (ServiceReference reference : serviceReferences) {
String[] interfaces = (String[]) reference.getProperty("objectClass");
List<String> properties = new ArrayList<>();
for (String key : reference.getPropertyKeys()) {
properties.add(key + " = " + reference.getProperty(key));
}
CompositeData data = new CompositeDataSupport(serviceType, new String[] { "Interfaces", "Properties" }, new Object[] { interfaces, properties.toArray(new String[0]) });
table.put(data);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
return table;
} catch (Exception e) {
throw new MBeanException(null, e.toString());
}
}
use of javax.management.openmbean.TabularData in project midpoint by Evolveum.
the class RemoteNodesManager method addNodeStatusFromRemoteNode.
/**
* Used exclusively for collecting running task information.
*
* @param info A structure to which information should be added
* @param node Node which to query
*/
void addNodeStatusFromRemoteNode(ClusterStatusInformation info, PrismObject<NodeType> node, OperationResult parentResult) {
OperationResult result = parentResult.createSubresult(RemoteNodesManager.class.getName() + ".addNodeStatusFromRemoteNode");
result.addParam("node", node);
NodeType nodeInfo = node.asObjectable();
String nodeIdentifier = nodeInfo.getNodeIdentifier();
String address = nodeInfo.getHostname() + ":" + nodeInfo.getJmxPort();
if (!taskManager.getClusterManager().isUp(nodeInfo)) {
nodeInfo.setExecutionStatus(NodeExecutionStatusType.DOWN);
info.addNodeInfo(nodeInfo);
result.recordStatus(OperationResultStatus.SUCCESS, "Node is down");
return;
}
JMXConnector connector = null;
try {
MBeanServerConnection mbsc;
try {
connector = connectViaJmx(address);
mbsc = connector.getMBeanServerConnection();
} catch (IOException e) {
LoggingUtils.logUnexpectedException(LOGGER, "Cannot connect to the remote node {} at {}", e, nodeIdentifier, address);
result.recordWarning("Cannot connect to the remote node " + nodeIdentifier + " at " + address + ": " + e.getMessage(), e);
nodeInfo.setExecutionStatus(NodeExecutionStatusType.COMMUNICATION_ERROR);
nodeInfo.setConnectionResult(result.createOperationResultType());
info.addNodeInfo(nodeInfo);
return;
}
try {
QuartzSchedulerMBean mbeanProxy = getMBeanProxy(nodeIdentifier, mbsc);
boolean running = false, down = true;
if (mbeanProxy != null) {
try {
running = mbeanProxy.isStarted() && !mbeanProxy.isShutdown() && !mbeanProxy.isStandbyMode();
down = mbeanProxy.isShutdown();
} catch (Exception e) {
// was: InstanceNotFoundException but it does not seem to work
String message = "Cannot get information from scheduler " + nodeIdentifier + " because it does not exist or is shut down.";
LoggingUtils.logUnexpectedException(LOGGER, message, e);
result.recordWarning(message, e);
nodeInfo.setConnectionResult(result.createOperationResultType());
}
} else {
result.recordWarning("Cannot get information from node " + nodeIdentifier + " at " + address + " because the JMX object for scheduler cannot be found on that node.");
nodeInfo.setConnectionResult(result.createOperationResultType());
}
LOGGER.trace(" - scheduler found = " + (mbeanProxy != null) + ", running = " + running + ", shutdown = " + down);
if (down) {
// this is a mark of error situation (we expect that during ordinary shutdown the node quickly goes down so there is little probability of getting this status on that occasion)
nodeInfo.setExecutionStatus(NodeExecutionStatusType.ERROR);
} else if (running) {
nodeInfo.setExecutionStatus(NodeExecutionStatusType.RUNNING);
} else {
nodeInfo.setExecutionStatus(NodeExecutionStatusType.PAUSED);
}
List<ClusterStatusInformation.TaskInfo> taskInfoList = new ArrayList<ClusterStatusInformation.TaskInfo>();
if (mbeanProxy != null) {
TabularData jobs = mbeanProxy.getCurrentlyExecutingJobs();
for (CompositeData job : (Collection<CompositeData>) jobs.values()) {
String oid = (String) job.get("jobName");
LOGGER.trace(" - task oid = " + oid);
taskInfoList.add(new ClusterStatusInformation.TaskInfo(oid));
}
}
if (result.isUnknown()) {
result.recordStatus(OperationResultStatus.SUCCESS, "Node " + nodeIdentifier + ": status = " + nodeInfo.getExecutionStatus() + ", # of running tasks: " + taskInfoList.size());
}
info.addNodeAndTaskInfo(nodeInfo, taskInfoList);
} catch (Exception e) {
// unfortunately, mbeanProxy.getCurrentlyExecutingJobs is declared to throw an Exception
LoggingUtils.logUnexpectedException(LOGGER, "Cannot get information from the remote node {} at {}", e, nodeIdentifier, address);
result.recordWarning("Cannot get information from the remote node " + nodeIdentifier + " at " + address + ": " + e.getMessage(), e);
nodeInfo.setExecutionStatus(NodeExecutionStatusType.COMMUNICATION_ERROR);
nodeInfo.setConnectionResult(result.createOperationResultType());
info.addNodeInfo(nodeInfo);
return;
}
} finally {
try {
if (connector != null) {
connector.close();
}
} catch (IOException e) {
LoggingUtils.logUnexpectedException(LOGGER, "Cannot close JMX connection to {}", e, address);
}
result.recordSuccessIfUnknown();
}
}
use of javax.management.openmbean.TabularData in project camel by apache.
the class AbstractLocalCamelController method browseInflightExchanges.
@SuppressWarnings("unchecked")
public List<Map<String, Object>> browseInflightExchanges(String camelContextName, String route, int limit, boolean sortByLongestDuration) throws Exception {
CamelContext context = this.getLocalCamelContext(camelContextName);
if (context == null) {
return null;
}
List<Map<String, Object>> answer = new ArrayList<Map<String, Object>>();
ManagementAgent agent = context.getManagementStrategy().getManagementAgent();
if (agent != null) {
MBeanServer mBeanServer = agent.getMBeanServer();
ObjectName on = new ObjectName(agent.getMBeanObjectDomainName() + ":type=services,name=DefaultInflightRepository,context=" + context.getManagementName());
if (mBeanServer.isRegistered(on)) {
TabularData list = (TabularData) mBeanServer.invoke(on, "browse", new Object[] { route, limit, sortByLongestDuration }, new String[] { "java.lang.String", "int", "boolean" });
Collection<CompositeData> values = (Collection<CompositeData>) list.values();
for (CompositeData data : values) {
Map<String, Object> row = new LinkedHashMap<String, Object>();
Object exchangeId = data.get("exchangeId");
if (exchangeId != null) {
row.put("exchangeId", exchangeId);
}
Object fromRouteId = data.get("fromRouteId");
if (fromRouteId != null) {
row.put("fromRouteId", fromRouteId);
}
Object routeId = data.get("routeId");
if (routeId != null) {
row.put("routeId", routeId);
}
Object nodeId = data.get("nodeId");
if (nodeId != null) {
row.put("nodeId", nodeId);
}
Object elapsed = data.get("elapsed");
if (elapsed != null) {
row.put("elapsed", elapsed);
}
Object duration = data.get("duration");
if (duration != null) {
row.put("duration", duration);
}
answer.add(row);
}
}
}
return answer;
}
use of javax.management.openmbean.TabularData in project camel by apache.
the class SpringManagedCamelContextTest method testListEips.
@Test
public void testListEips() throws Exception {
// JMX tests dont work well on AIX CI servers (hangs them)
if (isPlatform("aix")) {
return;
}
MBeanServer mbeanServer = getMBeanServer();
ObjectName on = ObjectName.getInstance("org.apache.camel:context=19-camel-1,type=context,name=\"camel-1\"");
assertTrue("Should be registered", mbeanServer.isRegistered(on));
TabularData data = (TabularData) mbeanServer.invoke(on, "listEips", null, null);
assertNotNull(data);
assertTrue(data.size() > 150);
}
use of javax.management.openmbean.TabularData in project cassandra by apache.
the class StorageService method getSnapshotDetails.
public Map<String, TabularData> getSnapshotDetails() {
Map<String, TabularData> snapshotMap = new HashMap<>();
for (Keyspace keyspace : Keyspace.all()) {
if (SchemaConstants.isSystemKeyspace(keyspace.getName()))
continue;
for (ColumnFamilyStore cfStore : keyspace.getColumnFamilyStores()) {
for (Map.Entry<String, Pair<Long, Long>> snapshotDetail : cfStore.getSnapshotDetails().entrySet()) {
TabularDataSupport data = (TabularDataSupport) snapshotMap.get(snapshotDetail.getKey());
if (data == null) {
data = new TabularDataSupport(SnapshotDetailsTabularData.TABULAR_TYPE);
snapshotMap.put(snapshotDetail.getKey(), data);
}
SnapshotDetailsTabularData.from(snapshotDetail.getKey(), keyspace.getName(), cfStore.getTableName(), snapshotDetail, data);
}
}
}
return snapshotMap;
}
Aggregations