Skip to content

Commit 709a6a0

Browse files
author
Mitchell
committed
feat: add CreateLocalDeployment IPC support (C + C++ + Rust)
Add CreateLocalDeployment operation to the C, C++, and Rust SDK, enabling components to trigger local deployments via IPC without shelling out to greengrass-cli. Changes since initial review: - Full schema: GgCreateLocalDeploymentArgs struct exposes all 6 fields (componentToConfiguration, rootComponentVersionsToAdd, rootComponentsToRemove, recipeDirectoryPath, artifactsDirectoryPath, failureHandlingPolicy) - C++ wrapper: Client::create_local_deployment() added - README: CreateLocalDeployment section with C/C++/Rust examples - Mock packets: renamed ACCEPTED_HEADERS to RESPONSE_HEADERS per real IPC traces captured via GGLite-IPC-EventStream-Sniffer against Classic Nucleus v2.17.0 - Doc comments: clarified Classic vs Lite behavior (Lite has native support via ggdeploymentd, no Cli dep or ACL required) Testing: - nix flake check: 17/17 checks pass (formatting, namespacing, spelling, IWYU, C tests 45/45, Rust tests 28/28, cross-compile x86_64 + aarch64 + armv7l) - Integration: cache-proxy-bridge/server/common all compile and pass 172 tests with the updated SDK vendored in
1 parent 494a597 commit 709a6a0

14 files changed

Lines changed: 1905 additions & 1 deletion

File tree

README.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,77 @@ The following Greengrass v2 IPC operations are currently supported by this SDK:
3131
- [UpdateThingShadow](https://docs.aws.amazon.com/greengrass/v2/developerguide/ipc-local-shadows.html#ipc-operation-updatethingshadow)
3232
- [DeleteThingShadow](https://docs.aws.amazon.com/greengrass/v2/developerguide/ipc-local-shadows.html#ipc-operation-deletethingshadow)
3333
- [ListNamedShadowsForThing](https://docs.aws.amazon.com/greengrass/v2/developerguide/ipc-local-shadows.html#ipc-operation-listnamedshadowsforthing)
34+
- [CreateLocalDeployment](https://docs.aws.amazon.com/greengrass/v2/developerguide/ipc-local-deployments-components.html#ipc-operation-createlocaldeployment)
35+
36+
## CreateLocalDeployment
37+
38+
Creates a local deployment to apply component configuration changes or
39+
add/remove components on the device.
40+
41+
> **Greengrass Classic vs Lite:** On Greengrass Classic, this operation requires
42+
> a dependency on `aws.greengrass.Cli` and an appropriate ACL policy in your
43+
> recipe. On Greengrass Nucleus Lite, CreateLocalDeployment is natively
44+
> supported — no additional dependency or ACL is needed.
45+
46+
### GgCreateLocalDeploymentArgs Fields
47+
48+
| Field | Type | Description |
49+
| -------------------------------- | ----------------- | ----------------------------------------------------------- |
50+
| `component_to_configuration` | `GgObject` (map) | Map of component names to configuration objects to merge |
51+
| `root_component_versions_to_add` | `GgObject` (map) | Map of component names to version strings to add |
52+
| `root_components_to_remove` | `GgObject` (list) | List of component names to remove |
53+
| `recipe_directory_path` | `GgBuffer` | Path to directory containing component recipes |
54+
| `artifacts_directory_path` | `GgBuffer` | Path to directory containing component artifacts |
55+
| `failure_handling_policy` | `GgBuffer` | Failure handling policy (e.g. `"ROLLBACK"`, `"DO_NOTHING"`) |
56+
57+
### C Example
58+
59+
```c
60+
#include "ggipc.h"
61+
62+
GgCreateLocalDeploymentArgs args = {0};
63+
// Set component configuration merge
64+
args.component_to_configuration = my_config_map;
65+
66+
uint8_t id_mem[64];
67+
GgBuffer deployment_id = {0};
68+
69+
GgError err = ggipc_create_local_deployment(
70+
&args,
71+
(GgBuffer){.data = id_mem, .len = sizeof(id_mem)},
72+
&deployment_id
73+
);
74+
```
75+
76+
### C++ Example
77+
78+
```cpp
79+
#include "gg_ipc/client.hpp"
80+
81+
GgCreateLocalDeploymentArgs args{};
82+
args.component_to_configuration = my_config_map;
83+
84+
std::array<std::byte, 64> id_mem;
85+
std::string_view deployment_id;
86+
87+
auto err = client.create_local_deployment(args, id_mem, &deployment_id);
88+
```
89+
90+
### Rust Example
91+
92+
```rust
93+
use aws_greengrass_component_sdk::Sdk;
94+
use std::mem::MaybeUninit;
95+
96+
let mut id_mem = [MaybeUninit::uninit(); 64];
97+
let deployment_id = sdk.create_local_deployment(
98+
config_map,
99+
&mut id_mem,
100+
)?;
101+
```
102+
103+
> **Note:** The Rust API currently only exposes `component_to_configuration`.
104+
> For other fields, use the generic `call()` method.
34105
35106
## Sample Greengrass Components
36107

cpp/include/gg/ipc/client.hpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <utility>
2323

2424
extern "C" {
25+
#include <gg/ipc/client.h>
2526
#include <gg/ipc/types.h>
2627
}
2728

@@ -162,6 +163,23 @@ class Client {
162163
/// <https://docs.aws.amazon.com/greengrass/v2/developerguide/ipc-local-deployments-components.html#ipc-operation-restartcomponent>
163164
std::error_code restart_component(std::string_view component_name) noexcept;
164165

166+
/// Create a local deployment on the core device.
167+
/// Triggers a local deployment that can merge configuration into
168+
/// components, add/remove root components, and specify local
169+
/// recipe/artifact paths.
170+
///
171+
/// On Classic Nucleus: requires a dependency on `aws.greengrass.Cli` and an
172+
/// access-control policy allowing `aws.greengrass#CreateLocalDeployment`.
173+
/// On Nucleus Lite: handled natively by ggdeploymentd — no dependency or
174+
/// ACL required.
175+
/// See:
176+
/// <https://docs.aws.amazon.com/greengrass/v2/developerguide/ipc-local-deployments-components.html#ipc-operation-createlocaldeployment>
177+
std::error_code create_local_deployment(
178+
const GgCreateLocalDeploymentArgs &args,
179+
std::span<std::byte> deployment_id_mem = {},
180+
std::string_view *deployment_id = nullptr
181+
) noexcept;
182+
165183
/// Get component configuration value.
166184
/// Retrieves configuration for the specified key path.
167185
/// Pass empty span for complete config.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// aws-greengrass-component-sdk - Lightweight AWS IoT Greengrass SDK
2+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
#include <gg/ipc/client.hpp>
6+
#include <cstddef>
7+
#include <span>
8+
#include <string_view>
9+
#include <system_error>
10+
11+
extern "C" {
12+
#include <gg/ipc/client.h>
13+
}
14+
15+
namespace gg::ipc {
16+
17+
std::error_code Client::create_local_deployment(
18+
const GgCreateLocalDeploymentArgs &args,
19+
std::span<std::byte> deployment_id_mem,
20+
std::string_view *deployment_id
21+
) noexcept {
22+
GgBuffer id_mem = { reinterpret_cast<uint8_t *>(deployment_id_mem.data()),
23+
deployment_id_mem.size() };
24+
GgBuffer id_out = {};
25+
auto err = ggipc_create_local_deployment(
26+
&args, id_mem, deployment_id != nullptr ? &id_out : nullptr
27+
);
28+
if ((deployment_id != nullptr) && (err == GG_ERR_OK)) {
29+
*deployment_id
30+
= { reinterpret_cast<const char *>(id_out.data), id_out.len };
31+
}
32+
return err;
33+
}
34+
35+
}

0 commit comments

Comments
 (0)