Exemplo n.º 1
0
        public async Task <IActionResult> GetDetailTemplateVersion(long id, long versionId)
        {
            var templateVersion = await templateVersionRepository
                                  .GetAll()
                                  .Include(x => x.PreprocessContainerRegistry)
                                  .Include(x => x.TrainingContainerRegistry)
                                  .Include(x => x.EvaluationContainerRegistry)
                                  .SingleOrDefaultAsync(x => x.Id == versionId && x.TemplateId == id);

            if (templateVersion == null)
            {
                return(JsonNotFound($"TemplateVersion (Id {id} VersionId {versionId}) is not found."));
            }

            var model = new VersionDetailsOutputModel(templateVersion);

            // Gitの表示用URLを作る
            if (templateVersion.PreprocessRepositoryGitId != null)
            {
                model.PreprocessGitModel.Url = gitLogic.GetTreeUiUrl(templateVersion.PreprocessRepositoryGitId.Value, templateVersion.PreprocessRepositoryName, templateVersion.PreprocessRepositoryOwner, templateVersion.PreprocessRepositoryCommitId);
            }
            model.TrainingGitModel.Url = gitLogic.GetTreeUiUrl(templateVersion.TrainingRepositoryGitId, templateVersion.TrainingRepositoryName, templateVersion.TrainingRepositoryOwner, templateVersion.TrainingRepositoryCommitId);
            if (templateVersion.EvaluationRepositoryGitId != null)
            {
                model.EvaluationGitModel.Url = gitLogic.GetTreeUiUrl(templateVersion.EvaluationRepositoryGitId.Value, templateVersion.EvaluationRepositoryName, templateVersion.EvaluationRepositoryOwner, templateVersion.EvaluationRepositoryCommitId);
            }

            return(JsonOK(model));
        }
Exemplo n.º 2
0
        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));
        }