Search in sources :

Example 1 with EtlRun

use of com.robertsanek.data.etl.EtlRun in project core by z1lc.

the class MasterEtl method runEtls.

@SuppressWarnings({ "rawtypes", "try" })
public boolean runEtls(boolean fastRun, boolean parallel) {
    Stopwatch total = Stopwatch.createStarted();
    List<Class<? extends Etl>> concreteEtls = getConcreteEtls(fastRun);
    log.info("Will run %s ETLs.", concreteEtls.size());
    log.info("Creating connection to Cloud SQL and re-generating table schemas... (this may take up to 3 minutes)");
    try (SessionFactory ignored = Unchecked.get(() -> getSessionFactory(Hbm2ddlType.CREATE, ConnectionType.RSANEK));
        SessionFactory noneSf = Unchecked.get(() -> getSessionFactory(Hbm2ddlType.NONE, ConnectionType.RSANEK))) {
        log.info("Schema re-generation complete, taking %s seconds. Beginning ETL with parallel = %s.", total.elapsed().getSeconds(), parallel);
        Stream<Class<? extends Etl>> stream = parallel ? concreteEtls.parallelStream() : concreteEtls.stream();
        List<EtlRun> etlRuns = stream.map(etlClazz -> runIndividualEtl(etlClazz, noneSf)).collect(Collectors.toList());
        try (Session session = noneSf.openSession()) {
            Transaction transaction = session.beginTransaction();
            etlRuns.forEach(session::save);
            session.flush();
            session.clear();
            transaction.commit();
        } catch (Exception e) {
            log.error(e);
        }
        log.info("Completed %s ETLs in %s seconds.", concreteEtls.size(), total.elapsed().getSeconds());
        return etlRuns.stream().allMatch(etlRun -> etlRun.getWas_successful() && etlRun.getRows_generated() > 0);
    }
}
Also used : SessionFactory(org.hibernate.SessionFactory) Etl(com.robertsanek.data.etl.Etl) GsonFactory(com.google.api.client.json.gson.GsonFactory) ZonedDateTime(java.time.ZonedDateTime) Inject(com.google.inject.Inject) GOOGLE_CLOUD_SQL_CRONUS_POSTGRES_USERNAME(com.robertsanek.util.SecretType.GOOGLE_CLOUD_SQL_CRONUS_POSTGRES_USERNAME) Reflections(org.reflections.Reflections) Transaction(org.hibernate.Transaction) Log(com.robertsanek.util.Log) CrossPlatformUtils(com.robertsanek.util.platform.CrossPlatformUtils) GeneralSecurityException(java.security.GeneralSecurityException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Locale(java.util.Locale) Duration(java.time.Duration) NonUniqueObjectException(org.hibernate.NonUniqueObjectException) Configuration(org.hibernate.cfg.Configuration) JobExecutionContext(org.quartz.JobExecutionContext) NotificationSender(com.robertsanek.util.NotificationSender) EtlRun(com.robertsanek.data.etl.EtlRun) SessionFactory(org.hibernate.SessionFactory) HttpTransport(com.google.api.client.http.HttpTransport) Set(java.util.Set) GoogleNetHttpTransport(com.google.api.client.googleapis.javanet.GoogleNetHttpTransport) RetryPolicy(net.jodah.failsafe.RetryPolicy) Collectors(java.util.stream.Collectors) Logs(com.robertsanek.util.Logs) GOOGLE_CLOUD_SQL_RSANEK_POSTGRES_PASSWORD(com.robertsanek.util.SecretType.GOOGLE_CLOUD_SQL_RSANEK_POSTGRES_PASSWORD) List(java.util.List) Stream(java.util.stream.Stream) DoNotRun(com.robertsanek.data.etl.DoNotRun) Settings(com.google.api.services.sqladmin.model.Settings) Modifier(java.lang.reflect.Modifier) HibernateException(org.hibernate.HibernateException) ExceptionUtils(org.apache.commons.lang3.exception.ExceptionUtils) Operation(com.google.api.services.sqladmin.model.Operation) IntStream(java.util.stream.IntStream) GoogleCredential(com.google.api.client.googleapis.auth.oauth2.GoogleCredential) UsesLocalFiles(com.robertsanek.data.etl.UsesLocalFiles) Stopwatch(com.google.common.base.Stopwatch) LocalDateTime(java.time.LocalDateTime) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Session(org.hibernate.Session) Unchecked(com.robertsanek.util.Unchecked) SecretProvider(com.robertsanek.util.SecretProvider) GOOGLE_CLOUD_SQL_RSANEK_POSTGRES_USERNAME(com.robertsanek.util.SecretType.GOOGLE_CLOUD_SQL_RSANEK_POSTGRES_USERNAME) SQLAdmin(com.google.api.services.sqladmin.SQLAdmin) IOException(java.io.IOException) DatabaseInstance(com.google.api.services.sqladmin.model.DatabaseInstance) FileInputStream(java.io.FileInputStream) SlowEtl(com.robertsanek.data.etl.SlowEtl) Failsafe(net.jodah.failsafe.Failsafe) AtomicLong(java.util.concurrent.atomic.AtomicLong) JsonFactory(com.google.api.client.json.JsonFactory) DateTimeFormatter(java.time.format.DateTimeFormatter) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Comparator(java.util.Comparator) Collections(java.util.Collections) InjectUtils(com.robertsanek.util.inject.InjectUtils) ServiceException(org.hibernate.service.spi.ServiceException) Stopwatch(com.google.common.base.Stopwatch) GeneralSecurityException(java.security.GeneralSecurityException) NonUniqueObjectException(org.hibernate.NonUniqueObjectException) HibernateException(org.hibernate.HibernateException) IOException(java.io.IOException) ServiceException(org.hibernate.service.spi.ServiceException) Transaction(org.hibernate.Transaction) Etl(com.robertsanek.data.etl.Etl) SlowEtl(com.robertsanek.data.etl.SlowEtl) EtlRun(com.robertsanek.data.etl.EtlRun) Session(org.hibernate.Session)

Aggregations

GoogleCredential (com.google.api.client.googleapis.auth.oauth2.GoogleCredential)1 GoogleNetHttpTransport (com.google.api.client.googleapis.javanet.GoogleNetHttpTransport)1 HttpTransport (com.google.api.client.http.HttpTransport)1 JsonFactory (com.google.api.client.json.JsonFactory)1 GsonFactory (com.google.api.client.json.gson.GsonFactory)1 SQLAdmin (com.google.api.services.sqladmin.SQLAdmin)1 DatabaseInstance (com.google.api.services.sqladmin.model.DatabaseInstance)1 Operation (com.google.api.services.sqladmin.model.Operation)1 Settings (com.google.api.services.sqladmin.model.Settings)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Stopwatch (com.google.common.base.Stopwatch)1 Inject (com.google.inject.Inject)1 DoNotRun (com.robertsanek.data.etl.DoNotRun)1 Etl (com.robertsanek.data.etl.Etl)1 EtlRun (com.robertsanek.data.etl.EtlRun)1 SlowEtl (com.robertsanek.data.etl.SlowEtl)1 UsesLocalFiles (com.robertsanek.data.etl.UsesLocalFiles)1 Log (com.robertsanek.util.Log)1 Logs (com.robertsanek.util.Logs)1 NotificationSender (com.robertsanek.util.NotificationSender)1