Esempio n. 1
0
  /**
   * Validates the given configuration entries. A valid configuration contains only valid properties
   * (i.e., defined or otherwise valid) that are not prefixes and whose values are formatted
   * correctly for their property types. A valid configuration also contains a value for property
   * {@link Property#INSTANCE_ZK_TIMEOUT} within a valid range.
   *
   * @param entries iterable through configuration keys and values
   * @throws SanityCheckException if a fatal configuration error is found
   */
  public static void validate(Iterable<Entry<String, String>> entries) {
    String instanceZkTimeoutValue = null;
    boolean usingVolumes = false;
    for (Entry<String, String> entry : entries) {
      String key = entry.getKey();
      String value = entry.getValue();
      Property prop = Property.getPropertyByKey(entry.getKey());
      if (prop == null && Property.isValidPropertyKey(key))
        continue; // unknown valid property (i.e. has proper prefix)
      else if (prop == null) log.warn(PREFIX + "unrecognized property key (" + key + ")");
      else if (prop.getType() == PropertyType.PREFIX)
        fatal(PREFIX + "incomplete property key (" + key + ")");
      else if (!prop.getType().isValidFormat(value))
        fatal(
            PREFIX
                + "improperly formatted value for key ("
                + key
                + ", type="
                + prop.getType()
                + ")");

      if (key.equals(Property.INSTANCE_ZK_TIMEOUT.getKey())) {
        instanceZkTimeoutValue = value;
      }

      if (key.equals(Property.INSTANCE_VOLUMES.getKey())) {
        usingVolumes = value != null && !value.isEmpty();
      }
    }

    if (instanceZkTimeoutValue != null) {
      checkTimeDuration(
          Property.INSTANCE_ZK_TIMEOUT,
          instanceZkTimeoutValue,
          new CheckTimeDurationBetween(1000, 300000));
    }

    if (!usingVolumes) {
      log.warn(
          "Use of "
              + INSTANCE_DFS_URI
              + " and "
              + INSTANCE_DFS_DIR
              + " are deprecated. Consider using "
              + Property.INSTANCE_VOLUMES
              + " instead.");
    }
  }