/** * Creates a file system context with a subject. * * @param subject the parent subject, set to null if not present */ private FileSystemContext(Subject subject, AlluxioConfiguration alluxioConf) { this(ClientContext.create(subject, alluxioConf)); }
/** * @return the {@link AlluxioConfiguration} backing this {@link FileSystemContext} */ public AlluxioConfiguration getConf() { return mClientContext.getConf(); }
/** * This constructor does not create a copy of the configuration. */ protected ClientContext(ClientContext ctx) { mSubject = ctx.getSubject(); mConf = ctx.getConf(); }
/** * This method is called before the connection is connected. Implementations should add any * additional operations before the connection is connected. * loading the cluster defaults */ protected void beforeConnect() throws IOException { // Bootstrap once for clients if (!isConnected()) { if (!mContext.getConf().clusterDefaultsLoaded()) { mContext.updateWithClusterDefaults(mAddress); } } }
/** * Releases a block worker client to the client pools. * * @param workerNetAddress the address of the channel * @param client the client to release */ public void releaseBlockWorkerClient(WorkerNetAddress workerNetAddress, BlockWorkerClient client) { SocketAddress address = NetworkAddressUtils.getDataPortSocketAddress(workerNetAddress, getConf()); ClientPoolKey key = new ClientPoolKey(address, SaslParticipantProviderUtils.getImpersonationUser(mClientContext.getSubject(), getConf())); if (mBlockWorkerClientPool.containsKey(key)) { mBlockWorkerClientPool.get(key).release(client); } else { LOG.warn("No client pool for key {}, closing client instead. Context is closed: {}", key, mClosed.get()); try { client.close(); } catch (IOException e) { LOG.warn("Error closing block worker client for key {}", key, e); } } }
/** * @param alluxioConf the specified {@link AlluxioConfiguration} to use * @return the client context with the given properties and an empty subject */ public static ClientContext create(AlluxioConfiguration alluxioConf) { return new ClientContext(null, alluxioConf); }
/** * Acquires a block worker client from the client pools. If there is no available client instance * available in the pool, it tries to create a new one. And an exception is thrown if it fails to * create a new one. * * @param workerNetAddress the network address of the channel * @return the acquired block worker */ public BlockWorkerClient acquireBlockWorkerClient(final WorkerNetAddress workerNetAddress) throws IOException { SocketAddress address = NetworkAddressUtils.getDataPortSocketAddress(workerNetAddress, getConf()); ClientPoolKey key = new ClientPoolKey(address, SaslParticipantProviderUtils.getImpersonationUser(mClientContext.getSubject(), getConf())); return mBlockWorkerClientPool.computeIfAbsent(key, k -> new BlockWorkerClientPool(mClientContext.getSubject(), address, getConf().getInt(PropertyKey.USER_BLOCK_WORKER_CLIENT_POOL_SIZE), getConf()) ).acquire(); }
/** * A client context with information about the subject and configuration of the client. * * @param subject the security subject to use * @param alluxioConf the {@link AlluxioConfiguration} to use. If null, the site property defaults * will be loaded * @return a new client context with the specified properties and subject */ public static ClientContext create(Subject subject, AlluxioConfiguration alluxioConf) { return new ClientContext(subject, alluxioConf); }
/** * Prints Alluxio configuration. * * @param args the arguments to specify the unit (optional) and configuration key (optional) */ public static void main(String[] args) { System.exit(getConf( ClientContext.create(new InstancedConfiguration(ConfigurationUtils.defaults())), args)); }
/** * Creates a new client base. * * @param context information required to connect to Alluxio * @param address the address */ public AbstractClient(ClientContext context, InetSocketAddress address) { this(context, address, () -> RetryUtils.defaultClientRetry( context.getConf().getDuration(PropertyKey.USER_RPC_RETRY_MAX_DURATION), context.getConf().getDuration(PropertyKey.USER_RPC_RETRY_BASE_SLEEP_MS), context.getConf().getDuration(PropertyKey.USER_RPC_RETRY_MAX_SLEEP_MS))); }
RuntimeConstants.VERSION, getServiceName(), mAddress); mChannel = GrpcChannelBuilder .newBuilder(mAddress, mContext.getConf()) .setSubject(mContext.getSubject()) .build();
/** * @return a new {@link ClientContext} with values loaded from the alluxio-site properties and * an empty subject. */ public static ClientContext create() { return new ClientContext(null, null); }
/** * Constructs an instance of {@link WorkerUfsManager}. */ public WorkerUfsManager() { mMasterClient = mCloser.register(new FileSystemMasterClient(MasterClientContext .newBuilder(ClientContext.create(ServerConfiguration.global())).build())); }
private void initializeLocalWorker() throws IOException { List<WorkerNetAddress> addresses = getWorkerAddresses(); if (!addresses.isEmpty()) { if (addresses.get(0).getHost().equals(NetworkAddressUtils.getClientHostName(mClientContext .getConf()))) { mLocalWorker = addresses.get(0); } } mLocalWorkerInitialized = true; }
/** * Constructs an instance of {@link JobUfsManager}. */ public JobUfsManager() { mMasterClient = mCloser.register(new FileSystemMasterClient(MasterClientContext .newBuilder(ClientContext.create(ServerConfiguration.global())).build())); }
private String getQualifiedMetricName(String metricName) { try { if (SecurityUtils.isAuthenticationEnabled(mContext.getConf()) && LoginUser.get(mContext.getConf()) != null) { return Metric.getMetricNameWithTags(metricName, CommonMetrics.TAG_USER, LoginUser.get(mContext.getConf()).getName()); } else { return metricName; } } catch (IOException e) { return metricName; } }
/** * Creates a new block master client pool. */ public BlockMasterClientPool() { super(ServerConfiguration.getInt(PropertyKey.WORKER_BLOCK_MASTER_CLIENT_POOL_SIZE)); mClientList = new ConcurrentLinkedQueue<>(); mMasterContext = MasterClientContext .newBuilder(ClientContext.create(ServerConfiguration.global())).build(); }
/** * Creates a file system context with a subject. * * @param ctx the parent subject, set to null if not present */ private FileSystemContext(ClientContext ctx) { mClientContext = ctx; mExecutorService = Executors.newFixedThreadPool(1, ThreadFactoryUtils.build("metrics-master-heartbeat-%d", true)); mClosed = new AtomicBoolean(false); mAppId = ctx.getConf().isSet(PropertyKey.USER_APP_ID) ? ctx.getConf().get(PropertyKey.USER_APP_ID) : IdUtils.createFileSystemContextId(); LOG.info("Created filesystem context with id {}. This ID will be used for identifying info " + "from the client, such as metrics. It can be set manually through the {} property", mAppId, PropertyKey.Name.USER_APP_ID); }
startAlluxioFramework(env); LOG.info("Launched Alluxio cluster, waiting for worker to register with master"); ClientContext ctx = ClientContext.create(sConf); try (final BlockMasterClient client = BlockMasterClient.Factory.create(MasterClientContext.newBuilder(ctx).build())) {
/** * @return an instance of {@link MasterClientContext} */ public MasterClientContext build() { if (mMasterInquireClient == null) { mMasterInquireClient = MasterInquireClient.Factory.create(mContext.getConf()); } return new MasterClientContext(mContext, mMasterInquireClient); } }