Package org.rhq.core.domain.measurement

Examples of org.rhq.core.domain.measurement.Availability


    public void initCurrentAvailability() {
        if (this.currentAvailability == null) {
            // initialize avail to be one big unknown period, starting at epoch.
            this.currentAvailability = new ResourceAvailability(this, AvailabilityType.UNKNOWN);
            this.availability = new ArrayList<Availability>(1);
            this.availability.add(new Availability(this, 0L, AvailabilityType.UNKNOWN));
        }
    }
View Full Code Here


        try {
            setupResource();
            commitAndClose();

            Availability aThen = new Availability(theResource, then, UP);
            aThen.setEndTime(middle);

            Availability aMiddle = new Availability(theResource, middle, DOWN);
            aMiddle.setEndTime(now);

            Availability aNow = new Availability(theResource, now, UP);

            /*
             * Simulate a report (aMiddle) that came in late (e.g. because of sorting
             * issues on the agent or because of a network blip anyway. Expectation is
             * that it gets just inserted in the middle.
View Full Code Here

        try {
            setupResource();
            commitAndClose();

            Availability aThen = new Availability(theResource, then, UP);

            Availability aMiddle = new Availability(theResource, middle, DOWN);
            aMiddle.setEndTime(now);

            Availability aNow = new Availability(theResource, now, UP);

            // UNKNOWN(0) -->
            persistAvailability(aThen);
            // UNKNOWN(0) --> UP(-60000) -->           
            persistAvailability(aMiddle);
View Full Code Here

                setupResource();
            }
        });
        // platform: UNKNOWN(0) -->       

        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

                setupResource();
            }
        });
        // platform: UNKNOWN(0) -->       

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

        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

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

        try {
            List<AvailabilityPoint> availPoints;
            Availability avail;

            setupResource();
            // platform: UNKNOWN(0) -->            
            commitAndClose();

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

            availPoints = availabilityManager.findAvailabilitiesForResource(overlord, theResource.getId(), 1,
                System.currentTimeMillis(), 3, false);
            assert availPoints.size() == 3 : "There is no avail data, but should still get 3 availability points";
            assert availPoints.get(0).getAvailabilityType() == UNKNOWN;
            assert availPoints.get(1).getAvailabilityType() == UNKNOWN;
            assert availPoints.get(2).getAvailabilityType() == UNKNOWN;

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

            // our avail data point is right on the start edge
            availPoints = availabilityManager.findAvailabilitiesForResource(overlord, theResource.getId(), startMillis,
                startMillis + 10000, 3, false);
            assert availPoints.size() == 3 : "There is 1 avail data, but should still get 3 availability points";
            assert availPoints.get(0).getAvailabilityType() == UP;
            assert availPoints.get(1).getAvailabilityType() == UP;
            assert availPoints.get(2).getAvailabilityType() == UP;

            // our avail data point is right on the end edge
            availPoints = availabilityManager.findAvailabilitiesForResource(overlord, theResource.getId(),
                startMillis - 3, startMillis, 3, false);
            assert availPoints.size() == 3 : "There is 1 avail data, but should still get 3 availability points";
            assert availPoints.get(0).getAvailabilityType() == UNKNOWN;
            assert !availPoints.get(0).isKnown() : availPoints;
            assert availPoints.get(1).getAvailabilityType() == UNKNOWN;
            assert !availPoints.get(1).isKnown() : availPoints;
            assert availPoints.get(2).getAvailabilityType() == UNKNOWN;
            assert !availPoints.get(2).isKnown() : availPoints;

            availPoints = availabilityManager.findAvailabilitiesForResource(overlord, theResource.getId(),
                startMillis - 20000, startMillis + 10000, 3, false);
            assert availPoints.size() == 3 : "There is 1 avail data, but should still get 3 availability points";
            assert availPoints.get(0).getAvailabilityType() == UNKNOWN;
            assert !availPoints.get(0).isKnown() : availPoints;
            assert availPoints.get(1).getAvailabilityType() == UNKNOWN;
            assert !availPoints.get(1).isKnown() : availPoints;
            assert availPoints.get(2).getAvailabilityType() == UP : availPoints;

            availPoints = availabilityManager.findAvailabilitiesForResource(overlord, theResource.getId(),
                startMillis - 10000, startMillis + 20000, 3, false);
            assert availPoints.size() == 3 : "There is 1 avail data, but should still get 3 availability points";
            assert availPoints.get(0).getAvailabilityType() == UNKNOWN;
            assert !availPoints.get(0).isKnown() : availPoints;
            assert availPoints.get(1).getAvailabilityType() == UP;
            assert availPoints.get(1).isKnown() : availPoints;
            assert availPoints.get(2).getAvailabilityType() == UP;

            availPoints = availabilityManager.findAvailabilitiesForResource(overlord, theResource.getId(),
                startMillis - 20000, startMillis + 20000, 10, false);
            assert availPoints.size() == 10 : "There is 1 avail data, but should still get 10 availability points";
            assert availPoints.get(0).getAvailabilityType() == UNKNOWN : availPoints;
            assert !availPoints.get(0).isKnown() : availPoints;
            assert availPoints.get(1).getAvailabilityType() == UNKNOWN : availPoints;
            assert !availPoints.get(1).isKnown() : availPoints;
            assert availPoints.get(2).getAvailabilityType() == UNKNOWN : availPoints;
            assert !availPoints.get(2).isKnown() : availPoints;
            assert availPoints.get(3).getAvailabilityType() == UNKNOWN : availPoints;
            assert !availPoints.get(3).isKnown() : availPoints;
            assert availPoints.get(4).getAvailabilityType() == UNKNOWN : availPoints;
            assert !availPoints.get(4).isKnown() : availPoints;
            assert availPoints.get(5).getAvailabilityType() == UP : availPoints;
            assert availPoints.get(5).isKnown() : availPoints;
            assert availPoints.get(6).getAvailabilityType() == UP : availPoints;
            assert availPoints.get(7).getAvailabilityType() == UP : availPoints;
            assert availPoints.get(8).getAvailabilityType() == UP : availPoints;
            assert availPoints.get(9).getAvailabilityType() == UP : availPoints;

            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) -->           

            availPoints = availabilityManager.findAvailabilitiesForResource(overlord, theResource.getId(),
                startMillis - 15000, startMillis + 35000, 5, false); // 45000 - 95000
View Full Code Here

        try {
            setupResource();
            commitAndClose();

            // setAllAgentResourceAvails will only operate on those that have at least 1 avail row
            Availability avail = new Availability(theResource, UNKNOWN);
            persistAvailability(avail);

            assert availabilityManager.getCurrentAvailabilityTypeForResource(overlord, theResource.getId()) == UNKNOWN;
            availabilityManager.updateAgentResourceAvailabilities(theAgent.getId(), UP, UP);
            assert availabilityManager.getCurrentAvailabilityTypeForResource(overlord, theResource.getId()) == UP;
View Full Code Here

            setupResource();
            commitAndClose();

            // add a report that says the resource was up 20 minutes ago
            Availability avail = new Availability(theResource, (System.currentTimeMillis() - 12000000), UP);
            AvailabilityReport report = new AvailabilityReport(false, theAgent.getName());
            report.addAvailability(avail);
            // UNKNOWN(0) -->            
            availabilityManager.mergeAvailabilityReport(report);
            // 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 !!
            // UNKNOWN(0) --> UP(-12000000) -->DOWN(now) -->           
            AvailabilityType curAvail;
            curAvail = availabilityManager.getCurrentAvailabilityTypeForResource(overlord, theResource.getId());
            assert curAvail == DOWN : curAvail;

            // make sure our resource's new availabilities are consistent (first (UNKNOWN) , second (UP), third (DOWN))
            beginTx();
            Resource resource = em.find(Resource.class, theResource.getId());
            List<Availability> allAvails = resource.getAvailability();
            assert allAvails.size() == 3;
            commitAndClose();

            Availability a1 = allAvails.get(0);
            Availability a2 = allAvails.get(1);
            Availability a3 = allAvails.get(2);
            assert a1.getAvailabilityType() == UNKNOWN;
            assert a2.getAvailabilityType() == UP : a2.getAvailabilityType();
            assert a3.getAvailabilityType() == DOWN : a3.getAvailabilityType();
            assert a1.getEndTime() != null;
            assert a2.getEndTime() != null;
            assert a3.getEndTime() == null;
            assert a1.getEndTime() > a1.getStartTime();
            assert a2.getEndTime() > a2.getStartTime();
            assert a2.getStartTime().equals(a1.getEndTime());
            assert a3.getStartTime().equals(a2.getEndTime());

        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        } finally {
View Full Code Here

            commitAndClose();

            for (Resource res : allResources) {
                int resId = res.getId();
                Availability currentAvailability = availabilityManager.getCurrentAvailabilityForResource(overlord,
                    resId);
                assert currentAvailability != null : "Current Availability was null for " + resId;
                assert currentAvailability.getAvailabilityType() == UNKNOWN : "Current AvailabilityType should have been UNKNOWN for "
                    + resId;

                AvailabilityCriteria c = new AvailabilityCriteria();
                c.addFilterResourceId(resId);
                c.addFilterInterval(0L, Long.MAX_VALUE);
                c.addSortStartTime(PageOrdering.ASC);
                List<Availability> allData = availabilityManager.findAvailabilityByCriteria(overlord, c);
                assert allData != null : "All availabilities was null for " + resId;
                assert allData.size() == 1 : "All availabilities size was " + allData.size() + " for " + resId;

                ResourceAvailability currentResAvail = resourceAvailabilityManager.getLatestAvailability(resId);
                assert currentResAvail != null : "Current ResourceAvailability was null for " + resId;
                assert currentResAvail.getAvailabilityType() == UNKNOWN : "Current ResourceAvailabilityType should have been UNKNOWN for "
                    + 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();
            LookupUtil.getAgentManager().checkForSuspectAgents();

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

            AvailabilityType curAvail;
            start = System.currentTimeMillis();
            resNum = 0;

            for (Resource resource : allResources) {
                curAvail = availabilityManager.getCurrentAvailabilityTypeForResource(overlord, resource.getId());
                AvailabilityType expected = (0 == resNum) ? DOWN : ((resNum > 80) ? DISABLED : UNKNOWN);
                ++resNum;
                assert curAvail == expected : "Expected " + expected.name() + " but got " + curAvail.name() + " for "
                    + resource;

                // make sure our resources' new availabilities are consistent
                // the first time we backfilled everything was unknown, only the platform was updated.
                // later we went UP/DISABLED then DOWN so we'll have 2, 3 or 4 rows)
                beginTx();
                resource = em.find(Resource.class, resource.getId());
                List<Availability> allAvails = resource.getAvailability();
                assert allAvails.size() == ((expected == DOWN) ? 4 : ((expected == DISABLED) ? 2 : 3)) : allAvails;
                commitAndClose();

                Availability a0 = allAvails.get(0);
                Availability a1 = allAvails.get(1);
                Availability a2 = null;
                Availability a3 = null;
                assert a0.getAvailabilityType() == UNKNOWN : allAvails;
                switch (expected) {
                case DOWN:
                    // platform
                    a2 = allAvails.get(2);
                    a3 = allAvails.get(3);
                    assert a1.getAvailabilityType() == DOWN : allAvails;
                    assert a2.getAvailabilityType() == UP : allAvails;
                    assert a3.getAvailabilityType() == DOWN : allAvails;
                    assert a0.getEndTime() != null : allAvails;
                    assert a1.getEndTime() != null : allAvails;
                    assert a2.getEndTime() != null : allAvails;
                    assert a3.getEndTime() == null : allAvails;
                    assert a0.getEndTime() > a0.getStartTime() : allAvails;
                    assert a0.getEndTime().equals(a1.getStartTime()) : allAvails;
                    assert a1.getEndTime().equals(a2.getStartTime()) : allAvails;
                    assert a2.getEndTime().equals(a3.getStartTime()) : allAvails;
                    break;
                case DISABLED:
                    assert a1.getAvailabilityType() == DISABLED : allAvails;
                    assert a0.getEndTime() != null : allAvails;
                    assert a1.getEndTime() == null : allAvails;
View Full Code Here

TOP

Related Classes of org.rhq.core.domain.measurement.Availability

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.