|| resourceContainer.getSynchronizationState() != ResourceContainer.SynchronizationState.SYNCHRONIZED) {
return;
}
// The avail proxy guarantees fast response time for an avail check
AvailabilityFacet resourceAvailabilityProxy = resourceContainer.getAvailabilityProxy();
++scan.numResources;
// See if this resource is scheduled for an avail check
boolean checkAvail = false;
boolean deferToParent = false;
long availabilityScheduleTime = resourceContainer.getAvailabilityScheduleTime();
MeasurementScheduleRequest availScheduleRequest = resourceContainer.getAvailabilitySchedule();
// if no avail check is scheduled or we're forcing the check, schedule the next check. Note that a forcedCheck
// is "off-schedule" so we need to push out the next check.
if ((0 == availabilityScheduleTime) || isForced) {
// if there is no availability schedule (platform) then just perform the avail check
// (note, platforms always return UP anyway).
if (null == availScheduleRequest) {
if (traceEnabled) {
LOG.trace("No availScheduleRequest for " + resource + ". checkAvail set to true");
}
checkAvail = true;
} else {
// if the schedule is enabled then schedule the next avail check, else just defer to the parent type
if (availScheduleRequest.isEnabled()) {
// Schedule the avail check at some time between now and (now + collectionInterval). By
// doing this random assignment for the first scheduled collection, we'll spread out the actual
// check times going forward. Do not check it on this pass (unless we're forced)
int interval = (int) availScheduleRequest.getInterval(); // intervals are short enough for safe cast
availabilityScheduleTime = scan.startTime + RANDOM.nextInt(interval + 1);
resourceContainer.setAvailabilityScheduleTime(availabilityScheduleTime);
if (traceEnabled) {
LOG.trace("Forced availabilityScheduleTime to " + new Date(availabilityScheduleTime) + " for "
+ resource);
}
++scan.numScheduledRandomly;
} else {
if (traceEnabled) {
LOG.trace("Deferred availability to parent for " + resource);
}
deferToParent = true;
}
}
} else {
// check avail if this resource scheduled time has been reached
checkAvail = scan.startTime >= availabilityScheduleTime;
if (checkAvail) {
if (traceEnabled) {
LOG.trace("Scheduled time has been reached for " + resource);
}
long interval = availScheduleRequest.getInterval(); // intervals are short enough for safe cast
resourceContainer.setAvailabilityScheduleTime(scan.startTime + interval);
++scan.numPushedByInterval;
} else {
if (traceEnabled) {
LOG.trace("Scheduled time has not been reached for " + resource);
}
}
}
// find out what the avail was the last time we checked it. this may be null
Availability previous = this.inventoryManager.getAvailabilityIfKnown(resource);
AvailabilityType previousType = (null == previous) ? UNKNOWN : previous.getAvailabilityType();
AvailabilityType current = null;
// If the resource's parent is DOWN, the rules are that the resource and all of the parent's other
// descendants, must also be DOWN. So, there's no need to even ask the resource component
// for its current availability - its current avail is set to the parent avail type and that's that.
// Otherwise, checkAvail as needed.
if (deferToParent || (DOWN == parentAvailType)) {
current = parentAvailType;
++scan.numDeferToParent;
// For the DOWN parent case it's unclear to me whether we should push out the avail check time of
// the child. For now, we'll leave it alone and let the next check happen according to the
// schedule already established.
if (traceEnabled) {
LOG.trace("Gave parent availability " + parentAvailType + " to " + resource);
}
} else {
// regardless of whether the avail schedule is met, we still must check avail if isForce is true or if
// it's a full report and we don't yet have an avail for the resource.
if (!checkAvail && (isForced || (scan.isFull && null == previous))) {
checkAvail = true;
}
if (checkAvail) {
if (traceEnabled) {
LOG.trace("Now checking availability for " + resource);
}
try {
++scan.numGetAvailabilityCalls;
// if the component is started, ask what its current availability is as of right now;
// if it's not started, then assume it's down, and the next time we check,
// we'll see if it's started and check for real then - otherwise, keep assuming it's
// down (this is for the case when a plugin component can't start for whatever reason
// or is just slow to start)
if (resourceContainer.getResourceComponentState() == ResourceComponentState.STARTED) {
current = translate(resourceAvailabilityProxy.getAvailability(), previousType);
} else {
// try to start the component and then perform the avail check
this.inventoryManager.activateResource(resource, resourceContainer, false);
if (resourceContainer.getResourceComponentState() == ResourceComponentState.STARTED) {
current = translate(resourceAvailabilityProxy.getAvailability(), previousType);
} else {
current = DOWN;
}
}
if (traceEnabled) {