Search in sources :

Example 1 with Master

use of org.apache.accumulo.master.Master in project accumulo by apache.

the class ReplicationOperationsImplIT method getReplicationOperations.

/**
 * Spoof out the Master so we can call the implementation without starting a full instance.
 */
private ReplicationOperationsImpl getReplicationOperations() throws Exception {
    Master master = EasyMock.createMock(Master.class);
    EasyMock.expect(master.getConnector()).andReturn(conn).anyTimes();
    EasyMock.expect(master.getInstance()).andReturn(inst).anyTimes();
    EasyMock.replay(master);
    final MasterClientServiceHandler mcsh = new MasterClientServiceHandler(master) {

        @Override
        protected Table.ID getTableId(Instance inst, String tableName) throws ThriftTableOperationException {
            try {
                return Table.ID.of(conn.tableOperations().tableIdMap().get(tableName));
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    };
    ClientContext context = new ClientContext(inst, new Credentials("root", new PasswordToken(ROOT_PASSWORD)), getClientConfig());
    return new ReplicationOperationsImpl(context) {

        @Override
        protected boolean getMasterDrain(final TInfo tinfo, final TCredentials rpcCreds, final String tableName, final Set<String> wals) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
            try {
                return mcsh.drainReplicationTable(tinfo, rpcCreds, tableName, wals);
            } catch (TException e) {
                throw new RuntimeException(e);
            }
        }
    };
}
Also used : TInfo(org.apache.accumulo.core.trace.thrift.TInfo) TException(org.apache.thrift.TException) MetadataTable(org.apache.accumulo.core.metadata.MetadataTable) Table(org.apache.accumulo.core.client.impl.Table) ReplicationTable(org.apache.accumulo.core.replication.ReplicationTable) Set(java.util.Set) Instance(org.apache.accumulo.core.client.Instance) TCredentials(org.apache.accumulo.core.security.thrift.TCredentials) ClientContext(org.apache.accumulo.core.client.impl.ClientContext) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) TException(org.apache.thrift.TException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) ThriftTableOperationException(org.apache.accumulo.core.client.impl.thrift.ThriftTableOperationException) Master(org.apache.accumulo.master.Master) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) MasterClientServiceHandler(org.apache.accumulo.master.MasterClientServiceHandler) TCredentials(org.apache.accumulo.core.security.thrift.TCredentials) Credentials(org.apache.accumulo.core.client.impl.Credentials) ReplicationOperationsImpl(org.apache.accumulo.core.client.impl.ReplicationOperationsImpl)

Example 2 with Master

use of org.apache.accumulo.master.Master in project accumulo by apache.

the class FateAdmin method main.

public static void main(String[] args) throws Exception {
    Help opts = new Help();
    JCommander jc = new JCommander(opts);
    jc.setProgramName(FateAdmin.class.getName());
    LinkedHashMap<String, TxOpts> txOpts = new LinkedHashMap<>(2);
    txOpts.put("fail", new FailOpts());
    txOpts.put("delete", new DeleteOpts());
    for (Entry<String, TxOpts> entry : txOpts.entrySet()) {
        jc.addCommand(entry.getKey(), entry.getValue());
    }
    jc.addCommand("print", new PrintOpts());
    jc.parse(args);
    if (opts.help || jc.getParsedCommand() == null) {
        jc.usage();
        System.exit(1);
    }
    System.err.printf("This tool has been deprecated%nFATE administration now available within 'accumulo shell'%n$ fate fail <txid>... | delete <txid>... | print [<txid>...]%n%n");
    AdminUtil<Master> admin = new AdminUtil<>();
    Instance instance = HdfsZooInstance.getInstance();
    String path = ZooUtil.getRoot(instance) + Constants.ZFATE;
    String masterPath = ZooUtil.getRoot(instance) + Constants.ZMASTER_LOCK;
    IZooReaderWriter zk = ZooReaderWriter.getInstance();
    ZooStore<Master> zs = new ZooStore<>(path, zk);
    if (jc.getParsedCommand().equals("fail")) {
        for (String txid : txOpts.get(jc.getParsedCommand()).txids) {
            if (!admin.prepFail(zs, zk, masterPath, txid)) {
                System.exit(1);
            }
        }
    } else if (jc.getParsedCommand().equals("delete")) {
        for (String txid : txOpts.get(jc.getParsedCommand()).txids) {
            if (!admin.prepDelete(zs, zk, masterPath, txid)) {
                System.exit(1);
            }
            admin.deleteLocks(zs, zk, ZooUtil.getRoot(instance) + Constants.ZTABLE_LOCKS, txid);
        }
    } else if (jc.getParsedCommand().equals("print")) {
        admin.print(new ReadOnlyStore<>(zs), zk, ZooUtil.getRoot(instance) + Constants.ZTABLE_LOCKS);
    }
}
Also used : Help(org.apache.accumulo.core.cli.Help) Instance(org.apache.accumulo.core.client.Instance) HdfsZooInstance(org.apache.accumulo.server.client.HdfsZooInstance) ZooStore(org.apache.accumulo.fate.ZooStore) LinkedHashMap(java.util.LinkedHashMap) Master(org.apache.accumulo.master.Master) AdminUtil(org.apache.accumulo.fate.AdminUtil) JCommander(com.beust.jcommander.JCommander) IZooReaderWriter(org.apache.accumulo.fate.zookeeper.IZooReaderWriter)

Example 3 with Master

use of org.apache.accumulo.master.Master in project accumulo by apache.

the class Metrics2ReplicationMetricsTest method testAddReplicationQueueTimeMetrics.

@Test
public void testAddReplicationQueueTimeMetrics() throws Exception {
    Master master = EasyMock.createMock(Master.class);
    MetricsSystem system = EasyMock.createMock(MetricsSystem.class);
    VolumeManager fileSystem = EasyMock.createMock(VolumeManager.class);
    ReplicationUtil util = EasyMock.createMock(ReplicationUtil.class);
    MutableStat stat = EasyMock.createMock(MutableStat.class);
    MutableQuantiles quantiles = EasyMock.createMock(MutableQuantiles.class);
    Path path1 = new Path("hdfs://localhost:9000/accumulo/wal/file1");
    Path path2 = new Path("hdfs://localhost:9000/accumulo/wal/file2");
    // First call will initialize the map of paths to modification time
    EasyMock.expect(util.getPendingReplicationPaths()).andReturn(ImmutableSet.of(path1, path2));
    EasyMock.expect(master.getFileSystem()).andReturn(fileSystem);
    EasyMock.expect(fileSystem.getFileStatus(path1)).andReturn(createStatus(100));
    EasyMock.expect(master.getFileSystem()).andReturn(fileSystem);
    EasyMock.expect(fileSystem.getFileStatus(path2)).andReturn(createStatus(200));
    // Second call will recognize the missing path1 and add the latency stat
    EasyMock.expect(util.getPendingReplicationPaths()).andReturn(ImmutableSet.of(path2));
    // Expect a call to reset the min/max
    stat.resetMinMax();
    EasyMock.expectLastCall();
    // Expect the calls of adding the stats
    quantiles.add(currentTime - 100);
    EasyMock.expectLastCall();
    stat.add(currentTime - 100);
    EasyMock.expectLastCall();
    EasyMock.replay(master, system, fileSystem, util, stat, quantiles);
    Metrics2ReplicationMetrics metrics = new TestMetrics2ReplicationMetrics(master, system);
    // Inject our mock objects
    replaceField(metrics, "replicationUtil", util);
    replaceField(metrics, "replicationQueueTimeQuantiles", quantiles);
    replaceField(metrics, "replicationQueueTimeStat", stat);
    // Two calls to this will initialize the map and then add metrics
    metrics.addReplicationQueueTimeMetrics();
    metrics.addReplicationQueueTimeMetrics();
    EasyMock.verify(master, system, fileSystem, util, stat, quantiles);
}
Also used : Master(org.apache.accumulo.master.Master) Path(org.apache.hadoop.fs.Path) VolumeManager(org.apache.accumulo.server.fs.VolumeManager) MutableQuantiles(org.apache.hadoop.metrics2.lib.MutableQuantiles) ReplicationUtil(org.apache.accumulo.server.replication.ReplicationUtil) MutableStat(org.apache.hadoop.metrics2.lib.MutableStat) MetricsSystem(org.apache.hadoop.metrics2.MetricsSystem) Test(org.junit.Test)

Example 4 with Master

use of org.apache.accumulo.master.Master in project accumulo by apache.

the class ImportTableTest method testTabletDir.

@Test
public void testTabletDir() {
    Master master = EasyMock.createMock(Master.class);
    VolumeManager volumeManager = EasyMock.createMock(VolumeManager.class);
    ImportedTableInfo iti = new ImportedTableInfo();
    iti.tableId = Table.ID.of("5");
    // Different volumes with different paths
    String[] tableDirs = new String[] { "hdfs://nn1:8020/apps/accumulo1/tables", "hdfs://nn2:8020/applications/accumulo/tables" };
    // This needs to be unique WRT the importtable command
    String tabletDir = "/c-00000001";
    EasyMock.expect(master.getFileSystem()).andReturn(volumeManager);
    // Choose the 2nd element
    VolumeChooserEnvironment chooserEnv = new VolumeChooserEnvironment(iti.tableId);
    EasyMock.expect(volumeManager.choose(EasyMock.eq(chooserEnv), EasyMock.eq(tableDirs))).andReturn(tableDirs[1]);
    EasyMock.replay(master, volumeManager);
    PopulateMetadataTable pmt = new PopulateMetadataTable(iti);
    Assert.assertEquals(tableDirs[1] + "/" + iti.tableId + "/" + tabletDir, pmt.getClonedTabletDir(master, tableDirs, tabletDir));
    EasyMock.verify(master, volumeManager);
}
Also used : Master(org.apache.accumulo.master.Master) VolumeManager(org.apache.accumulo.server.fs.VolumeManager) VolumeChooserEnvironment(org.apache.accumulo.server.fs.VolumeChooserEnvironment) Test(org.junit.Test)

Example 5 with Master

use of org.apache.accumulo.master.Master in project accumulo by apache.

the class ShutdownTServerTest method testSingleShutdown.

@Test
public void testSingleShutdown() throws Exception {
    final TServerInstance tserver = EasyMock.createMock(TServerInstance.class);
    final boolean force = false;
    final ShutdownTServer op = new ShutdownTServer(tserver, force);
    final Master master = EasyMock.createMock(Master.class);
    final long tid = 1l;
    final TServerConnection tserverCnxn = EasyMock.createMock(TServerConnection.class);
    final TabletServerStatus status = new TabletServerStatus();
    status.tableMap = new HashMap<>();
    // Put in a table info record, don't care what
    status.tableMap.put("a_table", new TableInfo());
    master.shutdownTServer(tserver);
    EasyMock.expectLastCall().once();
    EasyMock.expect(master.onlineTabletServers()).andReturn(Collections.singleton(tserver));
    EasyMock.expect(master.getConnection(tserver)).andReturn(tserverCnxn);
    EasyMock.expect(tserverCnxn.getTableMap(false)).andReturn(status);
    EasyMock.replay(tserver, tserverCnxn, master);
    // FATE op is not ready
    long wait = op.isReady(tid, master);
    assertTrue("Expected wait to be greater than 0", wait > 0);
    EasyMock.verify(tserver, tserverCnxn, master);
    // Reset the mocks
    EasyMock.reset(tserver, tserverCnxn, master);
    // The same as above, but should not expect call shutdownTServer on master again
    EasyMock.expect(master.onlineTabletServers()).andReturn(Collections.singleton(tserver));
    EasyMock.expect(master.getConnection(tserver)).andReturn(tserverCnxn);
    EasyMock.expect(tserverCnxn.getTableMap(false)).andReturn(status);
    EasyMock.replay(tserver, tserverCnxn, master);
    // FATE op is not ready
    wait = op.isReady(tid, master);
    assertTrue("Expected wait to be greater than 0", wait > 0);
    EasyMock.verify(tserver, tserverCnxn, master);
}
Also used : Master(org.apache.accumulo.master.Master) TServerConnection(org.apache.accumulo.server.master.LiveTServerSet.TServerConnection) TableInfo(org.apache.accumulo.core.master.thrift.TableInfo) TServerInstance(org.apache.accumulo.server.master.state.TServerInstance) ShutdownTServer(org.apache.accumulo.master.tserverOps.ShutdownTServer) TabletServerStatus(org.apache.accumulo.core.master.thrift.TabletServerStatus) Test(org.junit.Test)

Aggregations

Master (org.apache.accumulo.master.Master)8 Test (org.junit.Test)6 Instance (org.apache.accumulo.core.client.Instance)5 TServerInstance (org.apache.accumulo.server.master.state.TServerInstance)4 ZooReader (org.apache.accumulo.fate.zookeeper.ZooReader)3 VolumeManager (org.apache.accumulo.server.fs.VolumeManager)2 JCommander (com.beust.jcommander.JCommander)1 LinkedHashMap (java.util.LinkedHashMap)1 Set (java.util.Set)1 TreeSet (java.util.TreeSet)1 Help (org.apache.accumulo.core.cli.Help)1 AccumuloException (org.apache.accumulo.core.client.AccumuloException)1 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)1 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)1 ClientContext (org.apache.accumulo.core.client.impl.ClientContext)1 Credentials (org.apache.accumulo.core.client.impl.Credentials)1 ReplicationOperationsImpl (org.apache.accumulo.core.client.impl.ReplicationOperationsImpl)1 Table (org.apache.accumulo.core.client.impl.Table)1 ThriftTableOperationException (org.apache.accumulo.core.client.impl.thrift.ThriftTableOperationException)1 PasswordToken (org.apache.accumulo.core.client.security.tokens.PasswordToken)1