/** {@inheritDoc} */ @Override public CollectionAttributeType getAttributeType() { return m_wrapped.getAttributeType(); }
public List<CollectionAttribute> getStringAttributes() { return m_groups.values().stream() .flatMap(g -> g.getAttributes().stream()) .filter(a -> a.getAttributeType() instanceof NumericCollectionAttributeType == false || AttributeType.STRING.equals(a.getAttributeType().getType())) .collect(Collectors.toList()); }
/** * Adds the given attribute into the collection for this resource * * @param attr The Attribute to add */ public final void addAttribute(CollectionAttribute attr) { AttributeGroup group = getGroup(attr.getAttributeType().getGroupType()); LOG.debug("Adding attribute {}: {} to group {}", attr.getClass().getName(), attr, group); group.addAttribute(attr); }
/** * 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; }
/** * Adds the given attribute into the collection for this resource * * @param attr The Attribute to add */ public void addAttribute(CollectionAttribute attr) { AttributeGroup group = getGroup(attr.getAttributeType().getGroupType()); group.addAttribute(attr); }
/** * Adds the given attribute into the collection for this resource * * @param attr The Attribute to add */ public void addAttribute(CollectionAttribute attr) { AttributeGroup group = getGroup(attr.getAttributeType().getGroupType()); group.addAttribute(attr); }
/** * Adds the given attribute into the collection for this resource * * @param attr The Attribute to add */ public void addAttribute(CollectionAttribute attr) { AttributeGroup group = getGroup(attr.getAttributeType().getGroupType()); group.addAttribute(attr); }
@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 persistNumericAttribute(CollectionAttribute attribute) { boolean shouldIgnorePersist = isIgnorePersist() && AttributeType.COUNTER.equals(attribute.getType()); LOG.debug("Persisting {} {}", attribute, (shouldIgnorePersist ? ". Ignoring value because of sysUpTime changed." : "")); Number value = shouldIgnorePersist ? Double.NaN : attribute.getNumericValue(); m_builder.setAttributeValue(attribute.getAttributeType(), value); m_builder.setAttributeMetadata(attribute.getMetricIdentifier(), attribute.getName()); }
/** {@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); } }
private void addGroupToBuilder(CollectionSetBuilder builder, Resource resource, AttributeGroup group) { for (CollectionAttribute attribute : group.getAttributes()) { String value; if(!attribute.shouldPersist(params)){ continue; } else if (attribute.getAttributeType() instanceof HexStringAttributeType) { value = ((SnmpAttribute) attribute).getValue().toHexString(); } else { value = attribute.getStringValue(); } builder.withAttribute(resource, group.getName(), attribute.getName(), value, attribute.getType()); } } }
@Override public void visitGroup(AttributeGroup group) { pushShouldPersist(group); if (shouldPersist()) { final String resourceId = getResourceId(group.getResource()); final String groupId = resourceId + '/' + group.getName(); LOG.debug("visitGroup: {} = {}", groupId, group.getAttributes().size()); stats.checkNode(group.getResource().getParent().getName()); stats.checkGroup(groupId); stats.checkResource(resourceId); group.getAttributes().forEach(a -> { final String attribId = resourceId + '/' + a.getName(); if (a.getAttributeType().getType().isNumeric()) { LOG.debug("visitGroup: attribute {}", attribId); stats.checkAttribute(attribId, true); stats.markNumericSamplesMeter(); } else { stats.checkAttribute(attribId, false); } }); setBuilder(new EvaluatorPersistOperationBuilder()); } }
@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(); }