/** * Gets the last filename. * * @param serviceName the service name * @param resourceDir the resource directory * @param targetPath the target path * @return the last filename * @throws Exception the exception */ public static String getLastFilename(ResourceStorageDao resourceStorageDao, String serviceName, ResourcePath path, String targetPath) throws Exception { String filename = null; try { filename = resourceStorageDao.getStringAttribute(path, getCacheId(serviceName, targetPath)); } catch (Throwable e) { LOG.info("getLastFilename: creating a new filename tracker on {}", path); } return filename; }
/** * Sets the last filename. * * @param serviceName the service name * @param resourceDir the resource directory * @param targetPath the target path * @param filename the filename * @throws Exception the exception */ public static void setLastFilename(ResourceStorageDao resourceStorageDao, String serviceName, ResourcePath path, String targetPath, String filename) throws Exception { resourceStorageDao.setStringAttribute(path, getCacheId(serviceName, targetPath), filename); }
/** * <p>getQueryableIndexesForNodeSource</p> * * @param nodeSource a String. * @return a {@link java.util.List} object. */ private List<String> getQueryableIndexes(ResourcePath path) { return m_resourceStorageDao.children(path, 1).stream() .map(ResourcePath::getName) .collect(Collectors.toList()); }
@Override public boolean isResourceTypeOnParent(OnmsResource parent) { return m_resourceStorageDao.exists(parent.getPath(), 1); }
@Override public Set<OnmsAttribute> load() { return m_resourceStorageDao.getAttributes(m_path); } }
/** {@inheritDoc} */ @Override public void visitGroup(AttributeGroup group) { pushShouldPersist(group); if (shouldPersist()) { Map<String, String> dsNamesToRrdNames = new LinkedHashMap<String , String>(); for (CollectionAttribute a : group.getAttributes()) { if (a.getType().isNumeric()) { dsNamesToRrdNames.put(a.getName(), group.getName()); } } setBuilder(createBuilder(group.getResource(), group.getName(), group.getGroupType().getAttributeTypes())); ResourcePath path = ResourceTypeUtils.getResourcePathWithRepository(getRepository(), group.getResource().getPath()); m_resourceStorageDao.updateMetricToResourceMappings(path, dsNamesToRrdNames); } }
public boolean deleteResource(final OnmsResource resource, boolean recursive) { boolean result = false; if (recursive) { for (final OnmsResource childResource : resource.getChildResources()) { result = deleteResource(childResource, recursive) || result; } } result = m_resourceStorageDao.delete(resource.getPath()) || result; return result; }
final Set<Entry<String, String>> metaDataEntrySet = m_resourceStorageDao.getMetaData(pathToMetaFile).entrySet(); logger.debug("Meta-data for attribute '{}' at path '{}' contains: {}", attr, pathToMetaFile, metaDataEntrySet); if (metaDataEntrySet == null) continue;
/** {@inheritDoc} */ @Override public boolean isResourceTypeOnParent(OnmsResource parent) { if (parent == null) { return false; } return m_resourceStorageDao.exists(new ResourcePath(parent.getPath(), m_name), 1); }
@Override public Set<OnmsAttribute> load() { Set<OnmsAttribute> attributes = m_resourceStorageDao.getAttributes(m_path); if (m_snmpInterface != null) { attributes.add(new ExternalValueAttribute("nodeId", m_snmpInterface.getNodeId().toString())); attributes.add(new ExternalValueAttribute("ifIndex", m_snmpInterface.getIfIndex().toString())); if (m_snmpInterface.getIfSpeed() != null) { String ifSpeedFriendly = SIUtils.getHumanReadableIfSpeed(m_snmpInterface.getIfSpeed()); attributes.add(new ExternalValueAttribute("ifSpeed", m_snmpInterface.getIfSpeed().toString())); attributes.add(new ExternalValueAttribute("ifSpeedFriendly", ifSpeedFriendly)); } } return attributes; } }
/** {@inheritDoc} */ @Override public void visitGroup(AttributeGroup group) { pushShouldPersist(group); if (shouldPersist()) { Map<String, String> dsNamesToRrdNames = new LinkedHashMap<String , String>(); for (CollectionAttribute a : group.getAttributes()) { if (a.getType().isNumeric()) { dsNamesToRrdNames.put(a.getName(), group.getName()); } } setBuilder(createBuilder(group.getResource(), group.getName(), group.getGroupType().getAttributeTypes())); ResourcePath path = ResourceTypeUtils.getResourcePathWithRepository(getRepository(), group.getResource().getPath()); m_resourceStorageDao.updateMetricToResourceMappings(path, dsNamesToRrdNames); } }
@Override protected void persistStringAttribute(ResourcePath path, String key, String value) throws PersistException { try { m_resourceStorageDao.setStringAttribute(path, key, value); } catch (Throwable t) { throw new PersistException(t); } }
/** * Gets the last filename. * * @param serviceName the service name * @param resourceDir the resource directory * @param targetPath the target path * @return the last filename * @throws Exception the exception */ public static String getLastFilename(ResourceStorageDao resourceStorageDao, String serviceName, ResourcePath path, String targetPath) throws Exception { String filename = null; try { filename = resourceStorageDao.getStringAttribute(path, getCacheId(serviceName, targetPath)); } catch (Throwable e) { LOG.info("getLastFilename: creating a new filename tracker on {}", path); } return filename; }
@Override public OnmsResource getResourceByName(String domain) { if (!m_resourceStorageDao.exists(ResourcePath.get(ResourceTypeUtils.SNMP_DIRECTORY, domain), 1)) { throw new ObjectRetrievalFailureException(OnmsResource.class, domain, "Top-level resource of type domain could not be found: " + domain, null); } return createResourceForDomain(domain); }
protected Set<String> getQueryableInterfaces(OnmsResource parent) { if (!NodeResourceType.isNode(parent) && !DomainResourceType.isDomain(parent)) { return Collections.emptySet(); } return m_resourceStorageDao.children(parent.getPath(), 1).stream() .map(ResourcePath::getName) .collect(Collectors.toSet()); }
/** * Sets the last filename. * * @param serviceName the service name * @param resourceDir the resource directory * @param targetPath the target path * @param filename the filename * @throws Exception the exception */ public static void setLastFilename(ResourceStorageDao resourceStorageDao, String serviceName, ResourcePath path, String targetPath, String filename) throws Exception { resourceStorageDao.setStringAttribute(path, getCacheId(serviceName, targetPath), filename); }
/** * Gets the last timestamp. * * @param resource the TCA resource * @return the last timestamp */ private long getLastTimestamp(CollectionResource resource) { long timestamp = 0; ResourcePath path = ResourceTypeUtils.getResourcePathWithRepository(m_repository, resource.getPath()); try { LOG.debug("Retrieving timestamp from path {}", path); String ts = m_resourceStorageDao.getStringAttribute(path, LAST_TIMESTAMP); if (ts != null) { timestamp = Long.parseLong(ts); } } catch (Exception e) { LOG.error("Failed to retrieve timestamp from path {}", path, e); } return timestamp; }
/** {@inheritDoc} */ @Override public OnmsResource getChildByName(OnmsResource parent, String index) { if (parent == null) { return null; } final ResourcePath path = ResourcePath.get(parent.getPath(), getName(), index); if (!m_resourceStorageDao.exists(path, 0)) { throw new ObjectRetrievalFailureException(OnmsResource.class, path, "Generic resource with label " + m_label + " could not find resource at path: " + path, null); } return getResourceByPath(path, parent); }
private Set<String> findDomainNames() { Set<String> domainNames = Sets.newTreeSet(); // Get all of the non-numeric directory names in the RRD directory; these // are the names of the domains that have performance data for (ResourcePath child : m_resourceStorageDao.children(ResourcePath.get(ResourceTypeUtils.SNMP_DIRECTORY), 2)) { try { // if the directory name is an integer Integer.parseInt(child.getName()); continue; } catch (NumberFormatException e) { domainNames.add(child.getName()); } } return domainNames; }
@Override protected void persistStringAttribute(ResourcePath path, String key, String value) throws PersistException { try { m_resourceStorageDao.setStringAttribute(path, key, value); } catch (Throwable t) { throw new PersistException(t); } }