Search in sources :

Example 1 with LocalityTier

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

Example 2 with LocalityTier

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);
}
Also used : TieredIdentity(alluxio.wire.TieredIdentity) ArrayList(java.util.ArrayList) LocalityTier(alluxio.wire.TieredIdentity.LocalityTier) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 3 with LocalityTier

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);
    }
}
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 4 with LocalityTier

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);
    }
}
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 5 with LocalityTier

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

Aggregations

LocalityTier (alluxio.wire.TieredIdentity.LocalityTier)12 TieredIdentity (alluxio.wire.TieredIdentity)8 Test (org.junit.Test)7 ConfigurationRule (alluxio.ConfigurationRule)4 Closeable (java.io.Closeable)4 ArrayList (java.util.ArrayList)4 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)4 BlockWorkerInfo (alluxio.client.block.BlockWorkerInfo)2 WorkerNetAddress (alluxio.wire.WorkerNetAddress)2 AlluxioURI (alluxio.AlluxioURI)1 Constants (alluxio.Constants)1 URIStatus (alluxio.client.file.URIStatus)1 Pair (alluxio.collections.Pair)1 FailedPreconditionException (alluxio.exception.status.FailedPreconditionException)1 RunTaskContext (alluxio.job.RunTaskContext)1 SelectExecutorsContext (alluxio.job.SelectExecutorsContext)1 AbstractVoidPlanDefinition (alluxio.job.plan.AbstractVoidPlanDefinition)1 LoadTask (alluxio.job.plan.load.LoadDefinition.LoadTask)1 JobUtils (alluxio.job.util.JobUtils)1 SerializableVoid (alluxio.job.util.SerializableVoid)1