Skip to content

Commit

Permalink
Taulujen kopiointi S3-ämpäriin
Browse files Browse the repository at this point in the history
  • Loading branch information
augustk committed Jan 15, 2025
1 parent 49499af commit fa025d6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.amazonaws.regions.Regions;
import fi.oph.opintopolku.ovara.db.DatabaseToS3;
import fi.oph.opintopolku.ovara.db.domain.S3ExportResult;
import org.javatuples.Pair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -30,7 +32,9 @@ public static void main(String[] args) throws Exception {
try {
LOG.info("Haetaan scheman {} taulut", schemaName);
List<String> tableNames = db.getTableNames("pub");
LOG.info("Scheman {} taulut: ", tableNames);
LOG.info("Scheman {} taulut: {}", schemaName, tableNames);
LOG.info("Viedään scheman {} datat Ovaran AWS S3-ämpäriin", schemaName);
List<Pair<String, S3ExportResult>> results = db.exportTablesToS3(schemaName, tableNames);
} catch (Exception e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.javatuples.Pair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.*;
import java.util.List;
import java.util.stream.Collectors;

public class DatabaseToS3 {

private static final Logger LOG = LoggerFactory.getLogger(DatabaseToS3.class);

private final Config config;

public DatabaseToS3(Config config) throws Exception {
Expand Down Expand Up @@ -71,6 +75,7 @@ public List<Pair<String, S3ExportResult>> exportTablesToS3(String schemaName, Li
}

private Pair<String, S3ExportResult> exportTableToS3(String schemaName, String tableName) throws Exception {
LOG.info("Aloitetaan scheman {} taulun {} vienti Ovaran S3-ämpäriin", schemaName, tableName);
ResultSetHandler<S3ExportResult> h = new BeanHandler<S3ExportResult>(S3ExportResult.class);

Connection connection = getConnection();
Expand All @@ -86,6 +91,8 @@ private Pair<String, S3ExportResult> exportTableToS3(String schemaName, String t
String.format("%s.csv", tableName),
config.awsRegion());

LOG.info("Scheman {} taulun {} vienti Ovaran S3-ämpäriin valmistui. Tulokset: {}", schemaName, tableName, s3ExportResult.toString());

return new Pair<>(tableName, s3ExportResult);

} finally {
Expand Down

0 comments on commit fa025d6

Please sign in to comment.