Skip to content

Update model and client for GG 2.11 #483

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions awsiot/greengrasscoreipc/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,40 @@ def close(self): # type: (...) -> concurrent.futures.Future[None]
return super().close()


class CancelLocalDeploymentOperation(model._CancelLocalDeploymentOperation):
"""
CancelLocalDeploymentOperation

Create with GreengrassCoreIPCClient.new_cancel_local_deployment()
"""

def activate(self, request: model.CancelLocalDeploymentRequest): # type: (...) -> concurrent.futures.Future[None]
"""
Activate this operation by sending the initial CancelLocalDeploymentRequest message.

Returns a Future which completes with a result of None if the
request is successfully written to the wire, or an exception if
the request fails to send.
"""
return self._activate(request)

def get_response(self): # type: (...) -> concurrent.futures.Future[model.CancelLocalDeploymentResponse]
"""
Returns a Future which completes with a result of CancelLocalDeploymentResponse,
when the initial response is received, or an exception.
"""
return self._get_response()

def close(self): # type: (...) -> concurrent.futures.Future[None]
"""
Close the operation, whether or not it has completed.

Returns a Future which completes with a result of None
when the operation has closed.
"""
return super().close()


class CreateDebugPasswordOperation(model._CreateDebugPasswordOperation):
"""
CreateDebugPasswordOperation
Expand Down Expand Up @@ -1327,6 +1361,16 @@ def new_authorize_client_device_action(self) -> AuthorizeClientDeviceActionOpera
"""
return self._new_operation(AuthorizeClientDeviceActionOperation)

def new_cancel_local_deployment(self) -> CancelLocalDeploymentOperation:
"""
Create a new CancelLocalDeploymentOperation.

This operation will not send or receive any data until activate()
is called. Call activate() when you're ready for callbacks and
events to fire.
"""
return self._new_operation(CancelLocalDeploymentOperation)

def new_create_debug_password(self) -> CreateDebugPasswordOperation:
"""
Create a new CreateDebugPasswordOperation.
Expand Down
51 changes: 45 additions & 6 deletions awsiot/greengrasscoreipc/clientv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def __init__(self, client: typing.Optional[GreengrassCoreIPCClient] = None,
if executor is True:
executor = concurrent.futures.ThreadPoolExecutor()
self.executor = executor
self.ignore_executor_exceptions = False

def close(self, *, executor_wait=True) -> concurrent.futures.Future:
"""
Expand All @@ -49,6 +50,9 @@ def close(self, *, executor_wait=True) -> concurrent.futures.Future:
of None if the shutdown was clean and user-initiated.
"""
fut = self.client.close()

# events that arrive during the shutdown process will generate executor exceptions, ignore them
self.ignore_executor_exceptions = True
if self.executor is not None:
self.executor.shutdown(wait=executor_wait)
return fut
Expand Down Expand Up @@ -84,7 +88,11 @@ def __create_stream_handler(real_self, operation, on_stream_event, on_stream_err
on_stream_event = real_self.__wrap_error(on_stream_event)
def handler(self, event):
if real_self.executor is not None:
real_self.executor.submit(on_stream_event, event)
try:
real_self.executor.submit(on_stream_event, event)
except RuntimeError:
if not real_self.ignore_executor_exceptions:
raise
else:
on_stream_event(event)
setattr(stream_handler_type, "on_stream_event", handler)
Expand All @@ -97,7 +105,11 @@ def handler(self, error):
on_stream_closed = real_self.__wrap_error(on_stream_closed)
def handler(self):
if real_self.executor is not None:
real_self.executor.submit(on_stream_closed)
try:
real_self.executor.submit(on_stream_closed)
except RuntimeError:
if real_self.ignore_executor_exceptions:
raise
else:
on_stream_closed()
setattr(stream_handler_type, "on_stream_closed", handler)
Expand Down Expand Up @@ -144,6 +156,29 @@ def authorize_client_device_action_async(self, *,
write_future = operation.activate(request)
return self.__combine_futures(write_future, operation.get_response())

def cancel_local_deployment(self, *,
deployment_id: typing.Optional[str] = None) -> model.CancelLocalDeploymentResponse:
"""
Perform the CancelLocalDeployment operation synchronously.

Args:
deployment_id:
"""
return self.cancel_local_deployment_async(deployment_id=deployment_id).result()

def cancel_local_deployment_async(self, *,
deployment_id: typing.Optional[str] = None): # type: (...) -> concurrent.futures.Future[model.CancelLocalDeploymentResponse]
"""
Perform the CancelLocalDeployment operation asynchronously.

Args:
deployment_id:
"""
request = model.CancelLocalDeploymentRequest(deployment_id=deployment_id)
operation = self.client.new_cancel_local_deployment()
write_future = operation.activate(request)
return self.__combine_futures(write_future, operation.get_response())

def create_debug_password(self) -> model.CreateDebugPasswordResponse:
"""
Perform the CreateDebugPassword operation synchronously.
Expand All @@ -168,7 +203,8 @@ def create_local_deployment(self, *,
component_to_configuration: typing.Optional[typing.Dict[str, typing.Dict[str, typing.Any]]] = None,
component_to_run_with_info: typing.Optional[typing.Dict[str, model.RunWithInfo]] = None,
recipe_directory_path: typing.Optional[str] = None,
artifacts_directory_path: typing.Optional[str] = None) -> model.CreateLocalDeploymentResponse:
artifacts_directory_path: typing.Optional[str] = None,
failure_handling_policy: typing.Optional[str] = None) -> model.CreateLocalDeploymentResponse:
"""
Perform the CreateLocalDeployment operation synchronously.

Expand All @@ -180,8 +216,9 @@ def create_local_deployment(self, *,
component_to_run_with_info:
recipe_directory_path:
artifacts_directory_path:
failure_handling_policy: FailureHandlingPolicy enum value
"""
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()
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()

def create_local_deployment_async(self, *,
group_name: typing.Optional[str] = None,
Expand All @@ -190,7 +227,8 @@ def create_local_deployment_async(self, *,
component_to_configuration: typing.Optional[typing.Dict[str, typing.Dict[str, typing.Any]]] = None,
component_to_run_with_info: typing.Optional[typing.Dict[str, model.RunWithInfo]] = None,
recipe_directory_path: typing.Optional[str] = None,
artifacts_directory_path: typing.Optional[str] = None): # type: (...) -> concurrent.futures.Future[model.CreateLocalDeploymentResponse]
artifacts_directory_path: typing.Optional[str] = None,
failure_handling_policy: typing.Optional[str] = None): # type: (...) -> concurrent.futures.Future[model.CreateLocalDeploymentResponse]
"""
Perform the CreateLocalDeployment operation asynchronously.

Expand All @@ -202,8 +240,9 @@ def create_local_deployment_async(self, *,
component_to_run_with_info:
recipe_directory_path:
artifacts_directory_path:
failure_handling_policy: FailureHandlingPolicy enum value
"""
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)
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)
operation = self.client.new_create_local_deployment()
write_future = operation.activate(request)
return self.__combine_futures(write_future, operation.get_response())
Expand Down
Loading