/** * Converts a proto type to a wire type. * * @param tieredPIdentity the proto type to convert * @return the converted wire type */ public static TieredIdentity fromProto(alluxio.grpc.TieredIdentity tieredPIdentity) { return new TieredIdentity(tieredPIdentity.getTiersList().stream().map(GrpcUtils::fromProto) .collect(Collectors.toList())); }
/** * @return the tiered identity */ public TieredIdentity getTieredIdentity() { if (mTieredIdentity != null) { return mTieredIdentity; } return new TieredIdentity(Arrays.asList(new LocalityTier(Constants.LOCALITY_NODE, mHost))); }
tieredIdentity.add(new LocalityTier(localityTier, value)); return new TieredIdentity(tieredIdentity);
public static TieredIdentity createRandomTieredIdentity() { return new TieredIdentity( Arrays.asList(createRandomLocalityTier(), createRandomLocalityTier())); }
tiers.set(0, new LocalityTier(Constants.LOCALITY_NODE, name)); return new TieredIdentity(tiers);
private BlockWorkerInfo worker(long capacity, 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, 0); } }
private 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); } }
public void string() { TieredIdentity identity = new TieredIdentity( Arrays.asList(new LocalityTier("k1", "v1"), new LocalityTier("k2", "v2"))); assertEquals("TieredIdentity(k1=v1, k2=v2)", identity.toString()); }
@Test public void fromString() throws Exception { assertEquals(new TieredIdentity(Arrays.asList( new LocalityTier("node", "b"), new LocalityTier("rack", "d") )), TieredIdentityFactory.fromString("node=b,rack=d", mConfiguration)); }
@Test public void fromScriptClasspath() throws Exception { String customScriptName = "my-alluxio-locality.sh"; File dir = mFolder.newFolder("fromScriptClasspath"); Whitebox.invokeMethod(ClassLoader.getSystemClassLoader(), "addURL", dir.toURI().toURL()); 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(); }
@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); }
@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); } }
@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); } }
@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); } }
/** * @param tieredIdentity a Thrift tiered identity * @return the corresponding wire type tiered identity */ @Nullable public static TieredIdentity fromThrift(alluxio.thrift.TieredIdentity tieredIdentity) { if (tieredIdentity == null) { return null; } return new TieredIdentity(tieredIdentity.getTiers().stream() .map(LocalityTier::fromThrift).collect(Collectors.toList())); }
/** * @return the tiered identity */ public TieredIdentity getTieredIdentity() { if (mTieredIdentity != null) { return mTieredIdentity; } return new TieredIdentity(Arrays.asList(new LocalityTier(Constants.LOCALITY_NODE, mHost))); }
tieredIdentity.add(new LocalityTier(localityTier, value)); return new TieredIdentity(tieredIdentity);
tiers.set(0, new LocalityTier(Constants.LOCALITY_NODE, name)); return new TieredIdentity(tiers);
/** * Creates a new instance of {@link WorkerNetAddress} from thrift representation. * * @param address the thrift net address * @return the instance */ public static WorkerNetAddress fromThrift(alluxio.thrift.WorkerNetAddress address) { TieredIdentity tieredIdentity = TieredIdentity.fromThrift(address.getTieredIdentity()); if (tieredIdentity == null) { // This means the worker is pre-1.7.0. We handle this in post-1.7.0 clients by filling out // the tiered identity using the hostname field. tieredIdentity = new TieredIdentity( Arrays.asList(new LocalityTier(Constants.LOCALITY_NODE, address.getHost()))); } return new WorkerNetAddress() .setDataPort(address.getDataPort()) .setDomainSocketPath(address.getDomainSocketPath()) .setHost(address.getHost()) .setRpcPort(address.getRpcPort()) .setTieredIdentity(tieredIdentity) .setWebPort(address.getWebPort()); }