예제 #1
0
        public SolrCloudState GetClusterStatus(string collection, string shard = null)
        {
            var json = SendRaw(adminHandler, new SolrParams()
                               .AddRequired("wt", "json")
                               .AddRequired("action", "clustertsate")
                               .AddOptional("shard", shard));

            var status = SolrCloudStateParser.Parse(json);

            return(status);
        }
예제 #2
0
        public void ShouldProduceMergedStateFromSeveralJson()
        {
            var internalCollectionsState = SolrCloudStateParser.Parse(InternalCollectionsState);
            var external1State           = SolrCloudStateParser.Parse(FirstExternalCollectionState);
            var external2State           = SolrCloudStateParser.Parse(SecondExternalCollectionState);

            var totalCollectionsCount = internalCollectionsState.Collections.Count + external1State.Collections.Count + external2State.Collections.Count;
            var zkState = internalCollectionsState.Merge(external1State).Merge(external2State);

            Assert.Equal(zkState.Collections.Count, totalCollectionsCount);
        }
예제 #3
0
 private void Update()
 {
     if (zooKeeper == null)
     {
         zooKeeper = new ZooKeeper(
             zooKeeperConnection,
             TimeSpan.FromSeconds(10), this);
     }
     state = SolrCloudStateParser.Parse(
         Encoding.Default.GetString(
             zooKeeper.GetData("/clusterstate.json", true, null)));
 }
예제 #4
0
        public void ShouldProduceNotEmptyStateFromNotEmptyJson()
        {
            var collections = SolrCloudStateParser.Parse(NotEmptyJson).Collections.Values;

            Assert.True(collections.Any());
            var shards = collections.SelectMany(collection => collection.Shards.Values).ToList();

            Assert.True(shards.Any());
            Assert.True(shards.Any(shard => shard.IsActive));
            var replicas = shards.SelectMany(shard => shard.Replicas.Values).ToList();

            Assert.True(replicas.Any());
            Assert.True(replicas.Any(replica => replica.IsActive));
            Assert.True(replicas.Any(replica => replica.IsLeader));
        }
        /// <summary>
        /// Returns parsed external collections cloud state
        /// </summary>
        private async Task <SolrCloudState> GetExternalCollectionsStateAsync()
        {
            var            resultState = new SolrCloudState(new Dictionary <string, SolrCloudCollection>());
            ChildrenResult children;

            try
            {
                children = await zooKeeper.getChildrenAsync(CollectionsZkNode, true).ConfigureAwait(false);
            }
            catch (KeeperException ex)
            {
                return(resultState);
            }

            if (children == null || !children.Children.Any())
            {
                return(resultState);
            }

            foreach (var child in children.Children)
            {
                DataResult data;

                try
                {
                    data = await zooKeeper.getDataAsync(GetCollectionPath(child), true).ConfigureAwait(false);
                }
                catch (KeeperException ex)
                {
                    data = null;
                }

                var collectionState =
                    data != null
                    ? SolrCloudStateParser.Parse(Encoding.Default.GetString(data.Data))
                    : new SolrCloudState(new Dictionary <string, SolrCloudCollection>());

                resultState = resultState.Merge(collectionState);
            }

            return(resultState);
        }
        /// <summary>
        /// Returns parsed internal collections cloud state
        /// </summary>
        private async Task <SolrCloudState> GetInternalCollectionsStateAsync()
        {
            DataResult data;

            try
            {
                data = await zooKeeper.getDataAsync(ClusterState, true).ConfigureAwait(false);
            }
            catch (KeeperException ex)
            {
                return(new SolrCloudState(new Dictionary <string, SolrCloudCollection>()));
            }

            var collectionsState =
                data != null
                ? SolrCloudStateParser.Parse(Encoding.Default.GetString(data.Data))
                : new SolrCloudState(new Dictionary <string, SolrCloudCollection>());

            return(collectionsState);
        }
예제 #7
0
        public void ShouldProduceEmptyStateFromEmptyJson()
        {
            var state = SolrCloudStateParser.Parse(EmptyJson);

            Assert.False(state.Collections.Any());
        }