From ccbec40899adda15997f77c6890b5cc368bb7fad Mon Sep 17 00:00:00 2001 From: Navya Kuchibhotla Date: Tue, 12 Jul 2022 12:41:15 -0700 Subject: [PATCH] Update Greengrass V2 IPC model for PutComponentMetric operation --- awsiot/greengrasscoreipc/client.py | 44 ++++++ awsiot/greengrasscoreipc/clientv2.py | 23 +++ awsiot/greengrasscoreipc/model.py | 203 +++++++++++++++++++++++++++ 3 files changed, 270 insertions(+) diff --git a/awsiot/greengrasscoreipc/client.py b/awsiot/greengrasscoreipc/client.py index 06fa9807..ea80f4b9 100644 --- a/awsiot/greengrasscoreipc/client.py +++ b/awsiot/greengrasscoreipc/client.py @@ -586,6 +586,40 @@ def close(self): # type: (...) -> concurrent.futures.Future[None] return super().close() +class PutComponentMetricOperation(model._PutComponentMetricOperation): + """ + PutComponentMetricOperation + + Create with GreengrassCoreIPCClient.new_put_component_metric() + """ + + def activate(self, request: model.PutComponentMetricRequest): # type: (...) -> concurrent.futures.Future[None] + """ + Activate this operation by sending the initial PutComponentMetricRequest 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.PutComponentMetricResponse] + """ + Returns a Future which completes with a result of PutComponentMetricResponse, + 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 RestartComponentOperation(model._RestartComponentOperation): """ RestartComponentOperation @@ -1453,6 +1487,16 @@ def new_publish_to_topic(self) -> PublishToTopicOperation: """ return self._new_operation(PublishToTopicOperation) + def new_put_component_metric(self) -> PutComponentMetricOperation: + """ + Create a new PutComponentMetricOperation. + + 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(PutComponentMetricOperation) + def new_restart_component(self) -> RestartComponentOperation: """ Create a new RestartComponentOperation. diff --git a/awsiot/greengrasscoreipc/clientv2.py b/awsiot/greengrasscoreipc/clientv2.py index cab91036..36a01012 100644 --- a/awsiot/greengrasscoreipc/clientv2.py +++ b/awsiot/greengrasscoreipc/clientv2.py @@ -566,6 +566,29 @@ def publish_to_topic_async(self, *, write_future = operation.activate(request) return self.__combine_futures(write_future, operation.get_response()) + def put_component_metric(self, *, + metrics: typing.Optional[typing.List[model.Metric]] = None) -> model.PutComponentMetricResponse: + """ + Perform the PutComponentMetric operation synchronously. + + Args: + metrics: + """ + return self.put_component_metric_async(metrics=metrics).result() + + def put_component_metric_async(self, *, + metrics: typing.Optional[typing.List[model.Metric]] = None): # type: (...) -> concurrent.futures.Future[model.PutComponentMetricResponse] + """ + Perform the PutComponentMetric operation asynchronously. + + Args: + metrics: + """ + request = model.PutComponentMetricRequest(metrics=metrics) + operation = self.client.new_put_component_metric() + write_future = operation.activate(request) + return self.__combine_futures(write_future, operation.get_response()) + def restart_component(self, *, component_name: typing.Optional[str] = None) -> model.RestartComponentResponse: """ diff --git a/awsiot/greengrasscoreipc/model.py b/awsiot/greengrasscoreipc/model.py index ca654e72..c63b1194 100644 --- a/awsiot/greengrasscoreipc/model.py +++ b/awsiot/greengrasscoreipc/model.py @@ -93,6 +93,19 @@ def __eq__(self, other): return False +class MetricUnitType: + """ + MetricUnitType enum + """ + + BYTES = 'BYTES' + BYTES_PER_SECOND = 'BYTES_PER_SECOND' + COUNT = 'COUNT' + COUNT_PER_SECOND = 'COUNT_PER_SECOND' + MEGABYTES = 'MEGABYTES' + SECONDS = 'SECONDS' + + class MessageContext(rpc.Shape): """ MessageContext @@ -564,6 +577,83 @@ def __eq__(self, other): return False +class Metric(rpc.Shape): + """ + Metric + + All attributes are None by default, and may be set by keyword in the constructor. + + Keyword Args: + name: + unit: MetricUnitType enum value + value: + + Attributes: + name: + unit: MetricUnitType enum value + value: + """ + + def __init__(self, *, + name: typing.Optional[str] = None, + unit: typing.Optional[str] = None, + value: typing.Optional[float] = None): + super().__init__() + self.name = name # type: typing.Optional[str] + self.unit = unit # type: typing.Optional[str] + self.value = value # type: typing.Optional[float] + + def set_name(self, name: str): + self.name = name + return self + + def set_unit(self, unit: str): + self.unit = unit + return self + + def set_value(self, value: float): + self.value = value + return self + + + def _to_payload(self): + payload = {} + if self.name is not None: + payload['name'] = self.name + if self.unit is not None: + payload['unit'] = self.unit + if self.value is not None: + payload['value'] = self.value + return payload + + @classmethod + def _from_payload(cls, payload): + new = cls() + if 'name' in payload: + new.name = payload['name'] + if 'unit' in payload: + new.unit = payload['unit'] + if 'value' in payload: + new.value = float(payload['value']) + return new + + @classmethod + def _model_name(cls): + return 'aws.greengrass#Metric' + + def __repr__(self): + attrs = [] + for attr, val in self.__dict__.items(): + if val is not None: + attrs.append('%s=%r' % (attr, val)) + return '%s(%s)' % (self.__class__.__name__, ', '.join(attrs)) + + def __eq__(self, other): + if isinstance(other, self.__class__): + return self.__dict__ == other.__dict__ + return False + + class LifecycleState: """ LifecycleState enum @@ -5295,6 +5385,94 @@ def __eq__(self, other): return False +class PutComponentMetricResponse(rpc.Shape): + """ + PutComponentMetricResponse + """ + + def __init__(self): + super().__init__() + + + def _to_payload(self): + payload = {} + return payload + + @classmethod + def _from_payload(cls, payload): + new = cls() + return new + + @classmethod + def _model_name(cls): + return 'aws.greengrass#PutComponentMetricResponse' + + def __repr__(self): + attrs = [] + for attr, val in self.__dict__.items(): + if val is not None: + attrs.append('%s=%r' % (attr, val)) + return '%s(%s)' % (self.__class__.__name__, ', '.join(attrs)) + + def __eq__(self, other): + if isinstance(other, self.__class__): + return self.__dict__ == other.__dict__ + return False + + +class PutComponentMetricRequest(rpc.Shape): + """ + PutComponentMetricRequest + + All attributes are None by default, and may be set by keyword in the constructor. + + Keyword Args: + metrics: + + Attributes: + metrics: + """ + + def __init__(self, *, + metrics: typing.Optional[typing.List[Metric]] = None): + super().__init__() + self.metrics = metrics # type: typing.Optional[typing.List[Metric]] + + def set_metrics(self, metrics: typing.List[Metric]): + self.metrics = metrics + return self + + + def _to_payload(self): + payload = {} + if self.metrics is not None: + payload['metrics'] = [i._to_payload() for i in self.metrics] + return payload + + @classmethod + def _from_payload(cls, payload): + new = cls() + if 'metrics' in payload: + new.metrics = [Metric._from_payload(i) for i in payload['metrics']] + return new + + @classmethod + def _model_name(cls): + return 'aws.greengrass#PutComponentMetricRequest' + + def __repr__(self): + attrs = [] + for attr, val in self.__dict__.items(): + if val is not None: + attrs.append('%s=%r' % (attr, val)) + return '%s(%s)' % (self.__class__.__name__, ', '.join(attrs)) + + def __eq__(self, other): + if isinstance(other, self.__class__): + return self.__dict__ == other.__dict__ + return False + + class InvalidArgumentsError(GreengrassCoreIPCError): """ InvalidArgumentsError @@ -6078,6 +6256,7 @@ def __eq__(self, other): PostComponentUpdateEvent, MQTTMessage, MQTTCredential, + Metric, JsonMessage, ConfigurationUpdateEvent, CertificateUpdate, @@ -6148,6 +6327,8 @@ def __eq__(self, other): SubscribeToValidateConfigurationUpdatesRequest, DeferComponentUpdateResponse, DeferComponentUpdateRequest, + PutComponentMetricResponse, + PutComponentMetricRequest, InvalidArgumentsError, DeleteThingShadowResponse, DeleteThingShadowRequest, @@ -6539,6 +6720,28 @@ def _response_stream_type(cls): return None +class _PutComponentMetricOperation(rpc.ClientOperation): + @classmethod + def _model_name(cls): + return 'aws.greengrass#PutComponentMetric' + + @classmethod + def _request_type(cls): + return PutComponentMetricRequest + + @classmethod + def _request_stream_type(cls): + return None + + @classmethod + def _response_type(cls): + return PutComponentMetricResponse + + @classmethod + def _response_stream_type(cls): + return None + + class _RestartComponentOperation(rpc.ClientOperation): @classmethod def _model_name(cls):