Skip to content
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

PIOT-GDA-11-005: Implement BaseCloudClient and CloudClientFactory to support additional cloud integration options #158

Open
labbenchstudios opened this issue Mar 9, 2021 · 0 comments
Labels
additional Additional exercise exercise New feature to implement as an exercise
Milestone

Comments

@labbenchstudios
Copy link
Contributor

labbenchstudios commented Mar 9, 2021

Description

  • This optional exercise implements the detailed design depicted in Chapter 11 of Programming the Internet of Things, where a factory class is used to create ICloudClient instances - based on a configuration file entry - that allow connectivity to multiple cloud service providers' hosted MQTT brokers.

Objective

  • Create a factory class that can create instances of ICloudClient specific to a given cloud service provider.
  • Create an abstract base class that contains the generic functionality of any ICloudClient to be used as the super class of cloud service provider specific ICloudClient instances that use MQTT / TLS for connectivity.

Review the README

  • Please see README.md for further information on, and use of, this content.
  • License for embedded documentation and source codes: PIOT-DOC-LIC

Estimated effort may vary greatly

  • The estimated level of effort for this exercise shown in the 'Estimate' section below is a very rough approximation. The actual level of effort may vary greatly depending on your development and test environment, experience with the requisite technologies, and many other factors.

Actions

  • Create a new class named CloudClientFactory. If you prefer, you can create this as a Singleton via the following method signature: public static final CloudClientFactory getInstance(). If you choose this approach, your constructor should be private, and the instance can be declared as follows: private static final CloudClientFactory _Instance = new CloudClientFactory();.
  • Update your CSP specific ICloudClient implementation to use the appropriate configuration section from the next set of instructions (e.g., Cloud.GatewayService.AWS, which you can also add as a constant in ConfigConst)
  • Update your configuration file (PiotConfig.props) to support configuration sections for multiple, using Cloud.GatewayService as the generic properties with the entry specifying the actual cloud service configuration section to load. An example follows:
    • NOTE 1: For the Ubidots-specific configuration, please refer to PIOT-CFG-11-001 and PIOT-GDA-11-003.
    • NOTE 2: For students of Connected Devices, I show a coding sample during class that allows you to enter multiple 'cloudServiceName' entries - comma delimited - and implement the CloudClientFactory to return a List of ICloudClient implementations. You can choose to implement this on your own, or as shown below. The below example shows how you can have multiple CSP configurations, but use only one at a time based on the configuration.
[Cloud.GatewayService]
cloudServiceName = {TODO: enter 'AWS', 'Ubidots', or other - must match ending text of the next section}

[Cloud.GatewayService.AWS]
credFile         = ./cred/AwsCloudCred.props
certFile         = ./cert/AwsCloudCert.pem
privateKeyFile   = ./cert/AwsCloudKey.key
cloudServiceName = AWS
host             = {TODO: hostname}
securePort       = {TODO: secure port}
defaultQoS       = {TODO: select 0 or 1}
keepAlive        = {TODO: select keep alive seconds}
enableAuth       = True
enableCrypt      = True
baseUrl          = {WARNING: for AWS, do NOT enter here - use your credFile and do NOT commit to your repo}
baseTopic        = {blank}

[Cloud.GatewayService.Ubidots]
credFile         = ./cred/UbidotsCloudCred.props
certFile         = ./cert/UbidotsCloudCert.pem
cloudServiceName = Ubidots
host             = {TODO: hostname}
securePort       = {TODO: secure port}
defaultQoS       = {TODO: select 0 or 1}
keepAlive        = {TODO: select keep alive seconds}
enableAuth       = True
enableCrypt      = True
baseUrl          = {blank}
baseTopic        = {TODO: verify with CSP}
  • Create the method createCloudClient() method using the following signature: public ICloudClient createCloudClient()
  • Implement the method by including the following:
    • Retrieve the value of cloudServiceName from the Cloud.GatewayService section of the configuration file
    • Use the value to determine which specific ICloudClient instance to create.
    • Create - then return - the appropriate ICloudClient instance.
    • Be sure to handle any exceptions, such as an invalid configuration entry that does not specify the appropriate (or existing) ICloudClient implementation
  • NOTE: You may need to update MqttClientConnector if you're using it as the MQTT connection logic to integrate with your selected CSP. If so, you can simply do the following:
    • Add a new contructor to MqttClientConnector that accepts the String cloudGatewaySectionName parameter, and - once verified as a valid CSP entry - simply pass it to the initClientParameters() method. If not a valid CSP entry, simply pass the ConfigConst.MQTT_GATEWAY_SERVICE name to initClientParameters().

Estimate

  • Medium

Tests

  • In the src/test/java path within the 'programmingtheiot.part04.integration.connection' package, add the CloudClientFactoryTest test case by creating a new JUnit test class named CloudClientFactoryTest.
  • Add your integration tests within the class - these tests should allow you to verify that CloudClientFactory can create an ICloudClient instance for the target CSP based on the configuration file (PiotConfig.props).
    • Example Test:
      • Name: testCreateAndTestCloudClient
      • Purpose: Use CloudClientFactory to create a valid (non-null) and usable instance of ICloudClient based on settings within PiotConfig.props.
      • Acceptance: ICloudClient instance is non-null and connect / disconnect succeeds. This can be verified via Wireshark and through your CSP IoT connection console.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
additional Additional exercise exercise New feature to implement as an exercise
Projects
Programming the IoT - Exercises Kanba...
  
Lab Module 11 - Cloud Integration
Development

No branches or pull requests

1 participant