Search in sources :

Example 46 with ServerContext

use of org.apache.accumulo.server.ServerContext in project accumulo by apache.

the class Manager method onlineTables.

@Override
public Set<TableId> onlineTables() {
    Set<TableId> result = new HashSet<>();
    if (getManagerState() != ManagerState.NORMAL) {
        if (getManagerState() != ManagerState.UNLOAD_METADATA_TABLETS) {
            result.add(MetadataTable.ID);
        }
        if (getManagerState() != ManagerState.UNLOAD_ROOT_TABLET) {
            result.add(RootTable.ID);
        }
        return result;
    }
    ServerContext context = getContext();
    TableManager manager = context.getTableManager();
    for (TableId tableId : context.getTableIdToNameMap().keySet()) {
        TableState state = manager.getTableState(tableId);
        if ((state != null) && (state == TableState.ONLINE)) {
            result.add(tableId);
        }
    }
    return result;
}
Also used : TableId(org.apache.accumulo.core.data.TableId) ServerContext(org.apache.accumulo.server.ServerContext) TableManager(org.apache.accumulo.server.tables.TableManager) HashSet(java.util.HashSet) TableState(org.apache.accumulo.core.manager.state.tables.TableState)

Example 47 with ServerContext

use of org.apache.accumulo.server.ServerContext in project accumulo by apache.

the class CompactorTest method testCompactionInterrupted.

@Test
public void testCompactionInterrupted() throws Exception {
    UUID uuid = UUID.randomUUID();
    Supplier<UUID> supplier = () -> uuid;
    ExternalCompactionId eci = ExternalCompactionId.generate(supplier.get());
    PowerMock.resetAll();
    PowerMock.suppress(PowerMock.methods(Halt.class, "halt"));
    PowerMock.suppress(PowerMock.constructor(AbstractServer.class));
    ServerAddress client = PowerMock.createNiceMock(ServerAddress.class);
    HostAndPort address = HostAndPort.fromString("localhost:10240");
    EasyMock.expect(client.getAddress()).andReturn(address);
    TExternalCompactionJob job = PowerMock.createNiceMock(TExternalCompactionJob.class);
    TKeyExtent extent = PowerMock.createNiceMock(TKeyExtent.class);
    EasyMock.expect(job.isSetExternalCompactionId()).andReturn(true).anyTimes();
    EasyMock.expect(job.getExternalCompactionId()).andReturn(eci.toString()).anyTimes();
    EasyMock.expect(job.getExtent()).andReturn(extent).anyTimes();
    EasyMock.expect(extent.getTable()).andReturn("testTable".getBytes()).anyTimes();
    AccumuloConfiguration conf = PowerMock.createNiceMock(AccumuloConfiguration.class);
    EasyMock.expect(conf.getTimeInMillis(Property.INSTANCE_ZK_TIMEOUT)).andReturn(86400000L);
    ServerContext context = PowerMock.createNiceMock(ServerContext.class);
    EasyMock.expect(context.getConfiguration()).andReturn(conf);
    ZooReaderWriter zrw = PowerMock.createNiceMock(ZooReaderWriter.class);
    ZooKeeper zk = PowerMock.createNiceMock(ZooKeeper.class);
    EasyMock.expect(context.getZooReaderWriter()).andReturn(zrw).anyTimes();
    EasyMock.expect(zrw.getZooKeeper()).andReturn(zk).anyTimes();
    VolumeManagerImpl vm = PowerMock.createNiceMock(VolumeManagerImpl.class);
    EasyMock.expect(context.getVolumeManager()).andReturn(vm);
    vm.close();
    PowerMock.replayAll();
    InterruptedCompactor c = new InterruptedCompactor(supplier, client, job, conf, context, eci);
    c.run();
    PowerMock.verifyAll();
    c.close();
    assertFalse(c.isCompletedCalled());
    assertTrue(c.isFailedCalled());
    assertEquals(TCompactionState.CANCELLED, c.getLatestState());
}
Also used : Halt(org.apache.accumulo.core.util.Halt) ExternalCompactionId(org.apache.accumulo.core.metadata.schema.ExternalCompactionId) ServerAddress(org.apache.accumulo.server.rpc.ServerAddress) ZooReaderWriter(org.apache.accumulo.fate.zookeeper.ZooReaderWriter) VolumeManagerImpl(org.apache.accumulo.server.fs.VolumeManagerImpl) TKeyExtent(org.apache.accumulo.core.dataImpl.thrift.TKeyExtent) HostAndPort(org.apache.accumulo.core.util.HostAndPort) AbstractServer(org.apache.accumulo.server.AbstractServer) ZooKeeper(org.apache.zookeeper.ZooKeeper) ServerContext(org.apache.accumulo.server.ServerContext) UUID(java.util.UUID) TExternalCompactionJob(org.apache.accumulo.core.tabletserver.thrift.TExternalCompactionJob) AccumuloConfiguration(org.apache.accumulo.core.conf.AccumuloConfiguration) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 48 with ServerContext

use of org.apache.accumulo.server.ServerContext in project accumulo by apache.

the class ServerUtilOpts method getServerContext.

public synchronized ServerContext getServerContext() {
    if (context == null) {
        if (getClientConfigFile() == null) {
            context = new ServerContext(SiteConfiguration.auto());
        } else {
            ClientInfo info = ClientInfo.from(getClientProps());
            context = ServerContext.override(SiteConfiguration.auto(), info.getInstanceName(), info.getZooKeepers(), info.getZooKeepersSessionTimeOut());
        }
    }
    return context;
}
Also used : ServerContext(org.apache.accumulo.server.ServerContext) ClientInfo(org.apache.accumulo.core.clientImpl.ClientInfo)

Example 49 with ServerContext

use of org.apache.accumulo.server.ServerContext in project accumulo by apache.

the class Admin method execute.

@SuppressFBWarnings(value = "DM_EXIT", justification = "System.exit okay for CLI tool")
@Override
public void execute(final String[] args) {
    boolean everything;
    AdminOpts opts = new AdminOpts();
    JCommander cl = new JCommander(opts);
    cl.setProgramName("accumulo admin");
    CheckTabletsCommand checkTabletsCommand = new CheckTabletsCommand();
    cl.addCommand("checkTablets", checkTabletsCommand);
    ListInstancesCommand listIntancesOpts = new ListInstancesCommand();
    cl.addCommand("listInstances", listIntancesOpts);
    PingCommand pingCommand = new PingCommand();
    cl.addCommand("ping", pingCommand);
    DumpConfigCommand dumpConfigCommand = new DumpConfigCommand();
    cl.addCommand("dumpConfig", dumpConfigCommand);
    VolumesCommand volumesCommand = new VolumesCommand();
    cl.addCommand("volumes", volumesCommand);
    StopCommand stopOpts = new StopCommand();
    cl.addCommand("stop", stopOpts);
    StopAllCommand stopAllOpts = new StopAllCommand();
    cl.addCommand("stopAll", stopAllOpts);
    StopManagerCommand stopManagerOpts = new StopManagerCommand();
    cl.addCommand("stopManager", stopManagerOpts);
    StopMasterCommand stopMasterOpts = new StopMasterCommand();
    cl.addCommand("stopMaster", stopMasterOpts);
    RandomizeVolumesCommand randomizeVolumesOpts = new RandomizeVolumesCommand();
    cl.addCommand("randomizeVolumes", randomizeVolumesOpts);
    cl.parse(args);
    if (opts.help || cl.getParsedCommand() == null) {
        cl.usage();
        return;
    }
    ServerContext context = opts.getServerContext();
    AccumuloConfiguration conf = context.getConfiguration();
    // Login as the server on secure HDFS
    if (conf.getBoolean(Property.INSTANCE_RPC_SASL_ENABLED)) {
        SecurityUtil.serverLogin(conf);
    }
    try {
        int rc = 0;
        if (cl.getParsedCommand().equals("listInstances")) {
            ListInstances.listInstances(context.getZooKeepers(), listIntancesOpts.printAll, listIntancesOpts.printErrors);
        } else if (cl.getParsedCommand().equals("ping")) {
            if (ping(context, pingCommand.args) != 0)
                rc = 4;
        } else if (cl.getParsedCommand().equals("checkTablets")) {
            System.out.println("\n*** Looking for offline tablets ***\n");
            if (FindOfflineTablets.findOffline(context, checkTabletsCommand.tableName) != 0)
                rc = 5;
            System.out.println("\n*** Looking for missing files ***\n");
            if (checkTabletsCommand.tableName == null) {
                if (RemoveEntriesForMissingFiles.checkAllTables(context, checkTabletsCommand.fixFiles) != 0)
                    rc = 6;
            } else {
                if (RemoveEntriesForMissingFiles.checkTable(context, checkTabletsCommand.tableName, checkTabletsCommand.fixFiles) != 0)
                    rc = 6;
            }
        } else if (cl.getParsedCommand().equals("stop")) {
            stopTabletServer(context, stopOpts.args, opts.force);
        } else if (cl.getParsedCommand().equals("dumpConfig")) {
            printConfig(context, dumpConfigCommand);
        } else if (cl.getParsedCommand().equals("volumes")) {
            ListVolumesUsed.listVolumes(context);
        } else if (cl.getParsedCommand().equals("randomizeVolumes")) {
            System.out.println(RV_DEPRECATION_MSG);
        } else {
            everything = cl.getParsedCommand().equals("stopAll");
            if (everything)
                flushAll(context);
            stopServer(context, everything);
        }
        if (rc != 0)
            System.exit(rc);
    } catch (AccumuloException e) {
        log.error("{}", e.getMessage(), e);
        System.exit(1);
    } catch (AccumuloSecurityException e) {
        log.error("{}", e.getMessage(), e);
        System.exit(2);
    } catch (Exception e) {
        log.error("{}", e.getMessage(), e);
        System.exit(3);
    } finally {
        SingletonManager.setMode(Mode.CLOSED);
    }
}
Also used : AccumuloException(org.apache.accumulo.core.client.AccumuloException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) NamespaceNotFoundException(org.apache.accumulo.core.client.NamespaceNotFoundException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) IOException(java.io.IOException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) ServerContext(org.apache.accumulo.server.ServerContext) JCommander(com.beust.jcommander.JCommander) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) AccumuloConfiguration(org.apache.accumulo.core.conf.AccumuloConfiguration) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 50 with ServerContext

use of org.apache.accumulo.server.ServerContext in project accumulo by apache.

the class ChangeSecret method main.

public static void main(String[] args) throws Exception {
    var siteConfig = SiteConfiguration.auto();
    var hadoopConf = new Configuration();
    Opts opts = new Opts();
    ServerContext context = opts.getServerContext();
    try (var fs = context.getVolumeManager()) {
        ServerDirs serverDirs = new ServerDirs(siteConfig, hadoopConf);
        verifyHdfsWritePermission(serverDirs, fs);
        List<String> argsList = new ArrayList<>(args.length + 2);
        argsList.add("--old");
        argsList.add("--new");
        argsList.addAll(Arrays.asList(args));
        opts.parseArgs(ChangeSecret.class.getName(), args);
        Span span = TraceUtil.startSpan(ChangeSecret.class, "main");
        try (Scope scope = span.makeCurrent()) {
            verifyAccumuloIsDown(context, opts.oldPass);
            final InstanceId newInstanceId = InstanceId.of(UUID.randomUUID());
            updateHdfs(serverDirs, fs, newInstanceId);
            rewriteZooKeeperInstance(context, newInstanceId, opts.oldPass, opts.newPass);
            if (opts.oldPass != null) {
                deleteInstance(context, opts.oldPass);
            }
            System.out.println("New instance id is " + newInstanceId);
            System.out.println("Be sure to put your new secret in accumulo.properties");
        } finally {
            span.end();
        }
    }
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) SiteConfiguration(org.apache.accumulo.core.conf.SiteConfiguration) ServerContext(org.apache.accumulo.server.ServerContext) Scope(io.opentelemetry.context.Scope) ServerUtilOpts(org.apache.accumulo.server.cli.ServerUtilOpts) InstanceId(org.apache.accumulo.core.data.InstanceId) ArrayList(java.util.ArrayList) ServerDirs(org.apache.accumulo.server.ServerDirs) Span(io.opentelemetry.api.trace.Span)

Aggregations

ServerContext (org.apache.accumulo.server.ServerContext)87 Test (org.junit.Test)41 ZooReaderWriter (org.apache.accumulo.fate.zookeeper.ZooReaderWriter)18 AccumuloClient (org.apache.accumulo.core.client.AccumuloClient)15 AccumuloConfiguration (org.apache.accumulo.core.conf.AccumuloConfiguration)15 TServerInstance (org.apache.accumulo.core.metadata.TServerInstance)15 HostAndPort (org.apache.accumulo.core.util.HostAndPort)15 Path (org.apache.hadoop.fs.Path)15 ArrayList (java.util.ArrayList)14 KeyExtent (org.apache.accumulo.core.dataImpl.KeyExtent)14 VolumeManager (org.apache.accumulo.server.fs.VolumeManager)13 KeeperException (org.apache.zookeeper.KeeperException)13 ServerAddress (org.apache.accumulo.server.rpc.ServerAddress)12 TableId (org.apache.accumulo.core.data.TableId)11 LiveTServerSet (org.apache.accumulo.server.manager.LiveTServerSet)11 Value (org.apache.accumulo.core.data.Value)10 IOException (java.io.IOException)9 UUID (java.util.UUID)9 ConfigurationCopy (org.apache.accumulo.core.conf.ConfigurationCopy)9 Client (org.apache.accumulo.core.tabletserver.thrift.TabletClientService.Client)9