Examples of JvmResourceKey


Examples of org.rhq.plugins.jmx.util.JvmResourceKey

        Resource platform = getInventoryManager().getPlatform();

        Set<Resource> serverResources = getChildResourcesOfType(platform, SERVER_TYPE);
        for (Resource jmxServer : serverResources) {

            JvmResourceKey key = JvmResourceKey.valueOf(jmxServer.getResourceKey());
            boolean isTestProgram = TestProgram.class.getName().equals(key.getMainClassName());
            if (isTestProgram && key.getType().equals(keyType)) {

                switch (keyType) {
                case Explicit:
                    if (key.getExplicitValue().equals(value)) {
                        return jmxServer;
                    }
                    break;
                case JmxRemotingPort:
                    if (key.getJmxRemotingPort().equals(value)) {
                        return jmxServer;
                    }
                    break;
                default:
                }
View Full Code Here

Examples of org.rhq.plugins.jmx.util.JvmResourceKey

        return urls;
    }

    @Override
    public ResourceUpgradeReport upgrade(ResourceUpgradeContext inventoriedResource) {
        JvmResourceKey oldKey = JvmResourceKey.valueOf(inventoriedResource.getResourceKey());
        JvmResourceKey.Type oldKeyType = oldKey.getType();
        if (oldKeyType == JvmResourceKey.Type.Legacy || oldKeyType == JvmResourceKey.Type.JmxRemotingPort) {
            if (!inventoriedResource.getSystemInformation().isNative()) {
                log.warn("Cannot attempt to upgrade Resource key [" + inventoriedResource.getResourceKey()
                    + "] of JVM Resource, because this Agent is not running with native system info support (i.e. SIGAR).");
                return null;
            }

            Configuration pluginConfig = inventoriedResource.getPluginConfiguration();
            String connectorAddress = pluginConfig.getSimpleValue(CONNECTOR_ADDRESS_CONFIG_PROPERTY, null);
            JMXServiceURL jmxServiceURL;
            try {
                jmxServiceURL = new JMXServiceURL(connectorAddress);
            } catch (MalformedURLException e) {
                throw new RuntimeException("Failed to parse connector address: " + connectorAddress, e);
            }

            JMXConnector jmxConnector = null;
            Long pid;
            try {
                jmxConnector = connect(jmxServiceURL);
                MBeanServerConnection mbeanServerConnection = jmxConnector.getMBeanServerConnection();
                RuntimeMXBean runtimeMXBean = ManagementFactory.newPlatformMXBeanProxy(mbeanServerConnection,
                    ManagementFactory.RUNTIME_MXBEAN_NAME, RuntimeMXBean.class);
                pid = getJvmPid(runtimeMXBean);
                if (pid == null) {
                    throw new RuntimeException("Failed to determine JVM pid by parsing JVM name.");
                }
            } catch (SecurityException e) {
                // Authentication failed, which most likely means the username and password are not set correctly in
                // the Resource's plugin config. This is not an error, so return null.
                log.info("Unable to upgrade key of JVM Resource with key [" + inventoriedResource.getResourceKey()
                        + "], since authenticating to its JMX service URL [" + jmxServiceURL + "] failed: "
                        + e.getMessage());
                return null;
            } catch (IOException e) {
                // The JVM's not currently running, which means we won't be able to figure out its main class name,
                // which is needed to upgrade its key. This is not an error, so return null.
                log.debug("Unable to upgrade key of JVM Resource with key [" + inventoriedResource.getResourceKey()
                        + "], since connecting to its JMX service URL [" + jmxServiceURL + "] failed: " + e);
                return null;
            } finally {
                close(jmxConnector);
            }

            List<ProcessInfo> processes = inventoriedResource.getSystemInformation().getProcesses(
                "process|pid|match=" + pid);
            if (processes.size() != 1) {
                throw new IllegalStateException("Failed to find process with PID [" + pid + "].");
            }
            ProcessInfo process = processes.get(0);
            String mainClassName = getJavaMainClassName(process);
            String explicitKeyValue = getSystemPropertyValue(process, SYSPROP_RHQ_RESOURCE_KEY);
            if (oldKeyType == JvmResourceKey.Type.Legacy || explicitKeyValue != null) {
                // We need to upgrade the key.
                JvmResourceKey newKey;
                if (explicitKeyValue != null) {
                    newKey = JvmResourceKey.fromExplicitValue(mainClassName, explicitKeyValue);
                } else {
                    newKey = JvmResourceKey.fromJmxRemotingPort(mainClassName, oldKey.getJmxRemotingPort());
                }

                ResourceUpgradeReport resourceUpgradeReport = new ResourceUpgradeReport();
                resourceUpgradeReport.setNewResourceKey(newKey.toString());
                return resourceUpgradeReport;
            }
        }

        return null;
View Full Code Here

Examples of org.rhq.plugins.jmx.util.JvmResourceKey

        return buildResourceDetails(context, process, jmxServiceURL, jmxRemotingPort);
    }

    protected DiscoveredResourceDetails buildResourceDetails(ResourceDiscoveryContext context, ProcessInfo process,
                                                             JMXServiceURL jmxServiceURL, Integer jmxRemotingPort) {
        JvmResourceKey key = buildResourceKey(process, jmxRemotingPort);
        if (key == null) {
            return null;
        }
        String name = buildResourceName(key);
        String version = getJavaVersion(process, jmxServiceURL);
        String description = "JVM, monitored via " + ((jmxRemotingPort != null) ? "JMX Remoting" : "Sun JVM Attach API");

        Configuration pluginConfig = context.getDefaultPluginConfiguration();
        pluginConfig.put(new PropertySimple(CONNECTION_TYPE, J2SE5ConnectionTypeDescriptor.class.getName()));
        if (jmxRemotingPort != null) {
            pluginConfig.put(new PropertySimple(CONNECTOR_ADDRESS_CONFIG_PROPERTY, jmxServiceURL));
        }

        return new DiscoveredResourceDetails(context.getResourceType(), key.toString(), name, version, description,
            pluginConfig, process);
    }
View Full Code Here

Examples of org.rhq.plugins.jmx.util.JvmResourceKey

        return new DiscoveredResourceDetails(context.getResourceType(), key.toString(), name, version, description,
            pluginConfig, process);
    }

    private JvmResourceKey buildResourceKey(ProcessInfo process, Integer jmxRemotingPort) {
        JvmResourceKey key;
        String mainClassName = getJavaMainClassName(process);
        String keyString = getSystemPropertyValue(process, SYSPROP_RHQ_RESOURCE_KEY);
        if (keyString != null && !keyString.equals("")) {
            log.debug("Using explicitly specified Resource key: [" + keyString + "]...");
            key = JvmResourceKey.fromExplicitValue(mainClassName, keyString);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.