use of alluxio.uri.ZookeeperAuthority in project alluxio by Alluxio.
the class AlluxioURITest method semicolonZookeeperUri.
@Test
public void semicolonZookeeperUri() {
AlluxioURI uri = new AlluxioURI("alluxio://zk@host1:2181;host2:2181;host3:2181/xy z/a b c");
assertTrue(uri.hasAuthority());
assertEquals("zk@host1:2181,host2:2181,host3:2181", uri.getAuthority().toString());
assertTrue(uri.getAuthority() instanceof ZookeeperAuthority);
ZookeeperAuthority zkAuthority = (ZookeeperAuthority) uri.getAuthority();
assertEquals("host1:2181,host2:2181,host3:2181", zkAuthority.getZookeeperAddress());
}
use of alluxio.uri.ZookeeperAuthority in project alluxio by Alluxio.
the class FileSystem method getConfigurationFromUri.
@Override
protected Map<String, Object> getConfigurationFromUri(URI uri, Configuration conf) {
AlluxioURI alluxioUri = new AlluxioURI(uri.toString());
Map<String, Object> alluxioConfProperties = new HashMap<>();
if (alluxioUri.getAuthority() instanceof ZookeeperAuthority) {
ZookeeperAuthority authority = (ZookeeperAuthority) alluxioUri.getAuthority();
alluxioConfProperties.put(PropertyKey.ZOOKEEPER_ENABLED.getName(), true);
alluxioConfProperties.put(PropertyKey.ZOOKEEPER_ADDRESS.getName(), authority.getZookeeperAddress());
} else if (alluxioUri.getAuthority() instanceof SingleMasterAuthority) {
SingleMasterAuthority authority = (SingleMasterAuthority) alluxioUri.getAuthority();
alluxioConfProperties.put(PropertyKey.MASTER_HOSTNAME.getName(), authority.getHost());
alluxioConfProperties.put(PropertyKey.MASTER_RPC_PORT.getName(), authority.getPort());
alluxioConfProperties.put(PropertyKey.ZOOKEEPER_ENABLED.getName(), false);
alluxioConfProperties.put(PropertyKey.ZOOKEEPER_ADDRESS.getName(), null);
// Unset the embedded journal related configuration
// to support alluxio URI has the highest priority
alluxioConfProperties.put(PropertyKey.MASTER_EMBEDDED_JOURNAL_ADDRESSES.getName(), null);
alluxioConfProperties.put(PropertyKey.MASTER_RPC_ADDRESSES.getName(), null);
} else if (alluxioUri.getAuthority() instanceof MultiMasterAuthority) {
MultiMasterAuthority authority = (MultiMasterAuthority) alluxioUri.getAuthority();
alluxioConfProperties.put(PropertyKey.MASTER_RPC_ADDRESSES.getName(), authority.getMasterAddresses());
// Unset the zookeeper configuration to support alluxio URI has the highest priority
alluxioConfProperties.put(PropertyKey.ZOOKEEPER_ENABLED.getName(), false);
alluxioConfProperties.put(PropertyKey.ZOOKEEPER_ADDRESS.getName(), null);
} else if (alluxioUri.getAuthority() instanceof EmbeddedLogicalAuthority) {
EmbeddedLogicalAuthority authority = (EmbeddedLogicalAuthority) alluxioUri.getAuthority();
String masterNamesConfKey = PropertyKey.Template.MASTER_LOGICAL_NAMESERVICES.format(authority.getLogicalName()).getName();
String[] masterNames = conf.getTrimmedStrings(masterNamesConfKey);
Preconditions.checkArgument(masterNames.length != 0, "Invalid uri. You must set %s to use the logical name ", masterNamesConfKey);
StringJoiner masterRpcAddress = new StringJoiner(",");
for (String masterName : masterNames) {
String name = PropertyKey.Template.MASTER_LOGICAL_RPC_ADDRESS.format(authority.getLogicalName(), masterName).getName();
String address = conf.get(name);
Preconditions.checkArgument(address != null, "You need to set %s", name);
masterRpcAddress.add(address);
}
alluxioConfProperties.put(PropertyKey.MASTER_RPC_ADDRESSES.getName(), masterRpcAddress.toString());
alluxioConfProperties.put(PropertyKey.ZOOKEEPER_ENABLED.getName(), false);
alluxioConfProperties.put(PropertyKey.ZOOKEEPER_ADDRESS.getName(), null);
} else if (alluxioUri.getAuthority() instanceof ZookeeperLogicalAuthority) {
ZookeeperLogicalAuthority authority = (ZookeeperLogicalAuthority) alluxioUri.getAuthority();
String zkNodesConfKey = PropertyKey.Template.MASTER_LOGICAL_ZOOKEEPER_NAMESERVICES.format(authority.getLogicalName()).getName();
String[] zkNodeNames = conf.getTrimmedStrings(zkNodesConfKey);
Preconditions.checkArgument(zkNodeNames.length != 0, "Invalid uri. You must set %s to use the logical name", zkNodesConfKey);
StringJoiner zkAddress = new StringJoiner(",");
for (String zkName : zkNodeNames) {
String name = PropertyKey.Template.MASTER_LOGICAL_ZOOKEEPER_ADDRESS.format(authority.getLogicalName(), zkName).getName();
String address = conf.get(name);
Preconditions.checkArgument(address != null, "You need to set %s", name);
zkAddress.add(address);
}
alluxioConfProperties.put(PropertyKey.ZOOKEEPER_ENABLED.getName(), true);
alluxioConfProperties.put(PropertyKey.ZOOKEEPER_ADDRESS.getName(), zkAddress.toString());
}
return alluxioConfProperties;
}
use of alluxio.uri.ZookeeperAuthority in project alluxio by Alluxio.
the class LogLevelTest method parseZooKeeperHAMasterTarget.
@Test
public void parseZooKeeperHAMasterTarget() throws Exception {
String masterAddress = "masters-1:2181";
mConf.set(PropertyKey.ZOOKEEPER_ENABLED, true);
mConf.set(PropertyKey.ZOOKEEPER_ADDRESS, masterAddress);
CommandLine mockCommandLine = mock(CommandLine.class);
String[] mockArgs = new String[] { "--target", "master" };
when(mockCommandLine.getArgs()).thenReturn(mockArgs);
when(mockCommandLine.hasOption(LogLevel.TARGET_OPTION_NAME)).thenReturn(true);
when(mockCommandLine.getOptionValue(LogLevel.TARGET_OPTION_NAME)).thenReturn(mockArgs[1]);
PowerMockito.mockStatic(MasterInquireClient.Factory.class);
MasterInquireClient mockInquireClient = mock(MasterInquireClient.class);
when(mockInquireClient.getPrimaryRpcAddress()).thenReturn(new InetSocketAddress("masters-1", mConf.getInt(PropertyKey.MASTER_RPC_PORT)));
when(mockInquireClient.getConnectDetails()).thenReturn(() -> new ZookeeperAuthority(masterAddress));
when(MasterInquireClient.Factory.create(any(), any())).thenReturn(mockInquireClient);
List<LogLevel.TargetInfo> targets = LogLevel.parseOptTarget(mockCommandLine, mConf);
assertEquals(1, targets.size());
assertEquals(new LogLevel.TargetInfo("masters-1", MASTER_WEB_PORT, "master"), targets.get(0));
}
use of alluxio.uri.ZookeeperAuthority in project alluxio by Alluxio.
the class AlluxioURITest method basicZookeeperUri.
@Test
public void basicZookeeperUri() {
AlluxioURI uri = new AlluxioURI("alluxio://zk@host1:2181,host2:2181,host3:2181/xy z/a b c");
assertEquals(uri, new AlluxioURI("alluxio://zk@host1:2181,host2:2181,host3:2181/xy z/a b c"));
assertEquals("alluxio", uri.getScheme());
assertEquals("zk@host1:2181,host2:2181,host3:2181", uri.getAuthority().toString());
assertTrue(uri.getAuthority() instanceof ZookeeperAuthority);
ZookeeperAuthority zkAuthority = (ZookeeperAuthority) uri.getAuthority();
assertEquals("host1:2181,host2:2181,host3:2181", zkAuthority.getZookeeperAddress());
assertEquals(2, uri.getDepth());
assertEquals("a b c", uri.getName());
assertEquals("alluxio://zk@host1:2181,host2:2181,host3:2181/xy z", uri.getParent().toString());
assertEquals("alluxio://zk@host1:2181,host2:2181,host3:2181/", uri.getParent().getParent().toString());
assertEquals("/xy z/a b c", uri.getPath());
assertTrue(uri.hasAuthority());
assertTrue(uri.hasScheme());
assertTrue(uri.isAbsolute());
assertTrue(uri.isPathAbsolute());
assertEquals("alluxio://zk@host1:2181,host2:2181,host3:2181/xy z/a b c/d", uri.join("/d").toString());
assertEquals("alluxio://zk@host1:2181,host2:2181,host3:2181/xy z/a b c/d", uri.join(new AlluxioURI("/d")).toString());
assertEquals("alluxio://zk@host1:2181,host2:2181,host3:2181/xy z/a b c", uri.toString());
}
use of alluxio.uri.ZookeeperAuthority in project alluxio by Alluxio.
the class FileSystemFactoryTest method zkFileSystemCacheTest.
@Test
public void zkFileSystemCacheTest() {
Map<String, String> sysProps = new HashMap<>();
sysProps.put(PropertyKey.ZOOKEEPER_ENABLED.getName(), Boolean.toString(true));
sysProps.put(PropertyKey.ZOOKEEPER_ADDRESS.getName(), "zk@192.168.0.5");
sysProps.put(PropertyKey.ZOOKEEPER_ELECTION_PATH.getName(), "/alluxio/leader");
try (Closeable p = new SystemPropertyRule(sysProps).toResource()) {
ConfigurationUtils.reloadProperties();
InstancedConfiguration conf = new InstancedConfiguration(ConfigurationUtils.defaults());
MasterInquireClient.ConnectDetails connectDetails = MasterInquireClient.Factory.getConnectDetails(conf);
// Make sure we have a Zookeeper authority
assertTrue(connectDetails.toAuthority() instanceof ZookeeperAuthority);
fileSystemCacheTest();
} catch (IOException e) {
fail("Unable to set system properties");
}
}
Aggregations