Search in sources :

Example 1 with DcClusterShardTbl

use of com.ctrip.xpipe.redis.console.model.DcClusterShardTbl 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);
}
Also used : RedisTbl(com.ctrip.xpipe.redis.console.model.RedisTbl) DalException(org.unidal.dal.jdbc.DalException) DcClusterShardTbl(com.ctrip.xpipe.redis.console.model.DcClusterShardTbl) LinkedList(java.util.LinkedList) DalTransaction(com.ctrip.xpipe.redis.console.annotation.DalTransaction)

Example 2 with DcClusterShardTbl

use of com.ctrip.xpipe.redis.console.model.DcClusterShardTbl in project x-pipe by ctripcorp.

the class DcClusterShardServiceImplTest method testUpdateDcClusterShard.

@Test
public void testUpdateDcClusterShard() throws Exception {
    DcClusterShardTbl proto = service.find(dcNames[0], clusterName, shardNames[0]);
    long sentinelId = proto.getSetinelId();
    long expected = sentinelId + 1;
    proto.setSetinelId(expected);
    service.updateDcClusterShard(proto);
    Assert.assertEquals(expected, service.find(dcNames[0], clusterName, shardNames[0]).getSetinelId());
}
Also used : DcClusterShardTbl(com.ctrip.xpipe.redis.console.model.DcClusterShardTbl) Test(org.junit.Test)

Example 3 with DcClusterShardTbl

use of com.ctrip.xpipe.redis.console.model.DcClusterShardTbl in project x-pipe by ctripcorp.

the class DcClusterShardServiceImplTest method testFindAllByDcId.

@Test
public void testFindAllByDcId() throws Exception {
    List<DcClusterShardTbl> dcClusterShards = service.findAllByDcId(1L);
    for (DcClusterShardTbl dcClusterShard : dcClusterShards) {
        Assert.assertEquals(1L, dcClusterShard.getDcClusterInfo().getDcId());
        Assert.assertNotEquals(0, dcClusterShard.getShardId());
        Assert.assertNotNull(dcClusterShard.getRedisInfo());
    }
    logger.info("{}", dcClusterShards);
}
Also used : DcClusterShardTbl(com.ctrip.xpipe.redis.console.model.DcClusterShardTbl) Test(org.junit.Test)

Example 4 with DcClusterShardTbl

use of com.ctrip.xpipe.redis.console.model.DcClusterShardTbl in project x-pipe by ctripcorp.

the class DcMetaBuilderTest method getOrCreateShardMeta.

@Test
public void getOrCreateShardMeta() throws Exception {
    DcClusterShardTbl dcClusterShard = dcClusterShards.get(0);
    builder.getOrCreateClusterMeta(dcClusterShards.get(0).getClusterInfo());
    ClusterMeta clusterMeta = dcMeta.getClusters().get(dcClusterShard.getClusterInfo().getClusterName());
    logger.info("{}", dcClusterShard.getShardInfo());
    builder.getOrCreateShardMeta(clusterMeta.getId(), dcClusterShard.getShardInfo(), dcClusterShard.getSetinelId());
    String clusterId = dcClusterShard.getClusterInfo().getClusterName(), shardId = dcClusterShard.getShardInfo().getShardName();
    ShardMeta shardMeta = dcMeta.findCluster(clusterId).findShard(shardId);
    Assert.assertNotNull(shardMeta);
    logger.info("{}", shardMeta);
}
Also used : ClusterMeta(com.ctrip.xpipe.redis.core.entity.ClusterMeta) DcClusterShardTbl(com.ctrip.xpipe.redis.console.model.DcClusterShardTbl) ShardMeta(com.ctrip.xpipe.redis.core.entity.ShardMeta) AbstractConsoleIntegrationTest(com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest) Test(org.junit.Test)

Aggregations

DcClusterShardTbl (com.ctrip.xpipe.redis.console.model.DcClusterShardTbl)4 Test (org.junit.Test)3 AbstractConsoleIntegrationTest (com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest)1 DalTransaction (com.ctrip.xpipe.redis.console.annotation.DalTransaction)1 RedisTbl (com.ctrip.xpipe.redis.console.model.RedisTbl)1 ClusterMeta (com.ctrip.xpipe.redis.core.entity.ClusterMeta)1 ShardMeta (com.ctrip.xpipe.redis.core.entity.ShardMeta)1 LinkedList (java.util.LinkedList)1 DalException (org.unidal.dal.jdbc.DalException)1