use of org.apache.accumulo.core.clientImpl.ClientContext in project accumulo by apache.
the class CloneTestIT method assertTableState.
private void assertTableState(String tableName, AccumuloClient c, TableState expected) {
String tableId = c.tableOperations().tableIdMap().get(tableName);
TableState tableState = ((ClientContext) c).getTableState(TableId.of(tableId));
assertEquals(expected, tableState);
}
use of org.apache.accumulo.core.clientImpl.ClientContext in project accumulo by apache.
the class MetadataIT method testAmpleReadTablets.
@Test
public void testAmpleReadTablets() throws Exception {
try (ClientContext cc = (ClientContext) Accumulo.newClient().from(getClientProps()).build()) {
cc.securityOperations().grantTablePermission(cc.whoami(), MetadataTable.NAME, TablePermission.WRITE);
SortedSet<Text> partitionKeys = new TreeSet<>();
partitionKeys.add(new Text("a"));
partitionKeys.add(new Text("e"));
partitionKeys.add(new Text("j"));
cc.tableOperations().create("t");
cc.tableOperations().addSplits("t", partitionKeys);
Text startRow = new Text("a");
Text endRow = new Text("z");
// Call up Ample from the client context using table "t" and build
TabletsMetadata tablets = cc.getAmple().readTablets().forTable(TableId.of("1")).overlapping(startRow, endRow).fetch(FILES, LOCATION, LAST, PREV_ROW).build();
TabletMetadata tabletMetadata0 = Iterables.get(tablets, 0);
TabletMetadata tabletMetadata1 = Iterables.get(tablets, 1);
String infoTabletId0 = tabletMetadata0.getTableId().toString();
String infoExtent0 = tabletMetadata0.getExtent().toString();
String infoPrevEndRow0 = tabletMetadata0.getPrevEndRow().toString();
String infoEndRow0 = tabletMetadata0.getEndRow().toString();
String infoTabletId1 = tabletMetadata1.getTableId().toString();
String infoExtent1 = tabletMetadata1.getExtent().toString();
String infoPrevEndRow1 = tabletMetadata1.getPrevEndRow().toString();
String infoEndRow1 = tabletMetadata1.getEndRow().toString();
String testInfoTableId = "1";
String testInfoKeyExtent0 = "1;e;a";
String testInfoKeyExtent1 = "1;j;e";
String testInfoPrevEndRow0 = "a";
String testInfoPrevEndRow1 = "e";
String testInfoEndRow0 = "e";
String testInfoEndRow1 = "j";
assertEquals(infoTabletId0, testInfoTableId);
assertEquals(infoTabletId1, testInfoTableId);
assertEquals(infoExtent0, testInfoKeyExtent0);
assertEquals(infoExtent1, testInfoKeyExtent1);
assertEquals(infoPrevEndRow0, testInfoPrevEndRow0);
assertEquals(infoPrevEndRow1, testInfoPrevEndRow1);
assertEquals(infoEndRow0, testInfoEndRow0);
assertEquals(infoEndRow1, testInfoEndRow1);
}
}
use of org.apache.accumulo.core.clientImpl.ClientContext in project accumulo by apache.
the class AccumuloRecordReader method initialize.
/**
* Initialize a scanner over the given input split using this task attempt configuration.
*/
public void initialize(InputSplit inSplit, JobConf job) throws IOException {
baseSplit = (org.apache.accumulo.hadoopImpl.mapreduce.RangeInputSplit) inSplit;
log.debug("Initializing input split: " + baseSplit);
client = createClient(job, CLASS);
ClientContext context = (ClientContext) client;
Authorizations authorizations = InputConfigurator.getScanAuthorizations(CLASS, job);
String classLoaderContext = InputConfigurator.getClassLoaderContext(CLASS, job);
String table = baseSplit.getTableName();
// in case the table name changed, we can still use the previous name for terms of
// configuration, but the scanner will use the table id resolved at job setup time
InputTableConfig tableConfig = InputConfigurator.getInputTableConfig(CLASS, job, baseSplit.getTableName());
log.debug("Created client with user: " + context.whoami());
log.debug("Creating scanner for table: " + table);
log.debug("Authorizations are: " + authorizations);
if (baseSplit instanceof BatchInputSplit) {
BatchScanner scanner;
BatchInputSplit multiRangeSplit = (BatchInputSplit) baseSplit;
try {
// Note: BatchScanner will use at most one thread per tablet, currently BatchInputSplit
// will not span tablets
int scanThreads = 1;
scanner = context.createBatchScanner(baseSplit.getTableName(), authorizations, scanThreads);
setupIterators(job, scanner, baseSplit);
if (classLoaderContext != null) {
scanner.setClassLoaderContext(classLoaderContext);
}
} catch (TableNotFoundException e) {
throw new IOException(e);
}
scanner.setRanges(multiRangeSplit.getRanges());
scannerBase = scanner;
} else if (baseSplit instanceof RangeInputSplit) {
split = (RangeInputSplit) baseSplit;
Boolean isOffline = baseSplit.isOffline();
if (isOffline == null) {
isOffline = tableConfig.isOfflineScan();
}
Boolean isIsolated = baseSplit.isIsolatedScan();
if (isIsolated == null) {
isIsolated = tableConfig.shouldUseIsolatedScanners();
}
Boolean usesLocalIterators = baseSplit.usesLocalIterators();
if (usesLocalIterators == null) {
usesLocalIterators = tableConfig.shouldUseLocalIterators();
}
Scanner scanner;
try {
if (isOffline) {
scanner = new OfflineScanner(context, TableId.of(baseSplit.getTableId()), authorizations);
} else {
scanner = new ScannerImpl(context, TableId.of(baseSplit.getTableId()), authorizations);
}
if (isIsolated) {
log.info("Creating isolated scanner");
scanner = new IsolatedScanner(scanner);
}
if (usesLocalIterators) {
log.info("Using local iterators");
scanner = new ClientSideIteratorScanner(scanner);
}
setupIterators(job, scanner, baseSplit);
} catch (RuntimeException e) {
throw new IOException(e);
}
scanner.setRange(baseSplit.getRange());
scannerBase = scanner;
} else {
throw new IllegalArgumentException("Can not initialize from " + baseSplit.getClass());
}
Collection<IteratorSetting.Column> columns = baseSplit.getFetchedColumns();
if (columns == null) {
columns = tableConfig.getFetchedColumns();
}
// setup a scanner within the bounds of this split
for (Pair<Text, Text> c : columns) {
if (c.getSecond() != null) {
log.debug("Fetching column " + c.getFirst() + ":" + c.getSecond());
scannerBase.fetchColumn(c.getFirst(), c.getSecond());
} else {
log.debug("Fetching column family " + c.getFirst());
scannerBase.fetchColumnFamily(c.getFirst());
}
}
SamplerConfiguration samplerConfig = baseSplit.getSamplerConfiguration();
if (samplerConfig == null) {
samplerConfig = tableConfig.getSamplerConfiguration();
}
if (samplerConfig != null) {
scannerBase.setSamplerConfiguration(samplerConfig);
}
Map<String, String> executionHints = baseSplit.getExecutionHints();
if (executionHints == null || executionHints.isEmpty()) {
executionHints = tableConfig.getExecutionHints();
}
if (executionHints != null) {
scannerBase.setExecutionHints(executionHints);
}
scannerIterator = scannerBase.iterator();
numKeysRead = 0;
}
use of org.apache.accumulo.core.clientImpl.ClientContext in project accumulo by apache.
the class AccumuloRecordReader method initialize.
@Override
public void initialize(InputSplit inSplit, TaskAttemptContext attempt) throws IOException {
split = (RangeInputSplit) inSplit;
log.debug("Initializing input split: " + split);
Configuration conf = attempt.getConfiguration();
client = createClient(attempt, this.CLASS);
ClientContext context = (ClientContext) client;
Authorizations authorizations = InputConfigurator.getScanAuthorizations(CLASS, conf);
String classLoaderContext = InputConfigurator.getClassLoaderContext(CLASS, conf);
String table = split.getTableName();
// in case the table name changed, we can still use the previous name for terms of
// configuration,
// but the scanner will use the table id resolved at job setup time
InputTableConfig tableConfig = InputConfigurator.getInputTableConfig(CLASS, conf, split.getTableName());
log.debug("Creating client with user: " + client.whoami());
log.debug("Creating scanner for table: " + table);
log.debug("Authorizations are: " + authorizations);
if (split instanceof BatchInputSplit) {
BatchInputSplit batchSplit = (BatchInputSplit) split;
BatchScanner scanner;
try {
// Note: BatchScanner will use at most one thread per tablet, currently BatchInputSplit
// will not span tablets
int scanThreads = 1;
scanner = context.createBatchScanner(split.getTableName(), authorizations, scanThreads);
setupIterators(attempt, scanner, split);
if (classLoaderContext != null) {
scanner.setClassLoaderContext(classLoaderContext);
}
} catch (TableNotFoundException e) {
e.printStackTrace();
throw new IOException(e);
}
scanner.setRanges(batchSplit.getRanges());
scannerBase = scanner;
} else {
Scanner scanner;
Boolean isOffline = split.isOffline();
if (isOffline == null) {
isOffline = tableConfig.isOfflineScan();
}
Boolean isIsolated = split.isIsolatedScan();
if (isIsolated == null) {
isIsolated = tableConfig.shouldUseIsolatedScanners();
}
Boolean usesLocalIterators = split.usesLocalIterators();
if (usesLocalIterators == null) {
usesLocalIterators = tableConfig.shouldUseLocalIterators();
}
try {
if (isOffline) {
scanner = new OfflineScanner(context, TableId.of(split.getTableId()), authorizations);
} else {
// Not using public API to create scanner so that we can use table ID
// Table ID is used in case of renames during M/R job
scanner = new ScannerImpl(context, TableId.of(split.getTableId()), authorizations);
}
if (isIsolated) {
log.info("Creating isolated scanner");
scanner = new IsolatedScanner(scanner);
}
if (usesLocalIterators) {
log.info("Using local iterators");
scanner = new ClientSideIteratorScanner(scanner);
}
setupIterators(attempt, scanner, split);
} catch (RuntimeException e) {
throw new IOException(e);
}
scanner.setRange(split.getRange());
scannerBase = scanner;
}
Collection<IteratorSetting.Column> columns = split.getFetchedColumns();
if (columns == null) {
columns = tableConfig.getFetchedColumns();
}
// setup a scanner within the bounds of this split
for (Pair<Text, Text> c : columns) {
if (c.getSecond() != null) {
log.debug("Fetching column " + c.getFirst() + ":" + c.getSecond());
scannerBase.fetchColumn(c.getFirst(), c.getSecond());
} else {
log.debug("Fetching column family " + c.getFirst());
scannerBase.fetchColumnFamily(c.getFirst());
}
}
SamplerConfiguration samplerConfig = split.getSamplerConfiguration();
if (samplerConfig == null) {
samplerConfig = tableConfig.getSamplerConfiguration();
}
if (samplerConfig != null) {
scannerBase.setSamplerConfiguration(samplerConfig);
}
Map<String, String> executionHints = split.getExecutionHints();
if (executionHints == null || executionHints.isEmpty()) {
executionHints = tableConfig.getExecutionHints();
}
if (executionHints != null) {
scannerBase.setExecutionHints(executionHints);
}
scannerIterator = scannerBase.iterator();
numKeysRead = 0;
}
use of org.apache.accumulo.core.clientImpl.ClientContext in project accumulo by apache.
the class AccumuloReplicaSystem method replicate.
@SuppressFBWarnings(value = "PATH_TRAVERSAL_IN", justification = "path provided by admin")
@Override
public Status replicate(final Path p, final Status status, final ReplicationTarget target, final ReplicaSystemHelper helper) {
final AccumuloConfiguration localConf = conf;
log.debug("Replication RPC timeout is {}", localConf.get(Property.REPLICATION_RPC_TIMEOUT.getKey()));
final String principal = getPrincipal(localConf, target);
final File keytab;
final String password;
if (localConf.getBoolean(Property.INSTANCE_RPC_SASL_ENABLED)) {
String keytabPath = getKeytab(localConf, target);
keytab = new File(keytabPath);
if (!keytab.exists() || !keytab.isFile()) {
log.error("{} is not a regular file. Cannot login to replicate", keytabPath);
return status;
}
password = null;
} else {
keytab = null;
password = getPassword(localConf, target);
}
if (keytab != null) {
try {
final UserGroupInformation accumuloUgi = UserGroupInformation.getCurrentUser();
// Get a UGI with the principal + keytab
UserGroupInformation ugi = UserGroupInformation.loginUserFromKeytabAndReturnUGI(principal, keytab.getAbsolutePath());
// Run inside a doAs to avoid nuking the Tserver's user
return ugi.doAs((PrivilegedAction<Status>) () -> {
KerberosToken token;
try {
// Do *not* replace the current user
token = new KerberosToken(principal, keytab);
} catch (IOException e) {
log.error("Failed to create KerberosToken", e);
return status;
}
ClientContext peerContext = getContextForPeer(localConf, target, principal, token);
return _replicate(p, status, target, helper, localConf, peerContext, accumuloUgi);
});
} catch (IOException e) {
// Can't log in, can't replicate
log.error("Failed to perform local login", e);
return status;
}
} else {
// Simple case: make a password token, context and then replicate
PasswordToken token = new PasswordToken(password);
ClientContext peerContext = getContextForPeer(localConf, target, principal, token);
return _replicate(p, status, target, helper, localConf, peerContext, null);
}
}
Aggregations