コード例 #1
0
 public void Post([FromBody] Tenant site)
 {
     if (ModelState.IsValid)
     {
         tenants.AddTenant(site);
     }
 }
コード例 #2
0
 public Tenant Post([FromBody] Tenant Tenant)
 {
     if (ModelState.IsValid)
     {
         Tenant = Tenants.AddTenant(Tenant);
     }
     return(Tenant);
 }
コード例 #3
0
 public Tenant Post([FromBody] Tenant tenant)
 {
     if (ModelState.IsValid)
     {
         tenant = _tenants.AddTenant(tenant);
         _logger.Log(LogLevel.Information, this, LogFunction.Create, "Tenant Added {TenantId}", tenant.TenantId);
     }
     return(tenant);
 }
コード例 #4
0
        public async Task <Tenant> AddTenant(Tenant tenant)
        {
            await _tenantRepository.AddTenant(tenant);

            var settings = await _settingService.GetSettings(null);

            foreach (var item in settings)
            {
                if (await _settingService.GetSettingValueByType((Settings)Enum.Parse(typeof(Settings), item.Key),
                                                                tenant.Id) == null)
                {
                    try
                    {
                        var setting = new Setting
                        {
                            IsVisible = item.IsVisible,
                            TenantId  = tenant.Id,
                            Key       = item.Key,
                            Value     = item.Value
                        };
                        await _settingService.AddSetting(setting);
                    }
                    catch (Exception)
                    {
                        // ignored
                    }
                }
            }

            var roleExists = await _roleService.GetRoleByName("Admin", tenant.Id) != null;

            if (!roleExists)
            {
                await _roleService.AddRole("Admin", tenant.Id);
            }
            return(tenant);
        }
コード例 #5
0
        public async Task <IActionResult> CreateForTenant([FromBody] CreateInputModel model)
        {
            //データの入力チェック
            if (!ModelState.IsValid)
            {
                return(JsonBadRequest("Invalid inputs."));
            }

            Tenant tenant = tenantRepository.GetFromTenantName(model.TenantName);

            if (tenant != null)
            {
                //テナント名の重複があるのでエラー
                return(JsonConflict($"Tenant {model.TenantName} already exists: ID = {tenant.Id}"));
            }
            if (model.DefaultGitId != null && model.GitIds.Contains(model.DefaultGitId.Value) == false)
            {
                //デフォルトGitがGit一覧の中になかったらエラー
                return(JsonConflict($"Default Gity ID {model.DefaultGitId.Value} does NOT exist in selected gits."));
            }
            if (model.DefaultRegistryId != null && model.RegistryIds.Contains(model.DefaultRegistryId.Value) == false)
            {
                //デフォルトレジストリがレジストリ一覧の中になかったらエラー
                return(JsonConflict($"Default Registry ID {model.DefaultRegistryId.Value} does NOT exist in selected registries."));
            }

            tenant = new Tenant()
            {
                Name          = model.TenantName,
                DisplayName   = model.DisplayName,
                StorageBucket = model.TenantName,
                StorageId     = model.StorageId
            };

            Git git = null;

            if (model.GitIds != null && model.GitIds.Count() > 0)
            {
                //デフォルトGitの設定(無ければ一個目)
                tenant.DefaultGitId = model.DefaultGitId == null?
                                      model.GitIds.ElementAt(0) : model.DefaultGitId.Value;

                foreach (long gitId in model.GitIds)
                {
                    //データの存在チェック
                    git = await gitRepository.GetByIdAsync(gitId);

                    if (git == null)
                    {
                        return(JsonNotFound($"The selected git ID {gitId} is not found."));
                    }
                    await gitRepository.AttachGitToTenantAsync(tenant, git, true);
                }
            }
            Registry registry = null;

            if (model.RegistryIds != null && model.RegistryIds.Count() > 0)
            {
                //デフォルトレジストリの設定(無ければ一個目)
                tenant.DefaultRegistryId = model.DefaultRegistryId == null?
                                           model.RegistryIds.ElementAt(0) : model.DefaultRegistryId.Value;

                foreach (long registryId in model.RegistryIds)
                {
                    //データの存在チェック
                    registry = await registryRepository.GetByIdAsync(registryId);

                    if (registry == null)
                    {
                        return(JsonNotFound($"The selected registry ID {registryId} is not found."));
                    }
                    await registryRepository.AttachRegistryToTenantAsync(tenant, registry, true);
                }
            }

            //データの存在チェック
            var storage = tenantRepository.GetStorage(model.StorageId.Value);

            if (storage == null)
            {
                return(JsonNotFound($"The selected storage ID {model.StorageId.Value} is not found."));
            }

            //ObjectStorage に バケットを作成する
            bool isCreated = await storageLogic.CreateBucketAsync(tenant, storage);

            if (!isCreated)
            {
                // 既にバケットが存在していたならエラーとする
                return(JsonNotFound($"Can not create because [{tenant.Name}] exists in the NFS server. Please delete it from the NFS server."));
            }

            tenantRepository.AddTenant(tenant);

            //コンテナ管理サービス作業
            //テナントを登録
            var tenantResult = await clusterManagementLogic.RegistTenantAsync(tenant.Name);

            if (tenantResult == false)
            {
                return(JsonError(HttpStatusCode.ServiceUnavailable, "Couldn't create cluster master namespace. Please check the configuration to the connect cluster manager service."));
            }
            //初期データ投入処理
            commonDiLogic.InitializeTenant(tenant);

            unitOfWork.Commit();
            tenantRepository.Refresh();
            roleRepository.Refresh();

            var result = new IndexOutputModel(tenant);

            return(JsonOK(result));
        }