use of alluxio.wire.TieredIdentity in project alluxio by Alluxio.
the class TieredIdentityFactoryTest method outOfOrderScript.
@Test
public void outOfOrderScript() throws Exception {
String scriptPath = setupScript("rack=myrack,node=myhost", mFolder.newFile());
try (Closeable c = new ConfigurationRule(ImmutableMap.of(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")));
assertEquals(expected, identity);
}
}
use of alluxio.wire.TieredIdentity in project alluxio by Alluxio.
the class ClientTestUtils method worker.
public static BlockWorkerInfo worker(long capacity, long used, String node, String rack) {
WorkerNetAddress address = new WorkerNetAddress();
List<LocalityTier> tiers = new ArrayList<>();
if (node != null && !node.isEmpty()) {
address.setHost(node);
tiers.add(new LocalityTier(Constants.LOCALITY_NODE, node));
}
if (rack != null && !rack.isEmpty()) {
tiers.add(new LocalityTier(Constants.LOCALITY_RACK, rack));
}
address.setTieredIdentity(new TieredIdentity(tiers));
return new BlockWorkerInfo(address, capacity, used);
}
use of alluxio.wire.TieredIdentity in project alluxio by Alluxio.
the class TieredIdentityFactoryTest method notExecutable.
@Test
public void notExecutable() throws Exception {
File script = mFolder.newFile();
FileUtils.writeStringToFile(script, "#!/bin/bash");
try (Closeable c = new ConfigurationRule(ImmutableMap.of(PropertyKey.LOCALITY_SCRIPT, script.getAbsolutePath()), mConfiguration).toResource()) {
try {
TieredIdentity identity = TieredIdentityFactory.create(mConfiguration);
} catch (RuntimeException e) {
assertThat(e.getMessage(), containsString(script.getAbsolutePath()));
assertThat(e.getMessage(), containsString("Permission denied"));
}
}
}
use of alluxio.wire.TieredIdentity in project alluxio by Alluxio.
the class TieredIdentityFactoryTest method defaultConf.
@Test
public void defaultConf() throws Exception {
TieredIdentity identity = TieredIdentityFactory.create(mConfiguration);
TieredIdentity expected = new TieredIdentity(Arrays.asList(new LocalityTier("node", NetworkAddressUtils.getLocalNodeName(mConfiguration)), new LocalityTier("rack", null)));
assertEquals(expected, identity);
}
use of alluxio.wire.TieredIdentity in project alluxio by Alluxio.
the class TieredIdentityFactory method fromString.
/**
* @param identityString tiered identity string to parse
* @param conf Alluxio configuration
* @return the parsed tiered identity
*/
public static TieredIdentity fromString(String identityString, AlluxioConfiguration conf) throws IOException {
Set<String> allTiers = Sets.newHashSet(conf.getList(PropertyKey.LOCALITY_ORDER, ","));
Map<String, String> tiers = new HashMap<>();
for (String tier : identityString.split(",")) {
String[] parts = tier.split("=");
if (parts.length != 2) {
throw new IOException(String.format("Failed to parse tiered identity. The value should be a comma-separated list " + "of key=value pairs, but was %s", identityString));
}
String key = parts[0].trim();
if (tiers.containsKey(key)) {
throw new IOException(String.format("Encountered repeated tier definition for %s when parsing tiered identity from string " + "%s", key, identityString));
}
if (!allTiers.contains(key)) {
throw new IOException(String.format("Unrecognized tier: %s. The tiers defined by %s are %s", key, PropertyKey.LOCALITY_ORDER.toString(), allTiers));
}
tiers.put(key, parts[1].trim());
}
List<LocalityTier> tieredIdentity = new ArrayList<>();
for (String localityTier : conf.getList(PropertyKey.LOCALITY_ORDER, ",")) {
String value = tiers.getOrDefault(localityTier, null);
tieredIdentity.add(new LocalityTier(localityTier, value));
}
return new TieredIdentity(tieredIdentity);
}
Aggregations