MdpRelationalCapacityController.cs 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using Admin.NET.Plugin.AiDOP.DataPlatform.Core;
  2. using Admin.NET.Plugin.AiDOP.DataPlatform.Core.Connectors;
  3. using static Admin.NET.Plugin.AiDOP.DataPlatform.UnifiedIngress.MdpRelationalSource;
  4. namespace Admin.NET.Plugin.AiDOP.DataPlatform.UnifiedIngress;
  5. public sealed partial class MdpIngestDatasetController
  6. {
  7. [HttpPost("{id:long}/relational-trials/{profileId}/capacity-sample")]
  8. public Task<IActionResult> MeasureRelationalCapacity(long id, string profileId, long? factoryId, CancellationToken token) =>
  9. WithScope(factoryId, async scope =>
  10. {
  11. if (!await Can(TrialPermission)) return Forbid();
  12. var dataset = await Datasets(scope).FirstAsync(d => d.Id == id);
  13. if (dataset is null) return NotFound();
  14. using var deadline = CancellationTokenSource.CreateLinkedTokenSource(token);
  15. deadline.CancelAfter(TimeSpan.FromSeconds(35));
  16. var work = deadline.Token;
  17. try
  18. {
  19. var profile = (await TrialProfiles(scope, id, work)).SingleOrDefault(p => p.Id == profileId);
  20. if (profile is null) return NotFound();
  21. var source = await BoundSource(dataset, profile.SourceId);
  22. if (source is null || !dataset.Enabled || dataset.ActiveSchemaVersion is null || await Lifecycle(id) != "ACTIVE")
  23. return Conflict(new { message = "请先启用该来源已审批的采购接收版本" });
  24. var (runtime, binding, configuration) = await CreateRelationalTrial(db, profile, dataset, source);
  25. var report = await InspectProfile(profile, binding, work);
  26. var blocked = report.Checks.FirstOrDefault(check => check.Severity == "block");
  27. if (blocked is not null) return Conflict(new { message = blocked.Message, code = blocked.Code });
  28. var sample = await MdpDatasetSandbox.MeasureCapacityAsync(Settings, runtime, binding, configuration,
  29. Math.Clamp(profile.SyncPageSize, 1, 50), report.Advice?.EstimatedRows, work);
  30. return Ok(new { sample, history = (object?)null });
  31. }
  32. catch (OperationCanceledException) when (!token.IsCancellationRequested)
  33. {
  34. return StatusCode(504, new { message = "估算试跑超时,请核对来源读取和沙箱响应时间" });
  35. }
  36. catch (MdpIngestHttpException error)
  37. {
  38. return StatusCode(error.StatusCode, new { message = "估算配置未通过接收校验", code = error.Code });
  39. }
  40. catch (ConnectorContractException error)
  41. {
  42. return Conflict(new { message = "来源未通过估算读取检查", code = error.Code.ToString() });
  43. }
  44. catch (IngestContractException error)
  45. {
  46. return Conflict(new { message = "估算样本未通过采购接收校验", code = error.Code.ToString() });
  47. }
  48. catch (Exception error) when (error is System.Data.Common.DbException or SqlSugarException or IOException
  49. or System.Text.Json.JsonException or ArgumentException or InvalidOperationException or UnauthorizedAccessException)
  50. {
  51. return StatusCode(503, new { message = "请核对来源与隔离试跑库,或查看样本对账结果" });
  52. }
  53. });
  54. }