예제 #1
0
  private void validateTag(int tagCount, String[] tag) throws ValidationException {
    if (tag.length < 2)
      throw new ValidationException(
          String.format("tag[%d] must be in the format 'name=value'.", tagCount));

    Validator.validateNotNullOrEmpty(String.format("tag[%d].name", tagCount), tag[0]);
    Validator.validateCharacterSet(String.format("tag[%d].name", tagCount), tag[0]);

    Validator.validateNotNullOrEmpty(String.format("tag[%d].value", tagCount), tag[1]);
    Validator.validateCharacterSet(String.format("tag[%d].value", tagCount), tag[1]);
  }
예제 #2
0
  protected void execute(String[] command, long timestamp)
      throws ValidationException, DatastoreException {
    Validator.validateNotNullOrEmpty("metricName", command[1]);

    String metricName = command[1];

    DataPoint dp;
    try {
      if (command[3].contains("."))
        dp = m_doubleFactory.createDataPoint(timestamp, Double.parseDouble(command[3]));
      else dp = m_longFactory.createDataPoint(timestamp, Util.parseLong(command[3]));
    } catch (NumberFormatException e) {
      throw new ValidationException(e.getMessage());
    }

    ImmutableSortedMap.Builder<String, String> tags = Tags.create();

    int tagCount = 0;
    for (int i = 4; i < command.length; i++) {
      String[] tag = command[i].split("=");
      validateTag(tagCount, tag);

      tags.put(tag[0], tag[1]);
      tagCount++;
    }

    if (tagCount == 0) tags.put("add", "tag");

    m_counter.incrementAndGet();
    m_datastore.putDataPoint(metricName, tags.build(), dp);
  }