Search in sources :

Example 11 with TableExistsException

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);
            }
    }
}
Also used : TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) TableOfflineException(org.apache.accumulo.core.client.TableOfflineException) TableExistsException(org.apache.accumulo.core.client.TableExistsException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) ThriftTableOperationException(org.apache.accumulo.core.client.impl.thrift.ThriftTableOperationException) ThriftSecurityException(org.apache.accumulo.core.client.impl.thrift.ThriftSecurityException) NamespaceExistsException(org.apache.accumulo.core.client.NamespaceExistsException) NamespaceNotFoundException(org.apache.accumulo.core.client.NamespaceNotFoundException) TableOfflineException(org.apache.accumulo.core.client.TableOfflineException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) NamespaceNotFoundException(org.apache.accumulo.core.client.NamespaceNotFoundException) ThriftNotActiveServiceException(org.apache.accumulo.core.client.impl.thrift.ThriftNotActiveServiceException) ThriftSecurityException(org.apache.accumulo.core.client.impl.thrift.ThriftSecurityException) TableExistsException(org.apache.accumulo.core.client.TableExistsException) TableDeletedException(org.apache.accumulo.core.client.TableDeletedException) TException(org.apache.thrift.TException) IOException(java.io.IOException) ThriftTableOperationException(org.apache.accumulo.core.client.impl.thrift.ThriftTableOperationException) TTransportException(org.apache.thrift.transport.TTransportException) NamespaceExistsException(org.apache.accumulo.core.client.NamespaceExistsException) FileNotFoundException(java.io.FileNotFoundException) NotServingTabletException(org.apache.accumulo.core.tabletserver.thrift.NotServingTabletException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) TApplicationException(org.apache.thrift.TApplicationException) AccumuloException(org.apache.accumulo.core.client.AccumuloException)

Example 12 with TableExistsException

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;
}
Also used : Connector(org.apache.accumulo.core.client.Connector) AccumuloException(org.apache.accumulo.core.client.AccumuloException) AuthenticationToken(org.apache.accumulo.core.client.security.tokens.AuthenticationToken) IOException(java.io.IOException) Properties(org.apache.accumulo.core.client.security.tokens.AuthenticationToken.Properties) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) TableExistsException(org.apache.accumulo.core.client.TableExistsException) Property(org.apache.accumulo.core.conf.Property) AgeOffFilter(org.apache.accumulo.core.iterators.user.AgeOffFilter)

Example 13 with TableExistsException

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);
    }
}
Also used : Entity(uk.gov.gchq.gaffer.data.element.Entity) User(uk.gov.gchq.gaffer.user.User) Element(uk.gov.gchq.gaffer.data.element.Element) TableExistsException(org.apache.accumulo.core.client.TableExistsException) HashSet(java.util.HashSet) StoreException(uk.gov.gchq.gaffer.store.StoreException)

Example 14 with TableExistsException

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;
}
Also used : Connector(org.apache.accumulo.core.client.Connector) AccumuloException(org.apache.accumulo.core.client.AccumuloException) Configuration(org.apache.hadoop.conf.Configuration) Text(org.apache.hadoop.io.Text) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) MockInstance(org.apache.accumulo.core.client.mock.MockInstance) TableExistsException(org.apache.accumulo.core.client.TableExistsException) BatchWriterConfig(org.apache.accumulo.core.client.BatchWriterConfig) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) BatchWriter(org.apache.accumulo.core.client.BatchWriter)

Example 15 with TableExistsException

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);
    }
}
Also used : AccumuloException(org.apache.accumulo.core.client.AccumuloException) MergerException(org.apache.rya.export.api.MergerException) TableExistsException(org.apache.accumulo.core.client.TableExistsException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException)

Aggregations

TableExistsException (org.apache.accumulo.core.client.TableExistsException)32 AccumuloException (org.apache.accumulo.core.client.AccumuloException)21 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)17 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)17 Connector (org.apache.accumulo.core.client.Connector)9 IOException (java.io.IOException)8 BatchWriter (org.apache.accumulo.core.client.BatchWriter)8 BatchWriterConfig (org.apache.accumulo.core.client.BatchWriterConfig)7 Value (org.apache.accumulo.core.data.Value)7 HashMap (java.util.HashMap)6 Mutation (org.apache.accumulo.core.data.Mutation)6 ByteBuffer (java.nio.ByteBuffer)5 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)4 MutationsRejectedException (org.apache.accumulo.core.client.MutationsRejectedException)4 Key (org.apache.accumulo.core.data.Key)4 Text (org.apache.hadoop.io.Text)4 Map (java.util.Map)3 Entry (java.util.Map.Entry)3 NamespaceExistsException (org.apache.accumulo.core.client.NamespaceExistsException)3 NamespaceNotFoundException (org.apache.accumulo.core.client.NamespaceNotFoundException)3