public IActionResult Create([FromBody] CreateInputModel model) { // データの入力チェック if (!ModelState.IsValid) { return(JsonBadRequest("Invalid inputs.")); } // 同じ名前のレジストリは登録できないので、確認する var registry = registryRepository.GetRegistryAll().FirstOrDefault(r => r.Name == model.Name); if (registry != null) { return(JsonConflict($"Registry {model.Name} already exists.")); } registry = new Registry() { Name = model.Name, Host = model.Host, PortNo = model.PortNo.Value, ServiceType = model.ServiceType.Value, ProjectName = model.ProjectName, ApiUrl = model.ApiUrl, RegistryUrl = model.RegistryUrl }; registryRepository.Add(registry); unitOfWork.Commit(); var result = new IndexOutputModel(registry); return(JsonOK(result)); }
public IActionResult Create([FromBody] CreateInputModel model) { //データの入力チェック if (!ModelState.IsValid) { return(JsonBadRequest("Invalid inputs.")); } Storage storage = new Storage() { Name = model.Name, ServerAddress = model.ServerUrl, AccessKey = model.AccessKey, SecretKey = model.SecretKey, NfsServer = model.NfsServer, NfsRoot = model.NfsRoot }; tenantRepository.AddStorage(storage); unitOfWork.Commit(); tenantRepository.Refresh(); var result = new IndexOutputModel(storage); return(JsonOK(result)); }
/// <summary> /// ステータスを更新して、出力モデルに変換する /// </summary> /// <param name="history">学習履歴</param> private async Task <IndexOutputModel> GetUpdatedIndexOutputModelAsync(TrainingHistory history) { var status = await DoGetUpdatedIndexOutputModelAsync(history, clusterManagementLogic, CurrentUserInfo, trainingHistoryRepository, unitOfWork); var model = new IndexOutputModel(history); model.Status = status.Name; return(model); }
public async Task <IActionResult> GetDetail(long id) { var template = await templateRepository.GetByIdAsync(id); if (template == null) { return(JsonNotFound($"Template ID {id} is not found.")); } var result = new IndexOutputModel(template); return(JsonOK(result)); }
public async Task <IActionResult> GetDetails(long?id) { if (id == null) { return(JsonBadRequest("Git ID is required.")); } Git git = await gitRepository.GetByIdAsync(id.Value); if (git == null) { return(JsonNotFound($"Git Id {id.Value} is not found.")); } var model = new IndexOutputModel(git); return(JsonOK(model)); }
/// <summary> /// ステータスを更新して、出力モデルに変換する /// </summary> /// <param name="history">ノートブック履歴</param> private async Task <IndexOutputModel> GetUpdatedIndexOutputModelAsync(NotebookHistory history) { var model = new IndexOutputModel(history); var status = history.GetStatus(); if (status.Exist()) { //ノートブックコンテナがまだ進行中の場合、情報を更新する var newStatus = await clusterManagementLogic.GetContainerStatusAsync(history.Key, CurrentUserInfo.SelectedTenant.Name, false); if (status.Key != newStatus.Key) { //更新があったので、変更処理 await notebookHistoryRepository.UpdateStatusAsync(history.Id, newStatus, false); unitOfWork.Commit(); model.Status = newStatus.Name; } } return(model); }
public IActionResult Create([FromBody] CreateInputModel model) { //データの入力チェック if (!ModelState.IsValid) { return(JsonBadRequest("Invalid inputs.")); } Git git = new Git() { Name = model.Name, ServiceType = model.ServiceType.Value, ApiUrl = model.ApiUrl, RepositoryUrl = model.RepositoryUrl, }; gitRepository.Add(git); unitOfWork.Commit(); var result = new IndexOutputModel(git); return(JsonOK(result)); }
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)); }