Search in sources :

Example 11 with DcMeta

use of com.ctrip.xpipe.redis.core.entity.DcMeta 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;
}
Also used : DcMetaQueryVO(com.ctrip.xpipe.redis.console.service.vo.DcMetaQueryVO) HashMap(java.util.HashMap) List(java.util.List) LinkedList(java.util.LinkedList) ServerException(com.ctrip.xpipe.redis.console.exception.ServerException) DcMeta(com.ctrip.xpipe.redis.core.entity.DcMeta) ServerException(com.ctrip.xpipe.redis.console.exception.ServerException) DalException(org.unidal.dal.jdbc.DalException) DalException(org.unidal.dal.jdbc.DalException)

Example 12 with DcMeta

use of com.ctrip.xpipe.redis.core.entity.DcMeta in project x-pipe by ctripcorp.

the class MetaCloneTest method testClone.

@Test
public void testClone() {
    XpipeMeta xpipeMeta = getXpipeMeta();
    DcMeta dcMeta = xpipeMeta.getDcs().values().iterator().next();
    DcMeta clone = MetaClone.clone(dcMeta);
    Assert.assertEquals(dcMeta, clone);
    clone.setId(randomString());
    Assert.assertNotEquals(dcMeta, clone);
}
Also used : XpipeMeta(com.ctrip.xpipe.redis.core.entity.XpipeMeta) DcMeta(com.ctrip.xpipe.redis.core.entity.DcMeta) AbstractRedisTest(com.ctrip.xpipe.redis.core.AbstractRedisTest) Test(org.junit.Test)

Example 13 with DcMeta

use of com.ctrip.xpipe.redis.core.entity.DcMeta in project x-pipe by ctripcorp.

the class DemoStarter method startMetaServer1.

// ///////////////////////////////////////DC1/////////////////////////////////////////
@Test
public void startMetaServer1() throws Exception {
    DcMeta dcMeta = getDcMeta(getAndSetDc(1));
    startZkServer(dcMeta.getZkServer());
    startMetaServers(dcMeta);
}
Also used : DcMeta(com.ctrip.xpipe.redis.core.entity.DcMeta) Test(org.junit.Test) AbstractMultiDcTest(com.ctrip.xpipe.redis.integratedtest.full.multidc.AbstractMultiDcTest)

Example 14 with DcMeta

use of com.ctrip.xpipe.redis.core.entity.DcMeta in project x-pipe by ctripcorp.

the class DcMetaTest method test.

@Test
public void test() {
    DcMeta dcMeta = getDcMeta("jq");
    Codec codec = new JsonCodec(true);
    String dcMetaStr = codec.encode(dcMeta);
    logger.info("{}", dcMetaStr);
    DcMeta dcMetaDe = codec.decode(dcMetaStr, DcMeta.class);
    logger.info("[test]{}", dcMeta.getClusters().get("cluster1").parent());
    logger.info("[test]{}", dcMetaDe.getClusters().get("cluster1").parent());
}
Also used : Codec(com.ctrip.xpipe.api.codec.Codec) JsonCodec(com.ctrip.xpipe.codec.JsonCodec) JsonCodec(com.ctrip.xpipe.codec.JsonCodec) DcMeta(com.ctrip.xpipe.redis.core.entity.DcMeta) AbstractRedisTest(com.ctrip.xpipe.redis.core.AbstractRedisTest) Test(org.junit.Test)

Example 15 with DcMeta

use of com.ctrip.xpipe.redis.core.entity.DcMeta in project x-pipe by ctripcorp.

the class DefaultDcMetaCacheTest method testChangeDcMetaLog.

@Test
public void testChangeDcMetaLog() {
    // just check exception
    EventMonitor.DEFAULT.logEvent("type", getTestName());
    XpipeMeta xpipeMeta = getXpipeMeta();
    DcMeta dcMeta = (DcMeta) xpipeMeta.getDcs().values().toArray()[0];
    DcMeta future = MetaClone.clone(dcMeta);
    ClusterMeta futureCluster = (ClusterMeta) future.getClusters().values().toArray()[0];
    futureCluster.addShard(new ShardMeta().setId(randomString(5)));
    future.addCluster(new ClusterMeta().setId(randomString(10)));
    dcMetaCache.changeDcMeta(dcMeta, future);
    dcMetaCache.clusterAdded(new ClusterMeta().setId("add_" + randomString(5)));
    dcMetaCache.clusterDeleted("del_" + randomString(5));
}
Also used : XpipeMeta(com.ctrip.xpipe.redis.core.entity.XpipeMeta) ClusterMeta(com.ctrip.xpipe.redis.core.entity.ClusterMeta) DcMeta(com.ctrip.xpipe.redis.core.entity.DcMeta) ShardMeta(com.ctrip.xpipe.redis.core.entity.ShardMeta) Test(org.junit.Test) AbstractMetaServerTest(com.ctrip.xpipe.redis.meta.server.AbstractMetaServerTest)

Aggregations

DcMeta (com.ctrip.xpipe.redis.core.entity.DcMeta)31 Test (org.junit.Test)19 DirtiesContext (org.springframework.test.annotation.DirtiesContext)7 AbstractMigrationTest (com.ctrip.xpipe.redis.console.migration.AbstractMigrationTest)6 ClusterTbl (com.ctrip.xpipe.redis.console.model.ClusterTbl)5 ClusterMeta (com.ctrip.xpipe.redis.core.entity.ClusterMeta)5 XpipeMeta (com.ctrip.xpipe.redis.core.entity.XpipeMeta)5 AbstractMultiDcTest (com.ctrip.xpipe.redis.integratedtest.full.multidc.AbstractMultiDcTest)5 MigrationClusterTbl (com.ctrip.xpipe.redis.console.model.MigrationClusterTbl)4 AbstractRedisTest (com.ctrip.xpipe.redis.core.AbstractRedisTest)4 ShardMeta (com.ctrip.xpipe.redis.core.entity.ShardMeta)4 LinkedList (java.util.LinkedList)4 RedisMeta (com.ctrip.xpipe.redis.core.entity.RedisMeta)3 HostPort (com.ctrip.xpipe.endpoint.HostPort)2 LeaderElectorManager (com.ctrip.xpipe.api.cluster.LeaderElectorManager)1 Codec (com.ctrip.xpipe.api.codec.Codec)1 JsonCodec (com.ctrip.xpipe.codec.JsonCodec)1 ParallelCommandChain (com.ctrip.xpipe.command.ParallelCommandChain)1 AbstractConsoleIntegrationTest (com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest)1 ServerException (com.ctrip.xpipe.redis.console.exception.ServerException)1