Search in sources :

Example 1 with ResourceDTO

use of org.opennms.netmgt.model.resource.ResourceDTO in project opennms by OpenNMS.

the class GraphRestService method getGraphResourcesForNode.

@GET
@Path("fornode/{nodeCriteria}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML })
@Transactional(readOnly = true)
public GraphResourceDTO getGraphResourcesForNode(@PathParam("nodeCriteria") final String nodeCriteria, @DefaultValue("-1") @QueryParam("depth") final int depth) {
    OnmsNode node = m_nodeDao.get(nodeCriteria);
    if (node == null) {
        throw getException(Status.NOT_FOUND, "No node found with criteria '{}'.", nodeCriteria);
    }
    OnmsResource resource = m_resourceDao.getResourceForNode(node);
    if (resource == null) {
        throw getException(Status.NOT_FOUND, "No resource found for node with id {}.", "" + node.getId());
    }
    final ResourceVisitor visitor = new ResourceVisitor(this);
    final ResourceDTO resourceDTO = ResourceDTO.fromResource(resource, depth);
    visitor.visit(resourceDTO);
    return new GraphResourceDTO(resourceDTO, visitor.getGraphs());
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsResource(org.opennms.netmgt.model.OnmsResource) ResourceDTO(org.opennms.netmgt.model.resource.ResourceDTO) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with ResourceDTO

use of org.opennms.netmgt.model.resource.ResourceDTO in project opennms by OpenNMS.

the class ShowCommand method execute.

@Override
public void execute(final ResourceCli resourceCli) throws Exception {
    // Request and print the data
    final ResourceDTO resource = connect(resourceCli, this.resource).header("Accept", "application/xml").get(ResourceDTO.class);
    System.out.println("ID:         " + resource.getId());
    System.out.println("Name:       " + resource.getName());
    System.out.println("Label:      " + resource.getLabel());
    System.out.println("Type:       " + resource.getTypeLabel());
    System.out.println("Link:       " + resource.getLink());
    System.out.println("Parent ID:  " + resource.getParentId());
    System.out.println("Children:");
    if (resource.getChildren() != null) {
        for (final ResourceDTO childResource : resource.getChildren().getObjects()) {
            System.out.println("  " + childResource.getId());
        }
    }
    System.out.println("Attributes:");
    System.out.println("  External:");
    for (final Map.Entry<String, String> e : resource.getExternalValueAttributes().entrySet()) {
        System.out.println("    " + e.getKey() + " = '" + e.getValue() + "'");
    }
    System.out.println("  Metrics:");
    for (final Map.Entry<String, RrdGraphAttribute> e : resource.getRrdGraphAttributes().entrySet()) {
        System.out.println("    " + e.getKey() + " = '" + e.getValue().getRrdFile() + "'");
    }
    System.out.println("  Strings:");
    for (final Map.Entry<String, String> e : resource.getStringPropertyAttributes().entrySet()) {
        System.out.println("    " + e.getKey() + " = '" + e.getValue() + "'");
    }
}
Also used : Map(java.util.Map) RrdGraphAttribute(org.opennms.netmgt.model.RrdGraphAttribute) ResourceDTO(org.opennms.netmgt.model.resource.ResourceDTO)

Aggregations

ResourceDTO (org.opennms.netmgt.model.resource.ResourceDTO)2 Map (java.util.Map)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 OnmsNode (org.opennms.netmgt.model.OnmsNode)1 OnmsResource (org.opennms.netmgt.model.OnmsResource)1 RrdGraphAttribute (org.opennms.netmgt.model.RrdGraphAttribute)1 Transactional (org.springframework.transaction.annotation.Transactional)1