public static void validateNameFormat(String name,
      org.apache.hadoop.conf.Configuration conf) {
    if (StringUtils.isEmpty(name)) {
      throw new IllegalArgumentException("Name can not be empty!");
    }
    // validate component name
    if (name.contains("_")) {
      throw new IllegalArgumentException(
          "Invalid format: " + name
              + ", can not use '_', as DNS hostname does not allow '_'. Use '-' Instead. ");
    }
    boolean dnsEnabled = conf.getBoolean(RegistryConstants.KEY_DNS_ENABLED,
        RegistryConstants.DEFAULT_DNS_ENABLED);
    if (dnsEnabled && name.length() > RegistryConstants.MAX_FQDN_LABEL_LENGTH) {
      throw new IllegalArgumentException(String
          .format("Invalid format %s, must be no more than 63 characters ",
              name));
    }
    namePattern.validate(name);
  }
@Test
  public void testValidateCompName() {
    String[] invalidNames = {
        "EXAMPLE", // UPPER case not allowed
        "example_app" // underscore not allowed.
    };
    for (String name : invalidNames) {
      try {
        ServiceApiUtil.validateNameFormat(name, new Configuration());
        Assert.fail();
      } catch (IllegalArgumentException ex) {
        ex.printStackTrace();
      }
    }
  }