/** * @param conf the configuration to use * @return whether the configuration describes how to find the master host, either through * explicit configuration or through zookeeper */ public static boolean masterHostConfigured(AlluxioConfiguration conf) { boolean usingZk = conf.getBoolean(PropertyKey.ZOOKEEPER_ENABLED) && conf.isSet(PropertyKey.ZOOKEEPER_ADDRESS); return conf.isSet(PropertyKey.MASTER_HOSTNAME) || usingZk || getMasterRpcAddresses(conf).size() > 1; }
/** * @param conf configuration for creating the master inquire client * @return a master inquire client */ public static MasterInquireClient create(AlluxioConfiguration conf) { if (conf.getBoolean(PropertyKey.ZOOKEEPER_ENABLED)) { return ZkMasterInquireClient.getClient(conf.get(PropertyKey.ZOOKEEPER_ADDRESS), conf.get(PropertyKey.ZOOKEEPER_ELECTION_PATH), conf.get(PropertyKey.ZOOKEEPER_LEADER_PATH), conf.getInt(PropertyKey.ZOOKEEPER_LEADER_INQUIRY_RETRY_COUNT)); } else if (ConfigurationUtils.getMasterRpcAddresses(conf).size() > 1) { return new PollingMasterInquireClient( ConfigurationUtils.getMasterRpcAddresses(conf), conf); } else { return new SingleMasterInquireClient( NetworkAddressUtils.getConnectAddress(ServiceType.MASTER_RPC, conf)); } }
@Test public void resetContextFromMultiMasterToSingleMaster() throws Exception { URI uri = URI.create(Constants.HEADER + "host1:19998,host2:19998,host3:19998/tmp/path.txt"); FileSystem fs = getHadoopFilesystem(org.apache.hadoop.fs.FileSystem.get(uri, getConf())); assertFalse(fs.mFsContext.getConf().getBoolean(PropertyKey.ZOOKEEPER_ENABLED)); assertEquals(3, ConfigurationUtils.getMasterRpcAddresses(fs.mFsContext.getConf()).size()); assertEquals("host1:19998,host2:19998,host3:19998", fs.mFsContext.getConf().get(PropertyKey.MASTER_RPC_ADDRESSES)); uri = URI.create(Constants.HEADER + "host:19998/tmp/path.txt"); fs = getHadoopFilesystem(org.apache.hadoop.fs.FileSystem.get(uri, getConf())); assertFalse(fs.mFsContext.getConf().getBoolean(PropertyKey.ZOOKEEPER_ENABLED)); assertEquals(PropertyKey.MASTER_JOURNAL_TYPE.getDefaultValue(), fs.mFsContext.getConf().get(PropertyKey.MASTER_JOURNAL_TYPE)); assertEquals(1, ConfigurationUtils.getMasterRpcAddresses(fs.mFsContext.getConf()).size()); }
@Test public void resetContextFromZookeeperToMultiMaster() throws Exception { URI uri = URI.create(Constants.HEADER + "zk@zkHost:2181/tmp/path.txt"); FileSystem fs = getHadoopFilesystem(org.apache.hadoop.fs.FileSystem.get(uri, getConf())); assertTrue(fs.mFsContext.getConf().getBoolean(PropertyKey.ZOOKEEPER_ENABLED)); assertEquals("zkHost:2181", fs.mFsContext.getConf().get(PropertyKey.ZOOKEEPER_ADDRESS)); uri = URI.create(Constants.HEADER + "host1:19998,host2:19998,host3:19998/tmp/path.txt"); fs = getHadoopFilesystem(org.apache.hadoop.fs.FileSystem.get(uri, getConf())); assertFalse(fs.mFsContext.getConf().getBoolean(PropertyKey.ZOOKEEPER_ENABLED)); assertEquals(3, ConfigurationUtils.getMasterRpcAddresses(fs.mFsContext.getConf()).size()); assertEquals("host1:19998,host2:19998,host3:19998", fs.mFsContext.getConf().get(PropertyKey.MASTER_RPC_ADDRESSES)); }