ServiceApiUtil { public static void validateJvmOpts(String jvmOpts) throws IllegalArgumentException { Pattern pattern = Pattern.compile("[!~#?@*&%${}()<>\\[\\]|\",`;]"); Matcher matcher = pattern.matcher(jvmOpts); if (matcher.find()) { throw new IllegalArgumentException( RestApiErrorMessages.ERROR_JVM_OPTS); } } 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 testJvmOpts() throws Exception { String invalidJvmOpts = "`ping -c 3 example.com`"; intercept(IllegalArgumentException.class, "Invalid character in yarn.service.am.java.opts.", () -> ServiceApiUtil.validateJvmOpts(invalidJvmOpts)); String validJvmOpts = "-Dyarn.service.am.java.opts=-Xmx768m " + "-Djava.security.auth.login.config=/opt/hadoop/etc/jaas-zk.conf"; try { ServiceApiUtil.validateJvmOpts(validJvmOpts); } catch (Exception ex) { fail("Invalid character in yarn.service.am.java.opts."); } }