示例#1
0
        public IActionResult GetGitInfos([FromServices] IGitRepository gitRepository)
        {
            var tenant = CurrentUserInfo.SelectedTenant;
            var result = new GitInfoOutputModel()
            {
                DefaultGitId = tenant.DefaultGit?.Id
            };

            var gitMaps = gitRepository.GetUserTenantGitMapAll(tenant.Id, CurrentUserInfo.Id);

            result.Gits = gitMaps.Select(map => new GitCredentialOutputModel(map));
            return(JsonOK(result));
        }
        public async Task <IActionResult> Run([FromBody] CreateInputModel model)
        {
            if (!ModelState.IsValid)
            {
                return(JsonBadRequest("Invalid inputs."));
            }

            var dataSet = await aquariumDataSetRepository
                          .GetAll()
                          .Include(x => x.DataSetVersions)
                          .SingleOrDefaultAsync(x => x.Id == model.DataSetId);

            if (dataSet == null)
            {
                return(JsonNotFound($"DataSet ID {model.DataSetId} is not found."));
            }

            var dataSetVersion = dataSet.DataSetVersions.SingleOrDefault(x => x.Id == model.DataSetVersionId);

            if (dataSetVersion == null)
            {
                return(JsonNotFound($"DataSetVersion (DataSetId {model.DataSetId} and VersionId {model.DataSetVersionId}) is not found."));
            }

            var template = await templateRepository.GetByIdAsync(model.TemplateId);

            if (template == null)
            {
                return(JsonNotFound($"Template ID {model.TemplateId} is not found."));
            }
            if (!templateLogic.Accessible(template, CurrentUserInfo.SelectedTenant))
            {
                return(JsonBadRequest($"Template ID {model.TemplateId} is not accesible."));
            }

            var templateVersion = await templateVersionRepository
                                  .GetAll()
                                  .Include(x => x.PreprocessContainerRegistry)
                                  .Include(x => x.TrainingContainerRegistry)
                                  .Include(x => x.EvaluationContainerRegistry)
                                  .SingleOrDefaultAsync(x => x.TemplateId == model.TemplateId && x.Id == model.TemplateVersionId);

            if (templateVersion == null)
            {
                return(JsonNotFound($"TemplateVersion (TemplateID {model.TemplateId} and VersionId {model.TemplateVersionId} is not found."));
            }

            var registryMaps = registryRepository.GetUserTenantRegistryMapAll(CurrentUserInfo.SelectedTenant.Id, CurrentUserInfo.Id);

            if (templateVersion.PreprocessContainerRegistryId.HasValue &&
                !registryMaps.Any(x => x.TenantRegistryMap.RegistryId == templateVersion.PreprocessContainerRegistryId.Value))
            {
                return(JsonBadRequest($"Prprocess Container Registry ID {templateVersion.PreprocessContainerRegistryId.Value} is not accesible."));
            }
            if (!registryMaps.Any(x => x.TenantRegistryMap.RegistryId == templateVersion.TrainingContainerRegistryId))
            {
                return(JsonBadRequest($"Training Container Registry ID {templateVersion.TrainingContainerRegistryId} is not accesible."));
            }
            if (templateVersion.EvaluationContainerRegistryId.HasValue &&
                !registryMaps.Any(x => x.TenantRegistryMap.RegistryId == templateVersion.EvaluationContainerRegistryId.Value))
            {
                return(JsonBadRequest($"Evaluation Container Registry ID {templateVersion.EvaluationContainerRegistryId.Value} is not accesible."));
            }

            var gitMaps = gitRepository.GetUserTenantGitMapAll(CurrentUserInfo.SelectedTenant.Id, CurrentUserInfo.Id);

            if (templateVersion.PreprocessRepositoryGitId.HasValue &&
                !gitMaps.Any(x => x.TenantGitMap.GitId == templateVersion.PreprocessRepositoryGitId.Value))
            {
                return(JsonBadRequest($"Prprocess Repository Git ID {templateVersion.PreprocessRepositoryGitId.Value} is not accesible."));
            }
            if (!gitMaps.Any(x => x.TenantGitMap.GitId == templateVersion.TrainingRepositoryGitId))
            {
                return(JsonBadRequest($"Training Repository Git ID {templateVersion.TrainingRepositoryGitId} is not accesible."));
            }
            if (templateVersion.EvaluationRepositoryGitId.HasValue &&
                !gitMaps.Any(x => x.TenantGitMap.GitId == templateVersion.EvaluationRepositoryGitId.Value))
            {
                return(JsonBadRequest($"Evaluation Repository Git ID {templateVersion.EvaluationRepositoryGitId.Value} is not accesible."));
            }


            if (templateVersion.PreprocessContainerRegistryId == null)
            {
                // テンプレートに前処理がない
                return(await RunExperimentTrainingWithoutPreprocess(model, templateVersion, dataSetVersion));
            }

            var experimentPreprocess = experimentPreprocessRepository
                                       .GetAll()
                                       .Include(x => x.TrainingHistory)
                                       .Where(x => x.TemplateId == model.TemplateId && x.TemplateVersionId == model.TemplateVersionId &&
                                              x.DataSetId == model.DataSetId && x.DataSetVersionId == model.DataSetVersionId)
                                       .AsEnumerable()
                                       .FirstOrDefault(x => x.TrainingHistory.GetStatus() == ContainerStatus.Completed);

            if (experimentPreprocess == null)
            {
                // テンプレートに前処理があり、前処理が実行されていない
                return(await RunExperimentPreprocess(model, templateVersion, dataSetVersion));
            }

            // テンプレートに前処理があり、前処理が別実験で実行ずみ
            return(await RunExperimentTrainingWithPreprocess(model, templateVersion, dataSetVersion, experimentPreprocess));
        }