Package org.rhq.core.domain.resource

Examples of org.rhq.core.domain.resource.Agent


    public void testDeletingAgents() throws Exception {
        // create three agents:
        // 1) agent is the only thing registered - has no inventory yet
        // 2) agent's platform is NEW, not yet committed to inventory yet (it is in the discovery queue)
        // 3) agent's platform is COMMITTED in inventory
        Agent agentRegistered = createOnlyAgent(1);
        HashMap<Agent, Resource> agentPlatNew = createAgentWithResource(2, InventoryStatus.NEW);
        HashMap<Agent, Resource> agentPlatCommitted = createAgentWithResource(3, InventoryStatus.COMMITTED);

        Agent agentNew = agentPlatNew.keySet().iterator().next();
        Agent agentCommitted = agentPlatCommitted.keySet().iterator().next();
       
        // just for some complexity - we'll want to add our committed resource to a group
        Resource committedResource = agentPlatCommitted.values().iterator().next();
        groupManager.addResourcesToGroup(getOverlord(), newGroup.getId(), new int[] { committedResource.getId() });

        // delete our agents
        resourceManager.uninventoryAllResourcesByAgent(getOverlord(), agentRegistered);
        resourceManager.uninventoryAllResourcesByAgent(getOverlord(), agentNew);
        resourceManager.uninventoryAllResourcesByAgent(getOverlord(), agentCommitted);
       
        assert null == agentManager.getAgentByID(agentRegistered.getId());
        assert null == agentManager.getAgentByID(agentNew.getId());
        assert null == agentManager.getAgentByID(agentCommitted.getId());

        try {
            Resource doomed = resourceManager.getResourceById(getOverlord(), committedResource.getId());
            assert doomed.getAgent() == null : "Resource should not have an agent attached, it should have been uninventoried";
            assert doomed.getInventoryStatus() == InventoryStatus.UNINVENTORIED : "Should have been uninventoried";
View Full Code Here


        getTransactionManager().commit();
        return resourceType;
    }

    private Agent createOnlyAgent(int index) throws Exception {
        Agent agent;
        getTransactionManager().begin();
        try {
            agent = new Agent("DeleteAgentTest-Agent" + index, "testaddr", 16163 + index, "", "testtoken" + index);
            em.persist(agent);
            em.flush();
        } catch (Exception e) {
            System.out.println("CANNOT PREPARE TEST: " + e);
            getTransactionManager().rollback();
View Full Code Here

    }

    private HashMap<Agent, Resource> createAgentWithResource(int index, InventoryStatus invStatus) throws Exception {
        HashMap<Agent, Resource> ret = new HashMap<Agent, Resource>(1);

        Agent agent = createOnlyAgent(index);
        Resource resource;

        getTransactionManager().begin();
        try {
            resource = new Resource("DeleteAgentTest-Res" + index, "DeleteAgentTest-Res" + index, platformType);
View Full Code Here

    private void deleteNewResource(Resource doomedResource) throws Exception {
        if (doomedResource != null) {
            // get the type and agent that we will delete after we delete the resource itself
            ResourceType doomedResourceType = doomedResource.getResourceType();
            Agent doomedAgent = doomedResource.getAgent();

            // delete the resource itself
            Subject overlord = LookupUtil.getSubjectManager().getOverlord();
            ResourceManagerLocal resourceManager = LookupUtil.getResourceManager();
            List<Integer> deletedIds = resourceManager.uninventoryResource(overlord, doomedResource.getId());
            for (Integer deletedResourceId : deletedIds) {
                resourceManager.uninventoryResourceAsyncWork(overlord, deletedResourceId);
            }

            // delete the agent and the type
            getTransactionManager().begin();

            try {
                Agent agent = em.find(Agent.class, doomedAgent.getId());
                if (agent != null)
                    em.remove(agent);

                ResourceType type = em.find(ResourceType.class, doomedResourceType.getId());
                if (type != null)
View Full Code Here

            public void execute() throws Exception {

                resourceType = new ResourceType(RESOURCE_TYPE, PLUGIN, SERVER, null);
                em.persist(resourceType);

                agent = new Agent(AGENT_NAME, "localhost", 9999, "", "randomToken");
                em.persist(agent);

                resource = new Resource(RESOURCE_KEY, RESOURCE_NAME, resourceType);
                resource.setUuid(RESOURCE_UUID);
                resource.setAgent(agent);
View Full Code Here

                    int i = 0;
                    for (ListGridRecord selection : selections) {
                        final int agentId = selection.getAttributeAsInt(FIELD_ID);
                        final String agentName = selection.getAttribute(FIELD_NAME);
                        final String agentHost = selection.getAttribute(FIELD_ADDRESS.propertyName()); // this might not be needed
                        final Agent agent = new Agent();
                        agent.setId(agentId);
                        agent.setName(agentName);
                        agent.setAddress(agentHost);
                        agents[i++] = agent;
                    }

                    // ask if we want to uninstall it
                    SC.ask(MSG.view_adminTopology_agent_uninstallConfirm(), new BooleanCallback() {
View Full Code Here

                platformType, ResourceCategory.SERVER);
            ResourceType jvmType = createResourceType("JVM" + System.currentTimeMillis(), "jbossas5", appserverType,
                ResourceCategory.SERVICE);
            ResourceType memType = createResourceType("Memory Subsystem" + System.currentTimeMillis(), "jbossas5",
                jvmType, ResourceCategory.SERVICE);
            Agent agent = new Agent("agent" + System.currentTimeMillis(), "host" + System.currentTimeMillis(), 1, "",
                "token" + System.currentTimeMillis());
            em.persist(agent);
            em.flush();

            Resource platform = createResource(platformType, agent, "platformKey" + System.currentTimeMillis(),
View Full Code Here

        agentName = preprocess(agentName);
        String address = preprocess("localhost");
        int port = 16163;
        String endPoint = "socket://" + address + ":" + port + "/?rhq.communications.connector.rhqtype=agent";

        Agent agent = new Agent(agentName, address, port, endPoint, agentName);

        em.persist(agent);
        em.flush();

        return agent;
View Full Code Here

        // The agent should still be allowed to register again.
        CoreServerServiceImpl service = new CoreServerServiceImpl();
        AgentRegistrationRequest request = createRequest(prefixName("old"), "hostOld", 12345, "oldtoken");
        AgentRegistrationResults results = service.registerAgent(request);
        assert results != null : "cannot re-register an old agent";
        Agent agent = LookupUtil.getAgentManager().getAgentByAgentToken(results.getAgentToken());
        assert agent.getName().equals(request.getName());
        assert agent.getAddress().equals(request.getAddress());
        assert agent.getPort() == request.getPort();
        LookupUtil.getAgentManager().deleteAgent(agent);
    }
View Full Code Here

        // now change Z's host to hostZprime
        request = createRequest(zName, "hostZprime", 55550, results.getAgentToken());
        results = service.registerAgent(request);
        assert results != null;
        Agent agent = LookupUtil.getAgentManager().getAgentByAgentToken(results.getAgentToken());
        assert agent.getName().equals(zName);
        assert agent.getAddress().equals("hostZprime");
        assert agent.getPort() == 55550;

        // now change Z's port to 55551
        request = createRequest(zName, "hostZprime", 55551, results.getAgentToken());
        results = service.registerAgent(request);
        assert results != null;
        agent = LookupUtil.getAgentManager().getAgentByAgentToken(results.getAgentToken());
        assert agent.getName().equals(zName);
        assert agent.getAddress().equals("hostZprime");
        assert agent.getPort() == 55551;

        // now change Z's host/port to hostZdoubleprime/55552
        request = createRequest(zName, "hostZdoubleprime" + tuid, 55552, results.getAgentToken());
        results = service.registerAgent(request);
        assert results != null;
        agent = LookupUtil.getAgentManager().getAgentByAgentToken(results.getAgentToken());
        assert agent.getName().equals(zName);
        assert agent.getAddress().equals("hostZdoubleprime" + tuid);
        assert agent.getPort() == 55552;

        // now don't change Z's host/port but re-register everything the same with its token
        request = createRequest(zName, "hostZdoubleprime" + tuid, 55552, results.getAgentToken());
        results = service.registerAgent(request);
        assert results != null;
        agent = LookupUtil.getAgentManager().getAgentByAgentToken(results.getAgentToken());
        assert agent.getName().equals(zName);
        assert agent.getAddress().equals("hostZdoubleprime" + tuid);
        assert agent.getPort() == 55552;

        // remember this agent so our later tests can use it
        AgentRegistrationRequest zReq = request;
        AgentRegistrationResults zResults = results;
View Full Code Here

TOP

Related Classes of org.rhq.core.domain.resource.Agent

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.