Search in sources :

Example 1 with ClientProperty

use of org.apache.accumulo.core.client.ClientConfiguration.ClientProperty in project accumulo by apache.

the class AccumuloInputFormatIT method testGetSplits.

/**
 * Tests several different paths through the getSplits() method by setting different properties and verifying the results.
 */
@Test
public void testGetSplits() throws Exception {
    Connector conn = getConnector();
    String table = getUniqueNames(1)[0];
    conn.tableOperations().create(table);
    insertData(table, currentTimeMillis());
    ClientConfiguration clientConf = cluster.getClientConfig();
    AccumuloConfiguration clusterClientConf = new ConfigurationCopy(DefaultConfiguration.getInstance());
    // Pass SSL and CredentialProvider options into the ClientConfiguration given to AccumuloInputFormat
    boolean sslEnabled = Boolean.valueOf(clusterClientConf.get(Property.INSTANCE_RPC_SSL_ENABLED));
    if (sslEnabled) {
        ClientProperty[] sslProperties = new ClientProperty[] { ClientProperty.INSTANCE_RPC_SSL_ENABLED, ClientProperty.INSTANCE_RPC_SSL_CLIENT_AUTH, ClientProperty.RPC_SSL_KEYSTORE_PATH, ClientProperty.RPC_SSL_KEYSTORE_TYPE, ClientProperty.RPC_SSL_KEYSTORE_PASSWORD, ClientProperty.RPC_SSL_TRUSTSTORE_PATH, ClientProperty.RPC_SSL_TRUSTSTORE_TYPE, ClientProperty.RPC_SSL_TRUSTSTORE_PASSWORD, ClientProperty.RPC_USE_JSSE, ClientProperty.GENERAL_SECURITY_CREDENTIAL_PROVIDER_PATHS };
        for (ClientProperty prop : sslProperties) {
            // The default property is returned if it's not in the ClientConfiguration so we don't have to check if the value is actually defined
            clientConf.setProperty(prop, clusterClientConf.get(prop.getKey()));
        }
    }
    Job job = Job.getInstance();
    AccumuloInputFormat.setInputTableName(job, table);
    AccumuloInputFormat.setZooKeeperInstance(job, clientConf);
    AccumuloInputFormat.setConnectorInfo(job, getAdminPrincipal(), getAdminToken());
    // split table
    TreeSet<Text> splitsToAdd = new TreeSet<>();
    for (int i = 0; i < 10000; i += 1000) splitsToAdd.add(new Text(String.format("%09d", i)));
    conn.tableOperations().addSplits(table, splitsToAdd);
    // wait for splits to be propagated
    sleepUninterruptibly(500, TimeUnit.MILLISECONDS);
    // get splits without setting any range
    Collection<Text> actualSplits = conn.tableOperations().listSplits(table);
    List<InputSplit> splits = inputFormat.getSplits(job);
    // No ranges set on the job so it'll start with -inf
    assertEquals(actualSplits.size() + 1, splits.size());
    // set ranges and get splits
    List<Range> ranges = new ArrayList<>();
    for (Text text : actualSplits) ranges.add(new Range(text));
    AccumuloInputFormat.setRanges(job, ranges);
    splits = inputFormat.getSplits(job);
    assertEquals(actualSplits.size(), splits.size());
    // offline mode
    AccumuloInputFormat.setOfflineTableScan(job, true);
    try {
        inputFormat.getSplits(job);
        fail("An exception should have been thrown");
    } catch (IOException e) {
    }
    conn.tableOperations().offline(table, true);
    splits = inputFormat.getSplits(job);
    assertEquals(actualSplits.size(), splits.size());
    // auto adjust ranges
    ranges = new ArrayList<>();
    for (int i = 0; i < 5; i++) // overlapping ranges
    ranges.add(new Range(String.format("%09d", i), String.format("%09d", i + 2)));
    AccumuloInputFormat.setRanges(job, ranges);
    splits = inputFormat.getSplits(job);
    assertEquals(2, splits.size());
    AccumuloInputFormat.setAutoAdjustRanges(job, false);
    splits = inputFormat.getSplits(job);
    assertEquals(ranges.size(), splits.size());
    // BatchScan not available for offline scans
    AccumuloInputFormat.setBatchScan(job, true);
    // Reset auto-adjust ranges too
    AccumuloInputFormat.setAutoAdjustRanges(job, true);
    AccumuloInputFormat.setOfflineTableScan(job, true);
    try {
        inputFormat.getSplits(job);
        fail("An exception should have been thrown");
    } catch (IllegalArgumentException e) {
    }
    conn.tableOperations().online(table, true);
    AccumuloInputFormat.setOfflineTableScan(job, false);
    // test for resumption of success
    splits = inputFormat.getSplits(job);
    assertEquals(2, splits.size());
    // BatchScan not available with isolated iterators
    AccumuloInputFormat.setScanIsolation(job, true);
    try {
        inputFormat.getSplits(job);
        fail("An exception should have been thrown");
    } catch (IllegalArgumentException e) {
    }
    AccumuloInputFormat.setScanIsolation(job, false);
    // test for resumption of success
    splits = inputFormat.getSplits(job);
    assertEquals(2, splits.size());
    // BatchScan not available with local iterators
    AccumuloInputFormat.setLocalIterators(job, true);
    try {
        inputFormat.getSplits(job);
        fail("An exception should have been thrown");
    } catch (IllegalArgumentException e) {
    }
    AccumuloInputFormat.setLocalIterators(job, false);
    // Check we are getting back correct type pf split
    conn.tableOperations().online(table);
    splits = inputFormat.getSplits(job);
    for (InputSplit split : splits) assert (split instanceof BatchInputSplit);
    // We should divide along the tablet lines similar to when using `setAutoAdjustRanges(job, true)`
    assertEquals(2, splits.size());
}
Also used : Connector(org.apache.accumulo.core.client.Connector) ConfigurationCopy(org.apache.accumulo.core.conf.ConfigurationCopy) ClientProperty(org.apache.accumulo.core.client.ClientConfiguration.ClientProperty) ArrayList(java.util.ArrayList) BatchInputSplit(org.apache.accumulo.core.client.mapreduce.impl.BatchInputSplit) Text(org.apache.hadoop.io.Text) IOException(java.io.IOException) Range(org.apache.accumulo.core.data.Range) TreeSet(java.util.TreeSet) Job(org.apache.hadoop.mapreduce.Job) BatchInputSplit(org.apache.accumulo.core.client.mapreduce.impl.BatchInputSplit) RangeInputSplit(org.apache.accumulo.core.client.mapreduce.RangeInputSplit) InputSplit(org.apache.hadoop.mapreduce.InputSplit) ClientConfiguration(org.apache.accumulo.core.client.ClientConfiguration) AccumuloConfiguration(org.apache.accumulo.core.conf.AccumuloConfiguration) Test(org.junit.Test)

Example 2 with ClientProperty

use of org.apache.accumulo.core.client.ClientConfiguration.ClientProperty in project accumulo by apache.

the class SaslConnectionParams method getProperties.

protected static Map<String, String> getProperties(AccumuloConfiguration conf) {
    final Map<String, String> clientProperties = new HashMap<>();
    // Servers will only have the full principal in their configuration -- parse the
    // primary and realm from it.
    final String serverPrincipal = conf.get(Property.GENERAL_KERBEROS_PRINCIPAL);
    final KerberosName krbName;
    try {
        krbName = new KerberosName(serverPrincipal);
        clientProperties.put(ClientProperty.KERBEROS_SERVER_PRIMARY.getKey(), krbName.getServiceName());
    } catch (Exception e) {
    // bad value or empty, assume we're not using kerberos
    }
    HashSet<String> clientKeys = new HashSet<>();
    for (ClientProperty prop : ClientProperty.values()) {
        clientKeys.add(prop.getKey());
    }
    String key;
    for (Entry<String, String> entry : conf) {
        key = entry.getKey();
        if (clientKeys.contains(key)) {
            clientProperties.put(key, entry.getValue());
        }
    }
    return clientProperties;
}
Also used : ClientProperty(org.apache.accumulo.core.client.ClientConfiguration.ClientProperty) HashMap(java.util.HashMap) KerberosName(org.apache.hadoop.security.authentication.util.KerberosName) IOException(java.io.IOException) HashSet(java.util.HashSet)

Aggregations

IOException (java.io.IOException)2 ClientProperty (org.apache.accumulo.core.client.ClientConfiguration.ClientProperty)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 TreeSet (java.util.TreeSet)1 ClientConfiguration (org.apache.accumulo.core.client.ClientConfiguration)1 Connector (org.apache.accumulo.core.client.Connector)1 RangeInputSplit (org.apache.accumulo.core.client.mapreduce.RangeInputSplit)1 BatchInputSplit (org.apache.accumulo.core.client.mapreduce.impl.BatchInputSplit)1 AccumuloConfiguration (org.apache.accumulo.core.conf.AccumuloConfiguration)1 ConfigurationCopy (org.apache.accumulo.core.conf.ConfigurationCopy)1 Range (org.apache.accumulo.core.data.Range)1 Text (org.apache.hadoop.io.Text)1 InputSplit (org.apache.hadoop.mapreduce.InputSplit)1 Job (org.apache.hadoop.mapreduce.Job)1 KerberosName (org.apache.hadoop.security.authentication.util.KerberosName)1 Test (org.junit.Test)1