Search in sources :

Example 1 with MangoConfigurationReloadedEvent

use of com.serotonin.util.properties.MangoConfigurationWatcher.MangoConfigurationReloadedEvent 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 MangoConfigurationReloadedEvent

use of com.serotonin.util.properties.MangoConfigurationWatcher.MangoConfigurationReloadedEvent in project ma-core-public by infiniteautomation.

the class MigrationPointValueDaoDefinition method initialize.

@Override
public void initialize() {
    if (definitions.size() < 2) {
        throw new IllegalStateException("Migration requires two enabled time-series databases");
    }
    // list of injected definitions does not include ourselves, get the next two definitions
    this.primary = definitions.get(0);
    this.secondary = definitions.get(1);
    primary.initialize();
    secondary.initialize();
    this.pointValueDao = new MigrationPointValueDao(primary.getPointValueDao(), secondary.getPointValueDao(), dataPointDao, executorService, scheduledExecutorService, clock.withZone(config.getZone()), migrationProgressDao, config);
    context.addApplicationListener((ApplicationListener<MangoConfigurationReloadedEvent>) e -> pointValueDao.reloadConfig());
    if (log.isInfoEnabled()) {
        log.info("Time series migration enabled, from {} (secondary) to {} (primary)", secondary.getClass().getSimpleName(), primary.getClass().getSimpleName());
    }
}
Also used : MangoConfigurationReloadedEvent(com.serotonin.util.properties.MangoConfigurationWatcher.MangoConfigurationReloadedEvent) Logger(org.slf4j.Logger) Common(com.serotonin.m2m2.Common) MigrationProgressDao(com.serotonin.m2m2.db.dao.migration.progress.MigrationProgressDao) PointValueDao(com.serotonin.m2m2.db.dao.PointValueDao) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) PointValueDaoDefinition(com.serotonin.m2m2.db.PointValueDaoDefinition) ApplicationListener(org.springframework.context.ApplicationListener) ConditionalDefinition(com.serotonin.m2m2.module.ConditionalDefinition) List(java.util.List) DataPointDao(com.serotonin.m2m2.db.dao.DataPointDao) Environment(org.springframework.core.env.Environment) MigrationConfig(com.serotonin.m2m2.db.dao.migration.MigrationConfig) ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Clock(java.time.Clock) ExecutorService(java.util.concurrent.ExecutorService) MigrationPointValueDao(com.serotonin.m2m2.db.dao.migration.MigrationPointValueDao) MangoConfigurationReloadedEvent(com.serotonin.util.properties.MangoConfigurationWatcher.MangoConfigurationReloadedEvent) MigrationPointValueDao(com.serotonin.m2m2.db.dao.migration.MigrationPointValueDao)

Example 3 with MangoConfigurationReloadedEvent

use of com.serotonin.util.properties.MangoConfigurationWatcher.MangoConfigurationReloadedEvent 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

DataPointDao (com.serotonin.m2m2.db.dao.DataPointDao)3 PointValueDao (com.serotonin.m2m2.db.dao.PointValueDao)3 MangoConfigurationReloadedEvent (com.serotonin.util.properties.MangoConfigurationWatcher.MangoConfigurationReloadedEvent)3 List (java.util.List)3 ExecutorService (java.util.concurrent.ExecutorService)3 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)3 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 DelegatingPointValueDao (com.serotonin.m2m2.db.dao.DelegatingPointValueDao)2 MigrationProgress (com.serotonin.m2m2.db.dao.migration.MigrationProgressDao.MigrationProgress)2 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)2 AbstractTimer (com.serotonin.timer.AbstractTimer)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