Search in sources :

Example 6 with ZooReader

use of org.apache.accumulo.fate.zookeeper.ZooReader 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);
}
Also used : Connector(org.apache.accumulo.core.client.Connector) AuthenticationToken(org.apache.accumulo.core.client.security.tokens.AuthenticationToken) KerberosToken(org.apache.accumulo.core.client.security.tokens.KerberosToken) ZooCache(org.apache.accumulo.fate.zookeeper.ZooCache) IOException(java.io.IOException) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) ZooReader(org.apache.accumulo.fate.zookeeper.ZooReader) TestIngest(org.apache.accumulo.test.TestIngest) ClusterUser(org.apache.accumulo.cluster.ClusterUser) ClientConfiguration(org.apache.accumulo.core.client.ClientConfiguration) ClusterControl(org.apache.accumulo.cluster.ClusterControl) Test(org.junit.Test)

Example 7 with ZooReader

use of org.apache.accumulo.fate.zookeeper.ZooReader 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);
}
Also used : Connector(org.apache.accumulo.core.client.Connector) ZooReader(org.apache.accumulo.fate.zookeeper.ZooReader) ZooCache(org.apache.accumulo.fate.zookeeper.ZooCache) ClientConfiguration(org.apache.accumulo.core.client.ClientConfiguration) ClusterControl(org.apache.accumulo.cluster.ClusterControl) Test(org.junit.Test)

Example 8 with ZooReader

use of org.apache.accumulo.fate.zookeeper.ZooReader in project accumulo by apache.

the class ReplicationClient method getCoordinatorConnection.

public static ReplicationCoordinator.Client getCoordinatorConnection(ClientContext context) {
    Instance instance = context.getInstance();
    List<String> locations = instance.getMasterLocations();
    if (locations.size() == 0) {
        log.debug("No masters for replication to instance {}", instance.getInstanceName());
        return null;
    }
    // This is the master thrift service, we just want the hostname, not the port
    String masterThriftService = locations.get(0);
    if (masterThriftService.endsWith(":0")) {
        log.warn("Master found for {} did not have real location {}", instance.getInstanceName(), masterThriftService);
        return null;
    }
    String zkPath = ZooUtil.getRoot(instance) + Constants.ZMASTER_REPLICATION_COORDINATOR_ADDR;
    String replCoordinatorAddr;
    log.debug("Using ZooKeeper quorum at {} with path {} to find peer Master information", instance.getZooKeepers(), zkPath);
    // Get the coordinator port for the master we're trying to connect to
    try {
        ZooReader reader = new ZooReader(instance.getZooKeepers(), instance.getZooKeepersSessionTimeOut());
        replCoordinatorAddr = new String(reader.getData(zkPath, null), UTF_8);
    } catch (KeeperException | InterruptedException e) {
        log.error("Could not fetch remote coordinator port", e);
        return null;
    }
    // Throw the hostname and port through HostAndPort to get some normalization
    HostAndPort coordinatorAddr = HostAndPort.fromString(replCoordinatorAddr);
    log.debug("Connecting to master at {}", coordinatorAddr);
    try {
        // Master requests can take a long time: don't ever time out
        ReplicationCoordinator.Client client = ThriftUtil.getClientNoTimeout(new ReplicationCoordinator.Client.Factory(), coordinatorAddr, context);
        return client;
    } catch (TTransportException tte) {
        log.debug("Failed to connect to master coordinator service ({})", coordinatorAddr, tte);
        return null;
    }
}
Also used : Instance(org.apache.accumulo.core.client.Instance) TTransportException(org.apache.thrift.transport.TTransportException) ReplicationCoordinator(org.apache.accumulo.core.replication.thrift.ReplicationCoordinator) HostAndPort(org.apache.accumulo.core.util.HostAndPort) ZooReader(org.apache.accumulo.fate.zookeeper.ZooReader) TServiceClient(org.apache.thrift.TServiceClient) KeeperException(org.apache.zookeeper.KeeperException)

Example 9 with ZooReader

use of org.apache.accumulo.fate.zookeeper.ZooReader in project accumulo by apache.

the class ChangeSecret method verifyAccumuloIsDown.

private static void verifyAccumuloIsDown(Instance inst, String oldPassword) throws Exception {
    ZooReader zooReader = new ZooReaderWriter(inst.getZooKeepers(), inst.getZooKeepersSessionTimeOut(), oldPassword);
    String root = ZooUtil.getRoot(inst);
    final List<String> ephemerals = new ArrayList<>();
    recurse(zooReader, root, new Visitor() {

        @Override
        public void visit(ZooReader zoo, String path) throws Exception {
            Stat stat = zoo.getStatus(path);
            if (stat.getEphemeralOwner() != 0)
                ephemerals.add(path);
        }
    });
    if (ephemerals.size() > 0) {
        System.err.println("The following ephemeral nodes exist, something is still running:");
        for (String path : ephemerals) {
            System.err.println(path);
        }
        throw new Exception("Accumulo must be shut down in order to run this tool.");
    }
}
Also used : ZooReader(org.apache.accumulo.fate.zookeeper.ZooReader) Stat(org.apache.zookeeper.data.Stat) ZooReaderWriter(org.apache.accumulo.server.zookeeper.ZooReaderWriter) IZooReaderWriter(org.apache.accumulo.fate.zookeeper.IZooReaderWriter) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Example 10 with ZooReader

use of org.apache.accumulo.fate.zookeeper.ZooReader in project accumulo by apache.

the class ChangeSecret method rewriteZooKeeperInstance.

private static void rewriteZooKeeperInstance(final Instance inst, final String newInstanceId, String oldPass, String newPass) throws Exception {
    final ZooReaderWriter orig = new ZooReaderWriter(inst.getZooKeepers(), inst.getZooKeepersSessionTimeOut(), oldPass);
    final IZooReaderWriter new_ = new ZooReaderWriter(inst.getZooKeepers(), inst.getZooKeepersSessionTimeOut(), newPass);
    String root = ZooUtil.getRoot(inst);
    recurse(orig, root, new Visitor() {

        @Override
        public void visit(ZooReader zoo, String path) throws Exception {
            String newPath = path.replace(inst.getInstanceID(), newInstanceId);
            byte[] data = zoo.getData(path, null);
            List<ACL> acls = orig.getZooKeeper().getACL(path, new Stat());
            if (acls.containsAll(Ids.READ_ACL_UNSAFE)) {
                new_.putPersistentData(newPath, data, NodeExistsPolicy.FAIL);
            } else {
                // upgrade
                if (acls.containsAll(Ids.OPEN_ACL_UNSAFE)) {
                    // make user nodes private, they contain the user's password
                    String[] parts = path.split("/");
                    if (parts[parts.length - 2].equals("users")) {
                        new_.putPrivatePersistentData(newPath, data, NodeExistsPolicy.FAIL);
                    } else {
                        // everything else can have the readable acl
                        new_.putPersistentData(newPath, data, NodeExistsPolicy.FAIL);
                    }
                } else {
                    new_.putPrivatePersistentData(newPath, data, NodeExistsPolicy.FAIL);
                }
            }
        }
    });
    String path = "/accumulo/instances/" + inst.getInstanceName();
    orig.recursiveDelete(path, NodeMissingPolicy.SKIP);
    new_.putPersistentData(path, newInstanceId.getBytes(UTF_8), NodeExistsPolicy.OVERWRITE);
}
Also used : ZooReader(org.apache.accumulo.fate.zookeeper.ZooReader) Stat(org.apache.zookeeper.data.Stat) IZooReaderWriter(org.apache.accumulo.fate.zookeeper.IZooReaderWriter) ZooReaderWriter(org.apache.accumulo.server.zookeeper.ZooReaderWriter) IZooReaderWriter(org.apache.accumulo.fate.zookeeper.IZooReaderWriter) ArrayList(java.util.ArrayList) List(java.util.List) IOException(java.io.IOException)

Aggregations

ZooReader (org.apache.accumulo.fate.zookeeper.ZooReader)17 Test (org.junit.Test)11 Connector (org.apache.accumulo.core.client.Connector)6 Instance (org.apache.accumulo.core.client.Instance)6 IOException (java.io.IOException)5 ZooKeeperInstance (org.apache.accumulo.core.client.ZooKeeperInstance)4 ZooCache (org.apache.accumulo.fate.zookeeper.ZooCache)4 File (java.io.File)3 ClusterControl (org.apache.accumulo.cluster.ClusterControl)3 ClientConfiguration (org.apache.accumulo.core.client.ClientConfiguration)3 NewTableConfiguration (org.apache.accumulo.core.client.admin.NewTableConfiguration)3 PasswordToken (org.apache.accumulo.core.client.security.tokens.PasswordToken)3 Master (org.apache.accumulo.master.Master)3 TServerInstance (org.apache.accumulo.server.master.state.TServerInstance)3 Configuration (org.apache.hadoop.conf.Configuration)3 Path (org.apache.hadoop.fs.Path)3 BufferedOutputStream (java.io.BufferedOutputStream)2 FileOutputStream (java.io.FileOutputStream)2 Socket (java.net.Socket)2 ArrayList (java.util.ArrayList)2