Search in sources :

Example 51 with Authorizations

use of org.apache.accumulo.core.security.Authorizations in project accumulo by apache.

the class MultiTableBatchWriterIT method testTableRenameSameWriters.

@Test
public void testTableRenameSameWriters() throws Exception {
    try {
        final String[] names = getUniqueNames(4);
        final String table1 = names[0], table2 = names[1];
        final String newTable1 = names[2], newTable2 = names[3];
        TableOperations tops = accumuloClient.tableOperations();
        tops.create(table1);
        tops.create(table2);
        BatchWriter bw1 = mtbw.getBatchWriter(table1), bw2 = mtbw.getBatchWriter(table2);
        Mutation m1 = new Mutation("foo");
        m1.put("col1", "", "val1");
        m1.put("col2", "", "val2");
        bw1.addMutation(m1);
        bw2.addMutation(m1);
        tops.rename(table1, newTable1);
        tops.rename(table2, newTable2);
        Mutation m2 = new Mutation("bar");
        m2.put("col1", "", "val1");
        m2.put("col2", "", "val2");
        bw1.addMutation(m2);
        bw2.addMutation(m2);
        mtbw.close();
        Map<Entry<String, String>, String> expectations = new HashMap<>();
        expectations.put(Maps.immutableEntry("foo", "col1"), "val1");
        expectations.put(Maps.immutableEntry("foo", "col2"), "val2");
        expectations.put(Maps.immutableEntry("bar", "col1"), "val1");
        expectations.put(Maps.immutableEntry("bar", "col2"), "val2");
        for (String table : Arrays.asList(newTable1, newTable2)) {
            try (Scanner s = accumuloClient.createScanner(table, new Authorizations())) {
                s.setRange(new Range());
                Map<Entry<String, String>, String> actual = new HashMap<>();
                for (Entry<Key, Value> entry : s) {
                    actual.put(Maps.immutableEntry(entry.getKey().getRow().toString(), entry.getKey().getColumnFamily().toString()), entry.getValue().toString());
                }
                assertEquals("Differing results for " + table, expectations, actual);
            }
        }
    } finally {
        if (mtbw != null) {
            mtbw.close();
        }
    }
}
Also used : Scanner(org.apache.accumulo.core.client.Scanner) Authorizations(org.apache.accumulo.core.security.Authorizations) HashMap(java.util.HashMap) Range(org.apache.accumulo.core.data.Range) Entry(java.util.Map.Entry) TableOperations(org.apache.accumulo.core.client.admin.TableOperations) Value(org.apache.accumulo.core.data.Value) MultiTableBatchWriter(org.apache.accumulo.core.client.MultiTableBatchWriter) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) Key(org.apache.accumulo.core.data.Key) Test(org.junit.Test)

Example 52 with Authorizations

use of org.apache.accumulo.core.security.Authorizations in project incubator-rya by apache.

the class AccumuloIndexingConfigurationTest method testBuilderFromProperties.

@Test
public void testBuilderFromProperties() throws FileNotFoundException, IOException {
    String prefix = "rya_";
    String auth = "U";
    String visibility = "U";
    String user = "user";
    String password = "password";
    String instance = "instance";
    String zookeeper = "zookeeper";
    boolean useMock = false;
    boolean useComposite = true;
    boolean usePrefixHash = true;
    boolean useInference = true;
    boolean displayPlan = false;
    boolean useMetadata = true;
    Set<RyaURI> metaProperties = new HashSet<>(Arrays.asList(new RyaURI("urn:123"), new RyaURI("urn:456")));
    Properties props = new Properties();
    props.load(new FileInputStream("src/test/resources/accumulo_rya_indexing.properties"));
    AccumuloIndexingConfiguration conf = AccumuloIndexingConfiguration.fromProperties(props);
    assertEquals(conf.getTablePrefix(), prefix);
    assertEquals(conf.getCv(), visibility);
    assertEquals(conf.getAuthorizations(), new Authorizations(auth));
    assertEquals(conf.isInfer(), useInference);
    assertEquals(conf.isUseCompositeCardinality(), useComposite);
    assertEquals(conf.isDisplayQueryPlan(), displayPlan);
    assertEquals(conf.getAccumuloInstance(), instance);
    assertEquals(conf.getAccumuloPassword(), password);
    assertEquals(conf.getAccumuloUser(), user);
    assertEquals(conf.getAccumuloZookeepers(), zookeeper);
    assertEquals(conf.getUseMockAccumulo(), useMock);
    assertEquals(conf.isPrefixRowsWithHash(), usePrefixHash);
    assertTrue(Arrays.equals(conf.getAccumuloFreeTextPredicates(), new String[] { "http://pred1", "http://pred2" }));
    assertTrue(Arrays.equals(conf.getAccumuloTemporalPredicates(), new String[] { "http://pred3", "http://pred4" }));
    assertEquals(conf.getPcjTables(), Arrays.asList("table1", "table2"));
    assertEquals(conf.getUsePCJ(), false);
    assertEquals(conf.getUseOptimalPCJ(), true);
    assertEquals(conf.getUseEntity(), true);
    assertEquals(conf.getUseFreetext(), true);
    assertEquals(conf.getUseTemporal(), true);
    assertEquals(conf.getUsePCJUpdater(), true);
    assertEquals(conf.getFluoAppUpdaterName(), "fluo");
    assertEquals(conf.getUseStatementMetadata(), useMetadata);
    assertEquals(conf.getStatementMetadataProperties(), metaProperties);
}
Also used : RyaURI(org.apache.rya.api.domain.RyaURI) Authorizations(org.apache.accumulo.core.security.Authorizations) Properties(java.util.Properties) FileInputStream(java.io.FileInputStream) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 53 with Authorizations

use of org.apache.accumulo.core.security.Authorizations in project incubator-rya by apache.

the class AccumuloIndexingConfigurationTest method testBuilder.

@Test
public void testBuilder() {
    String prefix = "rya_";
    String auth = "U";
    String visibility = "U";
    String user = "user";
    String password = "password";
    String instance = "instance";
    String zookeeper = "zookeeper";
    boolean useMock = false;
    boolean useComposite = true;
    boolean usePrefixHash = true;
    boolean useInference = true;
    boolean displayPlan = false;
    AccumuloIndexingConfiguration conf = AccumuloIndexingConfiguration.builder().setAuths(auth).setVisibilities(visibility).setRyaPrefix(prefix).setUseInference(useInference).setUseCompositeCardinality(useComposite).setDisplayQueryPlan(displayPlan).setAccumuloInstance(instance).setAccumuloPassword(password).setAccumuloUser(user).setAccumuloZooKeepers(zookeeper).setUseMockAccumulo(useMock).setUseAccumuloPrefixHashing(usePrefixHash).setAccumuloFreeTextPredicates("http://pred1", "http://pred2").setAccumuloTemporalPredicates("http://pred3", "http://pred4").setUseAccumuloTemporalIndex(true).setUseAccumuloEntityIndex(true).setUseAccumuloFreetextIndex(true).setPcjUpdaterFluoAppName("fluo").setUseOptimalPcj(true).setPcjTables("table1", "table2").build();
    assertEquals(conf.getTablePrefix(), prefix);
    assertEquals(conf.getCv(), visibility);
    assertEquals(conf.getAuthorizations(), new Authorizations(auth));
    assertEquals(conf.isInfer(), useInference);
    assertEquals(conf.isUseCompositeCardinality(), useComposite);
    assertEquals(conf.isDisplayQueryPlan(), displayPlan);
    assertEquals(conf.getAccumuloInstance(), instance);
    assertEquals(conf.getAccumuloPassword(), password);
    assertEquals(conf.getAccumuloUser(), user);
    assertEquals(conf.getAccumuloZookeepers(), zookeeper);
    assertEquals(conf.getUseMockAccumulo(), useMock);
    assertEquals(conf.isPrefixRowsWithHash(), usePrefixHash);
    assertTrue(Arrays.equals(conf.getAccumuloFreeTextPredicates(), new String[] { "http://pred1", "http://pred2" }));
    assertTrue(Arrays.equals(conf.getAccumuloTemporalPredicates(), new String[] { "http://pred3", "http://pred4" }));
    assertEquals(conf.getPcjTables(), Arrays.asList("table1", "table2"));
    assertEquals(conf.getUsePCJ(), false);
    assertEquals(conf.getUseOptimalPCJ(), true);
    assertEquals(conf.getUseEntity(), true);
    assertEquals(conf.getUseFreetext(), true);
    assertEquals(conf.getUseTemporal(), true);
    assertEquals(conf.getUsePCJUpdater(), true);
    assertEquals(conf.getFluoAppUpdaterName(), "fluo");
}
Also used : Authorizations(org.apache.accumulo.core.security.Authorizations) Test(org.junit.Test)

Example 54 with Authorizations

use of org.apache.accumulo.core.security.Authorizations in project incubator-rya by apache.

the class RyaOutputFormatTest method testEntityIndexing.

@Test
public void testEntityIndexing() throws Exception {
    final EntityCentricIndex entity = new EntityCentricIndex();
    entity.setConf(conf);
    final RyaStatement input = RyaStatement.builder().setSubject(new RyaURI(GRAPH + ":s")).setPredicate(new RyaURI(GRAPH + ":p")).setObject(new RyaURI(GRAPH + ":o")).build();
    RyaOutputFormat.setCoreTablesEnabled(job, false);
    RyaOutputFormat.setFreeTextEnabled(job, false);
    RyaOutputFormat.setTemporalEnabled(job, false);
    RyaOutputFormat.setEntityEnabled(job, true);
    write(input);
    entity.close();
    final Set<Statement> expected = new HashSet<>();
    final Set<Statement> inserted = new HashSet<>();
    expected.add(RyaToRdfConversions.convertStatement(input));
    final String table = EntityCentricIndex.getTableName(conf);
    final Scanner scanner = connector.createScanner(table, new Authorizations(CV));
    for (final Map.Entry<Key, Value> row : scanner) {
        System.out.println(row);
        inserted.add(RyaToRdfConversions.convertStatement(EntityCentricIndex.deserializeStatement(row.getKey(), row.getValue())));
    }
    Assert.assertEquals(expected, inserted);
}
Also used : Scanner(org.apache.accumulo.core.client.Scanner) Authorizations(org.apache.accumulo.core.security.Authorizations) Statement(org.openrdf.model.Statement) RyaStatement(org.apache.rya.api.domain.RyaStatement) EntityCentricIndex(org.apache.rya.indexing.accumulo.entity.EntityCentricIndex) RyaStatement(org.apache.rya.api.domain.RyaStatement) RyaURI(org.apache.rya.api.domain.RyaURI) Value(org.apache.accumulo.core.data.Value) Map(java.util.Map) Key(org.apache.accumulo.core.data.Key) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 55 with Authorizations

use of org.apache.accumulo.core.security.Authorizations in project incubator-rya by apache.

the class AbstractAccumuloMRTool method init.

/**
 * Initializes configuration parameters, checking that required parameters
 * are found and ensuring that options corresponding to multiple property
 * names are set consistently. Requires at least that the username,
 * password, and instance name are all configured. Zookeeper hosts must be
 * configured if not using a mock instance. Table prefix, if not provided,
 * will be set to {@link RdfCloudTripleStoreConstants#TBL_PRFX_DEF}. Should
 * be called before configuring input/output. See {@link MRUtils} for
 * configuration properties.
 */
protected void init() {
    // Load configuration parameters
    zk = MRUtils.getACZK(conf);
    instance = MRUtils.getACInstance(conf);
    userName = MRUtils.getACUserName(conf);
    pwd = MRUtils.getACPwd(conf);
    mock = MRUtils.getACMock(conf, false);
    ttl = MRUtils.getACTtl(conf);
    tablePrefix = MRUtils.getTablePrefix(conf);
    rdfTableLayout = MRUtils.getTableLayout(conf, TABLE_LAYOUT.OSP);
    hdfsInput = conf.getBoolean(MRUtils.AC_HDFS_INPUT_PROP, false);
    // Set authorizations if specified
    String authString = conf.get(MRUtils.AC_AUTH_PROP);
    if (authString != null && !authString.isEmpty()) {
        authorizations = new Authorizations(authString.split(","));
        // for consistency
        conf.set(ConfigUtils.CLOUDBASE_AUTHS, authString);
    } else {
        authorizations = AccumuloRdfConstants.ALL_AUTHORIZATIONS;
    }
    // Set table prefix to the default if not set
    if (tablePrefix == null) {
        tablePrefix = RdfCloudTripleStoreConstants.TBL_PRFX_DEF;
        MRUtils.setTablePrefix(conf, tablePrefix);
    }
    // Check for required configuration parameters
    Preconditions.checkNotNull(instance, "Accumulo instance name [" + MRUtils.AC_INSTANCE_PROP + "] not set.");
    Preconditions.checkNotNull(userName, "Accumulo username [" + MRUtils.AC_USERNAME_PROP + "] not set.");
    Preconditions.checkNotNull(pwd, "Accumulo password [" + MRUtils.AC_PWD_PROP + "] not set.");
    Preconditions.checkNotNull(tablePrefix, "Table prefix [" + MRUtils.TABLE_PREFIX_PROPERTY + "] not set.");
    RdfCloudTripleStoreConstants.prefixTables(tablePrefix);
    // If connecting to real accumulo, set additional parameters and require zookeepers
    if (!mock) {
        Preconditions.checkNotNull(zk, "Zookeeper hosts not set (" + MRUtils.AC_ZK_PROP + ")");
        conf.setBoolean("mapred.map.tasks.speculative.execution", false);
        conf.setBoolean("mapred.reduce.tasks.speculative.execution", false);
        if (conf.get(MRUtils.HADOOP_IO_SORT_MB) == null) {
            conf.setInt(MRUtils.HADOOP_IO_SORT_MB, DEFAULT_IO_SORT_MB);
        }
        // for consistency
        conf.set(ConfigUtils.CLOUDBASE_ZOOKEEPERS, zk);
    }
    // Ensure consistency between alternative configuration properties
    conf.set(ConfigUtils.CLOUDBASE_INSTANCE, instance);
    conf.set(ConfigUtils.CLOUDBASE_USER, userName);
    conf.set(ConfigUtils.CLOUDBASE_PASSWORD, pwd);
    conf.setBoolean(ConfigUtils.USE_MOCK_INSTANCE, mock);
    conf.set(RdfCloudTripleStoreConfiguration.CONF_TBL_PREFIX, tablePrefix);
}
Also used : Authorizations(org.apache.accumulo.core.security.Authorizations)

Aggregations

Authorizations (org.apache.accumulo.core.security.Authorizations)242 Test (org.junit.Test)118 Scanner (org.apache.accumulo.core.client.Scanner)117 Key (org.apache.accumulo.core.data.Key)113 Value (org.apache.accumulo.core.data.Value)112 Text (org.apache.hadoop.io.Text)97 Mutation (org.apache.accumulo.core.data.Mutation)74 BatchWriter (org.apache.accumulo.core.client.BatchWriter)70 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)68 Range (org.apache.accumulo.core.data.Range)59 Map (java.util.Map)53 Entry (java.util.Map.Entry)47 PasswordToken (org.apache.accumulo.core.client.security.tokens.PasswordToken)39 Connector (org.apache.accumulo.core.client.Connector)34 ArrayList (java.util.ArrayList)31 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)30 AccumuloClient (org.apache.accumulo.core.client.AccumuloClient)29 AccumuloException (org.apache.accumulo.core.client.AccumuloException)28 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)26 Configuration (org.apache.hadoop.conf.Configuration)24