@Override public boolean isResourceTypeOnParent(OnmsResource parent) { return m_resourceStorageDao.exists(parent.getPath(), 1); }
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()); }
private void checkForNodeSnmpResources(OnmsResource parent) { // Make sure we have a node if (!NodeResourceType.isNode(parent)) { throw new ObjectRetrievalFailureException(OnmsResource.class, "Invalid parent type '" + parent +"' for node SNMP resource type."); } // Make sure we have one or more metrics in the parent path if (!m_resourceStorageDao.exists(parent.getPath(), 0)) { throw new ObjectRetrievalFailureException(OnmsResource.class, "No metrics found in parent path '" + parent.getPath() + "'"); } } }
/** {@inheritDoc} */ @Override public List<OnmsResource> getResourcesForParent(OnmsResource parent) { if (parent == null) { return Collections.emptyList(); } List<OnmsResource> resources = Lists.newArrayList(); List<String> indexes = getQueryableIndexes(new ResourcePath(parent.getPath(), m_name)); for (String index : indexes) { resources.add(getResourceByPath(new ResourcePath(parent.getPath(), m_name, index), parent)); } return OnmsResource.sortIntoResourceList(resources); }
/** {@inheritDoc} */ @Override public boolean isResourceTypeOnParent(OnmsResource parent) { if (parent == null) { return false; } return m_resourceStorageDao.exists(new ResourcePath(parent.getPath(), m_name), 1); }
private OnmsResource getResourceForNode(OnmsResource node) { final LazyResourceAttributeLoader loader = new LazyResourceAttributeLoader(m_resourceStorageDao, node.getPath()); final Set<OnmsAttribute> attributes = new LazySet<OnmsAttribute>(loader); final OnmsResource resource = new OnmsResource("", "Node-level Performance Data", this, attributes, node.getPath()); resource.setParent(node); return resource; }
@Override public List<OnmsResource> getResourcesForParent(OnmsResource parent) { final Set<String> ifaces = getQueryableInterfaces(parent); if (NodeResourceType.isNode(parent)) { OnmsNode node = ResourceTypeUtils.getNodeFromResource(parent); return getNodeResources(parent.getPath(), ifaces, node); } else if (DomainResourceType.isDomain(parent)) { return getDomainResources(parent.getPath(), ifaces); } else { return Collections.emptyList(); } }
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; }
pathToMetaFile = ResourcePath.get(attr.getResource().getPath(), metaFileNameWithoutExtension);
/** {@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); }
/** * <p>Constructor for PrettyOnmsResource.</p> * * @param rs a {@link org.opennms.netmgt.model.OnmsResource} object. */ public PrettyOnmsResource(OnmsResource rs) { super(rs.getName(), rs.getLabel(), rs.getResourceType(), rs.getAttributes(), rs.getChildResources(), rs.getPath()); }
/** * <p>Constructor for PrettyOnmsResource.</p> * * @param rs a {@link org.opennms.netmgt.model.OnmsResource} object. */ public PrettyOnmsResource(OnmsResource rs) { super(rs.getName(), rs.getLabel(), rs.getResourceType(), rs.getAttributes(), rs.getChildResources(), rs.getPath()); }
/** {@inheritDoc} */ @Override public OnmsResource getChildByName(final OnmsResource parent, final String name) { if (DomainResourceType.isDomain(parent)) { // Load all of the resources and search when dealing with domains. // This is not efficient, but resources of this type should be sparse. for (final OnmsResource resource : getResourcesForParent(parent)) { if (resource.getName().equals(name)) { return resource; } } throw new ObjectRetrievalFailureException(OnmsResource.class, "No child with name '" + name + "' found on '" + parent + "'"); } // Grab the node entity final OnmsNode node = ResourceTypeUtils.getNodeFromResource(parent); // Verify that the requested resource exists final ResourcePath resourcePath = new ResourcePath(parent.getPath(), name); if (!m_resourceStorageDao.exists(resourcePath, 0)) { throw new ObjectRetrievalFailureException(OnmsResource.class, "No resource with name '" + name + "' found."); } // Leverage the existing function for retrieving the resource list final List<OnmsResource> resources = getNodeResources(parent.getPath(), Sets.newHashSet(name), node); if (resources.size() != 1) { throw new ObjectRetrievalFailureException(OnmsResource.class, "No resource with name '" + name + "' found."); } final OnmsResource resource = resources.get(0); resource.setParent(parent); return resource; }
private static OnmsResource checkLabelForQuotes(OnmsResource childResource) { String lbl = Util.convertToJsSafeString(childResource.getLabel()); OnmsResource resource = new OnmsResource(childResource.getName(), lbl, childResource.getResourceType(), childResource.getAttributes(), childResource.getPath()); resource.setParent(childResource.getParent()); resource.setEntity(childResource.getEntity()); resource.setLink(childResource.getLink()); return resource; }
private static OnmsResource checkLabelForQuotes(OnmsResource childResource) { String lbl = Util.convertToJsSafeString(childResource.getLabel()); OnmsResource resource = new OnmsResource(childResource.getName(), lbl, childResource.getResourceType(), childResource.getAttributes(), childResource.getPath()); resource.setParent(childResource.getParent()); resource.setEntity(childResource.getEntity()); resource.setLink(childResource.getLink()); return resource; }
/** * Checks a resource label for quotes. * * @param childResource the child resource to check * @return the resource */ private OnmsResource checkLabelForQuotes(OnmsResource childResource) { String lbl = Util.convertToJsSafeString(childResource.getLabel()); OnmsResource resource = new OnmsResource(childResource.getName(), lbl, childResource.getResourceType(), childResource.getAttributes(), childResource.getPath()); resource.setParent(childResource.getParent()); resource.setEntity(childResource.getEntity()); resource.setLink(childResource.getLink()); return resource; }
@Override public OnmsResource getChildByName(OnmsResource parent, String ipAddress) { // Grab the node entity final OnmsNode node = ResourceTypeUtils.getNodeFromResource(parent); // Determine the location name final String locationName = MonitoringLocationUtils.getLocationNameOrNullIfDefault(node); // Grab the interface final OnmsIpInterface matchingIf = m_ipInterfaceDao.get(node, ipAddress); if (matchingIf == null) { throw new ObjectRetrievalFailureException(OnmsIpInterface.class, "No interface with ipAddr " + ipAddress + " could be found on node with id " + node.getId()); } // Verify the path final ResourcePath path = getInterfacePath(locationName, ipAddress); if (!m_resourceStorageDao.exists(path, 0)) { throw new ObjectRetrievalFailureException(OnmsResource.class, "No metrics found in parent path '" + parent.getPath() + "'"); } // Create the resource final OnmsResource resource = createResource(locationName, matchingIf, ipAddress, path); resource.setParent(parent); return resource; }
/** * Checks a label for quotes and returns a safe resource instance. * * @param childResource the resource to check * @return a new constructed resource instance */ private static OnmsResource checkLabelForQuotes(OnmsResource childResource) { String lbl = Util.convertToJsSafeString(childResource.getLabel()); OnmsResource resource = new OnmsResource(childResource.getName(), lbl, childResource.getResourceType(), childResource.getAttributes(), childResource.getPath()); resource.setParent(childResource.getParent()); resource.setEntity(childResource.getEntity()); resource.setLink(childResource.getLink()); return resource; } }
/** * Checks a resource label for quotes. * * @param childResource the child resource to check * @return the resource */ private OnmsResource checkLabelForQuotes(OnmsResource childResource) { String lbl = Util.convertToJsSafeString(childResource.getLabel()); OnmsResource resource = new OnmsResource(childResource.getName(), lbl, childResource.getResourceType(), childResource.getAttributes(), childResource.getPath()); resource.setParent(childResource.getParent()); resource.setEntity(childResource.getEntity()); resource.setLink(childResource.getLink()); return resource; }
/** * Checks a label for quotes and returns a safe resource instance. * * @param childResource the resource to check * @return a new constructed resource instance */ private static OnmsResource checkLabelForQuotes(OnmsResource childResource) { String lbl = Util.convertToJsSafeString(childResource.getLabel()); OnmsResource resource = new OnmsResource(childResource.getName(), lbl, childResource.getResourceType(), childResource.getAttributes(), childResource.getPath()); resource.setParent(childResource.getParent()); resource.setEntity(childResource.getEntity()); resource.setLink(childResource.getLink()); return resource; } }