use of org.apache.accumulo.core.data.TableId in project accumulo by apache.
the class SecurityOperation method _hasTablePermission.
/**
* Checks if a user has a table permission<br>
* This cannot check if a system user has permission.
*
* @return true if a user exists and has permission; false otherwise
*/
protected boolean _hasTablePermission(String user, TableId table, TablePermission permission, boolean useCached) throws ThriftSecurityException {
targetUserExists(user);
@SuppressWarnings("deprecation") TableId replicationTableId = org.apache.accumulo.core.replication.ReplicationTable.ID;
if ((table.equals(MetadataTable.ID) || table.equals(RootTable.ID) || table.equals(replicationTableId)) && permission.equals(TablePermission.READ))
return true;
try {
if (useCached)
return permHandle.hasCachedTablePermission(user, table.canonical(), permission);
return permHandle.hasTablePermission(user, table.canonical(), permission);
} catch (TableNotFoundException e) {
throw new ThriftSecurityException(user, SecurityErrorCode.TABLE_DOESNT_EXIST);
}
}
use of org.apache.accumulo.core.data.TableId in project accumulo by apache.
the class TabletServerResource method doCurrentOperations.
private List<CurrentOperations> doCurrentOperations(List<TabletStats> tsStats) throws Exception {
List<CurrentOperations> currentOperations = new ArrayList<>();
for (TabletStats info : tsStats) {
if (info.extent == null) {
historical = info;
continue;
}
total.numEntries += info.numEntries;
ActionStatsUpdator.update(total.minors, info.minors);
ActionStatsUpdator.update(total.majors, info.majors);
KeyExtent extent = KeyExtent.fromThrift(info.extent);
TableId tableId = extent.tableId();
String displayExtent = String.format("[%s]", extent.obscured());
String tableName = monitor.getContext().getPrintableTableInfoFromId(tableId);
currentOperations.add(new CurrentOperations(tableName, tableId, displayExtent, info.numEntries, info.ingestRate, info.queryRate, info.minors.num != 0 ? info.minors.elapsed / info.minors.num : null, stddev(info.minors.elapsed, info.minors.num, info.minors.sumDev), info.minors.elapsed != 0 ? info.minors.count / info.minors.elapsed : null, info.majors.num != 0 ? info.majors.elapsed / info.majors.num : null, stddev(info.majors.elapsed, info.majors.num, info.majors.sumDev), info.majors.elapsed != 0 ? info.majors.count / info.majors.elapsed : null));
}
return currentOperations;
}
use of org.apache.accumulo.core.data.TableId in project accumulo by apache.
the class ProblemsResource method getDetails.
/**
* Generates a list of the problem details as a JSON object
*
* @return problem details list
*/
@GET
@Path("details")
public ProblemDetail getDetails() {
ProblemDetail problems = new ProblemDetail();
if (monitor.getProblemException() == null) {
for (Entry<TableId, Map<ProblemType, Integer>> entry : monitor.getProblemSummary().entrySet()) {
ArrayList<ProblemReport> problemReports = new ArrayList<>();
Iterator<ProblemReport> iter = entry.getKey() == null ? ProblemReports.getInstance(monitor.getContext()).iterator() : ProblemReports.getInstance(monitor.getContext()).iterator(entry.getKey());
while (iter.hasNext()) {
problemReports.add(iter.next());
}
for (ProblemReport pr : problemReports) {
String tableName = monitor.getContext().getPrintableTableInfoFromId(pr.getTableId());
problems.addProblemDetail(new ProblemDetailInformation(tableName, entry.getKey(), pr.getProblemType().name(), pr.getServer(), pr.getTime(), pr.getResource(), pr.getException()));
}
}
}
return problems;
}
use of org.apache.accumulo.core.data.TableId in project accumulo by apache.
the class CompactableUtils method selectFiles.
static Set<StoredTabletFile> selectFiles(Tablet tablet, SortedMap<StoredTabletFile, DataFileValue> datafiles, PluginConfig selectorConfig) {
CompactionSelector selector = newInstance(tablet.getTableConfiguration(), selectorConfig.getClassName(), CompactionSelector.class);
final ServiceEnvironment senv = new ServiceEnvironmentImpl(tablet.getContext());
selector.init(new CompactionSelector.InitParameters() {
@Override
public Map<String, String> getOptions() {
return selectorConfig.getOptions();
}
@Override
public PluginEnvironment getEnvironment() {
return senv;
}
@Override
public TableId getTableId() {
return tablet.getExtent().tableId();
}
});
Selection selection = selector.select(new CompactionSelector.SelectionParameters() {
@Override
public PluginEnvironment getEnvironment() {
return senv;
}
@Override
public Collection<CompactableFile> getAvailableFiles() {
return Collections2.transform(datafiles.entrySet(), e -> new CompactableFileImpl(e.getKey(), e.getValue()));
}
@Override
public Collection<Summary> getSummaries(Collection<CompactableFile> files, Predicate<SummarizerConfiguration> summarySelector) {
var context = tablet.getContext();
var tsrm = tablet.getTabletResources().getTabletServerResourceManager();
SummaryCollection sc = new SummaryCollection();
SummarizerFactory factory = new SummarizerFactory(tablet.getTableConfiguration());
for (CompactableFile cf : files) {
var file = CompactableFileImpl.toStoredTabletFile(cf);
FileSystem fs = context.getVolumeManager().getFileSystemByPath(file.getPath());
Configuration conf = context.getHadoopConf();
SummaryCollection fsc = SummaryReader.load(fs, conf, factory, file.getPath(), summarySelector, tsrm.getSummaryCache(), tsrm.getIndexCache(), tsrm.getFileLenCache(), context.getCryptoService()).getSummaries(Collections.singletonList(new Gatherer.RowRange(tablet.getExtent())));
sc.merge(fsc, factory);
}
return sc.getSummaries();
}
@Override
public TableId getTableId() {
return tablet.getExtent().tableId();
}
@Override
public Optional<SortedKeyValueIterator<Key, Value>> getSample(CompactableFile file, SamplerConfiguration sc) {
try {
FileOperations fileFactory = FileOperations.getInstance();
Path path = new Path(file.getUri());
FileSystem ns = tablet.getTabletServer().getVolumeManager().getFileSystemByPath(path);
var fiter = fileFactory.newReaderBuilder().forFile(path.toString(), ns, ns.getConf(), tablet.getContext().getCryptoService()).withTableConfiguration(tablet.getTableConfiguration()).seekToBeginning().build();
return Optional.ofNullable(fiter.getSample(new SamplerConfigurationImpl(sc)));
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
});
return selection.getFilesToCompact().stream().map(CompactableFileImpl::toStoredTabletFile).collect(Collectors.toSet());
}
use of org.apache.accumulo.core.data.TableId in project accumulo by apache.
the class ReplicationServicerHandler method replicateLog.
@Override
public long replicateLog(String tableIdStr, WalEdits data, TCredentials tcreds) throws TException {
TableId tableId = TableId.of(tableIdStr);
log.debug("Got replication request to tableID {} with {} edits", tableId, data.getEditsSize());
tabletServer.getSecurityOperation().authenticateUser(tabletServer.getContext().rpcCreds(), tcreds);
String tableName;
try {
tableName = tabletServer.getContext().getTableName(tableId);
} catch (TableNotFoundException e) {
log.error("Could not find table with id {}", tableId);
throw new RemoteReplicationException(RemoteReplicationErrorCode.TABLE_DOES_NOT_EXIST, "Table with id " + tableId + " does not exist");
}
AccumuloConfiguration conf = tabletServer.getConfiguration();
Map<String, String> replicationHandlers = conf.getAllPropertiesWithPrefix(Property.TSERV_REPLICATION_REPLAYERS);
String propertyForHandlerTable = Property.TSERV_REPLICATION_REPLAYERS.getKey() + tableId;
String handlerClassForTable = replicationHandlers.get(propertyForHandlerTable);
if (handlerClassForTable == null) {
if (!replicationHandlers.isEmpty()) {
log.debug("Could not find replication replayer for {}", tableId);
}
handlerClassForTable = conf.get(Property.TSERV_REPLICATION_DEFAULT_HANDLER);
}
log.debug("Using {} replication replayer for table {}", handlerClassForTable, tableId);
// Get class for replayer
Class<? extends AccumuloReplicationReplayer> clz;
try {
Class<?> untypedClz = Class.forName(handlerClassForTable);
clz = untypedClz.asSubclass(AccumuloReplicationReplayer.class);
} catch (ClassNotFoundException e) {
log.error("Could not instantiate replayer class {}", handlerClassForTable, e);
throw new RemoteReplicationException(RemoteReplicationErrorCode.CANNOT_INSTANTIATE_REPLAYER, "Could not instantiate replayer class " + handlerClassForTable);
}
// Create an instance
AccumuloReplicationReplayer replayer;
try {
replayer = clz.getDeclaredConstructor().newInstance();
} catch (ReflectiveOperationException e1) {
log.error("Could not instantiate replayer class {}", clz.getName());
throw new RemoteReplicationException(RemoteReplicationErrorCode.CANNOT_INSTANTIATE_REPLAYER, "Could not instantiate replayer class" + clz.getName());
}
long entriesReplicated;
try {
entriesReplicated = replayer.replicateLog(tabletServer.getContext(), tableName, data);
} catch (AccumuloException | AccumuloSecurityException e) {
log.error("Could not get connection", e);
throw new RemoteReplicationException(RemoteReplicationErrorCode.CANNOT_AUTHENTICATE, "Cannot get connection as " + tabletServer.getContext().getCredentials().getPrincipal());
}
log.debug("Replicated {} mutations to {}", entriesReplicated, tableName);
return entriesReplicated;
}
Aggregations