Search in sources :

Example 1 with VisibilityHandler

use of org.locationtech.geowave.core.store.api.VisibilityHandler in project geowave by locationtech.

the class AbstractMapReduceIngest method run.

@Override
public int run(final String[] args) throws Exception {
    final Configuration conf = getConf();
    conf.set(INGEST_PLUGIN_KEY, ByteArrayUtils.byteArrayToString(PersistenceUtils.toBinary(ingestPlugin)));
    final VisibilityHandler visibilityHandler = visibilityOptions.getConfiguredVisibilityHandler();
    if (visibilityHandler != null) {
        conf.set(GLOBAL_VISIBILITY_KEY, ByteArrayUtils.byteArrayToString(PersistenceUtils.toBinary(visibilityHandler)));
    }
    final Job job = new Job(conf, getJobName());
    final StringBuilder indexNames = new StringBuilder();
    final List<Index> indexes = new ArrayList<>();
    for (final Index primaryIndex : indices) {
        indexes.add(primaryIndex);
        if (primaryIndex != null) {
            // add index
            GeoWaveOutputFormat.addIndex(job.getConfiguration(), primaryIndex);
            if (indexNames.length() != 0) {
                indexNames.append(",");
            }
            indexNames.append(primaryIndex.getName());
        }
    }
    job.getConfiguration().set(INDEX_NAMES_KEY, indexNames.toString());
    job.setJarByClass(AbstractMapReduceIngest.class);
    job.setInputFormatClass(AvroKeyInputFormat.class);
    AvroJob.setInputKeySchema(job, parentPlugin.getAvroSchema());
    FileInputFormat.setInputPaths(job, inputFile);
    setupMapper(job);
    setupReducer(job);
    // set geowave output format
    job.setOutputFormatClass(GeoWaveOutputFormat.class);
    GeoWaveOutputFormat.setStoreOptions(job.getConfiguration(), dataStoreOptions);
    final DataStore store = dataStoreOptions.createDataStore();
    final PersistentAdapterStore adapterStore = dataStoreOptions.createAdapterStore();
    final InternalAdapterStore internalAdapterStore = dataStoreOptions.createInternalAdapterStore();
    final DataTypeAdapter<?>[] dataAdapters = ingestPlugin.getDataAdapters();
    final Index[] indices = indexes.toArray(new Index[indexes.size()]);
    if ((dataAdapters != null) && (dataAdapters.length > 0)) {
        for (final DataTypeAdapter<?> dataAdapter : dataAdapters) {
            // metadata for which there is no data
            try {
                store.addType(dataAdapter, visibilityOptions.getConfiguredVisibilityHandler(), Lists.newArrayList(), indices);
                final short adapterId = internalAdapterStore.getAdapterId(dataAdapter.getTypeName());
                final InternalDataAdapter<?> internalAdapter = adapterStore.getAdapter(adapterId);
                GeoWaveOutputFormat.addDataAdapter(job.getConfiguration(), internalAdapter);
            } catch (IllegalArgumentException e) {
            // Skip any adapters that can't be mapped to the input indices
            }
        }
    } else {
        // indices from the client
        for (final Index index : indices) {
            store.addIndex(index);
        }
        if (indices.length > 0) {
            for (final MetadataType type : MetadataType.values()) {
                // stats and index metadata writers are created elsewhere
                if (!MetadataType.INDEX.equals(type) && !MetadataType.STATISTIC_VALUES.equals(type)) {
                    dataStoreOptions.createDataStoreOperations().createMetadataWriter(type).close();
                }
            }
        }
    }
    // distributed ingest
    if (dataStoreOptions.getFactoryOptions().getStoreOptions().isPersistDataStatistics()) {
        dataStoreOptions.createDataStoreOperations().createMetadataWriter(MetadataType.STATISTIC_VALUES).close();
    }
    job.setSpeculativeExecution(false);
    // add required indices
    final Index[] requiredIndices = parentPlugin.getRequiredIndices();
    if (requiredIndices != null) {
        for (final Index requiredIndex : requiredIndices) {
            GeoWaveOutputFormat.addIndex(job.getConfiguration(), requiredIndex);
        }
    }
    final int retVal = job.waitForCompletion(true) ? 0 : -1;
    // ingests
    if ((dataAdapters != null) && (dataAdapters.length > 0)) {
        AdapterIndexMappingStore adapterIndexMappingStore = null;
        for (final DataTypeAdapter<?> dataAdapter : dataAdapters) {
            final String typeName = dataAdapter.getTypeName();
            try (CloseableIterator<?> it = store.query(QueryBuilder.newBuilder().addTypeName(typeName).limit(1).build())) {
                if (!it.hasNext()) {
                    if (adapterIndexMappingStore == null) {
                        adapterIndexMappingStore = dataStoreOptions.createAdapterIndexMappingStore();
                    }
                    final Short adapterId = internalAdapterStore.getAdapterId(typeName);
                    if (adapterId != null) {
                        internalAdapterStore.remove(adapterId);
                        adapterStore.removeAdapter(adapterId);
                        adapterIndexMappingStore.remove(adapterId);
                    }
                }
            }
        }
    }
    return retVal;
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) InternalAdapterStore(org.locationtech.geowave.core.store.adapter.InternalAdapterStore) DataTypeAdapter(org.locationtech.geowave.core.store.api.DataTypeAdapter) ArrayList(java.util.ArrayList) MetadataType(org.locationtech.geowave.core.store.operations.MetadataType) Index(org.locationtech.geowave.core.store.api.Index) AdapterIndexMappingStore(org.locationtech.geowave.core.store.adapter.AdapterIndexMappingStore) PersistentAdapterStore(org.locationtech.geowave.core.store.adapter.PersistentAdapterStore) DataStore(org.locationtech.geowave.core.store.api.DataStore) VisibilityHandler(org.locationtech.geowave.core.store.api.VisibilityHandler) AvroJob(org.apache.avro.mapreduce.AvroJob) Job(org.apache.hadoop.mapreduce.Job)

Example 2 with VisibilityHandler

use of org.locationtech.geowave.core.store.api.VisibilityHandler in project geowave by locationtech.

the class GeoWaveDataStoreComponents method writeCommit.

public void writeCommit(final SimpleFeature feature, final GeoWaveTransaction transaction) throws IOException {
    final VisibilityHandler visibilityHandler = new GlobalVisibilityHandler(transaction.composeVisibility());
    dataStore.addType(adapter, adapterIndices);
    try (Writer<SimpleFeature> indexWriter = dataStore.createWriter(adapter.getTypeName())) {
        indexWriter.write(feature, visibilityHandler);
    }
}
Also used : GlobalVisibilityHandler(org.locationtech.geowave.core.store.data.visibility.GlobalVisibilityHandler) VisibilityHandler(org.locationtech.geowave.core.store.api.VisibilityHandler) GlobalVisibilityHandler(org.locationtech.geowave.core.store.data.visibility.GlobalVisibilityHandler) SimpleFeature(org.opengis.feature.simple.SimpleFeature)

Example 3 with VisibilityHandler

use of org.locationtech.geowave.core.store.api.VisibilityHandler in project geowave by locationtech.

the class LegacyInternalDataAdapterWrapper method fromBinary.

@SuppressWarnings("unchecked")
@Override
public void fromBinary(final byte[] bytes) {
    ByteBuffer buffer = ByteBuffer.wrap(bytes);
    adapterId = buffer.getShort();
    byte[] adapterBytes = new byte[buffer.remaining()];
    buffer.get(adapterBytes);
    adapter = (DataTypeAdapter<T>) PersistenceUtils.fromBinary(adapterBytes);
    VisibilityHandler visibilityHandler = new UnconstrainedVisibilityHandler();
    if (adapter instanceof LegacyFeatureDataAdapter) {
        visibilityHandler = ((LegacyFeatureDataAdapter) adapter).getVisibilityHandler();
        adapter = (DataTypeAdapter<T>) ((LegacyFeatureDataAdapter) adapter).getUpdatedAdapter();
    }
    this.updatedAdapter = adapter.asInternalAdapter(adapterId, visibilityHandler);
}
Also used : LegacyFeatureDataAdapter(org.locationtech.geowave.migration.legacy.adapter.vector.LegacyFeatureDataAdapter) UnconstrainedVisibilityHandler(org.locationtech.geowave.core.store.data.visibility.UnconstrainedVisibilityHandler) VisibilityHandler(org.locationtech.geowave.core.store.api.VisibilityHandler) UnconstrainedVisibilityHandler(org.locationtech.geowave.core.store.data.visibility.UnconstrainedVisibilityHandler) ByteBuffer(java.nio.ByteBuffer)

Example 4 with VisibilityHandler

use of org.locationtech.geowave.core.store.api.VisibilityHandler in project geowave by locationtech.

the class MigrationTest method testLegacyFeatureDataAdapterMigration.

@Test
public void testLegacyFeatureDataAdapterMigration() {
    final SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
    final AttributeTypeBuilder attributeTypeBuilder = new AttributeTypeBuilder();
    builder.setName("testType");
    builder.setNamespaceURI("geowave.namespace");
    builder.add(attributeTypeBuilder.binding(String.class).nillable(true).buildDescriptor("strAttr"));
    builder.add(attributeTypeBuilder.binding(Integer.class).nillable(true).buildDescriptor("intAttr"));
    builder.add(attributeTypeBuilder.binding(Date.class).nillable(false).buildDescriptor("dateAttr"));
    builder.add(attributeTypeBuilder.binding(Point.class).nillable(false).buildDescriptor("geom"));
    builder.crs(GeometryUtils.getDefaultCRS());
    final SimpleFeatureType featureType = builder.buildFeatureType();
    final AttributeDescriptor stringAttr = featureType.getDescriptor("strAttr");
    // Configure legacy visiblity
    stringAttr.getUserData().put("visibility", Boolean.TRUE);
    featureType.getUserData().put("visibilityManagerClass", "org.locationtech.geowave.adapter.vector.plugin.visibility.JsonDefinitionColumnVisibilityManagement");
    LegacyFeatureDataAdapter adapter = new LegacyFeatureDataAdapter(featureType, "EPSG:3257");
    final byte[] adapterBinary = PersistenceUtils.toBinary(adapter);
    final Persistable persistableAdapter = PersistenceUtils.fromBinary(adapterBinary);
    assertTrue(persistableAdapter instanceof LegacyFeatureDataAdapter);
    adapter = (LegacyFeatureDataAdapter) persistableAdapter;
    assertNotNull(adapter.getUpdatedAdapter());
    final FeatureDataAdapter updatedAdapter = adapter.getUpdatedAdapter();
    assertEquals(4, updatedAdapter.getFieldDescriptors().length);
    assertEquals(String.class, updatedAdapter.getFieldDescriptor("strAttr").bindingClass());
    assertEquals(Integer.class, updatedAdapter.getFieldDescriptor("intAttr").bindingClass());
    assertTrue(TemporalFieldDescriptor.class.isAssignableFrom(updatedAdapter.getFieldDescriptor("dateAttr").getClass()));
    final TemporalFieldDescriptor<?> temporalField = (TemporalFieldDescriptor<?>) updatedAdapter.getFieldDescriptor("dateAttr");
    assertEquals(Date.class, temporalField.bindingClass());
    assertTrue(temporalField.indexHints().contains(TimeField.TIME_DIMENSION_HINT));
    assertTrue(SpatialFieldDescriptor.class.isAssignableFrom(updatedAdapter.getFieldDescriptor("geom").getClass()));
    final SpatialFieldDescriptor<?> spatialField = (SpatialFieldDescriptor<?>) updatedAdapter.getFieldDescriptor("geom");
    assertEquals(Point.class, spatialField.bindingClass());
    assertEquals(GeometryUtils.getDefaultCRS(), spatialField.crs());
    assertTrue(spatialField.indexHints().contains(SpatialField.LATITUDE_DIMENSION_HINT));
    assertTrue(spatialField.indexHints().contains(SpatialField.LONGITUDE_DIMENSION_HINT));
    assertEquals("testType", updatedAdapter.getTypeName());
    assertEquals(SimpleFeature.class, updatedAdapter.getDataClass());
    assertTrue(updatedAdapter.hasTemporalConstraints());
    assertNotNull(adapter.getVisibilityHandler());
    final VisibilityHandler visibilityHandler = adapter.getVisibilityHandler();
    assertTrue(visibilityHandler instanceof JsonFieldLevelVisibilityHandler);
    assertEquals("strAttr", ((JsonFieldLevelVisibilityHandler) visibilityHandler).getVisibilityAttribute());
}
Also used : SimpleFeatureTypeBuilder(org.geotools.feature.simple.SimpleFeatureTypeBuilder) LegacyFeatureDataAdapter(org.locationtech.geowave.migration.legacy.adapter.vector.LegacyFeatureDataAdapter) Persistable(org.locationtech.geowave.core.index.persist.Persistable) AttributeDescriptor(org.opengis.feature.type.AttributeDescriptor) Point(org.locationtech.jts.geom.Point) Date(java.util.Date) AttributeTypeBuilder(org.geotools.feature.AttributeTypeBuilder) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) SpatialFieldDescriptor(org.locationtech.geowave.core.geotime.adapter.SpatialFieldDescriptor) VisibilityHandler(org.locationtech.geowave.core.store.api.VisibilityHandler) JsonFieldLevelVisibilityHandler(org.locationtech.geowave.core.store.data.visibility.JsonFieldLevelVisibilityHandler) JsonFieldLevelVisibilityHandler(org.locationtech.geowave.core.store.data.visibility.JsonFieldLevelVisibilityHandler) TemporalFieldDescriptor(org.locationtech.geowave.core.geotime.adapter.TemporalFieldDescriptor) FeatureDataAdapter(org.locationtech.geowave.adapter.vector.FeatureDataAdapter) LegacyFeatureDataAdapter(org.locationtech.geowave.migration.legacy.adapter.vector.LegacyFeatureDataAdapter) Test(org.junit.Test)

Example 5 with VisibilityHandler

use of org.locationtech.geowave.core.store.api.VisibilityHandler in project geowave by locationtech.

the class BaseDataStore method createWriter.

@SuppressWarnings("unchecked")
private <T> Writer<T> createWriter(final InternalDataAdapter<T> adapter, final VisibilityHandler visibilityHandler, final boolean writingOriginalData, final Index... indices) {
    final boolean secondaryIndex = writingOriginalData && baseOptions.isSecondaryIndexing() && DataIndexUtils.adapterSupportsDataIndex(adapter);
    final Writer<T>[] writers = new Writer[secondaryIndex ? indices.length + 1 : indices.length];
    final VisibilityHandler resolvedVisibilityHandler = resolveVisibilityHandler(adapter, visibilityHandler);
    int i = 0;
    if (secondaryIndex) {
        final DataStoreCallbackManager callbackManager = new DataStoreCallbackManager(statisticsStore, true);
        final AdapterToIndexMapping indexMapping = indexMappingStore.getMapping(adapter.getAdapterId(), DataIndexUtils.DATA_ID_INDEX.getName());
        final List<IngestCallback<T>> callbacks = Collections.singletonList(callbackManager.getIngestCallback(adapter, indexMapping, DataIndexUtils.DATA_ID_INDEX));
        final IngestCallbackList<T> callbacksList = new IngestCallbackList<>(callbacks);
        writers[i++] = createDataIndexWriter(adapter, indexMapping, resolvedVisibilityHandler, baseOperations, baseOptions, callbacksList, callbacksList);
    }
    for (final Index index : indices) {
        final DataStoreCallbackManager callbackManager = new DataStoreCallbackManager(statisticsStore, i == 0);
        callbackManager.setPersistStats(baseOptions.isPersistDataStatistics());
        final AdapterToIndexMapping indexMapping = indexMappingStore.getMapping(adapter.getAdapterId(), index.getName());
        final List<IngestCallback<T>> callbacks = writingOriginalData ? Collections.singletonList(callbackManager.getIngestCallback(adapter, indexMapping, index)) : Collections.emptyList();
        final IngestCallbackList<T> callbacksList = new IngestCallbackList<>(callbacks);
        writers[i] = createIndexWriter(adapter, indexMapping, index, resolvedVisibilityHandler, baseOperations, baseOptions, callbacksList, callbacksList);
        if (adapter.getAdapter() instanceof IndexDependentDataAdapter) {
            writers[i] = new IndependentAdapterIndexWriter<>((IndexDependentDataAdapter<T>) adapter.getAdapter(), index, resolvedVisibilityHandler, writers[i]);
        }
        i++;
    }
    return new IndexCompositeWriter<>(writers);
}
Also used : IngestCallbackList(org.locationtech.geowave.core.store.callback.IngestCallbackList) AdapterToIndexMapping(org.locationtech.geowave.core.store.AdapterToIndexMapping) Index(org.locationtech.geowave.core.store.api.Index) IndexCompositeWriter(org.locationtech.geowave.core.store.index.writer.IndexCompositeWriter) IndexDependentDataAdapter(org.locationtech.geowave.core.store.adapter.IndexDependentDataAdapter) VisibilityHandler(org.locationtech.geowave.core.store.api.VisibilityHandler) IngestCallback(org.locationtech.geowave.core.store.callback.IngestCallback) RowWriter(org.locationtech.geowave.core.store.operations.RowWriter) Writer(org.locationtech.geowave.core.store.api.Writer) IndexCompositeWriter(org.locationtech.geowave.core.store.index.writer.IndexCompositeWriter) MetadataWriter(org.locationtech.geowave.core.store.operations.MetadataWriter) IndependentAdapterIndexWriter(org.locationtech.geowave.core.store.index.writer.IndependentAdapterIndexWriter)

Aggregations

VisibilityHandler (org.locationtech.geowave.core.store.api.VisibilityHandler)10 Index (org.locationtech.geowave.core.store.api.Index)5 GlobalVisibilityHandler (org.locationtech.geowave.core.store.data.visibility.GlobalVisibilityHandler)5 DataStore (org.locationtech.geowave.core.store.api.DataStore)4 Test (org.junit.Test)3 Statistic (org.locationtech.geowave.core.store.api.Statistic)3 LegacyFeatureDataAdapter (org.locationtech.geowave.migration.legacy.adapter.vector.LegacyFeatureDataAdapter)3 ArrayList (java.util.ArrayList)2 FeatureDataAdapter (org.locationtech.geowave.adapter.vector.FeatureDataAdapter)2 NumericRange (org.locationtech.geowave.core.index.numeric.NumericRange)2 StoreFactoryFamilySpi (org.locationtech.geowave.core.store.StoreFactoryFamilySpi)2 AdapterIndexMappingStore (org.locationtech.geowave.core.store.adapter.AdapterIndexMappingStore)2 MockComponents (org.locationtech.geowave.core.store.adapter.MockComponents)2 MockAbstractDataAdapter (org.locationtech.geowave.core.store.adapter.MockComponents.MockAbstractDataAdapter)2 PersistentAdapterStore (org.locationtech.geowave.core.store.adapter.PersistentAdapterStore)2 JsonFieldLevelVisibilityHandler (org.locationtech.geowave.core.store.data.visibility.JsonFieldLevelVisibilityHandler)2 IndexImpl (org.locationtech.geowave.core.store.index.IndexImpl)2 DataIdQuery (org.locationtech.geowave.core.store.query.constraints.DataIdQuery)2 DataStatisticsStore (org.locationtech.geowave.core.store.statistics.DataStatisticsStore)2 CountStatistic (org.locationtech.geowave.core.store.statistics.adapter.CountStatistic)2