public async Task <IActionResult> Delete(long?id)
        {
            //データの入力チェック
            if (id == null)
            {
                return(JsonBadRequest("Invalid inputs."));
            }
            //データの存在チェック
            var inferenceHistory = await inferenceHistoryRepository.GetByIdAsync(id.Value);

            if (inferenceHistory == null)
            {
                return(JsonNotFound($"Inference ID {id} is not found."));
            }

            //ステータスを確認

            var status = inferenceHistory.GetStatus();

            if (status.Exist())
            {
                //推論がまだ進行中の場合、情報を更新する
                status = await clusterManagementLogic.GetContainerStatusAsync(inferenceHistory.Key, CurrentUserInfo.SelectedTenant.Name, false);
            }

            if (status.Exist())
            {
                //実行中であれば、コンテナを削除
                await clusterManagementLogic.DeleteContainerAsync(
                    ContainerType.Training, inferenceHistory.Key, CurrentUserInfo.SelectedTenant.Name, false);
            }

            //添付ファイルがあったらまとめて消す
            var files = await inferenceHistoryRepository.GetAllAttachedFilesAsync(inferenceHistory.Id);

            foreach (var file in files)
            {
                inferenceHistoryRepository.DeleteAttachedFile(file);
                await storageLogic.DeleteFileAsync(ResourceType.InferenceHistoryAttachedFiles, file.StoredPath);
            }

            await dataSetLogic.ReleaseLockAsync(inferenceHistory.DataSetId);

            inferenceHistoryRepository.Delete(inferenceHistory);
            unitOfWork.Commit();

            // ストレージ内の推論データを削除する
            await storageLogic.DeleteResultsAsync(ResourceType.InferenceContainerAttachedFiles, inferenceHistory.Id);

            await storageLogic.DeleteResultsAsync(ResourceType.InferenceContainerOutputFiles, inferenceHistory.Id);

            return(JsonNoContent());
        }
        /// <summary>
        /// 前処理コンテナを削除し、ステータスを変更する。
        /// 削除可否の判断が必要なら、呼び出しもとで判定すること。
        /// </summary>
        /// <param name="preprocessHistory">対象前処理履歴</param>
        /// <param name="force">他テナントに対する変更を許可するか</param>
        public async Task <bool> DeleteAsync(PreprocessHistory preprocessHistory, bool force)
        {
            // 前処理結果を削除
            bool result = true;

            foreach (var outputDataId in preprocessHistoryRepository.GetPreprocessOutputs(preprocessHistory.Id))
            {
                //1件でも失敗したら結果はfalse。ただし、エラーが出ても最後まで消し切る。
                result &= await dataLogic.DeleteDataAsync(outputDataId);
            }

            // 前処理履歴の削除
            preprocessHistoryRepository.Delete(preprocessHistory, force);

            // 結果に関わらずコミット
            unitOfWork.Commit();

            var status = ContainerStatus.Convert(preprocessHistory.Status);

            if (status.Exist())
            {
                //コンテナが動いていれば、停止する
                await clusterManagementLogic.DeleteContainerAsync(
                    ContainerType.Preprocessing, preprocessHistory.Name, CurrentUserInfo.SelectedTenant.Name, force);
            }

            // ストレージ内の前処理データを削除する
            await storageLogic.DeleteResultsAsync(ResourceType.PreprocContainerAttachedFiles, preprocessHistory.Id);

            return(result);
        }
        public async Task <IActionResult> Delete(long?id)
        {
            //データの入力チェック
            if (id == null)
            {
                return(JsonBadRequest("Invalid inputs."));
            }

            //データの存在チェック
            var notebookHistory = await notebookHistoryRepository.GetByIdAsync(id.Value);

            if (notebookHistory == null)
            {
                return(JsonNotFound($"Notebook ID {id} is not found."));
            }

            //ステータスを確認
            var status = notebookHistory.GetStatus();

            if (status.Exist())
            {
                //Notebookコンテナが起動中の場合、情報を更新する
                status = await clusterManagementLogic.GetContainerStatusAsync(notebookHistory.Key, CurrentUserInfo.SelectedTenant.Name, false);
            }

            if (status.Exist())
            {
                //実行中であれば、コンテナを削除
                await clusterManagementLogic.DeleteContainerAsync(
                    ContainerType.Notebook, notebookHistory.Key, CurrentUserInfo.SelectedTenant.Name, false);
            }

            notebookHistoryRepository.Delete(notebookHistory);
            unitOfWork.Commit();

            // ストレージ内のノートブックデータを削除する
            await storageLogic.DeleteResultsAsync(ResourceType.NotebookContainerAttachedFiles, notebookHistory.Id);

            await storageLogic.DeleteResultsAsync(ResourceType.NotebookContainerOutputFiles, notebookHistory.Id);

            return(JsonNoContent());
        }
        public async Task <IActionResult> Delete(long?id)
        {
            //データの入力チェック
            if (id == null)
            {
                return(JsonBadRequest("Invalid inputs."));
            }
            //データの存在チェック
            var trainingHistory = await trainingHistoryRepository.GetByIdAsync(id.Value);

            if (trainingHistory == null)
            {
                return(JsonNotFound($"Training ID {id} is not found."));
            }

            //ステータスを確認

            var status = trainingHistory.GetStatus();

            if (status.Exist())
            {
                //学習がまだ進行中の場合、情報を更新する
                status = await clusterManagementLogic.GetContainerStatusAsync(trainingHistory.Key, CurrentUserInfo.SelectedTenant.Name, false);
            }

            //派生した学習履歴があったら消せない
            var child = trainingHistoryRepository.Find(t => t.ParentId == trainingHistory.Id);

            if (child != null)
            {
                return(JsonConflict($"There is another training which is derived from training {trainingHistory.Id}."));
            }

            //学習結果を利用した推論ジョブがあったら消せない
            var inference = inferenceHistoryRepository.Find(t => t.ParentId == trainingHistory.Id);

            if (inference != null)
            {
                return(JsonConflict($"Training training {trainingHistory.Id} has been used by inference."));
            }

            if (status.Exist())
            {
                //実行中であれば、コンテナを削除
                await clusterManagementLogic.DeleteContainerAsync(
                    ContainerType.Training, trainingHistory.Key, CurrentUserInfo.SelectedTenant.Name, false);
            }

            //TensorBoardを起動中だった場合は、そっちも消す
            TensorBoardContainer container = tensorBoardContainerRepository.GetAvailableContainer(trainingHistory.Id);

            if (container != null)
            {
                await clusterManagementLogic.DeleteContainerAsync(
                    ContainerType.TensorBoard, container.Name, CurrentUserInfo.SelectedTenant.Name, false);

                tensorBoardContainerRepository.Delete(container, true);
            }

            //添付ファイルがあったらまとめて消す
            var files = await trainingHistoryRepository.GetAllAttachedFilesAsync(trainingHistory.Id);

            foreach (var file in files)
            {
                trainingHistoryRepository.DeleteAttachedFile(file);
                await storageLogic.DeleteFileAsync(ResourceType.TrainingHistoryAttachedFiles, file.StoredPath);
            }

            trainingHistoryRepository.Delete(trainingHistory);
            unitOfWork.Commit();

            // ストレージ内の学習データを削除する
            await storageLogic.DeleteResultsAsync(ResourceType.TrainingContainerAttachedFiles, trainingHistory.Id);

            await storageLogic.DeleteResultsAsync(ResourceType.TrainingContainerOutputFiles, trainingHistory.Id);

            return(JsonNoContent());
        }