use of org.apache.accumulo.core.client.TableExistsException in project accumulo by apache.
the class TableOperationsImpl method doFateOperation.
String doFateOperation(FateOperation op, List<ByteBuffer> args, Map<String, String> opts, String tableOrNamespaceName, boolean wait) throws AccumuloSecurityException, TableExistsException, TableNotFoundException, AccumuloException, NamespaceExistsException, NamespaceNotFoundException {
Long opid = null;
try {
opid = beginFateOperation();
executeFateOperation(opid, op, args, opts, !wait);
if (!wait) {
opid = null;
return null;
}
String ret = waitForFateOperation(opid);
return ret;
} catch (ThriftSecurityException e) {
switch(e.getCode()) {
case TABLE_DOESNT_EXIST:
throw new TableNotFoundException(null, tableOrNamespaceName, "Target table does not exist");
case NAMESPACE_DOESNT_EXIST:
throw new NamespaceNotFoundException(null, tableOrNamespaceName, "Target namespace does not exist");
default:
String tableInfo = Tables.getPrintableTableInfoFromName(context.getInstance(), tableOrNamespaceName);
throw new AccumuloSecurityException(e.user, e.code, tableInfo, e);
}
} catch (ThriftTableOperationException e) {
switch(e.getType()) {
case EXISTS:
throw new TableExistsException(e);
case NOTFOUND:
throw new TableNotFoundException(e);
case NAMESPACE_EXISTS:
throw new NamespaceExistsException(e);
case NAMESPACE_NOTFOUND:
throw new NamespaceNotFoundException(e);
case OFFLINE:
throw new TableOfflineException(context.getInstance(), Tables.getTableId(context.getInstance(), tableOrNamespaceName).canonicalID());
default:
throw new AccumuloException(e.description, e);
}
} catch (Exception e) {
throw new AccumuloException(e.getMessage(), e);
} finally {
Tables.clearCache(context.getInstance());
// always finish table op, even when exception
if (opid != null)
try {
finishFateOperation(opid);
} catch (Exception e) {
log.warn("Exception thrown while finishing fate table operation", e);
}
}
}
use of org.apache.accumulo.core.client.TableExistsException in project accumulo by apache.
the class TraceServer method ensureTraceTableExists.
/**
* Exceptions thrown out of here should be things that cause service failure (e.g. misconfigurations that aren't likely to change on retry).
*
* @return a working Connection that can be reused
* @throws ClassNotFoundException
* if TRACE_TOKEN_TYPE is set to a class that we can't load.
* @throws InstantiationException
* if we fail to create an instance of TRACE_TOKEN_TYPE.
* @throws IllegalAccessException
* if the class pointed to by TRACE_TOKEN_TYPE is private.
* @throws AccumuloSecurityException
* if the trace user has the wrong permissions
*/
private Connector ensureTraceTableExists(final AccumuloConfiguration conf) throws AccumuloSecurityException, ClassNotFoundException, InstantiationException, IllegalAccessException {
Connector connector = null;
while (true) {
try {
final boolean isDefaultTokenType = conf.get(Property.TRACE_TOKEN_TYPE).equals(Property.TRACE_TOKEN_TYPE.getDefaultValue());
String principal = conf.get(Property.TRACE_USER);
if (conf.getBoolean(Property.INSTANCE_RPC_SASL_ENABLED)) {
// Make sure that we replace _HOST if it exists in the principal
principal = SecurityUtil.getServerPrincipal(principal);
}
AuthenticationToken at;
Map<String, String> loginMap = conf.getAllPropertiesWithPrefix(Property.TRACE_TOKEN_PROPERTY_PREFIX);
if (loginMap.isEmpty() && isDefaultTokenType) {
// Assume the old type of user/password specification
Property p = Property.TRACE_PASSWORD;
at = new PasswordToken(conf.get(p).getBytes(UTF_8));
} else {
Properties props = new Properties();
AuthenticationToken token = AccumuloVFSClassLoader.getClassLoader().loadClass(conf.get(Property.TRACE_TOKEN_TYPE)).asSubclass(AuthenticationToken.class).newInstance();
int prefixLength = Property.TRACE_TOKEN_PROPERTY_PREFIX.getKey().length();
for (Entry<String, String> entry : loginMap.entrySet()) {
props.put(entry.getKey().substring(prefixLength), entry.getValue());
}
token.init(props);
at = token;
}
connector = instance.getConnector(principal, at);
if (!connector.tableOperations().exists(tableName)) {
connector.tableOperations().create(tableName);
IteratorSetting setting = new IteratorSetting(10, "ageoff", AgeOffFilter.class.getName());
AgeOffFilter.setTTL(setting, 7 * 24 * 60 * 60 * 1000l);
connector.tableOperations().attachIterator(tableName, setting);
}
connector.tableOperations().setProperty(tableName, Property.TABLE_FORMATTER_CLASS.getKey(), TraceFormatter.class.getName());
break;
} catch (AccumuloException | TableExistsException | TableNotFoundException | IOException | RuntimeException ex) {
log.info("Waiting to checking/create the trace table.", ex);
sleepUninterruptibly(1, TimeUnit.SECONDS);
}
}
return connector;
}
use of org.apache.accumulo.core.client.TableExistsException in project Gaffer by gchq.
the class AccumuloIDWithinSetRetrieverTest method setupGraph.
private static void setupGraph(final AccumuloStore store) {
try {
// Create table
// (this method creates the table, removes the versioning iterator, and adds the SetOfStatisticsCombiner iterator,
// and sets the age off iterator to age data off after it is more than ageOffTimeInMilliseconds milliseconds old).
TableUtils.createTable(store);
final Set<Element> data = new HashSet<>();
// Create edges A0 -> A1, A0 -> A2, ..., A0 -> A99. Also create an Entity for each.
final Entity entity = new Entity(TestGroups.ENTITY);
entity.setVertex("A0");
entity.putProperty(AccumuloPropertyNames.COUNT, 10000);
data.add(entity);
for (int i = 1; i < 100; i++) {
data.add(new Edge.Builder().group(TestGroups.EDGE).source("A0").dest("A" + i).directed(true).property(AccumuloPropertyNames.COLUMN_QUALIFIER, 1).property(AccumuloPropertyNames.COUNT, i).build());
data.add(new Entity.Builder().group(TestGroups.ENTITY).vertex("A" + i).property(AccumuloPropertyNames.COUNT, i).build());
}
data.add(AccumuloTestData.EDGE_C_D_DIRECTED);
data.add(AccumuloTestData.EDGE_C_D_UNDIRECTED);
addElements(data, store, new User());
} catch (final TableExistsException | StoreException e) {
fail("Failed to set up graph in Accumulo with exception: " + e);
}
}
use of org.apache.accumulo.core.client.TableExistsException in project hive by apache.
the class TestAccumuloDefaultIndexScanner method buildMockHandler.
public static AccumuloDefaultIndexScanner buildMockHandler(int maxMatches) {
try {
String table = "table";
Text emptyText = new Text("");
Configuration conf = new Configuration();
conf.set(AccumuloIndexParameters.INDEXTABLE_NAME, table);
conf.setInt(AccumuloIndexParameters.MAX_INDEX_ROWS, maxMatches);
conf.set(AccumuloIndexParameters.INDEXED_COLUMNS, "*");
conf.set(serdeConstants.LIST_COLUMNS, "rid,name,age,cars,mgr");
conf.set(AccumuloSerDeParameters.COLUMN_MAPPINGS, ":rowId,name:name,age:age,cars:cars,mgr:mgr");
AccumuloDefaultIndexScanner handler = new AccumuloDefaultIndexScanner();
handler.init(conf);
MockInstance inst = new MockInstance("test_instance");
Connector conn = inst.getConnector("root", new PasswordToken(""));
if (!conn.tableOperations().exists(table)) {
conn.tableOperations().create(table);
BatchWriterConfig batchConfig = new BatchWriterConfig();
BatchWriter writer = conn.createBatchWriter(table, batchConfig);
addRow(writer, "fred", "name_name", "row1");
addRow(writer, "25", "age_age", "row1");
addRow(writer, 5, "cars_cars", "row1");
addRow(writer, true, "mgr_mgr", "row1");
addRow(writer, "bill", "name_name", "row2");
addRow(writer, "20", "age_age", "row2");
addRow(writer, 2, "cars_cars", "row2");
addRow(writer, false, "mgr_mgr", "row2");
addRow(writer, "sally", "name_name", "row3");
addRow(writer, "23", "age_age", "row3");
addRow(writer, 6, "cars_cars", "row3");
addRow(writer, true, "mgr_mgr", "row3");
addRow(writer, "rob", "name_name", "row4");
addRow(writer, "60", "age_age", "row4");
addRow(writer, 1, "cars_cars", "row4");
addRow(writer, false, "mgr_mgr", "row4");
writer.close();
}
AccumuloConnectionParameters connectionParams = Mockito.mock(AccumuloConnectionParameters.class);
AccumuloStorageHandler storageHandler = Mockito.mock(AccumuloStorageHandler.class);
Mockito.when(connectionParams.getConnector()).thenReturn(conn);
handler.setConnectParams(connectionParams);
return handler;
} catch (AccumuloSecurityException | AccumuloException | TableExistsException | TableNotFoundException e) {
LOG.error(e.getLocalizedMessage(), e);
}
return null;
}
use of org.apache.accumulo.core.client.TableExistsException in project incubator-rya by apache.
the class AccumuloParentMetadataRepository method createTableIfNeeded.
private void createTableIfNeeded() throws MergerException {
try {
if (!doesMetadataTableExist()) {
log.debug("Creating table: " + mergeParentMetadataTableName);
connector.tableOperations().create(mergeParentMetadataTableName);
log.debug("Created table: " + mergeParentMetadataTableName);
log.debug("Granting authorizations to table: " + mergeParentMetadataTableName);
final String username = accumuloRyaDao.getConf().get(MRUtils.AC_USERNAME_PROP);
connector.securityOperations().grantTablePermission(username, mergeParentMetadataTableName, TablePermission.WRITE);
log.debug("Granted authorizations to table: " + mergeParentMetadataTableName);
}
} catch (final TableExistsException | AccumuloException | AccumuloSecurityException e) {
throw new MergerException("Could not create a new MergeParentMetadata table named: " + mergeParentMetadataTableName, e);
}
}
Aggregations