Search in sources :

Example 16 with ClientContext

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);
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) ClientContext(org.apache.accumulo.core.clientImpl.ClientContext) KeyManagementException(java.security.KeyManagementException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) URL(java.net.URL) Test(org.junit.Test) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 17 with ClientContext

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);
}
Also used : InstanceId(org.apache.accumulo.core.data.InstanceId) ClientContext(org.apache.accumulo.core.clientImpl.ClientContext) Test(org.junit.Test)

Example 18 with ClientContext

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");
    }
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) ClientContext(org.apache.accumulo.core.clientImpl.ClientContext) ZooCache(org.apache.accumulo.fate.zookeeper.ZooCache) InstanceOperations(org.apache.accumulo.core.client.admin.InstanceOperations) Before(org.junit.Before)

Example 19 with ClientContext

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);
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) Options(org.apache.commons.cli.Options) ClientContext(org.apache.accumulo.core.clientImpl.ClientContext) TreeMap(java.util.TreeMap) Shell(org.apache.accumulo.shell.Shell) CommandLine(org.apache.commons.cli.CommandLine) TableOperations(org.apache.accumulo.core.client.admin.TableOperations) CommandLineParser(org.apache.commons.cli.CommandLineParser) InstanceOperations(org.apache.accumulo.core.client.admin.InstanceOperations) DefaultParser(org.apache.commons.cli.DefaultParser) Test(org.junit.Test)

Example 20 with ClientContext

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();
    }
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) ClientContext(org.apache.accumulo.core.clientImpl.ClientContext) SSLContext(javax.net.ssl.SSLContext) StandaloneAccumuloCluster(org.apache.accumulo.cluster.standalone.StandaloneAccumuloCluster) ZooCache(org.apache.accumulo.fate.zookeeper.ZooCache) URL(java.net.URL) TrustManager(javax.net.ssl.TrustManager) X509TrustManager(javax.net.ssl.X509TrustManager) ZooReader(org.apache.accumulo.fate.zookeeper.ZooReader) ClientInfo(org.apache.accumulo.core.clientImpl.ClientInfo) ClusterControl(org.apache.accumulo.cluster.ClusterControl) Test(org.junit.Test) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Aggregations

ClientContext (org.apache.accumulo.core.clientImpl.ClientContext)53 AccumuloClient (org.apache.accumulo.core.client.AccumuloClient)22 Test (org.junit.Test)16 ArrayList (java.util.ArrayList)15 IOException (java.io.IOException)14 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)14 Text (org.apache.hadoop.io.Text)14 AccumuloException (org.apache.accumulo.core.client.AccumuloException)12 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)12 KeyExtent (org.apache.accumulo.core.dataImpl.KeyExtent)11 List (java.util.List)10 PasswordToken (org.apache.accumulo.core.client.security.tokens.PasswordToken)10 TableId (org.apache.accumulo.core.data.TableId)9 HashSet (java.util.HashSet)8 Map (java.util.Map)8 TreeSet (java.util.TreeSet)8 KerberosToken (org.apache.accumulo.core.client.security.tokens.KerberosToken)7 HostAndPort (org.apache.accumulo.core.util.HostAndPort)7 HashMap (java.util.HashMap)6 Scanner (org.apache.accumulo.core.client.Scanner)6