use of org.opennms.netmgt.model.ResourcePath in project opennms by OpenNMS.
the class InterfaceSnmpResourceType method getChildByName.
/** {@inheritDoc} */
@Override
public OnmsResource getChildByName(final OnmsResource parent, final String name) {
if (DomainResourceType.isDomain(parent)) {
// 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;
}
use of org.opennms.netmgt.model.ResourcePath in project opennms by OpenNMS.
the class ResponseTimeResourceType method getChildByName.
@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;
}
use of org.opennms.netmgt.model.ResourcePath in project opennms by OpenNMS.
the class ResponseTimeResourceType method getResourcesForParent.
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<OnmsResource>();
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;
}
use of org.opennms.netmgt.model.ResourcePath in project opennms by OpenNMS.
the class DistributedStatusResourceType method createResource.
private OnmsResource createResource(String definitionName, String locationMonitorId, String ipAddress) {
String monitor = definitionName + "-" + locationMonitorId;
String label = ipAddress + " from " + monitor;
final ResourcePath path = getRelativeInterfacePath(locationMonitorId, ipAddress);
final LazyResourceAttributeLoader loader = new LazyResourceAttributeLoader(m_resourceStorageDao, path);
final Set<OnmsAttribute> set = new LazySet<OnmsAttribute>(loader);
return new OnmsResource(getResourceName(locationMonitorId, ipAddress), label, this, set, path);
}
use of org.opennms.netmgt.model.ResourcePath in project opennms by OpenNMS.
the class DomainResourceType method createResourceForDomain.
private OnmsResource createResourceForDomain(String domain) {
final ResourcePath path = new ResourcePath(ResourceTypeUtils.SNMP_DIRECTORY, domain);
final LazyChildResourceLoader loader = new LazyChildResourceLoader(m_resourceDao);
final OnmsResource resource = new OnmsResource(domain, domain, this, s_emptyAttributeSet, new LazyList<OnmsResource>(loader), path);
loader.setParent(resource);
return resource;
}
Aggregations