Search in sources :

Example 86 with TabularData

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());
    }
}
Also used : Bundle(org.osgi.framework.Bundle) TabularType(javax.management.openmbean.TabularType) CompositeData(javax.management.openmbean.CompositeData) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) ArrayList(java.util.ArrayList) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) MBeanException(javax.management.MBeanException) TabularData(javax.management.openmbean.TabularData) ServiceReference(org.osgi.framework.ServiceReference) ArrayType(javax.management.openmbean.ArrayType) TabularDataSupport(javax.management.openmbean.TabularDataSupport) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) MBeanException(javax.management.MBeanException) CompositeType(javax.management.openmbean.CompositeType)

Example 87 with TabularData

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();
    }
}
Also used : CompositeData(javax.management.openmbean.CompositeData) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) IOException(java.io.IOException) ClusterStatusInformation(com.evolveum.midpoint.task.quartzimpl.cluster.ClusterStatusInformation) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) IOException(java.io.IOException) MalformedObjectNameException(javax.management.MalformedObjectNameException) SystemException(com.evolveum.midpoint.util.exception.SystemException) QuartzSchedulerMBean(org.quartz.core.jmx.QuartzSchedulerMBean) TabularData(javax.management.openmbean.TabularData) JMXConnector(javax.management.remote.JMXConnector) NodeType(com.evolveum.midpoint.xml.ns._public.common.common_3.NodeType) MBeanServerConnection(javax.management.MBeanServerConnection)

Example 88 with TabularData

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;
}
Also used : CamelContext(org.apache.camel.CamelContext) ManagementAgent(org.apache.camel.spi.ManagementAgent) CompositeData(javax.management.openmbean.CompositeData) ArrayList(java.util.ArrayList) ObjectName(javax.management.ObjectName) TabularData(javax.management.openmbean.TabularData) LinkedHashMap(java.util.LinkedHashMap) Collection(java.util.Collection) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) MBeanServer(javax.management.MBeanServer)

Example 89 with TabularData

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);
}
Also used : MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) TabularData(javax.management.openmbean.TabularData) ManagedCamelContextTest(org.apache.camel.management.ManagedCamelContextTest) Test(org.junit.Test)

Example 90 with TabularData

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;
}
Also used : TabularDataSupport(javax.management.openmbean.TabularDataSupport) TraceKeyspace(org.apache.cassandra.tracing.TraceKeyspace) AuthKeyspace(org.apache.cassandra.auth.AuthKeyspace) TabularData(javax.management.openmbean.TabularData)

Aggregations

TabularData (javax.management.openmbean.TabularData)183 CompositeData (javax.management.openmbean.CompositeData)91 TabularDataSupport (javax.management.openmbean.TabularDataSupport)67 ObjectName (javax.management.ObjectName)54 MBeanServer (javax.management.MBeanServer)50 CompositeType (javax.management.openmbean.CompositeType)47 CompositeDataSupport (javax.management.openmbean.CompositeDataSupport)43 Test (org.junit.Test)38 Map (java.util.Map)28 ArrayList (java.util.ArrayList)23 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)21 HashMap (java.util.HashMap)20 TabularType (javax.management.openmbean.TabularType)17 Bundle (org.osgi.framework.Bundle)17 AbstractIntegrationTest (org.apache.aries.jmx.AbstractIntegrationTest)15 Collection (java.util.Collection)13 IOException (java.io.IOException)11 DruidDataSource (com.alibaba.druid.pool.DruidDataSource)9 List (java.util.List)8 ServiceReference (org.osgi.framework.ServiceReference)8