Search in sources :

Example 66 with AccumuloRdfConfiguration

use of org.apache.rya.accumulo.AccumuloRdfConfiguration in project incubator-rya by apache.

the class AccumuloFreeTextIndexerTest method before.

@Before
public void before() throws Exception {
    conf = new AccumuloRdfConfiguration();
    conf.setBoolean(ConfigUtils.USE_MOCK_INSTANCE, true);
    conf.set(ConfigUtils.CLOUDBASE_USER, "USERNAME");
    conf.set(ConfigUtils.CLOUDBASE_PASSWORD, "PASS");
    conf.set(ConfigUtils.CLOUDBASE_AUTHS, "U");
    conf.setClass(ConfigUtils.TOKENIZER_CLASS, SimpleTokenizer.class, Tokenizer.class);
    conf.setTablePrefix("triplestore_");
    // If a table exists from last time, delete it.
    List<String> tableNames = AccumuloFreeTextIndexer.getTableNames(conf);
    for (String name : tableNames) {
        destroyTable(conf, name);
    }
// Tables are created in each test with setConf(conf)
}
Also used : AccumuloRdfConfiguration(org.apache.rya.accumulo.AccumuloRdfConfiguration) Before(org.junit.Before)

Example 67 with AccumuloRdfConfiguration

use of org.apache.rya.accumulo.AccumuloRdfConfiguration in project incubator-rya by apache.

the class StatementMetadataOptimizerTest method getConf.

private static RdfCloudTripleStoreConfiguration getConf(boolean useMongo) {
    RdfCloudTripleStoreConfiguration conf;
    Set<RyaURI> propertySet = new HashSet<>(Arrays.asList(new RyaURI("http://createdBy"), new RyaURI("http://createdOn")));
    if (useMongo) {
        MongoDBRdfConfiguration mConf = new MongoDBRdfConfiguration();
        mConf.setBoolean("sc.useMongo", true);
        mConf.setMongoHostname("localhost");
        mConf.setMongoPort("27017");
        mConf.setMongoDBName("rya_");
        conf = mConf;
    } else {
        conf = new AccumuloRdfConfiguration();
        conf.setBoolean(ConfigUtils.USE_MOCK_INSTANCE, true);
        conf.set(RdfCloudTripleStoreConfiguration.CONF_TBL_PREFIX, "rya_");
        conf.set(ConfigUtils.CLOUDBASE_USER, "root");
        conf.set(ConfigUtils.CLOUDBASE_PASSWORD, "");
        conf.set(ConfigUtils.CLOUDBASE_INSTANCE, "instance");
        conf.set(ConfigUtils.CLOUDBASE_AUTHS, "");
    }
    conf.setStatementMetadataProperties(propertySet);
    return conf;
}
Also used : RyaURI(org.apache.rya.api.domain.RyaURI) RdfCloudTripleStoreConfiguration(org.apache.rya.api.RdfCloudTripleStoreConfiguration) MongoDBRdfConfiguration(org.apache.rya.mongodb.MongoDBRdfConfiguration) AccumuloRdfConfiguration(org.apache.rya.accumulo.AccumuloRdfConfiguration) HashSet(java.util.HashSet)

Example 68 with AccumuloRdfConfiguration

use of org.apache.rya.accumulo.AccumuloRdfConfiguration in project incubator-rya by apache.

the class DocumentIndexIntersectingIteratorTest method testSerialization1.

@Test
public void testSerialization1() throws Exception {
    BatchWriter bw = null;
    AccumuloRdfConfiguration acc = new AccumuloRdfConfiguration();
    acc.set(AccumuloRdfConfiguration.CONF_ADDITIONAL_INDEXERS, EntityCentricIndex.class.getName());
    RyaTableMutationsFactory rtm = new RyaTableMutationsFactory(RyaTripleContext.getInstance(acc));
    bw = accCon.createBatchWriter(tablename, 500L * 1024L * 1024L, Long.MAX_VALUE, 30);
    for (int i = 0; i < 20; i++) {
        RyaStatement rs1 = new RyaStatement(new RyaURI("uri:" + i), new RyaURI("uri:cf1"), new RyaType(XMLSchema.STRING, "cq1"));
        RyaStatement rs2 = new RyaStatement(new RyaURI("uri:" + i), new RyaURI("uri:cf2"), new RyaType(XMLSchema.STRING, "cq2"));
        RyaStatement rs3 = null;
        RyaStatement rs4 = null;
        if (i == 5 || i == 15) {
            rs3 = new RyaStatement(new RyaURI("uri:" + i), new RyaURI("uri:cf3"), new RyaType(XMLSchema.INTEGER, Integer.toString(i)));
            rs4 = new RyaStatement(new RyaURI("uri:" + i), new RyaURI("uri:cf3"), new RyaType(XMLSchema.STRING, Integer.toString(i)));
        }
        Collection<Mutation> m1 = EntityCentricIndex.createMutations(rs1);
        for (Mutation m : m1) {
            bw.addMutation(m);
        }
        Collection<Mutation> m2 = EntityCentricIndex.createMutations(rs2);
        for (Mutation m : m2) {
            bw.addMutation(m);
        }
        if (rs3 != null) {
            Collection<Mutation> m3 = EntityCentricIndex.createMutations(rs3);
            for (Mutation m : m3) {
                bw.addMutation(m);
            }
        }
        if (rs4 != null) {
            Collection<Mutation> m4 = EntityCentricIndex.createMutations(rs4);
            for (Mutation m : m4) {
                bw.addMutation(m);
            }
        }
    }
    String q1 = // 
    "" + // 
    "SELECT ?X ?Y1 ?Y2 " + // 
    "{" + // 
    "?X <uri:cf1> ?Y1 ." + // 
    "?X <uri:cf2> ?Y2 ." + // 
    "?X <uri:cf3> 5 ." + "}";
    String q2 = // 
    "" + // 
    "SELECT ?X ?Y1 ?Y2 " + // 
    "{" + // 
    "?X <uri:cf1> ?Y1  ." + // 
    "?X <uri:cf2> ?Y2 ." + // 
    "?X <uri:cf3> \"15\" ." + "}";
    SPARQLParser parser = new SPARQLParser();
    ParsedQuery pq1 = parser.parseQuery(q1, null);
    ParsedQuery pq2 = parser.parseQuery(q2, null);
    TupleExpr te1 = pq1.getTupleExpr();
    TupleExpr te2 = pq2.getTupleExpr();
    List<StatementPattern> spList1 = StatementPatternCollector.process(te1);
    List<StatementPattern> spList2 = StatementPatternCollector.process(te2);
    System.out.println(spList1);
    System.out.println(spList2);
    RyaType rt1 = RdfToRyaConversions.convertValue(spList1.get(2).getObjectVar().getValue());
    RyaType rt2 = RdfToRyaConversions.convertValue(spList2.get(2).getObjectVar().getValue());
    RyaURI predURI1 = (RyaURI) RdfToRyaConversions.convertValue(spList1.get(0).getPredicateVar().getValue());
    RyaURI predURI2 = (RyaURI) RdfToRyaConversions.convertValue(spList1.get(1).getPredicateVar().getValue());
    RyaURI predURI3 = (RyaURI) RdfToRyaConversions.convertValue(spList1.get(2).getPredicateVar().getValue());
    // System.out.println("to string" + spList1.get(2).getObjectVar().getValue().stringValue());
    // System.out.println("converted obj" + rt1.getData());
    // System.out.println("equal: " + rt1.getData().equals(spList1.get(2).getObjectVar().getValue().stringValue()));
    System.out.println(rt1);
    System.out.println(rt2);
    RyaContext rc = RyaContext.getInstance();
    byte[][] b1 = rc.serializeType(rt1);
    byte[][] b2 = rc.serializeType(rt2);
    byte[] b3 = Bytes.concat("object".getBytes(), "\u0000".getBytes(), b1[0], b1[1]);
    byte[] b4 = Bytes.concat("object".getBytes(), "\u0000".getBytes(), b2[0], b2[1]);
    System.out.println(new String(b3));
    System.out.println(new String(b4));
    TextColumn tc1 = new TextColumn(new Text(predURI1.getData()), new Text("object"));
    TextColumn tc2 = new TextColumn(new Text(predURI2.getData()), new Text("object"));
    TextColumn tc3 = new TextColumn(new Text(predURI3.getData()), new Text(b3));
    tc1.setIsPrefix(true);
    tc2.setIsPrefix(true);
    TextColumn[] tc = new TextColumn[3];
    tc[0] = tc1;
    tc[1] = tc2;
    tc[2] = tc3;
    IteratorSetting is = new IteratorSetting(30, "fii", DocumentIndexIntersectingIterator.class);
    DocumentIndexIntersectingIterator.setColumnFamilies(is, tc);
    Scanner scan = accCon.createScanner(tablename, new Authorizations("auths"));
    scan.addScanIterator(is);
    int results = 0;
    System.out.println("************************Test 21****************************");
    Text t = null;
    for (Map.Entry<Key, Value> e : scan) {
        t = e.getKey().getColumnQualifier();
        System.out.println(e);
        results++;
    }
    Assert.assertEquals(1, results);
    String[] s = t.toString().split("\u001D" + "\u001E");
    String[] s1 = s[2].split("\u0000");
    RyaType rt = rc.deserialize(s1[2].getBytes());
    System.out.println("Rya type is " + rt);
    org.openrdf.model.Value v = RyaToRdfConversions.convertValue(rt);
    Assert.assertTrue(v.equals(spList1.get(2).getObjectVar().getValue()));
    tc1 = new TextColumn(new Text(predURI1.getData()), new Text("object"));
    tc2 = new TextColumn(new Text(predURI2.getData()), new Text("object"));
    tc3 = new TextColumn(new Text(predURI3.getData()), new Text(b4));
    tc1.setIsPrefix(true);
    tc2.setIsPrefix(true);
    tc = new TextColumn[3];
    tc[0] = tc1;
    tc[1] = tc2;
    tc[2] = tc3;
    is = new IteratorSetting(30, "fii", DocumentIndexIntersectingIterator.class);
    DocumentIndexIntersectingIterator.setColumnFamilies(is, tc);
    scan = accCon.createScanner(tablename, new Authorizations("auths"));
    scan.addScanIterator(is);
    results = 0;
    System.out.println("************************Test 21****************************");
    for (Map.Entry<Key, Value> e : scan) {
        t = e.getKey().getColumnQualifier();
        System.out.println(e);
        results++;
    }
    Assert.assertEquals(1, results);
    s = t.toString().split("\u001D" + "\u001E");
    s1 = s[2].split("\u0000");
    rt = rc.deserialize(s1[2].getBytes());
    System.out.println("Rya type is " + rt);
    v = RyaToRdfConversions.convertValue(rt);
    Assert.assertTrue(v.equals(spList2.get(2).getObjectVar().getValue()));
}
Also used : Scanner(org.apache.accumulo.core.client.Scanner) ParsedQuery(org.openrdf.query.parser.ParsedQuery) EntityCentricIndex(org.apache.rya.indexing.accumulo.entity.EntityCentricIndex) RyaStatement(org.apache.rya.api.domain.RyaStatement) RyaType(org.apache.rya.api.domain.RyaType) StatementPattern(org.openrdf.query.algebra.StatementPattern) RyaContext(org.apache.rya.api.resolver.RyaContext) SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) Authorizations(org.apache.accumulo.core.security.Authorizations) Text(org.apache.hadoop.io.Text) AccumuloRdfConfiguration(org.apache.rya.accumulo.AccumuloRdfConfiguration) TupleExpr(org.openrdf.query.algebra.TupleExpr) RyaURI(org.apache.rya.api.domain.RyaURI) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) RyaTableMutationsFactory(org.apache.rya.accumulo.RyaTableMutationsFactory) Value(org.apache.accumulo.core.data.Value) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) Map(java.util.Map) Key(org.apache.accumulo.core.data.Key) Test(org.junit.Test)

Example 69 with AccumuloRdfConfiguration

use of org.apache.rya.accumulo.AccumuloRdfConfiguration in project incubator-rya by apache.

the class AccumuloRemoveUserIT method makeRyaConfig.

private static AccumuloRdfConfiguration makeRyaConfig(final String ryaInstanceName, final String username, final String password, final String instanceName, final String zookeepers) {
    final AccumuloRdfConfiguration conf = new AccumuloRdfConfiguration();
    conf.setTablePrefix(ryaInstanceName);
    // Accumulo connection information.
    conf.set(ConfigUtils.CLOUDBASE_USER, username);
    conf.set(ConfigUtils.CLOUDBASE_PASSWORD, password);
    conf.set(ConfigUtils.CLOUDBASE_INSTANCE, instanceName);
    conf.set(ConfigUtils.CLOUDBASE_ZOOKEEPERS, zookeepers);
    conf.set(ConfigUtils.CLOUDBASE_AUTHS, "");
    return conf;
}
Also used : AccumuloRdfConfiguration(org.apache.rya.accumulo.AccumuloRdfConfiguration)

Example 70 with AccumuloRdfConfiguration

use of org.apache.rya.accumulo.AccumuloRdfConfiguration in project incubator-rya by apache.

the class AccumuloRemoveUserIT method removedUserCanNotInsert.

/**
 * Ensure a user that has been removed from the Rya instance can not interact with it.
 */
@Test
public void removedUserCanNotInsert() throws Exception {
    final String adminUser = testInstance.createUniqueUser();
    final String user = testInstance.createUniqueUser();
    final SecurityOperations secOps = super.getConnector().securityOperations();
    // Create the user that will install the instance of Rya.
    secOps.createLocalUser(adminUser, new PasswordToken(adminUser));
    secOps.grantSystemPermission(adminUser, SystemPermission.CREATE_TABLE);
    final RyaClient userAClient = AccumuloRyaClientFactory.build(new AccumuloConnectionDetails(adminUser, adminUser.toCharArray(), getInstanceName(), getZookeepers()), super.getClusterInstance().getCluster().getConnector(adminUser, adminUser));
    // Create the user that will be added to the instance of Rya.
    secOps.createLocalUser(user, new PasswordToken(user));
    final RyaClient userCClient = AccumuloRyaClientFactory.build(new AccumuloConnectionDetails(user, user.toCharArray(), getInstanceName(), getZookeepers()), super.getClusterInstance().getCluster().getConnector(user, user));
    // Install the instance of Rya.
    userAClient.getInstall().install(getRyaInstanceName(), InstallConfiguration.builder().build());
    // Add userC.
    userAClient.getAddUser().get().addUser(getRyaInstanceName(), user);
    // Remove userA.
    userCClient.getRemoveUser().get().removeUser(getRyaInstanceName(), adminUser);
    // Show that userA can not insert anything.
    boolean securityExceptionThrown = false;
    Sail sail = null;
    SailConnection sailConn = null;
    try {
        final AccumuloRdfConfiguration userAConf = makeRyaConfig(getRyaInstanceName(), adminUser, adminUser, getInstanceName(), getZookeepers());
        sail = RyaSailFactory.getInstance(userAConf);
        sailConn = sail.getConnection();
        final ValueFactory vf = sail.getValueFactory();
        sailConn.addStatement(vf.createURI("urn:Alice"), vf.createURI("urn:talksTo"), vf.createURI("urn:Bob"));
    } catch (final RuntimeException e) {
        final Throwable cause = e.getCause();
        if (cause instanceof AccumuloSecurityException) {
            securityExceptionThrown = true;
        }
    } finally {
        if (sailConn != null) {
            sailConn.close();
        }
        if (sail != null) {
            sail.shutDown();
        }
    }
    assertTrue(securityExceptionThrown);
}
Also used : SecurityOperations(org.apache.accumulo.core.client.admin.SecurityOperations) RyaClient(org.apache.rya.api.client.RyaClient) ValueFactory(org.openrdf.model.ValueFactory) AccumuloRdfConfiguration(org.apache.rya.accumulo.AccumuloRdfConfiguration) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) SailConnection(org.openrdf.sail.SailConnection) Sail(org.openrdf.sail.Sail) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) Test(org.junit.Test)

Aggregations

AccumuloRdfConfiguration (org.apache.rya.accumulo.AccumuloRdfConfiguration)108 MockInstance (org.apache.accumulo.core.client.mock.MockInstance)26 AccumuloRyaDAO (org.apache.rya.accumulo.AccumuloRyaDAO)25 Test (org.junit.Test)24 RyaURI (org.apache.rya.api.domain.RyaURI)22 Connector (org.apache.accumulo.core.client.Connector)21 PasswordToken (org.apache.accumulo.core.client.security.tokens.PasswordToken)20 RyaStatement (org.apache.rya.api.domain.RyaStatement)20 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)15 Sail (org.openrdf.sail.Sail)15 RyaType (org.apache.rya.api.domain.RyaType)14 StatementPattern (org.openrdf.query.algebra.StatementPattern)14 AccumuloException (org.apache.accumulo.core.client.AccumuloException)13 Before (org.junit.Before)13 ArrayList (java.util.ArrayList)12 RdfCloudTripleStore (org.apache.rya.rdftriplestore.RdfCloudTripleStore)12 RyaDAOException (org.apache.rya.api.persist.RyaDAOException)11 LiteralImpl (org.openrdf.model.impl.LiteralImpl)10 BindingSet (org.openrdf.query.BindingSet)10 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)10