symphony 0.1.4

Eclipse Symphony Target Provider Rust binding
Documentation
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
/*
 * Copyright (c) Microsoft Corporation and others.
 * Licensed under the MIT license.
 * SPDX-License-Identifier: MIT
 */

use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::time::SystemTime;

use serde_json::Value;

pub type ProviderConfig = Value;

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct ValidationRule {
    #[serde(rename = "requiredType")]
    pub required_component_type: String,
    #[serde(rename = "componentValidationRule")]
    pub component_validation_rule: ComponentValidationRule,
    #[serde(rename = "sidecarValidationRule")]
    pub sidecar_validation_rule: ComponentValidationRule,
    #[serde(rename = "allowSidecar")]
    pub allow_sidecar: bool,
    #[serde(rename = "supportScopes")]
    pub scope_isolation: bool,
    #[serde(rename = "instanceIsolation")]
    pub instance_isolation: bool,
}

impl Default for ValidationRule {
    fn default() -> Self {
        ValidationRule {
            required_component_type: "".to_string(),
            component_validation_rule: ComponentValidationRule {
                required_component_type: "".to_string(),
                change_detection_properties: vec![PropertyDesc {
                    ignore_case: true,
                    is_component_name: false,
                    name: "*".to_string(),
                    skip_if_missing: true,
                    prefix_match: false,
                }],
                change_detection_metadata: vec![],
                required_properties: vec![],
                optional_properties: vec![],
                required_metadata: vec![],
                optional_metadata: vec![],
            },
            sidecar_validation_rule: ComponentValidationRule {
                required_component_type: "".to_string(),
                change_detection_properties: vec![],
                change_detection_metadata: vec![],
                required_properties: vec![],
                optional_properties: vec![],
                required_metadata: vec![],
                optional_metadata: vec![],
            },
            allow_sidecar: true,
            scope_isolation: true,
            instance_isolation: true,
        }
    }
}

#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct DeploymentSpec {
    pub solution_name: String,
    pub solution: SolutionState,
    pub instance: InstanceState,
    pub targets: HashMap<String, TargetState>,
    pub devices: Option<Vec<DeviceSpec>>,
    pub assignments: Option<HashMap<String, String>>,
    pub component_start_index: Option<i32>,
    pub component_end_index: Option<i32>,
    pub active_target: Option<String>,
    pub generation: Option<String>,
    pub object_namespace: Option<String>,
    pub hash: Option<String>,
}

impl DeploymentSpec {
    /// Creates an empty `DeploymentSpec` with default values.
    pub fn empty() -> Self {
        DeploymentSpec {
            solution_name: String::new(),
            solution: SolutionState {
                metadata: ObjectMeta {
                    namespace: None,
                    name: None,
                    generation: None,
                    labels: None,
                    annotations: None,
                },
                spec: None,
            },
            instance: InstanceState {
                metadata: ObjectMeta {
                    namespace: None,
                    name: None,
                    generation: None,
                    labels: None,
                    annotations: None,
                },
                spec: None,
                status: InstanceStatus {}, // Assuming `InstanceStatus` has a default implementation
            },
            targets: HashMap::new(),
            devices: None,
            assignments: None,
            component_start_index: None,
            component_end_index: None,
            active_target: None,
            generation: None,
            object_namespace: None,
            hash: None,
        }
    }
}

#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct ComponentSpec {
    pub name: String,
    #[serde(rename = "type")]
    pub component_type: Option<String>,
    pub metadata: Option<HashMap<String, String>>,
    pub properties: Option<HashMap<String, serde_json::Value>>,
    pub parameters: Option<HashMap<String, String>>,
    pub routes: Option<Vec<RouteSpec>>,
    pub constraints: Option<String>,
    pub dependencies: Option<Vec<String>>,
    pub skills: Option<Vec<String>>,
    pub sidecars: Option<Vec<SidecarSpec>>,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct PropertyDesc {
    pub name: String,
    #[serde(rename = "ignoreCase")]
    pub ignore_case: bool,
    #[serde(rename = "skipIfMissing")]
    pub skip_if_missing: bool,
    #[serde(rename = "prefixMatch")]
    pub prefix_match: bool,
    #[serde(rename = "isComponentName")]
    pub is_component_name: bool,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct ComponentValidationRule {
    #[serde(rename = "requiredType")]
    pub required_component_type: String,
    #[serde(rename = "changeDetection")]
    pub change_detection_properties: Vec<PropertyDesc>,
    #[serde(rename = "changeDetectionMetadata")]
    pub change_detection_metadata: Vec<PropertyDesc>,
    #[serde(rename = "requiredProperties")]
    pub required_properties: Vec<String>,
    #[serde(rename = "optionalProperties")]
    pub optional_properties: Vec<String>,
    #[serde(rename = "requiredMetadata")]
    pub required_metadata: Vec<String>,
    #[serde(rename = "optionalMetadata")]
    pub optional_metadata: Vec<String>,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct RouteSpec {
    pub route: String,
    #[serde(rename = "type")]
    pub route_type: String,
    pub properties: Option<HashMap<String, String>>,
    pub filters: Option<Vec<FilterSpec>>,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct SidecarSpec {
    pub name: Option<String>,
    #[serde(rename = "type")]
    pub sidecar_type: Option<String>,
    pub properties: Option<HashMap<String, serde_json::Value>>,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct ComponentStep {
    pub action: ComponentAction,
    pub component: ComponentSpec,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct DeploymentStep {
    pub target: Option<String>,
    #[serde(default)]
    pub components: Vec<ComponentStep>,
    pub role: String,
    pub is_first: bool,
}

//  impl DeploymentStep {
//     // The get_components method that returns a Vec<ComponentSpec>
//     pub fn get_components(&self) -> Vec<ComponentSpec> {
//         let mut ret = Vec::new();
//         for component_step in &self.components {
//             ret.push(component_step.component.clone());
//         }
//         ret
//     }
// }

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
#[serde(rename_all = "camelCase")]
pub enum ComponentAction {
    Update,
    Delete,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct SolutionState {
    pub metadata: ObjectMeta,
    pub spec: Option<SolutionSpec>,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct SolutionSpec {
    pub display_name: Option<String>,
    pub metadata: Option<HashMap<String, String>>,
    pub components: Option<Vec<ComponentSpec>>,
    pub version: Option<String>,
    pub root_resource: Option<String>,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct InstanceState {
    pub metadata: ObjectMeta,
    pub spec: Option<InstanceSpec>,
    pub status: InstanceStatus,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct InstanceSpec {
    pub display_name: Option<String>,
    pub scope: Option<String>,
    pub parameters: Option<HashMap<String, String>>,
    pub metadata: Option<HashMap<String, String>>,
    pub solution: String,
    pub target: Option<TargetSelector>, // Include TargetSelector
    pub topologies: Option<Vec<TopologySpec>>,
    pub pipelines: Option<Vec<PipelineSpec>>,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct TargetSelector {
    pub name: Option<String>,
    pub selector: Option<HashMap<String, String>>,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct TargetState {
    pub metadata: ObjectMeta,
    pub status: TargetStatus,
    pub spec: Option<TargetSpec>,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct TargetSpec {
    pub display_name: Option<String>,
    pub scope: Option<String>,
    pub metadata: Option<HashMap<String, String>>,
    pub properties: Option<HashMap<String, String>>,
    pub components: Option<Vec<ComponentSpec>>,
    pub constraints: Option<String>,
    pub topologies: Option<Vec<TopologySpec>>,
    pub force_redeploy: Option<bool>,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct DeviceSpec {
    pub display_name: Option<String>,
    pub properties: Option<HashMap<String, String>>,
    pub bindings: Option<Vec<BindingSpec>>,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct BindingSpec {
    pub role: String,
    pub provider: String,
    pub config: Option<HashMap<String, String>>,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct FilterSpec {
    pub direction: String,
    pub filter_type: String,
    pub parameters: Option<HashMap<String, String>>,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct TopologySpec {
    pub device: Option<String>,
    pub selector: Option<HashMap<String, String>>,
    pub bindings: Option<Vec<BindingSpec>>,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct ObjectMeta {
    pub namespace: Option<String>,
    pub name: Option<String>,
    pub generation: Option<String>,
    pub labels: Option<HashMap<String, String>>,
    pub annotations: Option<HashMap<String, String>>,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct InstanceStatus {
    // Fields for instance status
}

#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct TargetStatus {
    // Fields for target status
}

#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct PipelineSpec {
    pub name: String,
    pub skill: String,
    pub parameters: Option<HashMap<String, String>>,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct DeployableStatus {
    pub properties: Option<HashMap<String, String>>,
    pub provisioning_status: ProvisioningStatus,
    pub last_modified: Option<SystemTime>,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct ProvisioningStatus {
    pub operation_id: String,
    pub status: String,
    pub failure_cause: Option<String>,
    pub log_errors: Option<bool>,
    pub error: Option<ErrorType>,
    pub output: Option<HashMap<String, String>>,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct ErrorType {
    pub code: Option<String>,
    pub message: Option<String>,
    pub target: Option<String>,
    pub details: Option<Vec<TargetError>>,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct TargetError {
    pub code: Option<String>,
    pub message: Option<String>,
    pub target: Option<String>,
    pub details: Option<Vec<ComponentError>>,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct ComponentError {
    pub code: Option<String>,
    pub message: Option<String>,
    pub target: Option<String>,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct ComponentResultSpec {
    pub status: State,
    pub message: String,
}

#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[serde(into = "u16", from = "u16")]
pub enum State {
    // HTTP Status codes
    OK = 200,
    Accepted = 202,
    BadRequest = 400,
    Unauthorized = 401,
    Forbidden = 403,
    NotFound = 404,
    MethodNotAllowed = 405,
    Conflict = 409,
    InternalError = 500,

    // Config errors
    BadConfig = 1000,
    MissingConfig = 1001,

    // API invocation errors
    InvalidArgument = 2000,
    APIRedirect = 3030,

    // IO errors
    FileAccessError = 4000,

    // Serialization errors
    SerializationError = 5000,
    DeserializeError = 5001,

    // Async requests
    DeleteRequested = 6000,

    // Operation results
    UpdateFailed = 8001,
    DeleteFailed = 8002,
    ValidateFailed = 8003,
    Updated = 8004,
    Deleted = 8005,

    // Workflow status
    Running = 9994,
    Paused = 9995,
    Done = 9996,
    Delayed = 9997,
    Untouched = 9998,
    NotImplemented = 9999,

    // Detailed error codes
    InitFailed = 10000,
    CreateActionConfigFailed = 10001,
    HelmActionFailed = 10002,
    GetComponentSpecFailed = 10003,
    CreateProjectorFailed = 10004,
    K8sRemoveServiceFailed = 10005,
    K8sRemoveDeploymentFailed = 10006,
    K8sDeploymentFailed = 10007,
    ReadYamlFailed = 10008,
    ApplyYamlFailed = 10009,
    ReadResourcePropertyFailed = 10010,
    ApplyResourceFailed = 10011,
    DeleteYamlFailed = 10012,
    DeleteResourceFailed = 10013,
    CheckResourceStatusFailed = 10014,
    ApplyScriptFailed = 10015,
    RemoveScriptFailed = 10016,
    YamlResourcePropertyNotFound = 10017,
    GetHelmPropertyFailed = 10018,
    HelmChartPullFailed = 10019,
    HelmChartLoadFailed = 10020,
    HelmChartApplyFailed = 10021,
    HelmChartUninstallFailed = 10022,
    IngressApplyFailed = 10023,
    HttpNewRequestFailed = 10024,
    HttpSendRequestFailed = 10025,
    HttpErrorResponse = 10026,
    MqttPublishFailed = 10027,
    MqttApplyFailed = 10028,
    MqttApplyTimeout = 10029,
    ConfigMapApplyFailed = 10030,
    HttpBadWaitStatusCode = 10031,
    HttpNewWaitRequestFailed = 10032,
    HttpSendWaitRequestFailed = 10033,
    HttpErrorWaitResponse = 10034,
    HttpBadWaitExpression = 10035,
    ScriptExecutionFailed = 10036,
    ScriptResultParsingFailed = 10037,
    WaitToGetInstancesFailed = 10038,
    WaitToGetSitesFailed = 10039,
    WaitToGetCatalogsFailed = 10040,
    InvalidWaitObjectType = 10041,
    CatalogsGetFailed = 10042,
    InvalidInstanceCatalog = 10043,
    CreateInstanceFromCatalogFailed = 10044,
    InvalidSolutionCatalog = 10045,
    CreateSolutionFromCatalogFailed = 10046,
    InvalidTargetCatalog = 10047,
    CreateTargetFromCatalogFailed = 10048,
    InvalidCatalogCatalog = 10049,
    CreateCatalogFromCatalogFailed = 10050,
    ParentObjectMissing = 10051,
    ParentObjectCreateFailed = 10052,
    MaterializeBatchFailed = 10053,
    DeleteInstanceFailed = 10054,
    CreateInstanceFailed = 10055,
    DeploymentNotReached = 10056,
    InvalidObjectType = 10057,
    UnsupportedAction = 10058,

    // Instance controller errors
    SolutionGetFailed = 11000,
    TargetCandidatesNotFound = 11001,
    TargetListGetFailed = 11002,
    ObjectInstanceConversionFailed = 11003,
    TimedOut = 11004,

    // Target controller errors
    TargetPropertyNotFound = 12000,
}

impl From<State> for u16 {
    fn from(value: State) -> Self {
        value as u16
    }
}

impl From<u16> for State {
    fn from(value: u16) -> Self {
        match value {
            // HTTP Status codes
            200 => State::OK,
            202 => State::Accepted,
            400 => State::BadRequest,
            401 => State::Unauthorized,
            403 => State::Forbidden,
            404 => State::NotFound,
            405 => State::MethodNotAllowed,
            409 => State::Conflict,
            500 => State::InternalError,

            // Config errors
            1000 => State::BadConfig,
            1001 => State::MissingConfig,

            // API invocation errors
            2000 => State::InvalidArgument,
            3030 => State::APIRedirect,

            // IO errors
            4000 => State::FileAccessError,

            // Serialization errors
            5000 => State::SerializationError,
            5001 => State::DeserializeError,

            // Async requests
            6000 => State::DeleteRequested,

            // Operation results
            8001 => State::UpdateFailed,
            8002 => State::DeleteFailed,
            8003 => State::ValidateFailed,
            8004 => State::Updated,
            8005 => State::Deleted,

            // Workflow status
            9994 => State::Running,
            9995 => State::Paused,
            9996 => State::Done,
            9997 => State::Delayed,
            9998 => State::Untouched,
            9999 => State::NotImplemented,

            // Detailed error codes
            10000 => State::InitFailed,
            10001 => State::CreateActionConfigFailed,
            10002 => State::HelmActionFailed,
            10003 => State::GetComponentSpecFailed,
            10004 => State::CreateProjectorFailed,
            10005 => State::K8sRemoveServiceFailed,
            10006 => State::K8sRemoveDeploymentFailed,
            10007 => State::K8sDeploymentFailed,
            10008 => State::ReadYamlFailed,
            10009 => State::ApplyYamlFailed,
            10010 => State::ReadResourcePropertyFailed,
            10011 => State::ApplyResourceFailed,
            10012 => State::DeleteYamlFailed,
            10013 => State::DeleteResourceFailed,
            10014 => State::CheckResourceStatusFailed,
            10015 => State::ApplyScriptFailed,
            10016 => State::RemoveScriptFailed,
            10017 => State::YamlResourcePropertyNotFound,
            10018 => State::GetHelmPropertyFailed,
            10019 => State::HelmChartPullFailed,
            10020 => State::HelmChartLoadFailed,
            10021 => State::HelmChartApplyFailed,
            10022 => State::HelmChartUninstallFailed,
            10023 => State::IngressApplyFailed,
            10024 => State::HttpNewRequestFailed,
            10025 => State::HttpSendRequestFailed,
            10026 => State::HttpErrorResponse,
            10027 => State::MqttPublishFailed,
            10028 => State::MqttApplyFailed,
            10029 => State::MqttApplyTimeout,
            10030 => State::ConfigMapApplyFailed,
            10031 => State::HttpBadWaitStatusCode,
            10032 => State::HttpNewWaitRequestFailed,
            10033 => State::HttpSendWaitRequestFailed,
            10034 => State::HttpErrorWaitResponse,
            10035 => State::HttpBadWaitExpression,
            10036 => State::ScriptExecutionFailed,
            10037 => State::ScriptResultParsingFailed,
            10038 => State::WaitToGetInstancesFailed,
            10039 => State::WaitToGetSitesFailed,
            10040 => State::WaitToGetCatalogsFailed,
            10041 => State::InvalidWaitObjectType,
            10042 => State::CatalogsGetFailed,
            10043 => State::InvalidInstanceCatalog,
            10044 => State::CreateInstanceFromCatalogFailed,
            10045 => State::InvalidSolutionCatalog,
            10046 => State::CreateSolutionFromCatalogFailed,
            10047 => State::InvalidTargetCatalog,
            10048 => State::CreateTargetFromCatalogFailed,
            10049 => State::InvalidCatalogCatalog,
            10050 => State::CreateCatalogFromCatalogFailed,
            10051 => State::ParentObjectMissing,
            10052 => State::ParentObjectCreateFailed,
            10053 => State::MaterializeBatchFailed,
            10054 => State::DeleteInstanceFailed,
            10055 => State::CreateInstanceFailed,
            10056 => State::DeploymentNotReached,
            10057 => State::InvalidObjectType,
            10058 => State::UnsupportedAction,

            // Instance controller errors
            11000 => State::SolutionGetFailed,
            11001 => State::TargetCandidatesNotFound,
            11002 => State::TargetListGetFailed,
            11003 => State::ObjectInstanceConversionFailed,
            11004 => State::TimedOut,

            // Target controller errors
            12000 => State::TargetPropertyNotFound,

            _ => State::InternalError, // Default case for unknown values
        }
    }
}