Package org.rhq.core.system

Examples of org.rhq.core.system.ProcessInfo


     * or got refreshed in order to determine if the process was still running.
     *
     * @return information on the resource's process, or null if process was not found
     */
    public ProcessInfo getNativeProcess() {
        ProcessInfo processInfo = null;

        synchronized (trackedProcesses) {
            //right, we've entered the critical section...
            //we might have waited for another thread to actually fill in the tracked processes
            //so let's check again if we really need to run the discovery
View Full Code Here


        String operand1 = null;
        String operand2 = criteria.getValue();

        for (ProcessInfo process : getProcesses()) {
            ProcessInfo processToMatch; // will be the same as process unless the parent qualifier was provided

            if (qualifier.equals(Qualifier.parent)) {
                processToMatch = getParentProcess(process);
            } else {
                processToMatch = process;
            }

            String[] cmdline = (processToMatch != null) ? processToMatch.getCommandLine() : null;

            if ((cmdline == null) || (cmdline.length == 0)) {
                continue; // no sense continuing with this process - there are no command line arguments
            }
View Full Code Here

        String operand2;

        String pidfileContentsCache = null; // so we avoid reading the file over and over again

        for (ProcessInfo process : getProcesses()) {
            ProcessInfo processToMatch; // will be the same as process unless the parent qualifier was provided

            if (qualifier.equals(Qualifier.parent)) {
                processToMatch = getParentProcess(process);
            } else {
                processToMatch = process;
            }

            if (attribute.getAttributeValue().equals(Attribute.ProcessCategoryAttributes.name.toString())) {
                operand1 = (processToMatch != null) ? processToMatch.getName() : "";
                operand2 = criteria.getValue();
            } else if (attribute.getAttributeValue().equals(Attribute.ProcessCategoryAttributes.basename.toString())) {
                operand1 = (processToMatch != null) ? processToMatch.getBaseName() : "";
                operand2 = criteria.getValue();
            } else if (attribute.getAttributeValue().equals(Attribute.ProcessCategoryAttributes.pid.toString())) {
                operand1 = (processToMatch != null) ? Long.toString(processToMatch.getPid()) : "";
                operand2 = criteria.getValue();
            } else if (attribute.getAttributeValue().equals(Attribute.ProcessCategoryAttributes.pidfile.toString())) {
                if (pidfileContentsCache == null) {
                    pidfileContentsCache = getPidfileContents(criteria.getValue());
                }

                operand1 = (processToMatch != null) ? String.valueOf(processToMatch.getPid()) : null;
                operand2 = pidfileContentsCache;
            } else {
                throw new IllegalArgumentException(
                    "Criteria with 'process' category must have an attribute of either 'name' or 'basename': "
                        + criteria);
View Full Code Here

     * @param  child
     *
     * @return the child's parent process or <code>null</code> if the child has no parent
     */
    private ProcessInfo getParentProcess(ProcessInfo child) {
        ProcessInfo parent = null;

        if (child != null) {
            parent = this.allProcesses.get(child.getParentPid());
        }

View Full Code Here

            LOG.debug("Invoked operation '" + operation + "' on " + resourceContext.getResourceKey() + " (waiting for "
                + desiredState + "), attempt " + i + ": " + res.getComplexResults().getMap().toString());

            //wait for max 30s for the operation to "express" itself
            int w = 0;
            ProcessInfo pi;
            while (w < 30) {
                pi = getResourceContext().getNativeProcess();

                switch (desiredState) {
                case RUNNING:
                    if (pi != null && pi.isRunning()) {
                        return;
                    }
                    break;
                case STOPPED:
                    if (pi == null || !pi.isRunning()) {
                        return;
                    }
                }

                Thread.sleep(1000);
View Full Code Here

    @Override
    public Configuration loadResourceConfiguration() throws Exception {
        Configuration config = new Configuration();
       
        ProcessInfo pinfo = context.getNativeProcess();
       
        int pid = pinfo == null ? 0 : (int) context.getNativeProcess().getPid();

        LOG.debug("PID = " + pid);
       
View Full Code Here

            throw new IllegalStateException("Only a single test process is expected but there are " + context.getAutoDiscoveredProcesses().size());
        }

        TestComponent.DISCOVERY_CALLS_COUNT.incrementAndGet();
               
        ProcessInfo pinfo = context.getAutoDiscoveredProcesses().get(0).getProcessInfo();
        return Collections.singleton(new DiscoveredResourceDetails(context.getResourceType(), "KEY", "NAME", "VERSION", null, context.getDefaultPluginConfiguration(), pinfo));
    }
View Full Code Here

    /**
     * Tests querying technique that is kind of like the one used when we need to autodiscovery Apache.
     */
    public void testPIQLApacheUseCase() {
        ProcessInfo p100 = buildProcessInfo(100, "$1", "--dollararg");
        ProcessInfo p101 = buildProcessInfo(101, 100, "/dollar", "--dollararg");
        ProcessInfo p102 = buildProcessInfo(102, 100, "/dollar", "--dollararg");
        ProcessInfo p200 = buildProcessInfo(200, "/dollar", "--dollararg");
        ProcessInfo p201 = buildProcessInfo(201, 200, "/dollar", "--dollararg");
        ProcessInfo p202 = buildProcessInfo(202, 200, "/dollar", "--dollararg");

        List<ProcessInfo> processes = query.getProcesses();
        processes.add(p100);
        processes.add(p101);
        processes.add(p102);
View Full Code Here

        return stopNode();
    }

    protected OperationResult stopNode() {
        ProcessInfo process = getResourceContext().getNativeProcess();

        if (process == null) {
            log.warn("Failed to obtain process info. It appears Cassandra is already shutdown.");
            return new OperationResult("Failed to obtain process info. It appears Cassandra is already shutdown.");
        }

        long pid = process.getPid();
        try {
            process.kill("KILL");

            Configuration pluginConfig = getResourceContext().getPluginConfiguration();
            File basedir = new File(pluginConfig.getSimpleValue("baseDir"));
            File binDir = new File(basedir, "bin");
            File pidFile = new File(binDir, "cassandra.pid");
View Full Code Here

        String jmxPort = null;
        StringBuilder commandLineBuilder = new StringBuilder(400);
        int classpathIndex = -1;

        ProcessInfo processInfo = processScanResult.getProcessInfo();
        String[] arguments = processInfo.getCommandLine();
        for (int i = 0; i < arguments.length; i++) {
            String arg = arguments[i];

            if (arg.startsWith("-Dcom.sun.management.jmxremote.port")) {
                String[] jmxPortArg = arg.split("=");
                jmxPort = jmxPortArg[1];
            }
            if (arg.startsWith("-cp") || (arg.startsWith("-classpath"))) {
                classpathIndex = i;
            }

            commandLineBuilder.append(arg);
            commandLineBuilder.append(' ');
        }

        pluginConfig.put(new PropertySimple(COMMAND_LINE_CONFIG_PROPERTY, commandLineBuilder.toString()));

        if (classpathIndex != -1 && classpathIndex + 1 < arguments.length) {
            String[] classpathEntries = arguments[classpathIndex + 1].split(File.pathSeparator);

            File yamlConfigurationPath = null;
            for (String classpathEntry : classpathEntries) {
                if (classpathEntry.endsWith("conf")) {
                    yamlConfigurationPath = new File(classpathEntry);
                    if (!yamlConfigurationPath.isAbsolute()) {
                        try {
                            //relative path, use process CWD to find absolute path of the conf directory
                            yamlConfigurationPath = new File(processInfo.getExecutable().getCwd(), classpathEntry);
                        } catch (Exception e) {
                            log.error("Error creating path for yaml file.", e);
                        }
                    }
                }
            }

            if (yamlConfigurationPath != null) {
                File yamlConfigurationFile = new File(yamlConfigurationPath, "cassandra.yaml");
                ConfigEditor yamlEditor = new ConfigEditor(yamlConfigurationFile);
                yamlEditor.load();

                pluginConfig.put(new PropertySimple(YAML_PROPERTY, yamlConfigurationFile.getAbsolutePath()));
                pluginConfig.put(new PropertySimple(CLUSTER_NAME_PROPERTY, yamlEditor.getClusterName()));
                pluginConfig.put(new PropertySimple(HOST_PROPERTY, yamlEditor.getListenAddress()));
                pluginConfig.put(new PropertySimple(AUTHENTICATOR_PROPERTY, yamlEditor.getAuthenticator()));
            }
        }

        if (jmxPort != null) {
            pluginConfig.put(new PropertySimple(JMX_PORT_PROPERTY, jmxPort));

            pluginConfig.put(new PropertySimple(JMXDiscoveryComponent.CONNECTION_TYPE,
                J2SE5ConnectionTypeDescriptor.class.getName()));
            pluginConfig.put(new PropertySimple(JMXDiscoveryComponent.CONNECTOR_ADDRESS_CONFIG_PROPERTY,
                "service:jmx:rmi:///jndi/rmi://" + pluginConfig.getSimpleValue(HOST_PROPERTY) + ":" + jmxPort
                    + "/jmxrmi"));
        }

        String resourceKey = "Cassandra (" + pluginConfig.getSimpleValue(HOST_PROPERTY) + ") " + jmxPort;
        String resourceName = RESOURCE_NAME;

        String path = processInfo.getExecutable().getCwd();
        pluginConfig.put(new PropertySimple(BASEDIR_PROPERTY, new File(path).getParentFile().getAbsolutePath()));

        return new DiscoveredResourceDetails(context.getResourceType(), resourceKey, resourceName, null, null,
            pluginConfig, processInfo);
    }
View Full Code Here

TOP

Related Classes of org.rhq.core.system.ProcessInfo

Copyright © 2018 www.massapicom. 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.