Examples of AvailabilityReport


Examples of org.rhq.core.domain.discovery.AvailabilityReport

            Availability avail;
            long now = System.currentTimeMillis();

            // add a report that says the resource is down
            avail = new Availability(theResource, DOWN);
            AvailabilityReport report = new AvailabilityReport(false, theAgent.getName());
            report.addAvailability(avail);
            availabilityManager.mergeAvailabilityReport(report);

            // now pretend the agent sent us a report from a previous time period - should insert this in the past
            avail = new Availability(theResource, (now - 600000), UP);
            report = new AvailabilityReport(false, theAgent.getName());
            report.addAvailability(avail);
            availabilityManager.mergeAvailabilityReport(report);
            assert getPointInTime(new Date(avail.getStartTime() - 2)) == UNKNOWN;

            //check for current availability.
            Date unknownTime = new Date(avail.getStartTime() - 2);
View Full Code Here

Examples of org.rhq.core.domain.discovery.AvailabilityReport

    public void testMergeReport() throws Exception {
        beginTx();

        try {
            Availability avail;
            AvailabilityReport report;

            setupResource();
            commitAndClose();

            long allAvailCount = setUpAvailabilities();

            // we now have 1:00 UP, 1:20 DOWN, 1:40 UP
            Subject overlord = LookupUtil.getSubjectManager().getOverlord();
            avail = availabilityManager.getCurrentAvailabilityForResource(overlord, theResource.getId());
            assert avail.getAvailabilityType() == UP;
            assert availabilityManager.getCurrentAvailabilityTypeForResource(overlord, theResource.getId()) == UP;

            // add something after the start of last, but still be UP (result: nothing added)
            Long currentStartTime = avail.getStartTime();
            avail = new Availability(theResource, (currentStartTime + 3600000), UP);
            report = new AvailabilityReport(false, theAgent.getName());
            report.addAvailability(avail);
            Thread.sleep(1000);
            availabilityManager.mergeAvailabilityReport(report);

            // the agent should have been updated, but no new rows in availability were added
            Agent agent = LookupUtil.getAgentManager().getAgentByName(theAgent.getName());
            Date lastReport = new Date(agent.getLastAvailabilityReport());
            assert lastReport != null;
            assert countAvailabilitiesInDB().equals(allAvailCount);
            avail = availabilityManager.getCurrentAvailabilityForResource(overlord, theResource.getId());

            // should have returned availability3
            // NOTE: availability3 never got an ID assigned, so we can't compare by id
            //       assert avail.getId() == availability3.getId();
            assert avail.getStartTime().equals(availability3.getStartTime());
            assert avail.getAvailabilityType() == availability3.getAvailabilityType();
            assert Math.abs(avail.getStartTime() - availability3.getStartTime()) < 1000;
            assert avail.getEndTime() == null;
            assert availability3.getEndTime() == null;

            // change start after the start of last (result: add new avail row)
            avail = new Availability(theResource, (currentStartTime + 7200000), DOWN);
            report = new AvailabilityReport(false, theAgent.getName());
            report.addAvailability(avail);
            Thread.sleep(1000);
            availabilityManager.mergeAvailabilityReport(report);

            // the agent should have been updated and a new row in availability was added (resource is now DOWN)
            agent = LookupUtil.getAgentManager().getAgentByName(theAgent.getName());
View Full Code Here

Examples of org.rhq.core.domain.discovery.AvailabilityReport

    public void testMergeReportWithStaleResource() throws Exception {
        beginTx();

        try {
            Availability avail;
            AvailabilityReport report;

            setupResource();
            commitAndClose();

            long allAvailCount = setUpAvailabilities();

            // we now have 1:00 UP, 1:20 DOWN, 1:40 UP
            Subject overlord = LookupUtil.getSubjectManager().getOverlord();
            avail = availabilityManager.getCurrentAvailabilityForResource(overlord, theResource.getId());
            assert avail.getAvailabilityType() == UP;
            assert availabilityManager.getCurrentAvailabilityTypeForResource(overlord, theResource.getId()) == UP;

            // add something after the start of last, but still be UP (result: nothing added)
            Long currentStartTime = avail.getStartTime();
            avail = new Availability(theResource, (currentStartTime + 3600000), UP);
            report = new AvailabilityReport(false, theAgent.getName());
            report.addAvailability(avail);

            // add something with a stale, non-existent resource. It should be ignored, logging a message,
            // and the rest of the report should be processed.
            avail = new Availability(new Resource(898989), (currentStartTime + 3600000), UP);
            report.addAvailability(avail);

            Thread.sleep(1000);
            availabilityManager.mergeAvailabilityReport(report);

            // the agent should have been updated, but no new rows in availability were added
            Agent agent = LookupUtil.getAgentManager().getAgentByName(theAgent.getName());
            Date lastReport = new Date(agent.getLastAvailabilityReport());
            assert lastReport != null;
            assert countAvailabilitiesInDB().equals(allAvailCount);
            avail = availabilityManager.getCurrentAvailabilityForResource(overlord, theResource.getId());

            // should have returned availability3
            // NOTE: availability3 never got an ID assigned, so we can't compare by id
            //       assert avail.getId() == availability3.getId();
            assert avail.getStartTime().equals(availability3.getStartTime());
            assert avail.getAvailabilityType() == availability3.getAvailabilityType();
            assert Math.abs(avail.getStartTime() - availability3.getStartTime()) < 1000;
            assert avail.getEndTime() == null;
            assert availability3.getEndTime() == null;

            // change start after the start of last (result: add new avail row)
            avail = new Availability(theResource, (currentStartTime + 7200000), DOWN);
            report = new AvailabilityReport(false, theAgent.getName());
            report.addAvailability(avail);
            Thread.sleep(1000);
            availabilityManager.mergeAvailabilityReport(report);

            // the agent should have been updated and a new row in availability was added (resource is now DOWN)
            agent = LookupUtil.getAgentManager().getAgentByName(theAgent.getName());
View Full Code Here

Examples of org.rhq.core.domain.discovery.AvailabilityReport

    public void testBZ884338_1() throws Exception {
        beginTx();

        try {
            Availability avail;
            AvailabilityReport report;

            setupResource();
            commitAndClose();

            long allAvailCount = setUpAvailabilities();
            assertTrue("should have >= 3 avail records", 3 <= allAvailCount);
            List<Availability> avails = getResourceAvailabilities(theResource);
            // there is always the UNKNOWN period starting at epoch, plus the three created in setup
            assertEquals(avails.toString(), 4, avails.size());

            // we now have 1:00 UP, 1:20 DOWN, 1:40 UP
            avail = availabilityManager.getCurrentAvailabilityForResource(overlord, theResource.getId());
            assert avail.getAvailabilityType() == UP;

            // insert a duplicate current 1:40 UP and an out-of-order 1:20 DOWN, these should be ignored
            Long currentStartTime = avail.getStartTime();
            long newStartTime = currentStartTime;
            avail = new Availability(theResource, newStartTime, UP);
            report = new AvailabilityReport(false, theAgent.getName());
            report.addAvailability(avail);

            newStartTime = (currentStartTime - (20 * 60 * 1000L));
            avail = new Availability(theResource, newStartTime, DOWN);
            report = new AvailabilityReport(false, theAgent.getName());
            report.addAvailability(avail);

            Thread.sleep(1000);
            availabilityManager.mergeAvailabilityReport(report);

            // the agent should have been updated, but no new rows in availability were added
View Full Code Here

Examples of org.rhq.core.domain.discovery.AvailabilityReport

    public void testBZ884338_2() throws Exception {
        beginTx();

        try {
            Availability avail;
            AvailabilityReport report;

            setupResource();

            commitAndClose();

            long allAvailCount = setUpAvailabilities();
            assertTrue("should have >= 3 avail records", 3 <= allAvailCount);
            List<Availability> avails = getResourceAvailabilities(theResource);
            // there is always the UNKNOWN period starting at epoch, plus the three created in setup
            assertEquals(avails.toString(), 4, avails.size());

            // we now have 1:00 UP, 1:20 DOWN, 1:40 UP
            avail = availabilityManager.getCurrentAvailabilityForResource(overlord, theResource.getId());

            beginTx();

            avail = em.find(Availability.class, avail.getId());
            assert avail.getAvailabilityType() == UP;

            // mess things up by assigning an end time to the latest avail record.
            Long currentStartTime = avail.getStartTime();

            Long nonNullEndTime = currentStartTime + 1000L;
            avail.setEndTime(nonNullEndTime);
            avail = em.merge(avail);

            commitAndClose();

            // try to insert new avail, this should trigger the repair code
            long newStartTime = (currentStartTime + (5 * 60 * 1000L));
            avail = new Availability(theResource, newStartTime, DOWN);
            report = new AvailabilityReport(false, theAgent.getName());
            report.addAvailability(avail);

            Thread.sleep(1000);
            availabilityManager.mergeAvailabilityReport(report);

            // the end time of avail 4 should have been reset to the start time of avail 5. Avail 5 should have been
View Full Code Here

Examples of org.rhq.core.domain.discovery.AvailabilityReport

            commitAndClose();

            // add a report that says the resources are now up - the report will add one avail for each resource
            // at this point, the resources do not yet have a row in availability - after the merge they will have 1
            AvailabilityReport report = new AvailabilityReport(false, theAgent.getName());
            for (Resource resource : allResources) {
                Availability avail = new Availability(resource, UP);
                report.addAvailability(avail);
            }

            long start = System.currentTimeMillis();
            availabilityManager.mergeAvailabilityReport(report);

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

            AvailabilityType curAvail;
            start = System.currentTimeMillis();

            for (Resource resource : allResources) {
                curAvail = availabilityManager.getCurrentAvailabilityTypeForResource(overlord, resource.getId());
                assert curAvail == UP : curAvail;
            }

            System.out.println("testMergeReportPerformance: checking validity of data 1 took "
                + (System.currentTimeMillis() - start) + "ms");

            // add a report that says the resources are now down - the report will add one avail for each resource
            // at this point, the resources have 1 row in availability - after the merge they will have 2
            report = new AvailabilityReport(false, theAgent.getName());
            for (Resource resource : allResources) {
                Availability avail = new Availability(resource, DOWN);
                report.addAvailability(avail);
            }

            start = System.currentTimeMillis();
            availabilityManager.mergeAvailabilityReport(report);

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

            start = System.currentTimeMillis();

            for (Resource resource : allResources) {
                curAvail = availabilityManager.getCurrentAvailabilityTypeForResource(overlord, resource.getId());
                assert curAvail == DOWN : curAvail;
            }

            System.out.println("testMergeReportPerformance: checking validity of data 2 took "
                + (System.currentTimeMillis() - start) + "ms");

            // add a report that says the resources are now unknown - the report will add one avail for each resource
            // at this point, the resources have 2 rows in availability - after the merge they will have 3
            report = new AvailabilityReport(false, theAgent.getName());
            for (Resource resource : allResources) {
                Availability avail = new Availability(resource, UNKNOWN);
                report.addAvailability(avail);
            }

            start = System.currentTimeMillis();
            availabilityManager.mergeAvailabilityReport(report);
View Full Code Here

Examples of org.rhq.core.domain.discovery.AvailabilityReport

     * Convenience method for persisting availability.  Availability data can no longer be directly merged
     * by the EntityManager because it does not update the corresponding currentAvailability data on the
     * Resource entity.  This method will update the necessary objects for you.
     */
    private void persistAvailability(Availability... availabilities) {
        AvailabilityReport report = new AvailabilityReport(false, theAgent.getName());
        for (Availability avail : availabilities) {
            report.addAvailability(avail);
        }
        availabilityManager.mergeAvailabilityReport(report);
    }
View Full Code Here

Examples of org.rhq.core.domain.discovery.AvailabilityReport

        Availability avail;
        List<Availability> avails;
        long now = System.currentTimeMillis();

        AvailabilityReport report = new AvailabilityReport(false, theAgent.getName());

        avails = availabilityManager.getAvailabilitiesForResource(overlord, theResource.getId(), 1, now);
        assert avails.size() == 1 : "Should only be initial unknown avail data";
        assert avails.get(0).getAvailabilityType() == UNKNOWN;
        assert avails.get(0).getStartTime().equals(1L);
        assert avails.get(0).getEndTime().equals(now);

        Long startMillis = 60000L;
        avail = new Availability(theResource, startMillis, UP);
        report.addAvailability(avail);
        availabilityManager.mergeAvailabilityReport(report);
        // platform: UNKNOWN(0) --> UP(60000) -->           

        avails = availabilityManager.getAvailabilitiesForResource(overlord, theResource.getId(), 30000L,
            startMillis + 10000);
        assertEquals("Range should cover both avails", 2, avails.size());
        assert avails.get(0).getAvailabilityType() == UNKNOWN;
        assert avails.get(0).getStartTime().equals(30000L);
        assert avails.get(0).getEndTime().equals(60000L);
        assert avails.get(1).getAvailabilityType() == UP;
        assert avails.get(1).getStartTime().equals(60000L);
        assert avails.get(1).getEndTime().equals(startMillis + 10000);

        avails = availabilityManager.getAvailabilitiesForResource(overlord, theResource.getId(), startMillis,
            startMillis + 10000);
        assertEquals("Range start on avail start border and extending to future", 1, avails.size());
        assert avails.get(0).getAvailabilityType() == UP;
        assert avails.get(0).getStartTime().equals(startMillis);
        assert avails.get(0).getEndTime().equals(startMillis + 10000);

        avails = availabilityManager.getAvailabilitiesForResource(overlord, theResource.getId(), 1000L,
            startMillis - 10000);
        assertEquals("Range completely in first avail", 1, avails.size());
        assert avails.get(0).getAvailabilityType() == UNKNOWN;
        assert avails.get(0).getStartTime().equals(1000L);
        assert avails.get(0).getEndTime().equals(startMillis - 10000);

        avails = availabilityManager.getAvailabilitiesForResource(overlord, theResource.getId(), startMillis + 5000,
            startMillis + 10000);
        assertEquals("Range completely in last avail", 1, avails.size());
        assert avails.get(0).getAvailabilityType() == UP;
        assert avails.get(0).getStartTime().equals(startMillis + 5000);
        assert avails.get(0).getEndTime().equals(startMillis + 10000);

        report = new AvailabilityReport(false, theAgent.getName()); // 70000
        report.setEnablementReport(true); // simulate a real disable
        report.addAvailability(new Availability(theResource, (startMillis + 10000L), DISABLED));
        availabilityManager.mergeAvailabilityReport(report);
        // UNKNOWN(0) --> UP(60000) --> DISABLED(70000) -->           

        // before setting other avails, must end disable with enablement report to unknown
        report = new AvailabilityReport(false, theAgent.getName()); // 75000
        report.setEnablementReport(true);
        report.addAvailability(new Availability(theResource, (startMillis + 15000L), UNKNOWN));
        availabilityManager.mergeAvailabilityReport(report);
        // UNKNOWN(0) --> UP(60000) --> DISABLED(70000) --> UNKNOWN(75000) -->           

        report = new AvailabilityReport(false, theAgent.getName()); // 80000
        report.addAvailability(new Availability(theResource, (startMillis + 20000L), UP));
        availabilityManager.mergeAvailabilityReport(report);
        // UNKNOWN(0) --> UP(60000) --> DISABLED(70000) --> UNKNOWN(75000) --> UP(80000)           

        report = new AvailabilityReport(false, theAgent.getName()); // 90000
        report.addAvailability(new Availability(theResource, (startMillis + 30000L), DOWN));
        availabilityManager.mergeAvailabilityReport(report);
        // UNKNOWN(0) --> UP(60000) --> DISABLED(70000) --> UNKNOWN(75000) --> UP(80000) --> DOWN(90000) -->           

        avails = availabilityManager.getAvailabilitiesForResource(overlord, theResource.getId(), startMillis - 15000,
            startMillis + 35000);
View Full Code Here

Examples of org.rhq.core.domain.discovery.AvailabilityReport

        Availability avail;
        List<Availability> avails;
        long now = System.currentTimeMillis();

        AvailabilityReport report = new AvailabilityReport(false, theAgent.getName());

        avails = availabilityManager.getAvailabilitiesForResource(overlord, theResource.getId(), 1, now);
        assert avails.size() == 1 : "Should only be initial unknown avail data";
        assert avails.get(0).getAvailabilityType() == UNKNOWN;
        assert avails.get(0).getStartTime().equals(1L);
        assert avails.get(0).getEndTime().equals(now);

        Long startMillis = 60000L;
        avail = new Availability(theResource, startMillis, UP);
        report.addAvailability(avail);
        availabilityManager.mergeAvailabilityReport(report);
        // platform: UNKNOWN(0) --> UP(60000) -->           

        avails = availabilityManager.getAvailabilitiesForResource(overlord, theResource.getId(), 30000L,
            startMillis + 10000);
View Full Code Here

Examples of org.rhq.core.domain.discovery.AvailabilityReport

        final Resource r1 = theResource;
        final Resource r2 = additionalResources.get(0);
        final Resource r3 = additionalResources.get(1);

        AvailabilityReport report = new AvailabilityReport(false, theAgent.getName());

        report.addAvailability(new Availability(r1, 10000L, DOWN));
        report.addAvailability(new Availability(r2, 10000L, DOWN));
        report.addAvailability(new Availability(r3, 10000L, DOWN));
        report.addAvailability(new Availability(r1, 20000L, UP));
        report.addAvailability(new Availability(r2, 20000L, UP));
        report.addAvailability(new Availability(r3, 30000L, UP));
        report.addAvailability(new Availability(r3, 40000L, DISABLED));
        availabilityManager.mergeAvailabilityReport(report);

        executeInTransaction(new TransactionCallback() {
            public void execute() throws Exception {
                // Create the test group
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.