@Override public boolean isResourceTypeOnParent(OnmsResource parent) { return m_resourceStorageDao.exists(parent.getPath(), 1); }
/** {@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 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); }
/** {@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 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() + "'"); } } }
private List<OnmsResource> getResourcesForParent(OnmsResource parent, boolean stopAfterFirst) { if (!NodeResourceType.isNode(parent)) { return Collections.emptyList(); } // Grab the node entity final OnmsNode node = ResourceTypeUtils.getNodeFromResource(parent); // Determine the location name final String locationName = MonitoringLocationUtils.getLocationNameOrNullIfDefault(node); // Verify the existence of the individual interfaces final LinkedList<OnmsResource> resources = new LinkedList<>(); for (final OnmsIpInterface i : node.getIpInterfaces()) { String ipAddr = InetAddressUtils.str(i.getIpAddress()); final ResourcePath path = getInterfacePath(locationName, ipAddr); if (m_resourceStorageDao.exists(path, 0)) { resources.add(createResource(locationName, i, ipAddr, path)); if (stopAfterFirst) { break; } } } return resources; }
/** {@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; }
/** {@inheritDoc} */ @Override public List<OnmsResource> getResourcesForParent(OnmsResource parent) { if (!NodeResourceType.isNode(parent)) { return Collections.emptyList(); } final OnmsNode node = ResourceTypeUtils.getNodeFromResource(parent); final List<OnmsResource> resources = Lists.newLinkedList(); final Collection<LocationMonitorIpInterface> statuses = m_locationMonitorDao.findStatusChangesForNodeForUniqueMonitorAndInterface(node.getId()); for (LocationMonitorIpInterface status : statuses) { String definitionName = status.getLocationMonitor().getLocation(); String id = status.getLocationMonitor().getId(); final OnmsIpInterface ipInterface = status.getIpInterface(); String ipAddr = InetAddressUtils.str(ipInterface.getIpAddress()); if (m_resourceStorageDao.exists(getRelativeInterfacePath(id, ipAddr), 0)) { resources.add(createResource(definitionName, id, ipAddr)); } } return OnmsResource.sortIntoResourceList(resources); }
@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; }