/**
   * returns a rrd series data, an array of [[timestamp,data1,data2,...]]
   *
   * @param persistenceService
   * @param item
   * @param consilidationFunction
   * @param timeBegin
   * @param timeEnd
   * @param resolution
   * @return
   */
  public Object getRrdSeries(
      QueryablePersistenceService persistenceService,
      Item item,
      ConsolFun consilidationFunction,
      Date timeBegin,
      Date timeEnd,
      long resolution) {
    Map<Long, ArrayList<String>> data = new TreeMap<Long, ArrayList<String>>();
    try {
      List<String> itemNames = new ArrayList<String>();

      if (item instanceof GroupItem) {
        GroupItem groupItem = (GroupItem) item;
        for (Item member : groupItem.getMembers()) {
          itemNames.add(member.getName());
        }
      } else {
        itemNames.add(item.getName());
      }
      for (String itemName : itemNames) {
        addRrdData(data, itemName, consilidationFunction, timeBegin, timeEnd, resolution);
      }

    } catch (FileNotFoundException e) {
      // rrd file does not exist, fallback to generic persistance service
      logger.debug(
          "no rrd file found '{}'", (RRD_FOLDER + File.separator + item.getName() + ".rrd"));
      return getPersistenceSeries(persistenceService, item, timeBegin, timeEnd, resolution);
    } catch (Exception e) {
      logger.error(e.getLocalizedMessage() + ": fallback to generic persistance service");
      return getPersistenceSeries(persistenceService, item, timeBegin, timeEnd, resolution);
    }
    return convertToRrd(data);
  }
 /**
  * Checks if a given persistence configuration entry is relevant for an item
  *
  * @param config the persistence configuration entry
  * @param item to check if the configuration applies to
  * @return true, if the configuration applies to the item
  */
 protected boolean appliesToItem(PersistenceConfiguration config, Item item) {
   for (EObject itemCfg : config.getItems()) {
     if (itemCfg instanceof AllConfig) {
       return true;
     }
     if (itemCfg instanceof ItemConfig) {
       ItemConfig singleItemConfig = (ItemConfig) itemCfg;
       if (item.getName().equals(singleItemConfig.getItem())) {
         return true;
       }
     }
     if (itemCfg instanceof GroupConfig) {
       GroupConfig groupItemCfg = (GroupConfig) itemCfg;
       String groupName = groupItemCfg.getGroup();
       try {
         Item gItem = itemRegistry.getItem(groupName);
         if (gItem instanceof GroupItem) {
           GroupItem groupItem = (GroupItem) gItem;
           if (groupItem.getAllMembers().contains(item)) {
             return true;
           }
         }
       } catch (Exception e) {
       }
     }
   }
   return false;
 }
Example #3
0
 /** {@inheritDoc} */
 @Override
 public void receiveCommand(String itemName, Command command) {
   // if the item is a group, we have to pass the command to it as it needs to pass the command to
   // its members
   if (itemRegistry != null) {
     try {
       Item item = itemRegistry.getItem(itemName);
       if (item instanceof GroupItem) {
         GroupItem groupItem = (GroupItem) item;
         groupItem.send(command);
       }
     } catch (ItemNotFoundException e) {
       logger.debug("Received command for non-existing item: {}", e.getMessage());
     }
   }
 }
  /**
   * Retrieves all items for which the persistence configuration applies to.
   *
   * @param config the persistence configuration entry
   * @return all items that this configuration applies to
   */
  protected Iterable<Item> getAllItems(PersistenceConfiguration config) {
    // first check, if we should return them all
    for (EObject itemCfg : config.getItems()) {
      if (itemCfg instanceof AllConfig) {
        return itemRegistry.getItems();
      }
    }

    // otherwise, go through the detailed definitions
    Set<Item> items = new HashSet<Item>();
    for (EObject itemCfg : config.getItems()) {
      if (itemCfg instanceof ItemConfig) {
        ItemConfig singleItemConfig = (ItemConfig) itemCfg;
        try {
          Item item = itemRegistry.getItem(singleItemConfig.getItem());
          items.add(item);
        } catch (ItemNotFoundException e) {
          logger.debug("Item '{}' does not exist.", singleItemConfig.getItem());
        }
      }
      if (itemCfg instanceof GroupConfig) {
        GroupConfig groupItemCfg = (GroupConfig) itemCfg;
        String groupName = groupItemCfg.getGroup();
        try {
          Item gItem = itemRegistry.getItem(groupName);
          if (gItem instanceof GroupItem) {
            GroupItem groupItem = (GroupItem) gItem;
            items.addAll(groupItem.getAllMembers());
          }
        } catch (ItemNotFoundException e) {
          logger.debug("Item group '{}' does not exist.", groupName);
        }
      }
    }
    return items;
  }