@Test public void fromScriptClasspath() throws Exception { String customScriptName = "my-alluxio-locality.sh"; File dir = mFolder.newFolder("fromScriptClasspath"); CommonUtils.classLoadURL(dir.getCanonicalPath()); File script = new File(dir, customScriptName); setupScript("node=myhost,rack=myrack,custom=mycustom", script); try (Closeable c = new ConfigurationRule(ImmutableMap.of( PropertyKey.LOCALITY_ORDER, "node,rack,custom", PropertyKey.LOCALITY_SCRIPT, customScriptName), 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); } script.delete(); }
@VisibleForTesting static TieredIdentity create(AlluxioConfiguration conf) { TieredIdentity scriptIdentity = fromScript(conf); List<LocalityTier> tiers = new ArrayList<>(); List<String> orderedTierNames = conf.getList(PropertyKey.LOCALITY_ORDER, ","); for (int i = 0; i < orderedTierNames.size(); i++) { String tierName = orderedTierNames.get(i); String value = null; if (scriptIdentity != null) { LocalityTier scriptTier = scriptIdentity.getTier(i); Preconditions.checkState(scriptTier.getTierName().equals(tierName)); value = scriptTier.getValue(); } if (conf.isSet(Template.LOCALITY_TIER.format(tierName))) { value = conf.get(Template.LOCALITY_TIER.format(tierName)); } tiers.add(new LocalityTier(tierName, value)); } if (tiers.size() > 0 && tiers.get(0).getTierName().equals(Constants.LOCALITY_NODE) && tiers.get(0).getValue() == null) { String name = NetworkAddressUtils.getLocalNodeName(conf); tiers.set(0, new LocalityTier(Constants.LOCALITY_NODE, name)); } return new TieredIdentity(tiers); }
TieredIdentityFactory { @VisibleForTesting static TieredIdentity create(AlluxioConfiguration conf) { TieredIdentity scriptIdentity = fromScript(conf); List<LocalityTier> tiers = new ArrayList<>(); List<String> orderedTierNames = conf.getList(PropertyKey.LOCALITY_ORDER, ","); for (int i = 0; i < orderedTierNames.size(); i++) { String tierName = orderedTierNames.get(i); String value = null; if (scriptIdentity != null) { LocalityTier scriptTier = scriptIdentity.getTier(i); Preconditions.checkState(scriptTier.getTierName().equals(tierName)); value = scriptTier.getValue(); } if (conf.isSet(Template.LOCALITY_TIER.format(tierName))) { value = conf.get(Template.LOCALITY_TIER.format(tierName)); } tiers.add(new LocalityTier(tierName, value)); } if (tiers.size() > 0 && tiers.get(0).getTierName().equals(Constants.LOCALITY_NODE) && tiers.get(0).getValue() == null) { String name = NetworkAddressUtils.getLocalNodeName(conf); tiers.set(0, new LocalityTier(Constants.LOCALITY_NODE, name)); } return new TieredIdentity(tiers); } }
TieredIdentityFactory { @VisibleForTesting static TieredIdentity create(AlluxioConfiguration conf) { TieredIdentity scriptIdentity = fromScript(conf); List<LocalityTier> tiers = new ArrayList<>(); List<String> orderedTierNames = conf.getList(PropertyKey.LOCALITY_ORDER, ","); for (int i = 0; i < orderedTierNames.size(); i++) { String tierName = orderedTierNames.get(i); String value = null; if (scriptIdentity != null) { LocalityTier scriptTier = scriptIdentity.getTier(i); Preconditions.checkState(scriptTier.getTierName().equals(tierName)); value = scriptTier.getValue(); } if (conf.isSet(Template.LOCALITY_TIER.format(tierName))) { value = conf.get(Template.LOCALITY_TIER.format(tierName)); } tiers.add(new LocalityTier(tierName, value)); } if (tiers.size() > 0 && tiers.get(0).getTierName().equals(Constants.LOCALITY_NODE) && tiers.get(0).getValue() == null) { String name = NetworkAddressUtils.getLocalNodeName(conf); tiers.set(0, new LocalityTier(Constants.LOCALITY_NODE, name)); } return new TieredIdentity(tiers); }  }
TieredIdentityFactory { @VisibleForTesting static TieredIdentity create(AlluxioConfiguration conf) { TieredIdentity scriptIdentity = fromScript(conf); List<LocalityTier> tiers = new ArrayList<>(); List<String> orderedTierNames = conf.getList(PropertyKey.LOCALITY_ORDER, ","); for (int i = 0; i < orderedTierNames.size(); i++) { String tierName = orderedTierNames.get(i); String value = null; if (scriptIdentity != null) { LocalityTier scriptTier = scriptIdentity.getTier(i); Preconditions.checkState(scriptTier.getTierName().equals(tierName)); value = scriptTier.getValue(); } if (conf.isSet(Template.LOCALITY_TIER.format(tierName))) { value = conf.get(Template.LOCALITY_TIER.format(tierName)); } tiers.add(new LocalityTier(tierName, value)); } if (tiers.size() > 0 && tiers.get(0).getTierName().equals(Constants.LOCALITY_NODE) && tiers.get(0).getValue() == null) { String name = NetworkAddressUtils.getLocalNodeName(conf); tiers.set(0, new LocalityTier(Constants.LOCALITY_NODE, name)); } return new TieredIdentity(tiers); }  static TieredIdentity localIdentity(AlluxioConfiguration conf); static TieredIdentity fromString(String identityString, AlluxioConfiguration conf); }
TieredIdentityFactory { @VisibleForTesting static TieredIdentity create(AlluxioConfiguration conf) { TieredIdentity scriptIdentity = fromScript(conf); List<LocalityTier> tiers = new ArrayList<>(); List<String> orderedTierNames = conf.getList(PropertyKey.LOCALITY_ORDER, ","); for (int i = 0; i < orderedTierNames.size(); i++) { String tierName = orderedTierNames.get(i); String value = null; if (scriptIdentity != null) { LocalityTier scriptTier = scriptIdentity.getTier(i); Preconditions.checkState(scriptTier.getTierName().equals(tierName)); value = scriptTier.getValue(); } if (conf.isSet(Template.LOCALITY_TIER.format(tierName))) { value = conf.get(Template.LOCALITY_TIER.format(tierName)); } tiers.add(new LocalityTier(tierName, value)); } if (tiers.size() > 0 && tiers.get(0).getTierName().equals(Constants.LOCALITY_NODE) && tiers.get(0).getValue() == null) { String name = NetworkAddressUtils.getLocalNodeName(conf); tiers.set(0, new LocalityTier(Constants.LOCALITY_NODE, name)); } return new TieredIdentity(tiers); }  static TieredIdentity localIdentity(AlluxioConfiguration conf); static TieredIdentity fromString(String identityString, AlluxioConfiguration conf);  }