org.apache.accumulo.core.security.Authorizations Java Examples

The following examples show how to use org.apache.accumulo.core.security.Authorizations. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Query.java    From accumulo-examples with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
  QueryOpts opts = new QueryOpts();
  opts.parseArgs(Query.class.getName(), args);

  try (AccumuloClient client = Accumulo.newClient().from(opts.getClientPropsPath()).build();
      BatchScanner bs = client.createBatchScanner(opts.tableName, Authorizations.EMPTY, 10)) {
    if (opts.useSample) {
      SamplerConfiguration samplerConfig = client.tableOperations()
          .getSamplerConfiguration(opts.tableName);
      CutoffIntersectingIterator.validateSamplerConfig(
          client.tableOperations().getSamplerConfiguration(opts.tableName));
      bs.setSamplerConfiguration(samplerConfig);
    }
    for (String entry : query(bs, opts.terms, opts.sampleCutoff)) {
      System.out.println("  " + entry);
    }
  }
}
 
Example #2
Source File: AuthCache.java    From qonduit with Apache License 2.0 6 votes vote down vote up
public static Authorizations getAuthorizations(String sessionId) {
    if (!StringUtils.isEmpty(sessionId)) {
        Authentication auth = CACHE.asMap().get(sessionId);
        if (null != auth) {
            Collection<? extends GrantedAuthority> authorities = CACHE.asMap().get(sessionId).getAuthorities();
            String[] auths = new String[authorities.size()];
            final AtomicInteger i = new AtomicInteger(0);
            authorities.forEach(a -> auths[i.getAndIncrement()] = a.getAuthority());
            return new Authorizations(auths);
        } else {
            return null;
        }
    } else {
        throw new IllegalArgumentException("session id cannot be null");
    }
}
 
Example #3
Source File: IndexStatsClient.java    From datawave with Apache License 2.0 6 votes vote down vote up
public Map<String,Double> getStat(Set<String> fields, Set<String> dataTypes, SortedSet<String> dates) throws IOException {
    final ScannerBase scanner;
    try {
        Authorizations auths = con.securityOperations().getUserAuthorizations(con.whoami());
        if (fields.isEmpty()) {
            scanner = con.createScanner(table, auths);
        } else {
            BatchScanner bScanner = con.createBatchScanner(table, auths, fields.size());
            bScanner.setRanges(buildRanges(fields));
            scanner = bScanner;
        }
    } catch (Exception e) {
        log.error(e);
        throw new IOException(e);
    }
    
    configureScanIterators(scanner, dataTypes, dates);
    
    Map<String,Double> results = scanResults(scanner);
    
    if (scanner instanceof BatchScanner) {
        scanner.close();
    }
    
    return results;
}
 
Example #4
Source File: EventKeyValueFactory.java    From datawave with Apache License 2.0 6 votes vote down vote up
public static EventKeyValue parse(Key key, Value value, Authorizations auths, MarkingFunctions markingFunctions) throws MarkingFunctions.Exception {
    
    if (null == key)
        throw new IllegalArgumentException("Cannot pass null key to EventKeyValueFactory");
    
    EventKeyValue e = new EventKeyValue();
    e.setShardId(key.getRow().toString());
    
    String[] parts = StringUtils.split(key.getColumnFamily().toString(), Constants.NULL_BYTE_STRING);
    if (parts.length > 0)
        e.setDatatype(parts[0]);
    if (parts.length > 1)
        e.setUid(parts[1]);
    
    String[] field = StringUtils.split(key.getColumnQualifier().toString(), Constants.NULL_BYTE_STRING);
    if (field.length > 0)
        e.setFieldName(field[0]);
    if (field.length > 1)
        e.setFieldValue(field[1]);
    
    e.setTimestamp(key.getTimestamp());
    
    parseColumnVisibility(e, key, auths, markingFunctions);
    
    return e;
}
 
Example #5
Source File: DataStoreImpl.java    From timely with Apache License 2.0 6 votes vote down vote up
@Override
public Scanner createScannerForMetric(AuthenticatedRequest request, String metric, Map<String, String> tags,
        int scannerBatchSize, int scannerReadAhead) throws TimelyException {
    try {
        if (null == metric) {
            throw new IllegalArgumentException("metric name must be specified");
        }
        Collection<Authorizations> auths = getSessionAuthorizations(request);
        LOG.debug("Creating metric scanner for [{}] with auths: {}", request.getUserName(), auths);
        Scanner s = ScannerHelper.createScanner(connector, this.metricsTable, auths);
        if (tags == null) {
            tags = new LinkedHashMap<>();
        }
        List<String> tagOrder = prioritizeTags(metric, tags);
        Map<String, String> orderedTags = orderTags(tagOrder, tags);
        Set<Tag> colFamValues = getColumnFamilies(metric, orderedTags);
        setQueryColumns(s, metric, orderedTags, colFamValues);
        s.setBatchSize(scannerBatchSize);
        s.setReadaheadThreshold(scannerReadAhead);
        return s;
    } catch (IllegalArgumentException | TableNotFoundException ex) {
        LOG.error("Error during lookup: " + ex.getMessage(), ex);
        throw new TimelyException(HttpResponseStatus.INTERNAL_SERVER_ERROR.code(),
                "Error during lookup: " + ex.getMessage(), ex.getMessage(), ex);
    }
}
 
Example #6
Source File: AccumuloResource.java    From vertexium with Apache License 2.0 6 votes vote down vote up
public void addAuthorizations(AccumuloGraph graph, String... authorizations) {
    try {
        String principal = graph.getConnector().whoami();
        Authorizations currentAuthorizations = graph.getConnector().securityOperations().getUserAuthorizations(principal);

        List<byte[]> newAuthorizationsArray = new ArrayList<>();
        for (byte[] currentAuth : currentAuthorizations) {
            newAuthorizationsArray.add(currentAuth);
        }

        for (String authorization : authorizations) {
            if (!currentAuthorizations.contains(authorization)) {
                newAuthorizationsArray.add(authorization.getBytes(UTF_8));
            }
        }

        Authorizations newAuthorizations = new Authorizations(newAuthorizationsArray);
        graph.getConnector().securityOperations().changeUserAuthorizations(principal, newAuthorizations);
    } catch (Exception ex) {
        throw new VertexiumException("could not add authorizations", ex);
    }
}
 
Example #7
Source File: PrintUtility.java    From datawave with Apache License 2.0 6 votes vote down vote up
/**
 * Utility class to print all the entries in a table
 *
 * @param conn
 *            Connector to mock accumulo
 * @param authorizations
 *            Authorizations to run scanner with
 * @param tableName
 *            Table to scan
 * @throws TableNotFoundException
 *             Invalid table name
 */
public static void printTable(final Connector conn, final Authorizations authorizations, final String tableName) throws TableNotFoundException {
    if (logger.isDebugEnabled()) {
        final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd HHmmss");
        
        final StringBuilder sb = new StringBuilder("--Begin entire " + tableName + " table--");
        
        sb.append("\n");
        
        final Scanner scanner = conn.createScanner(tableName, authorizations);
        for (final Entry<Key,Value> e : scanner) {
            sb.append(e.getKey().toStringNoTime());
            sb.append(' ');
            sb.append(dateFormat.format(new Date(e.getKey().getTimestamp())));
            sb.append('\t');
            sb.append(getPrintableValue(e.getValue()));
            sb.append("\n");
        }
        
        sb.append("--End entire ").append(tableName).append(" table--").append("\n");
        
        logger.debug(sb.toString());
    }
}
 
Example #8
Source File: IvaratorInterruptTest.java    From datawave with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setUp() throws Exception {
    // this will get property substituted into the TypeMetadataBridgeContext.xml file
    // for the injection test (when this unit test is first created)
    System.setProperty("type.metadata.dir", tempDirForIvaratorInterruptTest);
    
    QueryTestTableHelper qtth = new QueryTestTableHelper(ShardRange.class.toString(), log, RebuildingScannerTestHelper.TEARDOWN.NEVER,
                    RebuildingScannerTestHelper.INTERRUPT.FI_EVERY_OTHER);
    connector = qtth.connector;
    
    WiseGuysIngest.writeItAll(connector, WiseGuysIngest.WhatKindaRange.SHARD);
    Authorizations auths = new Authorizations("ALL");
    PrintUtility.printTable(connector, auths, SHARD_TABLE_NAME);
    PrintUtility.printTable(connector, auths, SHARD_INDEX_TABLE_NAME);
    PrintUtility.printTable(connector, auths, METADATA_TABLE_NAME);
    PrintUtility.printTable(connector, auths, MODEL_TABLE_NAME);
}
 
Example #9
Source File: AccumuloRyaInstanceDetailsRepository.java    From rya with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isInitialized() throws RyaDetailsRepositoryException {
    Scanner scanner = null;
    try {
        scanner = connector.createScanner(detailsTableName, new Authorizations());
        scanner.fetchColumn(COL_FAMILY, COL_QUALIFIER);
        return scanner.iterator().hasNext();
    } catch (final TableNotFoundException e) {
        return false;
    } finally {
        if(scanner != null) {
            scanner.close();
        }
    }
}
 
Example #10
Source File: TestDatawaveUserService.java    From datawave with Apache License 2.0 5 votes vote down vote up
protected List<String> readAccumuloAuthorizations() {
    try {
        Connector connector = accumuloConnectionFactory.getConnection(null, AccumuloConnectionFactory.Priority.ADMIN, new HashMap<>());
        Authorizations auths = connector.securityOperations().getUserAuthorizations(connector.whoami());
        return Arrays.asList(auths.toString().split("\\s*,\\s*"));
    } catch (Exception e) {
        throw new RuntimeException("Unable to acquire accumulo connector: " + e.getMessage(), e);
    }
}
 
Example #11
Source File: AuthorizationsUtil.java    From datawave with Apache License 2.0 5 votes vote down vote up
public static Set<Authorizations> mergeAuthorizations(String requestedAuths, Collection<? extends Collection<String>> userAuths) {
    HashSet<String> requested = null;
    if (!StringUtils.isEmpty(requestedAuths)) {
        requested = new HashSet<>(splitAuths(requestedAuths));
    }
    
    if (null == userAuths)
        return Collections.singleton(new Authorizations());
    
    HashSet<Authorizations> mergedAuths = new HashSet<>();
    HashSet<String> missingAuths = (requested == null) ? new HashSet<>() : new HashSet<>(requested);
    for (Collection<String> auths : userAuths) {
        if (null != requested) {
            missingAuths.removeAll(auths);
            auths = new HashSet<>(auths);
            auths.retainAll(requested);
        }
        
        mergedAuths.add(new Authorizations(auths.toArray(new String[auths.size()])));
    }
    
    if (!missingAuths.isEmpty()) {
        throw new IllegalArgumentException("User requested authorizations that they don't have. Missing: " + missingAuths + ", Requested: " + requested
                        + ", User: " + userAuths);
    }
    return mergedAuths;
}
 
Example #12
Source File: TestDatawaveUserServiceTest.java    From datawave with Apache License 2.0 5 votes vote down vote up
public MockAccumuloConnectionFactory() {
    try {
        inMemoryInstance.getConnector("root", "").securityOperations().changeUserAuthorizations("root", new Authorizations("PUB", "PVT"));
    } catch (AccumuloException | AccumuloSecurityException e) {
        throw new RuntimeException(e);
    }
}
 
Example #13
Source File: FlinkEnvManager.java    From OSTMap with Apache License 2.0 5 votes vote down vote up
/**
 * makes accumulo input accessible by flink DataSet api
 * @param env
 * @return
 * @throws IOException
 * @throws AccumuloSecurityException
 */
public DataSet<Tuple2<Key,Value>> getDataFromAccumulo(ExecutionEnvironment env) throws IOException, AccumuloSecurityException {
    job = Job.getInstance(new Configuration(), jobName);
    AccumuloInputFormat.setConnectorInfo(job, accumuloUser, new PasswordToken(accumuloPassword));
    AccumuloInputFormat.setScanAuthorizations(job, new Authorizations(AccumuloIdentifiers.AUTHORIZATION.toString()));
    ClientConfiguration clientConfig = new ClientConfiguration();
    clientConfig.withInstance(accumuloInstanceName);
    clientConfig.withZkHosts(accumuloZookeeper);
    AccumuloInputFormat.setZooKeeperInstance(job, clientConfig);
    AccumuloInputFormat.setInputTableName(job, inTable);
    return env.createHadoopInput(new AccumuloInputFormat(),Key.class,Value.class, job);
}
 
Example #14
Source File: ShardIndexQueryTransformer.java    From datawave with Apache License 2.0 5 votes vote down vote up
public ShardIndexQueryTransformer(BaseQueryLogic<Entry<Key,Value>> logic, Query settings, MarkingFunctions markingFunctions,
                ResponseObjectFactory responseObjectFactory, QueryModel qm) {
    super(markingFunctions);
    this.responseObjectFactory = responseObjectFactory;
    this.auths = new Authorizations(settings.getQueryAuthorizations().split(","));
    this.logic = logic;
    this.myQueryModel = qm;
}
 
Example #15
Source File: PcjVisibilityIT.java    From rya with Apache License 2.0 5 votes vote down vote up
private void setupTestUsers(final Connector accumuloConn, final String ryaInstanceName, final String pcjId) throws AccumuloException, AccumuloSecurityException {
    final PasswordToken pass = new PasswordToken("password");
    final SecurityOperations secOps = accumuloConn.securityOperations();

    // We need the table name so that we can update security for the users.
    final String pcjTableName = new PcjTableNameFactory().makeTableName(ryaInstanceName, pcjId);

    // Give the 'roor' user authorizations to see everything.
    secOps.changeUserAuthorizations("root", new Authorizations("A", "B", "C", "D", "E"));

    // Create a user that can see things with A and B.
    secOps.createLocalUser("abUser", pass);
    secOps.changeUserAuthorizations("abUser", new Authorizations("A", "B"));
    secOps.grantTablePermission("abUser", pcjTableName, TablePermission.READ);

    // Create a user that can see things with A, B, and C.
    secOps.createLocalUser("abcUser", pass);
    secOps.changeUserAuthorizations("abcUser", new Authorizations("A", "B", "C"));
    secOps.grantTablePermission("abcUser", pcjTableName, TablePermission.READ);

    // Create a user that can see things with A, D, and E.
    secOps.createLocalUser("adeUser", pass);
    secOps.changeUserAuthorizations("adeUser", new Authorizations("A", "D", "E"));
    secOps.grantTablePermission("adeUser", pcjTableName, TablePermission.READ);

    // Create a user that can't see anything.
    secOps.createLocalUser("noAuth", pass);
    secOps.changeUserAuthorizations("noAuth", new Authorizations());
    secOps.grantTablePermission("noAuth", pcjTableName, TablePermission.READ);
}
 
Example #16
Source File: AuthorizationsUtil.java    From datawave with Apache License 2.0 5 votes vote down vote up
public static String buildUserAuthorizationString(Principal principal) {
    String auths = "";
    if (principal != null && (principal instanceof DatawavePrincipal)) {
        DatawavePrincipal datawavePrincipal = (DatawavePrincipal) principal;
        
        auths = new Authorizations(datawavePrincipal.getPrimaryUser().getAuths().toArray(new String[0])).toString();
    }
    return auths;
}
 
Example #17
Source File: EventInputFormatIT.java    From accumulo-recipes with Apache License 2.0 5 votes vote down vote up
@Test
public void test() throws Exception {

    Connector connector = accumuloMiniClusterDriver.getConnector();
    AccumuloEventStore store = new AccumuloEventStore(connector);
    event = EventBuilder.create("", UUID.randomUUID().toString(), System.currentTimeMillis())
        .attr(new Attribute("key1", "val1"))
        .attr(new Attribute("key2", false)).build();
    store.save(singleton(event));
    store.flush();

    Job job = new Job(new Configuration());
    job.setJarByClass(getClass());
    job.setMapperClass(TestMapper.class);
    job.setNumReduceTasks(0);
    job.setMapOutputKeyClass(Text.class);
    job.setMapOutputValueClass(Text.class);
    job.setInputFormatClass(EventInputFormat.class);
    EventInputFormat.setZooKeeperInstance(job, accumuloMiniClusterDriver.getClientConfiguration());
    EventInputFormat.setInputInfo(job, "root", accumuloMiniClusterDriver.getRootPassword().getBytes(), new Authorizations());
    EventInputFormat.setQueryInfo(job, new Date(System.currentTimeMillis() - 50000), new Date(), Collections.singleton(""),
            QueryBuilder.create().eq("key1", "val1").build());
    job.setOutputFormatClass(NullOutputFormat.class);

    job.submit();
    job.waitForCompletion(true);

    assertNotNull(TestMapper.entry);
    assertEquals(TestMapper.entry.getId(), event.getId());
    assertTrue(TestMapper.entry.getTimestamp() - event.getTimestamp() < 50);
    assertEquals(new HashSet<Attribute>(TestMapper.entry.getAttributes()), new HashSet<Attribute>(event.getAttributes()));

}
 
Example #18
Source File: BatchResource.java    From datawave with Apache License 2.0 5 votes vote down vote up
/**
 * Initializes the scanner resource
 * 
 * @param auths
 * @param tableName
 * @throws TableNotFoundException
 * 
 */
@Override
protected void init(final String tableName, final Set<Authorizations> auths, Collection<Range> currentRange) throws TableNotFoundException {
    Preconditions.checkNotNull(tableName);
    Preconditions.checkArgument(null != currentRange && !currentRange.isEmpty());
    
    // copy the appropriate variables.
    ranges = Lists.newArrayList(currentRange);
    
    this.tableName = tableName;
    
    this.auths = Sets.newHashSet(auths);
    
    if (log.isTraceEnabled())
        log.trace("Creating scanner resource from " + tableName + " " + auths + " " + currentRange);
    
    internalTimer = new StopWatch();
    internalTimer.start();
    
    // let's pre-compute the hashcode.
    hashCode += new HashCodeBuilder().append(tableName).append(auths).append(ranges).toHashCode();
    
    baseScanner = ScannerHelper.createBatchScanner(getConnector(), tableName, auths, 2);
    
    if (baseScanner != null) {
        ((BatchScanner) baseScanner).setRanges(currentRange);
    }
    
}
 
Example #19
Source File: IndexStatsQueryLogic.java    From datawave with Apache License 2.0 5 votes vote down vote up
@Override
public GenericQueryConfiguration initialize(Connector connector, Query query, Set<Authorizations> auths) throws Exception {
    this.connector = connector;
    
    ShardQueryConfiguration config = new ShardQueryConfiguration();
    
    // Get the datatype set if specified
    String typeList = query.findParameter(QueryParameters.DATATYPE_FILTER_SET).getParameterValue();
    HashSet<String> typeFilter = null;
    
    if (null != typeList && !typeList.isEmpty()) {
        typeFilter = new HashSet<>();
        typeFilter.addAll(Arrays.asList(StringUtils.split(typeList, Constants.PARAM_VALUE_SEP)));
        
        if (!typeFilter.isEmpty()) {
            config.setDatatypeFilter(typeFilter);
            
            if (log.isDebugEnabled()) {
                log.debug("Type Filter: " + typeFilter);
            }
        }
    }
    
    config.setBeginDate(query.getBeginDate());
    config.setEndDate(query.getEndDate());
    config.setQueryString(query.getQuery());
    config.setAuthorizations(auths);
    
    return config;
}
 
Example #20
Source File: WebSocketClientIT.java    From timely with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() throws Exception {
    Connector con = mac.getConnector("root", "secret");
    con.securityOperations().changeUserAuthorizations("root", new Authorizations("A", "B", "C", "D", "E", "F"));
    s = new Server(conf);
    s.run();
    setupSslCtx();
}
 
Example #21
Source File: MongoDBRyaDAOIT.java    From rya with Apache License 2.0 5 votes vote down vote up
/**
 * Generates a test statement with the provided document visibility to
 * determine if the specified user authorization can view the statement.
 *
 * @param dao - The DAO that will be used by the test.
 * @param documentVisibility - The document visibility boolean expression
 * string.
 * @param userAuthorizations - The user authorization strings.
 * @return {@code true} if provided authorization could access the document
 * in the collection. {@code false} otherwise.
 * @throws RyaDAOException
 */
private boolean testVisibilityStatement(
        final MongoDBRyaDAO dao,
        final String documentVisibility,
        final Authorizations userAuthorizations) throws RyaDAOException {
    final MongoDatabase db = conf.getMongoClient().getDatabase(conf.get(MongoDBRdfConfiguration.MONGO_DB_NAME));
    final MongoCollection<Document> coll = db.getCollection(conf.getTriplesCollectionName());

    final RyaStatement statement = buildVisibilityTestRyaStatement(documentVisibility);

    dao.getConf().setAuths(AuthorizationsUtil.getAuthorizationsStringArray(Authorizations.EMPTY));
    dao.add(statement);
    dao.getConf().setAuths(AuthorizationsUtil.getAuthorizationsStringArray(userAuthorizations != null ? userAuthorizations : Authorizations.EMPTY));

    assertEquals(1, coll.countDocuments());

    final MongoDBQueryEngine queryEngine = (MongoDBQueryEngine) dao.getQueryEngine();
    queryEngine.setConf(conf);
    final CloseableIterable<RyaStatement> iter = queryEngine.query(new RyaQuery(statement));

    // Check if user has authorization to view document based on its visibility
    final boolean hasNext = iter.iterator().hasNext();

    // Reset
    dao.delete(statement, conf);
    assertEquals(0, coll.countDocuments());
    dao.getConf().setAuths(AuthorizationsUtil.getAuthorizationsStringArray(Authorizations.EMPTY));

    return hasNext;
}
 
Example #22
Source File: ConfigUtils.java    From rya with Apache License 2.0 5 votes vote down vote up
public static BatchScanner createBatchScanner(final String tablename, final Configuration conf)
        throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
    final Connector connector = ConfigUtils.getConnector(conf);
    final Authorizations auths = ConfigUtils.getAuthorizations(conf);
    Integer numThreads = null;
    if (conf instanceof RdfCloudTripleStoreConfiguration) {
        numThreads = ((RdfCloudTripleStoreConfiguration) conf).getNumThreads();
    } else {
        numThreads = conf.getInt(RdfCloudTripleStoreConfiguration.CONF_NUM_THREADS, 2);
    }
    return connector.createBatchScanner(tablename, auths, numThreads);
}
 
Example #23
Source File: FullChainStrategy.java    From datawave with Apache License 2.0 5 votes vote down vote up
@Override
public Iterator<T2> runChainedQuery(Connector connector, Query initialQuery, Set<Authorizations> auths, Iterator<T1> initialQueryResults,
                QueryLogic<T2> latterQueryLogic) throws Exception {
    Query latterQuery = buildLatterQuery(initialQuery, initialQueryResults, latterQueryLogic.getLogicName());
    
    if (null == latterQuery) {
        log.info("Could not compute a query to run.");
        
        // Stub out an empty iterator to return if we couldn't generate a query to run
        return new Iterator<T2>() {
            @Override
            public boolean hasNext() {
                return false;
            }
            
            @Override
            public T2 next() {
                return null;
            }
            
            @Override
            public void remove() {}
        };
    }
    
    GenericQueryConfiguration config = latterQueryLogic.initialize(connector, latterQuery, auths);
    
    latterQueryLogic.setupQuery(config);
    
    return latterQueryLogic.iterator();
}
 
Example #24
Source File: ExtendedRunningQueryTest.java    From datawave with Apache License 2.0 5 votes vote down vote up
@Test
public void testConstructor_NoArg() throws Exception {
    // Run the test
    PowerMock.replayAll();
    RunningQuery subject = new RunningQuery();
    Exception result1 = null;
    try {
        subject.next();
    } catch (NullPointerException e) {
        result1 = e;
    }
    Connector result2 = subject.getConnection();
    Priority result3 = subject.getConnectionPriority();
    QueryLogic<?> result4 = subject.getLogic();
    Query result5 = subject.getSettings();
    TransformIterator result6 = subject.getTransformIterator();
    Set<Authorizations> result7 = subject.getCalculatedAuths();
    PowerMock.verifyAll();
    
    // Verify results
    assertNotNull("Expected an exception to be thrown due to uninitialized instance variables", result1);
    
    assertNull("Expected a null connector", result2);
    
    assertNull("Expected a null priority", result3);
    
    assertNull("Expected null logic", result4);
    
    assertNull("Expected a null query (a.k.a. settings)", result5);
    
    assertNull("Expected a null iterator", result6);
    
    assertNull("Expected a null set of authorizations", result7);
}
 
Example #25
Source File: QueryScannerHelper.java    From datawave with Apache License 2.0 5 votes vote down vote up
public static BatchScanner createBatchScanner(Connector connector, String tableName, Collection<Authorizations> authorizations, int numQueryThreads,
                Query query, boolean reportErrors) throws TableNotFoundException {
    BatchScanner batchScanner = ScannerHelper.createBatchScanner(connector, tableName, authorizations, numQueryThreads);
    
    batchScanner.addScanIterator(getQueryInfoIterator(query, reportErrors));
    
    return batchScanner;
}
 
Example #26
Source File: QueryScannerHelper.java    From datawave with Apache License 2.0 5 votes vote down vote up
public static Scanner createScanner(Connector connector, String tableName, Collection<Authorizations> authorizations, Query query)
                throws TableNotFoundException {
    Scanner scanner = ScannerHelper.createScanner(connector, tableName, authorizations);
    
    scanner.addScanIterator(getQueryInfoIterator(query, false));
    
    return scanner;
}
 
Example #27
Source File: TimeskippingIT.java    From fluo with Apache License 2.0 5 votes vote down vote up
@Test
public void testTimestampSkippingIterPerformance() throws Exception {

  aClient.tableOperations().create("ttsi",
      new NewTableConfiguration().withoutDefaultIterators()
          .setProperties(Collections.singletonMap(AccumuloProps.TABLE_DELETE_BEHAVIOR,
              AccumuloProps.TABLE_DELETE_BEHAVIOR_VALUE)));

  BatchWriter bw = aClient.createBatchWriter("ttsi", new BatchWriterConfig());
  Mutation m = new Mutation("r1");
  for (int i = 0; i < 100000; i++) {
    m.put("f1", "q1", i, "v" + i);
  }

  bw.addMutation(m);
  bw.close();

  long t2 = System.currentTimeMillis();

  Scanner scanner = aClient.createScanner("ttsi", Authorizations.EMPTY);
  scanner.addScanIterator(new IteratorSetting(10, Skip100StampsIterator.class));

  Assert.assertEquals("999", Iterables.getOnlyElement(scanner).getValue().toString());
  long t3 = System.currentTimeMillis();

  if (t3 - t2 > 3000) {
    log.error("Timestamp skipping iterator took longer than expected " + (t3 - t2));
  }

  aClient.tableOperations().flush("ttsi", null, null, true);

  long t4 = System.currentTimeMillis();
  Assert.assertEquals("999", Iterables.getOnlyElement(scanner).getValue().toString());
  long t5 = System.currentTimeMillis();

  if (t5 - t4 > 3000) {
    log.error("Timestamp skipping iterator took longer than expected " + (t5 - t4));
  }
}
 
Example #28
Source File: DateIndexHelper.java    From datawave with Apache License 2.0 5 votes vote down vote up
/**
 * Create and instance of a date index helper
 * 
 * @param connector
 * @param dateIndexTableName
 * @param auths
 * @return the date index helper
 */
public DateIndexHelper initialize(Connector connector, String dateIndexTableName, Set<Authorizations> auths, int numQueryThreads,
                float collapseDatePercentThreshold) {
    if (dateIndexTableName != null && !dateIndexTableName.isEmpty()) {
        return initialize(connector, connector.getInstance(), dateIndexTableName, auths, numQueryThreads, collapseDatePercentThreshold);
    }
    log.warn("Attempting to create a date index helper however the date index table name is empty");
    return null;
}
 
Example #29
Source File: ValueToAttributesTest.java    From datawave with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setUp() throws Exception {
    
    QueryTestTableHelper qtth = new QueryTestTableHelper(DocumentRange.class.toString(), log);
    connector = qtth.connector;
    
    CompositeTestingIngest.writeItAll(connector, CompositeTestingIngest.WhatKindaRange.DOCUMENT);
    Authorizations auths = new Authorizations("ALL");
    PrintUtility.printTable(connector, auths, SHARD_TABLE_NAME);
    PrintUtility.printTable(connector, auths, SHARD_INDEX_TABLE_NAME);
    PrintUtility.printTable(connector, auths, MODEL_TABLE_NAME);
}
 
Example #30
Source File: AccumuloEntityStoreIT.java    From accumulo-recipes with Apache License 2.0 5 votes vote down vote up
@Test
public void testGreaterThan() throws Exception {

    Entity entity = EntityBuilder.create("type", "id")
        .attr(new Attribute("key1", "val1", meta))
        .attr(new Attribute("key2", 1, meta))
        .build();

    Entity entity2 = EntityBuilder.create("type", "id2")
        .attr(new Attribute("key1", "val1", meta))
        .attr(new Attribute("key2", 9, meta))
        .build();

    store.save(asList(entity, entity2));
    store.flush();

    Scanner scanner = connector.createScanner(DEFAULT_SHARD_TABLE_NAME, new Authorizations());
    for (Map.Entry<Key, Value> entry : scanner) {
        System.out.println("ENTRY: " + entry);
    }

    CloseableIterable<Entity> actualEntity = store.query(singleton("type"),
        QueryBuilder.create().greaterThan("key2", 8).build(), null, DEFAULT_AUTHS);

    assertEquals(1, Iterables.size(actualEntity));
    Entity actual = actualEntity.iterator().next();
    assertEquals(new HashSet(actual.getAttributes()), new HashSet(entity2.getAttributes()));
    assertEquals(actual.getId(), entity2.getId());
    assertEquals(actual.getType(), entity2.getType());
}