use of com.ctrip.xpipe.redis.console.exception.BadRequestException in project x-pipe by ctripcorp.
the class MigrationEventDao method loadMigrationEvent.
private MigrationEvent loadMigrationEvent(List<MigrationEventTbl> details) {
if (!CollectionUtils.isEmpty(details)) {
MigrationEvent event = new DefaultMigrationEvent(details.get(0));
for (MigrationEventTbl detail : details) {
MigrationClusterTbl cluster = detail.getRedundantClusters();
MigrationShardTbl shard = detail.getRedundantShards();
if (null == event.getMigrationCluster(cluster.getClusterId())) {
event.addMigrationCluster(new DefaultMigrationCluster(executors, scheduled, event, detail.getRedundantClusters(), dcService, clusterService, shardService, redisService, migrationService));
}
MigrationCluster migrationCluster = event.getMigrationCluster(cluster.getClusterId());
migrationCluster.addNewMigrationShard(new DefaultMigrationShard(migrationCluster, shard, migrationCluster.getClusterShards().get(shard.getShardId()), migrationCluster.getClusterDcs(), migrationService));
}
return event;
}
throw new BadRequestException("Cannot load migration event from null.");
}
use of com.ctrip.xpipe.redis.console.exception.BadRequestException in project x-pipe by ctripcorp.
the class ClusterServiceImpl method deleteCluster.
@Override
public void deleteCluster(String clusterName) {
ClusterTbl proto = find(clusterName);
if (null == proto)
throw new BadRequestException("Cannot find cluster");
proto.setClusterLastModifiedTime(DataModifiedTimeGenerator.generateModifiedTime());
List<DcTbl> relatedDcs = dcService.findClusterRelatedDc(clusterName);
final ClusterTbl queryProto = proto;
// Call cluster delete event
ClusterEvent clusterEvent = clusterDeleteEventFactory.createClusterEvent(clusterName);
try {
clusterDao.deleteCluster(queryProto);
} catch (Exception e) {
throw new ServerException(e.getMessage());
}
clusterEvent.onEvent();
/**
* Notify meta server *
*/
notifier.notifyClusterDelete(clusterName, relatedDcs);
}
use of com.ctrip.xpipe.redis.console.exception.BadRequestException 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 }));
}
use of com.ctrip.xpipe.redis.console.exception.BadRequestException 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);
}
});
}
use of com.ctrip.xpipe.redis.console.exception.BadRequestException 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;
}
Aggregations