Search in sources :

Example 6 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 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 7 with ServerException

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

the class ClusterServiceImpl method deleteCluster.

@Override
public void deleteCluster(String clusterName) {
    ClusterTbl proto = find(clusterName);
    if (null == proto)
        throw new BadRequestException("Cannot find cluster");
    proto.setClusterLastModifiedTime(DataModifiedTimeGenerator.generateModifiedTime());
    List<DcTbl> relatedDcs = dcService.findClusterRelatedDc(clusterName);
    final ClusterTbl queryProto = proto;
    // Call cluster delete event
    ClusterEvent clusterEvent = clusterDeleteEventFactory.createClusterEvent(clusterName);
    try {
        clusterDao.deleteCluster(queryProto);
    } catch (Exception e) {
        throw new ServerException(e.getMessage());
    }
    clusterEvent.onEvent();
    /**
     * Notify meta server *
     */
    notifier.notifyClusterDelete(clusterName, relatedDcs);
}
Also used : ClusterEvent(com.ctrip.xpipe.redis.console.notifier.cluster.ClusterEvent) ServerException(com.ctrip.xpipe.redis.console.exception.ServerException) BadRequestException(com.ctrip.xpipe.redis.console.exception.BadRequestException) ServerException(com.ctrip.xpipe.redis.console.exception.ServerException) XpipeRuntimeException(com.ctrip.xpipe.exception.XpipeRuntimeException) BadRequestException(com.ctrip.xpipe.redis.console.exception.BadRequestException) DalException(org.unidal.dal.jdbc.DalException)

Example 8 with ServerException

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

the class DcClusterServiceImpl method addDcCluster.

@Override
public DcClusterTbl addDcCluster(String dcName, String clusterName) {
    DcTbl dcInfo = dcService.find(dcName);
    ClusterTbl clusterInfo = clusterService.find(clusterName);
    if (null == dcInfo || null == clusterInfo)
        throw new BadRequestException("Cannot add dc-cluster to an unknown dc or cluster");
    DcClusterTbl proto = new DcClusterTbl();
    proto.setDcId(dcInfo.getId());
    proto.setClusterId(clusterInfo.getId());
    proto.setDcClusterPhase(1);
    try {
        dao.insert(proto);
    } catch (DalException e) {
        throw new ServerException("Cannot create dc-cluster.");
    }
    return find(dcName, clusterName);
}
Also used : ServerException(com.ctrip.xpipe.redis.console.exception.ServerException) DalException(org.unidal.dal.jdbc.DalException) BadRequestException(com.ctrip.xpipe.redis.console.exception.BadRequestException)

Example 9 with ServerException

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

the class ShardServiceImpl method deleteShard.

@Override
public void deleteShard(final String clusterName, final String shardName) {
    final ShardTbl shard = queryHandler.handleQuery(new DalQuery<ShardTbl>() {

        @Override
        public ShardTbl doQuery() throws DalException {
            return dao.findShard(clusterName, shardName, ShardTblEntity.READSET_FULL);
        }
    });
    if (null != shard) {
        // Call shard event
        Map<Long, SetinelTbl> sentinels = sentinelService.findByShard(shard.getId());
        ShardEvent shardEvent = createShardDeleteEvent(clusterName, shardName, shard, sentinels);
        try {
            shardDao.deleteShardsBatch(shard);
        } catch (Exception e) {
            throw new ServerException(e.getMessage());
        }
        shardEvent.onEvent();
    }
    /**
     * Notify meta server *
     */
    List<DcTbl> relatedDcs = dcService.findClusterRelatedDc(clusterName);
    if (null != relatedDcs) {
        for (DcTbl dc : relatedDcs) {
            notifier.notifyClusterUpdate(dc.getDcName(), clusterName);
        }
    }
}
Also used : ShardEvent(com.ctrip.xpipe.redis.console.notifier.shard.ShardEvent) ServerException(com.ctrip.xpipe.redis.console.exception.ServerException) DalException(org.unidal.dal.jdbc.DalException) ServerException(com.ctrip.xpipe.redis.console.exception.ServerException) DalException(org.unidal.dal.jdbc.DalException)

Example 10 with ServerException

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

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