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);
}
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();
}
}
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();
}
}
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);
}
}
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!");
}
Aggregations