/** {@inheritDoc} */
  @Override
  public boolean isResourceTypeOnNodeSource(String nodeSource, int nodeId) {
    File forSrc = new File(m_resourceDao.getRrdDirectory(), DefaultResourceDao.SNMP_DIRECTORY);

    File node =
        new File(forSrc, ResourceTypeUtils.getRelativeNodeSourceDirectory(nodeSource).toString());
    File generic = new File(node, getName());
    return generic.isDirectory();
  }
Пример #2
0
  @DELETE
  @Path("{resourceId}")
  @Transactional(readOnly = false)
  public void deleteResourceById(@PathParam("resourceId") final String resourceId) {
    final boolean found = m_resourceDao.deleteResourceById(resourceId);

    if (!found) {
      throw getException(Status.NOT_FOUND, "No resource with id '{}' found.", resourceId);
    }
  }
  private File getParentResourceDirectory(String parentResource, boolean verify) {
    File snmp = new File(m_resourceDao.getRrdDirectory(verify), ResourceTypeUtils.SNMP_DIRECTORY);

    File parent = new File(snmp, parentResource);
    if (verify && !parent.isDirectory()) {
      throw new ObjectRetrievalFailureException(
          File.class, "No parent resource directory exists for " + parentResource + ": " + parent);
    }

    return parent;
  }
Пример #4
0
 @GET
 @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML})
 @Transactional(readOnly = true)
 public ResourceDTOCollection getResources(
     @DefaultValue("1") @QueryParam("depth") final int depth) {
   List<ResourceDTO> resources = Lists.newLinkedList();
   for (OnmsResource resource : m_resourceDao.findTopLevelResources()) {
     resources.add(ResourceDTO.fromResource(resource, depth));
   }
   return new ResourceDTOCollection(resources);
 }
Пример #5
0
  @GET
  @Path("{resourceId}")
  @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML})
  @Transactional(readOnly = true)
  public ResourceDTO getResourceById(
      @PathParam("resourceId") final String resourceId,
      @DefaultValue("-1") @QueryParam("depth") final int depth) {
    OnmsResource resource = m_resourceDao.getResourceById(resourceId);
    if (resource == null) {
      throw getException(Status.NOT_FOUND, "No resource with id '{}' found.", resourceId);
    }

    return ResourceDTO.fromResource(resource, depth);
  }
  private File getLocationMonitorDirectory(String locationMonitorId, boolean verify)
      throws ObjectRetrievalFailureException {
    File locationMonitorDirectory =
        new File(m_resourceDao.getRrdDirectory(verify), locationMonitorId);

    if (verify && !locationMonitorDirectory.isDirectory()) {
      throw new ObjectRetrievalFailureException(
          File.class,
          "No node directory exists for node "
              + locationMonitorId
              + ": "
              + locationMonitorDirectory);
    }

    return locationMonitorDirectory;
  }
  private File getResourceTypeDirectory(int nodeId, boolean verify) {
    File snmp = new File(m_resourceDao.getRrdDirectory(verify), DefaultResourceDao.SNMP_DIRECTORY);

    File node = new File(snmp, Integer.toString(nodeId));
    if (verify && !node.isDirectory()) {
      throw new ObjectRetrievalFailureException(
          File.class, "No node directory exists for node " + nodeId + ": " + node);
    }

    File generic = new File(node, getName());
    if (verify && !generic.isDirectory()) {
      throw new ObjectRetrievalFailureException(
          File.class, "No node directory exists for generic index " + getName() + ": " + generic);
    }

    return generic;
  }
  /**
   * createGraphResultSet
   *
   * @param resourceId a {@link java.lang.String} object.
   * @param resource a {@link org.opennms.netmgt.model.OnmsResource} object.
   * @param reports an array of {@link java.lang.String} objects.
   * @param graphResults a {@link org.opennms.web.svclayer.model.GraphResults} object.
   * @return a {@link org.opennms.web.svclayer.model.GraphResults.GraphResultSet} object.
   */
  private GraphResultSet createGraphResultSet(
      String resourceId, OnmsResource resource, String[] reports, GraphResults graphResults)
      throws IllegalArgumentException {
    if (resource == null) {
      resource = m_resourceDao.getResourceById(resourceId);
      if (resource == null) {
        throw new IllegalArgumentException("Could not find resource \"" + resourceId + "\"");
      }
    }
    GraphResultSet rs = graphResults.new GraphResultSet();
    rs.setResource(resource);

    if (reports.length == 1 && "all".equals(reports[0])) {
      PrefabGraph[] queries = m_graphDao.getPrefabGraphsForResource(resource);
      List<String> queryNames = new ArrayList<String>(queries.length);
      for (PrefabGraph query : queries) {
        queryNames.add(query.getName());
      }

      reports = queryNames.toArray(new String[queryNames.size()]);
    }

    List<Graph> graphs = new ArrayList<Graph>(reports.length);

    List<String> filesToPromote = new LinkedList<String>();
    for (String report : reports) {
      PrefabGraph prefabGraph = m_graphDao.getPrefabGraph(report);
      Graph graph =
          new Graph(prefabGraph, resource, graphResults.getStart(), graphResults.getEnd());
      getAttributeFiles(graph, filesToPromote);
      graphs.add(graph);
    }

    sendEvent(filesToPromote);

    /*
     * Sort the graphs by their order in the properties file. PrefabGraph
     * implements the Comparable interface.
     */
    Collections.sort(graphs);

    rs.setGraphs(graphs);

    return rs;
  }
  private File getResourceTypeDirectory(String nodeSource, boolean verify) {
    File snmp = new File(m_resourceDao.getRrdDirectory(verify), DefaultResourceDao.SNMP_DIRECTORY);

    File dir =
        new File(snmp, ResourceTypeUtils.getRelativeNodeSourceDirectory(nodeSource).toString());
    if (verify && !dir.isDirectory()) {
      throw new ObjectRetrievalFailureException(
          File.class, "No directory exists for nodeSource " + nodeSource);
    }

    File generic = new File(dir, getName());
    if (verify && !generic.isDirectory()) {
      throw new ObjectRetrievalFailureException(
          File.class, "No node directory exists for generic index " + getName() + ": " + generic);
    }

    return generic;
  }
Пример #10
0
  @GET
  @Path("fornode/{nodeCriteria}")
  @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML})
  @Transactional(readOnly = true)
  public ResourceDTO getResourceForNode(
      @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());
    }

    return ResourceDTO.fromResource(resource, depth);
  }
  private List<String> getQueryableInterfacesForDomain(String domain) {
    if (domain == null) {
      throw new IllegalArgumentException("Cannot take null parameters.");
    }

    ArrayList<String> intfs = new ArrayList<String>();
    File snmp = new File(m_resourceDao.getRrdDirectory(), ResourceTypeUtils.SNMP_DIRECTORY);
    File domainDir = new File(snmp, domain);

    if (!domainDir.exists() || !domainDir.isDirectory()) {
      throw new IllegalArgumentException("No such directory: " + domainDir);
    }

    File[] intfDirs = domainDir.listFiles(RrdFileConstants.DOMAIN_INTERFACE_DIRECTORY_FILTER);

    if (intfDirs != null && intfDirs.length > 0) {
      intfs.ensureCapacity(intfDirs.length);
      for (int i = 0; i < intfDirs.length; i++) {
        intfs.add(intfDirs[i].getName());
      }
    }

    return intfs;
  }
  @Override
  public GraphResults findResults(
      String[] resourceIds, String[] reports, long start, long end, String relativeTime) {
    if (resourceIds == null) {
      throw new IllegalArgumentException("resourceIds argument cannot be null");
    }
    if (reports == null) {
      throw new IllegalArgumentException("reports argument cannot be null");
    }
    if (end < start) {
      throw new IllegalArgumentException("end time cannot be before start time");
    }

    GraphResults graphResults = new GraphResults();
    graphResults.setStart(new Date(start));
    graphResults.setEnd(new Date(end));
    graphResults.setRelativeTime(relativeTime);
    graphResults.setRelativeTimePeriods(m_periods);
    graphResults.setReports(reports);

    HashMap<String, List<OnmsResource>> resourcesMap = new HashMap<String, List<OnmsResource>>();

    for (String resourceId : resourceIds) {
      String[] values = parseResourceId(resourceId);
      if (values == null) {
        continue;
      }
      String parent = values[0];
      String childType = values[1];
      String childName = values[2];
      LOG.debug(
          "findResults: parent, childType, childName = {}, {}, {}",
          values[0],
          values[1],
          values[2]);
      OnmsResource resource = null;
      if (!resourcesMap.containsKey(parent)) {
        List<OnmsResource> resourceList =
            m_resourceDao.getResourceById(resourceId).getChildResources();
        if (resourceList == null) {
          LOG.warn("findResults: zero child resources found for {}", parent);
        } else {
          resourcesMap.put(parent, resourceList);
          LOG.debug("findResults: add resourceList to map for {}", parent);
        }
      }
      for (OnmsResource r : resourcesMap.get(parent)) {
        if (childType.equals(r.getResourceType().getName()) && childName.equals(r.getName())) {
          resource = r;
          LOG.debug("findResults: found resource in map{}", r.toString());
          break;
        }
      }
      try {
        graphResults.addGraphResultSet(
            createGraphResultSet(resourceId, resource, reports, graphResults));
      } catch (IllegalArgumentException e) {
        LOG.warn(e.getMessage(), e);
        continue;
      }
    }

    graphResults.setGraphTopOffsetWithText(m_rrdDao.getGraphTopOffsetWithText());
    graphResults.setGraphLeftOffset(m_rrdDao.getGraphLeftOffset());
    graphResults.setGraphRightOffset(m_rrdDao.getGraphRightOffset());

    return graphResults;
  }
 @Override
 public PrefabGraph[] getAllPrefabGraphs(String resourceId) {
   OnmsResource resource = m_resourceDao.getResourceById(resourceId);
   return m_graphDao.getPrefabGraphsForResource(resource);
 }
 /**
  * getInterfaceDirectory
  *
  * @param id a int.
  * @param ipAddr a {@link java.lang.String} object.
  * @return a {@link java.io.File} object.
  */
 public File getInterfaceDirectory(int id, String ipAddr) {
   return new File(m_resourceDao.getRrdDirectory(), getRelativeInterfacePath(id, ipAddr));
 }