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);
}
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);
}
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;
}
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);
}
});
}
Aggregations