use of org.apache.accumulo.core.tabletserver.thrift.ConstraintViolationException in project accumulo by apache.
the class Shell method execCommand.
public void execCommand(String input, boolean ignoreAuthTimeout, boolean echoPrompt) throws IOException {
audit.log(Level.INFO, getDefaultPrompt() + input);
if (echoPrompt) {
reader.print(getDefaultPrompt());
reader.println(input);
}
if (input.startsWith(COMMENT_PREFIX)) {
return;
}
String[] fields;
try {
fields = new QuotedStringTokenizer(input).getTokens();
} catch (BadArgumentException e) {
printException(e);
++exitCode;
return;
}
if (fields.length == 0)
return;
String command = fields[0];
fields = fields.length > 1 ? Arrays.copyOfRange(fields, 1, fields.length) : new String[] {};
Command sc = null;
if (command.length() > 0) {
try {
// Obtain the command from the command table
sc = commandFactory.get(command);
if (sc == null) {
reader.println(String.format("Unknown command \"%s\". Enter \"help\" for a list possible commands.", command));
reader.flush();
return;
}
long duration = System.nanoTime() - lastUserActivity;
if (!(sc instanceof ExitCommand) && !ignoreAuthTimeout && (duration < 0 || duration > authTimeout)) {
reader.println("Shell has been idle for too long. Please re-authenticate.");
boolean authFailed = true;
do {
String pwd = readMaskedLine("Enter current password for '" + connector.whoami() + "': ", '*');
if (pwd == null) {
reader.println();
return;
}
try {
authFailed = !connector.securityOperations().authenticateUser(connector.whoami(), new PasswordToken(pwd));
} catch (Exception e) {
++exitCode;
printException(e);
}
if (authFailed)
reader.print("Invalid password. ");
} while (authFailed);
lastUserActivity = System.nanoTime();
}
// Get the options from the command on how to parse the string
Options parseOpts = sc.getOptionsWithHelp();
// Parse the string using the given options
CommandLine cl = new BasicParser().parse(parseOpts, fields);
int actualArgLen = cl.getArgs().length;
int expectedArgLen = sc.numArgs();
if (cl.hasOption(helpOption)) {
// Display help if asked to; otherwise execute the command
sc.printHelp(this);
} else if (expectedArgLen != NO_FIXED_ARG_LENGTH_CHECK && actualArgLen != expectedArgLen) {
++exitCode;
// Check for valid number of fixed arguments (if not
// negative; negative means it is not checked, for
// vararg-like commands)
printException(new IllegalArgumentException(String.format("Expected %d argument%s. There %s %d.", expectedArgLen, expectedArgLen == 1 ? "" : "s", actualArgLen == 1 ? "was" : "were", actualArgLen)));
sc.printHelp(this);
} else {
int tmpCode = sc.execute(input, cl, this);
exitCode += tmpCode;
reader.flush();
}
} catch (ConstraintViolationException e) {
++exitCode;
printConstraintViolationException(e);
} catch (TableNotFoundException e) {
++exitCode;
if (getTableName().equals(e.getTableName()))
setTableName("");
printException(e);
} catch (ParseException e) {
// option when the user is asking for help
if (!(e instanceof MissingOptionException && (Arrays.asList(fields).contains("-" + helpOption) || Arrays.asList(fields).contains("--" + helpLongOption)))) {
++exitCode;
printException(e);
}
if (sc != null)
sc.printHelp(this);
} catch (UserInterruptException e) {
++exitCode;
} catch (Exception e) {
++exitCode;
printException(e);
}
} else {
++exitCode;
printException(new BadArgumentException("Unrecognized empty command", command, -1));
}
reader.flush();
}
use of org.apache.accumulo.core.tabletserver.thrift.ConstraintViolationException in project accumulo by apache.
the class Writer method update.
public void update(Mutation m) throws AccumuloException, AccumuloSecurityException, ConstraintViolationException, TableNotFoundException {
checkArgument(m != null, "m is null");
if (m.size() == 0)
throw new IllegalArgumentException("Can not add empty mutations");
while (true) {
TabletLocation tabLoc = TabletLocator.getLocator(context, tableId).locateTablet(context, new Text(m.getRow()), false, true);
if (tabLoc == null) {
log.trace("No tablet location found for row {}", new String(m.getRow(), UTF_8));
sleepUninterruptibly(500, TimeUnit.MILLISECONDS);
continue;
}
final HostAndPort parsedLocation = HostAndPort.fromString(tabLoc.tablet_location);
try {
updateServer(context, m, tabLoc.tablet_extent, parsedLocation);
return;
} catch (NotServingTabletException e) {
log.trace("Not serving tablet, server = {}", parsedLocation);
TabletLocator.getLocator(context, tableId).invalidateCache(tabLoc.tablet_extent);
} catch (ConstraintViolationException cve) {
log.error("error sending update to {}", parsedLocation, cve);
// probably do not need to invalidate cache, but it does not hurt
TabletLocator.getLocator(context, tableId).invalidateCache(tabLoc.tablet_extent);
throw cve;
} catch (TException e) {
log.error("error sending update to {}", parsedLocation, e);
TabletLocator.getLocator(context, tableId).invalidateCache(tabLoc.tablet_extent);
}
sleepUninterruptibly(500, TimeUnit.MILLISECONDS);
}
}
use of org.apache.accumulo.core.tabletserver.thrift.ConstraintViolationException in project accumulo by apache.
the class MetaConstraintRetryIT method test.
// a test for ACCUMULO-3096
@Test(expected = ConstraintViolationException.class)
public void test() throws Exception {
getConnector().securityOperations().grantTablePermission(getAdminPrincipal(), MetadataTable.NAME, TablePermission.WRITE);
Credentials credentials = new Credentials(getAdminPrincipal(), getAdminToken());
ClientContext context = new ClientContext(getConnector().getInstance(), credentials, cluster.getClientConfig());
Writer w = new Writer(context, MetadataTable.ID);
KeyExtent extent = new KeyExtent(Table.ID.of("5"), null, null);
Mutation m = new Mutation(extent.getMetadataEntry());
// unknown columns should cause contraint violation
m.put("badcolfam", "badcolqual", "3");
try {
MetadataTableUtil.update(w, null, m);
} catch (RuntimeException e) {
if (e.getCause().getClass().equals(ConstraintViolationException.class)) {
throw (ConstraintViolationException) e.getCause();
}
}
}
Aggregations