use of org.opennms.netmgt.model.OnmsResourceType in project opennms by OpenNMS.
the class ResourceDaoIntegrityIT method walkResourceTree.
@Test
@Transactional
public void walkResourceTree() throws IOException {
// Setup the file tree and the necessary objects in the DAOs
createResourceTree();
createNodes();
Map<String, ResourceType> types = createResourceTypes();
expect(m_resourceTypesDao.getLastUpdate()).andReturn(new Date(System.currentTimeMillis())).anyTimes();
expect(m_resourceTypesDao.getResourceTypes()).andReturn(types).anyTimes();
m_easyMockUtils.replayAll();
m_resourceDao.afterPropertiesSet();
// Walk the tree and collect the results
ResourceCollector visitor = new ResourceCollector();
ResourceTreeWalker walker = new ResourceTreeWalker();
walker.setResourceDao(m_resourceDao);
walker.setVisitor(visitor);
walker.walk();
// We must have at least one resource for every known type
for (OnmsResourceType type : m_resourceDao.getResourceTypes()) {
// Ignore this type for now #needstoomanydbojects
if (type.getName() == DistributedStatusResourceType.TYPE_NAME) {
continue;
}
assertTrue("No resources of type: " + type.getLabel(), visitor.resourceTypes.contains(type));
}
// We must be able to retrieve the same resource by id
for (Entry<ResourceId, OnmsResource> entry : visitor.resourcesById.entrySet()) {
OnmsResource resourceRetrievedById = m_resourceDao.getResourceById(entry.getKey());
assertNotNull(String.format("Failed to retrieve resource with id '%s'.", entry.getKey()), resourceRetrievedById);
assertEquals(String.format("Result mismatch for resource with id '%s'. Retrieved id is '%s'.", entry.getKey(), resourceRetrievedById.getId()), entry.getValue().getName(), resourceRetrievedById.getName());
}
// Build a line that represent the resource for every unique id
// and compare it to the known results
int k = 0;
String[] expectedResults = loadExpectedResults();
for (Entry<ResourceId, OnmsResource> entry : visitor.resourcesById.entrySet()) {
// Convert the attributes to strings and order them lexicographically
Set<String> attributeNames = new TreeSet<String>();
for (OnmsAttribute attribute : entry.getValue().getAttributes()) {
attributeNames.add(attribute.toString());
}
// Compare
String actualResult = entry.getKey() + ": " + attributeNames;
assertEquals(String.format("Result mismatch at line %d.", k + 1), expectedResults[k], actualResult);
k++;
}
// We should have as many unique resource ids as we have results
assertEquals(expectedResults.length, visitor.resourcesById.size());
m_easyMockUtils.verifyAll();
}
use of org.opennms.netmgt.model.OnmsResourceType in project opennms by OpenNMS.
the class RrdDashletConfigurationWindow method setRrdGraphEntryFromKscReportGraph.
private void setRrdGraphEntryFromKscReportGraph(RrdGraphEntry rrdGraphEntry, Graph graph) {
String graphLabel, graphId, graphUrl, nodeId, nodeLabel, resourceLabel, resourceTypeId, resourceTypeLabel;
String[] graphTypeArr = graph.getGraphtype().split("\\.");
String[] resourceIdArr = graph.getResourceId().orElse("").split("\\.");
nodeId = resourceIdArr[0].split("[\\[\\]]")[1];
String resourceTypeName = resourceIdArr[1].split("[\\[\\]]")[0];
OnmsNode onmsNode = m_nodeDao.get(nodeId);
nodeLabel = onmsNode.getLabel();
Map<OnmsResourceType, List<OnmsResource>> resourceTypeListMap = m_rrdGraphHelper.getResourceTypeMapForNodeId(nodeId);
for (Map.Entry<OnmsResourceType, List<OnmsResource>> entry : resourceTypeListMap.entrySet()) {
OnmsResourceType onmsResourceType = entry.getKey();
if (resourceTypeName.equals(onmsResourceType.getName())) {
resourceTypeId = "node[" + nodeId + "]." + resourceTypeName;
resourceTypeLabel = onmsResourceType.getLabel();
List<OnmsResource> onmsResourceList = entry.getValue();
for (OnmsResource onmsResource : onmsResourceList) {
String onmsResourceId = onmsResource.getId().toString();
if (onmsResourceId.equals(graph.getResourceId())) {
resourceLabel = onmsResource.getLabel();
Map<String, String> resultsMap = m_rrdGraphHelper.getGraphResultsForResourceId(onmsResource.getId());
Map<String, String> nameTitleMapping = m_rrdGraphHelper.getGraphNameTitleMappingForResourceId(onmsResource.getId());
graphId = onmsResourceId + "." + nameTitleMapping.get(graph.getGraphtype());
graphLabel = nameTitleMapping.get(graph.getGraphtype());
graphUrl = resultsMap.get(graph.getGraphtype());
rrdGraphEntry.setNodeId(nodeId);
rrdGraphEntry.setNodeLabel(nodeLabel);
rrdGraphEntry.setResourceTypeId(resourceTypeId);
rrdGraphEntry.setResourceTypeLabel(resourceTypeLabel);
rrdGraphEntry.setResourceId(onmsResourceId);
rrdGraphEntry.setResourceLabel(resourceLabel);
rrdGraphEntry.setGraphId(graphId);
rrdGraphEntry.setGraphLabel(graphLabel);
rrdGraphEntry.setGraphUrl(graphUrl);
break;
}
}
break;
}
}
}
use of org.opennms.netmgt.model.OnmsResourceType in project opennms by OpenNMS.
the class DefaultResourceDao method initResourceTypes.
private void initResourceTypes() {
final Map<String, OnmsResourceType> resourceTypes = Maps.newLinkedHashMap();
OnmsResourceType resourceType;
resourceType = new NodeSnmpResourceType(m_resourceStorageDao);
resourceTypes.put(resourceType.getName(), resourceType);
resourceType = new InterfaceSnmpResourceType(m_resourceStorageDao);
resourceTypes.put(resourceType.getName(), resourceType);
resourceType = new ResponseTimeResourceType(m_resourceStorageDao, m_ipInterfaceDao);
resourceTypes.put(resourceType.getName(), resourceType);
resourceType = new DistributedStatusResourceType(m_resourceStorageDao, m_locationMonitorDao);
resourceTypes.put(resourceType.getName(), resourceType);
resourceTypes.putAll(GenericIndexResourceType.createTypes(m_resourceTypesDao.getResourceTypes(), m_resourceStorageDao));
m_nodeResourceType = new NodeResourceType(this, m_nodeDao);
resourceTypes.put(m_nodeResourceType.getName(), m_nodeResourceType);
// Add 'nodeSource' as an alias to for the 'node' resource type to preserve backwards compatibility
// See NMS-8404 for details
resourceTypes.put("nodeSource", m_nodeResourceType);
if (isDomainResourceTypeUsed()) {
LOG.debug("One or more packages are configured with storeByIfAlias=true. Enabling the domain resource type.");
resourceType = new DomainResourceType(this, m_resourceStorageDao);
resourceTypes.put(resourceType.getName(), resourceType);
} else {
LOG.debug("No packages are configured with storeByIfAlias=true. Excluding the domain resource type.");
}
m_resourceTypes = resourceTypes;
m_lastUpdatedResourceTypesConfig = m_resourceTypesDao.getLastUpdate();
}
use of org.opennms.netmgt.model.OnmsResourceType in project opennms by OpenNMS.
the class DefaultResourceDao method getChildResource.
/**
* <p>getChildResource</p>
*
* @param parentResource a {@link org.opennms.netmgt.model.OnmsResource} object.
* @param resourceType a {@link java.lang.String} object.
* @param resource a {@link java.lang.String} object.
* @return a {@link org.opennms.netmgt.model.OnmsResource} object.
*/
protected OnmsResource getChildResource(OnmsResource parentResource, String resourceType, String resource) {
final OnmsResourceType targetType = m_resourceTypes.get(resourceType);
if (targetType == null) {
throw new ObjectRetrievalFailureException(OnmsResource.class, resourceType + "/" + resource, "Unsupported resource type: " + resourceType, null);
}
final OnmsResource childResource = targetType.getChildByName(parentResource, resource);
if (childResource != null) {
LOG.debug("getChildResource: returning resource {}", childResource);
return childResource;
}
throw new ObjectRetrievalFailureException(OnmsResource.class, resourceType + "/" + resource, "Could not find child resource '" + resource + "' with resource type '" + resourceType + "' on resource '" + resource + "'", null);
}
use of org.opennms.netmgt.model.OnmsResourceType in project opennms by OpenNMS.
the class ThresholdController method addStandardEditingBits.
private void addStandardEditingBits(ModelAndView modelAndView) {
Map<String, String> dsTypes = new LinkedHashMap<String, String>();
dsTypes.put("node", "Node");
// "interface" is a wrong word
dsTypes.put("if", "Interface");
Collection<OnmsResourceType> resourceTypes = m_resourceDao.getResourceTypes();
Multimap<String, String> genericDsTypes = TreeMultimap.create();
for (OnmsResourceType resourceType : resourceTypes) {
if (resourceType instanceof GenericIndexResourceType) // Put these in by label to sort them, we'll get them out in a moment
{
genericDsTypes.put(resourceType.getLabel(), resourceType.getName());
}
}
// Now get the resource types out of the TreeMultimap
for (String rtLabel : genericDsTypes.keys()) {
Collection<String> rtNames = genericDsTypes.get(rtLabel);
for (String rtName : rtNames) {
if (rtNames.size() > 1) {
dsTypes.put(rtName, rtLabel + " [" + rtName + "]");
} else {
dsTypes.put(rtName, rtLabel);
}
}
}
// Finally, set the sorted resource types into the model
modelAndView.addObject("dsTypes", dsTypes);
Collection<String> thresholdTypes = new ArrayList<String>();
for (final ThresholdType tt : ThresholdType.values()) {
thresholdTypes.add(tt.getEnumName());
}
modelAndView.addObject("thresholdTypes", thresholdTypes);
Collection<String> filterOperators = new ArrayList<String>();
for (final FilterOperator fo : FilterOperator.values()) {
filterOperators.add(fo.getEnumName());
}
modelAndView.addObject("filterOperators", filterOperators);
modelAndView.addObject("saveButtonTitle", SAVE_BUTTON_TITLE);
modelAndView.addObject("cancelButtonTitle", CANCEL_BUTTON_TITLE);
modelAndView.addObject("addFilterButtonTitle", ADDFILTER_BUTTON_TITLE);
modelAndView.addObject("editButtonTitle", EDIT_BUTTON_TITLE);
modelAndView.addObject("deleteButtonTitle", DELETE_BUTTON_TITLE);
modelAndView.addObject("updateButtonTitle", UPDATE_BUTTON_TITLE);
modelAndView.addObject("moveUpButtonTitle", MOVEUP_BUTTON_TITLE);
modelAndView.addObject("moveDownButtonTitle", MOVEDOWN_BUTTON_TITLE);
}
Aggregations