Search in sources :

Example 1 with DataNotFoundException

use of com.ctrip.xpipe.redis.console.exception.DataNotFoundException 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 2 with DataNotFoundException

use of com.ctrip.xpipe.redis.console.exception.DataNotFoundException 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)

Example 3 with DataNotFoundException

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

the class ShardMetaServiceImpl method getShardMeta.

@Override
public ShardMeta getShardMeta(final DcTbl dcInfo, final ClusterTbl clusterInfo, final ShardTbl shardInfo) {
    ExecutorService fixedThreadPool = Executors.newFixedThreadPool(2);
    Future<DcClusterTbl> future_dcClusterInfo = fixedThreadPool.submit(new Callable<DcClusterTbl>() {

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

        @Override
        public DcClusterShardTbl call() throws DalException {
            return dcClusterShardService.find(dcInfo.getDcName(), clusterInfo.getClusterName(), shardInfo.getShardName());
        }
    });
    try {
        return getShardMeta(dcInfo, clusterInfo, shardInfo, 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)

Example 4 with DataNotFoundException

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

the class ShardModelServiceImpl method getShardModel.

@Override
public ShardModel getShardModel(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 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<ShardTbl> future_shardInfo = fixedThreadPool.submit(new Callable<ShardTbl>() {

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

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

        @Override
        public DcClusterShardTbl call() throws Exception {
            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()) {
            ShardModel res = new ShardModel();
            res.setShardTbl((new ShardTbl()).setShardName(shardName));
            return res;
        }
        return getShardModel(future_dcInfo.get(), future_clusterInfo.get(), future_shardInfo.get(), future_dcClusterInfo.get(), future_dcClusterShardInfo.get());
    } catch (ExecutionException e) {
        throw new DataNotFoundException("Cannot construct shard-model", 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) ServerException(com.ctrip.xpipe.redis.console.exception.ServerException) DataNotFoundException(com.ctrip.xpipe.redis.console.exception.DataNotFoundException)

Aggregations

DataNotFoundException (com.ctrip.xpipe.redis.console.exception.DataNotFoundException)4 ServerException (com.ctrip.xpipe.redis.console.exception.ServerException)4 DalException (org.unidal.dal.jdbc.DalException)2 ClusterMeta (com.ctrip.xpipe.redis.core.entity.ClusterMeta)1 ShardMeta (com.ctrip.xpipe.redis.core.entity.ShardMeta)1 List (java.util.List)1