Package org.rhq.core.domain.resource

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


    public static void main(String[] args) throws Exception {
        ExternalizableStrategy.setStrategy(Subsystem.REFLECTIVE_SERIALIZATION);

        // create objects
        Agent writeAgent = new Agent("reflectiveAgent", "reflectiveAddress", 0, "reflectiveEndpoint", "reflectiveToken");

        ResourceType writeResourceType = new ResourceType();
        writeResourceType.setName("reflectiveType");
        writeResourceType.setPlugin("reflectivePlugin");
        writeResourceType.setId(7);

        Resource writeParentResource = new Resource();
        writeParentResource.setId(11);
        writeParentResource.setName("reflectiveParentResource");
        writeParentResource.setResourceKey("reflectiveParentKey");

        Resource writeResource = new Resource();
        writeResource.setId(42);
        writeResource.setName("reflectiveResource");
        writeResource.setResourceKey("reflectiveKey");

        // setup relationships
        writeResource.setAgent(writeAgent);
        writeResource.setResourceType(writeResourceType);
        writeResource.setParentResource(writeParentResource);

        System.out.println("BEFORE");
        System.out.println(writeResource.toString());
        System.out.println("BEFORE");

        String tempDir = System.getProperty("java.io.tmpdir");
        File tempFile = new File(tempDir, "entitySerializerTest.txt");

        FileOutputStream fos = new FileOutputStream(tempFile);
        try {
            ObjectOutput output = new ObjectOutputStream(fos);
            try {
                writeExternalRemote(writeResource, output);
            } finally {
                output.close();
            }
        } finally {
            fos.close();
        }

        Resource readResource = new Resource();
        FileInputStream fis = new FileInputStream(tempFile);
        try {
            ObjectInput ois = new ObjectInputStream(fis);
            try {
                readExternalRemote(readResource, ois);
            } finally {
                ois.close();
            }
        } finally {
            fis.close();
        }

        // quick verification
        System.out.println("AFTER");
        System.out.println(readResource.toString());
        System.out.println("AFTER");

        // deeper verification
        boolean equalsResource = writeResource.equals(readResource);
        boolean equalsParentResource = writeParentResource.equals(readResource.getParentResource());
        boolean equalsResourceType = writeResourceType.equals(readResource.getResourceType());
        boolean equalsAgent = writeAgent.equals(readResource.getAgent());

        System.out.println("equalsResource: " + equalsResource);
        System.out.println("equalsParentResource: " + equalsParentResource);
        System.out.println("equalsResourceType: " + equalsResourceType);
        System.out.println("equalsAgent: " + equalsAgent);
View Full Code Here


        Date now = new Date();

        Query q = em.createQuery("SELECT r FROM Resource r");
        List<Resource> resources = q.getResultList();
        Resource res = resources.get(0);
        Agent agent = agentManager.getAgentByResourceId(overlord, res.getId());

        q = em.createQuery("SELECT COUNT(a) FROM Availability a ");
        Object o = q.getSingleResult();
        Long l = (Long) o;
        if (l != 0) {
            throw new IllegalStateException("Availabilities table is not empty");
        }
        systemManager.vacuum(overlord, new String[] { "rhq_availability" });

        for (int MULTI : ROUNDS) {
            String round = String.format(ROUND__FORMAT, MULTI);

            long t1 = System.currentTimeMillis() - (MULTI * MILLIS_APART);
            for (int i = 0; i < MULTI; i++) {

                AvailabilityReport report = new AvailabilityReport(agent.getName());
                for (Resource r : resources) {
                    AvailabilityType at = (i % 2 == 0) ? AvailabilityType.UP : AvailabilityType.DOWN;
                    Availability a = new Availability(r, (t1 + i * MILLIS_APART), at);
                    report.addAvailability(a);
                }
View Full Code Here

        Subject overlord = LookupUtil.getSubjectManager().getOverlord();

        Query q = em.createQuery("SELECT r FROM Resource r");
        List<Resource> resources = q.getResultList();
        Resource res = resources.get(0);
        Agent agent = agentManager.getAgentByResourceId(overlord, res.getId());

        for (int MULTI : ROUNDS) {
            String round = String.format(ROUND__FORMAT, MULTI);

            long t1 = System.currentTimeMillis() - (MULTI * MILLIS_APART);
            for (int i = 0; i < MULTI; i++) {

                AvailabilityReport report = new AvailabilityReport(agent.getName());
                for (Resource r : resources) {
                    int rand = (int) (Math.random() * 2);
                    AvailabilityType at = (rand == 1) ? AvailabilityType.UP : AvailabilityType.DOWN;
                    Availability a = new Availability(r, (t1 + i * MILLIS_APART), at);
                    report.addAvailability(a);
View Full Code Here

        Subject overlord = LookupUtil.getSubjectManager().getOverlord();

        Query q = em.createQuery("SELECT r FROM Resource r");
        List<Resource> resources = q.getResultList();
        Resource res = resources.get(0);
        Agent agent = agentManager.getAgentByResourceId(overlord, res.getId());

        for (int MULTI : ROUNDS) {
            String round = String.format(ROUND__FORMAT, MULTI);

            long t1 = System.currentTimeMillis() - (MULTI * MILLIS_APART);
            for (int i = 0; i < MULTI; i++) {

                AvailabilityReport report = new AvailabilityReport(agent.getName());
                for (Resource r : resources) {
                    AvailabilityType at = AvailabilityType.UP;
                    Availability a = new Availability(r, (t1 + i * MILLIS_APART), at);
                    report.addAvailability(a);
                }
View Full Code Here

        Subject overlord = LookupUtil.getSubjectManager().getOverlord();

        Query q = em.createQuery("SELECT r FROM Resource r");
        List<Resource> resources = q.getResultList();
        Resource res = resources.get(0);
        Agent agent = agentManager.getAgentByResourceId(overlord, res.getId());

        q = em.createQuery("SELECT COUNT(a) FROM Availability a ");
        Object o = q.getSingleResult();
        Long l = (Long) o;
        if (l != 0) {
            throw new IllegalStateException("Availabilities table is not empty");
        }
        systemManager.vacuum(overlord, new String[] { "rhq_availability" });

        // Set up an alert definition on one resource
        AlertCondition goingDown = new AlertCondition();
        goingDown.setCategory(AlertConditionCategory.AVAILABILITY);
        goingDown.setComparator("==");
        goingDown.setOption(AvailabilityType.DOWN.toString());

        AlertDefinition def = new AlertDefinition();
        def.addCondition(goingDown);
        def.setName("Test alert definition");
        def.setPriority(AlertPriority.MEDIUM);
        def.setAlertDampening(new AlertDampening(AlertDampening.Category.NONE));
        def.setRecoveryId(0);
        alertDefinitionManager.createAlertDefinitionInNewTransaction(overlord, def, res.getId(), true);

        for (int MULTI : ROUNDS) {
            String round = String.format(ROUND__FORMAT, MULTI);

            long t1 = System.currentTimeMillis() - (MULTI * MILLIS_APART);
            for (int i = 0; i < MULTI; i++) {

                AvailabilityReport report = new AvailabilityReport(agent.getName());
                for (Resource r : resources) {
                    AvailabilityType at = (i % 2 == 0) ? AvailabilityType.UP : AvailabilityType.DOWN;
                    Availability a = new Availability(r, (t1 + i * MILLIS_APART), at);
                    report.addAvailability(a);
                }
View Full Code Here

                server.setComputePower(1);
                server.setOperationMode(Server.OperationMode.MAINTENANCE);
                int serverId = LookupUtil.getServerManager().create(server);
                assert serverId > 0 : "could not create our server identity in the DB";

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

                dynamicMeasuremenDef = new MeasurementDefinition(resourceType, DYNAMIC_DEF_NAME);
                dynamicMeasuremenDef.setDefaultOn(true);
View Full Code Here

            // UNKNOWN(0) --> UP(-12000000) -->           
            assert availabilityManager.getCurrentAvailabilityTypeForResource(overlord, theResource.getId()) == UP;

            // let's pretend we haven't heard from the agent in a few minutes
            beginTx();
            Agent agent = em.find(Agent.class, theAgent.getId());
            agent.setLastAvailabilityPing(System.currentTimeMillis() - (1000 * 60 * 18)); // 18 mins
            commitAndClose();

            // the agent should be suspect and will be considered down, the platform resource should be down
            // (although children should be UNKNOWN)
            LookupUtil.getAgentManager().checkForSuspectAgents(); // checks for 5 mins !!
View Full Code Here

                    + resId;
            }

            // let's pretend we haven't heard from the agent in a few minutes
            beginTx();
            Agent agent = em.find(Agent.class, theAgent.getId());
            agent.setLastAvailabilityPing(System.currentTimeMillis() - (1000 * 60 * 18)); // 18 mins
            commitAndClose();

            // the agent should be suspect and will be considered down. the resources have their initial
            // UNKNOWN avails.  The platform should get a new DOWN Availability row. The rest should remain
            // as is since they are already UNKNOWN.
            long start = System.currentTimeMillis();
            LookupUtil.getAgentManager().checkForSuspectAgents();

            System.out.println("testAgentBackfillPerformance: checkForSuspectAgents run 1 took "
                + (System.currentTimeMillis() - start) + "ms");

            // add a report that says the resources are now up or disabled- the report will add one avail for each
            // resource
            Thread.sleep(500);
            AvailabilityReport upReport = new AvailabilityReport(false, theAgent.getName());
            AvailabilityReport disabledReport = new AvailabilityReport(false, theAgent.getName());
            disabledReport.setEnablementReport(true);
            int resNum = 0;
            for (Resource resource : allResources) {
                if (resNum++ <= 80) {
                    upReport.addAvailability(new Availability(resource, UP));
                } else {
                    disabledReport.addAvailability(new Availability(resource, DISABLED));
                }
            }

            start = System.currentTimeMillis();
            availabilityManager.mergeAvailabilityReport(upReport);
            availabilityManager.mergeAvailabilityReport(disabledReport);

            System.out.println("testAgentBackfillPerformance: mergeAvailabilityReport run took "
                + (System.currentTimeMillis() - start) + "ms");

            // sanity check - make sure the merge at least appeared to work
            assert availabilityManager.getCurrentAvailabilityTypeForResource(overlord, theResource.getId()) == UP;

            // let's again pretend we haven't heard from the agent in a few minutes
            beginTx();
            agent = em.find(Agent.class, theAgent.getId());
            agent.setLastAvailabilityPing(System.currentTimeMillis() - (1000 * 60 * 18));
            commitAndClose();

            // the agent should be suspect and will be considered down
            // all of the resources have availabilities now, so another row will be added to them if they are not disabled
            start = System.currentTimeMillis();
View Full Code Here

        }
    }

    protected int getAgentId() throws NoResultException {
        try {
            Agent existingAgent = getAgent();
            int agentId = existingAgent.getId();
            return agentId;
        } catch (NoResultException nre) {
            throw nre;
        }
    }
View Full Code Here

            throw nre;
        }
    }

    protected Agent getAgent() throws NoResultException {
        Agent existingAgent;
        try {
            existingAgent = (Agent) em.createNamedQuery(Agent.QUERY_FIND_BY_NAME).setParameter("name", AGENT_NAME)
                .getSingleResult();
            return existingAgent;
        } catch (NoResultException nre) {
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.