Search in sources :

Example 16 with InstanceId

use of org.apache.accumulo.core.data.InstanceId in project accumulo by apache.

the class ZKPermHandler method initialize.

@Override
public void initialize(ServerContext context) {
    zooCache = new ZooCache(context.getZooReaderWriter(), null);
    zoo = context.getZooReaderWriter();
    InstanceId instanceId = context.getInstanceID();
    ZKUserPath = ZKSecurityTool.getInstancePath(instanceId) + "/users";
    ZKTablePath = ZKSecurityTool.getInstancePath(instanceId) + "/tables";
    ZKNamespacePath = ZKSecurityTool.getInstancePath(instanceId) + "/namespaces";
}
Also used : InstanceId(org.apache.accumulo.core.data.InstanceId) ZooCache(org.apache.accumulo.fate.zookeeper.ZooCache)

Example 17 with InstanceId

use of org.apache.accumulo.core.data.InstanceId in project accumulo by apache.

the class ThriftServerBindsBeforeZooKeeperLockIT method testManagerService.

@SuppressFBWarnings(value = "UNENCRYPTED_SOCKET", justification = "unencrypted socket is okay for testing")
@Test
public void testManagerService() throws Exception {
    final MiniAccumuloClusterImpl cluster = (MiniAccumuloClusterImpl) getCluster();
    try (AccumuloClient client = Accumulo.newClient().from(getClientProps()).build()) {
        final InstanceId instanceID = client.instanceOperations().getInstanceId();
        // Wait for the Manager to grab its lock
        while (true) {
            final ZooReader reader = new ZooReader(cluster.getZooKeepers(), 30000);
            try {
                List<String> locks = reader.getChildren(Constants.ZROOT + "/" + instanceID + Constants.ZMANAGER_LOCK);
                if (!locks.isEmpty()) {
                    break;
                }
            } catch (Exception e) {
                LOG.debug("Failed to find active manager location, retrying", e);
                Thread.sleep(1000);
            }
        }
        LOG.debug("Found active manager");
        int freePort = PortUtils.getRandomFreePort();
        Process manager = null;
        try {
            LOG.debug("Starting standby manager on {}", freePort);
            manager = startProcess(cluster, ServerType.MANAGER, freePort);
            while (true) {
                try (Socket s = new Socket("localhost", freePort)) {
                    if (s.isConnected()) {
                        // Pass
                        return;
                    }
                } catch (Exception e) {
                    LOG.debug("Caught exception trying to connect to Manager", e);
                }
                // Wait before trying again
                Thread.sleep(1000);
                // died trying to bind it. Pick a new port and restart it in that case.
                if (!manager.isAlive()) {
                    freePort = PortUtils.getRandomFreePort();
                    LOG.debug("Manager died, restarting it listening on {}", freePort);
                    manager = startProcess(cluster, ServerType.MANAGER, freePort);
                }
            }
        } finally {
            if (manager != null) {
                manager.destroyForcibly();
            }
        }
    }
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) ZooReader(org.apache.accumulo.fate.zookeeper.ZooReader) InstanceId(org.apache.accumulo.core.data.InstanceId) MiniAccumuloClusterImpl(org.apache.accumulo.miniclusterImpl.MiniAccumuloClusterImpl) IOException(java.io.IOException) Socket(java.net.Socket) Test(org.junit.Test) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 18 with InstanceId

use of org.apache.accumulo.core.data.InstanceId in project accumulo by apache.

the class ThriftServerBindsBeforeZooKeeperLockIT method testGarbageCollectorPorts.

@SuppressFBWarnings(value = "UNENCRYPTED_SOCKET", justification = "unencrypted socket is okay for testing")
@Test
public void testGarbageCollectorPorts() throws Exception {
    final MiniAccumuloClusterImpl cluster = (MiniAccumuloClusterImpl) getCluster();
    try (AccumuloClient client = Accumulo.newClient().from(getClientProps()).build()) {
        InstanceId instanceID = client.instanceOperations().getInstanceId();
        // Wait for the Manager to grab its lock
        while (true) {
            final ZooReader reader = new ZooReader(cluster.getZooKeepers(), 30000);
            try {
                List<String> locks = reader.getChildren(Constants.ZROOT + "/" + instanceID + Constants.ZGC_LOCK);
                if (!locks.isEmpty()) {
                    break;
                }
            } catch (Exception e) {
                LOG.debug("Failed to find active gc location, retrying", e);
                Thread.sleep(1000);
            }
        }
        LOG.debug("Found active gc");
        int freePort = PortUtils.getRandomFreePort();
        Process manager = null;
        try {
            LOG.debug("Starting standby gc on {}", freePort);
            manager = startProcess(cluster, ServerType.GARBAGE_COLLECTOR, freePort);
            while (true) {
                try (Socket s = new Socket("localhost", freePort)) {
                    if (s.isConnected()) {
                        // Pass
                        return;
                    }
                } catch (Exception e) {
                    LOG.debug("Caught exception trying to connect to GC", e);
                }
                // Wait before trying again
                Thread.sleep(1000);
                // died trying to bind it. Pick a new port and restart it in that case.
                if (!manager.isAlive()) {
                    freePort = PortUtils.getRandomFreePort();
                    LOG.debug("GC died, restarting it listening on {}", freePort);
                    manager = startProcess(cluster, ServerType.GARBAGE_COLLECTOR, freePort);
                }
            }
        } finally {
            if (manager != null) {
                manager.destroyForcibly();
            }
        }
    }
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) ZooReader(org.apache.accumulo.fate.zookeeper.ZooReader) InstanceId(org.apache.accumulo.core.data.InstanceId) MiniAccumuloClusterImpl(org.apache.accumulo.miniclusterImpl.MiniAccumuloClusterImpl) IOException(java.io.IOException) Socket(java.net.Socket) Test(org.junit.Test) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 19 with InstanceId

use of org.apache.accumulo.core.data.InstanceId in project accumulo by apache.

the class SystemCredentialsIT method main.

public static void main(final String[] args) throws AccumuloException, TableNotFoundException {
    var siteConfig = SiteConfiguration.auto();
    try (ServerContext context = new ServerContext(siteConfig)) {
        Credentials creds;
        InstanceId badInstanceID = InstanceId.of(SystemCredentials.class.getName());
        if (args.length < 2) {
            throw new RuntimeException("Incorrect usage; expected to be run by test only");
        }
        switch(args[0]) {
            case "bad":
                creds = SystemCredentials.get(badInstanceID, siteConfig);
                break;
            case "good":
                creds = SystemCredentials.get(context.getInstanceID(), siteConfig);
                break;
            case "bad_password":
                creds = new SystemCredentials(badInstanceID, "!SYSTEM", new PasswordToken("fake"));
                break;
            default:
                throw new RuntimeException("Incorrect usage; expected to be run by test only");
        }
        try (AccumuloClient client = Accumulo.newClient().from(context.getProperties()).as(creds.getPrincipal(), creds.getToken()).build()) {
            client.securityOperations().authenticateUser(creds.getPrincipal(), creds.getToken());
            try (Scanner scan = client.createScanner(RootTable.NAME, Authorizations.EMPTY)) {
                for (Entry<Key, Value> e : scan) {
                    e.hashCode();
                }
            } catch (RuntimeException e) {
                e.printStackTrace(System.err);
                System.exit(SCAN_FAILED);
            }
        } catch (AccumuloSecurityException e) {
            e.printStackTrace(System.err);
            System.exit(AUTHENICATION_FAILED);
        }
    }
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) SystemCredentials(org.apache.accumulo.server.security.SystemCredentials) Scanner(org.apache.accumulo.core.client.Scanner) InstanceId(org.apache.accumulo.core.data.InstanceId) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) ServerContext(org.apache.accumulo.server.ServerContext) Value(org.apache.accumulo.core.data.Value) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) Credentials(org.apache.accumulo.core.clientImpl.Credentials) SystemCredentials(org.apache.accumulo.server.security.SystemCredentials) Key(org.apache.accumulo.core.data.Key)

Example 20 with InstanceId

use of org.apache.accumulo.core.data.InstanceId in project accumulo by apache.

the class CompactionDriverTest method testTableBeingDeleted.

@Test
public void testTableBeingDeleted() throws Exception {
    final InstanceId instance = InstanceId.of(UUID.randomUUID());
    final long compactId = 123;
    final long cancelId = 122;
    final NamespaceId namespaceId = NamespaceId.of("14");
    final TableId tableId = TableId.of("43");
    final byte[] startRow = new byte[0];
    final byte[] endRow = new byte[0];
    Manager manager = EasyMock.createNiceMock(Manager.class);
    ServerContext ctx = EasyMock.createNiceMock(ServerContext.class);
    ZooReaderWriter zrw = EasyMock.createNiceMock(ZooReaderWriter.class);
    EasyMock.expect(manager.getInstanceID()).andReturn(instance).anyTimes();
    EasyMock.expect(manager.getContext()).andReturn(ctx);
    EasyMock.expect(ctx.getZooReaderWriter()).andReturn(zrw);
    final String zCancelID = CompactionDriver.createCompactionCancellationPath(instance, tableId);
    EasyMock.expect(zrw.getData(zCancelID)).andReturn(Long.toString(cancelId).getBytes());
    String deleteMarkerPath = PreDeleteTable.createDeleteMarkerPath(instance, tableId);
    EasyMock.expect(zrw.exists(deleteMarkerPath)).andReturn(true);
    EasyMock.replay(manager, ctx, zrw);
    final CompactionDriver driver = new CompactionDriver(compactId, namespaceId, tableId, startRow, endRow);
    final long tableIdLong = Long.parseLong(tableId.toString());
    var e = assertThrows(AcceptableThriftTableOperationException.class, () -> driver.isReady(tableIdLong, manager));
    assertTrue(e.getTableId().equals(tableId.toString()));
    assertTrue(e.getOp().equals(TableOperation.COMPACT));
    assertTrue(e.getType().equals(TableOperationExceptionType.OTHER));
    assertTrue(e.getDescription().equals(TableOperationsImpl.TABLE_DELETED_MSG));
    EasyMock.verify(manager, ctx, zrw);
}
Also used : TableId(org.apache.accumulo.core.data.TableId) ServerContext(org.apache.accumulo.server.ServerContext) InstanceId(org.apache.accumulo.core.data.InstanceId) ZooReaderWriter(org.apache.accumulo.fate.zookeeper.ZooReaderWriter) NamespaceId(org.apache.accumulo.core.data.NamespaceId) Manager(org.apache.accumulo.manager.Manager) Test(org.junit.Test)

Aggregations

InstanceId (org.apache.accumulo.core.data.InstanceId)23 Test (org.junit.Test)8 IOException (java.io.IOException)6 ZooReaderWriter (org.apache.accumulo.fate.zookeeper.ZooReaderWriter)6 AccumuloClient (org.apache.accumulo.core.client.AccumuloClient)5 TableId (org.apache.accumulo.core.data.TableId)5 ServerContext (org.apache.accumulo.server.ServerContext)5 Path (org.apache.hadoop.fs.Path)5 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)4 KeeperException (org.apache.zookeeper.KeeperException)4 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)3 Socket (java.net.Socket)3 SiteConfiguration (org.apache.accumulo.core.conf.SiteConfiguration)3 ZooReader (org.apache.accumulo.fate.zookeeper.ZooReader)3 Initialize (org.apache.accumulo.server.init.Initialize)3 Configuration (org.apache.hadoop.conf.Configuration)3 AccumuloException (org.apache.accumulo.core.client.AccumuloException)2 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)2 NamespaceId (org.apache.accumulo.core.data.NamespaceId)2 AdminUtil (org.apache.accumulo.fate.AdminUtil)2