Examples of AgentInstall


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

            return null;
        }
        Query q = entityManager.createNamedQuery(AgentInstall.QUERY_FIND_BY_NAME);
        q.setParameter("agentName", agentName);
        try {
            AgentInstall ai;
            ai = (AgentInstall) q.getSingleResult();

            entityManager.detach(ai);
            deobfuscateAgentInstall(ai);
            return ai;
View Full Code Here

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

            // If there is one already with the given agent name then update that record, overlaying it with the data from agentInstall.
            // If there is nothing with the given agent name, persist a new record with the data in agentInstall.
            // Note that if the caller didn't give us either an install ID or an agent name, we still persist the entity
            // with the expectation that the new ID will be used later by a new agent (new agent will register with this new ID and
            // will tell us what agent name it wants to use).
            AgentInstall existing = getAgentInstallByAgentName(user, agentInstall.getAgentName());
            if (existing != null) {
                existing.overlay(agentInstall); // note: "existing" is detached
                agentInstall = entityManager.merge(existing);
            } else {
                entityManager.persist(agentInstall);
            }
        } else {
            // Caller gave us an agentInstall with an ID. See if there is already an entity with the given ID.
            // If there is an entity with the given ID, but that entity's agentName does not match the agentName given in agentInstall,
            // abort - one agent can't change another agent's install data.
            // If there is an entity with the given ID and the agentName matches then update that record, overlaying it with data from agentInstall.
            // If there is no entity with the given ID then throw an error.
            AgentInstall existing = entityManager.find(AgentInstall.class, agentInstall.getId());
            if (existing != null) {
                if (agentInstall.getAgentName() != null) {
                    if (existing.getAgentName() != null && !agentInstall.getAgentName().equals(existing.getAgentName())) {
                        throw new IllegalStateException("Updating agent install ID [" + agentInstall.getId()
                            + "] with a mismatched agent name is not allowed");
                    }

                    // It is possible some past installs were aborted, or this agent is getting reinstalled.
                    // This cases like this, we'll have duplicate rows with the same agent name - this just deletes
                    // those older rows since this new agent supercedes the other ones.
                    Query q = entityManager.createNamedQuery(AgentInstall.QUERY_FIND_BY_NAME);
                    q.setParameter("agentName", agentInstall.getAgentName());
                    List<AgentInstall> otherAgentInstalls = q.getResultList();
                    if (otherAgentInstalls != null) {
                        for (AgentInstall otherAgentInstall : otherAgentInstalls) {
                            if (otherAgentInstall.getId() != agentInstall.getId()) {
                                entityManager.remove(otherAgentInstall);
                            }
                        }
                    }
                }
                existing.overlay(agentInstall); // modify the attached hibernate entity
                agentInstall = existing;
            } else {
                throw new IllegalStateException("Agent install ID [" + agentInstall.getId()
                    + "] does not exist. Cannot update install info for agent [" + agentInstall.getAgentName() + "]");
            }
View Full Code Here

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

        boolean credentialsOK = sshSession.isConnected();
        if (!credentialsOK) {
            return; // do not store anything - the credentials are probably bad and why we aren't connected so no sense remembering them
        }

        AgentInstall ai = agentManager.getAgentInstallByAgentName(subject, agentName);
        if (ai == null) {
            ai = new AgentInstall();
            ai.setAgentName(agentName);
        }

        // ai.setSshHost(remoteAccessInfo.getHost()); do NOT change the host
        ai.setSshPort(remoteAccessInfo.getPort());
        if (remoteAccessInfo.getRememberMe()) {
            ai.setSshUsername(remoteAccessInfo.getUser());
            ai.setSshPassword(remoteAccessInfo.getPassword());
        } else {
            // user doesn't want to remember the creds, set them to "" which tells our persistence layer to null them out
            ai.setSshUsername("");
            ai.setSshPassword("");
        }

        try {
            agentManager.updateAgentInstall(subject, ai);
        } catch (Exception e) {
View Full Code Here

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

                deobfuscateFile(new File(customData.getRhqAgentEnvFile()));
            }

            // before we install, let's create a AgentInstall and pass its ID
            // as the install ID so the agent can link up with it when it registers.
            AgentInstall agentInstall = new AgentInstall();
            agentInstall.setSshHost(remoteAccessInfo.getHost());
            agentInstall.setSshPort(remoteAccessInfo.getPort());
            if (remoteAccessInfo.getRememberMe()) {
                agentInstall.setSshUsername(remoteAccessInfo.getUser());
                agentInstall.setSshPassword(remoteAccessInfo.getPassword());
            }
            AgentInstall ai = agentManager.updateAgentInstall(subject, agentInstall);

            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.
View Full Code Here

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

    @RequiredPermission(Permission.MANAGE_INVENTORY)
    @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
    public String uninstallAgent(Subject subject, RemoteAccessInfo remoteAccessInfo, String agentInstallPath) {
        String agentName = remoteAccessInfo.getAgentName();
        if(agentName != null) {
            AgentInstall ai = agentManager.getAgentInstallByAgentName(subject, agentName);
            if (ai == null || ai.getInstallLocation() == null || ai.getInstallLocation().trim().length() == 0) {
                throw new IllegalArgumentException("Agent [" + agentName
                        + "] does not have a known install location. For security purposes, the uninstall will not be allowed."
                        + " You will have to manually uninstall it from that machine.");
            }
            // for security reasons, don't connect to a different machine than where the AgentInstall thinks the agent is.
            // If there is no known host in AgentInstall, then we accept the caller's hostname.
            if (ai.getSshHost() != null && !ai.getSshHost().equals(remoteAccessInfo.getHost())) {
                throw new IllegalArgumentException("Agent [" + agentName + "] is not known to be on host ["
                        + remoteAccessInfo.getHost() + "] - aborting uninstall");
            }
        }
View Full Code Here

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

        // Otherwise, this will create or update an existing AgentInstall entity without any additional data
        // known about it other than its agent name and install location.
        // Note that any failures in here won't abort the registration - this isn't required to have a functioning
        // agent. Its just additional information that is useful to the user for doing things like remote start/stop.
        try {
            AgentInstall ai = new AgentInstall();
            if (request.getInstallId() != null) {
                ai.setId(Integer.valueOf(request.getInstallId()));
            }
            ai.setAgentName(agentByName.getName());
            ai.setInstallLocation(request.getInstallLocation());
            ai = agentManager.updateAgentInstall(subjectManager.getOverlord(), ai);

            // We now have the persisted AgentInstall entity from the database - which may have additional information we didn't have before.
            // If, however, we still don't have the hostname, fill that in now with the address of the agent entity.
            // We do this now (rather than when we first updated above) because its possible the user, when remotely installing this agent,
            // provided a different host IP to connect over SSH to (probably for NAT reasons) and that was persisted before the agent was registered.
            // Therefore, we want to keep the user's host and not overwrite it. If, however, there is no host information at all, we will fill it in.
            if (ai.getSshHost() == null) {
                ai.setSshHost(agentByName.getAddress());
                ai = agentManager.updateAgentInstall(subjectManager.getOverlord(), ai);
            }
        } catch (Exception e) {
            log.warn("Could not update the install information for agent [" + agentByName.getName() + "]", e);
        }
View Full Code Here

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

    @Test
    public void testLinkAgentWithAgentInstall() throws Exception {
        AgentManagerLocal agentManager = LookupUtil.getAgentManager();
        SubjectManagerLocal sm = LookupUtil.getSubjectManager();

        AgentInstall persistedAgentInstall = agentManager.getAgentInstallByAgentName(sm.getOverlord(),
            "should-not-exist");
        assert persistedAgentInstall == null;

        AgentInstall agentInstall = new AgentInstall();
        agentInstall.setSshHost("CoreServerServiceImpl-SshHost");
        agentInstall.setSshPort(44);
        agentInstall.setSshUsername("CoreServerServiceImpl-SshUsername");
        agentInstall.setSshPassword("CoreServerServiceImpl-SshPassword");
        agentInstall = agentManager.updateAgentInstall(sm.getOverlord(), agentInstall);
        assert agentInstall.getId() > 0 : "didn't persist properly - ID should be non-zero";
        assert agentInstall.getAgentName() == null : "there should be no agent name yet";
        assert agentInstall.getInstallLocation() == null : "there should be no install location yet";

        CoreServerServiceImpl service = new CoreServerServiceImpl();
        AgentRegistrationRequest aReq = createRequest(prefixName(".AgentInstall"), A_HOST, A_PORT, null,
            String.valueOf(agentInstall.getId()), "/tmp/CoreServerServiceImplTest/rhq-agent");
        AgentRegistrationResults aResults = service.registerAgent(aReq);
        assert aResults != null : "got null results";

        persistedAgentInstall = agentManager.getAgentInstallByAgentName(sm.getOverlord(), aReq.getName());
        assert persistedAgentInstall != null : "the new agent info is missing";
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.