use of org.unidal.dal.jdbc.DalException 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 org.unidal.dal.jdbc.DalException 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 org.unidal.dal.jdbc.DalException 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 org.unidal.dal.jdbc.DalException 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;
}
use of org.unidal.dal.jdbc.DalException in project x-pipe by ctripcorp.
the class MigrationClusterDao method updatePublishInfoById.
public void updatePublishInfoById(long id, String publishInfo) {
MigrationClusterTbl migrationClusterTbl = new MigrationClusterTbl();
migrationClusterTbl.setId(id);
migrationClusterTbl.setPublishInfo(publishInfo);
queryHandler.handleUpdate(new DalQuery<Integer>() {
@Override
public Integer doQuery() throws DalException {
return migrationClusterTblDao.updatePublishInfoById(migrationClusterTbl, MigrationClusterTblEntity.UPDATESET_FULL);
}
});
}
Aggregations