@Override public void init() throws DBException { colFam = new Text(getProperties().getProperty("accumulo.columnFamily")); colFamBytes = colFam.toString().getBytes(UTF_8); inst = new ZooKeeperInstance( getProperties().getProperty("accumulo.instanceName"), getProperties().getProperty("accumulo.zooKeepers")); try { String principal = getProperties().getProperty("accumulo.username"); AuthenticationToken token = new PasswordToken(getProperties().getProperty("accumulo.password")); connector = inst.getConnector(principal, token); } catch (AccumuloException | AccumuloSecurityException e) { throw new DBException(e); } if (!(getProperties().getProperty("accumulo.pcFlag", "none").equals("none"))) { System.err.println("Sorry, the ZK based producer/consumer implementation has been removed. " + "Please see YCSB issue #416 for work on adding a general solution to coordinated work."); } }
@Override public boolean equals(Object obj) { // We assume we can cast obj to DelegationToken because the super.equals(obj) check ensures obj // is of the same type as this return super.equals(obj) && identifier.equals(((DelegationTokenImpl) obj).identifier); }
Connector connPeer = peerCluster.getConnector("root", new PasswordToken(ROOT_PASSWORD)); connPeer.securityOperations().createLocalUser(peerUserName, new PasswordToken(peerPassword)); connMaster.instanceOperations().setProperty( Property.REPLICATION_PEERS.getKey() + peerClusterName, ReplicaSystemFactory.getPeerConfigurationValue(AccumuloReplicaSystem.class, connMaster.instanceOperations() .setProperty(Property.REPLICATION_PEER_USER.getKey() + peerClusterName, peerUserName); connMaster.instanceOperations() connMaster.tableOperations().create(masterTable); String masterTableId = connMaster.tableOperations().tableIdMap().get(masterTable); Assert.assertNotNull(masterTableId); connPeer.tableOperations().create(peerTable); String peerTableId = connPeer.tableOperations().tableIdMap().get(peerTable); Assert.assertNotNull(peerTableId); BatchWriter bw = connMaster.createBatchWriter(masterTable, new BatchWriterConfig()); for (int rows = 0; rows < 5000; rows++) { Mutation m = new Mutation(Integer.toString(rows)); Iterators.size(connMaster.createScanner(masterTable, Authorizations.EMPTY).iterator());
@BeforeClass public static void setUp() throws Exception { TimeZone.setDefault(TimeZone.getTimeZone("GMT")); System.setProperty("file.encoding", "UTF8"); // Need to set SDFs after setting the timezone to GMT, else dates will be EST and converted to GMT simpleFormat = new SimpleDateFormat("yyyyMMdd"); InMemoryInstance i = new InMemoryInstance(BaseEdgeQueryTest.class.toString()); connector = i.getConnector("root", new PasswordToken("")); // Create the CB tables connector.tableOperations().create(EDGE_TABLE_NAME); connector.tableOperations().create(MODEL_TABLE_NAME); // Create the map of batchwriters to cb tables recordWriter = new MockAccumuloRecordWriter(); BatchWriterConfig bwCfg = new BatchWriterConfig().setMaxLatency(1, TimeUnit.SECONDS).setMaxMemory(1000L).setMaxWriteThreads(1); recordWriter.addWriter(new Text(EDGE_TABLE_NAME), connector.createBatchWriter(EDGE_TABLE_NAME, bwCfg)); addEdges(); } }
Connector connector = getConnector(); connector.tableOperations().create(testName.getMethodName()); BatchWriterConfig batchConfig = new BatchWriterConfig(); batchConfig.setMaxLatency(0, TimeUnit.MILLISECONDS); batchConfig.setMaxWriteThreads(1); batchConfig.setMaxMemory(Long.MAX_VALUE); AccumuloOutputFormat.setBatchWriterOptions(job, batchConfig); AccumuloOutputFormat.setZooKeeperInstance(job, cluster.getClientConfig()); AccumuloOutputFormat.setConnectorInfo(job, "root", new PasswordToken(ROOT_PASSWORD)); RecordWriter<Text,Mutation> writer = outputFormat.getRecordWriter(null, job, "Test", null); Mutation m = new Mutation(new Text(String.format("%08d", i))); for (int j = 0; j < 3; j++) { m.put(new Text("cf1"), new Text("cq" + j), new Value((i + "_" + j).getBytes(UTF_8))); writer.write(new Text(testName.getMethodName()), m); connector.securityOperations().revokeTablePermission("root", testName.getMethodName(), TablePermission.WRITE);
ParseException { PasswordToken noPasswordToken = new PasswordToken(); InMemoryInstance i = new InMemoryInstance("mock2"); Connector connector = i.getConnector("root", noPasswordToken); conf.set(ShardedDataTypeHandler.METADATA_TABLE_NAME, "DatawaveMetadata"); connector.tableOperations().create(conf.get(ShardedDataTypeHandler.METADATA_TABLE_NAME)); BatchWriter recordWriter = connector.createBatchWriter(conf.get(ShardedDataTypeHandler.METADATA_TABLE_NAME), new BatchWriterConfig());
TableExistsException, TableNotFoundException, IOException, InterruptedException { conn.securityOperations().createLocalUser(AUDIT_USER_1, new PasswordToken(PASSWORD)); conn.securityOperations().grantSystemPermission(AUDIT_USER_1, SystemPermission.SYSTEM); conn.securityOperations().changeUserAuthorizations(AUDIT_USER_1, auths); grantEverySystemPriv(conn, AUDIT_USER_1); auditConnector = getCluster().getConnector(AUDIT_USER_1, new PasswordToken(PASSWORD)); auditConnector.tableOperations().create(OLD_TEST_TABLE_NAME); BatchWriter bw = auditConnector.createBatchWriter(OLD_TEST_TABLE_NAME, new BatchWriterConfig()); Mutation m = new Mutation("myRow"); m.put("cf1", "cq1", "v1"); System.out.println("Scanner row: " + entry.getKey() + " " + entry.getValue()); scanner.close(); BatchScanner bs = auditConnector.createBatchScanner(OLD_TEST_TABLE_NAME, auths, 1); bs.fetchColumn(new Text("cf1"), new Text("cq1")); bs.setRanges(Arrays.asList(new Range("myRow", "myRow~"))); auditConnector.tableOperations().deleteRows(OLD_TEST_TABLE_NAME, new Text("myRow"), new Text("myRow~"));
Connector conn = instance.getConnector(getUsername(job.getConfiguration()), new PasswordToken(getPassword(job.getConfiguration()))); String tableId = Tables.getTableId(instance, tableName); startRow = range.getStartKey().getRow(); else startRow = new Text(); Scanner scanner = conn.createScanner(MetadataTable.NAME, Authorizations.EMPTY); MetadataSchema.TabletsSection.TabletColumnFamily.PREV_ROW_COLUMN.fetch(scanner); scanner.fetchColumnFamily(MetadataSchema.TabletsSection.LastLocationColumnFamily.NAME); scanner.fetchColumnFamily(MetadataSchema.TabletsSection.CurrentLocationColumnFamily.NAME); scanner.fetchColumnFamily(MetadataSchema.TabletsSection.FutureLocationColumnFamily.NAME); scanner.setRange(metadataRange); Key key = entry.getKey(); if (key.getColumnFamily().equals(MetadataSchema.TabletsSection.LastLocationColumnFamily.NAME)) { last = entry.getValue().toString(); if (key.getColumnFamily().equals(MetadataSchema.TabletsSection.CurrentLocationColumnFamily.NAME) || key.getColumnFamily().equals(MetadataSchema.TabletsSection.FutureLocationColumnFamily.NAME)) { location = entry.getValue().toString();
if (saslEnabled) { conn.securityOperations().createLocalUser(user, null); } else { conn.securityOperations().createLocalUser(user, new PasswordToken(user1.getPassword())); conn.securityOperations().changeUserAuthorizations(user, auths); conn.securityOperations().grantSystemPermission(user, SystemPermission.CREATE_TABLE); conn = conn.getInstance().getConnector(user, user1.getToken()); conn.tableOperations().create(tableName); try (ConditionalWriter cw = conn.createConditionalWriter(tableName, Scanner scanner = conn.createScanner(tableName, auths); scanner.setRange(new Range("99006")); scanner.fetchColumn(new Text("tx"), new Text("seq")); Entry<Key,Value> entry = Iterables.getOnlyElement(scanner); Assert.assertEquals("1", entry.getValue().toString());
conn.securityOperations().createLocalUser(AUDIT_USER_1, new PasswordToken(PASSWORD)); conn.tableOperations().create(OLD_TEST_TABLE_NAME); auditConnector = getCluster().getConnector(AUDIT_USER_1, new PasswordToken(PASSWORD)); auditConnector.tableOperations().create(NEW_TEST_TABLE_NAME); } catch (AccumuloSecurityException ex) {} try { auditConnector.tableOperations().rename(OLD_TEST_TABLE_NAME, NEW_TEST_TABLE_NAME); } catch (AccumuloSecurityException ex) {} try { try { Scanner scanner = auditConnector.createScanner(OLD_TEST_TABLE_NAME, auths); scanner.iterator().next().getKey(); } catch (RuntimeException ex) {} try { auditConnector.tableOperations().deleteRows(OLD_TEST_TABLE_NAME, new Text("myRow"), new Text("myRow~")); } catch (AccumuloSecurityException ex) {}
ClientContext context = new ClientContext(c.getInstance(), new Credentials("root", new PasswordToken(ROOT_PASSWORD)), getClientConfig()); String table = this.getUniqueNames(1)[0]; c.securityOperations().grantTablePermission("root", MetadataTable.NAME, TablePermission.WRITE); c.securityOperations().grantTablePermission("root", RootTable.NAME, TablePermission.WRITE); c.tableOperations().create(table); SortedSet<Text> partitions = new TreeSet<>(); for (String part : "a b c d e f g h i j k l m n o p q r s t u v w x y z".split(" ")) { partitions.add(new Text(part)); c.tableOperations().addSplits(table, partitions); BatchWriter bw = c.createBatchWriter(MetadataTable.NAME, new BatchWriterConfig()); Mutation assignment = new Mutation(moved.extent.getMetadataEntry()); moved.current.putLocation(assignment); bw = c.createBatchWriter(MetadataTable.NAME, new BatchWriterConfig()); assignment = new Mutation(new KeyExtent(MetadataTable.ID, null, null).getMetadataEntry()); moved.current.putLocation(assignment);
Scanner scanner = null; try { ZooKeeperInstance instance = new ZooKeeperInstance(config.getInstanceName(), config.getZookeepers()); Connector connector = instance.getConnector(config.getUsername(), new PasswordToken(config.getPassword())); Collection<Authorizations> authCollection = Collections.singleton(new Authorizations(config.getAuths().split(","))); if (!connector.tableOperations().exists(config.getTableName())) { throw new IllegalArgumentException("Table " + config.getTableName() + " does not exist"); scanner.setRange(r); Iterator<Map.Entry<Key,Value>> itr = scanner.iterator(); while (itr.hasNext()) { Map.Entry<Key,Value> nextEntry = itr.next(); Key key = nextEntry.getKey(); String field = key.getColumnFamily().toString(); if (fields != null && !fields.isEmpty() && !fields.contains(field)) { continue; } finally { if (scanner != null) { scanner.close();
public static void main(String[] args) throws Exception { try (ConfigurableApplicationContext ctx = new SpringApplicationBuilder(SpringBootstrap.class) .bannerMode(Mode.OFF).web(false).run(args)) { Configuration conf = ctx.getBean(Configuration.class); final BaseConfiguration apacheConf = new BaseConfiguration(); Accumulo accumuloConf = conf.getAccumulo(); apacheConf.setProperty("instance.name", accumuloConf.getInstanceName()); apacheConf.setProperty("instance.zookeeper.host", accumuloConf.getZookeepers()); final ClientConfiguration aconf = new ClientConfiguration(Collections.singletonList(apacheConf)); final Instance instance = new ZooKeeperInstance(aconf); Connector con = instance.getConnector(accumuloConf.getUsername(), new PasswordToken(accumuloConf.getPassword())); Scanner s = con.createScanner(conf.getMetaTable(), con.securityOperations().getUserAuthorizations(con.whoami())); try { s.setRange(new Range(Meta.METRIC_PREFIX, true, Meta.TAG_PREFIX, false)); for (Entry<Key, Value> e : s) { System.out.println(e.getKey().getRow().toString().substring(Meta.METRIC_PREFIX.length())); } } finally { s.close(); } } } }
SortedSet<Text> splits = new TreeSet<>(); for (int i = 0; i < 1000; i++) { splits.add(new Text(String.format("%03d", i))); c.tableOperations().setProperty(MetadataTable.NAME, Property.TABLE_SPLIT_THRESHOLD.getKey(), "10000"); String tableName = "table" + i; log.info("Creating " + tableName); c.tableOperations().create(tableName); log.info("adding splits"); c.tableOperations().addSplits(tableName, splits); log.info("flushing"); c.tableOperations().flush(MetadataTable.NAME, null, null, true); cluster.start(); Credentials creds = new Credentials("root", new PasswordToken(ROOT_PASSWORD));
protected void verifyAccumuloCell(String tableName, String rowKey, String colFamily, String colName, String val) throws IOException { try { Instance inst = new ZooKeeperInstance(accumuloCluster.getInstanceName(), accumuloCluster.getZooKeepers()); Connector conn = inst.getConnector(ACCUMULO_USER, new PasswordToken(ACCUMULO_PASSWORD)); Scanner scanner = conn.createScanner(tableName, Constants.NO_AUTHS); scanner.setRange(new Range(rowKey)); Iterator<Entry<Key, Value>> iter = scanner.iterator(); while (iter.hasNext()) { Entry<Key, Value> entry = iter.next(); String columnFamily = entry.getKey().getColumnFamily().toString(); String qual = entry.getKey().getColumnQualifier().toString(); if (columnFamily.equals(colFamily) && qual.equals(colName)) {
Connector c = getConnector(); String table = getUniqueNames(1)[0]; c.tableOperations().create(table); c.tableOperations().setProperty(table, Property.TABLE_SPLIT_THRESHOLD.getKey(), "256K"); c.tableOperations().setProperty(table, Property.TABLE_FILE_COMPRESSED_BLOCK_SIZE.getKey(), "1K"); TestIngest.Opts opts = new TestIngest.Opts(); Scanner s = c.createScanner(MetadataTable.NAME, Authorizations.EMPTY); KeyExtent extent = new KeyExtent(id, null, null); s.setRange(extent.toMetadataRange()); MetadataSchema.TabletsSection.TabletColumnFamily.PREV_ROW_COLUMN.fetch(s); int count = 0; for (Entry<Key,Value> entry : s) { extent = new KeyExtent(entry.getKey().getRow(), entry.getValue()); if (extent.getEndRow() != null && extent.getEndRow().toString().length() < 14) shortened++; count++; PasswordToken token = (PasswordToken) getAdminToken(); args = new String[] {"-i", cluster.getInstanceName(), "-u", "root", "-p", new String(token.getPassword(), UTF_8), "-z", cluster.getZooKeepers()};
this.defaultTableName = (tname == null) ? null : new Text(tname); this.conn = getInstance(conf).getConnector(getUsername(conf), new PasswordToken(getPassword(conf))); } else { this.connFactory = connectionFactory; this.conn = connectionFactory.getConnection(Priority.ADMIN, trackingMap); mtbw = conn.createMultiTableBatchWriter(getMaxMutationBufferSize(conf), getMaxLatency(conf), getMaxWriteThreads(conf)); } catch (Exception e) { log.error(e.getMessage(), e);
Connector conn = inst.getConnector("root", new PasswordToken("")); conn.tableOperations().create(table.getFullTableName()); conn.tableOperations().create(table.getIndexTableName()); conn.tableOperations().create(table.getMetricsTableName()); Indexer indexer = new Indexer(conn, new Authorizations(), table, new BatchWriterConfig()); indexer.index(m1); indexer.flush(); Scanner scan = conn.createScanner(table.getIndexTableName(), new Authorizations()); scan.setRange(new Range()); Iterator<Entry<Key, Value>> iter = scan.iterator(); assertKeyValuePair(iter.next(), AGE_VALUE, "cf_age", "row1", ""); assertKeyValuePair(iter.next(), bytes("abc"), "cf_arr", "row1", ""); assertFalse(iter.hasNext()); scan.close(); scan = conn.createScanner(table.getMetricsTableName(), new Authorizations());
Instance instance = configuration.instance(); if (instance == null) { instance = new ZooKeeperInstance(configuration.instanceName(), configuration.zookeepers()); connector = instance.getConnector(configuration.username(), new PasswordToken(configuration.password())); } catch (AccumuloException | AccumuloSecurityException e) { throw new RuntimeException("Unable to connect to Accumulo.", e); AgeOffFilter.setTTL(ageoffConfig, configuration.ageoffTTLhours() * 60L * 60L * 1000L); if (!connector.tableOperations().exists(tableName)) { try { connector.tableOperations().create(tableName); connector.tableOperations().attachIterator(tableName, ageoffConfig, EnumSet.allOf(IteratorUtil.IteratorScope.class)); } catch (TableExistsException e) { log.debug("Attempted to create cache table {} but someone else beat us to the punch.", tableName); BatchWriterConfig bwConfig = new BatchWriterConfig().setMaxWriteThreads(configuration.writeThreads()) .setMaxLatency(configuration.maxLatency(), TimeUnit.SECONDS).setMaxMemory(configuration.maxMemory()); try { batchWriter = connector.createBatchWriter(tableName, bwConfig);
protected void run(String[] args) throws ParseException, AccumuloSecurityException, AccumuloException, TableNotFoundException, IOException { parseConfig(args); ZooKeeperInstance instance = new ZooKeeperInstance(ClientConfiguration.loadDefault().withInstance(instanceName).withZkHosts(zookeepers)); Connector connector = instance.getConnector(username, new PasswordToken(password)); Authorizations auths = connector.securityOperations().getUserAuthorizations(connector.whoami()); BatchWriter writer = connector.createBatchWriter(tableName, new BatchWriterConfig().setMaxWriteThreads(bwThreads).setMaxMemory(bwMemory).setMaxLatency(60, TimeUnit.SECONDS)); BatchScanner scanner = connector.createBatchScanner(tableName, auths, bsThreads); scanner.setRanges(ranges); int numGroups = in.readInt(); while (numGroups-- > 0) { String groupName = Text.readString(in); String groupDisplayName = Text.readString(in); CounterGroup group = counters.addGroup(groupName, groupDisplayName); String counterName = Text.readString(in); String counterDisplayName = counterName; if (in.readBoolean())