Skip to content

Commit fee2d99

Browse files
authored
Merge branch 'develop' into AC-1567
2 parents 1d56a22 + 185a6ef commit fee2d99

File tree

4 files changed

+94
-7
lines changed

4 files changed

+94
-7
lines changed

src/WorkflowManager/Common/Services/PayloadService.cs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public PayloadService(
8686
CallingAeTitle = eventPayload.CallingAeTitle,
8787
Timestamp = eventPayload.Timestamp,
8888
PatientDetails = patientDetails,
89-
PayloadDeleted = PayloadDeleted.No,
89+
PayloadDeleted = PayloadDeleted.No
9090
};
9191

9292
if (await _payloadRepository.CreateAsync(payload))
@@ -173,12 +173,12 @@ public async Task<bool> DeletePayloadFromStorageAsync(string payloadId)
173173
throw new MonaiNotFoundException($"Payload with ID: {payloadId} not found");
174174
}
175175

176-
if (payload.PayloadDeleted == PayloadDeleted.InProgress)
176+
if (payload.PayloadDeleted == PayloadDeleted.InProgress || payload.PayloadDeleted == PayloadDeleted.Yes)
177177
{
178-
throw new MonaiBadRequestException($"Deletion of files for payload ID: {payloadId} already in progress");
178+
throw new MonaiBadRequestException($"Deletion of files for payload ID: {payloadId} already in progress or already deleted");
179179
}
180180

181-
// update the payload to in progress before we request deletion form MinIO
181+
// update the payload to in progress before we request deletion from storage
182182
payload.PayloadDeleted = PayloadDeleted.InProgress;
183183
await _payloadRepository.UpdateAsync(payload);
184184

@@ -188,12 +188,19 @@ public async Task<bool> DeletePayloadFromStorageAsync(string payloadId)
188188
{
189189
try
190190
{
191-
await _storageService.RemoveObjectsAsync(payload.Bucket, payload.Files.Select(f => f.Path));
191+
// get all objects for the payload in storage to be deleted
192+
var allPayloadObjects = await _storageService.ListObjectsAsync(payload.Bucket, payloadId, true);
193+
194+
if (allPayloadObjects.Any())
195+
{
196+
await _storageService.RemoveObjectsAsync(payload.Bucket, allPayloadObjects.Select(o => o.FilePath));
197+
}
198+
192199
payload.PayloadDeleted = PayloadDeleted.Yes;
193200
}
194-
catch
201+
catch (Exception ex)
195202
{
196-
_logger.PayloadUpdateFailed(payloadId);
203+
_logger.PayloadDeleteFailed(payloadId, ex);
197204
payload.PayloadDeleted = PayloadDeleted.Failed;
198205
}
199206
finally

src/WorkflowManager/Logging/Log.300000.Payload.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,8 @@ public static partial class Log
3737

3838
[LoggerMessage(EventId = 300005, Level = LogLevel.Error, Message = "Failed to update payload {payloadId} due to database error.")]
3939
public static partial void PayloadUpdateFailed(this ILogger logger, string payloadId);
40+
41+
[LoggerMessage(EventId = 300006, Level = LogLevel.Error, Message = "Failed to delete payload {payloadId} from storage.")]
42+
public static partial void PayloadDeleteFailed(this ILogger logger, string payloadId, Exception ex);
4043
}
4144
}

tests/IntegrationTests/WorkflowExecutor.IntegrationTests/Features/PayloadApi.feature

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,32 @@ Scenario Outline: Get payload by Id returns 400
124124
When I send a GET request
125125
Then I will get a 400 response
126126
And I will receive the error message Failed to validate id, not a valid guid
127+
128+
@DeletePayloadById
129+
Scenario Outline: Delete payload by Id returns 400 with invalid payload ID
130+
Given I have an endpoint /payload/invalid-payload-id
131+
When I send a DELETE request
132+
Then I will get a 400 response
133+
And I will receive the error message Failed to validate id, not a valid guid
134+
135+
@DeletePayloadById
136+
Scenario Outline: Delete payload by ID returns 404 when no payload exists
137+
Given I have an endpoint /payload/c5c3635b-81dd-44a9-8c3b-71adec7d47c6
138+
When I send a DELETE request
139+
Then I will get a 404 response
140+
And I will receive the error message Payload with ID: c5c3635b-81dd-44a9-8c3b-71adec7d47c6 not found
141+
142+
@DeletePayloadById
143+
Scenario Outline: Delete payload by ID returns 400 when PayloadDeleted is already InProgress
144+
Given I have an endpoint /payload/c5c3635b-81dd-44a9-8c3b-71adec7d47c6
145+
And I have a payload saved in mongo Payload_PayloadDeleted_InProgress
146+
When I send a DELETE request
147+
Then I will get a 400 response
148+
And I will receive the error message Deletion of files for payload ID: c5c3635b-81dd-44a9-8c3b-71adec7d47c6 already in progress or already deleted
149+
150+
@DeletePayloadById
151+
Scenario Outline: Delete payload by ID returns 202
152+
Given I have an endpoint /payload/d5c3633b-41de-44a9-8c3a-71adec3d47c1
153+
And I have a payload saved in mongo Payload_PayloadDeleted_No
154+
When I send a DELETE request
155+
Then I will get a 202 response

tests/IntegrationTests/WorkflowExecutor.IntegrationTests/TestData/PayloadTestData.cs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,54 @@ public static class PayloadsTestData
305305
}
306306
}
307307
},
308+
new PayloadTestData()
309+
{
310+
Name = "Payload_PayloadDeleted_InProgress",
311+
Payload = new Payload()
312+
{
313+
Id = Guid.NewGuid().ToString(),
314+
Timestamp = DateTime.UtcNow,
315+
Bucket = "bucket_1",
316+
CalledAeTitle = "MIG",
317+
CallingAeTitle = "Basic_AE",
318+
CorrelationId = Guid.NewGuid().ToString(),
319+
PayloadId = "c5c3635b-81dd-44a9-8c3b-71adec7d47c6",
320+
Workflows = new List<string> { Guid.NewGuid().ToString() },
321+
FileCount = 50,
322+
PayloadDeleted = PayloadDeleted.InProgress,
323+
PatientDetails = new PatientDetails()
324+
{
325+
PatientDob = new DateTime(1996, 02, 05, 0, 0, 0, kind: DateTimeKind.Utc),
326+
PatientId = Guid.NewGuid().ToString(),
327+
PatientName = "Mike Mcgee",
328+
PatientSex = "male"
329+
}
330+
}
331+
},
332+
new PayloadTestData()
333+
{
334+
Name = "Payload_PayloadDeleted_No",
335+
Payload = new Payload()
336+
{
337+
Id = Guid.NewGuid().ToString(),
338+
Timestamp = DateTime.UtcNow,
339+
Bucket = "bucket_1",
340+
CalledAeTitle = "MIG",
341+
CallingAeTitle = "Basic_AE",
342+
CorrelationId = Guid.NewGuid().ToString(),
343+
PayloadId = "d5c3633b-41de-44a9-8c3a-71adec3d47c1",
344+
Workflows = new List<string> { Guid.NewGuid().ToString() },
345+
FileCount = 50,
346+
PayloadDeleted = PayloadDeleted.No,
347+
PatientDetails = new PatientDetails()
348+
{
349+
PatientDob = new DateTime(1996, 02, 05, 0, 0, 0, kind: DateTimeKind.Utc),
350+
PatientId = Guid.NewGuid().ToString(),
351+
PatientName = "Mike Mcgee",
352+
PatientSex = "male"
353+
}
354+
}
355+
}
308356
};
309357
}
310358
}

0 commit comments

Comments
 (0)