Search in sources :

Example 11 with DalException

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

the class MigrationClusterDao method updateStatusAndEndTimeById.

public void updateStatusAndEndTimeById(long id, MigrationStatus status, Date endTime) {
    MigrationClusterTbl migrationClusterTbl = new MigrationClusterTbl();
    migrationClusterTbl.setId(id);
    migrationClusterTbl.setEndTime(endTime);
    migrationClusterTbl.setStatus(status.toString());
    queryHandler.handleUpdate(new DalQuery<Integer>() {

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

Example 12 with DalException

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

the class ClusterServiceImpl method balanceCluster.

// Add transaction for one cluster update, rollback if one 'DcClusterShard' update fails
@VisibleForTesting
@DalTransaction
protected void balanceCluster(Map<String, List<SetinelTbl>> dcToSentinels, final String cluster) {
    for (String dcName : dcToSentinels.keySet()) {
        List<DcClusterShardTbl> dcClusterShards = dcClusterShardService.findAllByDcCluster(dcName, cluster);
        List<SetinelTbl> sentinels = dcToSentinels.get(dcName);
        if (dcClusterShards == null || sentinels == null) {
            throw new XpipeRuntimeException("DcClusterShard | Sentinels should not be null");
        }
        long randomlySelectedSentinelId = randomlyChoseSentinels(sentinels);
        dcClusterShards.forEach(dcClusterShard -> {
            dcClusterShard.setSetinelId(randomlySelectedSentinelId);
            try {
                dcClusterShardService.updateDcClusterShard(dcClusterShard);
            } catch (DalException e) {
                throw new XpipeRuntimeException(e.getMessage());
            }
        });
    }
}
Also used : DalException(org.unidal.dal.jdbc.DalException) XpipeRuntimeException(com.ctrip.xpipe.exception.XpipeRuntimeException) VisibleForTesting(com.ctrip.xpipe.utils.VisibleForTesting) DalTransaction(com.ctrip.xpipe.redis.console.annotation.DalTransaction)

Example 13 with DalException

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

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

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

the class DcClusterDao method deleteDcClustersBatch.

@DalTransaction
public void deleteDcClustersBatch(final DcClusterTbl dcCluster) throws DalException {
    if (null == dcCluster)
        throw new DalException("Null cannot be deleted.");
    List<DcClusterShardTbl> dcClusterShards = queryHandler.handleQuery(new DalQuery<List<DcClusterShardTbl>>() {

        @Override
        public List<DcClusterShardTbl> doQuery() throws DalException {
            return dcClusterShardTblDao.findAllByDcClusterId(dcCluster.getDcClusterId(), DcClusterShardTblEntity.READSET_FULL);
        }
    });
    if (null != dcClusterShards) {
        dcClusterShardDao.deleteDcClusterShardsBatch(dcClusterShards);
    }
    queryHandler.handleDelete(new DalQuery<Integer>() {

        @Override
        public Integer doQuery() throws DalException {
            return dcClusterTblDao.deleteBatch(dcCluster, DcClusterTblEntity.UPDATESET_FULL);
        }
    }, true);
}
Also used : DalException(org.unidal.dal.jdbc.DalException) List(java.util.List) LinkedList(java.util.LinkedList) DalTransaction(com.ctrip.xpipe.redis.console.annotation.DalTransaction)

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