Skip to content

Commit

Permalink
Add ACR enum in DataService (#217)
Browse files Browse the repository at this point in the history
* Add ACR as DataType
* Implement GetHashCode() && Equals()
* Rename to DataService
* Rename JsonProperty for DataService
* Add DataService.Unknown
* Add .NET JSON support


Signed-off-by: Victor Chang <[email protected]>
  • Loading branch information
mocsharp authored Aug 24, 2023
1 parent 07e219e commit 50f2f18
Show file tree
Hide file tree
Showing 14 changed files with 152 additions and 27 deletions.
5 changes: 4 additions & 1 deletion src/Messaging/Common/BlockStorageInfo.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021-2022 MONAI Consortium
* Copyright 2021-2023 MONAI Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,6 +14,7 @@
* limitations under the License.
*/

using System.Text.Json.Serialization;
using Newtonsoft.Json;

namespace Monai.Deploy.Messaging.Common
Expand All @@ -24,12 +25,14 @@ public class BlockStorageInfo
/// Gets or sets the root path to the file.
/// </summary>
[JsonProperty(PropertyName = "path")]
[JsonPropertyName("path")]
public string Path { get; set; } = default!;

/// <summary>
/// Gets or sets the root path to the metadata file.
/// </summary>
[JsonProperty(PropertyName = "metadata")]
[JsonPropertyName("metadata")]
public string Metadata { get; set; } = default!;
}
}
6 changes: 5 additions & 1 deletion src/Messaging/Common/Credentials.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022 MONAI Consortium
* Copyright 2022-2023 MONAI Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,6 +15,7 @@
*/

using System.ComponentModel.DataAnnotations;
using System.Text.Json.Serialization;
using Newtonsoft.Json;

namespace Monai.Deploy.Messaging.Common
Expand All @@ -25,20 +26,23 @@ public class Credentials
/// Gets or sets the access key or user name of the credentials pair.
/// </summary>
[JsonProperty(PropertyName = "access_key")]
[JsonPropertyName("access_key")]
[Required]
public string AccessKey { get; set; }

/// <summary>
/// Gets or sets the access token or password of the credentials pair.
/// </summary>
[JsonProperty(PropertyName = "access_token")]
[JsonPropertyName("access_token")]
[Required]
public string AccessToken { get; set; }

/// <summary>
/// Gets or sets the session token of the credentials pair.
/// </summary>
[JsonProperty(PropertyName = "session_token")]
[JsonPropertyName("session_token")]
public string SessionToken { get; set; }

public Credentials()
Expand Down
9 changes: 8 additions & 1 deletion src/Messaging/Common/Storage.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022 MONAI Consortium
* Copyright 2022-2023 MONAI Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,6 +15,7 @@
*/

using System.ComponentModel.DataAnnotations;
using System.Text.Json.Serialization;
using Newtonsoft.Json;

namespace Monai.Deploy.Messaging.Common
Expand All @@ -26,39 +27,45 @@ public class Storage : ICloneable
/// For Argo, name of the artifact used in the template.
/// </summary>
[JsonProperty(PropertyName = "name")]
[JsonPropertyName("name")]
[Required]
public string Name { get; set; }

/// <summary>
/// Gets or sets the endpoint of the storage service.
/// </summary>
[JsonProperty(PropertyName = "endpoint")]
[JsonPropertyName("endpoint")]
[Required]
public string Endpoint { get; set; }

/// <summary>
/// Gets or sets credentials for accessing the storage service.
/// </summary>
[JsonProperty(PropertyName = "credentials")]
[JsonPropertyName("credentials")]
public Credentials? Credentials { get; set; }

/// <summary>
/// Gets or sets name of the bucket.
/// </summary>
[JsonProperty(PropertyName = "bucket")]
[JsonPropertyName("bucket")]
[Required]
public string Bucket { get; set; }

/// <summary>
/// Gets or sets whether the connection should be secured or not.
/// </summary>
[JsonProperty(PropertyName = "secured_connection")]
[JsonPropertyName("secured_connection")]
public bool SecuredConnection { get; set; }

/// <summary>
/// Gets or sets the optional relative root path to the data.
/// </summary>
[JsonProperty(PropertyName = "relative_root_path")]
[JsonPropertyName("relative_root_path")]
[Required]
public string RelativeRootPath { get; set; }

Expand Down
10 changes: 9 additions & 1 deletion src/Messaging/Events/EmailRequestEvent.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022 MONAI Consortium
* Copyright 2022-2023 MONAI Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,36 +15,44 @@
*/

using System.ComponentModel.DataAnnotations;
using System.Text.Json.Serialization;
using Newtonsoft.Json;

namespace Monai.Deploy.Messaging.Events
{
public class EmailRequestEvent : EventBase
{
[JsonProperty(PropertyName = "id")]
[JsonPropertyName("id")]
[Required]
public Guid Id { get; set; }

[JsonProperty(PropertyName = "workflow_instance_id")]
[JsonPropertyName("workflow_instance_id")]
[Required]
public string WorkflowInstanceId { get; set; }

[JsonProperty(PropertyName = "workflow_name")]
[JsonPropertyName("workflow_name")]
[Required]
public string WorkflowName { get; set; }

[JsonProperty(PropertyName = "task_id")]
[JsonPropertyName("task_id")]
[Required]
public string TaskId { get; set; }

[JsonProperty(PropertyName = "roles")]
[JsonPropertyName("roles")]
public string Roles { get; set; }

[JsonProperty(PropertyName = "emails")]
[JsonPropertyName("emails")]
public string Emails { get; set; }

[Required]
[JsonProperty(PropertyName = "metadata")]
[JsonPropertyName("metadata")]
public Dictionary<string, string> Metadata { get; set; }

public EmailRequestEvent()
Expand Down
15 changes: 11 additions & 4 deletions src/Messaging/Events/ExportCompleteEvent.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021-2022 MONAI Consortium
* Copyright 2021-2023 MONAI Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,8 +15,8 @@
*/

using System.ComponentModel.DataAnnotations;
using System.Text.Json.Serialization;
using Ardalis.GuardClauses;
using Monai.Deploy.Messaging.Common;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

Expand All @@ -28,37 +28,44 @@ public class ExportCompleteEvent : EventBase
/// Gets or sets the workflow instanceID generated by the Workflow Manager.
/// </summary>
[JsonProperty(PropertyName = "workflow_instance_id")]
[JsonPropertyName("workflow_instance_id")]
[Required]
public string WorkflowInstanceId { get; set; } = default!;

/// <summary>
/// Gets or sets the export task ID generated by the Workflow Manager.
/// </summary>
[JsonProperty(PropertyName = "export_task_id")]
[JsonPropertyName("export_task_id")]
[Required]
public string ExportTaskId { get; set; } = default!;

/// <summary>
/// Gets or sets the state of the export task.
/// </summary>
[JsonProperty(PropertyName = "status")]
[JsonConverter(typeof(StringEnumConverter))]
[JsonPropertyName("status")]
[Newtonsoft.Json.JsonConverter(typeof(StringEnumConverter))]
[System.Text.Json.Serialization.JsonConverter(typeof(JsonStringEnumConverter))]
[Required]
public ExportStatus Status { get; set; }

/// <summary>
/// Gets or sets error messages, if any, when exporting.
/// </summary>
[JsonProperty(PropertyName = "message")]
[JsonPropertyName("message")]
public string Message { get; set; } = default!;

/// <summary>
/// Gets or sets files exported with its status
/// </summary>
[JsonProperty(PropertyName = "file_statuses")]
[JsonPropertyName("file_statuses")]
public Dictionary<string, FileExportStatus> FileStatuses { get; set; }

[JsonConstructor]
[Newtonsoft.Json.JsonConstructor]
[System.Text.Json.Serialization.JsonConstructor]
public ExportCompleteEvent()
{
Status = ExportStatus.Unknown;
Expand Down
17 changes: 15 additions & 2 deletions src/Messaging/Events/ExportRequestEvent.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021-2022 MONAI Consortium
* Copyright 2021-2023 MONAI Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,7 +15,7 @@
*/

using System.ComponentModel.DataAnnotations;
using Monai.Deploy.Messaging.Common;
using System.Text.Json.Serialization;
using Newtonsoft.Json;

namespace Monai.Deploy.Messaging.Events
Expand All @@ -26,20 +26,23 @@ public class ExportRequestEvent : EventBase
/// Gets or sets the workflow instance ID generated by the Workflow Manager.
/// </summary>
[JsonProperty(PropertyName = "workflow_instance_id")]
[JsonPropertyName("workflow_instance_id")]
[Required]
public string WorkflowInstanceId { get; set; } = default!;

/// <summary>
/// Gets or sets the export task ID generated by the Workflow Manager.
/// </summary>
[JsonProperty(PropertyName = "export_task_id")]
[JsonPropertyName("export_task_id")]
[Required]
public string ExportTaskId { get; set; } = default!;

/// <summary>
/// Gets or sets a list of files to be exported.
/// </summary>
[JsonProperty(PropertyName = "files")]
[JsonPropertyName("files")]
[Required, MinLength(1)]
public IEnumerable<string> Files { get; set; } = default!;

Expand All @@ -49,6 +52,7 @@ public class ExportRequestEvent : EventBase
/// For ACR, the Transaction ID in the original inference request.
/// </summary>
[JsonProperty(PropertyName = "destinations")]
[JsonPropertyName("destinations")]
[Required]
public string[] Destinations { get; set; } = default!;

Expand All @@ -58,22 +62,29 @@ public class ExportRequestEvent : EventBase
/// For ACR, use the Transaction ID in the original request.
/// </summary>
[JsonProperty(PropertyName = "correlation_id")]
[JsonPropertyName("correlation_id")]
[Required]
public string CorrelationId { get; set; } = default!;

/// <summary>
/// Gets or sets the delivery tag or acknowledge token for the task.
/// </summary>
[JsonProperty(PropertyName = "delivery_tag")]
[JsonPropertyName("delivery_tag")]
public string DeliveryTag { get; set; } = default!;

/// <summary>
/// Gets or sets the message ID set by the message broker.
/// </summary>
[JsonProperty(PropertyName = "message_id")]
[JsonPropertyName("message_id")]
public string MessageId { get; set; } = default!;

/// <summary>
/// Gets or sets error messages related to this export task.
/// </summary>
[JsonProperty(PropertyName = "error_messages")]
[JsonPropertyName("error_messages")]
public List<string> ErrorMessages { get; private set; }

/// <summary>
Expand All @@ -82,6 +93,8 @@ public class ExportRequestEvent : EventBase
/// E.g. <code>MyCompnay.MyProject.MyNamepsace.MyPlugin, MyCompnay.MyProject.MyNamepsace</code> where
/// <code>MyCompnay.MyProject.MyNamepsace</code> is the name of the assembly (DLL).
/// </summary>
[JsonProperty(PropertyName = "plug_in_assemblies")]
[JsonPropertyName("plug_in_assemblies")]
public List<string> PluginAssemblies { get; private set; }

public ExportRequestEvent()
Expand Down
Loading

0 comments on commit 50f2f18

Please sign in to comment.