@Test public void testMultiCoverageDirect() throws Exception { File testDir = tempFolder.newFolder("multi-coverage"); URL testUrl = URLs.fileToUrl(testDir); FileUtils.copyDirectory( TestData.file(NetCDFMosaicReaderTest.class, "multi-coverage"), testDir); testMultiCoverageMosaic(testUrl, null); final File targetStoreConfiguration = new File(testDir, "target.properties"); final String properties = String.format( "SPI=org.geotools.data.h2.H2DataStoreFactory\n" + "driver=org.h2.Driver\n" + "database=%s\n" + "user=sa\n" + "password=", getTargetDbForProperties(testDir)); FileUtils.writeStringToFile(targetStoreConfiguration, properties, "UTF-8"); File logDir = new File(testDir, "logs"); assertTrue(logDir.mkdir()); H2MigrateConfiguration config = new H2MigrateConfiguration(); config.setMosaicPath(testDir.getPath()); config.setConcurrency(1); config.setTargetStoreConfiguration(targetStoreConfiguration.getPath()); config.setLogDirectory(logDir.getPath()); final H2Migrator migrator = new H2Migrator(config); migrator.migrate(); assertMultiCoverageMigration(testDir, logDir, config); testMultiCoverageMosaic(testUrl, null); }
public void migrate() throws Exception { ExecutorService executorService = Executors.newFixedThreadPool(configuration.getConcurrency()); DataStore targetStore = H2MigrateConfiguration.getDataStore(configuration.getTargetStoreConfiguration()); File logDirectory = configuration.getLogDirectory(); try (LogWriter netcdfWriter = new LogWriter(new File(logDirectory, "migrated.txt")); LogWriter h2Writer = new LogWriter(new File(logDirectory, "h2.txt"))) { targetStore.getTypeNames(); LinkedHashSet<String> filePaths = new LinkedHashSet<>(); final String[] coverages; if (configuration.getSourceStoreConfiguration() != null) { coverages = getFilesFromStore(filePaths); } else { coverages = getFilesFromReader(filePaths); } Map<String, Future> futures = new HashMap<>(); for (String path : filePaths) { futures.put( path, executorService.submit( () -> migrateNetcdf( path, coverages, targetStore, netcdfWriter, h2Writer))); } for (Map.Entry<String, Future> entry : futures.entrySet()) { try { entry.getValue().get(); } catch (Exception e) { if (configuration.isFailureIgnored()) { LOGGER.log(Level.WARNING, "Failed to migrate file: " + entry.getKey(), e); } else { throw new MigrationException( "Failed to migrate file: " + entry.getKey(), e); } } } updateMosaicConfiguration(coverages); LOGGER.info("Migration complete with success!"); } finally { executorService.shutdown(); if (targetStore != null) targetStore.dispose(); } }
H2Migrator { public void migrate() throws Exception { ExecutorService executorService = Executors.newFixedThreadPool(configuration.getConcurrency()); DataStore targetStore = H2MigrateConfiguration.getDataStore(configuration.getTargetStoreConfiguration()); File logDirectory = configuration.getLogDirectory(); try (LogWriter netcdfWriter = new LogWriter(new File(logDirectory, "migrated.txt")); LogWriter h2Writer = new LogWriter(new File(logDirectory, "h2.txt"))) { targetStore.getTypeNames(); LinkedHashSet<String> filePaths = new LinkedHashSet<>(); final String[] coverages; if (configuration.getSourceStoreConfiguration() != null) { coverages = getFilesFromStore(filePaths); } else { coverages = getFilesFromReader(filePaths); } Map<String, Future> futures = new HashMap<>(); for (String path : filePaths) { futures.put( path, executorService.submit( () -> migrateNetcdf( path, coverages, targetStore, netcdfWriter, h2Writer))); } for (Map.Entry<String, Future> entry : futures.entrySet()) { try { entry.getValue().get(); } catch (Exception e) { if (configuration.isFailureIgnored()) { LOGGER.log(Level.WARNING, "Failed to migrate file: " + entry.getKey(), e); } else { throw new MigrationException( "Failed to migrate file: " + entry.getKey(), e); } } } updateMosaicConfiguration(coverages); LOGGER.info("Migration complete with success!"); } finally { executorService.shutdown(); if (targetStore != null) targetStore.dispose(); } } }
H2Migrator { public void migrate() throws Exception { ExecutorService executorService = Executors.newFixedThreadPool(configuration.getConcurrency()); DataStore targetStore = H2MigrateConfiguration.getDataStore(configuration.getTargetStoreConfiguration()); File logDirectory = configuration.getLogDirectory(); try (LogWriter netcdfWriter = new LogWriter(new File(logDirectory, "migrated.txt")); LogWriter h2Writer = new LogWriter(new File(logDirectory, "h2.txt"))) { targetStore.getTypeNames(); LinkedHashSet<String> filePaths = new LinkedHashSet<>(); final String[] coverages; if (configuration.getSourceStoreConfiguration() != null) { coverages = getFilesFromStore(filePaths); } else { coverages = getFilesFromReader(filePaths); } Map<String, Future> futures = new HashMap<>(); for (String path : filePaths) { futures.put( path, executorService.submit( () -> migrateNetcdf( path, coverages, targetStore, netcdfWriter, h2Writer))); } for (Map.Entry<String, Future> entry : futures.entrySet()) { try { entry.getValue().get(); } catch (Exception e) { if (configuration.isFailureIgnored()) { LOGGER.log(Level.WARNING, "Failed to migrate file: " + entry.getKey(), e); } else { throw new MigrationException( "Failed to migrate file: " + entry.getKey(), e); } } } updateMosaicConfiguration(coverages); LOGGER.info("Migration complete with success!"); } finally { executorService.shutdown(); if (targetStore != null) targetStore.dispose(); } } H2Migrator(H2MigrateConfiguration configuration); }
H2Migrator { public void migrate() throws Exception { ExecutorService executorService = Executors.newFixedThreadPool(configuration.getConcurrency()); DataStore targetStore = H2MigrateConfiguration.getDataStore(configuration.getTargetStoreConfiguration()); File logDirectory = configuration.getLogDirectory(); try (LogWriter netcdfWriter = new LogWriter(new File(logDirectory, "migrated.txt")); LogWriter h2Writer = new LogWriter(new File(logDirectory, "h2.txt"))) { targetStore.getTypeNames(); LinkedHashSet<String> filePaths = new LinkedHashSet<>(); final String[] coverages; if (configuration.getSourceStoreConfiguration() != null) { coverages = getFilesFromStore(filePaths); } else { coverages = getFilesFromReader(filePaths); } Map<String, Future> futures = new HashMap<>(); for (String path : filePaths) { futures.put( path, executorService.submit( () -> migrateNetcdf( path, coverages, targetStore, netcdfWriter, h2Writer))); } for (Map.Entry<String, Future> entry : futures.entrySet()) { try { entry.getValue().get(); } catch (Exception e) { if (configuration.isFailureIgnored()) { LOGGER.log(Level.WARNING, "Failed to migrate file: " + entry.getKey(), e); } else { throw new MigrationException( "Failed to migrate file: " + entry.getKey(), e); } } } updateMosaicConfiguration(coverages); LOGGER.info("Migration complete with success!"); } finally { executorService.shutdown(); if (targetStore != null) targetStore.dispose(); } } H2Migrator(H2MigrateConfiguration configuration); void migrate(); String[] getFilesFromReader(LinkedHashSet<String> filePaths); }
H2Migrator { public void migrate() throws Exception { ExecutorService executorService = Executors.newFixedThreadPool(configuration.getConcurrency()); DataStore targetStore = H2MigrateConfiguration.getDataStore(configuration.getTargetStoreConfiguration()); File logDirectory = configuration.getLogDirectory(); try (LogWriter netcdfWriter = new LogWriter(new File(logDirectory, "migrated.txt")); LogWriter h2Writer = new LogWriter(new File(logDirectory, "h2.txt"))) { targetStore.getTypeNames(); LinkedHashSet<String> filePaths = new LinkedHashSet<>(); final String[] coverages; if (configuration.getSourceStoreConfiguration() != null) { coverages = getFilesFromStore(filePaths); } else { coverages = getFilesFromReader(filePaths); } Map<String, Future> futures = new HashMap<>(); for (String path : filePaths) { futures.put( path, executorService.submit( () -> migrateNetcdf( path, coverages, targetStore, netcdfWriter, h2Writer))); } for (Map.Entry<String, Future> entry : futures.entrySet()) { try { entry.getValue().get(); } catch (Exception e) { if (configuration.isFailureIgnored()) { LOGGER.log(Level.WARNING, "Failed to migrate file: " + entry.getKey(), e); } else { throw new MigrationException( "Failed to migrate file: " + entry.getKey(), e); } } } updateMosaicConfiguration(coverages); LOGGER.info("Migration complete with success!"); } finally { executorService.shutdown(); if (targetStore != null) targetStore.dispose(); } } H2Migrator(H2MigrateConfiguration configuration); void migrate(); String[] getFilesFromReader(LinkedHashSet<String> filePaths); static final String NETCDF_DATASTORE_PROPERTIES; }