/** * Returns the names of the dataousrces required to evaluate this threshold entity * * @return Collection of the names of datasources */ public Collection<String> getRequiredDatasources() { if (hasThresholds()) { final Set<String> dataSources = new HashSet<String>(); dataSources.addAll(getThresholdConfig().getRequiredDatasources()); dataSources.addAll(getThresholdConfig().getFilterDatasources()); return dataSources; } else { throw new IllegalStateException("No thresholds have been added."); } } /**
if (passedThresholdFilters(resourceWrapper, thresholdEntity)) { LOG.info("applyThresholds: Processing threshold {} : {} on resource {}", key, thresholdEntity, resourceWrapper); Collection<String> requiredDatasources = thresholdEntity.getThresholdConfig().getRequiredDatasources(); final Map<String, Double> values = new HashMap<String,Double>(); boolean valueMissing = false;
public void testThresholdEntityRequiredDataSources() throws Exception { ThresholdEntity entity=new ThresholdEntity(); expression.setExpression("(hrStorageSize-hrStorageUsed)*hrStorageAllocationUnits"); BaseThresholdDefConfigWrapper wrapper=BaseThresholdDefConfigWrapper.getConfigWrapper(expression); assertEquals(3, wrapper.getRequiredDatasources().size()); for (String ds : new String[] { "hrStorageSize", "hrStorageUsed", "hrStorageAllocationUnits" }) { assertTrue("Could not find expected variable: " + ds, wrapper.getRequiredDatasources().contains(ds)); } entity.addThreshold(wrapper); Collection<String> dataSources=entity.getRequiredDatasources(); final StringBuilder dsStringBuffer = new StringBuilder(); for (String dataSource : dataSources) { dsStringBuffer.append(dataSource).append(" "); } String dsString = dsStringBuffer.toString().trim(); assertTrue("Required data sources should contain hrStorageSize: " + dsString, dataSources.contains("hrStorageSize")); assertTrue("Required data sources should contain hrStorageUsed: " + dsString, dataSources.contains("hrStorageUsed")); assertTrue("Required data sources should contain hrStorageAllocationUnits: " + dsString, dataSources.contains("hrStorageAllocationUnits")); }