use of org.unidal.dal.jdbc.DalException in project x-pipe by ctripcorp.
the class MigrationClusterDao method updateStatusAndEndTimeById.
public void updateStatusAndEndTimeById(long id, MigrationStatus status, Date endTime) {
MigrationClusterTbl migrationClusterTbl = new MigrationClusterTbl();
migrationClusterTbl.setId(id);
migrationClusterTbl.setEndTime(endTime);
migrationClusterTbl.setStatus(status.toString());
queryHandler.handleUpdate(new DalQuery<Integer>() {
@Override
public Integer doQuery() throws DalException {
return migrationClusterTblDao.updateStatusAndEndTimeById(migrationClusterTbl, MigrationClusterTblEntity.UPDATESET_FULL);
}
});
}
use of org.unidal.dal.jdbc.DalException in project x-pipe by ctripcorp.
the class ClusterServiceImpl method balanceCluster.
// Add transaction for one cluster update, rollback if one 'DcClusterShard' update fails
@VisibleForTesting
@DalTransaction
protected void balanceCluster(Map<String, List<SetinelTbl>> dcToSentinels, final String cluster) {
for (String dcName : dcToSentinels.keySet()) {
List<DcClusterShardTbl> dcClusterShards = dcClusterShardService.findAllByDcCluster(dcName, cluster);
List<SetinelTbl> sentinels = dcToSentinels.get(dcName);
if (dcClusterShards == null || sentinels == null) {
throw new XpipeRuntimeException("DcClusterShard | Sentinels should not be null");
}
long randomlySelectedSentinelId = randomlyChoseSentinels(sentinels);
dcClusterShards.forEach(dcClusterShard -> {
dcClusterShard.setSetinelId(randomlySelectedSentinelId);
try {
dcClusterShardService.updateDcClusterShard(dcClusterShard);
} catch (DalException e) {
throw new XpipeRuntimeException(e.getMessage());
}
});
}
}
use of org.unidal.dal.jdbc.DalException 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 org.unidal.dal.jdbc.DalException 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 org.unidal.dal.jdbc.DalException in project x-pipe by ctripcorp.
the class DcClusterDao method deleteDcClustersBatch.
@DalTransaction
public void deleteDcClustersBatch(final DcClusterTbl dcCluster) throws DalException {
if (null == dcCluster)
throw new DalException("Null cannot be deleted.");
List<DcClusterShardTbl> dcClusterShards = queryHandler.handleQuery(new DalQuery<List<DcClusterShardTbl>>() {
@Override
public List<DcClusterShardTbl> doQuery() throws DalException {
return dcClusterShardTblDao.findAllByDcClusterId(dcCluster.getDcClusterId(), DcClusterShardTblEntity.READSET_FULL);
}
});
if (null != dcClusterShards) {
dcClusterShardDao.deleteDcClusterShardsBatch(dcClusterShards);
}
queryHandler.handleDelete(new DalQuery<Integer>() {
@Override
public Integer doQuery() throws DalException {
return dcClusterTblDao.deleteBatch(dcCluster, DcClusterTblEntity.UPDATESET_FULL);
}
}, true);
}
Aggregations