use of org.apache.accumulo.core.clientImpl.ClientContext in project accumulo by apache.
the class MonitorSslIT method test.
@SuppressFBWarnings(value = "URLCONNECTION_SSRF_FD", justification = "url provided by test")
@Test
public void test() throws Exception {
log.debug("Starting Monitor");
cluster.getClusterControl().startAllServers(ServerType.MONITOR);
String monitorLocation = null;
try (AccumuloClient client = Accumulo.newClient().from(getClientProperties()).build()) {
while (monitorLocation == null) {
try {
monitorLocation = MonitorUtil.getLocation((ClientContext) client);
} catch (Exception e) {
// ignored
}
if (monitorLocation == null) {
log.debug("Could not fetch monitor HTTP address from zookeeper");
Thread.sleep(2000);
}
}
}
URL url = new URL(monitorLocation);
log.debug("Fetching web page {}", url);
String result = FunctionalTestUtils.readWebPage(url).body();
assertTrue(result.length() > 100);
assertTrue(result.indexOf("Accumulo Overview") >= 0);
}
use of org.apache.accumulo.core.clientImpl.ClientContext in project accumulo by apache.
the class AdminTest method testZooKeeperTserverPath.
@Test
public void testZooKeeperTserverPath() {
ClientContext context = EasyMock.createMock(ClientContext.class);
InstanceId instanceId = InstanceId.of(UUID.randomUUID());
EasyMock.expect(context.getZooKeeperRoot()).andReturn(Constants.ZROOT + "/" + instanceId);
EasyMock.replay(context);
assertEquals(Constants.ZROOT + "/" + instanceId + Constants.ZTSERVERS, Admin.getTServersZkPath(context));
EasyMock.verify(context);
}
use of org.apache.accumulo.core.clientImpl.ClientContext in project accumulo by apache.
the class BadDeleteMarkersCreatedIT method alterConfig.
@Before
public void alterConfig() throws Exception {
try (AccumuloClient client = Accumulo.newClient().from(getClientProps()).build()) {
InstanceOperations iops = client.instanceOperations();
Map<String, String> config = iops.getSystemConfiguration();
gcCycleDelay = config.get(Property.GC_CYCLE_DELAY.getKey());
gcCycleStart = config.get(Property.GC_CYCLE_START.getKey());
iops.setProperty(Property.GC_CYCLE_DELAY.getKey(), "1s");
iops.setProperty(Property.GC_CYCLE_START.getKey(), "0s");
log.info("Restarting garbage collector");
}
getCluster().getClusterControl().stopAllServers(ServerType.GARBAGE_COLLECTOR);
try (AccumuloClient client = Accumulo.newClient().from(getClientProps()).build();
ClientContext context = (ClientContext) client) {
ZooCache zcache = context.getZooCache();
zcache.clear();
var path = ServiceLock.path(ZooUtil.getRoot(client.instanceOperations().getInstanceId()) + Constants.ZGC_LOCK);
byte[] gcLockData;
do {
gcLockData = ServiceLock.getLockData(zcache, path, null);
if (gcLockData != null) {
log.info("Waiting for GC ZooKeeper lock to expire");
Thread.sleep(2000);
}
} while (gcLockData != null);
log.info("GC lock was lost");
getCluster().getClusterControl().startAllServers(ServerType.GARBAGE_COLLECTOR);
log.info("Garbage collector was restarted");
do {
gcLockData = ServiceLock.getLockData(zcache, path, null);
if (gcLockData == null) {
log.info("Waiting for GC ZooKeeper lock to be acquired");
Thread.sleep(2000);
}
} while (gcLockData == null);
log.info("GC lock was acquired");
}
}
use of org.apache.accumulo.core.clientImpl.ClientContext in project accumulo by apache.
the class ListTabletsCommandTest method mockTest.
@Test
public void mockTest() throws Exception {
ListTabletsCommand cmd = new TestListTabletsCommand();
AccumuloClient client = EasyMock.createMock(AccumuloClient.class);
ClientContext context = EasyMock.createMock(ClientContext.class);
TableOperations tableOps = EasyMock.createMock(TableOperations.class);
InstanceOperations instOps = EasyMock.createMock(InstanceOperations.class);
Shell shellState = EasyMock.createMock(Shell.class);
Options opts = cmd.getOptions();
CommandLineParser parser = new DefaultParser();
String[] args = { "-t", tableName };
CommandLine cli = parser.parse(opts, args);
EasyMock.expect(shellState.getAccumuloClient()).andReturn(client).anyTimes();
EasyMock.expect(shellState.getContext()).andReturn(context).anyTimes();
EasyMock.expect(client.tableOperations()).andReturn(tableOps).anyTimes();
Map<String, String> idMap = new TreeMap<>();
idMap.put(tableName, tableId.canonical());
EasyMock.expect(tableOps.tableIdMap()).andReturn(idMap);
assertEquals("Incorrect number of rows: " + rows, rows.size(), 3);
EasyMock.replay(client, context, tableOps, instOps, shellState);
cmd.execute("listTablets -t " + tableName, cli, shellState);
EasyMock.verify(client, context, tableOps, instOps, shellState);
}
use of org.apache.accumulo.core.clientImpl.ClientContext in project accumulo by apache.
the class ReadWriteIT method sunnyDay.
@SuppressFBWarnings(value = { "PATH_TRAVERSAL_IN", "URLCONNECTION_SSRF_FD" }, justification = "path provided by test; url provided by test")
@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);
try (AccumuloClient accumuloClient = Accumulo.newClient().from(getClientProps()).build()) {
String tableName = getUniqueNames(1)[0];
ingest(accumuloClient, getClientInfo(), ROWS, COLS, 50, 0, tableName);
verify(accumuloClient, getClientInfo(), ROWS, COLS, 50, 0, tableName);
String monitorLocation = null;
while (monitorLocation == null) {
monitorLocation = MonitorUtil.getLocation((ClientContext) accumuloClient);
if (monitorLocation == null) {
log.debug("Could not fetch monitor HTTP address from zookeeper");
Thread.sleep(2000);
}
}
if (getCluster() instanceof StandaloneAccumuloCluster) {
String monitorSslKeystore = getCluster().getSiteConfiguration().get(Property.MONITOR_SSL_KEYSTORE.getKey());
if (monitorSslKeystore != null && !monitorSslKeystore.isEmpty()) {
log.info("Using HTTPS since monitor ssl keystore configuration was observed in accumulo configuration");
SSLContext ctx = SSLContext.getInstance("TLSv1.2");
TrustManager[] tm = { new TestTrustManager() };
ctx.init(new KeyManager[0], tm, random);
SSLContext.setDefault(ctx);
HttpsURLConnection.setDefaultSSLSocketFactory(ctx.getSocketFactory());
HttpsURLConnection.setDefaultHostnameVerifier(new TestHostnameVerifier());
}
}
URL url = new URL(monitorLocation);
log.debug("Fetching web page {}", url);
String result = FunctionalTestUtils.readWebPage(url).body();
assertTrue(result.length() > 100);
log.debug("Stopping accumulo cluster");
ClusterControl control = cluster.getClusterControl();
control.adminStopAll();
ClientInfo info = ClientInfo.from(accumuloClient.properties());
ZooReader zreader = new ZooReader(info.getZooKeepers(), info.getZooKeepersSessionTimeOut());
ZooCache zcache = new ZooCache(zreader, null);
var zLockPath = ServiceLock.path(ZooUtil.getRoot(accumuloClient.instanceOperations().getInstanceId()) + Constants.ZMANAGER_LOCK);
byte[] managerLockData;
do {
managerLockData = ServiceLock.getLockData(zcache, zLockPath, null);
if (managerLockData != null) {
log.info("Manager lock is still held");
Thread.sleep(1000);
}
} while (managerLockData != null);
control.stopAllServers(ServerType.MANAGER);
control.stopAllServers(ServerType.TABLET_SERVER);
control.stopAllServers(ServerType.GARBAGE_COLLECTOR);
control.stopAllServers(ServerType.MONITOR);
log.debug("success!");
// Restarting everything
cluster.start();
}
}
Aggregations