Skip to content

Commit 8587e97

Browse files
Put component metric (#457)
* Update Greengrass V2 IPC model for PutComponentMetric operation Co-authored-by: Navya Kuchibhotla <[email protected]>
1 parent 07adffc commit 8587e97

File tree

4 files changed

+449
-1
lines changed

4 files changed

+449
-1
lines changed

greengrass_ipc/include/aws/greengrass/GreengrassCoreIpcClient.h

+2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ namespace Aws
5252

5353
std::shared_ptr<DeleteThingShadowOperation> NewDeleteThingShadow() noexcept;
5454

55+
std::shared_ptr<PutComponentMetricOperation> NewPutComponentMetric() noexcept;
56+
5557
std::shared_ptr<DeferComponentUpdateOperation> NewDeferComponentUpdate() noexcept;
5658

5759
std::shared_ptr<SubscribeToValidateConfigurationUpdatesOperation>

greengrass_ipc/include/aws/greengrass/GreengrassCoreIpcModel.h

+149
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ namespace Aws
2121
{
2222
class GreengrassCoreIpcClient;
2323
class GreengrassCoreIpcServiceModel;
24+
enum MetricUnitType
25+
{
26+
METRIC_UNIT_TYPE_BYTES,
27+
METRIC_UNIT_TYPE_BYTES_PER_SECOND,
28+
METRIC_UNIT_TYPE_COUNT,
29+
METRIC_UNIT_TYPE_COUNT_PER_SECOND,
30+
METRIC_UNIT_TYPE_MEGABYTES,
31+
METRIC_UNIT_TYPE_SECONDS
32+
};
33+
2434
class MessageContext : public AbstractShapeBase
2535
{
2636
public:
@@ -257,6 +267,36 @@ namespace Aws
257267
CONFIGURATION_VALIDITY_STATUS_REJECTED
258268
};
259269

270+
class Metric : public AbstractShapeBase
271+
{
272+
public:
273+
Metric() noexcept {}
274+
Metric(const Metric &) = default;
275+
void SetName(const Aws::Crt::String &name) noexcept { m_name = name; }
276+
Aws::Crt::Optional<Aws::Crt::String> GetName() noexcept { return m_name; }
277+
void SetUnit(MetricUnitType unit) noexcept;
278+
Aws::Crt::Optional<MetricUnitType> GetUnit() noexcept;
279+
void SetValue(const double &value) noexcept { m_value = value; }
280+
Aws::Crt::Optional<double> GetValue() noexcept { return m_value; }
281+
void SerializeToJsonObject(Aws::Crt::JsonObject &payloadObject) const noexcept override;
282+
static void s_loadFromJsonView(Metric &, const Aws::Crt::JsonView &) noexcept;
283+
static Aws::Crt::ScopedResource<AbstractShapeBase> s_allocateFromPayload(
284+
Aws::Crt::StringView,
285+
Aws::Crt::Allocator *) noexcept;
286+
static void s_customDeleter(Metric *) noexcept;
287+
/* This needs to be defined so that `Metric` can be used as a key in maps. */
288+
bool operator<(const Metric &) const noexcept;
289+
static const char *MODEL_NAME;
290+
291+
protected:
292+
Aws::Crt::String GetModelName() const noexcept override;
293+
294+
private:
295+
Aws::Crt::Optional<Aws::Crt::String> m_name;
296+
Aws::Crt::Optional<Aws::Crt::String> m_unit;
297+
Aws::Crt::Optional<double> m_value;
298+
};
299+
260300
class BinaryMessage : public AbstractShapeBase
261301
{
262302
public:
@@ -1899,6 +1939,51 @@ namespace Aws
18991939
Aws::Crt::Optional<Aws::Crt::String> m_componentName;
19001940
};
19011941

1942+
class PutComponentMetricResponse : public AbstractShapeBase
1943+
{
1944+
public:
1945+
PutComponentMetricResponse() noexcept {}
1946+
PutComponentMetricResponse(const PutComponentMetricResponse &) = default;
1947+
void SerializeToJsonObject(Aws::Crt::JsonObject &payloadObject) const noexcept override;
1948+
static void s_loadFromJsonView(PutComponentMetricResponse &, const Aws::Crt::JsonView &) noexcept;
1949+
static Aws::Crt::ScopedResource<AbstractShapeBase> s_allocateFromPayload(
1950+
Aws::Crt::StringView,
1951+
Aws::Crt::Allocator *) noexcept;
1952+
static void s_customDeleter(PutComponentMetricResponse *) noexcept;
1953+
/* This needs to be defined so that `PutComponentMetricResponse` can be used as a key in maps. */
1954+
bool operator<(const PutComponentMetricResponse &) const noexcept;
1955+
static const char *MODEL_NAME;
1956+
1957+
protected:
1958+
Aws::Crt::String GetModelName() const noexcept override;
1959+
1960+
private:
1961+
};
1962+
1963+
class PutComponentMetricRequest : public AbstractShapeBase
1964+
{
1965+
public:
1966+
PutComponentMetricRequest() noexcept {}
1967+
PutComponentMetricRequest(const PutComponentMetricRequest &) = default;
1968+
void SetMetrics(const Aws::Crt::Vector<Metric> &metrics) noexcept { m_metrics = metrics; }
1969+
Aws::Crt::Optional<Aws::Crt::Vector<Metric>> GetMetrics() noexcept { return m_metrics; }
1970+
void SerializeToJsonObject(Aws::Crt::JsonObject &payloadObject) const noexcept override;
1971+
static void s_loadFromJsonView(PutComponentMetricRequest &, const Aws::Crt::JsonView &) noexcept;
1972+
static Aws::Crt::ScopedResource<AbstractShapeBase> s_allocateFromPayload(
1973+
Aws::Crt::StringView,
1974+
Aws::Crt::Allocator *) noexcept;
1975+
static void s_customDeleter(PutComponentMetricRequest *) noexcept;
1976+
/* This needs to be defined so that `PutComponentMetricRequest` can be used as a key in maps. */
1977+
bool operator<(const PutComponentMetricRequest &) const noexcept;
1978+
static const char *MODEL_NAME;
1979+
1980+
protected:
1981+
Aws::Crt::String GetModelName() const noexcept override;
1982+
1983+
private:
1984+
Aws::Crt::Optional<Aws::Crt::Vector<Metric>> m_metrics;
1985+
};
1986+
19021987
class PublishToTopicResponse : public AbstractShapeBase
19031988
{
19041989
public:
@@ -3484,6 +3569,69 @@ namespace Aws
34843569
Aws::Crt::String GetModelName() const noexcept override;
34853570
};
34863571

3572+
class PutComponentMetricOperationContext : public OperationModelContext
3573+
{
3574+
public:
3575+
PutComponentMetricOperationContext(const GreengrassCoreIpcServiceModel &serviceModel) noexcept;
3576+
Aws::Crt::ScopedResource<AbstractShapeBase> AllocateInitialResponseFromPayload(
3577+
Aws::Crt::StringView stringView,
3578+
Aws::Crt::Allocator *allocator = Aws::Crt::g_allocator) const noexcept override;
3579+
Aws::Crt::ScopedResource<AbstractShapeBase> AllocateStreamingResponseFromPayload(
3580+
Aws::Crt::StringView stringView,
3581+
Aws::Crt::Allocator *allocator = Aws::Crt::g_allocator) const noexcept override;
3582+
Aws::Crt::String GetRequestModelName() const noexcept override;
3583+
Aws::Crt::String GetInitialResponseModelName() const noexcept override;
3584+
Aws::Crt::Optional<Aws::Crt::String> GetStreamingResponseModelName() const noexcept override;
3585+
Aws::Crt::String GetOperationName() const noexcept override;
3586+
};
3587+
3588+
class PutComponentMetricResult
3589+
{
3590+
public:
3591+
PutComponentMetricResult() noexcept {}
3592+
PutComponentMetricResult(TaggedResult &&taggedResult) noexcept : m_taggedResult(std::move(taggedResult)) {}
3593+
PutComponentMetricResponse *GetOperationResponse() const noexcept
3594+
{
3595+
return static_cast<PutComponentMetricResponse *>(m_taggedResult.GetOperationResponse());
3596+
}
3597+
/**
3598+
* @return true if the response is associated with an expected response;
3599+
* false if the response is associated with an error.
3600+
*/
3601+
operator bool() const noexcept { return m_taggedResult == true; }
3602+
OperationError *GetOperationError() const noexcept { return m_taggedResult.GetOperationError(); }
3603+
RpcError GetRpcError() const noexcept { return m_taggedResult.GetRpcError(); }
3604+
ResultType GetResultType() const noexcept { return m_taggedResult.GetResultType(); }
3605+
3606+
private:
3607+
TaggedResult m_taggedResult;
3608+
};
3609+
3610+
class PutComponentMetricOperation : public ClientOperation
3611+
{
3612+
public:
3613+
PutComponentMetricOperation(
3614+
ClientConnection &connection,
3615+
const PutComponentMetricOperationContext &operationContext,
3616+
Aws::Crt::Allocator *allocator = Aws::Crt::g_allocator) noexcept;
3617+
/**
3618+
* Used to activate a stream for the `PutComponentMetricOperation`
3619+
* @param request The request used for the `PutComponentMetricOperation`
3620+
* @param onMessageFlushCallback An optional callback that is invoked when the request is flushed.
3621+
* @return An `RpcError` that can be used to check whether the stream was activated.
3622+
*/
3623+
std::future<RpcError> Activate(
3624+
const PutComponentMetricRequest &request,
3625+
OnMessageFlushCallback onMessageFlushCallback = nullptr) noexcept;
3626+
/**
3627+
* Retrieve the result from activating the stream.
3628+
*/
3629+
std::future<PutComponentMetricResult> GetResult() noexcept;
3630+
3631+
protected:
3632+
Aws::Crt::String GetModelName() const noexcept override;
3633+
};
3634+
34873635
class DeferComponentUpdateOperationContext : public OperationModelContext
34883636
{
34893637
public:
@@ -5482,6 +5630,7 @@ namespace Aws
54825630
PublishToIoTCoreOperationContext m_publishToIoTCoreOperationContext;
54835631
SubscribeToConfigurationUpdateOperationContext m_subscribeToConfigurationUpdateOperationContext;
54845632
DeleteThingShadowOperationContext m_deleteThingShadowOperationContext;
5633+
PutComponentMetricOperationContext m_putComponentMetricOperationContext;
54855634
DeferComponentUpdateOperationContext m_deferComponentUpdateOperationContext;
54865635
SubscribeToValidateConfigurationUpdatesOperationContext
54875636
m_subscribeToValidateConfigurationUpdatesOperationContext;

greengrass_ipc/source/GreengrassCoreIpcClient.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,15 @@ namespace Aws
104104
m_allocator);
105105
}
106106

107+
std::shared_ptr<PutComponentMetricOperation> GreengrassCoreIpcClient::NewPutComponentMetric() noexcept
108+
{
109+
return Aws::Crt::MakeShared<PutComponentMetricOperation>(
110+
m_allocator,
111+
m_connection,
112+
m_greengrassCoreIpcServiceModel.m_putComponentMetricOperationContext,
113+
m_allocator);
114+
}
115+
107116
std::shared_ptr<DeferComponentUpdateOperation> GreengrassCoreIpcClient::NewDeferComponentUpdate() noexcept
108117
{
109118
return Aws::Crt::MakeShared<DeferComponentUpdateOperation>(

0 commit comments

Comments
 (0)