/** * @return a client for determining the serving master */ public synchronized MasterInquireClient getMasterInquireClient() { switch (mDeployMode) { case NON_HA: Preconditions.checkState(mMasters.size() == 1, "Running with multiple masters requires Zookeeper to be enabled"); return new SingleMasterInquireClient(new InetSocketAddress( mMasterAddresses.get(0).getHostname(), mMasterAddresses.get(0).getRpcPort())); case EMBEDDED_HA: List<InetSocketAddress> addresses = new ArrayList<>(mMasterAddresses.size()); for (MasterNetAddress address : mMasterAddresses) { addresses.add(new InetSocketAddress(address.getHostname(), address.getRpcPort())); } return new PollingMasterInquireClient(addresses, ServerConfiguration.global()); case ZOOKEEPER_HA: return ZkMasterInquireClient.getClient(mCuratorServer.getConnectString(), ServerConfiguration.get(PropertyKey.ZOOKEEPER_ELECTION_PATH), ServerConfiguration.get(PropertyKey.ZOOKEEPER_LEADER_PATH), ServerConfiguration.getInt(PropertyKey.ZOOKEEPER_LEADER_INQUIRY_RETRY_COUNT)); default: throw new IllegalStateException("Unknown deploy mode: " + mDeployMode.toString()); } }
@Override public InetSocketAddress getPrimaryRpcAddress() throws UnavailableException { RetryPolicy retry = mRetryPolicySupplier.get(); while (retry.attempt()) { InetSocketAddress address = getAddress(); if (address != null) { return address; } } throw new UnavailableException(String.format( "Failed to determine primary master rpc address after polling each of %s %d times", mConnectDetails.getAddresses(), retry.getAttemptCount())); }
@Nullable private InetSocketAddress getAddress() { // Iterate over the masters and try to connect to each of their RPC ports. for (InetSocketAddress address : mConnectDetails.getAddresses()) { try { LOG.debug("Checking whether {} is listening for RPCs", address); pingMetaService(address); LOG.debug("Successfully connected to {}", address); return address; } catch (UnavailableException e) { LOG.debug("Failed to connect to {}", address); continue; } catch (UnauthenticatedException e) { throw new RuntimeException(e); } } return null; }
@Override public int run(CommandLine cl) { try (CloseableResource<FileSystemMasterClient> client = mFsContext.acquireMasterClientResource()) { try { InetSocketAddress address = client.get().getAddress(); System.out.println(address.getHostName()); List<InetSocketAddress> addresses = Arrays.asList(address); MasterInquireClient inquireClient = new PollingMasterInquireClient(addresses, () -> new ExponentialBackoffRetry(50, 100, 2), mFsContext.getConf() ); try { inquireClient.getPrimaryRpcAddress(); } catch (UnavailableException e) { System.err.println("The leader is not currently serving requests."); } } catch (UnavailableException e) { System.err.println("Failed to get the leader master."); } } return 0; }
@Override public InetSocketAddress getPrimaryRpcAddress() throws UnavailableException { RetryPolicy retry = mRetryPolicySupplier.get(); while (retry.attempt()) { InetSocketAddress address = getAddress(); if (address != null) { return address; } } throw new UnavailableException(String.format( "Failed to determine primary master rpc address after polling each of %s %d times", mConnectDetails.getAddresses(), retry.getAttemptCount())); }
@Nullable private InetSocketAddress getAddress() { // Iterate over the masters and try to connect to each of their RPC ports. for (InetSocketAddress address : mConnectDetails.getAddresses()) { try { LOG.debug("Checking whether {} is listening for RPCs", address); pingMetaService(address); LOG.debug("Successfully connected to {}", address); return address; } catch (TTransportException e) { LOG.debug("Failed to connect to {}", address); continue; } catch (UnauthenticatedException e) { throw new RuntimeException(e); } } return null; }
/** * Checks if the master client service is available. * Throws an exception if fails to determine that the master client service is running. * * @param alluxioConf Alluxio configuration */ public static void checkMasterClientService(AlluxioConfiguration alluxioConf) throws IOException { try (CloseableResource<FileSystemMasterClient> client = FileSystemContext.create(ClientContext.create(alluxioConf)) .acquireMasterClientResource()) { InetSocketAddress address = client.get().getAddress(); List<InetSocketAddress> addresses = Arrays.asList(address); MasterInquireClient inquireClient = new PollingMasterInquireClient(addresses, () -> new ExponentialBackoffRetry(50, 100, 2), alluxioConf); inquireClient.getPrimaryRpcAddress(); } catch (UnavailableException e) { throw new IOException("Cannot connect to Alluxio leader master."); } }
public static MasterInquireClient createForJobMaster(AlluxioConfiguration conf) { if (conf.getBoolean(PropertyKey.ZOOKEEPER_ENABLED)) { return ZkMasterInquireClient.getClient(conf.get(PropertyKey.ZOOKEEPER_ADDRESS), conf.get(PropertyKey.ZOOKEEPER_JOB_ELECTION_PATH), conf.get(PropertyKey.ZOOKEEPER_JOB_LEADER_PATH), conf.getInt(PropertyKey.ZOOKEEPER_LEADER_INQUIRY_RETRY_COUNT)); } else if (ConfigurationUtils.getJobMasterRpcAddresses(conf) .size() > 1) { return new PollingMasterInquireClient( ConfigurationUtils.getJobMasterRpcAddresses(conf), conf); } else { return new SingleMasterInquireClient( NetworkAddressUtils.getConnectAddress(ServiceType.JOB_MASTER_RPC, conf)); } } /**
/** * @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)); } }