@Test public void fromScript() throws Exception { String scriptPath = setupScript("node=myhost,rack=myrack,custom=mycustom", mFolder.newFile()); try (Closeable c = new ConfigurationRule(ImmutableMap.of( PropertyKey.LOCALITY_ORDER, "node,rack,custom", PropertyKey.LOCALITY_SCRIPT, scriptPath), mConfiguration).toResource()) { TieredIdentity identity = TieredIdentityFactory.create(mConfiguration); TieredIdentity expected = new TieredIdentity(Arrays.asList( new LocalityTier("node", "myhost"), new LocalityTier("rack", "myrack"), new LocalityTier("custom", "mycustom"))); assertEquals(expected, identity); } }
@Nullable private static TieredIdentity fromScript(AlluxioConfiguration conf) { String scriptName = conf.get(PropertyKey.LOCALITY_SCRIPT); Path script = Paths.get(scriptName); if (!Files.exists(script)) { URL resource = TieredIdentityFactory.class.getClassLoader().getResource(scriptName); if (resource != null) { script = Paths.get(resource.getPath()); } else { return null; } } LOG.debug("Found tiered identity script at {}", script); String identityString; try { identityString = ShellUtils.execCommand(script.toString()); } catch (IOException e) { throw new RuntimeException( String.format("Failed to run script %s: %s", script, e.toString()), e); } try { return fromString(identityString, conf); } catch (IOException e) { throw new RuntimeException( String.format("Failed to parse output of running %s: %s", script, e.getMessage()), e); } }
TieredIdentityFactory { @Nullable private static TieredIdentity fromScript(AlluxioConfiguration conf) { String scriptName = conf.get(PropertyKey.LOCALITY_SCRIPT); Path script = Paths.get(scriptName); if (!Files.exists(script)) { URL resource = TieredIdentityFactory.class.getClassLoader().getResource(scriptName); if (resource != null) { script = Paths.get(resource.getPath()); } else { return null; } } LOG.debug("Found tiered identity script at {}", script); String identityString; try { identityString = ShellUtils.execCommand(script.toString()); } catch (IOException e) { throw new RuntimeException( String.format("Failed to run script %s: %s", script, e.toString()), e); } try { return fromString(identityString, conf); } catch (IOException e) { throw new RuntimeException( String.format("Failed to parse output of running %s: %s", script, e.getMessage()), e); } } }
TieredIdentityFactory { @Nullable private static TieredIdentity fromScript(AlluxioConfiguration conf) { String scriptName = conf.get(PropertyKey.LOCALITY_SCRIPT); Path script = Paths.get(scriptName); if (!Files.exists(script)) { URL resource = TieredIdentityFactory.class.getClassLoader().getResource(scriptName); if (resource != null) { script = Paths.get(resource.getPath()); } else { return null; } } LOG.debug("Found tiered identity script at {}", script); String identityString; try { identityString = ShellUtils.execCommand(script.toString()); } catch (IOException e) { throw new RuntimeException( String.format("Failed to run script %s: %s", script, e.toString()), e); } try { return fromString(identityString, conf); } catch (IOException e) { throw new RuntimeException( String.format("Failed to parse output of running %s: %s", script, e.getMessage()), e); } }  }
TieredIdentityFactory { @Nullable private static TieredIdentity fromScript(AlluxioConfiguration conf) { String scriptName = conf.get(PropertyKey.LOCALITY_SCRIPT); Path script = Paths.get(scriptName); if (!Files.exists(script)) { URL resource = TieredIdentityFactory.class.getClassLoader().getResource(scriptName); if (resource != null) { script = Paths.get(resource.getPath()); } else { return null; } } LOG.debug("Found tiered identity script at {}", script); String identityString; try { identityString = ShellUtils.execCommand(script.toString()); } catch (IOException e) { throw new RuntimeException( String.format("Failed to run script %s: %s", script, e.toString()), e); } try { return fromString(identityString, conf); } catch (IOException e) { throw new RuntimeException( String.format("Failed to parse output of running %s: %s", script, e.getMessage()), e); } }  static TieredIdentity localIdentity(AlluxioConfiguration conf); static TieredIdentity fromString(String identityString, AlluxioConfiguration conf); }
TieredIdentityFactory { @Nullable private static TieredIdentity fromScript(AlluxioConfiguration conf) { String scriptName = conf.get(PropertyKey.LOCALITY_SCRIPT); Path script = Paths.get(scriptName); if (!Files.exists(script)) { URL resource = TieredIdentityFactory.class.getClassLoader().getResource(scriptName); if (resource != null) { script = Paths.get(resource.getPath()); } else { return null; } } LOG.debug("Found tiered identity script at {}", script); String identityString; try { identityString = ShellUtils.execCommand(script.toString()); } catch (IOException e) { throw new RuntimeException( String.format("Failed to run script %s: %s", script, e.toString()), e); } try { return fromString(identityString, conf); } catch (IOException e) { throw new RuntimeException( String.format("Failed to parse output of running %s: %s", script, e.getMessage()), e); } }  static TieredIdentity localIdentity(AlluxioConfiguration conf); static TieredIdentity fromString(String identityString, AlluxioConfiguration conf);  }