From ebd8d650c68923f0b2fd08a0616d6c852b438eff Mon Sep 17 00:00:00 2001 From: stas Date: Tue, 5 Apr 2022 14:11:01 -0700 Subject: [PATCH] merge models --- .../ApiService/OneFuzzTypes/Model.cs | 109 +++++++++++------- src/ApiService/ApiService/UserCredentials.cs | 1 - src/ApiService/ApiService/model.cs | 87 -------------- 3 files changed, 70 insertions(+), 127 deletions(-) delete mode 100644 src/ApiService/ApiService/model.cs diff --git a/src/ApiService/ApiService/OneFuzzTypes/Model.cs b/src/ApiService/ApiService/OneFuzzTypes/Model.cs index 10c96f0c2c..b43e4d6f61 100644 --- a/src/ApiService/ApiService/OneFuzzTypes/Model.cs +++ b/src/ApiService/ApiService/OneFuzzTypes/Model.cs @@ -1,61 +1,92 @@ -using Azure.Data.Tables; -using Azure.ResourceManager.Storage.Models; +using Microsoft.OneFuzz.Service.OneFuzzLib.Orm; using System; -using System.Runtime.Serialization; -using System.Text.Json.Serialization; +using System.Collections.Generic; namespace Microsoft.OneFuzz.Service; -record NodeCommandStopIfFree { } +/// Convention for database entities: +/// All entities are represented by immutable records +/// All database entities need to derive from EntityBase +/// Only properties that also apears as parameter initializers are mapped to the database +/// The name of the property will be tranlated to snake case and used as the column name +/// It is possible to rename the column name by using the [property:JsonPropertyName("column_name")] attribute +/// the "partion key" and "row key" are identified by the [PartitionKey] and [RowKey] attributes +/// Guids are mapped to string in the db -record StopNodeCommand{} -record StopTaskNodeCommand{ - Guid TaskId; +[SkipRename] +public enum HeartbeatType +{ + MachineAlive, + TaskAlive, } -record NodeCommandAddSshKey{ - string PublicKey; -} +public record HeartbeatData(HeartbeatType type); -record NodeCommand -{ - StopNodeCommand? Stop; - StopTaskNodeCommand? StopTask; - NodeCommandAddSshKey? AddSshKey; - NodeCommandStopIfFree? StopIfFree; -} +public record NodeHeartbeatEntry(Guid NodeId, HeartbeatData[] data); -enum NodeTaskState -{ - init, - setting_up, - running, -} +public record NodeCommandStopIfFree(); -record NodeTasks -{ - Guid MachineId; - Guid TaskId; - NodeTaskState State = NodeTaskState.init; +public record StopNodeCommand(); + +public record StopTaskNodeCommand(Guid TaskId); +public record NodeCommandAddSshKey(string PublicKey); + + +public record NodeCommand +( + StopNodeCommand? Stop, + StopTaskNodeCommand? StopTask, + NodeCommandAddSshKey? AddSshKey, + NodeCommandStopIfFree? StopIfFree +); + +public enum NodeTaskState +{ + Init, + SettingUp, + Running, } -enum NodeState +public record NodeTasks +( + Guid MachineId, + Guid TaskId, + NodeTaskState State = NodeTaskState.Init +); + +public enum NodeState { - init, + Init, free, - setting_up, - rebooting, - ready, - busy, - done, - shutdown, - halt, + SettingUp, + Rebooting, + Ready, + Busy, + Done, + Shutdown, + Halt, } +public partial record Node +( + DateTimeOffset? InitializedAt, + [PartitionKey] string PoolName, + Guid? PoolId, + [RowKey] Guid MachineId, + NodeState State, + Guid? ScalesetId, + DateTimeOffset Heartbeat, + Version Version, + bool ReimageRequested, + bool DeleteRequested, + bool DebugKeepNode +) : EntityBase(); + + public record Error (ErrorCode Code, string[]? Errors = null); -public record UserInfo (Guid? ApplicationId, Guid? ObjectId, String? Upn); \ No newline at end of file +public record UserInfo (Guid? ApplicationId, Guid? ObjectId, String? Upn); diff --git a/src/ApiService/ApiService/UserCredentials.cs b/src/ApiService/ApiService/UserCredentials.cs index dc5d937681..2f1b96df72 100644 --- a/src/ApiService/ApiService/UserCredentials.cs +++ b/src/ApiService/ApiService/UserCredentials.cs @@ -3,7 +3,6 @@ using System.Net.Http; using System.Net.Http.Headers; using System.Threading.Tasks; -using ApiService; using Azure.ResourceManager.Compute.Models; using Azure.ResourceManager.Network.Models; using Microsoft.Azure.Functions.Worker.Http; diff --git a/src/ApiService/ApiService/model.cs b/src/ApiService/ApiService/model.cs deleted file mode 100644 index 8e6f6df290..0000000000 --- a/src/ApiService/ApiService/model.cs +++ /dev/null @@ -1,87 +0,0 @@ -using Microsoft.OneFuzz.Service.OneFuzzLib.Orm; -using System; -using System.Collections.Generic; - -namespace Microsoft.OneFuzz.Service; - - -/// Convention for database entities: -/// All entities are represented by immutable records -/// All database entities need to derive from EntityBase -/// Only properties that also apears as parameter initializers are mapped to the database -/// The name of the property will be tranlated to snake case and used as the column name -/// It is possible to rename the column name by using the [property:JsonPropertyName("column_name")] attribute -/// the "partion key" and "row key" are identified by the [PartitionKey] and [RowKey] attributes -/// Guids are mapped to string in the db - - -[SkipRename] -public enum HeartbeatType -{ - MachineAlive, - TaskAlive, -} - -public record HeartbeatData(HeartbeatType type); - -public record NodeHeartbeatEntry(Guid NodeId, HeartbeatData[] data); - -public record NodeCommandStopIfFree(); - -public record StopNodeCommand(); - -public record StopTaskNodeCommand(Guid TaskId); - -public record NodeCommandAddSshKey(string PublicKey); - - -public record NodeCommand -( - StopNodeCommand? Stop, - StopTaskNodeCommand? StopTask, - NodeCommandAddSshKey? AddSshKey, - NodeCommandStopIfFree? StopIfFree -); - -public enum NodeTaskState -{ - Init, - SettingUp, - Running, -} - -public record NodeTasks -( - Guid MachineId, - Guid TaskId, - NodeTaskState State = NodeTaskState.Init -); - -public enum NodeState -{ - Init, - free, - SettingUp, - Rebooting, - Ready, - Busy, - Done, - Shutdown, - Halt, -} - - -public partial record Node -( - DateTimeOffset? InitializedAt, - [PartitionKey] string PoolName, - Guid? PoolId, - [RowKey] Guid MachineId, - NodeState State, - Guid? ScalesetId, - DateTimeOffset Heartbeat, - Version Version, - bool ReimageRequested, - bool DeleteRequested, - bool DebugKeepNode -): EntityBase();