@Override public List<OnmsResource> load() { Preconditions.checkNotNull(m_parent, "parent attribute"); // Gather the lists of children from all the available resource types and merge them // into a single list List<OnmsResource> children = getAvailableResourceTypes().stream() .map(t -> t.getResourcesForParent(m_parent)) .flatMap(List::stream) .collect(Collectors.toList()); // Set the parent field on all of the resources children.stream().forEach(c -> c.setParent(m_parent)); return children; }
/** {@inheritDoc} */ @Override public OnmsResource getChildByName(OnmsResource parent, String name) { // Load all of the resources and search. This is not the most efficient approach, // but resources of this type should be sparse. for (OnmsResource resource : getResourcesForParent(parent)) { if (resource.getName().equals(name)) { resource.setParent(parent); return resource; } } throw new ObjectRetrievalFailureException(OnmsResource.class, "No child with name '" + name + "' found on '" + parent + "'"); }
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; }
/** {@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; }
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; } }