use of alluxio.wire.TieredIdentity.LocalityTier in project alluxio by Alluxio.
the class TieredIdentityTest method createRandomLocalityTier.
private static LocalityTier createRandomLocalityTier() {
Random random = new Random();
String tier = CommonUtils.randomAlphaNumString(random.nextInt(10) + 1);
String value = CommonUtils.randomAlphaNumString(random.nextInt(10) + 1);
return new LocalityTier(tier, value);
}
use of alluxio.wire.TieredIdentity.LocalityTier in project alluxio by Alluxio.
the class TieredIdentityFactory method create.
/**
* Creates a tiered identity based on configuration.
*
* @return the created tiered identity
*/
@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();
}
// Explicit configuration overrides script output.
if (conf.isSet(Template.LOCALITY_TIER.format(tierName))) {
value = conf.getString(Template.LOCALITY_TIER.format(tierName));
}
tiers.add(new LocalityTier(tierName, value));
}
// If the user doesn't specify the value of the "node" tier, we fill in a sensible default.
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);
}
use of alluxio.wire.TieredIdentity.LocalityTier in project alluxio by Alluxio.
the class TieredIdentityFactoryTest method fromScript.
@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);
}
}
use of alluxio.wire.TieredIdentity.LocalityTier in project alluxio by Alluxio.
the class TieredIdentityFactoryTest method overrideScript.
@Test
public void overrideScript() throws Exception {
String scriptPath = setupScript("node=myhost,rack=myrack,custom=mycustom", mFolder.newFile());
try (Closeable c = new ConfigurationRule(ImmutableMap.of(Template.LOCALITY_TIER.format("node"), "overridden", 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", "overridden"), new LocalityTier("rack", "myrack"), new LocalityTier("custom", "mycustom")));
assertEquals(expected, identity);
}
}
use of alluxio.wire.TieredIdentity.LocalityTier in project alluxio by Alluxio.
the class TieredIdentityFactoryTest method fromScriptClasspath.
@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();
}
Aggregations