Search in sources :

Example 1 with MigrationProgress

use of com.serotonin.m2m2.db.dao.migration.MigrationProgressDao.MigrationProgress in project ma-core-public by MangoAutomation.

the class MigrationPointValueDao method postConstruct.

@PostConstruct
private void postConstruct() {
    if (env.getProperty("db.migration.startNewMigration", boolean.class, false)) {
        migrationProgressDao.deleteAll();
    }
    if (migrationProgressDao.count() > 0) {
        // migration in progress, restore from DB
        try (var stream = migrationProgressDao.stream()) {
            stream.map(progress -> new MigrationSeries(progress.getSeriesId(), progress.getStatus(), progress.getTimestamp())).forEach(this::addMigration);
        }
    } else {
        // start a new migration, get all points and insert progress items for them
        try (var stream = dataPointDao.streamSeriesIds()) {
            Stream<MigrationProgress> progressStream = stream.mapToObj(MigrationSeries::new).peek(this::addMigration).map(migration -> new MigrationProgress(migration.seriesId, migration.status, migration.timestamp));
            migrationProgressDao.bulkInsert(progressStream);
        }
    }
    context.addApplicationListener((ApplicationListener<MangoConfigurationReloadedEvent>) e -> loadProperties());
    loadProperties();
}
Also used : Histogram(com.codahale.metrics.Histogram) PointValueDao(com.serotonin.m2m2.db.dao.PointValueDao) RetryConfig(io.github.resilience4j.retry.RetryConfig) ZonedDateTime(java.time.ZonedDateTime) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) Metrics(io.github.resilience4j.retry.Retry.Metrics) DataPointVO(com.serotonin.m2m2.vo.DataPointVO) ArrayList(java.util.ArrayList) PriorityBlockingQueue(java.util.concurrent.PriorityBlockingQueue) Meter(com.codahale.metrics.Meter) MigrationProgress(com.serotonin.m2m2.db.dao.migration.MigrationProgressDao.MigrationProgress) Future(java.util.concurrent.Future) DataPointDao(com.serotonin.m2m2.db.dao.DataPointDao) Duration(java.time.Duration) Map(java.util.Map) ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ExecutorService(java.util.concurrent.ExecutorService) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) Nullable(org.checkerframework.checker.nullness.qual.Nullable) BatchPointValueImpl(com.serotonin.m2m2.db.dao.BatchPointValueImpl) Period(java.time.Period) MangoConfigurationReloadedEvent(com.serotonin.util.properties.MangoConfigurationWatcher.MangoConfigurationReloadedEvent) Logger(org.slf4j.Logger) Retry(io.github.resilience4j.retry.Retry) Predicate(java.util.function.Predicate) AbstractTimer(com.serotonin.timer.AbstractTimer) IntervalFunction(io.github.resilience4j.core.IntervalFunction) ApplicationListener(org.springframework.context.ApplicationListener) Instant(java.time.Instant) ZoneId(java.time.ZoneId) TimeUnit(java.util.concurrent.TimeUnit) ExponentiallyDecayingReservoir(com.codahale.metrics.ExponentiallyDecayingReservoir) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) ChronoUnit(java.time.temporal.ChronoUnit) Stream(java.util.stream.Stream) Environment(org.springframework.core.env.Environment) DateTimeFormatter(java.time.format.DateTimeFormatter) PostConstruct(javax.annotation.PostConstruct) DelegatingPointValueDao(com.serotonin.m2m2.db.dao.DelegatingPointValueDao) Optional(java.util.Optional) Queue(java.util.Queue) Comparator(java.util.Comparator) Collections(java.util.Collections) MangoConfigurationReloadedEvent(com.serotonin.util.properties.MangoConfigurationWatcher.MangoConfigurationReloadedEvent) MigrationProgress(com.serotonin.m2m2.db.dao.migration.MigrationProgressDao.MigrationProgress) PostConstruct(javax.annotation.PostConstruct)

Example 2 with MigrationProgress

use of com.serotonin.m2m2.db.dao.migration.MigrationProgressDao.MigrationProgress in project ma-core-public by infiniteautomation.

the class MigrationPointValueDao method postConstruct.

@PostConstruct
private void postConstruct() {
    if (env.getProperty("db.migration.startNewMigration", boolean.class, false)) {
        migrationProgressDao.deleteAll();
    }
    if (migrationProgressDao.count() > 0) {
        // migration in progress, restore from DB
        try (var stream = migrationProgressDao.stream()) {
            stream.map(progress -> new MigrationSeries(progress.getSeriesId(), progress.getStatus(), progress.getTimestamp())).forEach(this::addMigration);
        }
    } else {
        // start a new migration, get all points and insert progress items for them
        try (var stream = dataPointDao.streamSeriesIds()) {
            Stream<MigrationProgress> progressStream = stream.mapToObj(MigrationSeries::new).peek(this::addMigration).map(migration -> new MigrationProgress(migration.seriesId, migration.status, migration.timestamp));
            migrationProgressDao.bulkInsert(progressStream);
        }
    }
    context.addApplicationListener((ApplicationListener<MangoConfigurationReloadedEvent>) e -> loadProperties());
    loadProperties();
}
Also used : Histogram(com.codahale.metrics.Histogram) PointValueDao(com.serotonin.m2m2.db.dao.PointValueDao) RetryConfig(io.github.resilience4j.retry.RetryConfig) ZonedDateTime(java.time.ZonedDateTime) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) Metrics(io.github.resilience4j.retry.Retry.Metrics) DataPointVO(com.serotonin.m2m2.vo.DataPointVO) ArrayList(java.util.ArrayList) PriorityBlockingQueue(java.util.concurrent.PriorityBlockingQueue) Meter(com.codahale.metrics.Meter) MigrationProgress(com.serotonin.m2m2.db.dao.migration.MigrationProgressDao.MigrationProgress) Future(java.util.concurrent.Future) DataPointDao(com.serotonin.m2m2.db.dao.DataPointDao) Duration(java.time.Duration) Map(java.util.Map) ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ExecutorService(java.util.concurrent.ExecutorService) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) Nullable(org.checkerframework.checker.nullness.qual.Nullable) BatchPointValueImpl(com.serotonin.m2m2.db.dao.BatchPointValueImpl) Period(java.time.Period) MangoConfigurationReloadedEvent(com.serotonin.util.properties.MangoConfigurationWatcher.MangoConfigurationReloadedEvent) Logger(org.slf4j.Logger) Retry(io.github.resilience4j.retry.Retry) Predicate(java.util.function.Predicate) AbstractTimer(com.serotonin.timer.AbstractTimer) IntervalFunction(io.github.resilience4j.core.IntervalFunction) ApplicationListener(org.springframework.context.ApplicationListener) Instant(java.time.Instant) ZoneId(java.time.ZoneId) TimeUnit(java.util.concurrent.TimeUnit) ExponentiallyDecayingReservoir(com.codahale.metrics.ExponentiallyDecayingReservoir) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) ChronoUnit(java.time.temporal.ChronoUnit) Stream(java.util.stream.Stream) Environment(org.springframework.core.env.Environment) DateTimeFormatter(java.time.format.DateTimeFormatter) PostConstruct(javax.annotation.PostConstruct) DelegatingPointValueDao(com.serotonin.m2m2.db.dao.DelegatingPointValueDao) Optional(java.util.Optional) Queue(java.util.Queue) Comparator(java.util.Comparator) Collections(java.util.Collections) MangoConfigurationReloadedEvent(com.serotonin.util.properties.MangoConfigurationWatcher.MangoConfigurationReloadedEvent) MigrationProgress(com.serotonin.m2m2.db.dao.migration.MigrationProgressDao.MigrationProgress) PostConstruct(javax.annotation.PostConstruct)

Aggregations

ExponentiallyDecayingReservoir (com.codahale.metrics.ExponentiallyDecayingReservoir)2 Histogram (com.codahale.metrics.Histogram)2 Meter (com.codahale.metrics.Meter)2 BatchPointValueImpl (com.serotonin.m2m2.db.dao.BatchPointValueImpl)2 DataPointDao (com.serotonin.m2m2.db.dao.DataPointDao)2 DelegatingPointValueDao (com.serotonin.m2m2.db.dao.DelegatingPointValueDao)2 PointValueDao (com.serotonin.m2m2.db.dao.PointValueDao)2 MigrationProgress (com.serotonin.m2m2.db.dao.migration.MigrationProgressDao.MigrationProgress)2 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)2 AbstractTimer (com.serotonin.timer.AbstractTimer)2 MangoConfigurationReloadedEvent (com.serotonin.util.properties.MangoConfigurationWatcher.MangoConfigurationReloadedEvent)2 IntervalFunction (io.github.resilience4j.core.IntervalFunction)2 Retry (io.github.resilience4j.retry.Retry)2 Metrics (io.github.resilience4j.retry.Retry.Metrics)2 RetryConfig (io.github.resilience4j.retry.RetryConfig)2 Duration (java.time.Duration)2 Instant (java.time.Instant)2 Period (java.time.Period)2 ZoneId (java.time.ZoneId)2 ZonedDateTime (java.time.ZonedDateTime)2