use of org.apache.accumulo.core.conf.AccumuloConfiguration in project accumulo by apache.
the class ServerContext method setupCrypto.
/**
* Should only be called by the Tablet server
*/
public synchronized void setupCrypto() throws CryptoService.CryptoException {
if (cryptoService != null) {
throw new CryptoService.CryptoException("Crypto Service " + cryptoService.getClass().getName() + " already exists and cannot be setup again");
}
AccumuloConfiguration acuConf = getConfiguration();
cryptoService = CryptoServiceFactory.newInstance(acuConf, ClassloaderType.ACCUMULO);
}
use of org.apache.accumulo.core.conf.AccumuloConfiguration in project accumulo by apache.
the class MiniAccumuloClusterImpl method start.
/**
* Starts Accumulo and Zookeeper processes. Can only be called once.
*/
@SuppressFBWarnings(value = "UNENCRYPTED_SOCKET", justification = "insecure socket used for reservation")
@Override
public synchronized void start() throws IOException, InterruptedException {
if (config.useMiniDFS() && miniDFS == null) {
throw new IllegalStateException("Cannot restart mini when using miniDFS");
}
MiniAccumuloClusterControl control = getClusterControl();
if (config.useExistingInstance()) {
AccumuloConfiguration acuConf = config.getAccumuloConfiguration();
Configuration hadoopConf = config.getHadoopConfiguration();
ServerDirs serverDirs = new ServerDirs(acuConf, hadoopConf);
ConfigurationCopy cc = new ConfigurationCopy(acuConf);
Path instanceIdPath;
try (var fs = getServerContext().getVolumeManager()) {
instanceIdPath = serverDirs.getInstanceIdLocation(fs.getFirst());
} catch (IOException e) {
throw new RuntimeException(e);
}
InstanceId instanceIdFromFile = VolumeManager.getInstanceIDFromHdfs(instanceIdPath, hadoopConf);
ZooReaderWriter zrw = new ZooReaderWriter(cc.get(Property.INSTANCE_ZK_HOST), (int) cc.getTimeInMillis(Property.INSTANCE_ZK_TIMEOUT), cc.get(Property.INSTANCE_SECRET));
String rootPath = ZooUtil.getRoot(instanceIdFromFile);
String instanceName = null;
try {
for (String name : zrw.getChildren(Constants.ZROOT + Constants.ZINSTANCES)) {
String instanceNamePath = Constants.ZROOT + Constants.ZINSTANCES + "/" + name;
byte[] bytes = zrw.getData(instanceNamePath);
InstanceId iid = InstanceId.of(new String(bytes, UTF_8));
if (iid.equals(instanceIdFromFile)) {
instanceName = name;
}
}
} catch (KeeperException e) {
throw new RuntimeException("Unable to read instance name from zookeeper.", e);
}
if (instanceName == null) {
throw new RuntimeException("Unable to read instance name from zookeeper.");
}
config.setInstanceName(instanceName);
if (!AccumuloStatus.isAccumuloOffline(zrw, rootPath)) {
throw new RuntimeException("The Accumulo instance being used is already running. Aborting.");
}
} else {
if (!initialized) {
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
try {
MiniAccumuloClusterImpl.this.stop();
} catch (IOException e) {
log.error("IOException while attempting to stop the MiniAccumuloCluster.", e);
} catch (InterruptedException e) {
log.error("The stopping of MiniAccumuloCluster was interrupted.", e);
}
}));
}
if (!config.useExistingZooKeepers()) {
control.start(ServerType.ZOOKEEPER);
}
if (!initialized) {
if (!config.useExistingZooKeepers()) {
// sleep a little bit to let zookeeper come up before calling init, seems to work better
long startTime = System.currentTimeMillis();
while (true) {
try (Socket s = new Socket("localhost", config.getZooKeeperPort())) {
s.setReuseAddress(true);
s.getOutputStream().write("ruok\n".getBytes());
s.getOutputStream().flush();
byte[] buffer = new byte[100];
int n = s.getInputStream().read(buffer);
if (n >= 4 && new String(buffer, 0, 4).equals("imok")) {
break;
}
} catch (Exception e) {
if (System.currentTimeMillis() - startTime >= config.getZooKeeperStartupTime()) {
throw new ZooKeeperBindException("Zookeeper did not start within " + (config.getZooKeeperStartupTime() / 1000) + " seconds. Check the logs in " + config.getLogDir() + " for errors. Last exception: " + e);
}
// Don't spin absurdly fast
sleepUninterruptibly(250, TimeUnit.MILLISECONDS);
}
}
}
LinkedList<String> args = new LinkedList<>();
args.add("--instance-name");
args.add(config.getInstanceName());
args.add("--user");
args.add(config.getRootUserName());
args.add("--clear-instance-name");
// If we aren't using SASL, add in the root password
final String saslEnabled = config.getSiteConfig().get(Property.INSTANCE_RPC_SASL_ENABLED.getKey());
if (saslEnabled == null || !Boolean.parseBoolean(saslEnabled)) {
args.add("--password");
args.add(config.getRootPassword());
}
Process initProcess = exec(Initialize.class, args.toArray(new String[0])).getProcess();
int ret = initProcess.waitFor();
if (ret != 0) {
throw new RuntimeException("Initialize process returned " + ret + ". Check the logs in " + config.getLogDir() + " for errors.");
}
initialized = true;
}
}
log.info("Starting MAC against instance {} and zookeeper(s) {}.", config.getInstanceName(), config.getZooKeepers());
control.start(ServerType.TABLET_SERVER);
int ret = 0;
for (int i = 0; i < 5; i++) {
ret = exec(Main.class, SetGoalState.class.getName(), ManagerGoalState.NORMAL.toString()).getProcess().waitFor();
if (ret == 0) {
break;
}
sleepUninterruptibly(1, TimeUnit.SECONDS);
}
if (ret != 0) {
throw new RuntimeException("Could not set manager goal state, process returned " + ret + ". Check the logs in " + config.getLogDir() + " for errors.");
}
control.start(ServerType.MANAGER);
control.start(ServerType.GARBAGE_COLLECTOR);
if (executor == null) {
executor = Executors.newSingleThreadExecutor();
}
verifyUp();
}
use of org.apache.accumulo.core.conf.AccumuloConfiguration in project accumulo by apache.
the class VolumeManagerImpl method getLocalForTesting.
// for testing only
public static VolumeManager getLocalForTesting(String localBasePath) throws IOException {
AccumuloConfiguration accConf = DefaultConfiguration.getInstance();
Configuration hadoopConf = new Configuration();
FileSystem localFS = FileSystem.getLocal(hadoopConf);
Volume defaultLocalVolume = new VolumeImpl(localFS, localBasePath);
return new VolumeManagerImpl(Collections.singletonMap("", defaultLocalVolume), accConf, hadoopConf);
}
use of org.apache.accumulo.core.conf.AccumuloConfiguration in project accumulo by apache.
the class ClientServiceHandler method getNamespaceConfiguration.
@Override
public Map<String, String> getNamespaceConfiguration(TInfo tinfo, TCredentials credentials, String ns) throws ThriftTableOperationException, TException {
NamespaceId namespaceId;
try {
namespaceId = Namespaces.getNamespaceId(context, ns);
} catch (NamespaceNotFoundException e) {
String why = "Could not find namespace while getting configuration.";
throw new ThriftTableOperationException(null, ns, null, TableOperationExceptionType.NAMESPACE_NOTFOUND, why);
}
AccumuloConfiguration config = context.getNamespaceConfiguration(namespaceId);
return conf(credentials, config);
}
use of org.apache.accumulo.core.conf.AccumuloConfiguration in project accumulo by apache.
the class ClientServiceHandler method getTableConfiguration.
@Override
public Map<String, String> getTableConfiguration(TInfo tinfo, TCredentials credentials, String tableName) throws TException, ThriftTableOperationException {
TableId tableId = checkTableId(context, tableName, null);
AccumuloConfiguration config = context.getTableConfiguration(tableId);
return conf(credentials, config);
}
Aggregations