Search in sources :

Example 1 with StoreLoader

use of org.locationtech.geowave.core.store.cli.store.StoreLoader in project geowave by locationtech.

the class GeoWaveDedupeJobRunner method main.

public static void main(final String[] args) throws Exception {
    final ConfigOptions opts = new ConfigOptions();
    final MainParameterHolder holder = new MainParameterHolder();
    final OperationParser parser = new OperationParser();
    parser.addAdditionalObject(opts);
    parser.addAdditionalObject(holder);
    // Second round to get everything else.
    final CommandLineOperationParams params = parser.parse(args);
    // Set the datastore plugin
    if (holder.getMainParameter().size() == 0) {
        throw new ParameterException("Must specify datastore name as first argument.");
    }
    // Load the params for config file.
    opts.prepare(params);
    final StoreLoader loader = new StoreLoader(holder.getMainParameter().get(0));
    loader.loadFromConfig((File) params.getContext().get(ConfigOptions.PROPERTIES_FILE_CONTEXT), params.getConsole());
    final int res = ToolRunner.run(new Configuration(), new GeoWaveDedupeJobRunner(loader.getDataStorePlugin()), args);
    System.exit(res);
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) CommandLineOperationParams(org.locationtech.geowave.core.cli.parser.CommandLineOperationParams) ParameterException(com.beust.jcommander.ParameterException) StoreLoader(org.locationtech.geowave.core.store.cli.store.StoreLoader) OperationParser(org.locationtech.geowave.core.cli.parser.OperationParser) ConfigOptions(org.locationtech.geowave.core.cli.operations.config.options.ConfigOptions)

Example 2 with StoreLoader

use of org.locationtech.geowave.core.store.cli.store.StoreLoader in project geowave by locationtech.

the class GeoWaveGrpcVectorService method cqlQuery.

@Override
public void cqlQuery(final CQLQueryParametersProtos request, final StreamObserver<FeatureProtos> responseObserver) {
    final String cql = request.getCql();
    final String storeName = request.getBaseParams().getStoreName();
    final StoreLoader storeLoader = new StoreLoader(storeName);
    String typeName = request.getBaseParams().getTypeName();
    String indexName = request.getBaseParams().getIndexName();
    if (typeName.equalsIgnoreCase("")) {
        typeName = null;
    }
    if (indexName.equalsIgnoreCase("")) {
        indexName = null;
    }
    // first check to make sure the data store exists
    if (!storeLoader.loadFromConfig(GeoWaveGrpcServiceOptions.geowaveConfigFile)) {
        throw new ParameterException("Cannot find store name: " + storeLoader.getStoreName());
    }
    // get a handle to the relevant stores
    final DataStore dataStore = storeLoader.createDataStore();
    VectorQueryBuilder bldr = VectorQueryBuilder.newBuilder();
    if (typeName != null) {
        bldr = bldr.addTypeName(typeName);
    }
    if (indexName != null) {
        bldr = bldr.indexName(indexName);
    }
    try (final CloseableIterator<SimpleFeature> iterator = dataStore.query(bldr.constraints(bldr.constraintsFactory().cqlConstraints(cql)).build())) {
        while (iterator.hasNext()) {
            final SimpleFeature simpleFeature = iterator.next();
            final SimpleFeatureType type = simpleFeature.getType();
            final FeatureProtos.Builder b = FeatureProtos.newBuilder();
            final FeatureAttributeProtos.Builder attBuilder = FeatureAttributeProtos.newBuilder();
            for (int i = 0; i < type.getAttributeDescriptors().size(); i++) {
                setAttributeBuilderValue(simpleFeature.getAttribute(i), attBuilder);
                b.putAttributes(type.getAttributeDescriptors().get(i).getLocalName(), attBuilder.build());
            }
            final FeatureProtos f = b.build();
            responseObserver.onNext(f);
        }
        responseObserver.onCompleted();
    }
}
Also used : VectorQueryBuilder(org.locationtech.geowave.core.geotime.store.query.api.VectorQueryBuilder) ByteString(com.google.protobuf.ByteString) SimpleFeature(org.opengis.feature.simple.SimpleFeature) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) GeoWaveGTDataStore(org.locationtech.geowave.adapter.vector.plugin.GeoWaveGTDataStore) DataStore(org.locationtech.geowave.core.store.api.DataStore) FeatureProtos(org.locationtech.geowave.service.grpc.protobuf.FeatureProtos) StoreLoader(org.locationtech.geowave.core.store.cli.store.StoreLoader) ParameterException(com.beust.jcommander.ParameterException) FeatureAttributeProtos(org.locationtech.geowave.service.grpc.protobuf.FeatureAttributeProtos)

Example 3 with StoreLoader

use of org.locationtech.geowave.core.store.cli.store.StoreLoader in project geowave by locationtech.

the class GeoWaveGrpcVectorService method spatialTemporalQuery.

@Override
public void spatialTemporalQuery(final SpatialTemporalQueryParametersProtos request, final StreamObserver<FeatureProtos> responseObserver) {
    final String storeName = request.getSpatialParams().getBaseParams().getStoreName();
    final StoreLoader storeLoader = new StoreLoader(storeName);
    // first check to make sure the data store exists
    if (!storeLoader.loadFromConfig(GeoWaveGrpcServiceOptions.geowaveConfigFile)) {
        throw new ParameterException("Cannot find store name: " + storeLoader.getStoreName());
    }
    final DataStore dataStore = storeLoader.createDataStore();
    VectorQueryBuilder bldr = VectorQueryBuilder.newBuilder();
    String typeName = request.getSpatialParams().getBaseParams().getTypeName();
    String indexName = request.getSpatialParams().getBaseParams().getIndexName();
    if (typeName.equalsIgnoreCase("")) {
        typeName = null;
    } else {
        bldr = bldr.addTypeName(typeName);
    }
    if (indexName.equalsIgnoreCase("")) {
        indexName = null;
    } else {
        bldr = bldr.indexName(indexName);
    }
    final int constraintCount = request.getTemporalConstraintsCount();
    SpatialTemporalConstraintsBuilder stBldr = bldr.constraintsFactory().spatialTemporalConstraints();
    for (int i = 0; i < constraintCount; i++) {
        final TemporalConstraintsProtos t = request.getTemporalConstraints(i);
        stBldr.addTimeRange(Interval.of(Instant.ofEpochMilli(Timestamps.toMillis(t.getStartTime())), Instant.ofEpochMilli(Timestamps.toMillis(t.getEndTime()))));
    }
    Geometry queryGeom = null;
    try {
        queryGeom = new WKBReader(JTSFactoryFinder.getGeometryFactory()).read(request.getSpatialParams().getGeometry().toByteArray());
        stBldr = stBldr.spatialConstraints(queryGeom);
        stBldr = stBldr.spatialConstraintsCompareOperation(CompareOperation.valueOf(request.getCompareOperation()));
    } catch (final FactoryRegistryException | org.locationtech.jts.io.ParseException e) {
        LOGGER.error("Exception encountered creating query geometry", e);
    }
    try (final CloseableIterator<SimpleFeature> iterator = dataStore.query(bldr.constraints(stBldr.build()).build())) {
        while (iterator.hasNext()) {
            final SimpleFeature simpleFeature = iterator.next();
            final SimpleFeatureType type = simpleFeature.getType();
            final FeatureProtos.Builder b = FeatureProtos.newBuilder();
            final FeatureAttributeProtos.Builder attBuilder = FeatureAttributeProtos.newBuilder();
            for (int i = 0; i < type.getAttributeDescriptors().size(); i++) {
                setAttributeBuilderValue(simpleFeature.getAttribute(i), attBuilder);
                b.putAttributes(type.getAttributeDescriptors().get(i).getLocalName(), attBuilder.build());
            }
            final FeatureProtos f = b.build();
            responseObserver.onNext(f);
        }
        responseObserver.onCompleted();
    }
}
Also used : VectorQueryBuilder(org.locationtech.geowave.core.geotime.store.query.api.VectorQueryBuilder) SpatialTemporalConstraintsBuilder(org.locationtech.geowave.core.geotime.store.query.api.SpatialTemporalConstraintsBuilder) ByteString(com.google.protobuf.ByteString) WKBReader(org.locationtech.jts.io.WKBReader) SimpleFeature(org.opengis.feature.simple.SimpleFeature) TemporalConstraintsProtos(org.locationtech.geowave.service.grpc.protobuf.TemporalConstraintsProtos) Geometry(org.locationtech.jts.geom.Geometry) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) FactoryRegistryException(org.geotools.util.factory.FactoryRegistryException) GeoWaveGTDataStore(org.locationtech.geowave.adapter.vector.plugin.GeoWaveGTDataStore) DataStore(org.locationtech.geowave.core.store.api.DataStore) FeatureProtos(org.locationtech.geowave.service.grpc.protobuf.FeatureProtos) StoreLoader(org.locationtech.geowave.core.store.cli.store.StoreLoader) ParameterException(com.beust.jcommander.ParameterException) FeatureAttributeProtos(org.locationtech.geowave.service.grpc.protobuf.FeatureAttributeProtos)

Example 4 with StoreLoader

use of org.locationtech.geowave.core.store.cli.store.StoreLoader in project geowave by locationtech.

the class GeoWaveGrpcVectorService method vectorQuery.

@Override
public void vectorQuery(final VectorQueryParametersProtos request, final StreamObserver<FeatureProtos> responseObserver) {
    final String storeName = request.getStoreName();
    final StoreLoader storeLoader = new StoreLoader(storeName);
    // first check to make sure the data store exists
    if (!storeLoader.loadFromConfig(GeoWaveGrpcServiceOptions.geowaveConfigFile)) {
        throw new ParameterException("Cannot find store name: " + storeLoader.getStoreName());
    }
    GeoWaveGTDataStore gtStore = null;
    try {
        gtStore = new GeoWaveGTDataStore(new GeoWavePluginConfig(storeLoader.getDataStorePlugin()));
    } catch (final IOException | GeoWavePluginException e) {
        LOGGER.error("Exception encountered instantiating GeoWaveGTDataStore", e);
        responseObserver.onError(e);
    }
    Filter filter = null;
    try {
        filter = ECQL.toFilter(request.getQuery());
    } catch (final CQLException e) {
        LOGGER.error("Exception encountered creating filter from CQL", e);
        responseObserver.onError(e);
    }
    ContentFeatureCollection featureCollection = null;
    try {
        final String typeName = request.getTypeName();
        featureCollection = gtStore.getFeatureSource(typeName).getFeatures(filter);
    } catch (final IOException | NullPointerException e) {
        LOGGER.error("Exception encountered getting feature collection", e);
        responseObserver.onError(e);
    }
    try (final SimpleFeatureIterator iterator = featureCollection.features()) {
        while (iterator.hasNext()) {
            final SimpleFeature simpleFeature = iterator.next();
            final SimpleFeatureType type = simpleFeature.getType();
            final FeatureProtos.Builder b = FeatureProtos.newBuilder();
            final FeatureAttributeProtos.Builder attBuilder = FeatureAttributeProtos.newBuilder();
            for (int i = 0; i < type.getAttributeDescriptors().size(); i++) {
                setAttributeBuilderValue(simpleFeature.getAttribute(i), attBuilder);
                b.putAttributes(type.getAttributeDescriptors().get(i).getLocalName(), attBuilder.build());
            /*
           * b.putAttributes( type.getAttributeDescriptors().get( i).getLocalName(),
           * simpleFeature.getAttribute(i) == null ? "" : simpleFeature.getAttribute(
           * i).toString());
           */
            }
            final FeatureProtos f = b.build();
            responseObserver.onNext(f);
        }
        responseObserver.onCompleted();
    } catch (final NullPointerException e) {
        LOGGER.error("Exception encountered", e);
        responseObserver.onError(e);
    }
}
Also used : GeoWavePluginConfig(org.locationtech.geowave.adapter.vector.plugin.GeoWavePluginConfig) ContentFeatureCollection(org.geotools.data.store.ContentFeatureCollection) ByteString(com.google.protobuf.ByteString) IOException(java.io.IOException) SimpleFeature(org.opengis.feature.simple.SimpleFeature) GeoWavePluginException(org.locationtech.geowave.adapter.vector.plugin.GeoWavePluginException) SimpleFeatureIterator(org.geotools.data.simple.SimpleFeatureIterator) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) Filter(org.opengis.filter.Filter) GeoWaveGTDataStore(org.locationtech.geowave.adapter.vector.plugin.GeoWaveGTDataStore) FeatureProtos(org.locationtech.geowave.service.grpc.protobuf.FeatureProtos) StoreLoader(org.locationtech.geowave.core.store.cli.store.StoreLoader) ParameterException(com.beust.jcommander.ParameterException) FeatureAttributeProtos(org.locationtech.geowave.service.grpc.protobuf.FeatureAttributeProtos) CQLException(org.geotools.filter.text.cql2.CQLException)

Example 5 with StoreLoader

use of org.locationtech.geowave.core.store.cli.store.StoreLoader in project geowave by locationtech.

the class MigrationCommand method execute.

/**
 * Prep the driver & run the operation.
 */
@Override
public void execute(final OperationParams params) {
    if (parameters.size() != 1) {
        throw new ParameterException("Requires arguments: <store name>");
    }
    final String storeName = parameters.get(0);
    final StoreLoader inputStoreLoader = new StoreLoader(storeName);
    if (!inputStoreLoader.loadFromConfig(getGeoWaveConfigFile(), params.getConsole())) {
        throw new ParameterException("Cannot find store name: " + inputStoreLoader.getStoreName());
    }
    final DataStorePluginOptions storeOptions = inputStoreLoader.getDataStorePlugin();
    final DataStoreOperations operations = storeOptions.createDataStoreOperations();
    final PropertyStore propertyStore = storeOptions.createPropertyStore();
    try {
        if (!operations.metadataExists(MetadataType.ADAPTER) && !operations.metadataExists(MetadataType.INDEX)) {
            throw new ParameterException("There is no data in the data store to migrate.");
        }
    } catch (final IOException e) {
        throw new RuntimeException("Unable to determine if metadata tables exist for data store.", e);
    }
    final DataStoreProperty dataVersionProperty = propertyStore.getProperty(BaseDataStoreUtils.DATA_VERSION_PROPERTY);
    final int dataVersion = dataVersionProperty == null ? 0 : (int) dataVersionProperty.getValue();
    if (dataVersion == BaseDataStoreUtils.DATA_VERSION) {
        throw new ParameterException("The data version matches the CLI version, there are no migrations to apply.");
    }
    if (dataVersion > BaseDataStoreUtils.DATA_VERSION) {
        throw new ParameterException("The data store is using a newer serialization format.  Please update to a newer version " + "of the CLI that is compatible with the data store.");
    }
    // Do migration
    if (dataVersion < 1) {
        migrate0to1(storeOptions, operations, params.getConsole());
    }
    propertyStore.setProperty(new DataStoreProperty(BaseDataStoreUtils.DATA_VERSION_PROPERTY, BaseDataStoreUtils.DATA_VERSION));
    params.getConsole().println("Migration completed successfully!");
}
Also used : DataStoreOperations(org.locationtech.geowave.core.store.operations.DataStoreOperations) DataStorePluginOptions(org.locationtech.geowave.core.store.cli.store.DataStorePluginOptions) DataStoreProperty(org.locationtech.geowave.core.store.DataStoreProperty) ParameterException(com.beust.jcommander.ParameterException) StoreLoader(org.locationtech.geowave.core.store.cli.store.StoreLoader) IOException(java.io.IOException) PropertyStore(org.locationtech.geowave.core.store.PropertyStore)

Aggregations

StoreLoader (org.locationtech.geowave.core.store.cli.store.StoreLoader)12 ParameterException (com.beust.jcommander.ParameterException)11 DataStorePluginOptions (org.locationtech.geowave.core.store.cli.store.DataStorePluginOptions)6 SimpleFeature (org.opengis.feature.simple.SimpleFeature)6 ByteString (com.google.protobuf.ByteString)5 GeoWaveGTDataStore (org.locationtech.geowave.adapter.vector.plugin.GeoWaveGTDataStore)5 FeatureAttributeProtos (org.locationtech.geowave.service.grpc.protobuf.FeatureAttributeProtos)5 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)5 DataStore (org.locationtech.geowave.core.store.api.DataStore)4 FeatureProtos (org.locationtech.geowave.service.grpc.protobuf.FeatureProtos)4 Geometry (org.locationtech.jts.geom.Geometry)4 IOException (java.io.IOException)3 VectorQueryBuilder (org.locationtech.geowave.core.geotime.store.query.api.VectorQueryBuilder)3 Index (org.locationtech.geowave.core.store.api.Index)3 WKBReader (org.locationtech.jts.io.WKBReader)3 File (java.io.File)2 FactoryRegistryException (org.geotools.util.factory.FactoryRegistryException)2 IndexStore (org.locationtech.geowave.core.store.index.IndexStore)2 StreamObserver (io.grpc.stub.StreamObserver)1 Date (java.util.Date)1