Skip to content

Commit f8187d4

Browse files
authored
Update Greengrass V2 IPC model for PutComponentMetric operation (#332)
1 parent 17bb44d commit f8187d4

File tree

3 files changed

+270
-0
lines changed

3 files changed

+270
-0
lines changed

awsiot/greengrasscoreipc/client.py

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

588588

589+
class PutComponentMetricOperation(model._PutComponentMetricOperation):
590+
"""
591+
PutComponentMetricOperation
592+
593+
Create with GreengrassCoreIPCClient.new_put_component_metric()
594+
"""
595+
596+
def activate(self, request: model.PutComponentMetricRequest): # type: (...) -> concurrent.futures.Future[None]
597+
"""
598+
Activate this operation by sending the initial PutComponentMetricRequest message.
599+
600+
Returns a Future which completes with a result of None if the
601+
request is successfully written to the wire, or an exception if
602+
the request fails to send.
603+
"""
604+
return self._activate(request)
605+
606+
def get_response(self): # type: (...) -> concurrent.futures.Future[model.PutComponentMetricResponse]
607+
"""
608+
Returns a Future which completes with a result of PutComponentMetricResponse,
609+
when the initial response is received, or an exception.
610+
"""
611+
return self._get_response()
612+
613+
def close(self): # type: (...) -> concurrent.futures.Future[None]
614+
"""
615+
Close the operation, whether or not it has completed.
616+
617+
Returns a Future which completes with a result of None
618+
when the operation has closed.
619+
"""
620+
return super().close()
621+
622+
589623
class RestartComponentOperation(model._RestartComponentOperation):
590624
"""
591625
RestartComponentOperation
@@ -1453,6 +1487,16 @@ def new_publish_to_topic(self) -> PublishToTopicOperation:
14531487
"""
14541488
return self._new_operation(PublishToTopicOperation)
14551489

1490+
def new_put_component_metric(self) -> PutComponentMetricOperation:
1491+
"""
1492+
Create a new PutComponentMetricOperation.
1493+
1494+
This operation will not send or receive any data until activate()
1495+
is called. Call activate() when you're ready for callbacks and
1496+
events to fire.
1497+
"""
1498+
return self._new_operation(PutComponentMetricOperation)
1499+
14561500
def new_restart_component(self) -> RestartComponentOperation:
14571501
"""
14581502
Create a new RestartComponentOperation.

awsiot/greengrasscoreipc/clientv2.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,29 @@ def publish_to_topic_async(self, *,
566566
write_future = operation.activate(request)
567567
return self.__combine_futures(write_future, operation.get_response())
568568

569+
def put_component_metric(self, *,
570+
metrics: typing.Optional[typing.List[model.Metric]] = None) -> model.PutComponentMetricResponse:
571+
"""
572+
Perform the PutComponentMetric operation synchronously.
573+
574+
Args:
575+
metrics:
576+
"""
577+
return self.put_component_metric_async(metrics=metrics).result()
578+
579+
def put_component_metric_async(self, *,
580+
metrics: typing.Optional[typing.List[model.Metric]] = None): # type: (...) -> concurrent.futures.Future[model.PutComponentMetricResponse]
581+
"""
582+
Perform the PutComponentMetric operation asynchronously.
583+
584+
Args:
585+
metrics:
586+
"""
587+
request = model.PutComponentMetricRequest(metrics=metrics)
588+
operation = self.client.new_put_component_metric()
589+
write_future = operation.activate(request)
590+
return self.__combine_futures(write_future, operation.get_response())
591+
569592
def restart_component(self, *,
570593
component_name: typing.Optional[str] = None) -> model.RestartComponentResponse:
571594
"""

awsiot/greengrasscoreipc/model.py

Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,19 @@ def __eq__(self, other):
9393
return False
9494

9595

96+
class MetricUnitType:
97+
"""
98+
MetricUnitType enum
99+
"""
100+
101+
BYTES = 'BYTES'
102+
BYTES_PER_SECOND = 'BYTES_PER_SECOND'
103+
COUNT = 'COUNT'
104+
COUNT_PER_SECOND = 'COUNT_PER_SECOND'
105+
MEGABYTES = 'MEGABYTES'
106+
SECONDS = 'SECONDS'
107+
108+
96109
class MessageContext(rpc.Shape):
97110
"""
98111
MessageContext
@@ -564,6 +577,83 @@ def __eq__(self, other):
564577
return False
565578

566579

580+
class Metric(rpc.Shape):
581+
"""
582+
Metric
583+
584+
All attributes are None by default, and may be set by keyword in the constructor.
585+
586+
Keyword Args:
587+
name:
588+
unit: MetricUnitType enum value
589+
value:
590+
591+
Attributes:
592+
name:
593+
unit: MetricUnitType enum value
594+
value:
595+
"""
596+
597+
def __init__(self, *,
598+
name: typing.Optional[str] = None,
599+
unit: typing.Optional[str] = None,
600+
value: typing.Optional[float] = None):
601+
super().__init__()
602+
self.name = name # type: typing.Optional[str]
603+
self.unit = unit # type: typing.Optional[str]
604+
self.value = value # type: typing.Optional[float]
605+
606+
def set_name(self, name: str):
607+
self.name = name
608+
return self
609+
610+
def set_unit(self, unit: str):
611+
self.unit = unit
612+
return self
613+
614+
def set_value(self, value: float):
615+
self.value = value
616+
return self
617+
618+
619+
def _to_payload(self):
620+
payload = {}
621+
if self.name is not None:
622+
payload['name'] = self.name
623+
if self.unit is not None:
624+
payload['unit'] = self.unit
625+
if self.value is not None:
626+
payload['value'] = self.value
627+
return payload
628+
629+
@classmethod
630+
def _from_payload(cls, payload):
631+
new = cls()
632+
if 'name' in payload:
633+
new.name = payload['name']
634+
if 'unit' in payload:
635+
new.unit = payload['unit']
636+
if 'value' in payload:
637+
new.value = float(payload['value'])
638+
return new
639+
640+
@classmethod
641+
def _model_name(cls):
642+
return 'aws.greengrass#Metric'
643+
644+
def __repr__(self):
645+
attrs = []
646+
for attr, val in self.__dict__.items():
647+
if val is not None:
648+
attrs.append('%s=%r' % (attr, val))
649+
return '%s(%s)' % (self.__class__.__name__, ', '.join(attrs))
650+
651+
def __eq__(self, other):
652+
if isinstance(other, self.__class__):
653+
return self.__dict__ == other.__dict__
654+
return False
655+
656+
567657
class LifecycleState:
568658
"""
569659
LifecycleState enum
@@ -5295,6 +5385,94 @@ def __eq__(self, other):
52955385
return False
52965386

52975387

5388+
class PutComponentMetricResponse(rpc.Shape):
5389+
"""
5390+
PutComponentMetricResponse
5391+
"""
5392+
5393+
def __init__(self):
5394+
super().__init__()
5395+
5396+
5397+
def _to_payload(self):
5398+
payload = {}
5399+
return payload
5400+
5401+
@classmethod
5402+
def _from_payload(cls, payload):
5403+
new = cls()
5404+
return new
5405+
5406+
@classmethod
5407+
def _model_name(cls):
5408+
return 'aws.greengrass#PutComponentMetricResponse'
5409+
5410+
def __repr__(self):
5411+
attrs = []
5412+
for attr, val in self.__dict__.items():
5413+
if val is not None:
5414+
attrs.append('%s=%r' % (attr, val))
5415+
return '%s(%s)' % (self.__class__.__name__, ', '.join(attrs))
5416+
5417+
def __eq__(self, other):
5418+
if isinstance(other, self.__class__):
5419+
return self.__dict__ == other.__dict__
5420+
return False
5421+
5422+
5423+
class PutComponentMetricRequest(rpc.Shape):
5424+
"""
5425+
PutComponentMetricRequest
5426+
5427+
All attributes are None by default, and may be set by keyword in the constructor.
5428+
5429+
Keyword Args:
5430+
metrics:
5431+
5432+
Attributes:
5433+
metrics:
5434+
"""
5435+
5436+
def __init__(self, *,
5437+
metrics: typing.Optional[typing.List[Metric]] = None):
5438+
super().__init__()
5439+
self.metrics = metrics # type: typing.Optional[typing.List[Metric]]
5440+
5441+
def set_metrics(self, metrics: typing.List[Metric]):
5442+
self.metrics = metrics
5443+
return self
5444+
5445+
5446+
def _to_payload(self):
5447+
payload = {}
5448+
if self.metrics is not None:
5449+
payload['metrics'] = [i._to_payload() for i in self.metrics]
5450+
return payload
5451+
5452+
@classmethod
5453+
def _from_payload(cls, payload):
5454+
new = cls()
5455+
if 'metrics' in payload:
5456+
new.metrics = [Metric._from_payload(i) for i in payload['metrics']]
5457+
return new
5458+
5459+
@classmethod
5460+
def _model_name(cls):
5461+
return 'aws.greengrass#PutComponentMetricRequest'
5462+
5463+
def __repr__(self):
5464+
attrs = []
5465+
for attr, val in self.__dict__.items():
5466+
if val is not None:
5467+
attrs.append('%s=%r' % (attr, val))
5468+
return '%s(%s)' % (self.__class__.__name__, ', '.join(attrs))
5469+
5470+
def __eq__(self, other):
5471+
if isinstance(other, self.__class__):
5472+
return self.__dict__ == other.__dict__
5473+
return False
5474+
5475+
52985476
class InvalidArgumentsError(GreengrassCoreIPCError):
52995477
"""
53005478
InvalidArgumentsError
@@ -6078,6 +6256,7 @@ def __eq__(self, other):
60786256
PostComponentUpdateEvent,
60796257
MQTTMessage,
60806258
MQTTCredential,
6259+
Metric,
60816260
JsonMessage,
60826261
ConfigurationUpdateEvent,
60836262
CertificateUpdate,
@@ -6148,6 +6327,8 @@ def __eq__(self, other):
61486327
SubscribeToValidateConfigurationUpdatesRequest,
61496328
DeferComponentUpdateResponse,
61506329
DeferComponentUpdateRequest,
6330+
PutComponentMetricResponse,
6331+
PutComponentMetricRequest,
61516332
InvalidArgumentsError,
61526333
DeleteThingShadowResponse,
61536334
DeleteThingShadowRequest,
@@ -6539,6 +6720,28 @@ def _response_stream_type(cls):
65396720
return None
65406721

65416722

6723+
class _PutComponentMetricOperation(rpc.ClientOperation):
6724+
@classmethod
6725+
def _model_name(cls):
6726+
return 'aws.greengrass#PutComponentMetric'
6727+
6728+
@classmethod
6729+
def _request_type(cls):
6730+
return PutComponentMetricRequest
6731+
6732+
@classmethod
6733+
def _request_stream_type(cls):
6734+
return None
6735+
6736+
@classmethod
6737+
def _response_type(cls):
6738+
return PutComponentMetricResponse
6739+
6740+
@classmethod
6741+
def _response_stream_type(cls):
6742+
return None
6743+
6744+
65426745
class _RestartComponentOperation(rpc.ClientOperation):
65436746
@classmethod
65446747
def _model_name(cls):

0 commit comments

Comments
 (0)