Search in sources :

Example 21 with MockInstance

use of org.apache.accumulo.core.client.mock.MockInstance 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)

Aggregations

MockInstance (org.apache.accumulo.core.client.mock.MockInstance)21 PasswordToken (org.apache.accumulo.core.client.security.tokens.PasswordToken)20 Connector (org.apache.accumulo.core.client.Connector)18 Test (org.junit.Test)15 Authorizations (org.apache.accumulo.core.security.Authorizations)10 Table (org.apache.hadoop.hive.metastore.api.Table)9 Mutation (org.apache.accumulo.core.data.Mutation)7 Value (org.apache.accumulo.core.data.Value)7 Text (org.apache.hadoop.io.Text)7 JobConf (org.apache.hadoop.mapred.JobConf)7 Entry (java.util.Map.Entry)6 Instance (org.apache.accumulo.core.client.Instance)6 Key (org.apache.accumulo.core.data.Key)6 ByteArrayRef (org.apache.hadoop.hive.serde2.lazy.ByteArrayRef)6 HashMap (java.util.HashMap)5 BatchWriterConfig (org.apache.accumulo.core.client.BatchWriterConfig)5 Properties (java.util.Properties)4 Configuration (org.apache.hadoop.conf.Configuration)4 FileSystem (org.apache.hadoop.fs.FileSystem)4 AccumuloRowSerializer (org.apache.hadoop.hive.accumulo.serde.AccumuloRowSerializer)4