The storage adapter micro service for IoT PCS
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.github
app
conf
project
scripts
test
.gitattributes
.gitignore
.travis.yml
CONTRIBUTING.md
LICENSE
README.md
build.sbt
intellij-code-style.xml
sbt
sbt.cmd
version

README.md

DEPRECATED: This repository is no longer maintained. It has been moved to a new location. Please visit our new repository here. This microservice is present under services sub-module.

Build Issues Gitter

Storage Adapter Overview

This service allows management of key-values, abstracting the storage service semantic and presenting a simple interface to store data of any format using Azure Cosmos DB. DocDb is used in the service but could be easily swapped with a different store.

Values are organized in collections, it is possible to work with individual values and entire collections. Complex data structures are serialized by clients and managed as a simple text payload.

The service provides a RESTful endpoint to Create-Read-Update-Delete values, where each value has a unique Id referenced also as "Key", supporting concurrency.

IDs can be provided by the client or automatically generated by the service (i.e. UUIDs).

Dependencies

How to use the microservice

Quickstart - Running the service with Docker

  1. Install Docker: https://docs.docker.com/engine/installation
  2. Create your Azure Cosmos DB account with API type DocumentDB
  3. Find your Azure Cosmos DB account connection string. See Update your Connection Strings if you need help finding it.
  4. Store the "Azure Cosmos DB account connection string" in the env-vars-setup script, then run the script.
  5. Run the Storage Adapter service using the Docker run.
  6. Use an HTTP client such as Postman, to exercise the RESTful API to create a collection.

Running the service with IntelliJ

Intellij IDEA lets you open the application without using a command prompt, without configuring anything outside of the IDE. The SBT build tool takes care of downloading appropriate libraries, resolving dependencies and building the project (more info here).

Steps using IntelliJ IDEA Community 2017, with SBT plugin enabled:

  • "Open" the project with IntelliJ, the IDE should automatically recognize the SBT structure. Wait for the IDE to download some dependencies (see IntelliJ status bar). This may take a while, hang in there!
  • Create a new Run Configuration, of type "SBT Task", with any name.
    • Enter "run 9022" (including the double quotes) in Tasks. This ensures that the service starts using the TCP port 9022. If you desire to use a different port, feel free to change it.
    • Define the following environment variable:
      1. PCS_STORAGEADAPTER_DOCUMENTDB_CONNSTRING = {your CosmosDb DocumentDb connection string}
  • Either from the toolbar or the Run menu, execute the configuration just created, using the Debug command/button
  • Test that the service is up and running pointing your browser to http://127.0.0.1:9022/v1/status

And as a nice extra: if you edit the code, you don't need to stop/build/restart the application. Play and SBT automatically recompile the files modified on the fly. You can also see the re-build log in the Run Tool Window.

Run and Debug with Eclipse

The integration with Eclipse requires the

sbteclipse plugin, already included, and an initial setup via command line (more info here).

Steps using Eclipse Oxygen ("Eclipse for Java Developers" package):

  • Open a console (either Bash or Windows CMD), move into the project folder, execute sbt compile and then sbt eclipse. This generates some files required by Eclipse to recognize the project.
  • Open Eclipse, and from the Welcome screen "Import" an existing project, navigating to the root folder of the project.
  • From the console run sbt -jvm-debug 9999 "run 900X" to start the project
  • Test that the service is up and running pointing your browser to http://127.0.0.1:900X/v1/status
  • In Eclipse, select "Run -> Debug Configurations" and add a "Remote Java Application", using "localhost" and port "9999".
  • After saving this configuration, you can click "Debug" to connect to the running application.

Project Structure

This microservice contains the following projects:

--todo--

Build and Run from the command line

The scripts folder contains scripts for many frequent tasks:

  • build: compile all the projects and run the tests.
  • compile: compile all the projects.
  • run: compile the projects and run the service. This will prompt for elevated privileges in Windows to run the web service.

Updating the Docker image

The scripts folder includes a docker subfolder with the files required to package the service into a Docker image:

  • Dockerfile: docker images specifications
  • build: build a Docker container and store the image in the local registry
  • run: run the Docker container from the image stored in the local registry
  • content: a folder with files copied into the image, including the entry point script

Configuration and Environment variables

The service configuration is stored using Akka's HOCON format in application.conf.

The HOCON format is a human readable format, very close to JSON, with some useful features:

  • Ability to write comments
  • Support for substitutions, e.g. referencing environment variables
  • Supports JSON notation

The configuration file in the repository references some environment variables that need to created at least once. Depending on your OS and the IDE, there are several ways to manage environment variables:

Contributing to the solution

Please follow our contribution guildelines. We love PRs too.

Troubleshooting

Feedback

Please enter issues, bugs, or suggestions as GitHub Issues here: https://github.com/Azure/pcs-storage-adapter-java/issues.