use of org.apache.accumulo.core.client.NamespaceNotFoundException in project accumulo by apache.
the class ClientServiceHandler method getNamespaceConfiguration.
@Override
public Map<String, String> getNamespaceConfiguration(TInfo tinfo, TCredentials credentials, String ns) throws ThriftTableOperationException, TException {
Namespace.ID namespaceId;
try {
namespaceId = Namespaces.getNamespaceId(instance, ns);
} catch (NamespaceNotFoundException e) {
String why = "Could not find namespace while getting configuration.";
throw new ThriftTableOperationException(null, ns, null, TableOperationExceptionType.NAMESPACE_NOTFOUND, why);
}
AccumuloConfiguration config = context.getServerConfigurationFactory().getNamespaceConfiguration(namespaceId);
return conf(credentials, config);
}
use of org.apache.accumulo.core.client.NamespaceNotFoundException in project accumulo by apache.
the class ConfigCommand method execute.
@Override
public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws AccumuloException, AccumuloSecurityException, TableNotFoundException, IOException, ClassNotFoundException, NamespaceNotFoundException {
reader = shellState.getReader();
final String tableName = cl.getOptionValue(tableOpt.getOpt());
if (tableName != null && !shellState.getConnector().tableOperations().exists(tableName)) {
throw new TableNotFoundException(null, tableName, null);
}
final String namespace = cl.getOptionValue(namespaceOpt.getOpt());
if (namespace != null && !shellState.getConnector().namespaceOperations().exists(namespace)) {
throw new NamespaceNotFoundException(null, namespace, null);
}
if (cl.hasOption(deleteOpt.getOpt())) {
// delete property from table
String property = cl.getOptionValue(deleteOpt.getOpt());
if (property.contains("=")) {
throw new BadArgumentException("Invalid '=' operator in delete operation.", fullCommand, fullCommand.indexOf('='));
}
if (tableName != null) {
if (!Property.isValidTablePropertyKey(property)) {
Shell.log.warn("Invalid per-table property : " + property + ", still removing from zookeeper if it's there.");
}
shellState.getConnector().tableOperations().removeProperty(tableName, property);
Shell.log.debug("Successfully deleted table configuration option.");
} else if (namespace != null) {
if (!Property.isValidTablePropertyKey(property)) {
Shell.log.warn("Invalid per-table property : " + property + ", still removing from zookeeper if it's there.");
}
shellState.getConnector().namespaceOperations().removeProperty(namespace, property);
Shell.log.debug("Successfully deleted namespace configuration option.");
} else {
if (!Property.isValidZooPropertyKey(property)) {
Shell.log.warn("Invalid per-table property : " + property + ", still removing from zookeeper if it's there.");
}
shellState.getConnector().instanceOperations().removeProperty(property);
Shell.log.debug("Successfully deleted system configuration option");
}
} else if (cl.hasOption(setOpt.getOpt())) {
// set property on table
String property = cl.getOptionValue(setOpt.getOpt()), value = null;
if (!property.contains("=")) {
throw new BadArgumentException("Missing '=' operator in set operation.", fullCommand, fullCommand.indexOf(property));
}
final String[] pair = property.split("=", 2);
property = pair[0];
value = pair[1];
if (tableName != null) {
if (!Property.isValidTablePropertyKey(property)) {
throw new BadArgumentException("Invalid per-table property.", fullCommand, fullCommand.indexOf(property));
}
if (property.equals(Property.TABLE_DEFAULT_SCANTIME_VISIBILITY.getKey())) {
// validate that it is a valid expression
new ColumnVisibility(value);
}
shellState.getConnector().tableOperations().setProperty(tableName, property, value);
Shell.log.debug("Successfully set table configuration option.");
} else if (namespace != null) {
if (!Property.isValidTablePropertyKey(property)) {
throw new BadArgumentException("Invalid per-table property.", fullCommand, fullCommand.indexOf(property));
}
if (property.equals(Property.TABLE_DEFAULT_SCANTIME_VISIBILITY.getKey())) {
// validate that it is a valid expression
new ColumnVisibility(value);
}
shellState.getConnector().namespaceOperations().setProperty(namespace, property, value);
Shell.log.debug("Successfully set table configuration option.");
} else {
if (!Property.isValidZooPropertyKey(property)) {
throw new BadArgumentException("Property cannot be modified in zookeeper", fullCommand, fullCommand.indexOf(property));
}
shellState.getConnector().instanceOperations().setProperty(property, value);
Shell.log.debug("Successfully set system configuration option");
}
} else {
// display properties
final TreeMap<String, String> systemConfig = new TreeMap<>();
systemConfig.putAll(shellState.getConnector().instanceOperations().getSystemConfiguration());
final String outputFile = cl.getOptionValue(outputFileOpt.getOpt());
final PrintFile printFile = outputFile == null ? null : new PrintFile(outputFile);
final TreeMap<String, String> siteConfig = new TreeMap<>();
siteConfig.putAll(shellState.getConnector().instanceOperations().getSiteConfiguration());
final TreeMap<String, String> defaults = new TreeMap<>();
for (Entry<String, String> defaultEntry : DefaultConfiguration.getInstance()) {
defaults.put(defaultEntry.getKey(), defaultEntry.getValue());
}
final TreeMap<String, String> namespaceConfig = new TreeMap<>();
if (tableName != null) {
String n = Namespaces.getNamespaceName(shellState.getInstance(), Tables.getNamespaceId(shellState.getInstance(), Tables.getTableId(shellState.getInstance(), tableName)));
for (Entry<String, String> e : shellState.getConnector().namespaceOperations().getProperties(n)) {
namespaceConfig.put(e.getKey(), e.getValue());
}
}
Iterable<Entry<String, String>> acuconf = shellState.getConnector().instanceOperations().getSystemConfiguration().entrySet();
if (tableName != null) {
acuconf = shellState.getConnector().tableOperations().getProperties(tableName);
} else if (namespace != null) {
acuconf = shellState.getConnector().namespaceOperations().getProperties(namespace);
}
final TreeMap<String, String> sortedConf = new TreeMap<>();
for (Entry<String, String> propEntry : acuconf) {
sortedConf.put(propEntry.getKey(), propEntry.getValue());
}
for (Entry<String, String> propEntry : acuconf) {
final String key = propEntry.getKey();
// specified, or all of them if none specified
if (cl.hasOption(filterOpt.getOpt()) && !key.contains(cl.getOptionValue(filterOpt.getOpt()))) {
continue;
}
if ((tableName != null || namespace != null) && !Property.isValidTablePropertyKey(key)) {
continue;
}
COL2 = Math.max(COL2, propEntry.getKey().length() + 3);
}
final ArrayList<String> output = new ArrayList<>();
printConfHeader(output);
for (Entry<String, String> propEntry : sortedConf.entrySet()) {
final String key = propEntry.getKey();
// specified, or all of them if none specified
if (cl.hasOption(filterOpt.getOpt()) && !key.contains(cl.getOptionValue(filterOpt.getOpt()))) {
continue;
}
if ((tableName != null || namespace != null) && !Property.isValidTablePropertyKey(key)) {
continue;
}
String siteVal = siteConfig.get(key);
String sysVal = systemConfig.get(key);
String curVal = propEntry.getValue();
String dfault = defaults.get(key);
String nspVal = namespaceConfig.get(key);
boolean printed = false;
if (dfault != null && key.toLowerCase().contains("password")) {
siteVal = sysVal = dfault = curVal = curVal.replaceAll(".", "*");
}
if (sysVal != null) {
if (defaults.containsKey(key) && !Property.getPropertyByKey(key).isExperimental()) {
printConfLine(output, "default", key, dfault);
printed = true;
}
if (!defaults.containsKey(key) || !defaults.get(key).equals(siteVal)) {
printConfLine(output, "site", printed ? " @override" : key, siteVal == null ? "" : siteVal);
printed = true;
}
if (!siteConfig.containsKey(key) || !siteVal.equals(sysVal)) {
printConfLine(output, "system", printed ? " @override" : key, sysVal);
printed = true;
}
}
if (nspVal != null) {
if (!systemConfig.containsKey(key) || !sysVal.equals(nspVal)) {
printConfLine(output, "namespace", printed ? " @override" : key, nspVal);
printed = true;
}
}
// show per-table value only if it is different (overridden)
if (tableName != null && !curVal.equals(nspVal)) {
printConfLine(output, "table", printed ? " @override" : key, curVal);
} else if (namespace != null && !curVal.equals(sysVal)) {
printConfLine(output, "namespace", printed ? " @override" : key, curVal);
}
}
printConfFooter(output);
shellState.printLines(output.iterator(), !cl.hasOption(disablePaginationOpt.getOpt()), printFile);
if (printFile != null) {
printFile.close();
}
}
return 0;
}
use of org.apache.accumulo.core.client.NamespaceNotFoundException in project accumulo by apache.
the class DUCommand method execute.
@Override
public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws IOException, TableNotFoundException, NamespaceNotFoundException {
final SortedSet<String> tables = new TreeSet<>(Arrays.asList(cl.getArgs()));
if (cl.hasOption(ShellOptions.tableOption)) {
tables.add(cl.getOptionValue(ShellOptions.tableOption));
}
if (cl.hasOption(optNamespace.getOpt())) {
Instance instance = shellState.getInstance();
Namespace.ID namespaceId = Namespaces.getNamespaceId(instance, cl.getOptionValue(optNamespace.getOpt()));
tables.addAll(Namespaces.getTableNames(instance, namespaceId));
}
boolean prettyPrint = cl.hasOption(optHumanReadble.getOpt()) ? true : false;
// Add any patterns
if (cl.hasOption(optTablePattern.getOpt())) {
for (String table : shellState.getConnector().tableOperations().list()) {
if (table.matches(cl.getOptionValue(optTablePattern.getOpt()))) {
tables.add(table);
}
}
}
// If we didn't get any tables, and we have a table selected, add the current table
if (tables.isEmpty() && !shellState.getTableName().isEmpty()) {
tables.add(shellState.getTableName());
}
// sanity check...make sure the user-specified tables exist
for (String tableName : tables) {
if (!shellState.getConnector().tableOperations().exists(tableName)) {
throw new TableNotFoundException(tableName, tableName, "specified table that doesn't exist");
}
}
try {
String valueFormat = prettyPrint ? "%9s" : "%,24d";
for (DiskUsage usage : shellState.getConnector().tableOperations().getDiskUsage(tables)) {
Object value = prettyPrint ? NumUtil.bigNumberForSize(usage.getUsage()) : usage.getUsage();
shellState.getReader().println(String.format(valueFormat + " %s", value, usage.getTables()));
}
} catch (Exception ex) {
throw new RuntimeException(ex);
}
return 0;
}
use of org.apache.accumulo.core.client.NamespaceNotFoundException in project accumulo by apache.
the class MockNamespaceOperations method rename.
@Override
public void rename(String oldNamespaceName, String newNamespaceName) throws AccumuloSecurityException, NamespaceNotFoundException, AccumuloException, NamespaceExistsException {
if (!exists(oldNamespaceName))
throw new NamespaceNotFoundException(oldNamespaceName, oldNamespaceName, "");
if (exists(newNamespaceName))
throw new NamespaceExistsException(newNamespaceName, newNamespaceName, "");
MockNamespace n = acu.namespaces.get(oldNamespaceName);
for (String t : n.getTables(acu)) {
String tt = newNamespaceName + "." + Tables.qualify(t).getSecond();
acu.tables.put(tt, acu.tables.remove(t));
}
acu.namespaces.put(newNamespaceName, acu.namespaces.remove(oldNamespaceName));
}
use of org.apache.accumulo.core.client.NamespaceNotFoundException in project accumulo by apache.
the class TableOperationsImpl method compact.
@Override
public void compact(String tableName, CompactionConfig config) throws AccumuloSecurityException, TableNotFoundException, AccumuloException {
checkArgument(tableName != null, "tableName is null");
ByteBuffer EMPTY = ByteBuffer.allocate(0);
// Ensure compaction iterators exist on a tabletserver
final String skviName = SortedKeyValueIterator.class.getName();
for (IteratorSetting setting : config.getIterators()) {
String iteratorClass = setting.getIteratorClass();
if (!testClassLoad(tableName, iteratorClass, skviName)) {
throw new AccumuloException("TabletServer could not load iterator class " + iteratorClass);
}
}
// Make sure the specified compaction strategy exists on a tabletserver
final String compactionStrategyName = config.getCompactionStrategy().getClassName();
if (!CompactionStrategyConfigUtil.DEFAULT_STRATEGY.getClassName().equals(compactionStrategyName)) {
if (!testClassLoad(tableName, compactionStrategyName, "org.apache.accumulo.tserver.compaction.CompactionStrategy")) {
throw new AccumuloException("TabletServer could not load CompactionStrategy class " + compactionStrategyName);
}
}
Table.ID tableId = Tables.getTableId(context.getInstance(), tableName);
Text start = config.getStartRow();
Text end = config.getEndRow();
if (config.getFlush())
_flush(tableId, start, end, true);
List<ByteBuffer> args = Arrays.asList(ByteBuffer.wrap(tableId.getUtf8()), start == null ? EMPTY : TextUtil.getByteBuffer(start), end == null ? EMPTY : TextUtil.getByteBuffer(end), ByteBuffer.wrap(IteratorUtil.encodeIteratorSettings(config.getIterators())), ByteBuffer.wrap(CompactionStrategyConfigUtil.encode(config.getCompactionStrategy())));
Map<String, String> opts = new HashMap<>();
try {
doFateOperation(FateOperation.TABLE_COMPACT, args, opts, tableName, config.getWait());
} catch (TableExistsException | NamespaceExistsException e) {
// should not happen
throw new AssertionError(e);
} catch (NamespaceNotFoundException e) {
throw new TableNotFoundException(null, tableName, "Namespace not found", e);
}
}
Aggregations