Skip to content

Commit 77d1817

Browse files
bretambroseBret Ambrose
andauthored
Update model and client for GG 2.11 (#483)
Co-authored-by: Bret Ambrose <[email protected]>
1 parent d00fe53 commit 77d1817

File tree

3 files changed

+369
-8
lines changed

3 files changed

+369
-8
lines changed

awsiot/greengrasscoreipc/client.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,40 @@ def close(self): # type: (...) -> concurrent.futures.Future[None]
4242
return super().close()
4343

4444

45+
class CancelLocalDeploymentOperation(model._CancelLocalDeploymentOperation):
46+
"""
47+
CancelLocalDeploymentOperation
48+
49+
Create with GreengrassCoreIPCClient.new_cancel_local_deployment()
50+
"""
51+
52+
def activate(self, request: model.CancelLocalDeploymentRequest): # type: (...) -> concurrent.futures.Future[None]
53+
"""
54+
Activate this operation by sending the initial CancelLocalDeploymentRequest message.
55+
56+
Returns a Future which completes with a result of None if the
57+
request is successfully written to the wire, or an exception if
58+
the request fails to send.
59+
"""
60+
return self._activate(request)
61+
62+
def get_response(self): # type: (...) -> concurrent.futures.Future[model.CancelLocalDeploymentResponse]
63+
"""
64+
Returns a Future which completes with a result of CancelLocalDeploymentResponse,
65+
when the initial response is received, or an exception.
66+
"""
67+
return self._get_response()
68+
69+
def close(self): # type: (...) -> concurrent.futures.Future[None]
70+
"""
71+
Close the operation, whether or not it has completed.
72+
73+
Returns a Future which completes with a result of None
74+
when the operation has closed.
75+
"""
76+
return super().close()
77+
78+
4579
class CreateDebugPasswordOperation(model._CreateDebugPasswordOperation):
4680
"""
4781
CreateDebugPasswordOperation
@@ -1327,6 +1361,16 @@ def new_authorize_client_device_action(self) -> AuthorizeClientDeviceActionOpera
13271361
"""
13281362
return self._new_operation(AuthorizeClientDeviceActionOperation)
13291363

1364+
def new_cancel_local_deployment(self) -> CancelLocalDeploymentOperation:
1365+
"""
1366+
Create a new CancelLocalDeploymentOperation.
1367+
1368+
This operation will not send or receive any data until activate()
1369+
is called. Call activate() when you're ready for callbacks and
1370+
events to fire.
1371+
"""
1372+
return self._new_operation(CancelLocalDeploymentOperation)
1373+
13301374
def new_create_debug_password(self) -> CreateDebugPasswordOperation:
13311375
"""
13321376
Create a new CreateDebugPasswordOperation.

awsiot/greengrasscoreipc/clientv2.py

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def __init__(self, client: typing.Optional[GreengrassCoreIPCClient] = None,
3333
if executor is True:
3434
executor = concurrent.futures.ThreadPoolExecutor()
3535
self.executor = executor
36+
self.ignore_executor_exceptions = False
3637

3738
def close(self, *, executor_wait=True) -> concurrent.futures.Future:
3839
"""
@@ -49,6 +50,9 @@ def close(self, *, executor_wait=True) -> concurrent.futures.Future:
4950
of None if the shutdown was clean and user-initiated.
5051
"""
5152
fut = self.client.close()
53+
54+
# events that arrive during the shutdown process will generate executor exceptions, ignore them
55+
self.ignore_executor_exceptions = True
5256
if self.executor is not None:
5357
self.executor.shutdown(wait=executor_wait)
5458
return fut
@@ -84,7 +88,11 @@ def __create_stream_handler(real_self, operation, on_stream_event, on_stream_err
8488
on_stream_event = real_self.__wrap_error(on_stream_event)
8589
def handler(self, event):
8690
if real_self.executor is not None:
87-
real_self.executor.submit(on_stream_event, event)
91+
try:
92+
real_self.executor.submit(on_stream_event, event)
93+
except RuntimeError:
94+
if not real_self.ignore_executor_exceptions:
95+
raise
8896
else:
8997
on_stream_event(event)
9098
setattr(stream_handler_type, "on_stream_event", handler)
@@ -97,7 +105,11 @@ def handler(self, error):
97105
on_stream_closed = real_self.__wrap_error(on_stream_closed)
98106
def handler(self):
99107
if real_self.executor is not None:
100-
real_self.executor.submit(on_stream_closed)
108+
try:
109+
real_self.executor.submit(on_stream_closed)
110+
except RuntimeError:
111+
if real_self.ignore_executor_exceptions:
112+
raise
101113
else:
102114
on_stream_closed()
103115
setattr(stream_handler_type, "on_stream_closed", handler)
@@ -144,6 +156,29 @@ def authorize_client_device_action_async(self, *,
144156
write_future = operation.activate(request)
145157
return self.__combine_futures(write_future, operation.get_response())
146158

159+
def cancel_local_deployment(self, *,
160+
deployment_id: typing.Optional[str] = None) -> model.CancelLocalDeploymentResponse:
161+
"""
162+
Perform the CancelLocalDeployment operation synchronously.
163+
164+
Args:
165+
deployment_id:
166+
"""
167+
return self.cancel_local_deployment_async(deployment_id=deployment_id).result()
168+
169+
def cancel_local_deployment_async(self, *,
170+
deployment_id: typing.Optional[str] = None): # type: (...) -> concurrent.futures.Future[model.CancelLocalDeploymentResponse]
171+
"""
172+
Perform the CancelLocalDeployment operation asynchronously.
173+
174+
Args:
175+
deployment_id:
176+
"""
177+
request = model.CancelLocalDeploymentRequest(deployment_id=deployment_id)
178+
operation = self.client.new_cancel_local_deployment()
179+
write_future = operation.activate(request)
180+
return self.__combine_futures(write_future, operation.get_response())
181+
147182
def create_debug_password(self) -> model.CreateDebugPasswordResponse:
148183
"""
149184
Perform the CreateDebugPassword operation synchronously.
@@ -168,7 +203,8 @@ def create_local_deployment(self, *,
168203
component_to_configuration: typing.Optional[typing.Dict[str, typing.Dict[str, typing.Any]]] = None,
169204
component_to_run_with_info: typing.Optional[typing.Dict[str, model.RunWithInfo]] = None,
170205
recipe_directory_path: typing.Optional[str] = None,
171-
artifacts_directory_path: typing.Optional[str] = None) -> model.CreateLocalDeploymentResponse:
206+
artifacts_directory_path: typing.Optional[str] = None,
207+
failure_handling_policy: typing.Optional[str] = None) -> model.CreateLocalDeploymentResponse:
172208
"""
173209
Perform the CreateLocalDeployment operation synchronously.
174210
@@ -180,8 +216,9 @@ def create_local_deployment(self, *,
180216
component_to_run_with_info:
181217
recipe_directory_path:
182218
artifacts_directory_path:
219+
failure_handling_policy: FailureHandlingPolicy enum value
183220
"""
184-
return self.create_local_deployment_async(group_name=group_name, root_component_versions_to_add=root_component_versions_to_add, root_components_to_remove=root_components_to_remove, component_to_configuration=component_to_configuration, component_to_run_with_info=component_to_run_with_info, recipe_directory_path=recipe_directory_path, artifacts_directory_path=artifacts_directory_path).result()
221+
return self.create_local_deployment_async(group_name=group_name, root_component_versions_to_add=root_component_versions_to_add, root_components_to_remove=root_components_to_remove, component_to_configuration=component_to_configuration, component_to_run_with_info=component_to_run_with_info, recipe_directory_path=recipe_directory_path, artifacts_directory_path=artifacts_directory_path, failure_handling_policy=failure_handling_policy).result()
185222

186223
def create_local_deployment_async(self, *,
187224
group_name: typing.Optional[str] = None,
@@ -190,7 +227,8 @@ def create_local_deployment_async(self, *,
190227
component_to_configuration: typing.Optional[typing.Dict[str, typing.Dict[str, typing.Any]]] = None,
191228
component_to_run_with_info: typing.Optional[typing.Dict[str, model.RunWithInfo]] = None,
192229
recipe_directory_path: typing.Optional[str] = None,
193-
artifacts_directory_path: typing.Optional[str] = None): # type: (...) -> concurrent.futures.Future[model.CreateLocalDeploymentResponse]
230+
artifacts_directory_path: typing.Optional[str] = None,
231+
failure_handling_policy: typing.Optional[str] = None): # type: (...) -> concurrent.futures.Future[model.CreateLocalDeploymentResponse]
194232
"""
195233
Perform the CreateLocalDeployment operation asynchronously.
196234
@@ -202,8 +240,9 @@ def create_local_deployment_async(self, *,
202240
component_to_run_with_info:
203241
recipe_directory_path:
204242
artifacts_directory_path:
243+
failure_handling_policy: FailureHandlingPolicy enum value
205244
"""
206-
request = model.CreateLocalDeploymentRequest(group_name=group_name, root_component_versions_to_add=root_component_versions_to_add, root_components_to_remove=root_components_to_remove, component_to_configuration=component_to_configuration, component_to_run_with_info=component_to_run_with_info, recipe_directory_path=recipe_directory_path, artifacts_directory_path=artifacts_directory_path)
245+
request = model.CreateLocalDeploymentRequest(group_name=group_name, root_component_versions_to_add=root_component_versions_to_add, root_components_to_remove=root_components_to_remove, component_to_configuration=component_to_configuration, component_to_run_with_info=component_to_run_with_info, recipe_directory_path=recipe_directory_path, artifacts_directory_path=artifacts_directory_path, failure_handling_policy=failure_handling_policy)
207246
operation = self.client.new_create_local_deployment()
208247
write_future = operation.activate(request)
209248
return self.__combine_futures(write_future, operation.get_response())

0 commit comments

Comments
 (0)