/** {@inheritDoc} */ @Override public CollectionResource getResource() { return m_wrapped.getResource(); }
/** * Gets the attribute value. * * @param sourceAttributes the source attributes * @param index the index * @param type the resource type * @param attrName the attribute name * @return the attribute value */ private String getAttributeValue(List<CollectionAttribute> sourceAttributes, String index, String type, String attrName) { Optional<CollectionAttribute> attr = sourceAttributes.stream().filter(a -> attrName.equals(a.getAttributeType().getName()) && type.equals(a.getResource().getResourceTypeName()) && index.equals(a.getResource().getInstance())).findFirst(); return attr.isPresent() ? attr.get().getStringValue() : null; }
/** * Gets the attribute map. * * @param sourceAttributes the source attributes * @param type the resource type * @param objName the object name * @return the attribute map */ private Map<String, String> getAttributeMap(List<CollectionAttribute> sourceAttributes, String type, String objName) { Map<String,String> attributes = new HashMap<String,String>(); sourceAttributes.stream().filter(a -> objName.equals(a.getAttributeType().getName()) && type.equals(a.getResource().getResourceTypeName())).forEach(a -> attributes.put(a.getResource().getInstance(), a.getStringValue())); return attributes; }
/** * Matches. * * @param sourceType the source type * @param sourceAlias the source alias * @param index the resource index to check * @param a the collection attribute to check * @return true, if successful */ private boolean matches(final String sourceType, final String sourceAlias, final String index, final CollectionAttribute a) { final CollectionResource r = a.getResource(); return a.getName().equals(sourceAlias) && r.getResourceTypeName().equals(sourceType) && r.getInstance().equals(index); }
/** * <p>hasThresholds</p> * * @param attribute a {@link org.opennms.netmgt.collection.api.CollectionAttribute} object. * @return a boolean. */ public boolean hasThresholds(CollectionAttribute attribute) { CollectionResource resource = attribute.getResource(); if (!isCollectionEnabled(attribute.getResource())) return false; if (resource instanceof AliasedResource && !storeByIfAlias) return false; return hasThresholds(resource.getResourceTypeName(), attribute.getName()); }
/** {@inheritDoc} */ @Override public void persistStringAttribute(CollectionAttribute attribute) { LOG.debug("Persisting {}", attribute); CollectionResource resource = attribute.getResource(); String value = attribute.getStringValue(); if (value == null) { LOG.info("No data collected for attribute {}. Skipping.", attribute); return; } try { ResourcePath path = ResourceTypeUtils.getResourcePathWithRepository(m_repository, resource.getPath()); persistStringAttribute(path, attribute.getName(), value); } catch(PersistException e) { LOG.error("Unable to save string attribute {}.", attribute, e); } }
@Override public void visitAttribute(CollectionAttribute attribute) { pushShouldPersist(attribute); if (shouldPersist()) { setBuilder(createBuilder(attribute.getResource(), attribute.getName(), Collections.singleton(attribute.getAttributeType()))); storeAttribute(attribute); } }
/** {@inheritDoc} */ @Override public void visitAttribute(CollectionAttribute attribute) { pushShouldPersist(attribute); if (shouldPersist()) { final RrdPersistOperationBuilder builder = createBuilder(attribute.getResource(), attribute.getName(), Collections.singleton(attribute.getAttributeType())); builder.setAttributeMetadata("GROUP", m_group); setBuilder(builder); storeAttribute(attribute); } }
/** {@inheritDoc} */ @Override public void visitAttribute(CollectionAttribute attribute) { pushShouldPersist(attribute); if (shouldPersist()) { final RrdPersistOperationBuilder builder = createBuilder(attribute.getResource(), attribute.getName(), Collections.singleton(attribute.getAttributeType())); builder.setAttributeMetadata("GROUP", m_group); setBuilder(builder); storeAttribute(attribute); } }
@Override public void visitAttribute(CollectionAttribute attribute) { pushShouldPersist(attribute); if (shouldPersist()) { final String resourceId = getResourceId(attribute.getResource()); final String attribId = resourceId + '/' + attribute.getName(); LOG.debug("visitAttribute: {}", attribId); stats.checkNode(attribute.getResource().getParent().getName()); stats.checkResource(resourceId); if (attribute.getAttributeType().getType().isNumeric()) { stats.checkAttribute(attribId, true); stats.markNumericSamplesMeter(); } else { stats.checkAttribute(attribId, false); } setBuilder(new EvaluatorPersistOperationBuilder()); } }
/** * Test for bug #1817 where a string attribute will get persisted to * both strings.properties and an RRD file if it is a numeric value. */ @Test public void testPersistStringAttributeUsingBuilder() throws Exception { initPersister(); File nodeDir = m_fileAnticipator.expecting(getSnmpRrdDirectory(), m_node.getId().toString()); m_fileAnticipator.expecting(nodeDir, RrdResourceAttributeUtils.STRINGS_PROPERTIES_FILE_NAME); CollectionAttribute attribute = buildStringAttribute(); m_persister.pushShouldPersist(attribute.getResource()); m_persister.pushShouldPersist(attribute); m_persister.setBuilder(m_persister.createBuilder(attribute.getResource(), attribute.getName(), Sets.newHashSet(attribute.getAttributeType()))); // This will end up calling m_persister.persistStringAttribute(attribute); m_persister.storeAttribute(attribute); m_persister.commitBuilder(); m_persister.popShouldPersist(); }