private OnmsNode getNode(final OnmsResource resource, final Source source) { OnmsNode node = null; try { node = ResourceTypeUtils.getNodeFromResourceRoot(resource); } catch (final ObjectRetrievalFailureException e) { } if (node == null) { final OnmsResource otherResource = m_resourceDao.getResourceById(ResourceId.fromString(source.getResourceId()).getParent()); node = ResourceTypeUtils.getNodeFromResource(otherResource); } return node; }
public OnmsResource getChildByName(final OnmsResource parent, final String name) { final OnmsNode node = ResourceTypeUtils.getNodeFromResource(parent);
@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(); } }
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; }
@Override public Map<String, String> doInTransaction(TransactionStatus transactionStatus) { Map<String, String> data = new HashMap<>(); ResourceId resourceId = ResourceId.fromString(resourceIdString); OnmsNode node; OnmsResource resource; if(nodeId == null){ resource = determineResourceByResourceId(resourceId); node = ResourceTypeUtils.getNodeFromResource(resource); } else { node = m_nodeDao.get(nodeId); resource = m_resourceDao.getResourceForNode(node); } data.put("nodeId", node.getNodeId()); data.put("nodeLabel", node.getLabel()); for (OnmsResource onmsResource : resource.getChildResources()) { if (resourceId.equals(onmsResource.getId())) { data.put("resourceLabel", onmsResource.getLabel()); data.put("resourceTypeLabel", onmsResource.getResourceType().getLabel()); break; } } return data; } });
@Override public Map<String, String> doInTransaction(TransactionStatus transactionStatus) { Map<String, String> data = new HashMap<>(); ResourceId resourceId = ResourceId.fromString(resourceIdString); OnmsNode node; OnmsResource resource; if(nodeId == null){ resource = determineResourceByResourceId(resourceId); node = ResourceTypeUtils.getNodeFromResource(resource); } else { node = m_nodeDao.get(nodeId); resource = m_resourceDao.getResourceForNode(node); } data.put("nodeId", node.getNodeId()); data.put("nodeLabel", node.getLabel()); for (OnmsResource onmsResource : resource.getChildResources()) { if (resourceId.equals(onmsResource.getId())) { data.put("resourceLabel", onmsResource.getLabel()); data.put("resourceTypeLabel", onmsResource.getResourceType().getLabel()); break; } } return data; } });
/** {@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; }