Skip to content

Commit

Permalink
fix(uat): change discover to discovery
Browse files Browse the repository at this point in the history
  • Loading branch information
bgklika committed Aug 22, 2023
1 parent 0564071 commit 13f192d
Show file tree
Hide file tree
Showing 13 changed files with 78 additions and 79 deletions.
2 changes: 1 addition & 1 deletion uat/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,4 @@ MQTT clients based on IoT Device SDK for Java v2, mosquitto C, Paho Java, Paho P

Not all features of MQTT v5.0 have been implemented in clients and are supported by gRPC proto and the control as was requested, these are not bugs but designed by requirement.

Discover of Core device broker feature is implemented only in the client based on AWS IoT device SDK library.
Discovery of Core device broker feature is implemented only in the client based on AWS IoT device SDK library.
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@

package com.aws.greengrass.testing.mqtt5.client;

import com.aws.greengrass.testing.mqtt.client.CoreDeviceDiscoverReply;
import com.aws.greengrass.testing.mqtt.client.CoreDeviceDiscoverRequest;
import com.aws.greengrass.testing.mqtt5.client.exceptions.DiscoverException;
import com.aws.greengrass.testing.mqtt.client.CoreDeviceDiscoveryReply;
import com.aws.greengrass.testing.mqtt.client.CoreDeviceDiscoveryRequest;
import com.aws.greengrass.testing.mqtt5.client.exceptions.DiscoveryException;

/**
* Interface of discovery client.
*/
public interface DiscoverClient {
public interface DiscoveryClient {

/**
* Does discover of Core device broker.
* Does discovery of Core device broker.
*
* @param request the request
* @return formatted gRPC response
* @throws DiscoverException on errors
* @throws DiscoveryException on errors
*/
CoreDeviceDiscoverReply discoverCoreDevice(CoreDeviceDiscoverRequest request) throws DiscoverException;
CoreDeviceDiscoveryReply discoveryCoreDevice(CoreDeviceDiscoveryRequest request) throws DiscoveryException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ public interface GRPCLink {
* Handle all gRPC requests received from control.
*
* @param mqttLib MQTT library
* @param discoverClient the discover client
* @param discoveryClient the discovery client
* @return shutdown reason as received from control or null
* @throws GRPCException on errors
* @throws InterruptedException when thread has been interrupted
*/
String handleRequests(@NonNull MqttLib mqttLib, @NonNull DiscoverClient discoverClient)
String handleRequests(@NonNull MqttLib mqttLib, @NonNull DiscoveryClient discoveryClient)
throws GRPCException, InterruptedException;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

package com.aws.greengrass.testing.mqtt5.client;

import com.aws.greengrass.testing.mqtt5.client.discover.DiscoverClientImpl;
import com.aws.greengrass.testing.mqtt5.client.discover.DiscoveryClientImpl;
import com.aws.greengrass.testing.mqtt5.client.exceptions.ClientException;
import com.aws.greengrass.testing.mqtt5.client.grpc.GRPCLibImpl;
import com.aws.greengrass.testing.mqtt5.client.sdkmqtt.MqttLibImpl;
Expand Down Expand Up @@ -108,7 +108,7 @@ private static void doAll(String... args) throws Exception {
GRPCLink link = gprcLib.makeLink(arguments.getAgentId(), arguments.getHosts(), arguments.getPort());

try (MqttLib mqttLib = new MqttLibImpl()) {
String reason = link.handleRequests(mqttLib, new DiscoverClientImpl());
String reason = link.handleRequests(mqttLib, new DiscoveryClientImpl());
link.shutdown(reason);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
package com.aws.greengrass.testing.mqtt5.client.discover;

import com.aws.greengrass.testing.mqtt.client.CoreDeviceConnectivityInfo;
import com.aws.greengrass.testing.mqtt.client.CoreDeviceDiscoverReply;
import com.aws.greengrass.testing.mqtt.client.CoreDeviceDiscoverRequest;
import com.aws.greengrass.testing.mqtt.client.CoreDeviceDiscoveryReply;
import com.aws.greengrass.testing.mqtt.client.CoreDeviceDiscoveryRequest;
import com.aws.greengrass.testing.mqtt.client.CoreDeviceGroup;
import com.aws.greengrass.testing.mqtt5.client.DiscoverClient;
import com.aws.greengrass.testing.mqtt5.client.exceptions.DiscoverException;
import com.aws.greengrass.testing.mqtt5.client.exceptions.DiscoveryException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import software.amazon.awssdk.crt.io.SocketOptions;
Expand All @@ -29,14 +28,14 @@
import java.util.concurrent.TimeoutException;

/**
* Implementation of discover client.
* Implementation of discovery client.
*/
public class DiscoverClientImpl implements DiscoverClient {
private static final Logger logger = LogManager.getLogger(DiscoverClientImpl.class);
public class DiscoveryClientImpl implements com.aws.greengrass.testing.mqtt5.client.DiscoveryClient {
private static final Logger logger = LogManager.getLogger(DiscoveryClientImpl.class);

@Override
public CoreDeviceDiscoverReply discoverCoreDevice(CoreDeviceDiscoverRequest request)
throws DiscoverException {
public CoreDeviceDiscoveryReply discoveryCoreDevice(CoreDeviceDiscoveryRequest request)
throws DiscoveryException {
try (SocketOptions socketOptions = new SocketOptions();
TlsContextOptions tlsOptions = TlsContextOptions.createWithMtls(request.getCert(), request.getKey())
.withCertificateAuthority(request.getCa())
Expand All @@ -50,23 +49,23 @@ public CoreDeviceDiscoverReply discoverCoreDevice(CoreDeviceDiscoverRequest requ
return convertResponseToReply(response);
} catch (InterruptedException | ExecutionException | TimeoutException ex) {
logger.atError().withThrowable(ex).log("Failed during discover");
throw new DiscoverException("Could not do discover", ex);
throw new DiscoveryException("Could not do discovery", ex);
}
}
}

private CoreDeviceDiscoverReply convertResponseToReply(final DiscoverResponse response)
throws DiscoverException {
private CoreDeviceDiscoveryReply convertResponseToReply(final DiscoverResponse response)
throws DiscoveryException {
if (response == null) {
throw new DiscoverException("Discovery response is missing");
throw new DiscoveryException("Discovery response is missing");
}

final List<GGGroup> groups = response.getGGGroups();
if (groups == null || groups.isEmpty() || groups.get(0) == null) {
throw new DiscoverException("Groups are missing in discovery response");
throw new DiscoveryException("Groups are missing in discovery response");
}

CoreDeviceDiscoverReply.Builder builder = CoreDeviceDiscoverReply.newBuilder();
CoreDeviceDiscoveryReply.Builder builder = CoreDeviceDiscoveryReply.newBuilder();
for (final GGGroup group : groups) {
List<String> ca = group.getCAs();
logger.atInfo().log("Discovered groupId {} with {} CA", group.getGGGroupId(), ca.size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,28 @@
package com.aws.greengrass.testing.mqtt5.client.exceptions;

/**
* Client's exception related to discover parts.
* Client's exception related to discovery parts.
*/
public class DiscoverException extends ClientException {
public class DiscoveryException extends ClientException {
private static final long serialVersionUID = -2081564070408021325L;

public DiscoverException() {
public DiscoveryException() {
super();
}

public DiscoverException(String message) {
public DiscoveryException(String message) {
super(message);
}

public DiscoverException(String message, Throwable cause) {
public DiscoveryException(String message, Throwable cause) {
super(message, cause);
}

public DiscoverException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
public DiscoveryException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}

public DiscoverException(Throwable cause) {
public DiscoveryException(Throwable cause) {
super(cause);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

package com.aws.greengrass.testing.mqtt5.client.grpc;

import com.aws.greengrass.testing.mqtt.client.CoreDeviceDiscoverReply;
import com.aws.greengrass.testing.mqtt.client.CoreDeviceDiscoverRequest;
import com.aws.greengrass.testing.mqtt.client.CoreDeviceDiscoveryReply;
import com.aws.greengrass.testing.mqtt.client.CoreDeviceDiscoveryRequest;
import com.aws.greengrass.testing.mqtt.client.Empty;
import com.aws.greengrass.testing.mqtt.client.Mqtt5ConnAck;
import com.aws.greengrass.testing.mqtt.client.Mqtt5Message;
Expand All @@ -25,11 +25,11 @@
import com.aws.greengrass.testing.mqtt.client.MqttUnsubscribeRequest;
import com.aws.greengrass.testing.mqtt.client.ShutdownRequest;
import com.aws.greengrass.testing.mqtt.client.TLSSettings;
import com.aws.greengrass.testing.mqtt5.client.DiscoverClient;
import com.aws.greengrass.testing.mqtt5.client.DiscoveryClient;
import com.aws.greengrass.testing.mqtt5.client.GRPCClient;
import com.aws.greengrass.testing.mqtt5.client.MqttConnection;
import com.aws.greengrass.testing.mqtt5.client.MqttLib;
import com.aws.greengrass.testing.mqtt5.client.exceptions.DiscoverException;
import com.aws.greengrass.testing.mqtt5.client.exceptions.DiscoveryException;
import com.aws.greengrass.testing.mqtt5.client.exceptions.MqttException;
import io.grpc.Grpc;
import io.grpc.InsecureServerCredentials;
Expand Down Expand Up @@ -83,7 +83,7 @@ class GRPCControlServer {
private final int boundPort;

private MqttLib mqttLib;
private DiscoverClient discoverClient;
private DiscoveryClient discoveryClient;
private String shutdownReason;


Expand Down Expand Up @@ -598,14 +598,14 @@ public void unsubscribeMqtt(MqttUnsubscribeRequest request,
}

/**
* Handler of DiscoverCoreDevice gRPC call.
* Handler of DiscoveryCoreDevice gRPC call.
*
* @param request incoming request
* @param responseObserver response control
*/
@Override
public void discoverCoreDevice(CoreDeviceDiscoverRequest request,
StreamObserver<CoreDeviceDiscoverReply> responseObserver) {
public void discoveryCoreDevice(CoreDeviceDiscoveryRequest request,
StreamObserver<CoreDeviceDiscoveryReply> responseObserver) {
int timeout = request.getTimeout();
if (timeout < TIMEOUT_MIN) {
logger.atWarn().log("invalid unsubscribe timeout {}, must be >= {}", timeout, TIMEOUT_MIN);
Expand Down Expand Up @@ -660,11 +660,11 @@ public void discoverCoreDevice(CoreDeviceDiscoverRequest request,
return;
}

CoreDeviceDiscoverReply reply;
CoreDeviceDiscoveryReply reply;
try {
reply = discoverClient.discoverCoreDevice(request);
} catch (DiscoverException ex) {
logger.atError().withThrowable(ex).log("exception during discover");
reply = discoveryClient.discoveryCoreDevice(request);
} catch (DiscoveryException ex) {
logger.atError().withThrowable(ex).log("exception during discovery");
responseObserver.onError(ex);
return;
}
Expand Down Expand Up @@ -719,9 +719,9 @@ public String getShutdownReason() {
*
* @param mqttLib reference to MQTT side of the client to handler incoming requests
*/
public void waiting(MqttLib mqttLib, DiscoverClient discoverClient) throws InterruptedException {
public void waiting(MqttLib mqttLib, DiscoveryClient discoveryClient) throws InterruptedException {
this.mqttLib = mqttLib;
this.discoverClient = discoverClient;
this.discoveryClient = discoveryClient;
logger.atInfo().log("Server awaitTermination");
server.awaitTermination();
logger.atInfo().log("Server awaitTermination done");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

package com.aws.greengrass.testing.mqtt5.client.grpc;

import com.aws.greengrass.testing.mqtt5.client.DiscoverClient;
import com.aws.greengrass.testing.mqtt5.client.DiscoveryClient;
import com.aws.greengrass.testing.mqtt5.client.GRPCLink;
import com.aws.greengrass.testing.mqtt5.client.MqttLib;
import com.aws.greengrass.testing.mqtt5.client.exceptions.GRPCException;
Expand Down Expand Up @@ -93,10 +93,10 @@ public GRPCControlServer newServer(@NonNull GRPCDiscoveryClient client, @NonNull
}

@Override
public String handleRequests(@NonNull MqttLib mqttLib, @NonNull DiscoverClient discoverClient)
public String handleRequests(@NonNull MqttLib mqttLib, @NonNull DiscoveryClient discoveryClient)
throws GRPCException, InterruptedException {
logger.atInfo().log("Handle gRPC requests");
server.waiting(mqttLib, discoverClient);
server.waiting(mqttLib, discoveryClient);
return "Agent shutdown by OTF request '" + server.getShutdownReason() + "'";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

package com.aws.greengrass.testing.mqtt5.client.grpc;

import com.aws.greengrass.testing.mqtt5.client.DiscoverClient;
import com.aws.greengrass.testing.mqtt5.client.DiscoveryClient;
import com.aws.greengrass.testing.mqtt5.client.MqttLib;
import com.aws.greengrass.testing.mqtt5.client.exceptions.GRPCException;
import org.junit.jupiter.api.extension.ExtendWith;
Expand Down Expand Up @@ -69,14 +69,14 @@ void GIVEN_link_WHEN_handle_requests_THEN_server_is_called_correct_reason_return
when(server.getShutdownReason()).thenReturn(reason);

final MqttLib mqttLib = mock(MqttLib.class);
final DiscoverClient discoverClient = mock(DiscoverClient.class);
final DiscoveryClient discoveryClient = mock(DiscoveryClient.class);

// WHEN
String shutdownReason = gRPCLinkImpl.handleRequests(mqttLib, discoverClient);
String shutdownReason = gRPCLinkImpl.handleRequests(mqttLib, discoveryClient);

// THEN
assertEquals(expectedShutdownReason, shutdownReason);
verify(server).waiting(eq(mqttLib), eq(discoverClient));
verify(server).waiting(eq(mqttLib), eq(discoveryClient));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

package com.aws.greengrass.testing.mqtt.client.control.api;

import com.aws.greengrass.testing.mqtt.client.CoreDeviceDiscoverReply;
import com.aws.greengrass.testing.mqtt.client.CoreDeviceDiscoverRequest;
import com.aws.greengrass.testing.mqtt.client.CoreDeviceDiscoveryReply;
import com.aws.greengrass.testing.mqtt.client.CoreDeviceDiscoveryRequest;
import com.aws.greengrass.testing.mqtt.client.Mqtt5Disconnect;
import com.aws.greengrass.testing.mqtt.client.Mqtt5Message;
import com.aws.greengrass.testing.mqtt.client.MqttConnectRequest;
Expand Down Expand Up @@ -99,11 +99,11 @@ ConnectionControl createMqttConnection(@NonNull MqttConnectRequest connectReques


/**
* Do discover of Core device broker.
* Do discovery of Core device broker.
*
* @param discoverRequest the request with clients name and credentials
* @param discoveryRequest the request with clients name and credentials
* @return the reply with connectivity information of IoT Core device broker
* @throws StatusRuntimeException on errors
*/
CoreDeviceDiscoverReply discoverCoreDevice(@NonNull CoreDeviceDiscoverRequest discoverRequest);
CoreDeviceDiscoveryReply discoveryCoreDevice(@NonNull CoreDeviceDiscoveryRequest discoveryRequest);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

package com.aws.greengrass.testing.mqtt.client.control.implementation;

import com.aws.greengrass.testing.mqtt.client.CoreDeviceDiscoverReply;
import com.aws.greengrass.testing.mqtt.client.CoreDeviceDiscoverRequest;
import com.aws.greengrass.testing.mqtt.client.CoreDeviceDiscoveryReply;
import com.aws.greengrass.testing.mqtt.client.CoreDeviceDiscoveryRequest;
import com.aws.greengrass.testing.mqtt.client.Mqtt5ConnAck;
import com.aws.greengrass.testing.mqtt.client.Mqtt5Disconnect;
import com.aws.greengrass.testing.mqtt.client.Mqtt5Message;
Expand Down Expand Up @@ -203,9 +203,9 @@ public ConnectionControl createMqttConnection(@NonNull MqttConnectRequest connec
}

@Override
public CoreDeviceDiscoverReply discoverCoreDevice(@NonNull CoreDeviceDiscoverRequest discoverRequest) {
CoreDeviceDiscoverReply reply = blockingStub.discoverCoreDevice(discoverRequest);
logger.atInfo().log("discoverCoreDevice: found {} groups", reply.getGroupListCount());
public CoreDeviceDiscoveryReply discoveryCoreDevice(@NonNull CoreDeviceDiscoveryRequest discoveryRequest) {
CoreDeviceDiscoveryReply reply = blockingStub.discoveryCoreDevice(discoveryRequest);
logger.atInfo().log("discoveryCoreDevice: found {} groups", reply.getGroupListCount());
return reply;
}

Expand Down
10 changes: 5 additions & 5 deletions uat/proto/mqtt_client_control.proto
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ service MqttClientControl {
rpc PublishMqtt(MqttPublishRequest) returns (MqttPublishReply) {}

// do Core device discovery
rpc DiscoverCoreDevice(CoreDeviceDiscoverRequest) returns (CoreDeviceDiscoverReply) {}
rpc DiscoveryCoreDevice(CoreDeviceDiscoveryRequest) returns (CoreDeviceDiscoveryReply) {}
}

// Versions of MQTT protocol, used for compatibility, only MQTT_PROTOCOL_V50 actually supported
Expand Down Expand Up @@ -282,8 +282,8 @@ message MqttPublishReply {
}


// Request to discover Core device broker
message CoreDeviceDiscoverRequest {
// Request to discovery Core device broker
message CoreDeviceDiscoveryRequest {
int32 timeout = 1; // request timeout in seconds
string ca = 2; // PEM formatted CA to verify IoT Core
string cert = 3; // client's certificate, PEM formatted
Expand All @@ -304,8 +304,8 @@ message CoreDeviceGroup {
repeated CoreDeviceConnectivityInfo connectivityInfoList = 2; // connectivity information of Core Device broker
}

// Response to discover request
message CoreDeviceDiscoverReply {
// Response to discovery request
message CoreDeviceDiscoveryReply {
repeated CoreDeviceGroup groupList = 1; // device groups
}

Expand Down
Loading

0 comments on commit 13f192d

Please sign in to comment.