Package org.rhq.core.domain.install.remote

Examples of org.rhq.core.domain.install.remote.AgentInstallStep


        executeCommand("rm -f " + parentPath.replace(" ", "\\ ") + "/rhq-enterprise-agent*.jar",
            "Remove any old agent update binary jars", info); // because we use * wildcard, can't wrap in quotes, so escape spaces if there are any in the path

        log.info("Copying agent binary update distribution file to [" + accessInfo.getHost() + "]...");

        AgentInstallStep scpStep = sendFile(agentPath, parentPath, "Remote copy the agent binary update distribution");
        info.addStep(scpStep);
        if(scpStep.getResultCode() != 0) {
            return info; // abort and return what we did - no sense continuing if the agent distro failed to copy
        }

        log.info("Agent binary update distribution file copied");

        executeCommand("cd '" + parentPath + "' ; " + "java -jar '" + parentPath + "/" + agentFile + "' '--install="
            + parentPath + "'", "Install Agent", info);

        String agentConfigXmlFilename = parentPath + "/rhq-agent/conf/agent-configuration.xml";

        if (customData.getAgentConfigurationXmlFile() != null) {
            log.info("Copying custom agent configuration file...");

            AgentInstallStep step = sendFile(customData.getAgentConfigurationXmlFile(), agentConfigXmlFilename, "Remote copy the agent configuration file");
            info.addStep(step);
            if(step.getResultCode() != 0) {
                return info; // abort and return what we did - no sense continuing if the custom config file failed to copy
            }

            log.info("Custom agent configuration file copied.");

            // tell the info object - this is needed so it adds the --config command line option
            info.setCustomAgentConfigurationFile("agent-configuration.xml");
        }

        // try to see if we can figure out what the port will be that the agent will bind to
        // this will use awk to find a line in the agent config xml that matches this:
        //    <entry key="rhq.communications.connector.bind-port" value="16163" />
        // where we use " as the field separator and the port number will be the fourth field.
        String agentPortAwkCommand = "awk '-F\"' '/key.*=.*" + AgentInstallInfo.AGENT_PORT_PROP + "/ {print $4}' "
            + "'" + agentConfigXmlFilename + "'";
        String portStr = executeCommand(agentPortAwkCommand, "Determine the agent's bind port", info);
        try {
            int port = Integer.parseInt(portStr.trim());
            info.setAgentPort(port);
        } catch (Exception e) {
            info.setAgentPort(0); // indicate that we don't know it
        }

        if (customData.getRhqAgentEnvFile() != null) {
            log.info("Copying custom agent environment script...");
            String destFilename = parentPath + "/rhq-agent/bin/rhq-agent-env.sh";

            AgentInstallStep step = sendFile(customData.getRhqAgentEnvFile(), destFilename, "Remote copy the agent environment script file");
            info.addStep(step);
            if (step.getResultCode() != 0) {
                return info; // abort and return what we did - no sense continuing if the custom env script file failed to copy
            }

            log.info("Custom agent environment script copied.");
        }

        // Do a quick check to see if there is something already listening on the agent's port.
        long start = System.currentTimeMillis();
        Boolean squatterCheck = checkAgentConnection(info, 1);
        if (squatterCheck != null) { // if this is null, we weren't even able to check
            if (squatterCheck.booleanValue()) {
                AgentInstallStep step = new AgentInstallStep("ping " + info.getAgentAddress() + ":"
                    + info.getAgentPort(), "See if anything has already taken the agent port", 1,
                    "Port already in use", getTimeDiff(start));
                info.addStep(step);
                return info; // abort, don't install an agent if something is already squatting on its port
            } else {
                AgentInstallStep step = new AgentInstallStep("ping " + info.getAgentAddress() + ":"
                    + info.getAgentPort(), "See if anything has already taken the agent port", 0, "Port free",
                    getTimeDiff(start));
                info.addStep(step);
            }
        }
View Full Code Here


        } catch (JSchException e) {
            scpReturnCode = 1;
            scpMessage = e.getMessage();
        }

        AgentInstallStep step = new AgentInstallStep("ssh copy '" + sourceFilename
                + "' -> '" + destFilename + "'", description, scpReturnCode,
                scpMessage, getTimeDiff(start));

        return step;
    }
View Full Code Here

        log.info("Running SSH command [" + description + "]");
        long start = System.currentTimeMillis();
        String result = null;
        try {
            result = executeCommand(command);
            info.addStep(new AgentInstallStep(command, description, 0, result, getTimeDiff(start)));
        } catch (ExecuteException e) {
            info.addStep(new AgentInstallStep(command, description, e.errorCode, e.getMessage(), getTimeDiff(start)));
        }
        log.info("Result of SSH command [" + description + "]: " + result);
        return result;
    }
View Full Code Here

            SSHInstallUtility sshUtil = getSSHConnection(remoteAccessInfo);
            try {
                AgentInstallInfo info = sshUtil.installAgent(customData, String.valueOf(ai.getId()));

                List<AgentInstallStep> steps = info.getSteps();
                AgentInstallStep lastInstallStep = steps.get(steps.size() - 1);

                // At the moment, SSHInstallUtility might throw RuntimeException as well if it fails. Lets unify this for now.
                if(lastInstallStep.getResultCode() != 0) {
                    throw new RuntimeException(lastInstallStep.getDescription() + " failed, " + lastInstallStep.getResult());
                }

                return info;
            } finally {
                sshUtil.disconnect();
View Full Code Here

TOP

Related Classes of org.rhq.core.domain.install.remote.AgentInstallStep

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.