Skip to content

Update Greengrass V2 IPC model for PutComponentMetric operation #332

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 13, 2022
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 @@ -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
Expand Down Expand Up @@ -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.
Expand Down
23 changes: 23 additions & 0 deletions awsiot/greengrasscoreipc/clientv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down
203 changes: 203 additions & 0 deletions awsiot/greengrasscoreipc/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -6078,6 +6256,7 @@ def __eq__(self, other):
PostComponentUpdateEvent,
MQTTMessage,
MQTTCredential,
Metric,
JsonMessage,
ConfigurationUpdateEvent,
CertificateUpdate,
Expand Down Expand Up @@ -6148,6 +6327,8 @@ def __eq__(self, other):
SubscribeToValidateConfigurationUpdatesRequest,
DeferComponentUpdateResponse,
DeferComponentUpdateRequest,
PutComponentMetricResponse,
PutComponentMetricRequest,
InvalidArgumentsError,
DeleteThingShadowResponse,
DeleteThingShadowRequest,
Expand Down Expand Up @@ -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):
Expand Down