Skip to content

Commit 69385b4

Browse files
authored
Merge pull request #952 from Project-MONAI/nds-logging
Nds improve logging
2 parents 18a99ed + 31cdba3 commit 69385b4

File tree

7 files changed

+182
-3
lines changed

7 files changed

+182
-3
lines changed

src/TaskManager/TaskManager/Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ private static Logger ConfigureNLog(string assemblyVersionNumber)
154154
ext.RegisterLayoutRenderer("servicename", logEvent => typeof(Program).Namespace);
155155
ext.RegisterLayoutRenderer("serviceversion", logEvent => assemblyVersionNumber);
156156
ext.RegisterLayoutRenderer("machinename", logEvent => Environment.MachineName);
157+
ext.RegisterLayoutRenderer("appname", logEvent => "TaskManager");
157158
})
158159
.LoadConfigurationFromAppSettings()
159160
.GetCurrentClassLogger();

src/TaskManager/TaskManager/nlog.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ limitations under the License.
5252
<attribute name="Tag" layout="${environment:ENVIRONMENT_NAME}" />
5353
<attribute name="ServiceName" layout="${servicename}" />
5454
<attribute name="ServiceVersion" layout="${serviceversion}" />
55+
<attribute name="ApplicationName" layout="${appname}" />
5556
<attribute name="MachineName" layout="${machinename}" />
5657
<attribute name="CorrelationId" layout="${mdlc:item=correlationId}" />
5758
<attribute name="LoggerName" layout="${logger}" />

src/WorkflowManager/Contracts/Migrations/M004_WorkflowRevision_addDataRetension.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@ public M004_WorkflowRevision_AddDataRetension() : base("1.0.1") { }
2626

2727
public override void Up(BsonDocument document)
2828
{
29-
// document.Add("Workflow.DataRetentionDays", BsonNull.Create(null).ToJson(), true);
3029
var workflow = document["Workflow"].AsBsonDocument;
31-
workflow.Add("DataRetentionDays", BsonNull.Create(null).ToJson(), true);
30+
workflow.Add("DataRetentionDays", -1, true);
3231
}
3332

3433
public override void Down(BsonDocument document)

src/WorkflowManager/WorkflowExecuter/Services/WorkflowExecuterService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ await _artifactsRepository
253253

254254
private async Task ProcessArtifactReceivedOutputs(ArtifactsReceivedEvent message, WorkflowInstance workflowInstance, TaskObject taskTemplate, string taskId)
255255
{
256-
var artifactList = message.Artifacts.Select(a => $"{a.Path}").ToList();
256+
var artifactList = message.Artifacts.Select(a => a.Path).ToList();
257257
var artifactsInStorage = (await _storageService.VerifyObjectsExistAsync(workflowInstance.BucketId, artifactList, default)) ?? new Dictionary<string, bool>();
258258
if (artifactsInStorage.Any(a => a.Value) is false)
259259
{

src/WorkflowManager/WorkflowManager/Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ private static Logger ConfigureNLog(string assemblyVersionNumber)
189189
ext.RegisterLayoutRenderer("servicename", logEvent => typeof(Program).Namespace);
190190
ext.RegisterLayoutRenderer("serviceversion", logEvent => assemblyVersionNumber);
191191
ext.RegisterLayoutRenderer("machinename", logEvent => Environment.MachineName);
192+
ext.RegisterLayoutRenderer("appname", logEvent => "WorkflowManager");
192193
})
193194
.LoadConfigurationFromAppSettings()
194195
.GetCurrentClassLogger();

src/WorkflowManager/WorkflowManager/nlog.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ limitations under the License.
5252
<attribute name="Tag" layout="${environment:ENVIRONMENT_NAME}" />
5353
<attribute name="ServiceName" layout="${servicename}" />
5454
<attribute name="ServiceVersion" layout="${serviceversion}" />
55+
<attribute name="ApplicationName" layout="${appname}" />
5556
<attribute name="MachineName" layout="${machinename}" />
5657
<attribute name="CorrelationId" layout="${mdlc:item=correlationId}" />
5758
<attribute name="LoggerName" layout="${logger}" />

tests/UnitTests/WorkflowExecuter.Tests/Services/WorkflowExecuterServiceTests.cs

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3703,6 +3703,182 @@ public async Task ProcessTaskUpdate_ValidTaskUpdateEventWithExportHl7TaskDestina
37033703
response.Should().BeTrue();
37043704
}
37053705

3706+
//[Fact]
3707+
public async Task ProcessPayload_With_Multiple_Taskdestinations_One_Has_Inputs()
3708+
{
3709+
var workflowInstanceId = Guid.NewGuid().ToString();
3710+
var workflowId1 = Guid.NewGuid().ToString();
3711+
var workflowId2 = Guid.NewGuid().ToString();
3712+
var workflowRequest = new WorkflowRequestEvent
3713+
{
3714+
Bucket = "testbucket",
3715+
DataTrigger = new DataOrigin { Source = "aetitle", Destination = "aetitle" },
3716+
CorrelationId = Guid.NewGuid().ToString(),
3717+
Timestamp = DateTime.UtcNow,
3718+
Workflows = new List<string>
3719+
{
3720+
workflowId1.ToString()
3721+
}
3722+
};
3723+
3724+
var workflows = new List<WorkflowRevision>
3725+
{
3726+
new WorkflowRevision
3727+
{
3728+
Id = Guid.NewGuid().ToString(),
3729+
WorkflowId = workflowId1,
3730+
Revision = 1,
3731+
Workflow = new Workflow
3732+
{
3733+
Name = "Workflowname1",
3734+
Description = "Workflowdesc1",
3735+
Version = "1",
3736+
InformaticsGateway = new InformaticsGateway
3737+
{
3738+
AeTitle = "aetitle",
3739+
ExportDestinations = new string[] { "PROD_PACS" }
3740+
},
3741+
Tasks = new TaskObject[]
3742+
{
3743+
new TaskObject {
3744+
Id = "router",
3745+
Type = "router",
3746+
Description = "router",
3747+
Artifacts = new ArtifactMap
3748+
{
3749+
Input = new Artifact[] { new Artifact { Name = "dicomexport", Value = "{{ context.input }}" } },
3750+
Output = new OutputArtifact[]
3751+
{
3752+
new OutputArtifact
3753+
{
3754+
Name = "Artifact1",
3755+
Value = "Artifact1Value",
3756+
Mandatory = true,
3757+
Type = ArtifactType.DOC
3758+
},
3759+
new OutputArtifact
3760+
{
3761+
Name = "Artifact2",
3762+
Value = "Artifact2Value",
3763+
Mandatory = true,
3764+
Type = ArtifactType.CT
3765+
}
3766+
}
3767+
},
3768+
TaskDestinations = new TaskDestination[]
3769+
{
3770+
new TaskDestination
3771+
{
3772+
Name = "export1"
3773+
},
3774+
new TaskDestination
3775+
{
3776+
Name = "export2"
3777+
}
3778+
}
3779+
},
3780+
new TaskObject
3781+
{
3782+
Id ="export1",
3783+
Type = "export",
3784+
Artifacts = new ArtifactMap
3785+
{
3786+
Input = new Artifact[] { new Artifact { Name = "artifact", Value = "{{ context.executions.router.artifacts.output.Artifact1 }}" } }
3787+
},
3788+
ExportDestinations = new ExportDestination[]
3789+
{
3790+
}
3791+
},
3792+
new TaskObject
3793+
{
3794+
Id ="export2",
3795+
Type = "export",
3796+
Artifacts = new ArtifactMap
3797+
{
3798+
Input = new Artifact[] { new Artifact { Name = "artifact2", Value = "{{ context.executions.router.artifacts.output.Artifact2 }}" } }
3799+
},
3800+
ExportDestinations = new ExportDestination[]
3801+
{
3802+
}
3803+
},
3804+
}
3805+
}
3806+
}
3807+
};
3808+
var workflowInstance = new WorkflowInstance
3809+
{
3810+
Id = workflowInstanceId,
3811+
WorkflowId = workflowId1,
3812+
WorkflowName = workflows.First()!.Workflow!.Name,
3813+
PayloadId = Guid.NewGuid().ToString(),
3814+
Status = Status.Created,
3815+
BucketId = "bucket",
3816+
Tasks = new List<TaskExecution>
3817+
{
3818+
new TaskExecution
3819+
{
3820+
TaskId = "router",
3821+
Status = TaskExecutionStatus.Created
3822+
},
3823+
//new TaskExecution
3824+
//{
3825+
// TaskId = "export1",
3826+
// Status = TaskExecutionStatus.Created
3827+
//},
3828+
//new TaskExecution
3829+
//{
3830+
// TaskId = "export2",
3831+
// Status = TaskExecutionStatus.Created
3832+
//}
3833+
}
3834+
};
3835+
3836+
var artifactDict = new List<Messaging.Common.Storage>
3837+
{
3838+
new Messaging.Common.Storage
3839+
{
3840+
Name = "artifactname",
3841+
RelativeRootPath = "path/to/artifact"
3842+
}
3843+
};
3844+
3845+
_workflowInstanceRepository.Setup(w => w.GetByWorkflowInstanceIdAsync(workflowInstance.Id)).ReturnsAsync(workflowInstance);
3846+
3847+
_workflowRepository.Setup(w => w.GetByWorkflowsIdsAsync(new List<string> { workflowId1.ToString() })).ReturnsAsync(workflows);
3848+
_workflowRepository.Setup(w => w.GetByWorkflowIdAsync(workflowId1.ToString())).ReturnsAsync(workflows[0]);
3849+
_workflowInstanceRepository.Setup(w => w.CreateAsync(It.IsAny<List<WorkflowInstance>>())).ReturnsAsync(true);
3850+
_workflowInstanceRepository.Setup(w => w.UpdateTasksAsync(It.IsAny<string>(), It.IsAny<List<TaskExecution>>())).ReturnsAsync(true);
3851+
_workflowInstanceRepository.Setup(w => w.GetByWorkflowsIdsAsync(It.IsAny<List<string>>())).ReturnsAsync(new List<WorkflowInstance>());
3852+
_workflowInstanceRepository.Setup(w => w.UpdateTaskStatusAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<TaskExecutionStatus>())).ReturnsAsync(true);
3853+
var dcmInfo = new Dictionary<string, string>() { { "dicomexport", "/dcm" } };
3854+
_artifactMapper.Setup(a => a.TryConvertArtifactVariablesToPath(It.IsAny<Artifact[]>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>(), out dcmInfo)).Returns(true);
3855+
3856+
_messageBrokerPublisherService.Setup(m => m.Publish(It.IsAny<string>(), It.IsAny<Message>()));
3857+
3858+
var pathList = artifactDict.Select(a => a.RelativeRootPath).ToList();
3859+
3860+
_storageService.Setup(w => w.VerifyObjectsExistAsync(
3861+
workflowInstance.BucketId, It.Is<IReadOnlyList<string>>(l => l.Any(a => pathList.Any(p => p == a))), It.IsAny<CancellationToken>()))
3862+
.ReturnsAsync(new Dictionary<string, bool>() { { pathList.First(), true } });
3863+
3864+
var mess = new ArtifactsReceivedEvent
3865+
{
3866+
WorkflowInstanceId = workflowInstance.Id,
3867+
TaskId = "router",
3868+
Artifacts = [new Messaging.Common.Artifact { Type = ArtifactType.DOC, Path = "path/to/artifact" }]
3869+
};
3870+
3871+
3872+
var response = await WorkflowExecuterService.ProcessArtifactReceivedAsync(mess);
3873+
3874+
Assert.True(response);
3875+
//_workflowInstanceRepository.Verify(w => w.UpdateTaskStatusAsync(workflowInstanceId, "router", TaskExecutionStatus.Succeeded));
3876+
_workflowInstanceRepository.Verify(w => w.UpdateTaskStatusAsync(workflowInstanceId, "export1", TaskExecutionStatus.Succeeded));
3877+
3878+
3879+
3880+
#pragma warning restore CS8604 // Possible null reference argument.
3881+
}
37063882
}
37073883

37083884
#pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type.

0 commit comments

Comments
 (0)