Search in sources :

Example 1 with ServerException

use of com.ctrip.xpipe.redis.console.exception.ServerException in project x-pipe by ctripcorp.

the class MigrationEventDao method postConstruct.

@PostConstruct
private void postConstruct() {
    try {
        migrationEventTblDao = ContainerLoader.getDefaultContainer().lookup(MigrationEventTblDao.class);
        migrationClusterTblDao = ContainerLoader.getDefaultContainer().lookup(MigrationClusterTblDao.class);
        migrationShardTblDao = ContainerLoader.getDefaultContainer().lookup(MigrationShardTblDao.class);
        clusterTblDao = ContainerLoader.getDefaultContainer().lookup(ClusterTblDao.class);
        shardTblDao = ContainerLoader.getDefaultContainer().lookup(ShardTblDao.class);
    } catch (ComponentLookupException e) {
        throw new ServerException("Cannot construct dao.", e);
    }
}
Also used : ServerException(com.ctrip.xpipe.redis.console.exception.ServerException) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) PostConstruct(javax.annotation.PostConstruct)

Example 2 with ServerException

use of com.ctrip.xpipe.redis.console.exception.ServerException in project x-pipe by ctripcorp.

the class ClusterMetaServiceImpl method getClusterMeta.

@Override
public ClusterMeta getClusterMeta(final String dcName, final String clusterName) {
    ExecutorService fixedThreadPool = Executors.newFixedThreadPool(5);
    Future<DcTbl> future_dcInfo = fixedThreadPool.submit(new Callable<DcTbl>() {

        @Override
        public DcTbl call() throws Exception {
            return dcService.find(dcName);
        }
    });
    Future<ClusterTbl> future_clusterInfo = fixedThreadPool.submit(new Callable<ClusterTbl>() {

        @Override
        public ClusterTbl call() throws Exception {
            return clusterService.find(clusterName);
        }
    });
    Future<DcClusterTbl> future_dcClusterInfo = fixedThreadPool.submit(new Callable<DcClusterTbl>() {

        @Override
        public DcClusterTbl call() throws Exception {
            return dcClusterService.find(dcName, clusterName);
        }
    });
    Future<List<ShardTbl>> future_shardsInfo = fixedThreadPool.submit(new Callable<List<ShardTbl>>() {

        @Override
        public List<ShardTbl> call() throws Exception {
            return shardService.findAllByClusterName(clusterName);
        }
    });
    Future<List<DcTbl>> future_clusterRelatedDc = fixedThreadPool.submit(new Callable<List<DcTbl>>() {

        @Override
        public List<DcTbl> call() throws Exception {
            return dcService.findClusterRelatedDc(clusterName);
        }
    });
    ClusterMeta clusterMeta = new ClusterMeta();
    clusterMeta.setId(clusterName);
    try {
        DcTbl dcInfo = future_dcInfo.get();
        ClusterTbl clusterInfo = future_clusterInfo.get();
        DcClusterTbl dcClusterInfo = future_dcClusterInfo.get();
        List<DcTbl> clusterRelatedDc = future_clusterRelatedDc.get();
        if (null == dcInfo || null == clusterInfo || null == dcClusterInfo)
            return clusterMeta;
        clusterMeta.setId(clusterInfo.getClusterName());
        clusterInfo.setActivedcId(getClusterMetaCurrentPrimaryDc(dcInfo, clusterInfo));
        for (DcTbl dc : clusterRelatedDc) {
            if (dc.getId() == clusterInfo.getActivedcId()) {
                clusterMeta.setActiveDc(dc.getDcName());
            } else {
                if (Strings.isNullOrEmpty(clusterMeta.getBackupDcs())) {
                    clusterMeta.setBackupDcs(dc.getDcName());
                } else {
                    clusterMeta.setBackupDcs(clusterMeta.getBackupDcs() + "," + dc.getDcName());
                }
            }
        }
        List<ShardTbl> shards = future_shardsInfo.get();
        if (null != shards) {
            for (ShardTbl shard : shards) {
                clusterMeta.addShard(shardMetaService.getShardMeta(dcInfo, clusterInfo, shard));
            }
        }
    } catch (ExecutionException e) {
        throw new DataNotFoundException("Cannot construct cluster-meta", e);
    } catch (InterruptedException e) {
        throw new ServerException("Concurrent execution failed.", e);
    } finally {
        fixedThreadPool.shutdown();
    }
    return clusterMeta;
}
Also used : DataNotFoundException(com.ctrip.xpipe.redis.console.exception.DataNotFoundException) List(java.util.List) ServerException(com.ctrip.xpipe.redis.console.exception.ServerException) ClusterMeta(com.ctrip.xpipe.redis.core.entity.ClusterMeta) ServerException(com.ctrip.xpipe.redis.console.exception.ServerException) DataNotFoundException(com.ctrip.xpipe.redis.console.exception.DataNotFoundException)

Example 3 with ServerException

use of com.ctrip.xpipe.redis.console.exception.ServerException in project x-pipe by ctripcorp.

the class DefaultMigrationCluster method updateStat.

@Override
@DalTransaction
public void updateStat(MigrationState stat) {
    logger.info("[updateStat]{}-{}, {} -> {}", migrationCluster.getMigrationEventId(), clusterName(), this.currentState.getStatus(), stat.getStatus());
    this.currentState = stat;
    try {
        tryUpdateStartTime(stat.getStatus());
        updateStorageClusterStatus();
        updateStorageMigrationClusterStatus();
    } catch (Exception e) {
        logger.error("[updateStat] ", e);
        throw new ServerException(e.getMessage());
    }
}
Also used : ServerException(com.ctrip.xpipe.redis.console.exception.ServerException) ServerException(com.ctrip.xpipe.redis.console.exception.ServerException) TimeoutException(java.util.concurrent.TimeoutException) DalTransaction(com.ctrip.xpipe.redis.console.annotation.DalTransaction)

Example 4 with ServerException

use of com.ctrip.xpipe.redis.console.exception.ServerException in project x-pipe by ctripcorp.

the class DcMetaServiceImpl method getDcMeta.

@Override
public DcMeta getDcMeta(final String dcName) {
    ExecutorService fixedThreadPool = Executors.newFixedThreadPool(6);
    DcMeta dcMeta = new DcMeta();
    dcMeta.setId(dcName);
    dcMeta.setLastModifiedTime(DataModifiedTimeGenerator.generateModifiedTime());
    Future<DcTbl> future_dcInfo = fixedThreadPool.submit(new Callable<DcTbl>() {

        @Override
        public DcTbl call() throws Exception {
            return dcService.find(dcName);
        }
    });
    Future<List<SetinelTbl>> future_sentinels = fixedThreadPool.submit(new Callable<List<SetinelTbl>>() {

        @Override
        public List<SetinelTbl> call() throws DalException {
            return sentinelService.findAllByDcName(dcName);
        }
    });
    Future<List<KeepercontainerTbl>> future_keepercontainers = fixedThreadPool.submit(new Callable<List<KeepercontainerTbl>>() {

        @Override
        public List<KeepercontainerTbl> call() throws DalException {
            return keepercontainerService.findAllByDcName(dcName);
        }
    });
    Future<HashMap<Long, DcTbl>> future_alldcs = fixedThreadPool.submit(new Callable<HashMap<Long, DcTbl>>() {

        @Override
        public HashMap<Long, DcTbl> call() throws DalException {
            return loadAllDcs();
        }
    });
    Future<HashMap<Long, List<DcClusterTbl>>> future_allDcClusters = fixedThreadPool.submit(new Callable<HashMap<Long, List<DcClusterTbl>>>() {

        @Override
        public HashMap<Long, List<DcClusterTbl>> call() throws Exception {
            return loadAllDcClusters();
        }
    });
    Future<List<DcTbl>> future_allDetails = fixedThreadPool.submit(new Callable<List<DcTbl>>() {

        @Override
        public List<DcTbl> call() throws Exception {
            return dcService.findAllDetails(dcName);
        }
    });
    try {
        DcTbl dcInfo = future_dcInfo.get();
        if (null == dcInfo)
            return dcMeta;
        dcMeta.setId(dcInfo.getDcName());
        dcMeta.setLastModifiedTime(dcInfo.getDcLastModifiedTime());
        if (null != future_sentinels.get()) {
            for (SetinelTbl setinel : future_sentinels.get()) {
                dcMeta.addSentinel(setinelMetaService.encodeSetinelMeta(setinel, dcMeta));
            }
        }
        if (null != future_keepercontainers.get()) {
            for (KeepercontainerTbl keepercontainer : future_keepercontainers.get()) {
                dcMeta.addKeeperContainer(keepercontainerMetaService.encodeKeepercontainerMeta(keepercontainer, dcMeta));
            }
        }
        List<DcTbl> allDetails = future_allDetails.get();
        if (null != allDetails) {
            DcMetaQueryVO dcMetaQueryVO = loadMetaVO(dcInfo, allDetails);
            if (null != future_alldcs.get()) {
                dcMetaQueryVO.setAllDcs(future_alldcs.get());
            }
            if (null != future_allDcClusters.get()) {
                dcMetaQueryVO.setAllDcClusterMap(future_allDcClusters.get());
            }
            for (ClusterTbl cluster : dcMetaQueryVO.getClusterInfo().values()) {
                dcMeta.addCluster(clusterMetaService.loadClusterMeta(dcMeta, cluster, dcMetaQueryVO));
            }
        }
    } catch (ExecutionException e) {
        throw new ServerException("Execution failed.", e);
    } catch (InterruptedException e) {
        throw new ServerException("Concurrent execution failed.", e);
    } finally {
        fixedThreadPool.shutdown();
    }
    return dcMeta;
}
Also used : DcMetaQueryVO(com.ctrip.xpipe.redis.console.service.vo.DcMetaQueryVO) HashMap(java.util.HashMap) List(java.util.List) LinkedList(java.util.LinkedList) ServerException(com.ctrip.xpipe.redis.console.exception.ServerException) DcMeta(com.ctrip.xpipe.redis.core.entity.DcMeta) ServerException(com.ctrip.xpipe.redis.console.exception.ServerException) DalException(org.unidal.dal.jdbc.DalException) DalException(org.unidal.dal.jdbc.DalException)

Example 5 with ServerException

use of com.ctrip.xpipe.redis.console.exception.ServerException in project x-pipe by ctripcorp.

the class ShardMetaServiceImpl method getShardMeta.

@Override
public ShardMeta getShardMeta(final String dcName, final String clusterName, final String shardName) {
    ExecutorService fixedThreadPool = Executors.newFixedThreadPool(5);
    Future<DcTbl> future_dcInfo = fixedThreadPool.submit(new Callable<DcTbl>() {

        @Override
        public DcTbl call() throws DalException {
            return dcService.find(dcName);
        }
    });
    Future<ClusterTbl> future_clusterInfo = fixedThreadPool.submit(new Callable<ClusterTbl>() {

        @Override
        public ClusterTbl call() throws DalException {
            return clusterService.find(clusterName);
        }
    });
    Future<ShardTbl> future_shardInfo = fixedThreadPool.submit(new Callable<ShardTbl>() {

        @Override
        public ShardTbl call() throws DalException {
            return shardService.find(clusterName, shardName);
        }
    });
    Future<DcClusterTbl> future_dcClusterInfo = fixedThreadPool.submit(new Callable<DcClusterTbl>() {

        @Override
        public DcClusterTbl call() throws DalException {
            return dcClusterService.find(dcName, clusterName);
        }
    });
    Future<DcClusterShardTbl> future_dcClusterShardInfo = fixedThreadPool.submit(new Callable<DcClusterShardTbl>() {

        @Override
        public DcClusterShardTbl call() throws DalException {
            return dcClusterShardService.find(dcName, clusterName, shardName);
        }
    });
    try {
        if (null == future_dcInfo.get() || null == future_clusterInfo.get() || null == future_shardInfo.get() || null == future_dcClusterInfo.get() || null == future_dcClusterShardInfo.get()) {
            return new ShardMeta().setId(shardName);
        }
        return getShardMeta(future_dcInfo.get(), future_clusterInfo.get(), future_shardInfo.get(), future_dcClusterInfo.get(), future_dcClusterShardInfo.get());
    } catch (ExecutionException e) {
        throw new DataNotFoundException("Cannot construct shard-meta", e);
    } catch (InterruptedException e) {
        throw new ServerException("Concurrent execution failed.", e);
    } finally {
        fixedThreadPool.shutdown();
    }
}
Also used : DataNotFoundException(com.ctrip.xpipe.redis.console.exception.DataNotFoundException) ServerException(com.ctrip.xpipe.redis.console.exception.ServerException) DalException(org.unidal.dal.jdbc.DalException) ShardMeta(com.ctrip.xpipe.redis.core.entity.ShardMeta)

Aggregations

ServerException (com.ctrip.xpipe.redis.console.exception.ServerException)18 PostConstruct (javax.annotation.PostConstruct)7 ComponentLookupException (org.codehaus.plexus.component.repository.exception.ComponentLookupException)7 DalException (org.unidal.dal.jdbc.DalException)7 DataNotFoundException (com.ctrip.xpipe.redis.console.exception.DataNotFoundException)4 BadRequestException (com.ctrip.xpipe.redis.console.exception.BadRequestException)3 List (java.util.List)3 LinkedList (java.util.LinkedList)2 XpipeRuntimeException (com.ctrip.xpipe.exception.XpipeRuntimeException)1 DalTransaction (com.ctrip.xpipe.redis.console.annotation.DalTransaction)1 ClusterEvent (com.ctrip.xpipe.redis.console.notifier.cluster.ClusterEvent)1 ShardEvent (com.ctrip.xpipe.redis.console.notifier.shard.ShardEvent)1 DcMetaQueryVO (com.ctrip.xpipe.redis.console.service.vo.DcMetaQueryVO)1 ClusterMeta (com.ctrip.xpipe.redis.core.entity.ClusterMeta)1 DcMeta (com.ctrip.xpipe.redis.core.entity.DcMeta)1 ShardMeta (com.ctrip.xpipe.redis.core.entity.ShardMeta)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 Type (java.lang.reflect.Type)1 HashMap (java.util.HashMap)1 TimeoutException (java.util.concurrent.TimeoutException)1