Search in sources :

Example 1 with LegacyFeatureDataAdapter

use of org.locationtech.geowave.migration.legacy.adapter.vector.LegacyFeatureDataAdapter 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 2 with LegacyFeatureDataAdapter

use of org.locationtech.geowave.migration.legacy.adapter.vector.LegacyFeatureDataAdapter 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 3 with LegacyFeatureDataAdapter

use of org.locationtech.geowave.migration.legacy.adapter.vector.LegacyFeatureDataAdapter in project geowave by locationtech.

the class MigrationCommand method migrate0to1.

public void migrate0to1(final DataStorePluginOptions options, final DataStoreOperations operations, final Console console) {
    console.println("Migration 1.x -> 2.x");
    final DataStore dataStore = options.createDataStore();
    console.println("  Migrating data type adapters...");
    final PersistentAdapterStore adapterStore = options.createAdapterStore();
    final List<Short> adapterIDs = Lists.newArrayList();
    int migratedAdapters = 0;
    final InternalDataAdapter<?>[] adapters = adapterStore.getAdapters();
    for (final InternalDataAdapter<?> adapter : adapters) {
        adapterIDs.add(adapter.getAdapterId());
        if (adapter instanceof LegacyInternalDataAdapterWrapper) {
            adapterStore.removeAdapter(adapter.getAdapterId());
            // Write updated adapter
            adapterStore.addAdapter(((LegacyInternalDataAdapterWrapper<?>) adapter).getUpdatedAdapter());
            migratedAdapters++;
        } else if (adapter.getAdapter() instanceof LegacyFeatureDataAdapter) {
            final FeatureDataAdapter updatedAdapter = ((LegacyFeatureDataAdapter) adapter.getAdapter()).getUpdatedAdapter();
            final VisibilityHandler visibilityHandler = ((LegacyFeatureDataAdapter) adapter.getAdapter()).getVisibilityHandler();
            // Write updated adapter
            adapterStore.removeAdapter(adapter.getAdapterId());
            adapterStore.addAdapter(updatedAdapter.asInternalAdapter(adapter.getAdapterId(), visibilityHandler));
            migratedAdapters++;
        }
    }
    if (migratedAdapters > 0) {
        console.println("    Migrated " + migratedAdapters + " data type adapters.");
    } else {
        console.println("    No data type adapters needed to be migrated.");
    }
    console.println("  Migrating indices...");
    final IndexStore indexStore = options.createIndexStore();
    int migratedIndices = 0;
    try (CloseableIterator<Index> indices = indexStore.getIndices()) {
        while (indices.hasNext()) {
            final Index index = indices.next();
            final CommonIndexModel indexModel = index.getIndexModel();
            // if the index model uses any spatial fields, update and re-write
            if ((indexModel != null) && (indexModel instanceof BasicIndexModel)) {
                final NumericDimensionField<?>[] oldFields = indexModel.getDimensions();
                final NumericDimensionField<?>[] updatedFields = new NumericDimensionField<?>[oldFields.length];
                boolean updated = false;
                for (int i = 0; i < oldFields.length; i++) {
                    if (oldFields[i] instanceof LegacySpatialField) {
                        updatedFields[i] = ((LegacySpatialField<?>) oldFields[i]).getUpdatedField(index);
                        updated = true;
                    } else {
                        updatedFields[i] = oldFields[i];
                    }
                }
                if (updated) {
                    ((BasicIndexModel) indexModel).init(updatedFields);
                    indexStore.removeIndex(index.getName());
                    indexStore.addIndex(index);
                    migratedIndices++;
                }
            }
        }
    }
    if (migratedIndices > 0) {
        console.println("    Migrated " + migratedIndices + " indices.");
    } else {
        console.println("    No indices needed to be migrated.");
    }
    console.println("  Migrating index mappings...");
    // Rewrite adapter to index mappings
    final LegacyAdapterIndexMappingStore legacyIndexMappings = new LegacyAdapterIndexMappingStore(operations, options.getFactoryOptions().getStoreOptions());
    final AdapterIndexMappingStore indexMappings = options.createAdapterIndexMappingStore();
    console.println("    Writing new mappings...");
    int indexMappingCount = 0;
    for (final Short adapterId : adapterIDs) {
        final LegacyAdapterToIndexMapping mapping = legacyIndexMappings.getIndicesForAdapter(adapterId);
        final InternalDataAdapter<?> adapter = adapterStore.getAdapter(adapterId);
        for (final String indexName : mapping.getIndexNames()) {
            indexMappings.addAdapterIndexMapping(BaseDataStoreUtils.mapAdapterToIndex(adapter, indexStore.getIndex(indexName)));
            indexMappingCount++;
        }
    }
    if (indexMappingCount > 0) {
        console.println("    Migrated " + indexMappingCount + " index mappings.");
        console.println("    Deleting legacy index mappings...");
        try (MetadataDeleter deleter = operations.createMetadataDeleter(MetadataType.LEGACY_INDEX_MAPPINGS)) {
            deleter.delete(new MetadataQuery(null));
        } catch (final Exception e) {
            LOGGER.warn("Error deleting legacy index mappings", e);
        }
    } else {
        console.println("    No index mappings to migrate.");
    }
    // Update statistics
    console.println("  Migrating statistics...");
    final List<Statistic<?>> defaultStatistics = new ArrayList<>();
    for (final Index index : dataStore.getIndices()) {
        if (index instanceof DefaultStatisticsProvider) {
            defaultStatistics.addAll(((DefaultStatisticsProvider) index).getDefaultStatistics());
        }
    }
    for (final DataTypeAdapter<?> adapter : dataStore.getTypes()) {
        final DefaultStatisticsProvider defaultStatProvider = BaseDataStoreUtils.getDefaultStatisticsProvider(adapter);
        if (defaultStatProvider != null) {
            defaultStatistics.addAll(defaultStatProvider.getDefaultStatistics());
        }
    }
    console.println("    Calculating updated statistics...");
    dataStore.addStatistic(defaultStatistics.toArray(new Statistic[defaultStatistics.size()]));
    console.println("    Deleting legacy statistics...");
    try (MetadataDeleter deleter = operations.createMetadataDeleter(MetadataType.LEGACY_STATISTICS)) {
        deleter.delete(new MetadataQuery(null));
    } catch (final Exception e) {
        LOGGER.warn("Error deleting legacy statistics", e);
    }
}
Also used : NumericDimensionField(org.locationtech.geowave.core.store.dimension.NumericDimensionField) ArrayList(java.util.ArrayList) DefaultStatisticsProvider(org.locationtech.geowave.core.store.statistics.DefaultStatisticsProvider) Index(org.locationtech.geowave.core.store.api.Index) LegacyAdapterIndexMappingStore(org.locationtech.geowave.migration.legacy.core.store.LegacyAdapterIndexMappingStore) CommonIndexModel(org.locationtech.geowave.core.store.index.CommonIndexModel) Statistic(org.locationtech.geowave.core.store.api.Statistic) MetadataDeleter(org.locationtech.geowave.core.store.operations.MetadataDeleter) DataStore(org.locationtech.geowave.core.store.api.DataStore) InternalDataAdapter(org.locationtech.geowave.core.store.adapter.InternalDataAdapter) LegacySpatialField(org.locationtech.geowave.migration.legacy.core.geotime.LegacySpatialField) LegacyFeatureDataAdapter(org.locationtech.geowave.migration.legacy.adapter.vector.LegacyFeatureDataAdapter) LegacyInternalDataAdapterWrapper(org.locationtech.geowave.migration.legacy.adapter.LegacyInternalDataAdapterWrapper) AdapterIndexMappingStore(org.locationtech.geowave.core.store.adapter.AdapterIndexMappingStore) LegacyAdapterIndexMappingStore(org.locationtech.geowave.migration.legacy.core.store.LegacyAdapterIndexMappingStore) ParameterException(com.beust.jcommander.ParameterException) IOException(java.io.IOException) PersistentAdapterStore(org.locationtech.geowave.core.store.adapter.PersistentAdapterStore) VisibilityHandler(org.locationtech.geowave.core.store.api.VisibilityHandler) BasicIndexModel(org.locationtech.geowave.core.store.index.BasicIndexModel) LegacyAdapterToIndexMapping(org.locationtech.geowave.migration.legacy.core.store.LegacyAdapterToIndexMapping) FeatureDataAdapter(org.locationtech.geowave.adapter.vector.FeatureDataAdapter) LegacyFeatureDataAdapter(org.locationtech.geowave.migration.legacy.adapter.vector.LegacyFeatureDataAdapter) IndexStore(org.locationtech.geowave.core.store.index.IndexStore) MetadataQuery(org.locationtech.geowave.core.store.operations.MetadataQuery)

Aggregations

VisibilityHandler (org.locationtech.geowave.core.store.api.VisibilityHandler)3 LegacyFeatureDataAdapter (org.locationtech.geowave.migration.legacy.adapter.vector.LegacyFeatureDataAdapter)3 FeatureDataAdapter (org.locationtech.geowave.adapter.vector.FeatureDataAdapter)2 ParameterException (com.beust.jcommander.ParameterException)1 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 AttributeTypeBuilder (org.geotools.feature.AttributeTypeBuilder)1 SimpleFeatureTypeBuilder (org.geotools.feature.simple.SimpleFeatureTypeBuilder)1 Test (org.junit.Test)1 SpatialFieldDescriptor (org.locationtech.geowave.core.geotime.adapter.SpatialFieldDescriptor)1 TemporalFieldDescriptor (org.locationtech.geowave.core.geotime.adapter.TemporalFieldDescriptor)1 Persistable (org.locationtech.geowave.core.index.persist.Persistable)1 AdapterIndexMappingStore (org.locationtech.geowave.core.store.adapter.AdapterIndexMappingStore)1 InternalDataAdapter (org.locationtech.geowave.core.store.adapter.InternalDataAdapter)1 PersistentAdapterStore (org.locationtech.geowave.core.store.adapter.PersistentAdapterStore)1 DataStore (org.locationtech.geowave.core.store.api.DataStore)1 Index (org.locationtech.geowave.core.store.api.Index)1 Statistic (org.locationtech.geowave.core.store.api.Statistic)1