Search in sources :

Example 41 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 42 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 43 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)

Example 44 with ServerContext

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

the class ECAdmin method execute.

@SuppressFBWarnings(value = "DM_EXIT", justification = "System.exit okay for CLI tool")
@Override
public void execute(final String[] args) {
    ServerUtilOpts opts = new ServerUtilOpts();
    JCommander cl = new JCommander(opts);
    cl.setProgramName("accumulo ec-admin");
    CancelCommand cancelOps = new CancelCommand();
    cl.addCommand("cancel", cancelOps);
    ListCompactorsCommand listCompactorsOpts = new ListCompactorsCommand();
    cl.addCommand("listCompactors", listCompactorsOpts);
    RunningCommand runningOpts = new RunningCommand();
    cl.addCommand("running", runningOpts);
    cl.parse(args);
    if (opts.help || cl.getParsedCommand() == null) {
        cl.usage();
        return;
    }
    ServerContext context = opts.getServerContext();
    try {
        if (cl.getParsedCommand().equals("listCompactors")) {
            listCompactorsByQueue(context);
        } else if (cl.getParsedCommand().equals("cancel")) {
            cancelCompaction(context, cancelOps.ecid);
        } else if (cl.getParsedCommand().equals("running")) {
            runningCompactions(context, runningOpts.details);
        } else {
            log.error("Unknown command {}", cl.getParsedCommand());
            cl.usage();
            System.exit(1);
        }
    } catch (Exception e) {
        log.error("{}", e.getMessage(), e);
        System.exit(1);
    } finally {
        SingletonManager.setMode(Mode.CLOSED);
    }
}
Also used : ServerContext(org.apache.accumulo.server.ServerContext) JCommander(com.beust.jcommander.JCommander) ServerUtilOpts(org.apache.accumulo.server.cli.ServerUtilOpts) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 45 with ServerContext

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

the class LoginProperties method execute.

@Override
public void execute(String[] args) throws Exception {
    try (var context = new ServerContext(SiteConfiguration.auto())) {
        AccumuloConfiguration config = context.getConfiguration();
        Authenticator authenticator = ClassLoaderUtil.loadClass(config.get(Property.INSTANCE_SECURITY_AUTHENTICATOR), Authenticator.class).getDeclaredConstructor().newInstance();
        System.out.println("Supported token types for " + authenticator.getClass().getName() + " are : ");
        for (Class<? extends AuthenticationToken> tokenType : authenticator.getSupportedTokenTypes()) {
            System.out.println("\t" + tokenType.getName() + ", which accepts the following properties : ");
            for (TokenProperty tokenProperty : tokenType.getDeclaredConstructor().newInstance().getProperties()) {
                System.out.println("\t\t" + tokenProperty);
            }
            System.out.println();
        }
    }
}
Also used : ServerContext(org.apache.accumulo.server.ServerContext) TokenProperty(org.apache.accumulo.core.client.security.tokens.AuthenticationToken.TokenProperty) Authenticator(org.apache.accumulo.server.security.handler.Authenticator) AccumuloConfiguration(org.apache.accumulo.core.conf.AccumuloConfiguration)

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