use of org.apache.accumulo.fate.zookeeper.ZooCache in project accumulo by apache.
the class AdminTest method testCannotQualifySessionId.
@Test
public void testCannotQualifySessionId() {
ZooCache zc = EasyMock.createMock(ZooCache.class);
String root = "/accumulo/id/tservers";
String server = "localhost:12345";
String serverPath = root + "/" + server;
EasyMock.expect(zc.getChildren(serverPath)).andReturn(Collections.emptyList());
EasyMock.replay(zc);
// A server that isn't in ZooKeeper. Can't qualify it, should return the original
assertEquals(server, Admin.qualifyWithZooKeeperSessionId(root, zc, server));
EasyMock.verify(zc);
}
use of org.apache.accumulo.fate.zookeeper.ZooCache in project accumulo by apache.
the class AdminTest method testQualifySessionId.
@Test
public void testQualifySessionId() {
ZooCache zc = EasyMock.createMock(ZooCache.class);
String root = "/accumulo/id/tservers";
String server = "localhost:12345";
final long session = 123456789l;
String serverPath = root + "/" + server;
EasyMock.expect(zc.getChildren(serverPath)).andReturn(Collections.singletonList("child"));
EasyMock.expect(zc.get(EasyMock.eq(serverPath + "/child"), EasyMock.anyObject(ZcStat.class))).andAnswer(new IAnswer<byte[]>() {
@Override
public byte[] answer() throws Throwable {
ZcStat stat = (ZcStat) EasyMock.getCurrentArguments()[1];
stat.setEphemeralOwner(session);
return new byte[0];
}
});
EasyMock.replay(zc);
assertEquals(server + "[" + Long.toHexString(session) + "]", Admin.qualifyWithZooKeeperSessionId(root, zc, server));
EasyMock.verify(zc);
}
use of org.apache.accumulo.fate.zookeeper.ZooCache in project accumulo by apache.
the class ReadWriteIT method sunnyDay.
@Test
public void sunnyDay() throws Exception {
// Start accumulo, create a table, insert some data, verify we can read it out.
// Shutdown cleanly.
log.debug("Starting Monitor");
cluster.getClusterControl().startAllServers(ServerType.MONITOR);
Connector connector = getConnector();
String tableName = getUniqueNames(1)[0];
ingest(connector, getCluster().getClientConfig(), getAdminPrincipal(), ROWS, COLS, 50, 0, tableName);
verify(connector, getCluster().getClientConfig(), getAdminPrincipal(), ROWS, COLS, 50, 0, tableName);
String monitorLocation = null;
while (null == monitorLocation) {
monitorLocation = MonitorUtil.getLocation(getConnector().getInstance());
if (null == monitorLocation) {
log.debug("Could not fetch monitor HTTP address from zookeeper");
Thread.sleep(2000);
}
}
String scheme = "http://";
if (getCluster() instanceof StandaloneAccumuloCluster) {
StandaloneAccumuloCluster standaloneCluster = (StandaloneAccumuloCluster) getCluster();
File accumuloSite = new File(standaloneCluster.getServerAccumuloConfDir(), "accumulo-site.xml");
if (accumuloSite.isFile()) {
Configuration conf = new Configuration(false);
conf.addResource(new Path(accumuloSite.toURI()));
String monitorSslKeystore = conf.get(Property.MONITOR_SSL_KEYSTORE.getKey());
if (null != monitorSslKeystore) {
log.info("Setting scheme to HTTPS since monitor ssl keystore configuration was observed in {}", accumuloSite);
scheme = "https://";
SSLContext ctx = SSLContext.getInstance("SSL");
TrustManager[] tm = new TrustManager[] { new TestTrustManager() };
ctx.init(new KeyManager[0], tm, new SecureRandom());
SSLContext.setDefault(ctx);
HttpsURLConnection.setDefaultSSLSocketFactory(ctx.getSocketFactory());
HttpsURLConnection.setDefaultHostnameVerifier(new TestHostnameVerifier());
}
} else {
log.info("{} is not a normal file, not checking for monitor running with SSL", accumuloSite);
}
}
URL url = new URL(scheme + monitorLocation);
log.debug("Fetching web page {}", url);
String result = FunctionalTestUtils.readAll(url.openStream());
assertTrue(result.length() > 100);
log.debug("Stopping accumulo cluster");
ClusterControl control = cluster.getClusterControl();
control.adminStopAll();
ZooReader zreader = new ZooReader(connector.getInstance().getZooKeepers(), connector.getInstance().getZooKeepersSessionTimeOut());
ZooCache zcache = new ZooCache(zreader, null);
byte[] masterLockData;
do {
masterLockData = ZooLock.getLockData(zcache, ZooUtil.getRoot(connector.getInstance()) + Constants.ZMASTER_LOCK, null);
if (null != masterLockData) {
log.info("Master lock is still held");
Thread.sleep(1000);
}
} while (null != masterLockData);
control.stopAllServers(ServerType.GARBAGE_COLLECTOR);
control.stopAllServers(ServerType.MONITOR);
control.stopAllServers(ServerType.TRACER);
log.debug("success!");
// Restarting everything
cluster.start();
}
use of org.apache.accumulo.fate.zookeeper.ZooCache in project accumulo by apache.
the class RestartIT method restartMasterSplit.
@Test
public void restartMasterSplit() throws Exception {
Connector c = getConnector();
final String tableName = getUniqueNames(1)[0];
final AuthenticationToken token = getAdminToken();
final ClusterControl control = getCluster().getClusterControl();
VOPTS.setTableName(tableName);
c.tableOperations().create(tableName);
c.tableOperations().setProperty(tableName, Property.TABLE_SPLIT_THRESHOLD.getKey(), "5K");
final String[] args;
if (token instanceof PasswordToken) {
byte[] password = ((PasswordToken) token).getPassword();
args = new String[] { "-u", getAdminPrincipal(), "-p", new String(password, UTF_8), "-i", cluster.getInstanceName(), "-z", cluster.getZooKeepers(), "--rows", Integer.toString(VOPTS.rows), "--table", tableName };
OPTS.setPrincipal(getAdminPrincipal());
VOPTS.setPrincipal(getAdminPrincipal());
} else if (token instanceof KerberosToken) {
ClusterUser rootUser = getAdminUser();
args = new String[] { "-u", getAdminPrincipal(), "--keytab", rootUser.getKeytab().getAbsolutePath(), "-i", cluster.getInstanceName(), "-z", cluster.getZooKeepers(), "--rows", Integer.toString(VOPTS.rows), "--table", tableName };
ClientConfiguration clientConfig = cluster.getClientConfig();
OPTS.updateKerberosCredentials(clientConfig);
VOPTS.updateKerberosCredentials(clientConfig);
} else {
throw new RuntimeException("Unknown token");
}
Future<Integer> ret = svc.submit(new Callable<Integer>() {
@Override
public Integer call() {
try {
return control.exec(TestIngest.class, args);
} catch (Exception e) {
log.error("Error running TestIngest", e);
return -1;
}
}
});
control.stopAllServers(ServerType.MASTER);
ZooReader zreader = new ZooReader(c.getInstance().getZooKeepers(), c.getInstance().getZooKeepersSessionTimeOut());
ZooCache zcache = new ZooCache(zreader, null);
byte[] masterLockData;
do {
masterLockData = ZooLock.getLockData(zcache, ZooUtil.getRoot(c.getInstance()) + Constants.ZMASTER_LOCK, null);
if (null != masterLockData) {
log.info("Master lock is still held");
Thread.sleep(1000);
}
} while (null != masterLockData);
cluster.start();
assertEquals(0, ret.get().intValue());
VerifyIngest.verifyIngest(c, VOPTS, SOPTS);
}
use of org.apache.accumulo.fate.zookeeper.ZooCache in project accumulo by apache.
the class RestartIT method restartMasterRecovery.
@Test
public void restartMasterRecovery() throws Exception {
Connector c = getConnector();
String tableName = getUniqueNames(1)[0];
c.tableOperations().create(tableName);
OPTS.setTableName(tableName);
VOPTS.setTableName(tableName);
ClientConfiguration clientConfig = cluster.getClientConfig();
if (clientConfig.hasSasl()) {
OPTS.updateKerberosCredentials(clientConfig);
VOPTS.updateKerberosCredentials(clientConfig);
} else {
OPTS.setPrincipal(getAdminPrincipal());
VOPTS.setPrincipal(getAdminPrincipal());
}
TestIngest.ingest(c, OPTS, BWOPTS);
ClusterControl control = getCluster().getClusterControl();
// TODO implement a kill all too?
// cluster.stop() would also stop ZooKeeper
control.stopAllServers(ServerType.MASTER);
control.stopAllServers(ServerType.TRACER);
control.stopAllServers(ServerType.TABLET_SERVER);
control.stopAllServers(ServerType.GARBAGE_COLLECTOR);
control.stopAllServers(ServerType.MONITOR);
ZooReader zreader = new ZooReader(c.getInstance().getZooKeepers(), c.getInstance().getZooKeepersSessionTimeOut());
ZooCache zcache = new ZooCache(zreader, null);
byte[] masterLockData;
do {
masterLockData = ZooLock.getLockData(zcache, ZooUtil.getRoot(c.getInstance()) + Constants.ZMASTER_LOCK, null);
if (null != masterLockData) {
log.info("Master lock is still held");
Thread.sleep(1000);
}
} while (null != masterLockData);
cluster.start();
sleepUninterruptibly(5, TimeUnit.MILLISECONDS);
control.stopAllServers(ServerType.MASTER);
masterLockData = new byte[0];
do {
masterLockData = ZooLock.getLockData(zcache, ZooUtil.getRoot(c.getInstance()) + Constants.ZMASTER_LOCK, null);
if (null != masterLockData) {
log.info("Master lock is still held");
Thread.sleep(1000);
}
} while (null != masterLockData);
cluster.start();
VerifyIngest.verifyIngest(c, VOPTS, SOPTS);
}
Aggregations