Package org.rhq.core.domain.measurement

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


    // this should only ever be called once, during initial persistence
    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


                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();
View Full Code Here

            category = type.getCategory();
        } else {
            category = ResourceCategory.SERVICE;
        }

        ResourceAvailability resourceAvail = resource.getCurrentAvailability();
        return getResourceIcon(category, resourceAvail.getAvailabilityType(), size);
    }
View Full Code Here

        return;
    }

    private void updateResourceAvailability(Availability reported) {
        ResourceAvailability currentAvailability = resourceAvailabilityManager.getLatestAvailability(reported
            .getResource().getId());

        updateResourceAvailabilityIfNecessary(reported, currentAvailability);
    }
View Full Code Here

        for (ResourceAvailability resourceAvailability : resourceAvailabilityList) {
            resourceAvailabilities.put(resourceAvailability.getResourceId(), resourceAvailability);
        }

        for (Availability reported : reportedChanges) {
            ResourceAvailability currentAvailability = resourceAvailabilities.get(reported.getResource().getId());

            // update the last known availability data for this resource but only if necessary (actually changed)
            updateResourceAvailabilityIfNecessary(reported, currentAvailability);
        }
View Full Code Here

    public AvailabilityType getLatestAvailabilityType(Subject whoami, int resourceId) {
        if (!authorizationManager.canViewResource(whoami, resourceId)) {
            throw new PermissionException("User [" + whoami.getName() + "] does not have permission to view resource");
        }
        ResourceAvailability ra = getLatestAvailability(resourceId);
        return (ra != null) ? ra.getAvailabilityType() : null;
    }
View Full Code Here

    public ResourceAvailability getLatestAvailability(int resourceId) {
        Query query = entityManager.createNamedQuery(ResourceAvailability.QUERY_FIND_BY_RESOURCE_ID);
        query.setParameter("resourceId", resourceId);
        try {
            ResourceAvailability result = (ResourceAvailability) query.getSingleResult();
            return result;
        } catch (NoResultException nre) {
            return null;
        } catch (RuntimeException re) {
            Throwable cause = re.getCause();
View Full Code Here

        Resource res = getResourceById(subject, resourceId);

        // platforms are never unknown, just up or down, so we need to default the availability to a different value
        // depending on the resource's category
        ResourceAvailability result = new ResourceAvailability(res,
            res.getResourceType().getCategory() == ResourceCategory.PLATFORM ? AvailabilityType.DOWN
                : AvailabilityType.UNKNOWN);

        try {
            // validate the resource and agent, protect against REST dummy agent
            Agent agent = agentManager.getAgentByResourceId(subjectManager.getOverlord(), resourceId);
            if (agent == null) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Resource [" + resourceId + "] does not exist or has no agent assigned");
                }
                new IllegalStateException("No agent is associated with the resource with id [" + resourceId + "]");
            } else if (agent.getName().startsWith(ResourceHandlerBean.DUMMY_AGENT_NAME_PREFIX)
                && agent.getAgentToken().startsWith(ResourceHandlerBean.DUMMY_AGENT_TOKEN_PREFIX)) {
                return getResourceById(subject, resourceId).getCurrentAvailability();
            }
            AgentClient client = agentManager.getAgentClient(agent);
            if (client == null) {
                throw new IllegalStateException("No agent is associated with the resource with id [" + resourceId + "]");
            }

            AvailabilityReport report = null;

            // first, quickly see if we can even ping the agent, if not, don't bother trying to get the resource avail
            boolean agentPing = client.pingService(5000L);
            if (agentPing) {
                // we can't serialize the resource due to the hibernate proxies (agent can't deserialize hibernate objs)
                // but we know we only need the basics for the agent to collect availability, so create a bare resource object
                Resource bareResource = new Resource(res.getResourceKey(), res.getName(), res.getResourceType());
                bareResource.setId(res.getId());
                bareResource.setUuid(res.getUuid());
                // root the avail check at the desired resource. Ask for a full report to guarantee that we
                // get back the agent-side avail for the resource and keep the server in sync.  This also means we'll
                // get the descendants as well.
                report = client.getDiscoveryAgentService().getCurrentAvailability(bareResource, false);
            }

            if (report != null) {
                // although the data came from the agent this should be processed like a server-side report
                // because it was requested and initiated by the server (bz 1094540).  The availabilities will
                // still be merged but certain backfill logic will remain unscathed.
                report.setServerSideReport(true);

                AvailabilityType foundAvail = report.forResource(res.getId());
                if (foundAvail != null) {
                    availabilityManager.mergeAvailabilityReport(report);
                } else {
                    foundAvail = res.getCurrentAvailability() == null ? AvailabilityType.UNKNOWN : res
                        .getCurrentAvailability().getAvailabilityType();
                }

                // make sure we don't somehow leak/persist a MISSING avail
                foundAvail = (AvailabilityType.MISSING == foundAvail) ? AvailabilityType.DOWN : foundAvail;
                result.setAvailabilityType(foundAvail);
            }

        } catch (Exception e) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Failed to get live availability: " + e.getMessage());
View Full Code Here

        String name = original.getName();
        String uuid = original.getUuid();
        String resourceKey = original.getResourceKey();
        Resource parent = original.getParentResource();
        ResourceType type = original.getResourceType();
        ResourceAvailability avail = original.getCurrentAvailability();

        return constructResource(id, name, uuid, resourceKey, parent != null ? parent.getId() : null, type.getId(),
            avail != null ? avail.getAvailabilityType() : AvailabilityType.UNKNOWN);
    }
View Full Code Here

     * @return the resource availability
     */
    private ResourceAvailability pingResource(int resourceId) {
        Subject user = getOverlord();
        ResourceManagerLocal resourceManager = LookupUtil.getResourceManager();
        ResourceAvailability avail = resourceManager.getLiveResourceAvailability(user, resourceId);
        return avail;
    }
View Full Code Here

TOP

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

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.