ServiceApiUtil { public static void validateNameFormat(String name, org.apache.hadoop.conf.Configuration conf) { if (StringUtils.isEmpty(name)) { throw new IllegalArgumentException("Name can not be empty!"); } 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); } static  String(String s); @VisibleForTesting static void setJsonSerDeser(JsonSerDeser jsd); @VisibleForTesting static void validateAndResolveService(Service service,
      SliderFileSystem fs, org.apache.hadoop.conf.Configuration conf); static void validateJvmOpts(String jvmOpts); static void validateKerberosPrincipal(
      KerberosPrincipal kerberosPrincipal); static void validateNameFormat(String name,
      org.apache.hadoop.conf.Configuration conf); @VisibleForTesting static List<Component> getComponents(SliderFileSystem
      fs, String serviceName); static Service loadService(SliderFileSystem fs, String
      serviceName); static Service loadServiceUpgrade(SliderFileSystem fs,
      String serviceName, String version); static Service loadServiceFrom(SliderFileSystem fs,
      Path appDefPath); static Path getServiceJsonPath(SliderFileSystem fs, String serviceName); static void validateCompResourceSize(
      org.apache.hadoop.yarn.api.records.Resource maxResource,
      Service service); static Collection<Component> sortByDependencies(List<Component>
      components); static void createDirAndPersistApp(SliderFileSystem fs, Path appDir,
      Service service); static Path writeAppDefinition(SliderFileSystem fs, Path appDir,
      Service service); static Path writeAppDefinition(SliderFileSystem fs, Service service); static List<Container> getLiveContainers(Service service,
      List<String> componentInstances); static void validateInstancesUpgrade(List<Container>
      liveContainers); static boolean isUpgradable(Container container); static List<Container> validateAndResolveCompsUpgrade(
      Service liveService, Collection<String> compNames); static List<Container> validateAndResolveCompsStable(
      Service liveService, Collection<String> compNames); static String getHostnameSuffix(String serviceName, org.apache
      .hadoop.conf.Configuration conf); static String parseAndValidateComponentInstanceName(String
      instanceOrHostname, String serviceName, org.apache.hadoop.conf
      .Configuration conf); static String parseComponentName(String componentInstanceName); static List<String> resolveCompsDependency(Service service); static void checkServiceDependencySatisified(Service service); static JsonSerDeser<Service> jsonSerDeser; static final JsonSerDeser<Container[]> CONTAINER_JSON_SERDE; static final JsonSerDeser<ComponentContainers[]> COMP_CONTAINERS_JSON_SERDE; static final JsonSerDeser<Component[]> COMP_JSON_SERDE; }
@Test public void testValidateCompName() { String[] invalidNames = { "EXAMPLE", "example_app" }; for (String name : invalidNames) { try { ServiceApiUtil.validateNameFormat(name, new Configuration()); Assert.fail(); } catch (IllegalArgumentException ex) { ex.printStackTrace(); } } }