Search in sources :

Example 1 with SingleUseMiniHBaseStore

use of uk.gov.gchq.gaffer.hbasestore.SingleUseMiniHBaseStore in project Gaffer by gchq.

the class HBaseAddElementsFromHdfsJobFactoryTest method shouldSetupJob.

@Test
public void shouldSetupJob() throws IOException, StoreException {
    // Given
    final JobConf localConf = createLocalConf();
    final FileSystem fs = FileSystem.getLocal(localConf);
    fs.mkdirs(new Path(outputDir));
    final JobFactory factory = getJobFactory();
    final Job job = mock(Job.class);
    final MapReduce operation = getMapReduceOperation();
    final HBaseStore store = new SingleUseMiniHBaseStore();
    final Schema schema = Schema.fromJson(StreamUtil.schemas(getClass()));
    final HBaseProperties properties = HBaseProperties.loadStoreProperties(StreamUtil.storeProps(getClass()));
    store.initialise("graphId", schema, properties);
    given(job.getConfiguration()).willReturn(localConf);
    // When
    factory.setupJob(job, operation, TextMapperGeneratorImpl.class.getName(), store);
    // Then
    verify(job).setJarByClass(factory.getClass());
    verify(job).setJobName("Ingest HDFS data: Generator=" + TextMapperGeneratorImpl.class.getName() + ", output=" + outputDir);
    verify(job).setMapperClass(AddElementsFromHdfsMapper.class);
    verify(job).setMapOutputKeyClass(ImmutableBytesWritable.class);
    verify(job).setMapOutputValueClass(KeyValue.class);
    verify(job).setReducerClass(AddElementsFromHdfsReducer.class);
    verify(job).setOutputKeyClass(ImmutableBytesWritable.class);
    verify(job).setOutputValueClass(KeyValue.class);
    verify(job).setOutputFormatClass(HFileOutputFormat2.class);
    assertEquals(fs.makeQualified(new Path(outputDir)).toString(), job.getConfiguration().get("mapreduce.output.fileoutputformat.outputdir"));
    verify(job).setNumReduceTasks(1);
}
Also used : Path(org.apache.hadoop.fs.Path) JobFactory(uk.gov.gchq.gaffer.hdfs.operation.handler.job.factory.JobFactory) SingleUseMiniHBaseStore(uk.gov.gchq.gaffer.hbasestore.SingleUseMiniHBaseStore) HBaseStore(uk.gov.gchq.gaffer.hbasestore.HBaseStore) FileSystem(org.apache.hadoop.fs.FileSystem) Schema(uk.gov.gchq.gaffer.store.schema.Schema) SingleUseMiniHBaseStore(uk.gov.gchq.gaffer.hbasestore.SingleUseMiniHBaseStore) Job(org.apache.hadoop.mapreduce.Job) HBaseProperties(uk.gov.gchq.gaffer.hbasestore.HBaseProperties) JobConf(org.apache.hadoop.mapred.JobConf) MapReduce(uk.gov.gchq.gaffer.hdfs.operation.MapReduce) Test(org.junit.jupiter.api.Test) AbstractJobFactoryTest(uk.gov.gchq.gaffer.hdfs.operation.hander.job.factory.AbstractJobFactoryTest)

Example 2 with SingleUseMiniHBaseStore

use of uk.gov.gchq.gaffer.hbasestore.SingleUseMiniHBaseStore in project Gaffer by gchq.

the class TableUtilsTest method shouldCreateTableAndValidateIt.

@Test
public void shouldCreateTableAndValidateIt() throws Exception {
    // Given
    final SingleUseMiniHBaseStore store = new SingleUseMiniHBaseStore();
    final Schema schema = new Schema.Builder().type(TestTypes.ID_STRING, new TypeDefinition.Builder().aggregateFunction(new StringConcat()).clazz(String.class).build()).type(TestTypes.DIRECTED_TRUE, Boolean.class).edge(TestGroups.EDGE, new SchemaEdgeDefinition.Builder().source(TestTypes.ID_STRING).destination(TestTypes.ID_STRING).directed(TestTypes.DIRECTED_TRUE).build()).build();
    final HBaseProperties props = HBaseProperties.loadStoreProperties(StreamUtil.storeProps(TableUtilsTest.class));
    store.initialise(GRAPH_ID, schema, props);
    // When
    TableUtils.createTable(store);
    TableUtils.ensureTableExists(store);
// Then - no exceptions
}
Also used : StringConcat(uk.gov.gchq.koryphe.impl.binaryoperator.StringConcat) Schema(uk.gov.gchq.gaffer.store.schema.Schema) SingleUseMiniHBaseStore(uk.gov.gchq.gaffer.hbasestore.SingleUseMiniHBaseStore) HBaseProperties(uk.gov.gchq.gaffer.hbasestore.HBaseProperties) TypeDefinition(uk.gov.gchq.gaffer.store.schema.TypeDefinition) Test(org.junit.jupiter.api.Test)

Example 3 with SingleUseMiniHBaseStore

use of uk.gov.gchq.gaffer.hbasestore.SingleUseMiniHBaseStore in project Gaffer by gchq.

the class HBaseAddElementsFromHdfsJobFactoryTest method getStoreConfiguredWith.

@Override
protected Store getStoreConfiguredWith(final Class<JSONSerialiser> jsonSerialiserClass, final String jsonSerialiserModules, final Boolean strictJson) throws IOException, StoreException {
    final HBaseStore store = new SingleUseMiniHBaseStore();
    final Schema schema = Schema.fromJson(StreamUtil.schemas(getClass()));
    final HBaseProperties properties = HBaseProperties.loadStoreProperties(StreamUtil.storeProps(getClass()));
    super.configureStoreProperties(properties, jsonSerialiserClass, jsonSerialiserModules, strictJson);
    store.initialise("graphId", schema, properties);
    final JobConf localConf = createLocalConf();
    final FileSystem fs = FileSystem.getLocal(localConf);
    fs.mkdirs(new Path(outputDir));
    return store;
}
Also used : Path(org.apache.hadoop.fs.Path) SingleUseMiniHBaseStore(uk.gov.gchq.gaffer.hbasestore.SingleUseMiniHBaseStore) HBaseStore(uk.gov.gchq.gaffer.hbasestore.HBaseStore) Schema(uk.gov.gchq.gaffer.store.schema.Schema) FileSystem(org.apache.hadoop.fs.FileSystem) SingleUseMiniHBaseStore(uk.gov.gchq.gaffer.hbasestore.SingleUseMiniHBaseStore) HBaseProperties(uk.gov.gchq.gaffer.hbasestore.HBaseProperties) JobConf(org.apache.hadoop.mapred.JobConf)

Example 4 with SingleUseMiniHBaseStore

use of uk.gov.gchq.gaffer.hbasestore.SingleUseMiniHBaseStore in project Gaffer by gchq.

the class TableUtilsTest method shouldFailTableValidationWhenTableDoesntHaveCoprocessor.

@Test
public void shouldFailTableValidationWhenTableDoesntHaveCoprocessor() throws Exception {
    // Given
    final SingleUseMiniHBaseStore store = new SingleUseMiniHBaseStore();
    final Schema schema = new Schema.Builder().type(TestTypes.ID_STRING, new TypeDefinition.Builder().aggregateFunction(new StringConcat()).clazz(String.class).build()).type(TestTypes.DIRECTED_TRUE, Boolean.class).edge(TestGroups.EDGE, new SchemaEdgeDefinition.Builder().source(TestTypes.ID_STRING).destination(TestTypes.ID_STRING).directed(TestTypes.DIRECTED_TRUE).build()).build();
    final HBaseProperties props = HBaseProperties.loadStoreProperties(StreamUtil.storeProps(TableUtilsTest.class));
    store.initialise(GRAPH_ID, schema, props);
    // Remove coprocessor
    final TableName tableName = store.getTableName();
    try (final Admin admin = store.getConnection().getAdmin()) {
        final HTableDescriptor descriptor = admin.getTableDescriptor(tableName);
        descriptor.removeCoprocessor(GafferCoprocessor.class.getName());
        admin.modifyTable(tableName, descriptor);
    } catch (final StoreException | IOException e) {
        throw new RuntimeException(e);
    }
    // When / Then
    assertThatExceptionOfType(StoreException.class).isThrownBy(() -> TableUtils.ensureTableExists(store)).extracting("message").isNotNull();
}
Also used : StringConcat(uk.gov.gchq.koryphe.impl.binaryoperator.StringConcat) Schema(uk.gov.gchq.gaffer.store.schema.Schema) SingleUseMiniHBaseStore(uk.gov.gchq.gaffer.hbasestore.SingleUseMiniHBaseStore) IOException(java.io.IOException) Admin(org.apache.hadoop.hbase.client.Admin) TypeDefinition(uk.gov.gchq.gaffer.store.schema.TypeDefinition) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) StoreException(uk.gov.gchq.gaffer.store.StoreException) TableName(org.apache.hadoop.hbase.TableName) GafferCoprocessor(uk.gov.gchq.gaffer.hbasestore.coprocessor.GafferCoprocessor) HBaseProperties(uk.gov.gchq.gaffer.hbasestore.HBaseProperties) Test(org.junit.jupiter.api.Test)

Aggregations

HBaseProperties (uk.gov.gchq.gaffer.hbasestore.HBaseProperties)4 SingleUseMiniHBaseStore (uk.gov.gchq.gaffer.hbasestore.SingleUseMiniHBaseStore)4 Schema (uk.gov.gchq.gaffer.store.schema.Schema)4 Test (org.junit.jupiter.api.Test)3 FileSystem (org.apache.hadoop.fs.FileSystem)2 Path (org.apache.hadoop.fs.Path)2 JobConf (org.apache.hadoop.mapred.JobConf)2 HBaseStore (uk.gov.gchq.gaffer.hbasestore.HBaseStore)2 TypeDefinition (uk.gov.gchq.gaffer.store.schema.TypeDefinition)2 StringConcat (uk.gov.gchq.koryphe.impl.binaryoperator.StringConcat)2 IOException (java.io.IOException)1 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)1 TableName (org.apache.hadoop.hbase.TableName)1 Admin (org.apache.hadoop.hbase.client.Admin)1 Job (org.apache.hadoop.mapreduce.Job)1 GafferCoprocessor (uk.gov.gchq.gaffer.hbasestore.coprocessor.GafferCoprocessor)1 MapReduce (uk.gov.gchq.gaffer.hdfs.operation.MapReduce)1 AbstractJobFactoryTest (uk.gov.gchq.gaffer.hdfs.operation.hander.job.factory.AbstractJobFactoryTest)1 JobFactory (uk.gov.gchq.gaffer.hdfs.operation.handler.job.factory.JobFactory)1 StoreException (uk.gov.gchq.gaffer.store.StoreException)1