Search in sources :

Example 1 with ResizeMRCommand

use of org.locationtech.geowave.adapter.raster.operations.ResizeMRCommand in project geowave by locationtech.

the class RasterTileResizeJobRunner method main.

public static void main(final String[] args) throws Exception {
    final ConfigOptions opts = new ConfigOptions();
    final OperationParser parser = new OperationParser();
    parser.addAdditionalObject(opts);
    final ResizeMRCommand command = new ResizeMRCommand();
    final CommandLineOperationParams params = parser.parse(command, args);
    opts.prepare(params);
    final int res = ToolRunner.run(new Configuration(), command.createRunner(params), args);
    System.exit(res);
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) CommandLineOperationParams(org.locationtech.geowave.core.cli.parser.CommandLineOperationParams) OperationParser(org.locationtech.geowave.core.cli.parser.OperationParser) ConfigOptions(org.locationtech.geowave.core.cli.operations.config.options.ConfigOptions) ResizeMRCommand(org.locationtech.geowave.adapter.raster.operations.ResizeMRCommand)

Example 2 with ResizeMRCommand

use of org.locationtech.geowave.adapter.raster.operations.ResizeMRCommand in project geowave by locationtech.

the class KDEJobRunner method runJob.

/**
 * Main method to execute the MapReduce analytic.
 */
@SuppressWarnings("deprecation")
public int runJob() throws Exception {
    Configuration conf = super.getConf();
    if (conf == null) {
        conf = new Configuration();
        setConf(conf);
    }
    Index inputPrimaryIndex = null;
    final Index[] idxArray = inputDataStoreOptions.createDataStore().getIndices();
    for (final Index idx : idxArray) {
        if ((idx != null) && ((kdeCommandLineOptions.getIndexName() == null) || kdeCommandLineOptions.getIndexName().equals(idx.getName()))) {
            inputPrimaryIndex = idx;
            break;
        }
    }
    final CoordinateReferenceSystem inputIndexCrs = GeometryUtils.getIndexCrs(inputPrimaryIndex);
    final String inputCrsCode = GeometryUtils.getCrsCode(inputIndexCrs);
    Index outputPrimaryIndex = outputIndex;
    CoordinateReferenceSystem outputIndexCrs = null;
    String outputCrsCode = null;
    if (outputPrimaryIndex != null) {
        outputIndexCrs = GeometryUtils.getIndexCrs(outputPrimaryIndex);
        outputCrsCode = GeometryUtils.getCrsCode(outputIndexCrs);
    } else {
        final SpatialDimensionalityTypeProvider sdp = new SpatialDimensionalityTypeProvider();
        final SpatialOptions so = sdp.createOptions();
        so.setCrs(inputCrsCode);
        outputPrimaryIndex = SpatialDimensionalityTypeProvider.createIndexFromOptions(so);
        outputIndexCrs = inputIndexCrs;
        outputCrsCode = inputCrsCode;
    }
    final CoordinateSystem cs = outputIndexCrs.getCoordinateSystem();
    final CoordinateSystemAxis csx = cs.getAxis(0);
    final CoordinateSystemAxis csy = cs.getAxis(1);
    final double xMax = csx.getMaximumValue();
    final double xMin = csx.getMinimumValue();
    final double yMax = csy.getMaximumValue();
    final double yMin = csy.getMinimumValue();
    if ((xMax == Double.POSITIVE_INFINITY) || (xMin == Double.NEGATIVE_INFINITY) || (yMax == Double.POSITIVE_INFINITY) || (yMin == Double.NEGATIVE_INFINITY)) {
        LOGGER.error("Raster KDE resize with raster primary index CRS dimensions min/max equal to positive infinity or negative infinity is not supported");
        throw new RuntimeException("Raster KDE resize with raster primary index CRS dimensions min/max equal to positive infinity or negative infinity is not supported");
    }
    DataStorePluginOptions rasterResizeOutputDataStoreOptions;
    String kdeCoverageName;
    // the KDE output and then run a resize operation
    if ((kdeCommandLineOptions.getTileSize() > 1)) {
        // this is the ending data store options after resize, the KDE will
        // need to output to a temporary namespace, a resize operation
        // will use the outputDataStoreOptions
        rasterResizeOutputDataStoreOptions = outputDataStoreOptions;
        // first clone the outputDataStoreOptions, then set it to a tmp
        // namespace
        final Map<String, String> configOptions = outputDataStoreOptions.getOptionsAsMap();
        final StoreFactoryOptions options = ConfigUtils.populateOptionsFromList(outputDataStoreOptions.getFactoryFamily().getDataStoreFactory().createOptionsInstance(), configOptions);
        options.setGeoWaveNamespace(outputDataStoreOptions.getGeoWaveNamespace() + "_tmp");
        outputDataStoreOptions = new DataStorePluginOptions(options);
        kdeCoverageName = kdeCommandLineOptions.getCoverageName() + TMP_COVERAGE_SUFFIX;
    } else {
        rasterResizeOutputDataStoreOptions = null;
        kdeCoverageName = kdeCommandLineOptions.getCoverageName();
    }
    if (kdeCommandLineOptions.getHdfsHostPort() == null) {
        final Properties configProperties = ConfigOptions.loadProperties(configFile);
        final String hdfsFSUrl = ConfigHDFSCommand.getHdfsUrl(configProperties);
        kdeCommandLineOptions.setHdfsHostPort(hdfsFSUrl);
    }
    GeoWaveConfiguratorBase.setRemoteInvocationParams(kdeCommandLineOptions.getHdfsHostPort(), kdeCommandLineOptions.getJobTrackerOrResourceManHostPort(), conf);
    conf.setInt(MAX_LEVEL_KEY, kdeCommandLineOptions.getMaxLevel());
    conf.setInt(MIN_LEVEL_KEY, kdeCommandLineOptions.getMinLevel());
    conf.set(COVERAGE_NAME_KEY, kdeCoverageName);
    if (kdeCommandLineOptions.getCqlFilter() != null) {
        conf.set(GaussianCellMapper.CQL_FILTER_KEY, kdeCommandLineOptions.getCqlFilter());
    }
    conf.setDouble(X_MIN_KEY, xMin);
    conf.setDouble(X_MAX_KEY, xMax);
    conf.setDouble(Y_MIN_KEY, yMin);
    conf.setDouble(Y_MAX_KEY, yMax);
    conf.set(INPUT_CRSCODE_KEY, inputCrsCode);
    conf.set(OUTPUT_CRSCODE_KEY, outputCrsCode);
    preJob1Setup(conf);
    final Job job = new Job(conf);
    job.setJarByClass(this.getClass());
    addJobClasspathDependencies(job, conf);
    job.setJobName(getJob1Name());
    job.setMapperClass(getJob1Mapper());
    job.setCombinerClass(CellSummationCombiner.class);
    job.setReducerClass(getJob1Reducer());
    job.setMapOutputKeyClass(LongWritable.class);
    job.setMapOutputValueClass(DoubleWritable.class);
    job.setOutputKeyClass(DoubleWritable.class);
    job.setOutputValueClass(LongWritable.class);
    job.setInputFormatClass(GeoWaveInputFormat.class);
    job.setOutputFormatClass(SequenceFileOutputFormat.class);
    job.setNumReduceTasks(8);
    job.setSpeculativeExecution(false);
    final PersistentAdapterStore adapterStore = inputDataStoreOptions.createAdapterStore();
    final IndexStore indexStore = inputDataStoreOptions.createIndexStore();
    final InternalAdapterStore internalAdapterStore = inputDataStoreOptions.createInternalAdapterStore();
    final short internalAdapterId = internalAdapterStore.getAdapterId(kdeCommandLineOptions.getFeatureType());
    final DataTypeAdapter<?> adapter = adapterStore.getAdapter(internalAdapterId).getAdapter();
    VectorQueryBuilder bldr = VectorQueryBuilder.newBuilder().addTypeName(adapter.getTypeName());
    if (kdeCommandLineOptions.getIndexName() != null) {
        bldr = bldr.indexName(kdeCommandLineOptions.getIndexName());
    }
    GeoWaveInputFormat.setMinimumSplitCount(job.getConfiguration(), kdeCommandLineOptions.getMinSplits());
    GeoWaveInputFormat.setMaximumSplitCount(job.getConfiguration(), kdeCommandLineOptions.getMaxSplits());
    GeoWaveInputFormat.setStoreOptions(job.getConfiguration(), inputDataStoreOptions);
    if (kdeCommandLineOptions.getCqlFilter() != null) {
        Geometry bbox = null;
        if (adapter instanceof GeotoolsFeatureDataAdapter) {
            final String geometryAttribute = ((GeotoolsFeatureDataAdapter) adapter).getFeatureType().getGeometryDescriptor().getLocalName();
            final Filter filter = ECQL.toFilter(kdeCommandLineOptions.getCqlFilter());
            final ExtractGeometryFilterVisitorResult geoAndCompareOpData = (ExtractGeometryFilterVisitorResult) filter.accept(new ExtractGeometryFilterVisitor(GeometryUtils.getDefaultCRS(), geometryAttribute), null);
            bbox = geoAndCompareOpData.getGeometry();
        }
        if ((bbox != null) && !bbox.equals(GeometryUtils.infinity())) {
            bldr = bldr.constraints(bldr.constraintsFactory().spatialTemporalConstraints().spatialConstraints(bbox).build());
        }
    }
    GeoWaveInputFormat.setQuery(conf, bldr.build(), adapterStore, internalAdapterStore, indexStore);
    FileSystem fs = null;
    try {
        fs = FileSystem.get(conf);
        fs.delete(new Path("/tmp/" + inputDataStoreOptions.getGeoWaveNamespace() + "_stats_" + kdeCommandLineOptions.getMinLevel() + "_" + kdeCommandLineOptions.getMaxLevel() + "_" + kdeCommandLineOptions.getCoverageName()), true);
        FileOutputFormat.setOutputPath(job, new Path("/tmp/" + inputDataStoreOptions.getGeoWaveNamespace() + "_stats_" + kdeCommandLineOptions.getMinLevel() + "_" + kdeCommandLineOptions.getMaxLevel() + "_" + kdeCommandLineOptions.getCoverageName() + "/basic"));
        final boolean job1Success = job.waitForCompletion(true);
        boolean job2Success = false;
        boolean postJob2Success = false;
        // Linear MapReduce job chaining
        if (job1Success) {
            setupEntriesPerLevel(job, conf);
            // Stats Reducer Job configuration parameters
            final Job statsReducer = new Job(conf);
            statsReducer.setJarByClass(this.getClass());
            addJobClasspathDependencies(statsReducer, conf);
            statsReducer.setJobName(getJob2Name());
            statsReducer.setMapperClass(IdentityMapper.class);
            statsReducer.setPartitionerClass(getJob2Partitioner());
            statsReducer.setReducerClass(getJob2Reducer());
            statsReducer.setNumReduceTasks(getJob2NumReducers((kdeCommandLineOptions.getMaxLevel() - kdeCommandLineOptions.getMinLevel()) + 1));
            statsReducer.setMapOutputKeyClass(DoubleWritable.class);
            statsReducer.setMapOutputValueClass(LongWritable.class);
            statsReducer.setOutputKeyClass(getJob2OutputKeyClass());
            statsReducer.setOutputValueClass(getJob2OutputValueClass());
            statsReducer.setInputFormatClass(SequenceFileInputFormat.class);
            statsReducer.setOutputFormatClass(getJob2OutputFormatClass());
            FileInputFormat.setInputPaths(statsReducer, new Path("/tmp/" + inputDataStoreOptions.getGeoWaveNamespace() + "_stats_" + kdeCommandLineOptions.getMinLevel() + "_" + kdeCommandLineOptions.getMaxLevel() + "_" + kdeCommandLineOptions.getCoverageName() + "/basic"));
            setupJob2Output(conf, statsReducer, outputDataStoreOptions.getGeoWaveNamespace(), kdeCoverageName, outputPrimaryIndex);
            job2Success = statsReducer.waitForCompletion(true);
            if (job2Success) {
                postJob2Success = postJob2Actions(conf, outputDataStoreOptions.getGeoWaveNamespace(), kdeCoverageName);
            }
        } else {
            job2Success = false;
        }
        if (rasterResizeOutputDataStoreOptions != null) {
            // delegate to resize command to wrap it up with the correctly
            // requested tile size
            final ResizeMRCommand resizeCommand = new ResizeMRCommand();
            final File configFile = File.createTempFile("temp-config", null);
            final ManualOperationParams params = new ManualOperationParams();
            params.getContext().put(ConfigOptions.PROPERTIES_FILE_CONTEXT, configFile);
            final AddStoreCommand addStore = new AddStoreCommand();
            addStore.setParameters("temp-out");
            addStore.setPluginOptions(outputDataStoreOptions);
            addStore.execute(params);
            addStore.setParameters("temp-raster-out");
            addStore.setPluginOptions(rasterResizeOutputDataStoreOptions);
            addStore.execute(params);
            // We're going to override these anyway.
            resizeCommand.setParameters("temp-out", "temp-raster-out");
            resizeCommand.getOptions().setInputCoverageName(kdeCoverageName);
            resizeCommand.getOptions().setMinSplits(kdeCommandLineOptions.getMinSplits());
            resizeCommand.getOptions().setMaxSplits(kdeCommandLineOptions.getMaxSplits());
            resizeCommand.setHdfsHostPort(kdeCommandLineOptions.getHdfsHostPort());
            resizeCommand.setJobTrackerOrResourceManHostPort(kdeCommandLineOptions.getJobTrackerOrResourceManHostPort());
            resizeCommand.getOptions().setOutputCoverageName(kdeCommandLineOptions.getCoverageName());
            resizeCommand.getOptions().setOutputTileSize(kdeCommandLineOptions.getTileSize());
            final int resizeStatus = ToolRunner.run(resizeCommand.createRunner(params), new String[] {});
            if (resizeStatus == 0) {
                // delegate to clear command to clean up with tmp namespace
                // after successful resize
                final ClearStoreCommand clearCommand = new ClearStoreCommand();
                clearCommand.setParameters("temp-out");
                clearCommand.execute(params);
            } else {
                LOGGER.warn("Resize command error code '" + resizeStatus + "'.  Retaining temporary namespace '" + outputDataStoreOptions.getGeoWaveNamespace() + "' with tile size of 1.");
            }
        }
        fs.delete(new Path("/tmp/" + inputDataStoreOptions.getGeoWaveNamespace() + "_stats_" + kdeCommandLineOptions.getMinLevel() + "_" + kdeCommandLineOptions.getMaxLevel() + "_" + kdeCommandLineOptions.getCoverageName()), true);
        return (job1Success && job2Success && postJob2Success) ? 0 : 1;
    } finally {
        if (fs != null) {
            try {
                fs.close();
            } catch (final IOException e) {
                LOGGER.info(e.getMessage());
            // Attempt to close, but don't throw an error if it is
            // already closed.
            // Log message, so find bugs does not complain.
            }
        }
    }
}
Also used : VectorQueryBuilder(org.locationtech.geowave.core.geotime.store.query.api.VectorQueryBuilder) Configuration(org.apache.hadoop.conf.Configuration) ClearStoreCommand(org.locationtech.geowave.core.store.cli.store.ClearStoreCommand) CoordinateSystem(org.opengis.referencing.cs.CoordinateSystem) CoordinateSystemAxis(org.opengis.referencing.cs.CoordinateSystemAxis) Index(org.locationtech.geowave.core.store.api.Index) Properties(java.util.Properties) AddStoreCommand(org.locationtech.geowave.core.store.cli.store.AddStoreCommand) SpatialDimensionalityTypeProvider(org.locationtech.geowave.core.geotime.index.SpatialDimensionalityTypeProvider) ManualOperationParams(org.locationtech.geowave.core.cli.parser.ManualOperationParams) DataStorePluginOptions(org.locationtech.geowave.core.store.cli.store.DataStorePluginOptions) GeotoolsFeatureDataAdapter(org.locationtech.geowave.core.geotime.store.GeotoolsFeatureDataAdapter) FileSystem(org.apache.hadoop.fs.FileSystem) ExtractGeometryFilterVisitorResult(org.locationtech.geowave.core.geotime.util.ExtractGeometryFilterVisitorResult) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) Job(org.apache.hadoop.mapreduce.Job) ResizeMRCommand(org.locationtech.geowave.adapter.raster.operations.ResizeMRCommand) Path(org.apache.hadoop.fs.Path) InternalAdapterStore(org.locationtech.geowave.core.store.adapter.InternalAdapterStore) IOException(java.io.IOException) SpatialOptions(org.locationtech.geowave.core.geotime.index.SpatialOptions) Geometry(org.locationtech.jts.geom.Geometry) PersistentAdapterStore(org.locationtech.geowave.core.store.adapter.PersistentAdapterStore) Filter(org.opengis.filter.Filter) StoreFactoryOptions(org.locationtech.geowave.core.store.StoreFactoryOptions) ExtractGeometryFilterVisitor(org.locationtech.geowave.core.geotime.util.ExtractGeometryFilterVisitor) File(java.io.File) IndexStore(org.locationtech.geowave.core.store.index.IndexStore)

Example 3 with ResizeMRCommand

use of org.locationtech.geowave.adapter.raster.operations.ResizeMRCommand in project geowave by locationtech.

the class CustomCRSKDERasterResizeIT method testKDEAndRasterResize.

@Test
public void testKDEAndRasterResize() throws Exception {
    TestUtils.deleteAll(inputDataStorePluginOptions);
    TestUtils.testLocalIngest(inputDataStorePluginOptions, DimensionalityType.SPATIAL, "EPSG:4901", KDE_SHAPEFILE_FILE, "geotools-vector", 1);
    final File configFile = File.createTempFile("test_export", null);
    final ManualOperationParams params = new ManualOperationParams();
    params.getContext().put(ConfigOptions.PROPERTIES_FILE_CONTEXT, configFile);
    final AddStoreCommand addStore = new AddStoreCommand();
    addStore.setParameters("test-in");
    addStore.setPluginOptions(inputDataStorePluginOptions);
    addStore.execute(params);
    addStore.setParameters("raster-spatial");
    addStore.setPluginOptions(outputDataStorePluginOptions);
    addStore.execute(params);
    final String outputIndexName = "raster-spatial-idx";
    final IndexPluginOptions outputIndexOptions = new IndexPluginOptions();
    outputIndexOptions.selectPlugin("spatial");
    outputIndexOptions.setName(outputIndexName);
    ((SpatialOptions) outputIndexOptions.getDimensionalityOptions()).setCrs("EPSG:4240");
    final DataStore outputDataStore = outputDataStorePluginOptions.createDataStore();
    final Index outputIndex = outputIndexOptions.createIndex(outputDataStore);
    outputDataStore.addIndex(outputIndex);
    // use the min level to define the request boundary because it is the
    // most coarse grain
    final double decimalDegreesPerCellMinLevel = 180.0 / Math.pow(2, BASE_MIN_LEVEL);
    final double cellOriginXMinLevel = Math.round(TARGET_MIN_LON / decimalDegreesPerCellMinLevel);
    final double cellOriginYMinLevel = Math.round(TARGET_MIN_LAT / decimalDegreesPerCellMinLevel);
    final double numCellsMinLevel = Math.round(TARGET_DECIMAL_DEGREES_SIZE / decimalDegreesPerCellMinLevel);
    final GeneralEnvelope queryEnvelope = new GeneralEnvelope(new double[] { // scaling on the tile composition/rendering
    decimalDegreesPerCellMinLevel * cellOriginXMinLevel, decimalDegreesPerCellMinLevel * cellOriginYMinLevel }, new double[] { // scaling
    decimalDegreesPerCellMinLevel * (cellOriginXMinLevel + numCellsMinLevel), decimalDegreesPerCellMinLevel * (cellOriginYMinLevel + numCellsMinLevel) });
    final MapReduceTestEnvironment env = MapReduceTestEnvironment.getInstance();
    final String geomField = ((FeatureDataAdapter) inputDataStorePluginOptions.createDataStore().getTypes()[0]).getFeatureType().getGeometryDescriptor().getLocalName();
    final Envelope cqlEnv = JTS.transform(new Envelope(155.12, 155.17, 16.07, 16.12), CRS.findMathTransform(CRS.decode("EPSG:4326"), CRS.decode("EPSG:4901"), true));
    final String cqlStr = String.format("BBOX(%s, %f, %f, %f, %f)", geomField, cqlEnv.getMinX(), cqlEnv.getMinY(), cqlEnv.getMaxX(), cqlEnv.getMaxY());
    for (int i = MIN_TILE_SIZE_POWER_OF_2; i <= MAX_TILE_SIZE_POWER_OF_2; i += INCREMENT) {
        LOGGER.warn("running mapreduce kde: " + i);
        final String tileSizeCoverageName = TEST_COVERAGE_NAME_MR_PREFIX + i;
        final KdeCommand command = new KdeCommand();
        command.setParameters("test-in", "raster-spatial");
        command.getKdeOptions().setCqlFilter(cqlStr);
        command.getKdeOptions().setOutputIndex(outputIndexName);
        command.getKdeOptions().setFeatureType(KDE_FEATURE_TYPE_NAME);
        command.getKdeOptions().setMinLevel(BASE_MIN_LEVEL);
        command.getKdeOptions().setMaxLevel(BASE_MAX_LEVEL);
        command.getKdeOptions().setMinSplits(MapReduceTestUtils.MIN_INPUT_SPLITS);
        command.getKdeOptions().setMaxSplits(MapReduceTestUtils.MAX_INPUT_SPLITS);
        command.getKdeOptions().setCoverageName(tileSizeCoverageName);
        command.getKdeOptions().setHdfsHostPort(env.getHdfs());
        command.getKdeOptions().setJobTrackerOrResourceManHostPort(env.getJobtracker());
        command.getKdeOptions().setTileSize((int) Math.pow(2, i));
        ToolRunner.run(command.createRunner(params), new String[] {});
    }
    final int numLevels = (BASE_MAX_LEVEL - BASE_MIN_LEVEL) + 1;
    final double[][][][] initialSampleValuesPerRequestSize = new double[numLevels][][][];
    LOGGER.warn("testing mapreduce kdes");
    for (int l = 0; l < numLevels; l++) {
        initialSampleValuesPerRequestSize[l] = testSamplesMatch(TEST_COVERAGE_NAME_MR_PREFIX, ((MAX_TILE_SIZE_POWER_OF_2 - MIN_TILE_SIZE_POWER_OF_2) / INCREMENT) + 1, queryEnvelope, new Rectangle((int) (numCellsMinLevel * Math.pow(2, l)), (int) (numCellsMinLevel * Math.pow(2, l))), null);
    }
    for (int i = MIN_TILE_SIZE_POWER_OF_2; i <= MAX_TILE_SIZE_POWER_OF_2; i += INCREMENT) {
        LOGGER.warn("running spark kde: " + i);
        final String tileSizeCoverageName = TEST_COVERAGE_NAME_SPARK_PREFIX + i;
        final KDESparkCommand command = new KDESparkCommand();
        // We're going to override these anyway.
        command.setParameters("test-in", "raster-spatial");
        command.getKDESparkOptions().setOutputIndex(outputIndexName);
        command.getKDESparkOptions().setCqlFilter(cqlStr);
        command.getKDESparkOptions().setTypeName(KDE_FEATURE_TYPE_NAME);
        command.getKDESparkOptions().setMinLevel(BASE_MIN_LEVEL);
        command.getKDESparkOptions().setMaxLevel(BASE_MAX_LEVEL);
        command.getKDESparkOptions().setMinSplits(MapReduceTestUtils.MIN_INPUT_SPLITS);
        command.getKDESparkOptions().setMaxSplits(MapReduceTestUtils.MAX_INPUT_SPLITS);
        command.getKDESparkOptions().setCoverageName(tileSizeCoverageName);
        command.getKDESparkOptions().setMaster("local[*]");
        command.getKDESparkOptions().setTileSize((int) Math.pow(2, i));
        command.execute(params);
    }
    LOGGER.warn("testing spark kdes");
    for (int l = 0; l < numLevels; l++) {
        testSamplesMatch(TEST_COVERAGE_NAME_SPARK_PREFIX, ((MAX_TILE_SIZE_POWER_OF_2 - MIN_TILE_SIZE_POWER_OF_2) / INCREMENT) + 1, queryEnvelope, new Rectangle((int) (numCellsMinLevel * Math.pow(2, l)), (int) (numCellsMinLevel * Math.pow(2, l))), initialSampleValuesPerRequestSize[l]);
    }
    // go from the original mr KDEs to a resized version using the MR command
    for (int i = MIN_TILE_SIZE_POWER_OF_2; i <= MAX_TILE_SIZE_POWER_OF_2; i += INCREMENT) {
        LOGGER.warn("running mapreduce resize: " + i);
        final String originalTileSizeCoverageName = TEST_COVERAGE_NAME_MR_PREFIX + i;
        final String resizeTileSizeCoverageName = TEST_RESIZE_COVERAGE_NAME_MR_PREFIX + i;
        final ResizeMRCommand command = new ResizeMRCommand();
        // We're going to override these anyway.
        command.setParameters("raster-spatial", "raster-spatial");
        command.getOptions().setInputCoverageName(originalTileSizeCoverageName);
        command.getOptions().setMinSplits(MapReduceTestUtils.MIN_INPUT_SPLITS);
        command.getOptions().setMaxSplits(MapReduceTestUtils.MAX_INPUT_SPLITS);
        command.setHdfsHostPort(env.getHdfs());
        command.setJobTrackerOrResourceManHostPort(env.getJobtracker());
        command.getOptions().setOutputCoverageName(resizeTileSizeCoverageName);
        command.getOptions().setIndexName(TestUtils.createWebMercatorSpatialIndex().getName());
        // due to time considerations when running the test, downsample to
        // at most 2 powers of 2 lower
        int targetRes = (MAX_TILE_SIZE_POWER_OF_2 - i);
        if ((i - targetRes) > 2) {
            targetRes = i - 2;
        }
        command.getOptions().setOutputTileSize((int) Math.pow(2, targetRes));
        ToolRunner.run(command.createRunner(params), new String[] {});
    }
    LOGGER.warn("testing mapreduce resize");
    for (int l = 0; l < numLevels; l++) {
        testSamplesMatch(TEST_RESIZE_COVERAGE_NAME_MR_PREFIX, ((MAX_TILE_SIZE_POWER_OF_2 - MIN_TILE_SIZE_POWER_OF_2) / INCREMENT) + 1, queryEnvelope, new Rectangle((int) (numCellsMinLevel * Math.pow(2, l)), (int) (numCellsMinLevel * Math.pow(2, l))), initialSampleValuesPerRequestSize[l]);
    }
    // Spark command
    for (int i = MIN_TILE_SIZE_POWER_OF_2; i <= MAX_TILE_SIZE_POWER_OF_2; i += INCREMENT) {
        LOGGER.warn("running spark resize: " + i);
        final String originalTileSizeCoverageName = TEST_COVERAGE_NAME_SPARK_PREFIX + i;
        final String resizeTileSizeCoverageName = TEST_RESIZE_COVERAGE_NAME_SPARK_PREFIX + i;
        final ResizeSparkCommand command = new ResizeSparkCommand();
        // We're going to override these anyway.
        command.setParameters("raster-spatial", "raster-spatial");
        command.getOptions().setInputCoverageName(originalTileSizeCoverageName);
        command.getOptions().setMinSplits(MapReduceTestUtils.MIN_INPUT_SPLITS);
        command.getOptions().setMaxSplits(MapReduceTestUtils.MAX_INPUT_SPLITS);
        command.getOptions().setOutputCoverageName(resizeTileSizeCoverageName);
        command.getOptions().setIndexName(TestUtils.createWebMercatorSpatialIndex().getName());
        command.setMaster("local[*]");
        // due to time considerations when running the test, downsample to
        // at most 2 powers of 2 lower
        int targetRes = (MAX_TILE_SIZE_POWER_OF_2 - i);
        if ((i - targetRes) > 2) {
            targetRes = i - 2;
        }
        command.getOptions().setOutputTileSize((int) Math.pow(2, targetRes));
        command.execute(params);
    }
    LOGGER.warn("testing spark resize");
    for (int l = 0; l < numLevels; l++) {
        testSamplesMatch(TEST_RESIZE_COVERAGE_NAME_SPARK_PREFIX, ((MAX_TILE_SIZE_POWER_OF_2 - MIN_TILE_SIZE_POWER_OF_2) / INCREMENT) + 1, queryEnvelope, new Rectangle((int) (numCellsMinLevel * Math.pow(2, l)), (int) (numCellsMinLevel * Math.pow(2, l))), initialSampleValuesPerRequestSize[l]);
    }
}
Also used : Rectangle(java.awt.Rectangle) KDESparkCommand(org.locationtech.geowave.analytic.spark.kde.operations.KDESparkCommand) Index(org.locationtech.geowave.core.store.api.Index) KdeCommand(org.locationtech.geowave.analytic.mapreduce.operations.KdeCommand) AddStoreCommand(org.locationtech.geowave.core.store.cli.store.AddStoreCommand) GeneralEnvelope(org.geotools.geometry.GeneralEnvelope) Envelope(org.locationtech.jts.geom.Envelope) SpatialOptions(org.locationtech.geowave.core.geotime.index.SpatialOptions) ManualOperationParams(org.locationtech.geowave.core.cli.parser.ManualOperationParams) DataStore(org.locationtech.geowave.core.store.api.DataStore) IndexPluginOptions(org.locationtech.geowave.core.store.index.IndexPluginOptions) ResizeSparkCommand(org.locationtech.geowave.analytic.spark.resize.ResizeSparkCommand) GeneralEnvelope(org.geotools.geometry.GeneralEnvelope) File(java.io.File) FeatureDataAdapter(org.locationtech.geowave.adapter.vector.FeatureDataAdapter) ResizeMRCommand(org.locationtech.geowave.adapter.raster.operations.ResizeMRCommand) Test(org.junit.Test)

Aggregations

ResizeMRCommand (org.locationtech.geowave.adapter.raster.operations.ResizeMRCommand)3 File (java.io.File)2 Configuration (org.apache.hadoop.conf.Configuration)2 ManualOperationParams (org.locationtech.geowave.core.cli.parser.ManualOperationParams)2 SpatialOptions (org.locationtech.geowave.core.geotime.index.SpatialOptions)2 Index (org.locationtech.geowave.core.store.api.Index)2 AddStoreCommand (org.locationtech.geowave.core.store.cli.store.AddStoreCommand)2 Rectangle (java.awt.Rectangle)1 IOException (java.io.IOException)1 Properties (java.util.Properties)1 FileSystem (org.apache.hadoop.fs.FileSystem)1 Path (org.apache.hadoop.fs.Path)1 Job (org.apache.hadoop.mapreduce.Job)1 GeneralEnvelope (org.geotools.geometry.GeneralEnvelope)1 Test (org.junit.Test)1 FeatureDataAdapter (org.locationtech.geowave.adapter.vector.FeatureDataAdapter)1 KdeCommand (org.locationtech.geowave.analytic.mapreduce.operations.KdeCommand)1 KDESparkCommand (org.locationtech.geowave.analytic.spark.kde.operations.KDESparkCommand)1 ResizeSparkCommand (org.locationtech.geowave.analytic.spark.resize.ResizeSparkCommand)1 ConfigOptions (org.locationtech.geowave.core.cli.operations.config.options.ConfigOptions)1