@Override public String toString() { return toString(false); }
public void setEnablementReport(boolean enablementReport) { this.enablementReport = enablementReport; // all enablement reports are generated server side if (enablementReport) { setServerSideReport(true); } }
public boolean isEnablementReport() { return report.isEnablementReport(); }
AvailabilityReport report = reports.get(agent); if (null == report) { report = new AvailabilityReport(agent.getName()); report.setEnablementReport(true); reports.put(agent, report); report.addAvailability(new AvailabilityReport.Datum(familyResourceId, AvailabilityType.UNKNOWN, now));
@Override @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) public void setResourceAvailabilities(Map<Agent, int[]> map, AvailabilityType avail) { long now = System.currentTimeMillis(); for (Agent agent : map.keySet()) { AvailabilityReport report = new AvailabilityReport(true, null); report.setServerSideReport(true); for (int resourceId : map.get(agent)) { report.addAvailability(new Datum(resourceId, avail, now)); } AvailabilityReportSerializer.getSingleton().lock(agent.getName()); try { this.availabilityManager.mergeAvailabilityReport(report); } finally { AvailabilityReportSerializer.getSingleton().unlock(agent.getName()); } } return; }
@Override @TransactionAttribute(TransactionAttributeType.NEVER) public boolean mergeAvailabilityReport(AvailabilityReport report) { int reportSize = report.getResourceAvailability().size(); String agentName = report.getAgentName(); StopWatch watch = new StopWatch(); List<Availability> availabilities = new ArrayList<Availability>(report.getResourceAvailability().size()); for (AvailabilityReport.Datum datum : report.getResourceAvailability()) { availabilities.add(new Availability(new Resource(datum.getResourceId()), datum.getStartTime(), datum .getAvailabilityType())); if (!report.isServerSideReport() && agentToUpdate != null) { if (report.isChangesOnlyReport() && agentManager.isAgentBackfilled(agentToUpdate.intValue())) { mergeInfo.setAskForFullReport(true); MeasurementMonitor.getMBean().incrementAvailabilityReports(report.isChangesOnlyReport()); MeasurementMonitor.getMBean().incrementAvailabilitiesInserted(mergeInfo.getNumInserted()); MeasurementMonitor.getMBean().incrementAvailabilityInsertTime(watch.getElapsed()); watch.reset(); if (!report.isServerSideReport()) { if (agentToUpdate != null) { if (mergeInfo.isAskForFullReport() && report.isChangesOnlyReport()) { log.debug("The server is unsure that it has up-to-date availabilities for agent [" + agentName + "]; asking for a full report to be sent");
List<AvailabilityReport.Datum> reportAvails = report.getResourceAvailability(); log.info("Sending availability report to Server..."); if (log.isDebugEnabled()) { log.debug("Availability report content: " + report.toString(log.isTraceEnabled()));
@Override public boolean mergeAvailabilityReport(AvailabilityReport availabilityReport) { AvailabilityReportSerializer.getSingleton().lock(availabilityReport.getAgentName()); try { String reportToString = availabilityReport.toString(false); if (log.isDebugEnabled()) log.debug("Processing " + reportToString); long start = System.currentTimeMillis(); AvailabilityManagerLocal availabilityManager = LookupUtil.getAvailabilityManager(); boolean ok = availabilityManager.mergeAvailabilityReport(availabilityReport); long elapsed = (System.currentTimeMillis() - start); if (elapsed > 20000L) { log.warn("Performance: processed " + reportToString + " - needFull=[" + !ok + "] in (" + elapsed + ")ms"); } else { if (log.isDebugEnabled()) { log.debug("Performance: processed " + reportToString + " - needFull=[" + !ok + "] in (" + elapsed + ")ms"); } } return ok; } catch (Exception e) { log.info("Error processing availability report from [" + availabilityReport.getAgentName() + "]: " + ThrowableUtil.getAllMessages(e)); return true; // not sure what happened, but avoid infinite recursion during error conditions; do not ask for a full report } finally { AvailabilityReportSerializer.getSingleton().unlock(availabilityReport.getAgentName()); } }
@PUT @Path("/{id}/availability") @ApiOperation("Set the current availability of the passed resource") @TransactionAttribute(TransactionAttributeType.NEVER) public void reportAvailability(@ApiParam("Id of the resource to update") @PathParam("id") int resourceId, @ApiParam(value= "New Availability setting", required = true) AvailabilityRest avail) { if (avail.getResourceId() != resourceId) throw new IllegalArgumentException("Resource Ids do not match"); Resource resource = fetchResource(resourceId); AvailabilityType at; at = AvailabilityType.valueOf(avail.getType()); // According to jshaughn, plaforms must not be set to DISABLED, so catch this case here. if (resource.getResourceType().getCategory()==ResourceCategory.PLATFORM && at==AvailabilityType.DISABLED) { throw new BadArgumentException("Availability","Platforms must not be set to DISABLED"); } Agent agent = agentMgr.getAgentByResourceId(caller,resourceId); AvailabilityReport report = new AvailabilityReport(true, agent.getName()); Availability availability = new Availability(resource, avail.getSince(), at); report.addAvailability(availability); availMgr.mergeAvailabilityReport(report); }
report.setServerSideReport(true); AvailabilityType foundAvail = report.forResource(res.getId()); if (foundAvail != null) { availabilityManager.mergeAvailabilityReport(report);
oos = new ObjectOutputStream(baos); oos.writeObject(availabilityReport); LOG.debug("Built availability report for [" + availabilityReport.getResourceAvailability().size() + "] resources with a size of [" + baos.size() + "] bytes in [" + (end - start) + "]ms"); } catch (IOException e) {
@Override @NotNull public AvailabilityReport getCurrentAvailability(Resource resource, boolean changesOnly) { try { //make sure we have the full version of the resource ResourceContainer container = getResourceContainer(resource.getId()); if (container == null) { //don't bother doing anything return new AvailabilityReport(changesOnly, getAgent().getName()); } resource = container.getResource(); MeasurementScheduleRequest availSchedule = container.getAvailabilitySchedule(); boolean forceScanForRoot = availSchedule == null || availSchedule.isEnabled(); // force scan for root resource only if availability schedule is enabled AvailabilityExecutor availExec = new CustomScanRootAvailabilityExecutor(this, resource, forceScanForRoot); if (changesOnly) { availExec.sendChangesOnlyReportNextTime(); } else { availExec.sendFullReportNextTime(); } return availabilityThreadPoolExecutor.submit((Callable<AvailabilityReport>) availExec).get(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new RuntimeException("Availability scan execution was interrupted", e); } catch (ExecutionException e) { // Should never happen, reports are always generated, even if they're just to report the error throw new RuntimeException("Unexpected exception", e); } }
availabilityReport.addAvailability(availability);
AvailabilityReport report = reports.get(agent); if (null == report) { report = new AvailabilityReport(agent.getName()); report.setEnablementReport(true); reports.put(agent, report); report.addAvailability(new AvailabilityReport.Datum(familyResourceId, AvailabilityType.DISABLED, now));
/** * Shows the list of availabilities known so far * for resources that have been discovered * @param tokens tokenized command line tokens[0] is the command itself */ private void avail(String[] tokens) { Set<Resource> resources = getResources(); int id = getResourceIdFromTokens(tokens, 0); for (Resource res : resources) { if (id == 0 || (res.getId() == id)) { AvailabilityReport availabilityReport = inventoryManager.getCurrentAvailability(res, false); for(AvailabilityReport.Datum datum : availabilityReport.getResourceAvailability()) { if (datum.getResourceId() == res.getId()) { System.out.println(res.getName() + "( " + res.getId() + " ):" + datum.getAvailabilityType()); break; } } } } }
availabilityReport = new AvailabilityReport(changesOnly, inventoryManager.getAgent().getName());
public String toString(boolean includeAll) { return report.toString(includeAll); } }