Search in sources :

Example 6 with DalException

use of org.unidal.dal.jdbc.DalException 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 DalException

use of org.unidal.dal.jdbc.DalException in project x-pipe by ctripcorp.

the class ClusterServiceImpl method unbindDc.

@Override
public void unbindDc(String clusterName, String dcName) {
    final ClusterTbl cluster = find(clusterName);
    final DcTbl dc = dcService.find(dcName);
    if (null == dc || null == cluster)
        throw new BadRequestException("Cannot unbind dc due to unknown dc or cluster");
    queryHandler.handleQuery(new DalQuery<Integer>() {

        @Override
        public Integer doQuery() throws DalException {
            return clusterDao.unbindDc(cluster, dc);
        }
    });
    /**
     * Notify meta server *
     */
    notifier.notifyClusterDelete(clusterName, Arrays.asList(new DcTbl[] { dc }));
}
Also used : DalException(org.unidal.dal.jdbc.DalException) BadRequestException(com.ctrip.xpipe.redis.console.exception.BadRequestException)

Example 8 with DalException

use of org.unidal.dal.jdbc.DalException in project x-pipe by ctripcorp.

the class ClusterServiceImpl method bindDc.

@Override
public void bindDc(String clusterName, String dcName) {
    final ClusterTbl cluster = find(clusterName);
    final DcTbl dc = dcService.find(dcName);
    if (null == dc || null == cluster)
        throw new BadRequestException("Cannot bind dc due to unknown dc or cluster");
    queryHandler.handleQuery(new DalQuery<Integer>() {

        @Override
        public Integer doQuery() throws DalException {
            return clusterDao.bindDc(cluster, dc);
        }
    });
}
Also used : DalException(org.unidal.dal.jdbc.DalException) BadRequestException(com.ctrip.xpipe.redis.console.exception.BadRequestException)

Example 9 with DalException

use of org.unidal.dal.jdbc.DalException in project x-pipe by ctripcorp.

the class ClusterDao method createCluster.

@DalTransaction
public ClusterTbl createCluster(final ClusterTbl cluster) throws DalException {
    // check for unique cluster name
    ClusterTbl clusterWithSameName = queryHandler.handleQuery(new DalQuery<ClusterTbl>() {

        @Override
        public ClusterTbl doQuery() throws DalException {
            return clusterTblDao.findClusterByClusterName(cluster.getClusterName(), ClusterTblEntity.READSET_FULL);
        }
    });
    if (null != clusterWithSameName)
        throw new BadRequestException("Duplicated cluster name");
    cluster.setCreateTime(new Date());
    // cluster meta
    queryHandler.handleInsert(new DalQuery<Integer>() {

        @Override
        public Integer doQuery() throws DalException {
            return clusterTblDao.insert(cluster);
        }
    });
    // related dc-cluster
    ClusterTbl newCluster = clusterTblDao.findClusterByClusterName(cluster.getClusterName(), ClusterTblEntity.READSET_FULL);
    DcTbl activeDc = dcTblDao.findByPK(cluster.getActivedcId(), DcTblEntity.READSET_FULL);
    DcClusterTbl protoDcCluster = dcClusterTblDao.createLocal();
    protoDcCluster.setDcId(activeDc.getId()).setClusterId(newCluster.getId());
    queryHandler.handleInsert(new DalQuery<Integer>() {

        @Override
        public Integer doQuery() throws DalException {
            return dcClusterTblDao.insert(protoDcCluster);
        }
    });
    return newCluster;
}
Also used : DalException(org.unidal.dal.jdbc.DalException) BadRequestException(com.ctrip.xpipe.redis.console.exception.BadRequestException) Date(java.util.Date) DalTransaction(com.ctrip.xpipe.redis.console.annotation.DalTransaction)

Example 10 with DalException

use of org.unidal.dal.jdbc.DalException in project x-pipe by ctripcorp.

the class MigrationClusterDao method updatePublishInfoById.

public void updatePublishInfoById(long id, String publishInfo) {
    MigrationClusterTbl migrationClusterTbl = new MigrationClusterTbl();
    migrationClusterTbl.setId(id);
    migrationClusterTbl.setPublishInfo(publishInfo);
    queryHandler.handleUpdate(new DalQuery<Integer>() {

        @Override
        public Integer doQuery() throws DalException {
            return migrationClusterTblDao.updatePublishInfoById(migrationClusterTbl, MigrationClusterTblEntity.UPDATESET_FULL);
        }
    });
}
Also used : MigrationClusterTbl(com.ctrip.xpipe.redis.console.model.MigrationClusterTbl) DalException(org.unidal.dal.jdbc.DalException)

Aggregations

DalException (org.unidal.dal.jdbc.DalException)20 BadRequestException (com.ctrip.xpipe.redis.console.exception.BadRequestException)6 ServerException (com.ctrip.xpipe.redis.console.exception.ServerException)6 DalTransaction (com.ctrip.xpipe.redis.console.annotation.DalTransaction)5 LinkedList (java.util.LinkedList)5 List (java.util.List)4 MigrationClusterTbl (com.ctrip.xpipe.redis.console.model.MigrationClusterTbl)3 DataNotFoundException (com.ctrip.xpipe.redis.console.exception.DataNotFoundException)2 ConfigTbl (com.ctrip.xpipe.redis.console.model.ConfigTbl)2 XpipeRuntimeException (com.ctrip.xpipe.exception.XpipeRuntimeException)1 ConfigModel (com.ctrip.xpipe.redis.console.model.ConfigModel)1 DcClusterShardTbl (com.ctrip.xpipe.redis.console.model.DcClusterShardTbl)1 MigrationShardTbl (com.ctrip.xpipe.redis.console.model.MigrationShardTbl)1 RedisTbl (com.ctrip.xpipe.redis.console.model.RedisTbl)1 ShardEvent (com.ctrip.xpipe.redis.console.notifier.shard.ShardEvent)1 DcMetaQueryVO (com.ctrip.xpipe.redis.console.service.vo.DcMetaQueryVO)1 DcMeta (com.ctrip.xpipe.redis.core.entity.DcMeta)1 ShardMeta (com.ctrip.xpipe.redis.core.entity.ShardMeta)1 VisibleForTesting (com.ctrip.xpipe.utils.VisibleForTesting)1 Date (java.util.Date)1