Skip to content

Commit

Permalink
Update Greengrass V2 IPC model for PutComponentMetric operation (#296)
Browse files Browse the repository at this point in the history
* Update Greengrass V2 IPC model for PutComponentMetric operation

* @kucnavya fix: increase timeout for subscriptionClosed from commit:
4ea1e66

Co-authored-by: Navya Kuchibhotla <kucnavya@amazon.com>
Co-authored-by: Vera Xia <zhvxia@amazon.com>
  • Loading branch information
3 people authored Jul 28, 2022
1 parent 427f913 commit d59e0bb
Show file tree
Hide file tree
Showing 11 changed files with 477 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import software.amazon.awssdk.aws.greengrass.model.PauseComponentRequest;
import software.amazon.awssdk.aws.greengrass.model.PublishToIoTCoreRequest;
import software.amazon.awssdk.aws.greengrass.model.PublishToTopicRequest;
import software.amazon.awssdk.aws.greengrass.model.PutComponentMetricRequest;
import software.amazon.awssdk.aws.greengrass.model.RestartComponentRequest;
import software.amazon.awssdk.aws.greengrass.model.ResumeComponentRequest;
import software.amazon.awssdk.aws.greengrass.model.SendConfigurationValidityReportRequest;
Expand Down Expand Up @@ -101,6 +102,9 @@ PublishToIoTCoreResponseHandler publishToIoTCore(final PublishToIoTCoreRequest r
PublishToTopicResponseHandler publishToTopic(final PublishToTopicRequest request,
final Optional<StreamResponseHandler<EventStreamJsonMessage>> streamResponseHandler);

PutComponentMetricResponseHandler putComponentMetric(final PutComponentMetricRequest request,
final Optional<StreamResponseHandler<EventStreamJsonMessage>> streamResponseHandler);

RestartComponentResponseHandler restartComponent(final RestartComponentRequest request,
final Optional<StreamResponseHandler<EventStreamJsonMessage>> streamResponseHandler);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import software.amazon.awssdk.aws.greengrass.model.PauseComponentRequest;
import software.amazon.awssdk.aws.greengrass.model.PublishToIoTCoreRequest;
import software.amazon.awssdk.aws.greengrass.model.PublishToTopicRequest;
import software.amazon.awssdk.aws.greengrass.model.PutComponentMetricRequest;
import software.amazon.awssdk.aws.greengrass.model.RestartComponentRequest;
import software.amazon.awssdk.aws.greengrass.model.ResumeComponentRequest;
import software.amazon.awssdk.aws.greengrass.model.SendConfigurationValidityReportRequest;
Expand Down Expand Up @@ -178,6 +179,14 @@ public PublishToTopicResponseHandler publishToTopic(final PublishToTopicRequest
return new PublishToTopicResponseHandler(doOperationInvoke(operationContext, request, streamResponseHandler));
}

@Override
public PutComponentMetricResponseHandler putComponentMetric(
final PutComponentMetricRequest request,
final Optional<StreamResponseHandler<EventStreamJsonMessage>> streamResponseHandler) {
final PutComponentMetricOperationContext operationContext = GreengrassCoreIPCServiceModel.getPutComponentMetricModelContext();
return new PutComponentMetricResponseHandler(doOperationInvoke(operationContext, request, streamResponseHandler));
}

@Override
public RestartComponentResponseHandler restartComponent(final RestartComponentRequest request,
final Optional<StreamResponseHandler<EventStreamJsonMessage>> streamResponseHandler) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
import software.amazon.awssdk.aws.greengrass.model.PublishToIoTCoreResponse;
import software.amazon.awssdk.aws.greengrass.model.PublishToTopicRequest;
import software.amazon.awssdk.aws.greengrass.model.PublishToTopicResponse;
import software.amazon.awssdk.aws.greengrass.model.PutComponentMetricRequest;
import software.amazon.awssdk.aws.greengrass.model.PutComponentMetricResponse;
import software.amazon.awssdk.aws.greengrass.model.RestartComponentRequest;
import software.amazon.awssdk.aws.greengrass.model.RestartComponentResponse;
import software.amazon.awssdk.aws.greengrass.model.ResumeComponentRequest;
Expand Down Expand Up @@ -558,6 +560,31 @@ public CompletableFuture<PublishToTopicResponse> publishToTopicAsync(
return client.publishToTopic(request, Optional.empty()).getResponse();
}

/**
* Perform the putComponentMetric operation synchronously.
*
* @throws InterruptedException if thread is interrupted while waiting for the response
* @return the response
*
* @param request request object
*/
public PutComponentMetricResponse putComponentMetric(final PutComponentMetricRequest request)
throws InterruptedException {
return getResponse(this.putComponentMetricAsync(request));
}

/**
* Perform the putComponentMetric operation asynchronously.
*
* @return a future which resolves to the response
*
* @param request request object
*/
public CompletableFuture<PutComponentMetricResponse> putComponentMetricAsync(
final PutComponentMetricRequest request) {
return client.putComponentMetric(request, Optional.empty()).getResponse();
}

/**
* Perform the restartComponent operation synchronously.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package software.amazon.awssdk.aws.greengrass;

import java.lang.Override;
import java.lang.Void;
import java.util.concurrent.CompletableFuture;
import software.amazon.awssdk.aws.greengrass.model.PutComponentMetricResponse;
import software.amazon.awssdk.eventstreamrpc.OperationResponse;
import software.amazon.awssdk.eventstreamrpc.StreamResponse;
import software.amazon.awssdk.eventstreamrpc.model.EventStreamJsonMessage;

public final class PutComponentMetricResponseHandler implements StreamResponse<PutComponentMetricResponse, EventStreamJsonMessage> {
private final OperationResponse<PutComponentMetricResponse, EventStreamJsonMessage> operationResponse;

public PutComponentMetricResponseHandler(
final OperationResponse<PutComponentMetricResponse, EventStreamJsonMessage> operationResponse) {
this.operationResponse = operationResponse;
}

@Override
public CompletableFuture<Void> getRequestFlushFuture() {
return operationResponse.getRequestFlushFuture();
}

@Override
public CompletableFuture<PutComponentMetricResponse> getResponse() {
return operationResponse.getResponse();
}

@Override
public CompletableFuture<Void> sendStreamEvent(final EventStreamJsonMessage event) {
return operationResponse.sendStreamEvent(event);
}

@Override
public CompletableFuture<Void> closeStream() {
return operationResponse.closeStream();
}

@Override
public boolean isClosed() {
return operationResponse.isClosed();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@
import software.amazon.awssdk.aws.greengrass.model.MQTTCredential;
import software.amazon.awssdk.aws.greengrass.model.MQTTMessage;
import software.amazon.awssdk.aws.greengrass.model.MessageContext;
import software.amazon.awssdk.aws.greengrass.model.Metric;
import software.amazon.awssdk.aws.greengrass.model.MetricUnitType;
import software.amazon.awssdk.aws.greengrass.model.PauseComponentRequest;
import software.amazon.awssdk.aws.greengrass.model.PauseComponentResponse;
import software.amazon.awssdk.aws.greengrass.model.PostComponentUpdateEvent;
Expand All @@ -76,6 +78,8 @@
import software.amazon.awssdk.aws.greengrass.model.PublishToIoTCoreResponse;
import software.amazon.awssdk.aws.greengrass.model.PublishToTopicRequest;
import software.amazon.awssdk.aws.greengrass.model.PublishToTopicResponse;
import software.amazon.awssdk.aws.greengrass.model.PutComponentMetricRequest;
import software.amazon.awssdk.aws.greengrass.model.PutComponentMetricResponse;
import software.amazon.awssdk.aws.greengrass.model.QOS;
import software.amazon.awssdk.aws.greengrass.model.ReceiveMode;
import software.amazon.awssdk.aws.greengrass.model.ReportedLifecycleState;
Expand Down Expand Up @@ -204,6 +208,10 @@ public class GreengrassCoreIPCServiceModel extends EventStreamRPCServiceModel {

private static final PublishToTopicOperationContext _PUBLISH_TO_TOPIC_OPERATION_CONTEXT = new PublishToTopicOperationContext();

public static final String PUT_COMPONENT_METRIC = SERVICE_NAMESPACE + "#" + "PutComponentMetric";

private static final PutComponentMetricOperationContext _PUT_COMPONENT_METRIC_OPERATION_CONTEXT = new PutComponentMetricOperationContext();

public static final String RESTART_COMPONENT = SERVICE_NAMESPACE + "#" + "RestartComponent";

private static final RestartComponentOperationContext _RESTART_COMPONENT_OPERATION_CONTEXT = new RestartComponentOperationContext();
Expand Down Expand Up @@ -299,6 +307,8 @@ public class GreengrassCoreIPCServiceModel extends EventStreamRPCServiceModel {
SERVICE_OPERATION_SET.add(PUBLISH_TO_IOT_CORE);
SERVICE_OPERATION_MODEL_MAP.put(PUBLISH_TO_TOPIC, _PUBLISH_TO_TOPIC_OPERATION_CONTEXT);
SERVICE_OPERATION_SET.add(PUBLISH_TO_TOPIC);
SERVICE_OPERATION_MODEL_MAP.put(PUT_COMPONENT_METRIC, _PUT_COMPONENT_METRIC_OPERATION_CONTEXT);
SERVICE_OPERATION_SET.add(PUT_COMPONENT_METRIC);
SERVICE_OPERATION_MODEL_MAP.put(RESTART_COMPONENT, _RESTART_COMPONENT_OPERATION_CONTEXT);
SERVICE_OPERATION_SET.add(RESTART_COMPONENT);
SERVICE_OPERATION_MODEL_MAP.put(RESUME_COMPONENT, _RESUME_COMPONENT_OPERATION_CONTEXT);
Expand Down Expand Up @@ -387,6 +397,8 @@ public class GreengrassCoreIPCServiceModel extends EventStreamRPCServiceModel {
SERVICE_OBJECT_MODEL_MAP.put(MQTTCredential.APPLICATION_MODEL_TYPE, MQTTCredential.class);
SERVICE_OBJECT_MODEL_MAP.put(MQTTMessage.APPLICATION_MODEL_TYPE, MQTTMessage.class);
SERVICE_OBJECT_MODEL_MAP.put(MessageContext.APPLICATION_MODEL_TYPE, MessageContext.class);
SERVICE_OBJECT_MODEL_MAP.put(Metric.APPLICATION_MODEL_TYPE, Metric.class);
SERVICE_OBJECT_MODEL_MAP.put(MetricUnitType.APPLICATION_MODEL_TYPE, MetricUnitType.class);
SERVICE_OBJECT_MODEL_MAP.put(PauseComponentRequest.APPLICATION_MODEL_TYPE, PauseComponentRequest.class);
SERVICE_OBJECT_MODEL_MAP.put(PauseComponentResponse.APPLICATION_MODEL_TYPE, PauseComponentResponse.class);
SERVICE_OBJECT_MODEL_MAP.put(PostComponentUpdateEvent.APPLICATION_MODEL_TYPE, PostComponentUpdateEvent.class);
Expand All @@ -396,6 +408,8 @@ public class GreengrassCoreIPCServiceModel extends EventStreamRPCServiceModel {
SERVICE_OBJECT_MODEL_MAP.put(PublishToIoTCoreResponse.APPLICATION_MODEL_TYPE, PublishToIoTCoreResponse.class);
SERVICE_OBJECT_MODEL_MAP.put(PublishToTopicRequest.APPLICATION_MODEL_TYPE, PublishToTopicRequest.class);
SERVICE_OBJECT_MODEL_MAP.put(PublishToTopicResponse.APPLICATION_MODEL_TYPE, PublishToTopicResponse.class);
SERVICE_OBJECT_MODEL_MAP.put(PutComponentMetricRequest.APPLICATION_MODEL_TYPE, PutComponentMetricRequest.class);
SERVICE_OBJECT_MODEL_MAP.put(PutComponentMetricResponse.APPLICATION_MODEL_TYPE, PutComponentMetricResponse.class);
SERVICE_OBJECT_MODEL_MAP.put(QOS.APPLICATION_MODEL_TYPE, QOS.class);
SERVICE_OBJECT_MODEL_MAP.put(ReceiveMode.APPLICATION_MODEL_TYPE, ReceiveMode.class);
SERVICE_OBJECT_MODEL_MAP.put(ReportedLifecycleState.APPLICATION_MODEL_TYPE, ReportedLifecycleState.class);
Expand Down Expand Up @@ -522,6 +536,10 @@ public static PublishToTopicOperationContext getPublishToTopicModelContext() {
return _PUBLISH_TO_TOPIC_OPERATION_CONTEXT;
}

public static PutComponentMetricOperationContext getPutComponentMetricModelContext() {
return _PUT_COMPONENT_METRIC_OPERATION_CONTEXT;
}

public static RestartComponentOperationContext getRestartComponentModelContext() {
return _RESTART_COMPONENT_OPERATION_CONTEXT;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package software.amazon.awssdk.aws.greengrass;

import java.lang.Class;
import java.lang.Override;
import java.lang.String;
import java.util.Optional;
import software.amazon.awssdk.aws.greengrass.model.PutComponentMetricRequest;
import software.amazon.awssdk.aws.greengrass.model.PutComponentMetricResponse;
import software.amazon.awssdk.eventstreamrpc.EventStreamRPCServiceModel;
import software.amazon.awssdk.eventstreamrpc.OperationModelContext;
import software.amazon.awssdk.eventstreamrpc.model.EventStreamJsonMessage;

public class PutComponentMetricOperationContext implements OperationModelContext<PutComponentMetricRequest, PutComponentMetricResponse, EventStreamJsonMessage, EventStreamJsonMessage> {
@Override
public EventStreamRPCServiceModel getServiceModel() {
return GreengrassCoreIPCServiceModel.getInstance();
}

@Override
public String getOperationName() {
return GreengrassCoreIPCServiceModel.PUT_COMPONENT_METRIC;
}

@Override
public Class<PutComponentMetricRequest> getRequestTypeClass() {
return PutComponentMetricRequest.class;
}

@Override
public Class<PutComponentMetricResponse> getResponseTypeClass() {
return PutComponentMetricResponse.class;
}

@Override
public String getRequestApplicationModelType() {
return PutComponentMetricRequest.APPLICATION_MODEL_TYPE;
}

@Override
public String getResponseApplicationModelType() {
return PutComponentMetricResponse.APPLICATION_MODEL_TYPE;
}

@Override
public Optional<Class<EventStreamJsonMessage>> getStreamingRequestTypeClass() {
return Optional.empty();
}

@Override
public Optional<Class<EventStreamJsonMessage>> getStreamingResponseTypeClass() {
return Optional.empty();
}

public Optional<String> getStreamingRequestApplicationModelType() {
return Optional.empty();
}

@Override
public Optional<String> getStreamingResponseApplicationModelType() {
return Optional.empty();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
package software.amazon.awssdk.aws.greengrass.model;

import com.google.gson.annotations.Expose;
import java.lang.Double;
import java.lang.Object;
import java.lang.Override;
import java.lang.String;
import java.util.Objects;
import java.util.Optional;
import software.amazon.awssdk.eventstreamrpc.model.EventStreamJsonMessage;

public class Metric implements EventStreamJsonMessage {
public static final String APPLICATION_MODEL_TYPE = "aws.greengrass#Metric";

public static final Metric VOID;

static {
VOID = new Metric() {
@Override
public boolean isVoid() {
return true;
}
};
}

@Expose(
serialize = true,
deserialize = true
)
private Optional<String> name;

@Expose(
serialize = true,
deserialize = true
)
private Optional<String> unit;

@Expose(
serialize = true,
deserialize = true
)
private Optional<Double> value;

public Metric() {
this.name = Optional.empty();
this.unit = Optional.empty();
this.value = Optional.empty();
}

public String getName() {
if (name.isPresent()) {
return name.get();
}
return null;
}

public void setName(final String name) {
this.name = Optional.ofNullable(name);
}

public Metric withName(final String name) {
setName(name);
return this;
}

public MetricUnitType getUnit() {
if (unit.isPresent()) {
return MetricUnitType.get(unit.get());
}
return null;
}

public String getUnitAsString() {
if (unit.isPresent()) {
return unit.get();
}
return null;
}

public void setUnit(final String unit) {
this.unit = Optional.ofNullable(unit);
}

public Metric withUnit(final String unit) {
setUnit(unit);
return this;
}

public void setUnit(final MetricUnitType unit) {
this.unit = Optional.ofNullable(unit.getValue());
}

public Metric withUnit(final MetricUnitType unit) {
setUnit(unit);
return this;
}

public Double getValue() {
if (value.isPresent()) {
return value.get();
}
return null;
}

public void setValue(final Double value) {
this.value = Optional.ofNullable(value);
}

public Metric withValue(final Double value) {
setValue(value);
return this;
}

@Override
public String getApplicationModelType() {
return APPLICATION_MODEL_TYPE;
}

@Override
public boolean equals(Object rhs) {
if (rhs == null) return false;
if (!(rhs instanceof Metric)) return false;
if (this == rhs) return true;
final Metric other = (Metric)rhs;
boolean isEquals = true;
isEquals = isEquals && this.name.equals(other.name);
isEquals = isEquals && this.unit.equals(other.unit);
isEquals = isEquals && this.value.equals(other.value);
return isEquals;
}

@Override
public int hashCode() {
return Objects.hash(name, unit, value);
}
}
Loading

0 comments on commit d59e0bb

Please sign in to comment.