Search in sources :

Example 16 with DalException

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

the class MigrationClusterDao method updateStartTime.

public void updateStartTime(long id, Date date) {
    MigrationClusterTbl migrationClusterTbl = new MigrationClusterTbl();
    migrationClusterTbl.setId(id);
    migrationClusterTbl.setStartTime(date);
    queryHandler.handleUpdate(new DalQuery<Integer>() {

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

Example 17 with DalException

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

the class MigrationShardDao method updateMigrationShard.

public void updateMigrationShard(MigrationShardTbl migrationShard) {
    MigrationShardTbl proto = migrationShardDao.createLocal();
    proto.setId(migrationShard.getId()).setMigrationClusterId(migrationShard.getMigrationClusterId()).setShardId(migrationShard.getShardId()).setLog(migrationShard.getLog());
    final MigrationShardTbl forUpdate = proto;
    queryHandler.handleUpdate(new DalQuery<Integer>() {

        @Override
        public Integer doQuery() throws DalException {
            migrationShardDao.updateByPK(forUpdate, MigrationShardTblEntity.UPDATESET_FULL);
            return null;
        }
    });
}
Also used : MigrationShardTbl(com.ctrip.xpipe.redis.console.model.MigrationShardTbl) DalException(org.unidal.dal.jdbc.DalException)

Example 18 with DalException

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

the class RedisDao method generateUniqueKeeperId.

private String generateUniqueKeeperId(final RedisTbl redis) {
    final String runId = idGenerator.generateRunid();
    // check for unique runId
    DcClusterShardTbl targetDcClusterShard = queryHandler.handleQuery(new DalQuery<DcClusterShardTbl>() {

        @Override
        public DcClusterShardTbl doQuery() throws DalException {
            return dcClusterShardTblDao.findByPK(redis.getDcClusterShardId(), DcClusterShardTblEntity.READSET_FULL);
        }
    });
    if (null == targetDcClusterShard)
        throw new BadRequestException("Cannot find related dc-cluster-shard");
    List<RedisTbl> redisWithSameRunId = queryHandler.handleQuery(new DalQuery<List<RedisTbl>>() {

        @Override
        public List<RedisTbl> doQuery() throws DalException {
            return redisTblDao.findByRunid(runId, RedisTblEntity.READSET_FULL);
        }
    });
    if (null != redisWithSameRunId && redisWithSameRunId.size() > 0) {
        for (final RedisTbl tmpRedis : redisWithSameRunId) {
            DcClusterShardTbl tmpDcClusterShard = queryHandler.handleQuery(new DalQuery<DcClusterShardTbl>() {

                @Override
                public DcClusterShardTbl doQuery() throws DalException {
                    return dcClusterShardTblDao.findByPK(tmpRedis.getDcClusterShardId(), DcClusterShardTblEntity.READSET_FULL);
                }
            });
            if (null != tmpDcClusterShard && targetDcClusterShard.getShardId() == tmpDcClusterShard.getShardId()) {
                throw new ServerException("Cannot generate unque keeper id, please retry.");
            }
        }
    }
    return runId;
}
Also used : ServerException(com.ctrip.xpipe.redis.console.exception.ServerException) DalException(org.unidal.dal.jdbc.DalException) BadRequestException(com.ctrip.xpipe.redis.console.exception.BadRequestException) List(java.util.List) LinkedList(java.util.LinkedList)

Example 19 with DalException

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

the class MigrationEventDao method lockCluster.

private void lockCluster(final long clusterId) {
    ClusterTbl cluster = queryHandler.handleQuery(new DalQuery<ClusterTbl>() {

        @Override
        public ClusterTbl doQuery() throws DalException {
            return clusterTblDao.findByPK(clusterId, ClusterTblEntity.READSET_FULL);
        }
    });
    if (null == cluster)
        throw new BadRequestException(String.format("Cluster:%s do not exist!", clusterId));
    if (!cluster.getStatus().toLowerCase().equals(ClusterStatus.Normal.toString().toLowerCase())) {
        throw new BadRequestException(String.format("Cluster:%s already under migrating tasks!Please verify it first!", cluster.getClusterName()));
    } else {
        cluster.setStatus(ClusterStatus.Lock.toString());
    }
    final ClusterTbl proto = cluster;
    queryHandler.handleUpdate(new DalQuery<Integer>() {

        @Override
        public Integer doQuery() throws DalException {
            return clusterTblDao.updateByPK(proto, ClusterTblEntity.UPDATESET_FULL);
        }
    });
}
Also used : DalException(org.unidal.dal.jdbc.DalException) BadRequestException(com.ctrip.xpipe.redis.console.exception.BadRequestException)

Example 20 with DalException

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

the class ShardDao method deleteShardsBatch.

@DalTransaction
public void deleteShardsBatch(final ShardTbl shard) throws DalException {
    if (null == shard)
        throw new DalException("Null cannot be deleted.");
    List<DcClusterShardTbl> relatedDcClusterShards = queryHandler.handleQuery(new DalQuery<List<DcClusterShardTbl>>() {

        @Override
        public List<DcClusterShardTbl> doQuery() throws DalException {
            return dcClusterShardTblDao.findAllByShardId(shard.getId(), DcClusterShardTblEntity.READSET_FULL);
        }
    });
    if (null != relatedDcClusterShards) {
        dcClusterShardDao.deleteDcClusterShardsBatch(relatedDcClusterShards);
    }
    ShardTbl proto = shard;
    proto.setShardName(generateDeletedName(shard.getShardName()));
    queryHandler.handleDelete(new DalQuery<Integer>() {

        @Override
        public Integer doQuery() throws DalException {
            return shardTblDao.deleteShard(proto, ShardTblEntity.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