DcMetaBuilder extends AbstractCommand<DcMeta> { public ShardMeta getOrCreateShardMeta(String clusterId, ShardTbl shard, long sentinelId) { ClusterMeta clusterMeta = dcMeta.findCluster(clusterId); if(clusterMeta == null) { throw new IllegalArgumentException(String.format("Cluster: %s not found in dcMeta", clusterId)); } return MapUtils.getOrCreate(clusterMeta.getShards(), shard.getShardName(), new ObjectFactory<ShardMeta>() { @Override public ShardMeta create() { ShardMeta shardMeta = new ShardMeta(shard.getShardName()); shardMeta.setParent(clusterMeta); shardMeta.setSentinelMonitorName(SentinelUtil.getSentinelMonitorName(clusterId, shard.getSetinelMonitorName(), dcMeta.getId())); shardMeta.setSentinelId(sentinelId); return shardMeta; } }); } DcMetaBuilder(DcMeta dcMeta, long dcId, Set<String> clusterTypes, ExecutorService executors, RedisMetaService redisMetaService, DcClusterService dcClusterService,
                         ClusterMetaService clusterMetaService, DcClusterShardService dcClusterShardService, DcService dcService, RetryCommandFactory factory); @Override String getName(); @VisibleForTesting ClusterMeta getOrCreateClusterMeta(ClusterTbl cluster); ShardMeta getOrCreateShardMeta(String clusterId, ShardTbl shard, long sentinelId); DcMetaBuilder setDcNameMap(Map<Long, String> dcNameMap); DcMetaBuilder setCluster2DcClusterMap(Map<Long, List<DcClusterTbl>> cluster2DcClusterMap); DcMetaBuilder setDcClusterShards(List<DcClusterShardTbl> dcClusterShards);  }
@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); }