use of org.apache.accumulo.minicluster.impl.MiniAccumuloClusterImpl in project accumulo by apache.
the class MissingWalHeaderCompletesRecoveryIT method testPartialHeaderWalRecoveryCompletes.
@Test
public void testPartialHeaderWalRecoveryCompletes() throws Exception {
Connector conn = getConnector();
MiniAccumuloClusterImpl cluster = getCluster();
FileSystem fs = getCluster().getFileSystem();
// Fake out something that looks like host:port, it's irrelevant
String fakeServer = "127.0.0.1:12345";
File walogs = new File(cluster.getConfig().getAccumuloDir(), ServerConstants.WAL_DIR);
File walogServerDir = new File(walogs, fakeServer.replace(':', '+'));
File partialHeaderWalog = new File(walogServerDir, UUID.randomUUID().toString());
log.info("Created WAL with malformed header at {}", partialHeaderWalog.toURI());
// Write half of the header
FSDataOutputStream wal = fs.create(new Path(partialHeaderWalog.toURI()));
wal.write(DfsLogger.LOG_FILE_HEADER_V3.getBytes(UTF_8), 0, DfsLogger.LOG_FILE_HEADER_V3.length() / 2);
wal.close();
Assert.assertTrue("root user did not have write permission to metadata table", conn.securityOperations().hasTablePermission("root", MetadataTable.NAME, TablePermission.WRITE));
String tableName = getUniqueNames(1)[0];
conn.tableOperations().create(tableName);
Table.ID tableId = Table.ID.of(conn.tableOperations().tableIdMap().get(tableName));
Assert.assertNotNull("Table ID was null", tableId);
LogEntry logEntry = new LogEntry(null, 0, "127.0.0.1:12345", partialHeaderWalog.toURI().toString());
log.info("Taking {} offline", tableName);
conn.tableOperations().offline(tableName, true);
log.info("{} is offline", tableName);
Text row = MetadataSchema.TabletsSection.getRow(tableId, null);
Mutation m = new Mutation(row);
m.put(logEntry.getColumnFamily(), logEntry.getColumnQualifier(), logEntry.getValue());
BatchWriter bw = conn.createBatchWriter(MetadataTable.NAME, new BatchWriterConfig());
bw.addMutation(m);
bw.close();
log.info("Bringing {} online", tableName);
conn.tableOperations().online(tableName, true);
log.info("{} is online", tableName);
// otherwise the tablet will never come online and we won't be able to read it.
try (Scanner s = conn.createScanner(tableName, Authorizations.EMPTY)) {
Assert.assertEquals(0, Iterables.size(s));
}
}
use of org.apache.accumulo.minicluster.impl.MiniAccumuloClusterImpl in project accumulo-examples by apache.
the class ExamplesIT method testDirList.
@Test
public void testDirList() throws Exception {
String[] names = getUniqueNames(3);
String dirTable = names[0], indexTable = names[1], dataTable = names[2];
String[] args;
String dirListDirectory;
switch(getClusterType()) {
case MINI:
dirListDirectory = ((MiniAccumuloClusterImpl) getCluster()).getConfig().getDir().getAbsolutePath();
break;
case STANDALONE:
dirListDirectory = ((StandaloneAccumuloCluster) getCluster()).getAccumuloHome();
break;
default:
throw new RuntimeException("Unknown cluster type");
}
assumeTrue(new File(dirListDirectory).exists());
// Index a directory listing on /tmp. If this is running against a standalone cluster, we can't guarantee Accumulo source will be there.
args = new String[] { "-c", getConnectionFile(), "--dirTable", dirTable, "--indexTable", indexTable, "--dataTable", dataTable, "--vis", visibility, "--chunkSize", Integer.toString(10000), dirListDirectory };
Entry<Integer, String> entry = getClusterControl().execWithStdout(Ingest.class, args);
assertEquals("Got non-zero return code. Stdout=" + entry.getValue(), 0, entry.getKey().intValue());
String expectedFile;
switch(getClusterType()) {
case MINI:
// Should be present in a minicluster dir
expectedFile = "accumulo-site.xml";
break;
case STANDALONE:
// Should be in place on standalone installs (not having to follow symlinks)
expectedFile = "LICENSE";
break;
default:
throw new RuntimeException("Unknown cluster type");
}
args = new String[] { "-c", getConnectionFile(), "-t", indexTable, "--auths", auths, "--search", "--path", expectedFile };
entry = getClusterControl().execWithStdout(QueryUtil.class, args);
if (ClusterType.MINI == getClusterType()) {
MiniAccumuloClusterImpl impl = (MiniAccumuloClusterImpl) cluster;
for (LogWriter writer : impl.getLogWriters()) {
writer.flush();
}
}
log.info("result " + entry.getValue());
assertEquals(0, entry.getKey().intValue());
assertTrue(entry.getValue().contains(expectedFile));
}
use of org.apache.accumulo.minicluster.impl.MiniAccumuloClusterImpl in project accumulo by apache.
the class ShellConfigIT method experimentalPropTest.
@Test
public void experimentalPropTest() throws Exception {
// ensure experimental props do not show up in config output unless set
AuthenticationToken token = getAdminToken();
File clientConfFile = null;
switch(getClusterType()) {
case MINI:
MiniAccumuloClusterImpl mac = (MiniAccumuloClusterImpl) getCluster();
clientConfFile = mac.getConfig().getClientConfFile();
break;
case STANDALONE:
StandaloneAccumuloClusterConfiguration standaloneConf = (StandaloneAccumuloClusterConfiguration) getClusterConfiguration();
clientConfFile = standaloneConf.getClientConfFile();
break;
default:
Assert.fail("Unknown cluster type");
}
Assert.assertNotNull(clientConfFile);
TestShell ts = null;
if (token instanceof PasswordToken) {
String passwd = new String(((PasswordToken) token).getPassword(), UTF_8);
ts = new TestShell(getAdminPrincipal(), passwd, getCluster().getInstanceName(), getCluster().getZooKeepers(), clientConfFile);
} else if (token instanceof KerberosToken) {
ts = new TestShell(getAdminPrincipal(), null, getCluster().getInstanceName(), getCluster().getZooKeepers(), clientConfFile);
} else {
Assert.fail("Unknown token type");
}
assertTrue(Property.CRYPTO_CIPHER_KEY_ALGORITHM_NAME.isExperimental());
String configOutput = ts.exec("config");
assertTrue(configOutput.contains(PerTableVolumeChooser.TABLE_VOLUME_CHOOSER));
assertFalse(configOutput.contains(Property.CRYPTO_CIPHER_KEY_ALGORITHM_NAME.getKey()));
}
use of org.apache.accumulo.minicluster.impl.MiniAccumuloClusterImpl in project accumulo by apache.
the class ThriftServerBindsBeforeZooKeeperLockIT method testMonitorService.
@Test
public void testMonitorService() throws Exception {
final MiniAccumuloClusterImpl cluster = (MiniAccumuloClusterImpl) getCluster();
Collection<ProcessReference> monitors = cluster.getProcesses().get(ServerType.MONITOR);
// Need to start one monitor and let it become active.
if (null == monitors || 0 == monitors.size()) {
getClusterControl().start(ServerType.MONITOR, "localhost");
}
final ZooKeeperInstance inst = new ZooKeeperInstance(cluster.getClientConfig());
while (true) {
try {
MonitorUtil.getLocation(inst);
break;
} catch (Exception e) {
LOG.debug("Failed to find active monitor location, retrying", e);
Thread.sleep(1000);
}
}
LOG.debug("Found active monitor");
while (true) {
int freePort = PortUtils.getRandomFreePort();
String monitorUrl = "http://localhost:" + freePort;
Process monitor = null;
try {
LOG.debug("Starting standby monitor on {}", freePort);
monitor = startProcess(cluster, ServerType.MONITOR, freePort);
while (true) {
URL url = new URL(monitorUrl);
try {
HttpURLConnection cnxn = (HttpURLConnection) url.openConnection();
final int responseCode = cnxn.getResponseCode();
String errorText;
// This is our "assertion", but we want to re-check it if it's not what we expect
if (HttpURLConnection.HTTP_OK == responseCode) {
return;
} else {
errorText = FunctionalTestUtils.readAll(cnxn.getErrorStream());
}
LOG.debug("Unexpected responseCode and/or error text, will retry: '{}' '{}'", responseCode, errorText);
} catch (Exception e) {
LOG.debug("Caught exception trying to fetch monitor info", e);
}
// Wait before trying again
Thread.sleep(1000);
// died trying to bind it. Pick a new port and restart it in that case.
if (!monitor.isAlive()) {
freePort = PortUtils.getRandomFreePort();
monitorUrl = "http://localhost:" + freePort;
LOG.debug("Monitor died, restarting it listening on {}", freePort);
monitor = startProcess(cluster, ServerType.MONITOR, freePort);
}
}
} finally {
if (null != monitor) {
monitor.destroyForcibly();
}
}
}
}
use of org.apache.accumulo.minicluster.impl.MiniAccumuloClusterImpl in project accumulo by apache.
the class ThriftServerBindsBeforeZooKeeperLockIT method testGarbageCollectorPorts.
@Test
public void testGarbageCollectorPorts() throws Exception {
final MiniAccumuloClusterImpl cluster = (MiniAccumuloClusterImpl) getCluster();
final ZooKeeperInstance inst = new ZooKeeperInstance(cluster.getClientConfig());
// Wait for the Master to grab its lock
while (true) {
final ZooReader reader = new ZooReader(inst.getZooKeepers(), 30000);
try {
List<String> locks = reader.getChildren(Constants.ZROOT + "/" + inst.getInstanceID() + Constants.ZGC_LOCK);
if (locks.size() > 0) {
break;
}
} catch (Exception e) {
LOG.debug("Failed to find active gc location, retrying", e);
Thread.sleep(1000);
}
}
LOG.debug("Found active gc");
while (true) {
int freePort = PortUtils.getRandomFreePort();
Process master = null;
try {
LOG.debug("Starting standby gc on {}", freePort);
master = startProcess(cluster, ServerType.GARBAGE_COLLECTOR, freePort);
while (true) {
Socket s = null;
try {
s = new Socket("localhost", freePort);
if (s.isConnected()) {
// Pass
return;
}
} catch (Exception e) {
LOG.debug("Caught exception trying to connect to GC", e);
} finally {
if (null != s) {
s.close();
}
}
// Wait before trying again
Thread.sleep(1000);
// died trying to bind it. Pick a new port and restart it in that case.
if (!master.isAlive()) {
freePort = PortUtils.getRandomFreePort();
LOG.debug("GC died, restarting it listening on {}", freePort);
master = startProcess(cluster, ServerType.GARBAGE_COLLECTOR, freePort);
}
}
} finally {
if (null != master) {
master.destroyForcibly();
}
}
}
}
Aggregations