예제 #1
0
        public override R EndExecute(IAsyncResult result)
        {
            if (!Object.ReferenceEquals(result, asyncResult))
            {
                throw new ArgumentException("provided result argument does not match");
            }

            if (asyncResultDic != null && asyncResultDic.Count > 0)
            {
                IList <IClusterResponse <T> > clusterResults = new List <IClusterResponse <T> >();

                foreach (KeyValuePair <Server, IAsyncResult> pair in asyncResultDic)
                {
                    IClusterResponse <T> response = null;
                    try
                    {
                        response = new ClusterResponse <T>((T)_shard.EndSendMessage(pair.Key, pair.Value), pair.Key);
                    }
                    catch (Exception ex)
                    {
                        response = new ClusterResponse <T>(default(T), pair.Key, false, 1);
                    }

                    clusterResults.Add(response);
                }


                responseCollection.Responses = clusterResults;
                return(responseCollection); //_factory(clusterResults);
            }

            return(default(R));
        }
예제 #2
0
        public IDictionary <String, IResponseCollection <T> > SendMessageToAllShards <T>(Message message, bool primaryOnly)
        {
            IDictionary <String, IResponseCollection <T> > responses    = new HashVector <String, IResponseCollection <T> >();
            IDictionary <String, RequestAsync>             asyncResults = new HashVector <String, RequestAsync>();

            foreach (String shard in _remoteShards.Keys)
            {
                IShard dest = GetShardInstance(shard);
                if (dest != null)
                {
                    try
                    {
                        if (primaryOnly)
                        {
                            ShardRequestBase <T> request = dest.CreateUnicastRequest <T>(dest.Primary, message);
                            asyncResults.Add(shard, new RequestAsync(request.BeginExecute(), request, dest.Primary));
                        }
                        else
                        {
                            ShardMulticastRequest <ResponseCollection <T>, T> multicastRequest = dest.CreateMulticastRequest <ResponseCollection <T>, T>(dest.ActiveChannelsList, message);
                            asyncResults.Add(shard, new RequestAsync(multicastRequest.BeginExecute(), multicastRequest));
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                }
            }

            foreach (KeyValuePair <String, RequestAsync> pair in asyncResults)
            {
                String shardName = pair.Key;
                IResponseCollection <T> shardResponse = new ResponseCollection <T>();

                if (primaryOnly)
                {
                    ShardRequestBase <T>          req             = pair.Value.Request;
                    IClusterResponse <T>          clusterResponse = new ClusterResponse <T>(req.EndExecute(pair.Value.AsyncResult), pair.Value.Destination);
                    IList <IClusterResponse <T> > list            = new List <IClusterResponse <T> >();
                    list.Add(clusterResponse);

                    shardResponse.Responses = list;
                }
                else
                {
                    ShardMulticastRequest <ResponseCollection <T>, T> req = pair.Value.Request;
                    shardResponse = req.EndExecute(pair.Value.AsyncResult);
                }

                responses.Add(shardName, shardResponse);
            }

            return(responses);
        }
예제 #3
0
        public async Task <ClusterResponse> List()
        {
            using (var response = await _httpClient.GetAsync(_rancherApiBaseUrl + "/clusters"))
            {
                response.EnsureSuccessStatusCode();
                var content = await response.Content.ReadAsStringAsync();

                ClusterResponse clusterResponse = JsonConvert.DeserializeObject <ClusterResponse>(content);

                return(clusterResponse);
            }
        }
예제 #4
0
        public async Task <IActionResult> Cluster(string ns = "demo")
        {
            var mod = new ClusterResponse();

            try
            {
                var list = await K8sClient.ListNamespacedPodAsync(ns);

                PodCollection webPods = new PodCollection()
                {
                    Name = "Website Pods"
                };
                PodCollection middlePods = new PodCollection()
                {
                    Name = "Middle API Pods"
                };
                PodCollection backendPods = new PodCollection()
                {
                    Name = "Backend API Pods"
                };
                foreach (var item in list.Items)
                {
                    if (item.Metadata.Name.ToLower().Contains("web"))
                    {
                        webPods.Pods.Add(item);
                    }
                    if (item.Metadata.Name.ToLower().Contains("middle"))
                    {
                        middlePods.Pods.Add(item);
                    }
                    if (item.Metadata.Name.ToLower().Contains("backend"))
                    {
                        backendPods.Pods.Add(item);
                    }
                }
                mod.PodCollections.Add(webPods);
                mod.PodCollections.Add(middlePods);
                mod.PodCollections.Add(backendPods);
            }
            catch (Exception ex)
            {
                mod.Error = ex.Message;
                if (ex.InnerException != null)
                {
                    mod.Error += " - " + ex.InnerException.Message;
                }
            }


            return(View(mod));
        }