Search in sources :

Example 1 with MigrationEvent

use of com.ctrip.xpipe.redis.console.migration.model.MigrationEvent in project x-pipe by ctripcorp.

the class MigrationEventDao method loadMigrationEvent.

private MigrationEvent loadMigrationEvent(List<MigrationEventTbl> details) {
    if (!CollectionUtils.isEmpty(details)) {
        MigrationEvent event = new DefaultMigrationEvent(details.get(0));
        for (MigrationEventTbl detail : details) {
            MigrationClusterTbl cluster = detail.getRedundantClusters();
            MigrationShardTbl shard = detail.getRedundantShards();
            if (null == event.getMigrationCluster(cluster.getClusterId())) {
                event.addMigrationCluster(new DefaultMigrationCluster(executors, scheduled, event, detail.getRedundantClusters(), dcService, clusterService, shardService, redisService, migrationService));
            }
            MigrationCluster migrationCluster = event.getMigrationCluster(cluster.getClusterId());
            migrationCluster.addNewMigrationShard(new DefaultMigrationShard(migrationCluster, shard, migrationCluster.getClusterShards().get(shard.getShardId()), migrationCluster.getClusterDcs(), migrationService));
        }
        return event;
    }
    throw new BadRequestException("Cannot load migration event from null.");
}
Also used : DefaultMigrationEvent(com.ctrip.xpipe.redis.console.migration.model.impl.DefaultMigrationEvent) DefaultMigrationCluster(com.ctrip.xpipe.redis.console.migration.model.impl.DefaultMigrationCluster) MigrationCluster(com.ctrip.xpipe.redis.console.migration.model.MigrationCluster) DefaultMigrationCluster(com.ctrip.xpipe.redis.console.migration.model.impl.DefaultMigrationCluster) BadRequestException(com.ctrip.xpipe.redis.console.exception.BadRequestException) DefaultMigrationShard(com.ctrip.xpipe.redis.console.migration.model.impl.DefaultMigrationShard) MigrationEvent(com.ctrip.xpipe.redis.console.migration.model.MigrationEvent) DefaultMigrationEvent(com.ctrip.xpipe.redis.console.migration.model.impl.DefaultMigrationEvent)

Example 2 with MigrationEvent

use of com.ctrip.xpipe.redis.console.migration.model.MigrationEvent in project x-pipe by ctripcorp.

the class MigrationServiceImpl method continueMigrationEvent.

@Override
public void continueMigrationEvent(long id) {
    logger.info("[continueMigrationEvent]{}", id);
    MigrationEvent event = getEvent(id);
    if (event == null) {
        throw new IllegalArgumentException("event not found:" + id);
    }
    event.process();
}
Also used : MigrationEvent(com.ctrip.xpipe.redis.console.migration.model.MigrationEvent)

Example 3 with MigrationEvent

use of com.ctrip.xpipe.redis.console.migration.model.MigrationEvent in project x-pipe by ctripcorp.

the class DefaultMigrationEventManager method getEvent.

@Override
public MigrationEvent getEvent(long eventId) {
    MigrationEvent migrationEvent = currentWorkingEvents.get(eventId);
    if (migrationEvent == null) {
        // load it from db
        logger.info("[getEvent][load from db]{}", eventId);
        migrationEvent = loadAndAdd(eventId);
    }
    return migrationEvent;
}
Also used : MigrationEvent(com.ctrip.xpipe.redis.console.migration.model.MigrationEvent)

Example 4 with MigrationEvent

use of com.ctrip.xpipe.redis.console.migration.model.MigrationEvent in project x-pipe by ctripcorp.

the class DefaultMigrationEventManager method defaultMigrationEventManager.

@PostConstruct
public void defaultMigrationEventManager() {
    scheduled = Executors.newScheduledThreadPool(1, XpipeThreadFactory.create("EventManagerCleaner"));
    scheduled.scheduleWithFixedDelay(new AbstractExceptionLogTask() {

        @Override
        protected void doRun() throws Exception {
            List<Long> finished = new LinkedList<>();
            currentWorkingEvents.forEach((id, migrationEvent) -> {
                if (migrationEvent.isDone()) {
                    finished.add(id);
                }
            });
            finished.forEach((id) -> removeEvent(id));
        }
    }, 60, 60, TimeUnit.SECONDS);
}
Also used : Logger(org.slf4j.Logger) CrossDcLeaderAware(com.ctrip.xpipe.api.cluster.CrossDcLeaderAware) LoggerFactory(org.slf4j.LoggerFactory) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Autowired(org.springframework.beans.factory.annotation.Autowired) AbstractExceptionLogTask(com.ctrip.xpipe.concurrent.AbstractExceptionLogTask) Executors(java.util.concurrent.Executors) TimeUnit(java.util.concurrent.TimeUnit) PreDestroy(javax.annotation.PreDestroy) XpipeThreadFactory(com.ctrip.xpipe.utils.XpipeThreadFactory) Component(org.springframework.stereotype.Component) List(java.util.List) MigrationEventDao(com.ctrip.xpipe.redis.console.dao.MigrationEventDao) MigrationEvent(com.ctrip.xpipe.redis.console.migration.model.MigrationEvent) Observable(com.ctrip.xpipe.api.observer.Observable) Map(java.util.Map) PostConstruct(javax.annotation.PostConstruct) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) LinkedList(java.util.LinkedList) AbstractExceptionLogTask(com.ctrip.xpipe.concurrent.AbstractExceptionLogTask) List(java.util.List) LinkedList(java.util.LinkedList) PostConstruct(javax.annotation.PostConstruct)

Example 5 with MigrationEvent

use of com.ctrip.xpipe.redis.console.migration.model.MigrationEvent in project x-pipe by ctripcorp.

the class MigrationServiceImpl method createMigrationEvent.

@Override
public Long createMigrationEvent(MigrationRequest request) {
    MigrationEvent event = migrationEventDao.createMigrationEvent(request);
    migrationEventManager.addEvent(event);
    return event.getEvent().getId();
}
Also used : MigrationEvent(com.ctrip.xpipe.redis.console.migration.model.MigrationEvent)

Aggregations

MigrationEvent (com.ctrip.xpipe.redis.console.migration.model.MigrationEvent)7 CrossDcLeaderAware (com.ctrip.xpipe.api.cluster.CrossDcLeaderAware)1 Observable (com.ctrip.xpipe.api.observer.Observable)1 AbstractExceptionLogTask (com.ctrip.xpipe.concurrent.AbstractExceptionLogTask)1 MigrationEventDao (com.ctrip.xpipe.redis.console.dao.MigrationEventDao)1 BadRequestException (com.ctrip.xpipe.redis.console.exception.BadRequestException)1 MigrationCluster (com.ctrip.xpipe.redis.console.migration.model.MigrationCluster)1 DefaultMigrationCluster (com.ctrip.xpipe.redis.console.migration.model.impl.DefaultMigrationCluster)1 DefaultMigrationEvent (com.ctrip.xpipe.redis.console.migration.model.impl.DefaultMigrationEvent)1 DefaultMigrationShard (com.ctrip.xpipe.redis.console.migration.model.impl.DefaultMigrationShard)1 MigrationStatus (com.ctrip.xpipe.redis.console.migration.status.MigrationStatus)1 XpipeThreadFactory (com.ctrip.xpipe.utils.XpipeThreadFactory)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Executors (java.util.concurrent.Executors)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 TimeUnit (java.util.concurrent.TimeUnit)1 PostConstruct (javax.annotation.PostConstruct)1