ServiceApiUtil { public static void validateKerberosPrincipal( KerberosPrincipal kerberosPrincipal) throws IOException { if (!StringUtils.isEmpty(kerberosPrincipal.getPrincipalName())) { if (!kerberosPrincipal.getPrincipalName().contains("/")) { throw new IllegalArgumentException(String.format( RestApiErrorMessages.ERROR_KERBEROS_PRINCIPAL_NAME_FORMAT, kerberosPrincipal.getPrincipalName())); } } } 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 testKerberosPrincipal() throws IOException { SliderFileSystem sfs = ServiceTestUtils.initMockFs(); Service app = createValidApplication("comp-a"); KerberosPrincipal kp = new KerberosPrincipal(); kp.setKeytab("file: kp.setPrincipalName("user/_HOST@domain.com"); app.setKerberosPrincipal(kp); try { ServiceApiUtil.validateKerberosPrincipal(app.getKerberosPrincipal()); } catch (IllegalArgumentException e) { Assert.fail(NO_EXCEPTION_PREFIX + e.getMessage()); } kp.setKeytab("/some/path"); try { ServiceApiUtil.validateKerberosPrincipal(app.getKerberosPrincipal()); } catch (IllegalArgumentException e) { Assert.fail(NO_EXCEPTION_PREFIX + e.getMessage()); } }
@Test public void testKerberosPrincipalNameFormat() throws IOException { Service app = createValidApplication("comp-a"); KerberosPrincipal kp = new KerberosPrincipal(); kp.setPrincipalName("user@domain.com"); app.setKerberosPrincipal(kp); try { ServiceApiUtil.validateKerberosPrincipal(app.getKerberosPrincipal()); Assert.fail(EXCEPTION_PREFIX + "service with invalid principal name " + "format."); } catch (IllegalArgumentException e) { assertEquals( String.format( RestApiErrorMessages.ERROR_KERBEROS_PRINCIPAL_NAME_FORMAT, kp.getPrincipalName()), e.getMessage()); } kp.setPrincipalName("user/_HOST@domain.com"); try { ServiceApiUtil.validateKerberosPrincipal(app.getKerberosPrincipal()); } catch (IllegalArgumentException e) { Assert.fail(NO_EXCEPTION_PREFIX + e.getMessage()); } kp.setPrincipalName(null); kp.setKeytab(null); try { ServiceApiUtil.validateKerberosPrincipal(app.getKerberosPrincipal()); } catch (NullPointerException e) { Assert.fail(NO_EXCEPTION_PREFIX + e.getMessage()); } }