/** * Creates a new local Alluxio master with a isolated port. * * @param workDirectory Alluxio work directory, this method will create it if it doesn't exist yet * @return the created Alluxio master */ public static LocalAlluxioMaster create(final String workDirectory) throws IOException { if (!Files.isDirectory(Paths.get(workDirectory))) { Files.createDirectory(Paths.get(workDirectory)); } return new LocalAlluxioMaster(null, null); }
@Override public FileSystem getClient(FileSystemContext context) throws IOException { return mMaster.getClient(context); }
/** * Iterates over the masters in the order of master creation, stops the first standby master. * * @return true if a standby master is successfully stopped, otherwise, false */ public boolean stopStandby() { for (int k = 0; k < mNumOfMasters; k++) { if (!mMasters.get(k).isServing()) { try { LOG.info("master {} is a standby. stopping it...", k); mMasters.get(k).stop(); LOG.info("master {} stopped.", k); } catch (Exception e) { LOG.error(e.getMessage(), e); return false; } return true; } } return false; }
/** * Creates a new local Alluxio master with an isolated work directory and port. * * @return an instance of Alluxio master */ public static LocalAlluxioMaster create() throws IOException { String workDirectory = uniquePath(); FileUtils.deletePathRecursively(workDirectory); ServerConfiguration.set(PropertyKey.WORK_DIR, workDirectory); return create(workDirectory, null, null); }
final LocalAlluxioMaster master = LocalAlluxioMaster.create(mWorkDirectory); master.start(); LOG.info("master NO.{} started, isServing: {}, address: {}", k, master.isServing(), master.getAddress()); mMasters.add(master); while (!hasLeader) { for (int i = 0; i < mMasters.size(); i++) { if (mMasters.get(i).isServing()) { LOG.info("master NO.{} is selected as leader. address: {}", i, mMasters.get(i).getAddress()); hasLeader = true; break; String.valueOf(getLocalAlluxioMaster().getRpcLocalPort()));
/** * @return the URI of the master */ public String getUri() { return Constants.HEADER + mHostname + ":" + getRpcLocalPort(); }
@Override public LocalAlluxioMaster getLocalAlluxioMaster() { for (LocalAlluxioMaster master : mMasters) { // Return the leader master, if possible. if (master.isServing()) { return master; } } return mMasters.get(0); }
@Override public void stopMasters() throws Exception { mMaster.stop(); } }
/** * @return the URI of the master */ public String getMasterURI() { return mMaster.getUri(); }
/** * 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"); }
final LocalAlluxioMaster master = LocalAlluxioMaster.create(mWorkDirectory); master.start(); LOG.info("master NO.{} started, isServing: {}, address: {}", k, master.isServing(), master.getAddress()); mMasters.add(master); while (!hasLeader) { for (int i = 0; i < mMasters.size(); i++) { if (mMasters.get(i).isServing()) { LOG.info("master NO.{} is selected as leader. address: {}", i, mMasters.get(i).getAddress()); hasLeader = true; break; String.valueOf(getLocalAlluxioMaster().getRpcLocalPort()));
/** * Iterates over the masters in the order of master creation, stops the leader master. * * @return true if the leader master is successfully stopped, false otherwise */ public boolean stopLeader() { for (int k = 0; k < mNumOfMasters; k++) { if (mMasters.get(k).isServing()) { try { LOG.info("master {} is the leader. stopping it...", k); mMasters.get(k).stop(); LOG.info("master {} stopped.", k); } catch (Exception e) { LOG.error(e.getMessage(), e); return false; } return true; } } return false; }
/** * Creates a new local Alluxio master with an isolated work directory and port. * * @return an instance of Alluxio master */ public static LocalAlluxioMaster create() throws IOException { String workDirectory = uniquePath(); FileUtils.deletePathRecursively(workDirectory); Configuration.set(PropertyKey.WORK_DIR, workDirectory); return create(workDirectory); }
/** * @return the RPC port of the master */ public int getMasterRpcPort() { return mMaster.getRpcLocalPort(); }
/** * @return index of leader master in {@link #mMasters}, or -1 if there is no leader temporarily */ public int getLeaderIndex() { for (int i = 0; i < mNumOfMasters; i++) { if (mMasters.get(i).isServing()) { return i; } } return -1; }
@Override public void stopMasters() throws Exception { for (int k = 0; k < mNumOfMasters; k++) { mMasters.get(k).stop(); } } }
@Override public String get() { return getUri(); } };
/** * 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"); }
/** * Iterates over the masters in the order of master creation, stops the leader master. * * @return true if the leader master is successfully stopped, false otherwise */ public boolean stopLeader() { for (int k = 0; k < mNumOfMasters; k++) { if (mMasters.get(k).isServing()) { try { LOG.info("master {} is the leader. stopping it...", k); mMasters.get(k).stop(); LOG.info("master {} stopped.", k); } catch (Exception e) { LOG.error(e.getMessage(), e); return false; } return true; } } return false; }