Esempio n. 1
0
        public async Task <IActionResult> GetResourceByTenant([FromServices] INodeRepository nodeRepository)
        {
            var nodes  = nodeRepository.GetAll().OrderBy(n => n.Name);
            var result = tenantRepository.GetAllTenants().OrderBy(t => t.DisplayName).ToDictionary(t => t.Name, t => new TenantResourceOutputModel(t));

            var response = await clusterManagementLogic.GetAllContainerDetailsInfosAsync();

            if (response.IsSuccess)
            {
                foreach (var container in response.Value)
                {
                    //nodeInfoから必要な情報を取って、結果に含める
                    var nodeInfo = nodes.FirstOrDefault(n => n.Name == container.NodeName);
                    if (nodeInfo == null)
                    {
                        //登録ノードに所属していないコンテナは無視
                        continue;
                    }

                    if (result.ContainsKey(container.TenantName))
                    {
                        //テナント単位で集計する場合、テナントIDは自明なので、CreateContainerDetailsOutputModel()は使わない
                        result[container.TenantName].Add(new ContainerDetailsOutputModel(container)
                        {
                            CreatedBy = userRepository.GetUserName(container.CreatedBy)
                        });
                    }
                    else
                    {
                        //正体不明のテナントに紐づいたコンテナ

                        var unknownModel = new TenantResourceOutputModel(container.TenantName, containerManageOptions);
                        unknownModel.Add(new ContainerDetailsOutputModel(container)
                        {
                            CreatedBy = userRepository.GetUserName(container.CreatedBy)
                        });
                        result.Add(container.TenantName, unknownModel);
                    }
                }

                foreach (var tenant in result.Values)
                {
                    // ノード名の昇順に並び替える
                    tenant.ContainerResourceList = tenant.ContainerResourceList.OrderBy(c => c.NodeName).ToList();
                }
                return(JsonOK(result.Values));
            }
            else
            {
                return(JsonError(HttpStatusCode.ServiceUnavailable, string.Join("\n", "Fetching container resource is failed.", response.Error)));
            }
        }
Esempio n. 2
0
        public async Task <IActionResult> GetResourceByTenant()
        {
            var result = tenantRepository.GetAllTenants().ToDictionary(t => t.Name, t => new TenantResourceOutputModel(t));

            var response = await clusterManagementLogic.GetAllContainerDetailsInfosAsync();

            if (response.IsSuccess)
            {
                foreach (var container in response.Value)
                {
                    if (result.ContainsKey(container.TenantName))
                    {
                        //テナント単位で集計する場合、テナントIDは自明なので、CreateContainerDetailsOutputModel()は使わない
                        result[container.TenantName].Add(new ContainerDetailsOutputModel(container)
                        {
                            CreatedBy = userRepository.GetUserName(container.CreatedBy)
                        });
                    }
                    else
                    {
                        //正体不明のテナントに紐づいたコンテナ

                        var unknownModel = new TenantResourceOutputModel(container.TenantName);
                        unknownModel.Add(new ContainerDetailsOutputModel(container)
                        {
                            CreatedBy = userRepository.GetUserName(container.CreatedBy)
                        });
                        result.Add(container.TenantName, unknownModel);
                    }
                }
                return(JsonOK(result.Values));
            }
            else
            {
                return(JsonError(HttpStatusCode.ServiceUnavailable, string.Join("\n", "Fetching container resource is failed.", response.Error)));
            }
        }