use of org.unidal.dal.jdbc.DalException in project x-pipe by ctripcorp.
the class ConfigDao method setConfig.
public void setConfig(ConfigModel config, Date until) throws DalException {
logger.info("[setConfig] {}: {}", config, until);
boolean insert = false;
try {
getKey(config.getKey());
} catch (DalException e) {
logger.info("[setKey][not exist, create]{}", e.getMessage());
insert = true;
}
ConfigTbl configTbl = new ConfigTbl();
configTbl.setKey(config.getKey());
configTbl.setValue(config.getVal());
if (config.getUpdateIP() != null) {
configTbl.setLatestUpdateIp(config.getUpdateIP());
}
if (config.getUpdateUser() != null) {
configTbl.setLatestUpdateUser(config.getUpdateUser());
}
if (until != null) {
configTbl.setUntil(until);
}
if (!insert) {
queryHandler.handleUpdate(new DalQuery<Integer>() {
@Override
public Integer doQuery() throws DalException {
return configTblDao.updateValAndUntilByKey(configTbl, ConfigTblEntity.UPDATESET_FULL);
}
});
} else {
configTbl.setDesc("insert automatically");
queryHandler.handleInsert(new DalQuery<Integer>() {
@Override
public Integer doQuery() throws DalException {
return configTblDao.insert(configTbl);
}
});
}
logger.info("[setConfig] config update successfully, as {}", config.toString());
}
use of org.unidal.dal.jdbc.DalException in project x-pipe by ctripcorp.
the class DcClusterShardDao method deleteDcClusterShardsBatch.
@DalTransaction
public void deleteDcClusterShardsBatch(List<DcClusterShardTbl> dcClusterShards) throws DalException {
if (null == dcClusterShards || dcClusterShards.isEmpty()) {
logger.warn("[deleteDcClusterShardsBatch] Empty list: {}", dcClusterShards);
return;
}
List<RedisTbl> redises = new LinkedList<RedisTbl>();
for (final DcClusterShardTbl dcClusterShard : dcClusterShards) {
List<RedisTbl> relatedRedises = redisDao.findAllByDcClusterShard(dcClusterShard.getDcClusterShardId());
if (null != relatedRedises && !relatedRedises.isEmpty()) {
for (RedisTbl redis : relatedRedises) {
redis.setRunId(generateDeletedName(redis.getRunId()));
}
redises.addAll(relatedRedises);
}
}
redisDao.deleteRedisesBatch(redises);
queryHandler.handleBatchDelete(new DalQuery<int[]>() {
@Override
public int[] doQuery() throws DalException {
return dcClusterShardTblDao.deleteDcClusterShardsBatch(dcClusterShards.toArray(new DcClusterShardTbl[dcClusterShards.size()]), DcClusterShardTblEntity.UPDATESET_FULL);
}
}, true);
}
use of org.unidal.dal.jdbc.DalException in project x-pipe by ctripcorp.
the class ConfigServiceImpl method getConfig.
@Override
public ConfigModel getConfig(String key) {
try {
ConfigTbl configTbl = configDao.getByKey(key);
ConfigModel config = new ConfigModel();
config.setKey(key);
config.setVal(configTbl.getValue());
config.setUpdateIP(configTbl.getLatestUpdateIp());
config.setUpdateUser(configTbl.getLatestUpdateUser());
return config;
} catch (DalException e) {
logger.error("[getConfig] {}", e);
return null;
}
}
use of org.unidal.dal.jdbc.DalException in project x-pipe by ctripcorp.
the class DcMetaServiceImpl method getDcMeta.
@Override
public DcMeta getDcMeta(final String dcName) {
ExecutorService fixedThreadPool = Executors.newFixedThreadPool(6);
DcMeta dcMeta = new DcMeta();
dcMeta.setId(dcName);
dcMeta.setLastModifiedTime(DataModifiedTimeGenerator.generateModifiedTime());
Future<DcTbl> future_dcInfo = fixedThreadPool.submit(new Callable<DcTbl>() {
@Override
public DcTbl call() throws Exception {
return dcService.find(dcName);
}
});
Future<List<SetinelTbl>> future_sentinels = fixedThreadPool.submit(new Callable<List<SetinelTbl>>() {
@Override
public List<SetinelTbl> call() throws DalException {
return sentinelService.findAllByDcName(dcName);
}
});
Future<List<KeepercontainerTbl>> future_keepercontainers = fixedThreadPool.submit(new Callable<List<KeepercontainerTbl>>() {
@Override
public List<KeepercontainerTbl> call() throws DalException {
return keepercontainerService.findAllByDcName(dcName);
}
});
Future<HashMap<Long, DcTbl>> future_alldcs = fixedThreadPool.submit(new Callable<HashMap<Long, DcTbl>>() {
@Override
public HashMap<Long, DcTbl> call() throws DalException {
return loadAllDcs();
}
});
Future<HashMap<Long, List<DcClusterTbl>>> future_allDcClusters = fixedThreadPool.submit(new Callable<HashMap<Long, List<DcClusterTbl>>>() {
@Override
public HashMap<Long, List<DcClusterTbl>> call() throws Exception {
return loadAllDcClusters();
}
});
Future<List<DcTbl>> future_allDetails = fixedThreadPool.submit(new Callable<List<DcTbl>>() {
@Override
public List<DcTbl> call() throws Exception {
return dcService.findAllDetails(dcName);
}
});
try {
DcTbl dcInfo = future_dcInfo.get();
if (null == dcInfo)
return dcMeta;
dcMeta.setId(dcInfo.getDcName());
dcMeta.setLastModifiedTime(dcInfo.getDcLastModifiedTime());
if (null != future_sentinels.get()) {
for (SetinelTbl setinel : future_sentinels.get()) {
dcMeta.addSentinel(setinelMetaService.encodeSetinelMeta(setinel, dcMeta));
}
}
if (null != future_keepercontainers.get()) {
for (KeepercontainerTbl keepercontainer : future_keepercontainers.get()) {
dcMeta.addKeeperContainer(keepercontainerMetaService.encodeKeepercontainerMeta(keepercontainer, dcMeta));
}
}
List<DcTbl> allDetails = future_allDetails.get();
if (null != allDetails) {
DcMetaQueryVO dcMetaQueryVO = loadMetaVO(dcInfo, allDetails);
if (null != future_alldcs.get()) {
dcMetaQueryVO.setAllDcs(future_alldcs.get());
}
if (null != future_allDcClusters.get()) {
dcMetaQueryVO.setAllDcClusterMap(future_allDcClusters.get());
}
for (ClusterTbl cluster : dcMetaQueryVO.getClusterInfo().values()) {
dcMeta.addCluster(clusterMetaService.loadClusterMeta(dcMeta, cluster, dcMetaQueryVO));
}
}
} catch (ExecutionException e) {
throw new ServerException("Execution failed.", e);
} catch (InterruptedException e) {
throw new ServerException("Concurrent execution failed.", e);
} finally {
fixedThreadPool.shutdown();
}
return dcMeta;
}
use of org.unidal.dal.jdbc.DalException in project x-pipe by ctripcorp.
the class ShardMetaServiceImpl method getShardMeta.
@Override
public ShardMeta getShardMeta(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 DalException {
return dcService.find(dcName);
}
});
Future<ClusterTbl> future_clusterInfo = fixedThreadPool.submit(new Callable<ClusterTbl>() {
@Override
public ClusterTbl call() throws DalException {
return clusterService.find(clusterName);
}
});
Future<ShardTbl> future_shardInfo = fixedThreadPool.submit(new Callable<ShardTbl>() {
@Override
public ShardTbl call() throws DalException {
return shardService.find(clusterName, shardName);
}
});
Future<DcClusterTbl> future_dcClusterInfo = fixedThreadPool.submit(new Callable<DcClusterTbl>() {
@Override
public DcClusterTbl call() throws DalException {
return dcClusterService.find(dcName, clusterName);
}
});
Future<DcClusterShardTbl> future_dcClusterShardInfo = fixedThreadPool.submit(new Callable<DcClusterShardTbl>() {
@Override
public DcClusterShardTbl call() throws DalException {
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()) {
return new ShardMeta().setId(shardName);
}
return getShardMeta(future_dcInfo.get(), future_clusterInfo.get(), future_shardInfo.get(), 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();
}
}
Aggregations