@Override public void start() throws Exception { mRegistry.start(false); mLatch.await(); }
@Override public void stop() throws Exception { mRegistry.stop(); mLatch.countDown(); }
@Before public void before() throws Exception { mRegistry = new MasterRegistry(); mClock = new ManualClock(); mExecutorService = Executors.newFixedThreadPool(2, ThreadFactoryUtils.build("TestMetricsMaster-%d", true)); mMetricsMaster = new DefaultMetricsMaster(MasterTestUtils.testMasterContext(), mClock, ExecutorServiceFactories.constantExecutorServiceFactory(mExecutorService)); mRegistry.add(MetricsMaster.class, mMetricsMaster); mRegistry.start(true); }
private void startServices() throws Exception { mRegistry = new MasterRegistry(); JournalSystem journalSystem = JournalTestUtils.createJournalSystem(mJournalFolder.getAbsolutePath()); CoreMasterContext context = MasterTestUtils.testMasterContext(journalSystem); new MetricsMasterFactory().create(mRegistry, context); new BlockMasterFactory().create(mRegistry, context); mFileSystemMaster = new FileSystemMasterFactory().create(mRegistry, context); journalSystem.start(); journalSystem.gainPrimacy(); mRegistry.start(true); mMockJobMasterClient = Mockito.mock(JobMasterClient.class); PowerMockito.mockStatic(JobMasterClient.Factory.class); Mockito.when(JobMasterClient.Factory.create(any(JobMasterClientContext.class))) .thenReturn(mMockJobMasterClient); }
/** * Writes a backup to the specified stream. * * @param os the stream to write to */ public void backup(OutputStream os) throws IOException { int count = 0; GzipCompressorOutputStream zipStream = new GzipCompressorOutputStream(os); for (Master master : mRegistry.getServers()) { Iterator<JournalEntry> it = master.getJournalEntryIterator(); while (it.hasNext()) { it.next().toBuilder().clearSequenceNumber().build().writeDelimitedTo(zipStream); count++; } } // finish() instead of close() since close would close os, which is owned by the caller. zipStream.finish(); LOG.info("Created backup with {} entries", count); }
URI journalLocation = JournalUtils.getJournalLocation(); mJournalSystem = new JournalSystem.Builder().setLocation(journalLocation).build(); mRegistry = new MasterRegistry(); mSafeModeManager = new DefaultSafeModeManager(); mBackupManager = new BackupManager(mRegistry);
@Override public MetricsMaster create(MasterRegistry registry, CoreMasterContext context) { LOG.info("Creating {} ", MetricsMaster.class.getName()); MetricsMaster master = new DefaultMetricsMaster(context); registry.add(MetricsMaster.class, master); return master; } }
/** * Gets the registered class from the master registry. * * @param clazz the class of the master to get * @param <T> the type of the master to get * @return the given master */ public <T extends Master> T getMaster(Class<T> clazz) { return mRegistry.get(clazz); }
/** * Sets up the dependencies before a test runs. */ @Before public void before() throws Exception { mRegistry = new MasterRegistry(); mSafeModeManager = new TestSafeModeManager(); mStartTimeMs = System.currentTimeMillis(); mPort = ServerConfiguration.getInt(PropertyKey.MASTER_RPC_PORT); mMetrics = Lists.newArrayList(); JournalSystem journalSystem = new NoopJournalSystem(); CoreMasterContext masterContext = MasterTestUtils.testMasterContext(); mMetricsMaster = new MetricsMasterFactory().create(mRegistry, masterContext); mClock = new ManualClock(); mExecutorService = Executors.newFixedThreadPool(2, ThreadFactoryUtils.build("TestBlockMaster-%d", true)); mBlockMaster = new DefaultBlockMaster(mMetricsMaster, masterContext, mClock, ExecutorServiceFactories.constantExecutorServiceFactory(mExecutorService)); mRegistry.add(BlockMaster.class, mBlockMaster); mRegistry.start(true); }
/** * Restores master state from the specified backup. * * @param is an input stream to read from the backup */ public void initFromBackup(InputStream is) throws IOException { int count = 0; try (GzipCompressorInputStream gzIn = new GzipCompressorInputStream(is); JournalEntryStreamReader reader = new JournalEntryStreamReader(gzIn)) { List<Master> masters = mRegistry.getServers(); JournalEntry entry; Map<String, Master> mastersByName = Maps.uniqueIndex(masters, Master::getName); while ((entry = reader.readEntry()) != null) { String masterName = JournalEntryAssociation.getMasterForEntry(entry); Master master = mastersByName.get(masterName); master.processJournalEntry(entry); try (JournalContext jc = master.createJournalContext()) { jc.append(entry); count++; } } } LOG.info("Restored {} entries from backup", count); } }
mRegistry = new MasterRegistry(); mSafeModeManager = new DefaultSafeModeManager(); mBackupManager = new BackupManager(mRegistry);
@Override public MetricsMaster create(MasterRegistry registry, MasterContext context) { LOG.info("Creating {} ", MetricsMaster.class.getName()); MetricsMaster master = new DefaultMetricsMaster(context); registry.add(MetricsMaster.class, master); return master; } }
@Override public <T extends Master> T getMaster(Class<T> clazz) { return mRegistry.get(clazz); }
@Before public void before() throws Exception { ServerConfiguration.set(PropertyKey.MASTER_MOUNT_TABLE_ROOT_UFS, mTestFolder.newFolder()); GroupMappingServiceTestUtils.resetCache(); mRegistry = new MasterRegistry(); mRegistry.add(MetricsMaster.class, mMetricsMaster); CoreMasterContext masterContext = MasterTestUtils.testMasterContext(); mMetricsMaster = new MetricsMasterFactory().create(mRegistry, masterContext); new BlockMasterFactory().create(mRegistry, masterContext); mFileSystemMaster = new FileSystemMasterFactory().create(mRegistry, masterContext); mRegistry.start(true); createDirAndFileForTest(); }
@Override public BlockMaster create(MasterRegistry registry, CoreMasterContext context) { LOG.info("Creating {} ", BlockMaster.class.getName()); MetricsMaster metricsMaster = registry.get(MetricsMaster.class); BlockMaster master = new DefaultBlockMaster(metricsMaster, context); registry.add(BlockMaster.class, master); return master; } }
/** * Stops all masters, including block master, fileSystem master and additional masters. */ protected void stopMasters() { try { mRegistry.stop(); } catch (IOException e) { throw new RuntimeException(e); } }
/** * 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); } }
@Before public void before() throws Exception { MasterRegistry registry = new MasterRegistry(); JournalSystem journalSystem = JournalTestUtils.createJournalSystem(mTestFolder); CoreMasterContext context = MasterTestUtils.testMasterContext(journalSystem); new MetricsMasterFactory().create(registry, context); mBlockMaster = new BlockMasterFactory().create(registry, context); InodeDirectoryIdGenerator directoryIdGenerator = new InodeDirectoryIdGenerator(mBlockMaster); UfsManager manager = mock(UfsManager.class); MountTable mountTable = new MountTable(manager, mock(MountInfo.class)); InodeLockManager lockManager = new InodeLockManager(); mInodeStore = context.getInodeStoreFactory() .apply(new InodeStoreArgs(lockManager, ServerConfiguration.global())); mInodeTree = new InodeTree(mInodeStore, mBlockMaster, directoryIdGenerator, mountTable, lockManager); journalSystem.start(); journalSystem.gainPrimacy(); mBlockMaster.start(true); ServerConfiguration.set(PropertyKey.SECURITY_AUTHORIZATION_PERMISSION_ENABLED, "true"); ServerConfiguration .set(PropertyKey.SECURITY_AUTHORIZATION_PERMISSION_SUPERGROUP, "test-supergroup"); mInodeTree.initializeRoot(TEST_OWNER, TEST_GROUP, TEST_MODE, NoopJournalContext.INSTANCE); mMockReplicationHandler = new MockHandler(); mReplicationChecker = new ReplicationChecker(mInodeTree, mBlockMaster, context.getSafeModeManager(), mMockReplicationHandler); }
/** * Starts all masters, including block master, FileSystem master, and additional masters. * * @param isLeader if the Master is leader */ protected void startMasters(boolean isLeader) { try { if (isLeader) { if (ServerConfiguration.isSet(PropertyKey.MASTER_JOURNAL_INIT_FROM_BACKUP)) { AlluxioURI backup = new AlluxioURI(ServerConfiguration.get(PropertyKey.MASTER_JOURNAL_INIT_FROM_BACKUP)); if (mJournalSystem.isEmpty()) { initFromBackup(backup); } else { LOG.info("The journal system is not freshly formatted, skipping restoring backup from " + backup); } } mSafeModeManager.notifyPrimaryMasterStarted(); } mRegistry.start(isLeader); LOG.info("All masters started"); } catch (IOException e) { throw new RuntimeException(e); } }