Search in sources :

Example 11 with AccumuloSecurityException

use of org.apache.accumulo.core.client.AccumuloSecurityException in project presto by prestodb.

the class AccumuloTableManager method setLocalityGroups.

public void setLocalityGroups(String tableName, Map<String, Set<Text>> groups) {
    if (groups.isEmpty()) {
        return;
    }
    try {
        connector.tableOperations().setLocalityGroups(tableName, groups);
        LOG.debug("Set locality groups for %s to %s", tableName, groups);
    } catch (AccumuloException | AccumuloSecurityException e) {
        throw new PrestoException(UNEXPECTED_ACCUMULO_ERROR, "Failed to set locality groups", e);
    } catch (TableNotFoundException e) {
        throw new PrestoException(ACCUMULO_TABLE_DNE, "Failed to set locality groups, table does not exist", e);
    }
}
Also used : AccumuloException(org.apache.accumulo.core.client.AccumuloException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) PrestoException(com.facebook.presto.spi.PrestoException)

Example 12 with AccumuloSecurityException

use of org.apache.accumulo.core.client.AccumuloSecurityException in project presto by prestodb.

the class AccumuloTableManager method setIterator.

public void setIterator(String table, IteratorSetting setting) {
    try {
        // Remove any existing iterator settings of the same name, if applicable
        Map<String, EnumSet<IteratorScope>> iterators = connector.tableOperations().listIterators(table);
        if (iterators.containsKey(setting.getName())) {
            connector.tableOperations().removeIterator(table, setting.getName(), iterators.get(setting.getName()));
        }
        connector.tableOperations().attachIterator(table, setting);
    } catch (AccumuloSecurityException | AccumuloException e) {
        throw new PrestoException(UNEXPECTED_ACCUMULO_ERROR, "Failed to set iterator on table " + table, e);
    } catch (TableNotFoundException e) {
        throw new PrestoException(ACCUMULO_TABLE_DNE, "Failed to set iterator, table does not exist", e);
    }
}
Also used : AccumuloException(org.apache.accumulo.core.client.AccumuloException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) EnumSet(java.util.EnumSet) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) PrestoException(com.facebook.presto.spi.PrestoException)

Example 13 with AccumuloSecurityException

use of org.apache.accumulo.core.client.AccumuloSecurityException in project presto by prestodb.

the class AccumuloQueryRunner method getAccumuloConnector.

/**
     * Gets the AccumuloConnector singleton, starting the MiniAccumuloCluster on initialization.
     * This singleton instance is required so all test cases access the same MiniAccumuloCluster.
     *
     * @return Accumulo connector
     */
private static Connector getAccumuloConnector() {
    if (connector != null) {
        return connector;
    }
    try {
        MiniAccumuloCluster accumulo = createMiniAccumuloCluster();
        Instance instance = new ZooKeeperInstance(accumulo.getInstanceName(), accumulo.getZooKeepers());
        connector = instance.getConnector(MAC_USER, new PasswordToken(MAC_PASSWORD));
        LOG.info("Connection to MAC instance %s at %s established, user %s password %s", accumulo.getInstanceName(), accumulo.getZooKeepers(), MAC_USER, MAC_PASSWORD);
        return connector;
    } catch (AccumuloException | AccumuloSecurityException | InterruptedException | IOException e) {
        throw new PrestoException(UNEXPECTED_ACCUMULO_ERROR, "Failed to get connector to Accumulo", e);
    }
}
Also used : AccumuloException(org.apache.accumulo.core.client.AccumuloException) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) Instance(org.apache.accumulo.core.client.Instance) ZooKeeperInstance(org.apache.accumulo.core.client.ZooKeeperInstance) MiniAccumuloCluster(org.apache.accumulo.minicluster.MiniAccumuloCluster) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) PrestoException(com.facebook.presto.spi.PrestoException) IOException(java.io.IOException) ZooKeeperInstance(org.apache.accumulo.core.client.ZooKeeperInstance)

Example 14 with AccumuloSecurityException

use of org.apache.accumulo.core.client.AccumuloSecurityException in project gora by apache.

the class AccumuloStore method initialize.

/**
   * Initialize the data store by reading the credentials, setting the client's properties up and
   * reading the mapping file. Initialize is called when then the call to
   * {@link org.apache.gora.store.DataStoreFactory#createDataStore} is made.
   *
   * @param keyClass
   * @param persistentClass
   * @param properties
   */
@Override
public void initialize(Class<K> keyClass, Class<T> persistentClass, Properties properties) {
    try {
        super.initialize(keyClass, persistentClass, properties);
        String mock = DataStoreFactory.findProperty(properties, this, MOCK_PROPERTY, null);
        String mappingFile = DataStoreFactory.getMappingFile(properties, this, DEFAULT_MAPPING_FILE);
        String user = DataStoreFactory.findProperty(properties, this, USERNAME_PROPERTY, null);
        String password = DataStoreFactory.findProperty(properties, this, PASSWORD_PROPERTY, null);
        mapping = readMapping(mappingFile);
        if (mapping.encoder == null || "".equals(mapping.encoder)) {
            encoder = new BinaryEncoder();
        } else {
            try {
                encoder = (Encoder) getClass().getClassLoader().loadClass(mapping.encoder).newInstance();
            } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
                throw new IOException(e);
            }
        }
        try {
            AuthenticationToken token = new PasswordToken(password);
            if (mock == null || !mock.equals("true")) {
                String instance = DataStoreFactory.findProperty(properties, this, INSTANCE_NAME_PROPERTY, null);
                String zookeepers = DataStoreFactory.findProperty(properties, this, ZOOKEEPERS_NAME_PROPERTY, null);
                conn = new ZooKeeperInstance(instance, zookeepers).getConnector(user, token);
            } else {
                conn = new MockInstance().getConnector(user, token);
            }
            credentials = new Credentials(user, token);
            if (autoCreateSchema && !schemaExists())
                createSchema();
        } catch (AccumuloException | AccumuloSecurityException e) {
            throw new IOException(e);
        }
    } catch (IOException e) {
        LOG.error(e.getMessage(), e);
    }
}
Also used : AccumuloException(org.apache.accumulo.core.client.AccumuloException) AuthenticationToken(org.apache.accumulo.core.client.security.tokens.AuthenticationToken) IOException(java.io.IOException) ZooKeeperInstance(org.apache.accumulo.core.client.ZooKeeperInstance) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) BinaryEncoder(org.apache.gora.accumulo.encoders.BinaryEncoder) MockInstance(org.apache.accumulo.core.client.mock.MockInstance) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) Credentials(org.apache.accumulo.core.client.impl.Credentials)

Example 15 with AccumuloSecurityException

use of org.apache.accumulo.core.client.AccumuloSecurityException in project gora by apache.

the class AccumuloStore method getPartitions.

@Override
public List<PartitionQuery<K, T>> getPartitions(Query<K, T> query) throws IOException {
    try {
        TabletLocator tl;
        if (conn instanceof MockConnector)
            tl = new MockTabletLocator();
        else
            tl = TabletLocator.getLocator(new ClientContext(conn.getInstance(), credentials, AccumuloConfiguration.getTableConfiguration(conn, Tables.getTableId(conn.getInstance(), mapping.tableName))), new Text(Tables.getTableId(conn.getInstance(), mapping.tableName)));
        Map<String, Map<KeyExtent, List<Range>>> binnedRanges = new HashMap<>();
        tl.invalidateCache();
        while (tl.binRanges(new ClientContext(conn.getInstance(), credentials, AccumuloConfiguration.getTableConfiguration(conn, Tables.getTableId(conn.getInstance(), mapping.tableName))), Collections.singletonList(createRange(query)), binnedRanges).size() > 0) {
            // TODO log?
            if (!Tables.exists(conn.getInstance(), Tables.getTableId(conn.getInstance(), mapping.tableName)))
                throw new TableDeletedException(Tables.getTableId(conn.getInstance(), mapping.tableName));
            else if (Tables.getTableState(conn.getInstance(), Tables.getTableId(conn.getInstance(), mapping.tableName)) == TableState.OFFLINE)
                throw new TableOfflineException(conn.getInstance(), Tables.getTableId(conn.getInstance(), mapping.tableName));
            UtilWaitThread.sleep(100);
            tl.invalidateCache();
        }
        List<PartitionQuery<K, T>> ret = new ArrayList<>();
        Text startRow = null;
        Text endRow = null;
        if (query.getStartKey() != null)
            startRow = new Text(toBytes(query.getStartKey()));
        if (query.getEndKey() != null)
            endRow = new Text(toBytes(query.getEndKey()));
        //hadoop expects hostnames, accumulo keeps track of IPs... so need to convert
        HashMap<String, String> hostNameCache = new HashMap<>();
        for (Entry<String, Map<KeyExtent, List<Range>>> entry : binnedRanges.entrySet()) {
            String ip = entry.getKey().split(":", 2)[0];
            String location = hostNameCache.get(ip);
            if (location == null) {
                InetAddress inetAddress = InetAddress.getByName(ip);
                location = inetAddress.getHostName();
                hostNameCache.put(ip, location);
            }
            Map<KeyExtent, List<Range>> tablets = entry.getValue();
            for (KeyExtent ke : tablets.keySet()) {
                K startKey = null;
                if (startRow == null || !ke.contains(startRow)) {
                    if (ke.getPrevEndRow() != null) {
                        startKey = followingKey(encoder, getKeyClass(), getBytes(ke.getPrevEndRow()));
                    }
                } else {
                    startKey = fromBytes(getKeyClass(), getBytes(startRow));
                }
                K endKey = null;
                if (endRow == null || !ke.contains(endRow)) {
                    if (ke.getEndRow() != null)
                        endKey = lastPossibleKey(encoder, getKeyClass(), getBytes(ke.getEndRow()));
                } else {
                    endKey = fromBytes(getKeyClass(), getBytes(endRow));
                }
                PartitionQueryImpl<K, T> pqi = new PartitionQueryImpl<>(query, startKey, endKey, location);
                pqi.setConf(getConf());
                ret.add(pqi);
            }
        }
        return ret;
    } catch (TableNotFoundException | AccumuloException | AccumuloSecurityException e) {
        throw new IOException(e);
    }
}
Also used : TableOfflineException(org.apache.accumulo.core.client.TableOfflineException) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) KeyExtent(org.apache.accumulo.core.data.impl.KeyExtent) TableDeletedException(org.apache.accumulo.core.client.TableDeletedException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) List(java.util.List) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) MockTabletLocator(org.apache.accumulo.core.client.mock.impl.MockTabletLocator) AccumuloException(org.apache.accumulo.core.client.AccumuloException) PartitionQueryImpl(org.apache.gora.query.impl.PartitionQueryImpl) ClientContext(org.apache.accumulo.core.client.impl.ClientContext) Text(org.apache.hadoop.io.Text) IOException(java.io.IOException) Range(org.apache.accumulo.core.data.Range) MockTabletLocator(org.apache.accumulo.core.client.mock.impl.MockTabletLocator) TabletLocator(org.apache.accumulo.core.client.impl.TabletLocator) MockConnector(org.apache.accumulo.core.client.mock.MockConnector) Map(java.util.Map) HashMap(java.util.HashMap) PartitionQuery(org.apache.gora.query.PartitionQuery) InetAddress(java.net.InetAddress)

Aggregations

AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)15 AccumuloException (org.apache.accumulo.core.client.AccumuloException)14 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)8 IOException (java.io.IOException)7 Text (org.apache.hadoop.io.Text)6 Connector (org.apache.accumulo.core.client.Connector)5 StoreException (uk.gov.gchq.gaffer.store.StoreException)5 AuthenticationToken (org.apache.accumulo.core.client.security.tokens.AuthenticationToken)4 PasswordToken (org.apache.accumulo.core.client.security.tokens.PasswordToken)4 PrestoException (com.facebook.presto.spi.PrestoException)3 ZooKeeperInstance (org.apache.accumulo.core.client.ZooKeeperInstance)3 EnumSet (java.util.EnumSet)2 HashMap (java.util.HashMap)2 TreeSet (java.util.TreeSet)2 Instance (org.apache.accumulo.core.client.Instance)2 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)2 MockConnector (org.apache.accumulo.core.client.mock.MockConnector)2 MockInstance (org.apache.accumulo.core.client.mock.MockInstance)2 Range (org.apache.accumulo.core.data.Range)2 AccumuloConnectionParameters (org.apache.hadoop.hive.accumulo.AccumuloConnectionParameters)2