Search in sources :

Example 1 with ClientInfo

use of org.apache.accumulo.core.clientImpl.ClientInfo in project accumulo by apache.

the class ZooKeeperInstance method getConnector.

@Override
public Connector getConnector(String principal, AuthenticationToken token) throws AccumuloException, AccumuloSecurityException {
    Properties properties = ClientConfConverter.toProperties(clientConf);
    properties.setProperty(ClientProperty.AUTH_PRINCIPAL.getKey(), principal);
    properties.setProperty(ClientProperty.INSTANCE_NAME.getKey(), getInstanceName());
    ClientInfo info = new ClientInfoImpl(properties, token);
    AccumuloConfiguration serverConf = ClientConfConverter.toAccumuloConf(properties);
    return new org.apache.accumulo.core.clientImpl.ConnectorImpl(new ClientContext(SingletonReservation.noop(), info, serverConf));
}
Also used : ClientInfoImpl(org.apache.accumulo.core.clientImpl.ClientInfoImpl) ClientContext(org.apache.accumulo.core.clientImpl.ClientContext) ClientInfo(org.apache.accumulo.core.clientImpl.ClientInfo) Properties(java.util.Properties) AccumuloConfiguration(org.apache.accumulo.core.conf.AccumuloConfiguration)

Example 2 with ClientInfo

use of org.apache.accumulo.core.clientImpl.ClientInfo in project accumulo by apache.

the class AccumuloClientIT method testAccumuloClientBuilder.

@Test
public void testAccumuloClientBuilder() throws Exception {
    AccumuloClient c = Accumulo.newClient().from(getClientProps()).build();
    String instanceName = getClientInfo().getInstanceName();
    String zookeepers = getClientInfo().getZooKeepers();
    ClusterUser testuser1 = getUser(0);
    final String user1 = testuser1.getPrincipal();
    final String password1 = testuser1.getPassword();
    c.securityOperations().createLocalUser(user1, new PasswordToken(password1));
    AccumuloClient client = Accumulo.newClient().to(instanceName, zookeepers).as(user1, password1).zkTimeout(1234).build();
    Properties props = client.properties();
    assertFalse(props.containsKey(ClientProperty.AUTH_TOKEN.getKey()));
    ClientInfo info = ClientInfo.from(client.properties());
    assertEquals(instanceName, info.getInstanceName());
    assertEquals(zookeepers, info.getZooKeepers());
    assertEquals(user1, client.whoami());
    assertEquals(1234, info.getZooKeepersSessionTimeOut());
    props = Accumulo.newClientProperties().to(instanceName, zookeepers).as(user1, password1).build();
    assertTrue(props.containsKey(ClientProperty.AUTH_TOKEN.getKey()));
    assertEquals(password1, props.get(ClientProperty.AUTH_TOKEN.getKey()));
    assertEquals("password", props.get(ClientProperty.AUTH_TYPE.getKey()));
    assertEquals(instanceName, props.getProperty(ClientProperty.INSTANCE_NAME.getKey()));
    info = ClientInfo.from(props);
    assertEquals(instanceName, info.getInstanceName());
    assertEquals(zookeepers, info.getZooKeepers());
    assertEquals(user1, info.getPrincipal());
    assertTrue(info.getAuthenticationToken() instanceof PasswordToken);
    props = new Properties();
    props.put(ClientProperty.INSTANCE_NAME.getKey(), instanceName);
    props.put(ClientProperty.INSTANCE_ZOOKEEPERS.getKey(), zookeepers);
    props.put(ClientProperty.AUTH_PRINCIPAL.getKey(), user1);
    props.put(ClientProperty.INSTANCE_ZOOKEEPERS_TIMEOUT.getKey(), "22s");
    ClientProperty.setPassword(props, password1);
    client.close();
    client = Accumulo.newClient().from(props).build();
    info = ClientInfo.from(client.properties());
    assertEquals(instanceName, info.getInstanceName());
    assertEquals(zookeepers, info.getZooKeepers());
    assertEquals(user1, client.whoami());
    assertEquals(22000, info.getZooKeepersSessionTimeOut());
    ClusterUser testuser2 = getUser(1);
    final String user2 = testuser2.getPrincipal();
    final String password2 = testuser2.getPassword();
    c.securityOperations().createLocalUser(user2, new PasswordToken(password2));
    AccumuloClient client2 = Accumulo.newClient().from(client.properties()).as(user2, new PasswordToken(password2)).build();
    info = ClientInfo.from(client2.properties());
    assertEquals(instanceName, info.getInstanceName());
    assertEquals(zookeepers, info.getZooKeepers());
    assertEquals(user2, client2.whoami());
    assertEquals(user2, info.getPrincipal());
    c.close();
    client.close();
    client2.close();
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) ClusterUser(org.apache.accumulo.cluster.ClusterUser) ClientInfo(org.apache.accumulo.core.clientImpl.ClientInfo) Properties(java.util.Properties) Test(org.junit.Test)

Example 3 with ClientInfo

use of org.apache.accumulo.core.clientImpl.ClientInfo in project accumulo by apache.

the class ShellServerIT method exporttableImporttable.

@SuppressFBWarnings(value = "PATH_TRAVERSAL_IN", justification = "path provided by test")
@Test
public void exporttableImporttable() throws Exception {
    final String table = getUniqueNames(1)[0];
    final String table2 = table + "2";
    // exporttable / importtable
    ts.exec("createtable " + table + " -evc", true);
    make10();
    ts.exec("addsplits row5", true);
    ts.exec("config -t " + table + " -s table.split.threshold=345M", true);
    ts.exec("offline " + table, true);
    File exportDir = new File(rootPath, "ShellServerIT.export");
    String exportUri = "file://" + exportDir;
    String localTmp = "file://" + new File(rootPath, "ShellServerIT.tmp");
    ts.exec("exporttable -t " + table + " " + exportUri, true);
    DistCp cp = newDistCp(new Configuration(false));
    String import_ = "file://" + new File(rootPath, "ShellServerIT.import");
    ClientInfo info = ClientInfo.from(getCluster().getClientProperties());
    if (info.saslEnabled()) {
        // DistCp bugs out trying to get a fs delegation token to perform the cp. Just copy it
        // ourselves by hand.
        FileSystem fs = getCluster().getFileSystem();
        FileSystem localFs = FileSystem.getLocal(new Configuration(false));
        // Path on local fs to cp into
        Path localTmpPath = new Path(localTmp);
        localFs.mkdirs(localTmpPath);
        // Path in remote fs to importtable from
        Path importDir = new Path(import_);
        fs.mkdirs(importDir);
        // Implement a poor-man's DistCp
        try (BufferedReader reader = new BufferedReader(new FileReader(new File(exportDir, "distcp.txt"), UTF_8))) {
            for (String line; (line = reader.readLine()) != null; ) {
                Path exportedFile = new Path(line);
                // There isn't a cp on FileSystem??
                log.info("Copying {} to {}", line, localTmpPath);
                fs.copyToLocalFile(exportedFile, localTmpPath);
                Path tmpFile = new Path(localTmpPath, exportedFile.getName());
                log.info("Moving {} to the import directory {}", tmpFile, importDir);
                fs.moveFromLocalFile(tmpFile, importDir);
            }
        }
    } else {
        String[] distCpArgs = { "-f", exportUri + "/distcp.txt", import_ };
        assertEquals("Failed to run distcp: " + Arrays.toString(distCpArgs), 0, cp.run(distCpArgs));
    }
    ts.exec("importtable " + table2 + " " + import_, true);
    ts.exec("config -t " + table2 + " -np", true, "345M", true);
    ts.exec("getsplits -t " + table2, true, "row5", true);
    ts.exec("constraint --list -t " + table2, true, "VisibilityConstraint=2", true);
    ts.exec("online " + table, true);
    ts.exec("deletetable -f " + table, true);
    ts.exec("deletetable -f " + table2, true);
}
Also used : Path(org.apache.hadoop.fs.Path) DistCp(org.apache.hadoop.tools.DistCp) Configuration(org.apache.hadoop.conf.Configuration) DefaultConfiguration(org.apache.accumulo.core.conf.DefaultConfiguration) AccumuloConfiguration(org.apache.accumulo.core.conf.AccumuloConfiguration) FileSystem(org.apache.hadoop.fs.FileSystem) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) ClientInfo(org.apache.accumulo.core.clientImpl.ClientInfo) File(java.io.File) Test(org.junit.Test) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 4 with ClientInfo

use of org.apache.accumulo.core.clientImpl.ClientInfo in project accumulo by apache.

the class AccumuloInputFormatIT method testCorrectRangeInputSplits.

@Test
public void testCorrectRangeInputSplits() throws Exception {
    Job job = Job.getInstance();
    String table = getUniqueNames(1)[0];
    Authorizations auths = new Authorizations("foo");
    Collection<Pair<Text, Text>> fetchColumns = Collections.singleton(new Pair<>(new Text("foo"), new Text("bar")));
    boolean isolated = true, localIters = true;
    Level level = Level.WARN;
    try (AccumuloClient accumuloClient = Accumulo.newClient().from(getClientProps()).build()) {
        accumuloClient.tableOperations().create(table);
        ClientInfo ci = getClientInfo();
        org.apache.accumulo.core.client.mapreduce.AccumuloInputFormat.setZooKeeperInstance(job, ci.getInstanceName(), ci.getZooKeepers());
        org.apache.accumulo.core.client.mapreduce.AccumuloInputFormat.setConnectorInfo(job, ci.getPrincipal(), ci.getAuthenticationToken());
        org.apache.accumulo.core.client.mapreduce.AccumuloInputFormat.setInputTableName(job, table);
        org.apache.accumulo.core.client.mapreduce.AccumuloInputFormat.setScanAuthorizations(job, auths);
        org.apache.accumulo.core.client.mapreduce.AccumuloInputFormat.setScanIsolation(job, isolated);
        org.apache.accumulo.core.client.mapreduce.AccumuloInputFormat.setLocalIterators(job, localIters);
        org.apache.accumulo.core.client.mapreduce.AccumuloInputFormat.fetchColumns(job, fetchColumns);
        org.apache.accumulo.core.client.mapreduce.AccumuloInputFormat.setLogLevel(job, level);
        org.apache.accumulo.core.client.mapreduce.AccumuloInputFormat aif = new org.apache.accumulo.core.client.mapreduce.AccumuloInputFormat();
        List<InputSplit> splits = aif.getSplits(job);
        assertEquals(1, splits.size());
        InputSplit split = splits.get(0);
        assertEquals(org.apache.accumulo.core.client.mapreduce.RangeInputSplit.class, split.getClass());
        org.apache.accumulo.core.client.mapreduce.RangeInputSplit risplit = (org.apache.accumulo.core.client.mapreduce.RangeInputSplit) split;
        assertEquals(table, risplit.getTableName());
        assertEquals(isolated, risplit.isIsolatedScan());
        assertEquals(localIters, risplit.usesLocalIterators());
        assertEquals(fetchColumns, risplit.getFetchedColumns());
        assertEquals(level, risplit.getLogLevel());
    }
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) Authorizations(org.apache.accumulo.core.security.Authorizations) Text(org.apache.hadoop.io.Text) Level(org.apache.log4j.Level) ClientInfo(org.apache.accumulo.core.clientImpl.ClientInfo) Job(org.apache.hadoop.mapreduce.Job) InputSplit(org.apache.hadoop.mapreduce.InputSplit) Pair(org.apache.accumulo.core.util.Pair) Test(org.junit.Test)

Example 5 with ClientInfo

use of org.apache.accumulo.core.clientImpl.ClientInfo in project accumulo by apache.

the class ConfiguratorBaseTest method testSetClientProperties.

@Test
public void testSetClientProperties() {
    Configuration conf = new Configuration();
    Properties props = Accumulo.newClientProperties().to("myinstance", "myzookeepers").as("user", "pass").build();
    assertFalse(ConfiguratorBase.isClientConfigured(this.getClass(), conf));
    ConfiguratorBase.setClientProperties(this.getClass(), conf, props, null);
    assertTrue(ConfiguratorBase.isClientConfigured(this.getClass(), conf));
    Properties props2 = ConfiguratorBase.getClientProperties(this.getClass(), conf);
    ClientInfo info2 = ClientInfo.from(props2);
    assertEquals("myinstance", info2.getInstanceName());
    assertEquals("myzookeepers", info2.getZooKeepers());
    assertEquals("user", info2.getPrincipal());
    assertTrue(info2.getAuthenticationToken() instanceof PasswordToken);
}
Also used : PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) Configuration(org.apache.hadoop.conf.Configuration) ClientInfo(org.apache.accumulo.core.clientImpl.ClientInfo) Properties(java.util.Properties) Test(org.junit.Test)

Aggregations

ClientInfo (org.apache.accumulo.core.clientImpl.ClientInfo)17 Test (org.junit.Test)13 AccumuloClient (org.apache.accumulo.core.client.AccumuloClient)11 Properties (java.util.Properties)5 Text (org.apache.hadoop.io.Text)5 ClusterControl (org.apache.accumulo.cluster.ClusterControl)3 ZooCache (org.apache.accumulo.fate.zookeeper.ZooCache)3 ZooReader (org.apache.accumulo.fate.zookeeper.ZooReader)3 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)2 IOException (java.io.IOException)2 ClusterUser (org.apache.accumulo.cluster.ClusterUser)2 PasswordToken (org.apache.accumulo.core.client.security.tokens.PasswordToken)2 ClientContext (org.apache.accumulo.core.clientImpl.ClientContext)2 AccumuloConfiguration (org.apache.accumulo.core.conf.AccumuloConfiguration)2 Mutation (org.apache.accumulo.core.data.Mutation)2 Range (org.apache.accumulo.core.data.Range)2 Authorizations (org.apache.accumulo.core.security.Authorizations)2 Pair (org.apache.accumulo.core.util.Pair)2 ServerContext (org.apache.accumulo.server.ServerContext)2 VerifyParams (org.apache.accumulo.test.VerifyIngest.VerifyParams)2