public boolean hasThresholds(final String resourceTypeName, final String attributeName) { boolean ok = false; synchronized(m_thresholdGroups) { for (ThresholdGroup group : m_thresholdGroups) { Map<String,Set<ThresholdEntity>> entityMap = getEntityMap(group, resourceTypeName); if (entityMap != null) { for (final Entry<String, Set<ThresholdEntity>> entry : entityMap.entrySet()) { final Set<ThresholdEntity> value = entry.getValue(); for (final ThresholdEntity thresholdEntity : value) { final Collection<String> requiredDatasources = thresholdEntity.getRequiredDatasources(); if (requiredDatasources.contains(attributeName)) { ok = true; LOG.debug("hasThresholds: {}@{}? {}", resourceTypeName, attributeName, ok); } else { LOG.trace("hasThresholds: {}@{}? {}", resourceTypeName, attributeName, ok); } } } } } } return ok; }
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")); }