-
Notifications
You must be signed in to change notification settings - Fork 40
/
http_entrypoints.rs
990 lines (926 loc) · 35.7 KB
/
http_entrypoints.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
//! Handler functions (entrypoints) for HTTP APIs internal to the control plane
use super::params::{OximeterInfo, RackInitializationRequest};
use crate::context::ApiContext;
use dropshot::ApiDescription;
use dropshot::Body;
use dropshot::FreeformBody;
use dropshot::HttpError;
use dropshot::HttpResponseCreated;
use dropshot::HttpResponseDeleted;
use dropshot::HttpResponseOk;
use dropshot::HttpResponseUpdatedNoContent;
use dropshot::Path;
use dropshot::Query;
use dropshot::RequestContext;
use dropshot::ResultsPage;
use dropshot::TypedBody;
use nexus_internal_api::*;
use nexus_types::deployment::Blueprint;
use nexus_types::deployment::BlueprintMetadata;
use nexus_types::deployment::BlueprintTarget;
use nexus_types::deployment::BlueprintTargetSet;
use nexus_types::deployment::ClickhousePolicy;
use nexus_types::external_api::params::PhysicalDiskPath;
use nexus_types::external_api::params::SledSelector;
use nexus_types::external_api::params::UninitializedSledId;
use nexus_types::external_api::shared::ProbeInfo;
use nexus_types::external_api::shared::UninitializedSled;
use nexus_types::external_api::views::SledPolicy;
use nexus_types::internal_api::params::InstanceMigrateRequest;
use nexus_types::internal_api::params::SledAgentInfo;
use nexus_types::internal_api::params::SwitchPutRequest;
use nexus_types::internal_api::params::SwitchPutResponse;
use nexus_types::internal_api::views::to_list;
use nexus_types::internal_api::views::BackgroundTask;
use nexus_types::internal_api::views::DemoSaga;
use nexus_types::internal_api::views::Ipv4NatEntryView;
use nexus_types::internal_api::views::Saga;
use omicron_common::api::external::http_pagination::data_page_params_for;
use omicron_common::api::external::http_pagination::PaginatedById;
use omicron_common::api::external::http_pagination::ScanById;
use omicron_common::api::external::http_pagination::ScanParams;
use omicron_common::api::external::Instance;
use omicron_common::api::internal::nexus::DiskRuntimeState;
use omicron_common::api::internal::nexus::DownstairsClientStopRequest;
use omicron_common::api::internal::nexus::DownstairsClientStopped;
use omicron_common::api::internal::nexus::ProducerEndpoint;
use omicron_common::api::internal::nexus::ProducerRegistrationResponse;
use omicron_common::api::internal::nexus::RepairFinishInfo;
use omicron_common::api::internal::nexus::RepairProgress;
use omicron_common::api::internal::nexus::RepairStartInfo;
use omicron_common::api::internal::nexus::SledVmmState;
use omicron_common::update::ArtifactId;
use omicron_uuid_kinds::GenericUuid;
use omicron_uuid_kinds::InstanceUuid;
use std::collections::BTreeMap;
type NexusApiDescription = ApiDescription<ApiContext>;
/// Returns a description of the internal nexus API
pub(crate) fn internal_api() -> NexusApiDescription {
nexus_internal_api_mod::api_description::<NexusInternalApiImpl>()
.expect("registered API endpoints successfully")
}
enum NexusInternalApiImpl {}
impl NexusInternalApi for NexusInternalApiImpl {
type Context = ApiContext;
async fn sled_agent_get(
rqctx: RequestContext<Self::Context>,
path_params: Path<SledAgentPathParam>,
) -> Result<HttpResponseOk<SledAgentInfo>, HttpError> {
let apictx = &rqctx.context().context;
let nexus = &apictx.nexus;
let opctx = crate::context::op_context_for_internal_api(&rqctx).await;
let path = path_params.into_inner();
let sled_id = &path.sled_id;
let handler = async {
let (.., sled) = nexus
.sled_lookup(&opctx, &sled_id.into_untyped_uuid())?
.fetch()
.await?;
Ok(HttpResponseOk(sled.into()))
};
apictx
.internal_latencies
.instrument_dropshot_handler(&rqctx, handler)
.await
}
async fn sled_agent_put(
rqctx: RequestContext<Self::Context>,
path_params: Path<SledAgentPathParam>,
sled_info: TypedBody<SledAgentInfo>,
) -> Result<HttpResponseUpdatedNoContent, HttpError> {
let apictx = &rqctx.context().context;
let nexus = &apictx.nexus;
let opctx = crate::context::op_context_for_internal_api(&rqctx).await;
let path = path_params.into_inner();
let info = sled_info.into_inner();
let sled_id = &path.sled_id;
let handler = async {
nexus
.upsert_sled(&opctx, sled_id.into_untyped_uuid(), info)
.await?;
Ok(HttpResponseUpdatedNoContent())
};
apictx
.internal_latencies
.instrument_dropshot_handler(&rqctx, handler)
.await
}
async fn sled_firewall_rules_request(
rqctx: RequestContext<Self::Context>,
path_params: Path<SledAgentPathParam>,
) -> Result<HttpResponseUpdatedNoContent, HttpError> {
let apictx = &rqctx.context().context;
let nexus = &apictx.nexus;
let opctx = crate::context::op_context_for_internal_api(&rqctx).await;
let path = path_params.into_inner();
let sled_id = &path.sled_id;
let handler = async {
nexus
.sled_request_firewall_rules(
&opctx,
sled_id.into_untyped_uuid(),
)
.await?;
Ok(HttpResponseUpdatedNoContent())
};
apictx
.internal_latencies
.instrument_dropshot_handler(&rqctx, handler)
.await
}
async fn rack_initialization_complete(
rqctx: RequestContext<Self::Context>,
path_params: Path<RackPathParam>,
info: TypedBody<RackInitializationRequest>,
) -> Result<HttpResponseUpdatedNoContent, HttpError> {
let apictx = &rqctx.context().context;
let nexus = &apictx.nexus;
let path = path_params.into_inner();
let request = info.into_inner();
let opctx = crate::context::op_context_for_internal_api(&rqctx).await;
nexus.rack_initialize(&opctx, path.rack_id, request).await?;
Ok(HttpResponseUpdatedNoContent())
}
async fn switch_put(
rqctx: RequestContext<Self::Context>,
path_params: Path<SwitchPathParam>,
body: TypedBody<SwitchPutRequest>,
) -> Result<HttpResponseOk<SwitchPutResponse>, HttpError> {
let apictx = &rqctx.context().context;
let handler = async {
let nexus = &apictx.nexus;
let path = path_params.into_inner();
let switch = body.into_inner();
nexus.switch_upsert(path.switch_id, switch).await?;
Ok(HttpResponseOk(SwitchPutResponse {}))
};
apictx
.internal_latencies
.instrument_dropshot_handler(&rqctx, handler)
.await
}
async fn cpapi_instances_put(
rqctx: RequestContext<Self::Context>,
path_params: Path<VmmPathParam>,
new_runtime_state: TypedBody<SledVmmState>,
) -> Result<HttpResponseUpdatedNoContent, HttpError> {
let apictx = &rqctx.context().context;
let nexus = &apictx.nexus;
let path = path_params.into_inner();
let new_state = new_runtime_state.into_inner();
let opctx = crate::context::op_context_for_internal_api(&rqctx).await;
let handler = async {
nexus
.notify_vmm_updated(&opctx, path.propolis_id, &new_state)
.await?;
Ok(HttpResponseUpdatedNoContent())
};
apictx
.internal_latencies
.instrument_dropshot_handler(&rqctx, handler)
.await
}
async fn instance_migrate(
rqctx: RequestContext<Self::Context>,
path_params: Path<InstancePathParam>,
migrate_params: TypedBody<InstanceMigrateRequest>,
) -> Result<HttpResponseOk<Instance>, HttpError> {
let apictx = &rqctx.context().context;
let nexus = &apictx.nexus;
let path = path_params.into_inner();
let migrate = migrate_params.into_inner();
let handler = async {
let opctx =
crate::context::op_context_for_internal_api(&rqctx).await;
let instance = nexus
.instance_migrate(
&opctx,
InstanceUuid::from_untyped_uuid(path.instance_id),
migrate,
)
.await?;
Ok(HttpResponseOk(instance.into()))
};
apictx
.internal_latencies
.instrument_dropshot_handler(&rqctx, handler)
.await
}
async fn cpapi_disks_put(
rqctx: RequestContext<Self::Context>,
path_params: Path<DiskPathParam>,
new_runtime_state: TypedBody<DiskRuntimeState>,
) -> Result<HttpResponseUpdatedNoContent, HttpError> {
let apictx = &rqctx.context().context;
let nexus = &apictx.nexus;
let path = path_params.into_inner();
let new_state = new_runtime_state.into_inner();
let handler = async {
let opctx =
crate::context::op_context_for_internal_api(&rqctx).await;
nexus.notify_disk_updated(&opctx, path.disk_id, &new_state).await?;
Ok(HttpResponseUpdatedNoContent())
};
apictx
.internal_latencies
.instrument_dropshot_handler(&rqctx, handler)
.await
}
async fn cpapi_volume_remove_read_only_parent(
rqctx: RequestContext<Self::Context>,
path_params: Path<VolumePathParam>,
) -> Result<HttpResponseUpdatedNoContent, HttpError> {
let apictx = &rqctx.context().context;
let nexus = &apictx.nexus;
let path = path_params.into_inner();
let handler = async {
let opctx =
crate::context::op_context_for_internal_api(&rqctx).await;
nexus
.volume_remove_read_only_parent(&opctx, path.volume_id)
.await?;
Ok(HttpResponseUpdatedNoContent())
};
apictx
.internal_latencies
.instrument_dropshot_handler(&rqctx, handler)
.await
}
async fn cpapi_disk_remove_read_only_parent(
rqctx: RequestContext<Self::Context>,
path_params: Path<DiskPathParam>,
) -> Result<HttpResponseUpdatedNoContent, HttpError> {
let apictx = &rqctx.context().context;
let nexus = &apictx.nexus;
let path = path_params.into_inner();
let handler = async {
let opctx =
crate::context::op_context_for_internal_api(&rqctx).await;
nexus.disk_remove_read_only_parent(&opctx, path.disk_id).await?;
Ok(HttpResponseUpdatedNoContent())
};
apictx
.internal_latencies
.instrument_dropshot_handler(&rqctx, handler)
.await
}
async fn cpapi_producers_post(
request_context: RequestContext<Self::Context>,
producer_info: TypedBody<ProducerEndpoint>,
) -> Result<HttpResponseCreated<ProducerRegistrationResponse>, HttpError>
{
let context = &request_context.context().context;
let handler = async {
let nexus = &context.nexus;
let producer_info = producer_info.into_inner();
let opctx =
crate::context::op_context_for_internal_api(&request_context)
.await;
nexus
.assign_producer(&opctx, producer_info)
.await
.map_err(HttpError::from)
.map(|_| {
HttpResponseCreated(ProducerRegistrationResponse {
lease_duration:
crate::app::oximeter::PRODUCER_LEASE_DURATION,
})
})
};
context
.internal_latencies
.instrument_dropshot_handler(&request_context, handler)
.await
}
async fn cpapi_assigned_producers_list(
request_context: RequestContext<Self::Context>,
path_params: Path<CollectorIdPathParams>,
query_params: Query<PaginatedById>,
) -> Result<HttpResponseOk<ResultsPage<ProducerEndpoint>>, HttpError> {
let context = &request_context.context().context;
let handler = async {
let nexus = &context.nexus;
let collector_id = path_params.into_inner().collector_id;
let query = query_params.into_inner();
let pagparams = data_page_params_for(&request_context, &query)?;
let opctx =
crate::context::op_context_for_internal_api(&request_context)
.await;
let producers = nexus
.list_assigned_producers(&opctx, collector_id, &pagparams)
.await?;
Ok(HttpResponseOk(ScanById::results_page(
&query,
producers,
&|_, producer: &ProducerEndpoint| producer.id,
)?))
};
context
.internal_latencies
.instrument_dropshot_handler(&request_context, handler)
.await
}
async fn cpapi_collectors_post(
request_context: RequestContext<Self::Context>,
oximeter_info: TypedBody<OximeterInfo>,
) -> Result<HttpResponseUpdatedNoContent, HttpError> {
let context = &request_context.context().context;
let handler = async {
let nexus = &context.nexus;
let oximeter_info = oximeter_info.into_inner();
let opctx =
crate::context::op_context_for_internal_api(&request_context)
.await;
nexus.upsert_oximeter_collector(&opctx, &oximeter_info).await?;
Ok(HttpResponseUpdatedNoContent())
};
context
.internal_latencies
.instrument_dropshot_handler(&request_context, handler)
.await
}
async fn cpapi_artifact_download(
request_context: RequestContext<Self::Context>,
path_params: Path<ArtifactId>,
) -> Result<HttpResponseOk<FreeformBody>, HttpError> {
let context = &request_context.context().context;
let nexus = &context.nexus;
let opctx =
crate::context::op_context_for_internal_api(&request_context).await;
// TODO: return 404 if the error we get here says that the record isn't found
let body = nexus
.updates_download_artifact(&opctx, path_params.into_inner())
.await?;
Ok(HttpResponseOk(Body::from(body).into()))
}
async fn cpapi_upstairs_repair_start(
rqctx: RequestContext<Self::Context>,
path_params: Path<UpstairsPathParam>,
repair_start_info: TypedBody<RepairStartInfo>,
) -> Result<HttpResponseUpdatedNoContent, HttpError> {
let apictx = &rqctx.context().context;
let nexus = &apictx.nexus;
let path = path_params.into_inner();
let handler = async {
let opctx =
crate::context::op_context_for_internal_api(&rqctx).await;
nexus
.upstairs_repair_start(
&opctx,
path.upstairs_id,
repair_start_info.into_inner(),
)
.await?;
Ok(HttpResponseUpdatedNoContent())
};
apictx
.internal_latencies
.instrument_dropshot_handler(&rqctx, handler)
.await
}
async fn cpapi_upstairs_repair_finish(
rqctx: RequestContext<Self::Context>,
path_params: Path<UpstairsPathParam>,
repair_finish_info: TypedBody<RepairFinishInfo>,
) -> Result<HttpResponseUpdatedNoContent, HttpError> {
let apictx = &rqctx.context().context;
let nexus = &apictx.nexus;
let path = path_params.into_inner();
let handler = async {
let opctx =
crate::context::op_context_for_internal_api(&rqctx).await;
nexus
.upstairs_repair_finish(
&opctx,
path.upstairs_id,
repair_finish_info.into_inner(),
)
.await?;
Ok(HttpResponseUpdatedNoContent())
};
apictx
.internal_latencies
.instrument_dropshot_handler(&rqctx, handler)
.await
}
async fn cpapi_upstairs_repair_progress(
rqctx: RequestContext<Self::Context>,
path_params: Path<UpstairsRepairPathParam>,
repair_progress: TypedBody<RepairProgress>,
) -> Result<HttpResponseUpdatedNoContent, HttpError> {
let apictx = &rqctx.context().context;
let nexus = &apictx.nexus;
let path = path_params.into_inner();
let handler = async {
let opctx =
crate::context::op_context_for_internal_api(&rqctx).await;
nexus
.upstairs_repair_progress(
&opctx,
path.upstairs_id,
path.repair_id,
repair_progress.into_inner(),
)
.await?;
Ok(HttpResponseUpdatedNoContent())
};
apictx
.internal_latencies
.instrument_dropshot_handler(&rqctx, handler)
.await
}
async fn cpapi_downstairs_client_stop_request(
rqctx: RequestContext<Self::Context>,
path_params: Path<UpstairsDownstairsPathParam>,
downstairs_client_stop_request: TypedBody<DownstairsClientStopRequest>,
) -> Result<HttpResponseUpdatedNoContent, HttpError> {
let apictx = &rqctx.context().context;
let nexus = &apictx.nexus;
let path = path_params.into_inner();
let handler = async {
let opctx =
crate::context::op_context_for_internal_api(&rqctx).await;
nexus
.downstairs_client_stop_request_notification(
&opctx,
path.upstairs_id,
path.downstairs_id,
downstairs_client_stop_request.into_inner(),
)
.await?;
Ok(HttpResponseUpdatedNoContent())
};
apictx
.internal_latencies
.instrument_dropshot_handler(&rqctx, handler)
.await
}
async fn cpapi_downstairs_client_stopped(
rqctx: RequestContext<Self::Context>,
path_params: Path<UpstairsDownstairsPathParam>,
downstairs_client_stopped: TypedBody<DownstairsClientStopped>,
) -> Result<HttpResponseUpdatedNoContent, HttpError> {
let apictx = &rqctx.context().context;
let nexus = &apictx.nexus;
let path = path_params.into_inner();
let handler = async {
let opctx =
crate::context::op_context_for_internal_api(&rqctx).await;
nexus
.downstairs_client_stopped_notification(
&opctx,
path.upstairs_id,
path.downstairs_id,
downstairs_client_stopped.into_inner(),
)
.await?;
Ok(HttpResponseUpdatedNoContent())
};
apictx
.internal_latencies
.instrument_dropshot_handler(&rqctx, handler)
.await
}
// Sagas
async fn saga_list(
rqctx: RequestContext<Self::Context>,
query_params: Query<PaginatedById>,
) -> Result<HttpResponseOk<ResultsPage<Saga>>, HttpError> {
let apictx = &rqctx.context().context;
let handler = async {
let nexus = &apictx.nexus;
let query = query_params.into_inner();
let pagparams = data_page_params_for(&rqctx, &query)?;
let opctx =
crate::context::op_context_for_internal_api(&rqctx).await;
let saga_stream = nexus.sagas_list(&opctx, &pagparams).await?;
let view_list = to_list(saga_stream).await;
Ok(HttpResponseOk(ScanById::results_page(
&query,
view_list,
&|_, saga: &Saga| saga.id,
)?))
};
apictx
.internal_latencies
.instrument_dropshot_handler(&rqctx, handler)
.await
}
async fn saga_view(
rqctx: RequestContext<Self::Context>,
path_params: Path<SagaPathParam>,
) -> Result<HttpResponseOk<Saga>, HttpError> {
let apictx = &rqctx.context().context;
let handler = async {
let opctx =
crate::context::op_context_for_internal_api(&rqctx).await;
let nexus = &apictx.nexus;
let path = path_params.into_inner();
let saga = nexus.saga_get(&opctx, path.saga_id).await?;
Ok(HttpResponseOk(saga))
};
apictx
.internal_latencies
.instrument_dropshot_handler(&rqctx, handler)
.await
}
async fn saga_demo_create(
rqctx: RequestContext<Self::Context>,
) -> Result<HttpResponseOk<DemoSaga>, HttpError> {
let apictx = &rqctx.context().context;
let handler = async {
let nexus = &apictx.nexus;
let demo_saga = nexus.saga_demo_create().await?;
Ok(HttpResponseOk(demo_saga))
};
apictx
.internal_latencies
.instrument_dropshot_handler(&rqctx, handler)
.await
}
async fn saga_demo_complete(
rqctx: RequestContext<Self::Context>,
path_params: Path<DemoSagaPathParam>,
) -> Result<HttpResponseUpdatedNoContent, HttpError> {
let apictx = &rqctx.context().context;
let handler = async {
let nexus = &apictx.nexus;
let path = path_params.into_inner();
nexus.saga_demo_complete(path.demo_saga_id)?;
Ok(HttpResponseUpdatedNoContent())
};
apictx
.internal_latencies
.instrument_dropshot_handler(&rqctx, handler)
.await
}
// Background Tasks
async fn bgtask_list(
rqctx: RequestContext<Self::Context>,
) -> Result<HttpResponseOk<BTreeMap<String, BackgroundTask>>, HttpError>
{
let apictx = &rqctx.context().context;
let handler = async {
let nexus = &apictx.nexus;
let opctx =
crate::context::op_context_for_internal_api(&rqctx).await;
let bgtask_list = nexus.bgtasks_list(&opctx).await?;
Ok(HttpResponseOk(bgtask_list))
};
apictx
.internal_latencies
.instrument_dropshot_handler(&rqctx, handler)
.await
}
async fn bgtask_view(
rqctx: RequestContext<Self::Context>,
path_params: Path<BackgroundTaskPathParam>,
) -> Result<HttpResponseOk<BackgroundTask>, HttpError> {
let apictx = &rqctx.context().context;
let handler = async {
let opctx =
crate::context::op_context_for_internal_api(&rqctx).await;
let nexus = &apictx.nexus;
let path = path_params.into_inner();
let bgtask = nexus.bgtask_status(&opctx, &path.bgtask_name).await?;
Ok(HttpResponseOk(bgtask))
};
apictx
.internal_latencies
.instrument_dropshot_handler(&rqctx, handler)
.await
}
async fn bgtask_activate(
rqctx: RequestContext<Self::Context>,
body: TypedBody<BackgroundTasksActivateRequest>,
) -> Result<HttpResponseUpdatedNoContent, HttpError> {
let apictx = &rqctx.context().context;
let handler = async {
let opctx =
crate::context::op_context_for_internal_api(&rqctx).await;
let nexus = &apictx.nexus;
let body = body.into_inner();
nexus.bgtask_activate(&opctx, body.bgtask_names).await?;
Ok(HttpResponseUpdatedNoContent())
};
apictx
.internal_latencies
.instrument_dropshot_handler(&rqctx, handler)
.await
}
// NAT RPW internal APIs
async fn ipv4_nat_changeset(
rqctx: RequestContext<Self::Context>,
path_params: Path<RpwNatPathParam>,
query_params: Query<RpwNatQueryParam>,
) -> Result<HttpResponseOk<Vec<Ipv4NatEntryView>>, HttpError> {
let apictx = &rqctx.context().context;
let handler = async {
let opctx =
crate::context::op_context_for_internal_api(&rqctx).await;
let nexus = &apictx.nexus;
let path = path_params.into_inner();
let query = query_params.into_inner();
let mut changeset = nexus
.datastore()
.ipv4_nat_changeset(&opctx, path.from_gen, query.limit)
.await?;
changeset.sort_by_key(|e| e.gen);
Ok(HttpResponseOk(changeset))
};
apictx
.internal_latencies
.instrument_dropshot_handler(&rqctx, handler)
.await
}
// APIs for managing blueprints
async fn blueprint_list(
rqctx: RequestContext<Self::Context>,
query_params: Query<PaginatedById>,
) -> Result<HttpResponseOk<ResultsPage<BlueprintMetadata>>, HttpError> {
let apictx = &rqctx.context().context;
let handler = async {
let nexus = &apictx.nexus;
let query = query_params.into_inner();
let opctx =
crate::context::op_context_for_internal_api(&rqctx).await;
let pagparams = data_page_params_for(&rqctx, &query)?;
let blueprints = nexus.blueprint_list(&opctx, &pagparams).await?;
Ok(HttpResponseOk(ScanById::results_page(
&query,
blueprints,
&|_, blueprint: &BlueprintMetadata| blueprint.id,
)?))
};
apictx
.internal_latencies
.instrument_dropshot_handler(&rqctx, handler)
.await
}
/// Fetches one blueprint
async fn blueprint_view(
rqctx: RequestContext<Self::Context>,
path_params: Path<nexus_types::external_api::params::BlueprintPath>,
) -> Result<HttpResponseOk<Blueprint>, HttpError> {
let apictx = &rqctx.context().context;
let handler = async {
let opctx =
crate::context::op_context_for_internal_api(&rqctx).await;
let nexus = &apictx.nexus;
let path = path_params.into_inner();
let blueprint =
nexus.blueprint_view(&opctx, path.blueprint_id).await?;
Ok(HttpResponseOk(blueprint))
};
apictx
.internal_latencies
.instrument_dropshot_handler(&rqctx, handler)
.await
}
/// Deletes one blueprint
async fn blueprint_delete(
rqctx: RequestContext<Self::Context>,
path_params: Path<nexus_types::external_api::params::BlueprintPath>,
) -> Result<HttpResponseDeleted, HttpError> {
let apictx = &rqctx.context().context;
let handler = async {
let opctx =
crate::context::op_context_for_internal_api(&rqctx).await;
let nexus = &apictx.nexus;
let path = path_params.into_inner();
nexus.blueprint_delete(&opctx, path.blueprint_id).await?;
Ok(HttpResponseDeleted())
};
apictx
.internal_latencies
.instrument_dropshot_handler(&rqctx, handler)
.await
}
async fn blueprint_target_view(
rqctx: RequestContext<Self::Context>,
) -> Result<HttpResponseOk<BlueprintTarget>, HttpError> {
let apictx = &rqctx.context().context;
let handler = async {
let opctx =
crate::context::op_context_for_internal_api(&rqctx).await;
let nexus = &apictx.nexus;
let target = nexus.blueprint_target_view(&opctx).await?;
Ok(HttpResponseOk(target))
};
apictx
.internal_latencies
.instrument_dropshot_handler(&rqctx, handler)
.await
}
async fn blueprint_target_set(
rqctx: RequestContext<Self::Context>,
target: TypedBody<BlueprintTargetSet>,
) -> Result<HttpResponseOk<BlueprintTarget>, HttpError> {
let apictx = &rqctx.context().context;
let handler = async {
let opctx =
crate::context::op_context_for_internal_api(&rqctx).await;
let nexus = &apictx.nexus;
let target = target.into_inner();
let target = nexus.blueprint_target_set(&opctx, target).await?;
Ok(HttpResponseOk(target))
};
apictx
.internal_latencies
.instrument_dropshot_handler(&rqctx, handler)
.await
}
async fn blueprint_target_set_enabled(
rqctx: RequestContext<Self::Context>,
target: TypedBody<BlueprintTargetSet>,
) -> Result<HttpResponseOk<BlueprintTarget>, HttpError> {
let apictx = &rqctx.context().context;
let handler = async {
let opctx =
crate::context::op_context_for_internal_api(&rqctx).await;
let nexus = &apictx.nexus;
let target = target.into_inner();
let target =
nexus.blueprint_target_set_enabled(&opctx, target).await?;
Ok(HttpResponseOk(target))
};
apictx
.internal_latencies
.instrument_dropshot_handler(&rqctx, handler)
.await
}
async fn blueprint_regenerate(
rqctx: RequestContext<Self::Context>,
) -> Result<HttpResponseOk<Blueprint>, HttpError> {
let apictx = &rqctx.context().context;
let handler = async {
let opctx =
crate::context::op_context_for_internal_api(&rqctx).await;
let nexus = &apictx.nexus;
let result = nexus.blueprint_create_regenerate(&opctx).await?;
Ok(HttpResponseOk(result))
};
apictx
.internal_latencies
.instrument_dropshot_handler(&rqctx, handler)
.await
}
async fn blueprint_import(
rqctx: RequestContext<Self::Context>,
blueprint: TypedBody<Blueprint>,
) -> Result<HttpResponseUpdatedNoContent, HttpError> {
let apictx = &rqctx.context().context;
let handler = async {
let opctx =
crate::context::op_context_for_internal_api(&rqctx).await;
let nexus = &apictx.nexus;
let blueprint = blueprint.into_inner();
nexus.blueprint_import(&opctx, blueprint).await?;
Ok(HttpResponseUpdatedNoContent())
};
apictx
.internal_latencies
.instrument_dropshot_handler(&rqctx, handler)
.await
}
async fn sled_list_uninitialized(
rqctx: RequestContext<Self::Context>,
) -> Result<HttpResponseOk<ResultsPage<UninitializedSled>>, HttpError> {
let apictx = &rqctx.context().context;
let handler = async {
let nexus = &apictx.nexus;
let opctx =
crate::context::op_context_for_internal_api(&rqctx).await;
let sleds = nexus.sled_list_uninitialized(&opctx).await?;
Ok(HttpResponseOk(ResultsPage { items: sleds, next_page: None }))
};
apictx
.internal_latencies
.instrument_dropshot_handler(&rqctx, handler)
.await
}
async fn sled_add(
rqctx: RequestContext<Self::Context>,
sled: TypedBody<UninitializedSledId>,
) -> Result<HttpResponseCreated<SledId>, HttpError> {
let apictx = &rqctx.context().context;
let nexus = &apictx.nexus;
let handler = async {
let opctx =
crate::context::op_context_for_internal_api(&rqctx).await;
let id = nexus.sled_add(&opctx, sled.into_inner()).await?;
Ok(HttpResponseCreated(SledId { id }))
};
apictx
.internal_latencies
.instrument_dropshot_handler(&rqctx, handler)
.await
}
async fn sled_expunge(
rqctx: RequestContext<Self::Context>,
sled: TypedBody<SledSelector>,
) -> Result<HttpResponseOk<SledPolicy>, HttpError> {
let apictx = &rqctx.context().context;
let nexus = &apictx.nexus;
let handler = async {
let opctx =
crate::context::op_context_for_internal_api(&rqctx).await;
let previous_policy =
nexus.sled_expunge(&opctx, sled.into_inner().sled).await?;
Ok(HttpResponseOk(previous_policy))
};
apictx
.internal_latencies
.instrument_dropshot_handler(&rqctx, handler)
.await
}
async fn physical_disk_expunge(
rqctx: RequestContext<Self::Context>,
disk: TypedBody<PhysicalDiskPath>,
) -> Result<HttpResponseUpdatedNoContent, HttpError> {
let apictx = &rqctx.context().context;
let nexus = &apictx.nexus;
let handler = async {
let opctx =
crate::context::op_context_for_internal_api(&rqctx).await;
nexus.physical_disk_expunge(&opctx, disk.into_inner()).await?;
Ok(HttpResponseUpdatedNoContent())
};
apictx
.internal_latencies
.instrument_dropshot_handler(&rqctx, handler)
.await
}
async fn probes_get(
rqctx: RequestContext<Self::Context>,
path_params: Path<ProbePathParam>,
query_params: Query<PaginatedById>,
) -> Result<HttpResponseOk<Vec<ProbeInfo>>, HttpError> {
let apictx = &rqctx.context().context;
let handler = async {
let query = query_params.into_inner();
let path = path_params.into_inner();
let nexus = &apictx.nexus;
let opctx =
crate::context::op_context_for_internal_api(&rqctx).await;
let pagparams = data_page_params_for(&rqctx, &query)?;
Ok(HttpResponseOk(
nexus
.probe_list_for_sled(&opctx, &pagparams, path.sled)
.await?,
))
};
apictx
.internal_latencies
.instrument_dropshot_handler(&rqctx, handler)
.await
}
async fn clickhouse_policy_get(
rqctx: RequestContext<Self::Context>,
) -> Result<HttpResponseOk<ClickhousePolicy>, HttpError> {
let apictx = &rqctx.context().context;
let handler = async {
let nexus = &apictx.nexus;
let opctx =
crate::context::op_context_for_internal_api(&rqctx).await;
match nexus.datastore().clickhouse_policy_get_latest(&opctx).await?
{
Some(policy) => Ok(HttpResponseOk(policy)),
None => Err(HttpError::for_not_found(
None,
"No clickhouse policy in database".into(),
)),
}
};
apictx
.internal_latencies
.instrument_dropshot_handler(&rqctx, handler)
.await
}
async fn clickhouse_policy_set(
rqctx: RequestContext<Self::Context>,
policy: TypedBody<ClickhousePolicy>,
) -> Result<HttpResponseUpdatedNoContent, HttpError> {
let apictx = &rqctx.context().context;
let nexus = &apictx.nexus;
let handler = async {
let opctx =
crate::context::op_context_for_internal_api(&rqctx).await;
nexus
.datastore()
.clickhouse_policy_insert_latest_version(
&opctx,
&policy.into_inner(),
)
.await?;
Ok(HttpResponseUpdatedNoContent())
};
apictx
.internal_latencies
.instrument_dropshot_handler(&rqctx, handler)
.await
}
}