use of com.ctrip.xpipe.redis.console.exception.ServerException in project x-pipe by ctripcorp.
the class ShardMetaServiceImpl method getShardMeta.
@Override
public ShardMeta getShardMeta(final DcTbl dcInfo, final ClusterTbl clusterInfo, final ShardTbl shardInfo) {
ExecutorService fixedThreadPool = Executors.newFixedThreadPool(2);
Future<DcClusterTbl> future_dcClusterInfo = fixedThreadPool.submit(new Callable<DcClusterTbl>() {
@Override
public DcClusterTbl call() throws DalException {
return dcClusterService.find(dcInfo.getDcName(), clusterInfo.getClusterName());
}
});
Future<DcClusterShardTbl> future_dcClusterShardInfo = fixedThreadPool.submit(new Callable<DcClusterShardTbl>() {
@Override
public DcClusterShardTbl call() throws DalException {
return dcClusterShardService.find(dcInfo.getDcName(), clusterInfo.getClusterName(), shardInfo.getShardName());
}
});
try {
return getShardMeta(dcInfo, clusterInfo, shardInfo, future_dcClusterInfo.get(), future_dcClusterShardInfo.get());
} catch (ExecutionException e) {
throw new DataNotFoundException("Cannot construct shard-meta", e);
} catch (InterruptedException e) {
throw new ServerException("Concurrent execution failed.", e);
} finally {
fixedThreadPool.shutdown();
}
}
use of com.ctrip.xpipe.redis.console.exception.ServerException 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.ServerException 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.ServerException 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);
}
}
}
use of com.ctrip.xpipe.redis.console.exception.ServerException in project x-pipe by ctripcorp.
the class ShardModelServiceImpl method getShardModel.
@Override
public ShardModel getShardModel(final String dcName, final String clusterName, final String shardName) {
ExecutorService fixedThreadPool = Executors.newFixedThreadPool(5);
Future<DcTbl> future_dcInfo = fixedThreadPool.submit(new Callable<DcTbl>() {
@Override
public DcTbl call() throws Exception {
return dcService.find(dcName);
}
});
Future<ClusterTbl> future_clusterInfo = fixedThreadPool.submit(new Callable<ClusterTbl>() {
@Override
public ClusterTbl call() throws Exception {
return clusterService.find(clusterName);
}
});
Future<ShardTbl> future_shardInfo = fixedThreadPool.submit(new Callable<ShardTbl>() {
@Override
public ShardTbl call() throws Exception {
return shardService.find(clusterName, shardName);
}
});
Future<DcClusterTbl> future_dcClusterInfo = fixedThreadPool.submit(new Callable<DcClusterTbl>() {
@Override
public DcClusterTbl call() throws Exception {
return dcClusterService.find(dcName, clusterName);
}
});
Future<DcClusterShardTbl> future_dcClusterShardInfo = fixedThreadPool.submit(new Callable<DcClusterShardTbl>() {
@Override
public DcClusterShardTbl call() throws Exception {
return dcClusterShardService.find(dcName, clusterName, shardName);
}
});
try {
if (null == future_dcInfo.get() || null == future_clusterInfo.get() || null == future_shardInfo.get() || null == future_dcClusterInfo.get() || null == future_dcClusterShardInfo.get()) {
ShardModel res = new ShardModel();
res.setShardTbl((new ShardTbl()).setShardName(shardName));
return res;
}
return getShardModel(future_dcInfo.get(), future_clusterInfo.get(), future_shardInfo.get(), future_dcClusterInfo.get(), future_dcClusterShardInfo.get());
} catch (ExecutionException e) {
throw new DataNotFoundException("Cannot construct shard-model", e);
} catch (InterruptedException e) {
throw new ServerException("Concurrent execution failed.", e);
} finally {
fixedThreadPool.shutdown();
}
}
Aggregations