Add queue hardening by modifying DeploymentJobTargets, DeploymentJobSteps, and DeploymentJobs tables
- Drop existing indexes on DeploymentJobTargets and DeploymentJobSteps - Alter Status column to nvarchar(450) in DeploymentJobTargets, DeploymentJobSteps, and DeploymentJobs - Add new columns: Finished, OutputMetadataJson, Started to DeploymentJobTargets; ErrorMessage, Finished, OutputMetadataJson, Started to DeploymentJobSteps; CorrelationId, HeartbeatAt, Priority, RowVersion, ScheduledAt, WorkerName to DeploymentJobs - Create new indexes for improved query performance - Add constraints to ensure OutputMetadataJson is valid JSON - Record migration in __EFMigrationsHistory
This commit is contained in:
@@ -34,16 +34,28 @@ namespace Microsoft.SelfService.Portal.Core.API.Controllers
|
||||
{
|
||||
var deploymentBatches = _deploymentBatchInterface
|
||||
.GetDeploymentBatches()
|
||||
.Select(batch => new GetDeploymentBatchDto
|
||||
.Select(batch =>
|
||||
{
|
||||
Id = batch.Id,
|
||||
TemplateId = batch.TemplateId,
|
||||
DeploymentRuleId = batch.DeploymentRuleId,
|
||||
Status = batch.Status,
|
||||
Created = batch.Created,
|
||||
CreatedBy = batch.CreatedBy,
|
||||
Modified = batch.Modified,
|
||||
ModifiedBy = batch.ModifiedBy
|
||||
var primarySelection = batch.TemplateSelections
|
||||
.OrderBy(selection => selection.SortOrder)
|
||||
.FirstOrDefault();
|
||||
|
||||
return new GetDeploymentBatchDto
|
||||
{
|
||||
Id = batch.Id,
|
||||
TemplateId = batch.TemplateId,
|
||||
DeploymentRuleId = batch.DeploymentRuleId,
|
||||
Status = batch.Status,
|
||||
Created = batch.Created,
|
||||
CreatedBy = batch.CreatedBy,
|
||||
Modified = batch.Modified,
|
||||
ModifiedBy = batch.ModifiedBy,
|
||||
PrimaryTemplateVersionId = primarySelection?.TemplateVersionId,
|
||||
PrimaryTemplateName = primarySelection?.TemplateVersion?.Template?.Name,
|
||||
PrimaryTemplateVersion = primarySelection?.TemplateVersion?.Version,
|
||||
TemplateSelectionCount = batch.TemplateSelections.Count,
|
||||
TargetAssignmentCount = batch.TargetAssignments.Count
|
||||
};
|
||||
})
|
||||
.ToList();
|
||||
|
||||
@@ -80,6 +92,20 @@ namespace Microsoft.SelfService.Portal.Core.API.Controllers
|
||||
if (!ModelState.IsValid)
|
||||
return BadRequest(ModelState);
|
||||
|
||||
if (deploymentBatch.TemplateVersionId.HasValue
|
||||
&& (deploymentBatch.TemplateSelections == null || deploymentBatch.TemplateSelections.Count == 0))
|
||||
{
|
||||
deploymentBatch.TemplateSelections = new List<AddDeploymentTemplateSelectionDto>
|
||||
{
|
||||
new()
|
||||
{
|
||||
TemplateVersionId = deploymentBatch.TemplateVersionId.Value,
|
||||
TemplateRole = "Service",
|
||||
SortOrder = 10
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
var deploymentBatchMap = _mapper.Map<DeploymentGroupModel>(deploymentBatch);
|
||||
|
||||
if (!_deploymentBatchInterface.AddDeploymentBatchById(deploymentBatchMap, deploymentBatch.TargetIds))
|
||||
|
||||
@@ -100,12 +100,6 @@ namespace Microsoft.SelfService.Portal.Core.API.Controllers
|
||||
if (request == null)
|
||||
return BadRequest(ModelState);
|
||||
|
||||
if (request.TargetIds == null || request.TargetIds.Count == 0)
|
||||
{
|
||||
ModelState.AddModelError("", "At least one Target must be selected.");
|
||||
return BadRequest(ModelState);
|
||||
}
|
||||
|
||||
if (!ModelState.IsValid)
|
||||
return BadRequest(ModelState);
|
||||
|
||||
@@ -149,6 +143,11 @@ namespace Microsoft.SelfService.Portal.Core.API.Controllers
|
||||
Started = job.Started,
|
||||
Finished = job.Finished,
|
||||
ErrorMessage = job.ErrorMessage,
|
||||
CorrelationId = job.CorrelationId,
|
||||
Priority = job.Priority,
|
||||
ScheduledAt = job.ScheduledAt,
|
||||
HeartbeatAt = job.HeartbeatAt,
|
||||
WorkerName = job.WorkerName,
|
||||
TargetCount = job.Targets.Count,
|
||||
SucceededTargetCount = job.Targets.Count(target => target.Status == QueueJobStatus.Succeeded),
|
||||
FailedTargetCount = job.Targets.Count(target => target.Status == QueueJobStatus.Failed)
|
||||
@@ -185,6 +184,13 @@ namespace Microsoft.SelfService.Portal.Core.API.Controllers
|
||||
ErrorMessage = queueJob.ErrorMessage,
|
||||
MetadataJson = queueJob.MetadataJson,
|
||||
RuleSnapshotJson = queueJob.RuleSnapshotJson,
|
||||
CorrelationId = queueJob.CorrelationId,
|
||||
Priority = queueJob.Priority,
|
||||
ScheduledAt = queueJob.ScheduledAt,
|
||||
HeartbeatAt = queueJob.HeartbeatAt,
|
||||
WorkerName = queueJob.WorkerName,
|
||||
LockedBy = queueJob.LockedBy,
|
||||
LockedUntil = queueJob.LockedUntil,
|
||||
Created = queueJob.Created,
|
||||
CreatedBy = queueJob.CreatedBy,
|
||||
Modified = queueJob.Modified,
|
||||
@@ -197,7 +203,10 @@ namespace Microsoft.SelfService.Portal.Core.API.Controllers
|
||||
TemplateId = target.TemplateId,
|
||||
Status = target.Status,
|
||||
Attempts = target.Attempts,
|
||||
ErrorMessage = target.ErrorMessage
|
||||
ErrorMessage = target.ErrorMessage,
|
||||
Started = target.Started,
|
||||
Finished = target.Finished,
|
||||
OutputMetadataJson = target.OutputMetadataJson
|
||||
}).ToList(),
|
||||
Steps = queueJob.Steps
|
||||
.OrderBy(step => step.SortOrder)
|
||||
@@ -212,7 +221,11 @@ namespace Microsoft.SelfService.Portal.Core.API.Controllers
|
||||
MetadataJson = step.MetadataJson,
|
||||
ApprovedAt = step.ApprovedAt,
|
||||
ApprovedBy = step.ApprovedBy,
|
||||
ApprovalComment = step.ApprovalComment
|
||||
ApprovalComment = step.ApprovalComment,
|
||||
Started = step.Started,
|
||||
Finished = step.Finished,
|
||||
OutputMetadataJson = step.OutputMetadataJson,
|
||||
ErrorMessage = step.ErrorMessage
|
||||
}).ToList()
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user