in shell/src/main/java/org/apache/accumulo/shell/commands/ConfigCommand.java [77:368]
public int execute(final String fullCommand, final CommandLine cl, final Shell shellState)
throws AccumuloException, AccumuloSecurityException, TableNotFoundException, IOException,
NamespaceNotFoundException {
reader = shellState.getReader();
boolean force = cl.hasOption(forceOpt);
final String tableName = cl.getOptionValue(tableOpt.getOpt());
if (tableName != null && !shellState.getAccumuloClient().tableOperations().exists(tableName)) {
throw new TableNotFoundException(null, tableName, null);
}
final String namespace = cl.getOptionValue(namespaceOpt.getOpt());
if (namespace != null
&& !shellState.getAccumuloClient().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('='));
}
String invalidTablePropFormatString =
"Invalid per-table property : {}, still removing from zookeeper if it's there.";
if (tableName != null) {
if (!Property.isValidTablePropertyKey(property)) {
Shell.log.warn(invalidTablePropFormatString, property);
}
shellState.getAccumuloClient().tableOperations().removeProperty(tableName, property);
Shell.log.debug("Successfully deleted table configuration option.");
} else if (namespace != null) {
if (!Property.isValidTablePropertyKey(property)) {
Shell.log.warn(invalidTablePropFormatString, property);
}
shellState.getAccumuloClient().namespaceOperations().removeProperty(namespace, property);
Shell.log.debug("Successfully deleted namespace configuration option.");
} else {
if (!Property.isValidZooPropertyKey(property)) {
Shell.log.warn(invalidTablePropFormatString, property);
}
shellState.getAccumuloClient().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());
String value;
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];
// check for deprecation
var theProp = Property.getPropertyByKey(property);
if (theProp != null && theProp.isDeprecated()) {
if (!force
&& !shellState.confirm("Trying to set deprecated property `" + property + "` continue")
.orElse(false)) {
throw new BadArgumentException(
"Tried to set deprecated property and force not specified.", fullCommand,
fullCommand.indexOf(property));
}
}
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())) {
new ColumnVisibility(value); // validate that it is a valid expression
}
shellState.getAccumuloClient().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())) {
new ColumnVisibility(value); // validate that it is a valid expression
}
shellState.getAccumuloClient().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.getAccumuloClient().instanceOperations().setProperty(property, value);
Shell.log.debug("Successfully set system configuration option.");
}
} else {
boolean warned = false;
// display properties
final TreeMap<String,String> systemConfig = new TreeMap<>();
try {
systemConfig
.putAll(shellState.getAccumuloClient().instanceOperations().getSystemConfiguration());
} catch (AccumuloSecurityException e) {
if (e.getSecurityErrorCode() == PERMISSION_DENIED) {
Shell.log.warn(
"User unable to retrieve system configuration (requires System.SYSTEM permission)");
warned = true;
} else {
throw e;
}
}
final String outputFile = cl.getOptionValue(outputFileOpt.getOpt());
final PrintFile printFile = outputFile == null ? null : new PrintFile(outputFile);
final TreeMap<String,String> siteConfig = new TreeMap<>();
try {
siteConfig
.putAll(shellState.getAccumuloClient().instanceOperations().getSiteConfiguration());
} catch (AccumuloSecurityException e) {
if (e.getSecurityErrorCode() == PERMISSION_DENIED) {
Shell.log.warn(
"User unable to retrieve site configuration (requires System.SYSTEM permission)");
warned = true;
} else {
throw e;
}
}
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 = TableNameUtil.qualify(tableName).getFirst();
try {
namespaceConfig
.putAll(shellState.getAccumuloClient().namespaceOperations().getConfiguration(n));
} catch (AccumuloSecurityException e) {
if (e.getSecurityErrorCode() == PERMISSION_DENIED) {
Shell.log.warn(
"User unable to retrieve {} namespace configuration (requires Namespace.ALTER_NAMESPACE permission)",
StringUtils.isEmpty(n) ? "default" : n);
warned = true;
} else {
throw e;
}
}
}
Map<String,String> acuconf = systemConfig;
if (acuconf.isEmpty()) {
acuconf = defaults;
}
if (tableName != null) {
if (warned) {
Shell.log.warn(
"User does not have permission to see entire configuration heirarchy. Property values shown below may be set above the table level.");
}
try {
acuconf = shellState.getAccumuloClient().tableOperations().getConfiguration(tableName);
} catch (AccumuloException e) {
if (e.getCause() != null && e.getCause() instanceof AccumuloSecurityException) {
AccumuloSecurityException ase = (AccumuloSecurityException) e.getCause();
if (ase.getSecurityErrorCode() == PERMISSION_DENIED) {
Shell.log.error(
"User unable to retrieve {} table configuration (requires Table.ALTER_TABLE permission)",
tableName);
}
}
throw e;
}
} else if (namespace != null) {
if (warned) {
Shell.log.warn(
"User does not have permission to see entire configuration heirarchy. Property values shown below may be set above the namespace level.");
}
try {
acuconf =
shellState.getAccumuloClient().namespaceOperations().getConfiguration(namespace);
} catch (AccumuloSecurityException e) {
Shell.log.error(
"User unable to retrieve {} namespace configuration (requires Namespace.ALTER_NAMESPACE permission)",
StringUtils.isEmpty(namespace) ? "default" : namespace);
throw e;
}
}
final Map<String,String> sortedConf = ImmutableSortedMap.copyOf(acuconf);
for (Entry<String,String> propEntry : acuconf.entrySet()) {
final String key = propEntry.getKey();
final String value = propEntry.getValue();
// only show properties which names or values
// match the filter text
if (matchTheFilterText(cl, key, value)) {
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();
final String value = propEntry.getValue();
// only show properties which names or values
// match the filter text
if (matchTheFilterText(cl, key, value)) {
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 (sysVal != null) {
if (dfault != null && key.toLowerCase().contains("password")) {
siteVal = sysVal = dfault = curVal = curVal.replaceAll(".", "*");
}
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) || !Objects.equals(siteVal, sysVal)) {
printConfLine(output, "system", printed ? " @override" : key, sysVal);
printed = true;
}
}
if (nspVal != null) {
// If the user can't see the system configuration, then print the default
// configuration value if the current namespace value is different from it.
if (sysVal == null && dfault != null && !dfault.equals(nspVal)
&& !Property.getPropertyByKey(key).isExperimental()) {
printConfLine(output, "default", key, dfault);
printed = true;
}
if (!systemConfig.containsKey(key) || !Objects.equals(sysVal, 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)) {
// If the user can't see the system configuration, then print the default
// configuration value if the current table value is different from it.
if (nspVal == null && dfault != null && !dfault.equals(curVal)
&& !Property.getPropertyByKey(key).isExperimental()) {
printConfLine(output, "default", key, dfault);
printed = true;
}
printConfLine(output, "table", printed ? " @override" : key, curVal);
} else if (namespace != null && !curVal.equals(sysVal)) {
// If the user can't see the system configuration, then print the default
// configuration value if the current namespace value is different from it.
if (sysVal == null && dfault != null && !dfault.equals(curVal)
&& !Property.getPropertyByKey(key).isExperimental()) {
printConfLine(output, "default", key, dfault);
printed = true;
}
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;
}