Search in sources :

Example 6 with TieredIdentity

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);
    }
}
Also used : TieredIdentity(alluxio.wire.TieredIdentity) Closeable(java.io.Closeable) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ConfigurationRule(alluxio.ConfigurationRule) LocalityTier(alluxio.wire.TieredIdentity.LocalityTier) Test(org.junit.Test)

Example 7 with TieredIdentity

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);
}
Also used : WorkerNetAddress(alluxio.wire.WorkerNetAddress) TieredIdentity(alluxio.wire.TieredIdentity) ArrayList(java.util.ArrayList) BlockWorkerInfo(alluxio.client.block.BlockWorkerInfo) LocalityTier(alluxio.wire.TieredIdentity.LocalityTier)

Example 8 with TieredIdentity

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"));
        }
    }
}
Also used : TieredIdentity(alluxio.wire.TieredIdentity) Closeable(java.io.Closeable) File(java.io.File) ConfigurationRule(alluxio.ConfigurationRule) Test(org.junit.Test)

Example 9 with TieredIdentity

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);
}
Also used : TieredIdentity(alluxio.wire.TieredIdentity) LocalityTier(alluxio.wire.TieredIdentity.LocalityTier) Test(org.junit.Test)

Example 10 with TieredIdentity

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);
}
Also used : HashMap(java.util.HashMap) TieredIdentity(alluxio.wire.TieredIdentity) ArrayList(java.util.ArrayList) IOException(java.io.IOException) LocalityTier(alluxio.wire.TieredIdentity.LocalityTier)

Aggregations

TieredIdentity (alluxio.wire.TieredIdentity)10 LocalityTier (alluxio.wire.TieredIdentity.LocalityTier)8 Test (org.junit.Test)6 ConfigurationRule (alluxio.ConfigurationRule)5 Closeable (java.io.Closeable)5 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)4 ArrayList (java.util.ArrayList)3 WorkerNetAddress (alluxio.wire.WorkerNetAddress)2 File (java.io.File)2 Constants (alluxio.Constants)1 BlockWorkerInfo (alluxio.client.block.BlockWorkerInfo)1 Pair (alluxio.collections.Pair)1 AlluxioConfiguration (alluxio.conf.AlluxioConfiguration)1 PropertyKey (alluxio.conf.PropertyKey)1 TieredIdentityUtils (alluxio.util.TieredIdentityUtils)1 NettyUtils (alluxio.util.network.NettyUtils)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 List (java.util.List)1