Search in sources :

Example 6 with BadRequestException

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

the class ClusterServiceImpl method updateCluster.

@Override
public void updateCluster(String clusterName, ClusterTbl cluster) {
    ClusterTbl proto = find(clusterName);
    if (null == proto)
        throw new BadRequestException("Cannot find cluster");
    if (proto.getId() != cluster.getId()) {
        throw new BadRequestException("Cluster not match.");
    }
    proto.setClusterDescription(cluster.getClusterDescription());
    proto.setClusterLastModifiedTime(DataModifiedTimeGenerator.generateModifiedTime());
    if (!checkEmails(cluster.getClusterAdminEmails())) {
        throw new IllegalArgumentException("Emails should be ctrip emails and separated by comma or semicolon");
    }
    proto.setClusterAdminEmails(cluster.getClusterAdminEmails());
    proto.setClusterOrgId(getOrgIdFromClusterOrgName(cluster));
    // organization info should not be updated by cluster,
    // it's automatically updated by scheduled task
    proto.setOrganizationInfo(null);
    final ClusterTbl queryProto = proto;
    clusterDao.updateCluster(queryProto);
}
Also used : BadRequestException(com.ctrip.xpipe.redis.console.exception.BadRequestException)

Example 7 with BadRequestException

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

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

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

Aggregations

BadRequestException (com.ctrip.xpipe.redis.console.exception.BadRequestException)9 DalException (org.unidal.dal.jdbc.DalException)7 ServerException (com.ctrip.xpipe.redis.console.exception.ServerException)3 XpipeRuntimeException (com.ctrip.xpipe.exception.XpipeRuntimeException)1 DalTransaction (com.ctrip.xpipe.redis.console.annotation.DalTransaction)1 MigrationCluster (com.ctrip.xpipe.redis.console.migration.model.MigrationCluster)1 MigrationEvent (com.ctrip.xpipe.redis.console.migration.model.MigrationEvent)1 DefaultMigrationCluster (com.ctrip.xpipe.redis.console.migration.model.impl.DefaultMigrationCluster)1 DefaultMigrationEvent (com.ctrip.xpipe.redis.console.migration.model.impl.DefaultMigrationEvent)1 DefaultMigrationShard (com.ctrip.xpipe.redis.console.migration.model.impl.DefaultMigrationShard)1 ClusterEvent (com.ctrip.xpipe.redis.console.notifier.cluster.ClusterEvent)1 Date (java.util.Date)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1