Skip to content

Commit d78d47b

Browse files
Merge pull request #316 from microsoft/main
Fork Sync: Update from parent repository
2 parents cdcd3b7 + 4044e5c commit d78d47b

38 files changed

+182
-219
lines changed

src/ApiService/ApiService/Functions/AgentCanSchedule.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,7 @@ private async Async.Task<HttpResponseData> Post(HttpRequestData req) {
3535
_log.Warning($"Unable to find {canScheduleRequest.MachineId:Tag:MachineId}");
3636
return await _context.RequestHandling.NotOk(
3737
req,
38-
new Error(
39-
ErrorCode.UNABLE_TO_FIND,
40-
new string[] {
41-
"unable to find node"
42-
}),
38+
Error.Create(ErrorCode.UNABLE_TO_FIND, "unable to find node"),
4339
canScheduleRequest.MachineId.ToString());
4440
}
4541

src/ApiService/ApiService/Functions/AgentEvents.cs

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ private async Async.Task<HttpResponseData> Post(HttpRequestData req) {
3535
NodeStateUpdate updateEvent => await OnStateUpdate(envelope.MachineId, updateEvent),
3636
WorkerEvent workerEvent => await OnWorkerEvent(envelope.MachineId, workerEvent),
3737
NodeEvent nodeEvent => await OnNodeEvent(envelope.MachineId, nodeEvent),
38-
_ => new Error(ErrorCode.INVALID_REQUEST, new string[] { $"invalid node event: {envelope.Event.GetType().Name}" }),
38+
_ => Error.Create(ErrorCode.INVALID_REQUEST, $"invalid node event: {envelope.Event.GetType().Name}"),
3939
};
4040

4141
if (error is Error e) {
@@ -114,17 +114,17 @@ private async Async.Task<HttpResponseData> Post(HttpRequestData req) {
114114
} else if (ev.State == NodeState.SettingUp) {
115115
if (ev.Data is NodeSettingUpEventData settingUpData) {
116116
if (!settingUpData.Tasks.Any()) {
117-
return new Error(ErrorCode.INVALID_REQUEST, Errors: new string[] {
118-
$"setup without tasks. machine_id: {machineId}",
119-
});
117+
return Error.Create(ErrorCode.INVALID_REQUEST,
118+
$"setup without tasks. machine_id: {machineId}"
119+
);
120120
}
121121

122122
foreach (var taskId in settingUpData.Tasks) {
123123
var task = await _context.TaskOperations.GetByTaskId(taskId);
124124
if (task is null) {
125-
return new Error(
125+
return Error.Create(
126126
ErrorCode.INVALID_REQUEST,
127-
Errors: new string[] { $"unable to find task: {taskId}" });
127+
$"unable to find task: {taskId}");
128128
}
129129

130130
_log.Info($"node starting task. {machineId:Tag:MachineId} {task.JobId:Tag:JobId} {task.TaskId:Tag:TaskId}");
@@ -154,7 +154,7 @@ private async Async.Task<HttpResponseData> Post(HttpRequestData req) {
154154
if (ev.Data is NodeDoneEventData doneData) {
155155
if (doneData.Error is not null) {
156156
var errorText = EntityConverter.ToJsonString(doneData);
157-
error = new Error(ErrorCode.TASK_FAILED, Errors: new string[] { errorText });
157+
error = Error.Create(ErrorCode.TASK_FAILED, errorText);
158158
_log.Error($"node 'done' {machineId:Tag:MachineId} - {errorText:Tag:Error}");
159159
}
160160
}
@@ -178,9 +178,9 @@ private async Async.Task<HttpResponseData> Post(HttpRequestData req) {
178178
return await OnWorkerEventRunning(machineId, ev.Running);
179179
}
180180

181-
return new Error(
182-
Code: ErrorCode.INVALID_REQUEST,
183-
Errors: new string[] { "WorkerEvent should have either 'done' or 'running' set" });
181+
return Error.Create(
182+
ErrorCode.INVALID_REQUEST,
183+
"WorkerEvent should have either 'done' or 'running' set");
184184
}
185185

186186
private async Async.Task<Error?> OnWorkerEventRunning(Guid machineId, WorkerRunningEvent running) {
@@ -189,15 +189,11 @@ private async Async.Task<HttpResponseData> Post(HttpRequestData req) {
189189
_context.NodeOperations.GetByMachineId(machineId));
190190

191191
if (task is null) {
192-
return new Error(
193-
Code: ErrorCode.INVALID_REQUEST,
194-
Errors: new string[] { $"unable to find task: {running.TaskId}" });
192+
return Error.Create(ErrorCode.INVALID_REQUEST, $"unable to find task: {running.TaskId}");
195193
}
196194

197195
if (node is null) {
198-
return new Error(
199-
Code: ErrorCode.INVALID_REQUEST,
200-
Errors: new string[] { $"unable to find node: {machineId}" });
196+
return Error.Create(ErrorCode.INVALID_REQUEST, $"unable to find node: {machineId}");
201197
}
202198

203199
if (!node.State.ReadyForReset()) {
@@ -240,15 +236,11 @@ private async Async.Task<HttpResponseData> Post(HttpRequestData req) {
240236
_context.NodeOperations.GetByMachineId(machineId));
241237

242238
if (task is null) {
243-
return new Error(
244-
Code: ErrorCode.INVALID_REQUEST,
245-
Errors: new string[] { $"unable to find task: {done.TaskId}" });
239+
return Error.Create(ErrorCode.INVALID_REQUEST, $"unable to find task: {done.TaskId}");
246240
}
247241

248242
if (node is null) {
249-
return new Error(
250-
Code: ErrorCode.INVALID_REQUEST,
251-
Errors: new string[] { $"unable to find node: {machineId}" });
243+
return Error.Create(ErrorCode.INVALID_REQUEST, $"unable to find node: {machineId}");
252244
}
253245

254246
// trim stdout/stderr if too long
@@ -272,13 +264,12 @@ private async Async.Task<HttpResponseData> Post(HttpRequestData req) {
272264
} else {
273265
await _context.TaskOperations.MarkFailed(
274266
task,
275-
new Error(
276-
Code: ErrorCode.TASK_FAILED,
277-
Errors: new string[] {
278-
$"task failed. exit_status:{done.ExitStatus}",
279-
done.Stdout,
280-
done.Stderr,
281-
}));
267+
Error.Create(
268+
ErrorCode.TASK_FAILED,
269+
$"task failed. exit_status:{done.ExitStatus}",
270+
done.Stdout,
271+
done.Stderr
272+
));
282273

283274
// keep node if any keep options are set
284275
if ((task.Config.Debug?.Contains(TaskDebugFlag.KeepNodeOnFailure) == true)

src/ApiService/ApiService/Functions/AgentRegistration.cs

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,29 +40,29 @@ private async Async.Task<HttpResponseData> Get(HttpRequestData req) {
4040
if (machineId == Guid.Empty) {
4141
return await _context.RequestHandling.NotOk(
4242
req,
43-
new Error(
43+
Error.Create(
4444
ErrorCode.INVALID_REQUEST,
45-
new string[] { "'machine_id' query parameter must be provided" }),
45+
"'machine_id' query parameter must be provided"),
4646
"agent registration");
4747
}
4848

4949
var agentNode = await _context.NodeOperations.GetByMachineId(machineId);
5050
if (agentNode is null) {
5151
return await _context.RequestHandling.NotOk(
5252
req,
53-
new Error(
53+
Error.Create(
5454
ErrorCode.INVALID_REQUEST,
55-
new string[] { $"unable to find a registration associated with machine_id '{machineId}'" }),
55+
$"unable to find a registration associated with machine_id '{machineId}'"),
5656
"agent registration");
5757
}
5858

5959
var pool = await _context.PoolOperations.GetByName(agentNode.PoolName);
6060
if (!pool.IsOk) {
6161
return await _context.RequestHandling.NotOk(
6262
req,
63-
new Error(
63+
Error.Create(
6464
ErrorCode.INVALID_REQUEST,
65-
new string[] { "unable to find a pool associated with the provided machine_id" }),
65+
"unable to find a pool associated with the provided machine_id"),
6666
"agent registration");
6767
}
6868

@@ -101,18 +101,16 @@ private async Async.Task<HttpResponseData> Post(HttpRequestData req) {
101101
if (machineId == Guid.Empty) {
102102
return await _context.RequestHandling.NotOk(
103103
req,
104-
new Error(
105-
ErrorCode.INVALID_REQUEST,
106-
new string[] { "'machine_id' query parameter must be provided" }),
104+
Error.Create(
105+
ErrorCode.INVALID_REQUEST, "'machine_id' query parameter must be provided"),
107106
"agent registration");
108107
}
109108

110109
if (poolName is null) {
111110
return await _context.RequestHandling.NotOk(
112111
req,
113-
new Error(
114-
ErrorCode.INVALID_REQUEST,
115-
new string[] { "'pool_name' query parameter must be provided" }),
112+
Error.Create(
113+
ErrorCode.INVALID_REQUEST, "'pool_name' query parameter must be provided"),
116114
"agent registration");
117115
}
118116

@@ -124,9 +122,8 @@ private async Async.Task<HttpResponseData> Post(HttpRequestData req) {
124122
if (!poolResult.IsOk) {
125123
return await _context.RequestHandling.NotOk(
126124
req,
127-
new Error(
128-
Code: ErrorCode.INVALID_REQUEST,
129-
Errors: new[] { $"unable to find pool '{poolName}'" }),
125+
Error.Create(
126+
ErrorCode.INVALID_REQUEST, $"unable to find pool '{poolName}'"),
130127
"agent registration");
131128
}
132129

@@ -140,9 +137,9 @@ private async Async.Task<HttpResponseData> Post(HttpRequestData req) {
140137
if (os != null && pool.Os != os) {
141138
return await _context.RequestHandling.NotOk(
142139
req,
143-
new Error(
144-
Code: ErrorCode.INVALID_REQUEST,
145-
Errors: new[] { $"OS mismatch: pool '{poolName}' is configured for '{pool.Os}', but agent is running '{os}'" }),
140+
Error.Create(
141+
ErrorCode.INVALID_REQUEST,
142+
$"OS mismatch: pool '{poolName}' is configured for '{pool.Os}', but agent is running '{os}'"),
146143
"agent registration");
147144
}
148145

src/ApiService/ApiService/Functions/Containers.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ private async Async.Task<HttpResponseData> Get(HttpRequestData req) {
3939
if (container is null) {
4040
return await _context.RequestHandling.NotOk(
4141
req,
42-
new Error(
43-
Code: ErrorCode.INVALID_REQUEST,
44-
Errors: new[] { "invalid container" }),
42+
Error.Create(
43+
ErrorCode.INVALID_REQUEST,
44+
"invalid container"),
4545
context: get.Name.String);
4646
}
4747

@@ -101,9 +101,9 @@ private async Async.Task<HttpResponseData> Post(HttpRequestData req) {
101101
if (sas is null) {
102102
return await _context.RequestHandling.NotOk(
103103
req,
104-
new Error(
105-
Code: ErrorCode.INVALID_REQUEST,
106-
Errors: new[] { "invalid container" }),
104+
Error.Create(
105+
ErrorCode.INVALID_REQUEST,
106+
"invalid container"),
107107
context: post.Name.String);
108108
}
109109

src/ApiService/ApiService/Functions/Download.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,19 @@ private async Async.Task<HttpResponseData> Get(HttpRequestData req) {
2525
if (queryContainer is null || !Container.TryParse(queryContainer, out var container)) {
2626
return await _context.RequestHandling.NotOk(
2727
req,
28-
new Error(
28+
Error.Create(
2929
ErrorCode.INVALID_REQUEST,
30-
new string[] { "'container' query parameter must be provided and valid" }),
30+
"'container' query parameter must be provided and valid"),
3131
"download");
3232
}
3333

3434
var filename = query["filename"];
3535
if (filename is null) {
3636
return await _context.RequestHandling.NotOk(
3737
req,
38-
new Error(
38+
Error.Create(
3939
ErrorCode.INVALID_REQUEST,
40-
new string[] { "'filename' query parameter must be provided" }),
40+
"'filename' query parameter must be provided"),
4141
"download");
4242
}
4343

src/ApiService/ApiService/Functions/Jobs.cs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,7 @@ private async Task<HttpResponseData> Post(HttpRequestData req) {
5959
if (containerSas is null) {
6060
return await _context.RequestHandling.NotOk(
6161
req,
62-
new Error(
63-
Code: ErrorCode.UNABLE_TO_CREATE_CONTAINER,
64-
Errors: new string[] { "unable to create logs container " }),
62+
Error.Create(ErrorCode.UNABLE_TO_CREATE_CONTAINER, "unable to create logs container "),
6563
"logs");
6664
}
6765

@@ -73,9 +71,9 @@ private async Task<HttpResponseData> Post(HttpRequestData req) {
7371
_logTracer.WithTag("HttpRequest", "POST").WithHttpStatus(r.ErrorV).Error($"failed to insert job {job.JobId:Tag:JobId}");
7472
return await _context.RequestHandling.NotOk(
7573
req,
76-
new Error(
77-
Code: ErrorCode.UNABLE_TO_CREATE,
78-
Errors: new string[] { "unable to create job " }
74+
Error.Create(
75+
ErrorCode.UNABLE_TO_CREATE,
76+
"unable to create job"
7977
),
8078
"job");
8179
}
@@ -95,9 +93,9 @@ private async Task<HttpResponseData> Delete(HttpRequestData req) {
9593
if (job is null) {
9694
return await _context.RequestHandling.NotOk(
9795
req,
98-
new Error(
99-
Code: ErrorCode.INVALID_JOB,
100-
Errors: new string[] { "no such job" }),
96+
Error.Create(
97+
ErrorCode.INVALID_JOB,
98+
"no such job"),
10199
context: jobId.ToString());
102100
}
103101

@@ -124,9 +122,7 @@ private async Task<HttpResponseData> Get(HttpRequestData req) {
124122
if (job is null) {
125123
return await _context.RequestHandling.NotOk(
126124
req,
127-
new Error(
128-
Code: ErrorCode.INVALID_JOB,
129-
Errors: new string[] { "no such job" }),
125+
Error.Create(ErrorCode.INVALID_JOB, "no such job"),
130126
context: jobId.ToString());
131127
}
132128

src/ApiService/ApiService/Functions/Migrations/JinjaToScriban.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ await notifications.Select(notification => notification.NotificationId).ToListAs
7272
_log.Info($"Migrated notification: {notification.NotificationId} to jinja");
7373
} else {
7474
failedNotificationIds.Add(notification.NotificationId);
75-
_log.Error(new Error(ErrorCode.UNABLE_TO_UPDATE, new[] { r.ErrorV.Reason, r.ErrorV.Status.ToString() }));
75+
_log.Error(Error.Create(ErrorCode.UNABLE_TO_UPDATE, r.ErrorV.Reason, r.ErrorV.Status.ToString()));
7676
}
7777
} catch (Exception ex) {
7878
failedNotificationIds.Add(notification.NotificationId);

src/ApiService/ApiService/Functions/Node.cs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ private async Async.Task<HttpResponseData> Get(HttpRequestData req) {
3838
if (node is null) {
3939
return await _context.RequestHandling.NotOk(
4040
req,
41-
new Error(
42-
Code: ErrorCode.UNABLE_TO_FIND,
43-
Errors: new string[] { "unable to find node" }),
41+
Error.Create(ErrorCode.UNABLE_TO_FIND, "unable to find node"),
4442
context: machineId.ToString());
4543
}
4644

@@ -94,9 +92,7 @@ private async Async.Task<HttpResponseData> Patch(HttpRequestData req) {
9492
if (node is null) {
9593
return await _context.RequestHandling.NotOk(
9694
req,
97-
new Error(
98-
Code: ErrorCode.UNABLE_TO_FIND,
99-
Errors: new string[] { "unable to find node" }),
95+
Error.Create(ErrorCode.UNABLE_TO_FIND, "unable to find node"),
10096
context: patch.MachineId.ToString());
10197
}
10298

@@ -130,9 +126,7 @@ private async Async.Task<HttpResponseData> Post(HttpRequestData req) {
130126
if (node is null) {
131127
return await _context.RequestHandling.NotOk(
132128
req,
133-
new Error(
134-
Code: ErrorCode.UNABLE_TO_FIND,
135-
Errors: new string[] { "unable to find node" }),
129+
Error.Create(ErrorCode.UNABLE_TO_FIND, "unable to find node"),
136130
context: post.MachineId.ToString());
137131
}
138132

@@ -166,9 +160,7 @@ private async Async.Task<HttpResponseData> Delete(HttpRequestData req) {
166160
if (node is null) {
167161
return await _context.RequestHandling.NotOk(
168162
req,
169-
new Error(
170-
Code: ErrorCode.UNABLE_TO_FIND,
171-
new string[] { "unable to find node" }),
163+
Error.Create(ErrorCode.UNABLE_TO_FIND, "unable to find node"),
172164
context: delete.MachineId.ToString());
173165
}
174166

src/ApiService/ApiService/Functions/NodeAddSshKey.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ private async Async.Task<HttpResponseData> Post(HttpRequestData req) {
3030
if (node == null) {
3131
return await _context.RequestHandling.NotOk(
3232
req,
33-
new Error(ErrorCode.UNABLE_TO_FIND, new[] { "unable to find node" }),
33+
Error.Create(ErrorCode.UNABLE_TO_FIND, "unable to find node"),
3434
$"{request.OkV.MachineId}");
3535
}
3636

src/ApiService/ApiService/Functions/Notifications.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,18 @@ private async Async.Task<HttpResponseData> Delete(HttpRequestData req) {
6161
var entries = await _context.NotificationOperations.SearchByPartitionKeys(new[] { $"{request.OkV.NotificationId}" }).ToListAsync();
6262

6363
if (entries.Count == 0) {
64-
return await _context.RequestHandling.NotOk(req, new Error(ErrorCode.INVALID_REQUEST, new[] { "unable to find notification" }), context: "notification delete");
64+
return await _context.RequestHandling.NotOk(req, Error.Create(ErrorCode.INVALID_REQUEST, "unable to find notification"), context: "notification delete");
6565
}
6666

6767
if (entries.Count > 1) {
68-
return await _context.RequestHandling.NotOk(req, new Error(ErrorCode.INVALID_REQUEST, new[] { "error identifying Notification" }), context: "notification delete");
68+
return await _context.RequestHandling.NotOk(req, Error.Create(ErrorCode.INVALID_REQUEST, "error identifying Notification"), context: "notification delete");
6969
}
7070

7171
var result = await _context.NotificationOperations.Delete(entries[0]);
7272

7373
if (!result.IsOk) {
7474
var (status, error) = result.ErrorV;
75-
return await _context.RequestHandling.NotOk(req, new Error(ErrorCode.UNABLE_TO_UPDATE, new[] { error }), "notification delete");
75+
return await _context.RequestHandling.NotOk(req, Error.Create(ErrorCode.UNABLE_TO_UPDATE, error), "notification delete");
7676
}
7777

7878
var response = req.CreateResponse(HttpStatusCode.OK);

0 commit comments

Comments
 (0)