/** * @return the externally resolvable address of the master */ public InetSocketAddress getAddress() { return mMasterProcess.getRpcAddress(); }
/** * Constructs a new {@link AlluxioMasterRestServiceHandler}. * * @param context context for the servlet */ public AlluxioMasterRestServiceHandler(@Context ServletContext context) { // Poor man's dependency injection through the Jersey application scope. mMasterProcess = (AlluxioMasterProcess) context .getAttribute(MasterWebServer.ALLUXIO_MASTER_SERVLET_RESOURCE_KEY); mBlockMaster = mMasterProcess.getMaster(BlockMaster.class); mFileSystemMaster = mMasterProcess.getMaster(FileSystemMaster.class); mMetaMaster = mMasterProcess.getMaster(MetaMaster.class); mFsClient = (FileSystem) context .getAttribute(MasterWebServer.ALLUXIO_FILESYSTEM_CLIENT_RESOURCE_KEY); }
/** * @summary get the start time of the master in milliseconds * @return the response object * @deprecated since version 1.4 and will be removed in version 2.0 * @see #getInfo(Boolean) */ @GET @Path(GET_START_TIME_MS) @ReturnType("java.lang.Long") @Deprecated public Response getStartTimeMs() { return RestUtils.call(() -> mMasterProcess.getStartTimeMs(), ServerConfiguration.global()); }
@Override public void stop() throws Exception { if (isServing()) { stopServing(); stopMasters(); mJournalSystem.stop(); } }
/** * @summary get the Alluxio master information * @param rawConfiguration if it's true, raw configuration values are returned, * otherwise, they are looked up; if it's not provided in URL queries, then * it is null, which means false. * @return the response object */ @GET @Path(GET_INFO) @ReturnType("alluxio.wire.AlluxioMasterInfo") public Response getInfo(@QueryParam(QUERY_RAW_CONFIGURATION) final Boolean rawConfiguration) { // TODO(jiri): Add a mechanism for retrieving only a subset of the fields. return RestUtils.call(() -> { boolean rawConfig = false; if (rawConfiguration != null) { rawConfig = rawConfiguration; } return new AlluxioMasterInfo().setCapacity(getCapacityInternal()) .setConfiguration(getConfigurationInternal(rawConfig)) .setLostWorkers(mBlockMaster.getLostWorkersInfoList()).setMetrics(getMetricsInternal()) .setMountPoints(getMountPointsInternal()) .setRpcAddress(mMasterProcess.getRpcAddress().toString()) .setStartTimeMs(mMasterProcess.getStartTimeMs()) .setStartupConsistencyCheck(getStartupConsistencyCheckInternal()) .setTierCapacity(getTierCapacityInternal()).setUfsCapacity(getUfsCapacityInternal()) .setUptimeMs(mMasterProcess.getUptimeMs()).setVersion(RuntimeConstants.VERSION) .setWorkers(mBlockMaster.getWorkerInfoList()); }, ServerConfiguration.global()); }
@Override public void stop() throws Exception { super.stop(); if (mLeaderSelector != null) { mLeaderSelector.stop(); } }
/** * @return true if the master is serving, false otherwise */ public boolean isServing() { return mMasterProcess.isServing(); }
/** * @summary get the uptime of the master in milliseconds * @return the response object * @deprecated since version 1.4 and will be removed in version 2.0 * @see #getInfo(Boolean) */ @GET @Path(GET_UPTIME_MS) @ReturnType("java.lang.Long") @Deprecated public Response getUptimeMs() { return RestUtils.call(() -> mMasterProcess.getUptimeMs(), ServerConfiguration.global()); }
/** * Starts the gRPC server. The AlluxioMaster registers the Services of registered * {@link Master}s and meta services. */ protected void startServingRPCServer() { // TODO(ggezer) Executor threads not reused until thread capacity is hit. // ExecutorService executorService = Executors.newFixedThreadPool(mMaxWorkerThreads); try { SocketAddress bindAddress = getRpcAddressFromBindSocket(); LOG.info("Starting gRPC server on address {}", bindAddress); GrpcServerBuilder serverBuilder = GrpcServerBuilder.forAddress(bindAddress, ServerConfiguration.global()); for (Master master : mRegistry.getServers()) { registerServices(serverBuilder, master.getServices()); } mGrpcServer = serverBuilder.build().start(); mSafeModeManager.notifyRpcServerStarted(); LOG.info("Started gRPC server on address {}", bindAddress); // Wait until the server is shut down. mGrpcServer.awaitTermination(); } catch (IOException e) { throw new RuntimeException(e); } }
/** * Creates a new {@link AlluxioMasterProcess}. * * @param rpcBindSocket the socket whose address the rpc server will eventually bind to * @param webBindSocket the socket whose address the web server will eventually bind to * @return a new instance of {@link MasterProcess} using the given sockets for the master */ public static AlluxioMasterProcess create(ServerSocket rpcBindSocket, ServerSocket webBindSocket) { URI journalLocation = JournalUtils.getJournalLocation(); JournalSystem journalSystem = new JournalSystem.Builder().setLocation(journalLocation).build(); if (ServerConfiguration.getBoolean(PropertyKey.ZOOKEEPER_ENABLED)) { Preconditions.checkState(!(journalSystem instanceof RaftJournalSystem), "Raft journal cannot be used with Zookeeper enabled"); PrimarySelector primarySelector = PrimarySelector.Factory.createZkPrimarySelector(); return new FaultTolerantAlluxioMasterProcess(journalSystem, primarySelector, rpcBindSocket, webBindSocket); } else if (journalSystem instanceof RaftJournalSystem) { PrimarySelector primarySelector = ((RaftJournalSystem) journalSystem).getPrimarySelector(); return new FaultTolerantAlluxioMasterProcess(journalSystem, primarySelector, rpcBindSocket, webBindSocket); } return new AlluxioMasterProcess(journalSystem, rpcBindSocket, webBindSocket); }
/** * Starts serving web ui server, resetting master web port, adding the metrics servlet to the web * server and starting web ui. */ protected void startServingWebServer() { try { mWebServer = new MasterWebServer(ServiceType.MASTER_WEB.getServiceName(), getWebAddressFromBindSocket(), this); // reset master web port // Add the metrics servlet to the web server. mWebServer.addHandler(mMetricsServlet.getHandler()); // Add the prometheus metrics servlet to the web server. mWebServer.addHandler(mPMetricsServlet.getHandler()); // start web ui mWebServer.start(); } catch (IOException e) { throw new RuntimeException(e); } }
@Override public void stop() throws Exception { if (isServing()) { stopServing(); stopMasters(); mJournalSystem.stop(); } }
/** * Stops the master processes and cleans up client connections. */ public void stop() throws Exception { if (mSecondaryMasterThread != null) { mSecondaryMaster.stop(); while (mSecondaryMasterThread.isAlive()) { LOG.info("Stopping thread {}.", mSecondaryMasterThread.getName()); mSecondaryMasterThread.interrupt(); mSecondaryMasterThread.join(1000); } mSecondaryMasterThread = null; } if (mMasterThread != null) { mMasterProcess.stop(); while (mMasterThread.isAlive()) { LOG.info("Stopping thread {}.", mMasterThread.getName()); mMasterThread.interrupt(); mMasterThread.join(1000); } mMasterThread = null; } clearClients(); System.clearProperty("alluxio.web.resources"); System.clearProperty("alluxio.master.min.worker.threads"); }
/** * Stops serving, trying stop RPC server and web ui server and letting {@link MetricsSystem} stop * all the sinks. */ protected void stopServing() throws Exception { if (isServing()) { if (!mGrpcServer.shutdown()) { LOG.warn("RPC Server shutdown timed out."); } } if (mJvmPauseMonitor != null) { mJvmPauseMonitor.stop(); } if (mWebServer != null) { mWebServer.stop(); mWebServer = null; } MetricsSystem.stopSinks(); }
@Test public void getUptimeMs() { when(mMasterProcess.getUptimeMs()).thenReturn(100L); Response response = mHandler.getUptimeMs(); try { assertNotNull("Response must be not null!", response); assertNotNull("Response must have a entry!", response.getEntity()); assertEquals("Entry must be a Long!", Long.class, response.getEntity().getClass()); Long entry = (Long) response.getEntity(); assertEquals(100L, entry.longValue()); } finally { response.close(); } }
/** * @return a new instance of {@link MasterProcess} */ public static MasterProcess create() { URI journalLocation = JournalUtils.getJournalLocation(); JournalSystem journalSystem = new JournalSystem.Builder().setLocation(journalLocation).build(); if (Configuration.getBoolean(PropertyKey.ZOOKEEPER_ENABLED)) { PrimarySelector primarySelector = PrimarySelector.Factory.createZkPrimarySelector(); return new FaultTolerantAlluxioMasterProcess(journalSystem, primarySelector); } return new AlluxioMasterProcess(journalSystem); }
/** * Gets the actual port that the RPC service is listening on. * * @return the RPC local port */ public int getRpcLocalPort() { return mMasterProcess.getRpcAddress().getPort(); }
/** * Constructs a new {@link BlockMasterClientRestServiceHandler}. * * @param context context for the servlet */ public BlockMasterClientRestServiceHandler(@Context ServletContext context) { // Poor man's dependency injection through the Jersey application scope. mBlockMaster = ((AlluxioMasterProcess) context .getAttribute(MasterWebServer.ALLUXIO_MASTER_SERVLET_RESOURCE_KEY)) .getMaster(BlockMaster.class); }
@Override public void stop() throws Exception { super.stop(); if (mLeaderSelector != null) { mLeaderSelector.stop(); } }
@Test public void getStartTimeMs() { when(mMasterProcess.getStartTimeMs()).thenReturn(100L); Response response = mHandler.getStartTimeMs(); try { assertNotNull("Response must be not null!", response); assertNotNull("Response must have a entry!", response.getEntity()); assertEquals("Entry must be a Long!", Long.class, response.getEntity().getClass()); Long entry = (Long) response.getEntity(); assertEquals(100L, entry.longValue()); } finally { response.close(); } }