remote-monitoring-services-.../config
Elvin Morales 3badbaf364 Fix retry logic for deployment not seeding correctly 2018-11-19 15:23:38 -08:00
..
.github Adding codeowners & renaming microservice folders 2018-08-08 14:25:34 -07:00
.vscode Adding codeowners & renaming microservice folders 2018-08-08 14:25:34 -07:00
Services Fix retry logic for deployment not seeding correctly 2018-11-19 15:23:38 -08:00
Services.Test Convert ApplicationPermissions string to the ApplicationPermissionsAssigned boolean 2018-11-08 11:57:36 -08:00
WebService Merge branch 'master' into reMergeRbac 2018-11-19 14:36:47 -05:00
WebService.Test Merge branch 'master' into isaac/StatusAPI 2018-11-15 12:12:54 -08:00
docs fix typo in docs 2018-11-08 12:36:52 -08:00
scripts Add PCS_ARM_ENDPOINT_URL env var, add case insensitve dictionary, cleanup 2018-10-19 13:38:01 -07:00
.gitattributes Adding codeowners & renaming microservice folders 2018-08-08 14:25:34 -07:00
.gitconfig Adding codeowners & renaming microservice folders 2018-08-08 14:25:34 -07:00
.gitignore Adding codeowners & renaming microservice folders 2018-08-08 14:25:34 -07:00
CONTRIBUTING.md Adding codeowners & renaming microservice folders 2018-08-08 14:25:34 -07:00
DEVELOPMENT.md Adding codeowners & renaming microservice folders 2018-08-08 14:25:34 -07:00
LICENSE Adding codeowners & renaming microservice folders 2018-08-08 14:25:34 -07:00
README.md Merge remote-tracking branch 'origin/master' into rebase-actions-branch 2018-10-29 10:52:19 -07:00
config.sln move md file into docs folder, rename logicappclient to AzureResourceManagerClient 2018-10-22 15:08:33 -07:00
config.sln.DotSettings pcs suffix removed 2018-08-21 15:10:22 -07:00

README.md

Build Issues Gitter

Config Service Overview

This service handles communication with the Storage Adapter microservice to complete tasks.

The microservice provides a RESTful endpoint to make CRUD operations for "devicegroups", "solution-settings", and "user-settings". The data will be stored by the Storage Adapter microservice.

Why?

This microservice was built as part of the Azure IoT Remote Monitoring project to provide a generic implementation for an end-to-end IoT solution. More information here.

Features

  • Create or update device groups
  • Get all or a single device group
  • Get or upload logo
  • Get or set overall solution settings
  • Get or set individual user settings
  • Create or delete a package
  • Get all or a single uploaded package.

Documentation

  • View the API documentation in the Wiki

How to Use

Running the Service with Docker

You can run the microservice and its dependencies using Docker with the instructions here.

Running the Service Locally

Prerequisites

1. Deploy Azure Services

This service has a dependency on the following Azure resources. Follow the instructions for Deploy the Azure services.

  • Cosmos DB
  • Iot Hub
  • Maps (optional)

2. Setup Dependencies

This service depends on the following repositories. Run those services from the instructions in their READMEs in the following order.

  1. Storage Adapter Dotnet Microservice
  2. Telemetry Dotnet Microservice
  3. Device Simulation Dotnet Microservice
  4. Authentication Microservice

3. Environment variables required to run the service

In order to run the service, some environment variables need to be created at least once. See specific instructions for IDE or command line setup below for more information. More information on environment variables here.

  • PCS_AZUREMAPS_KEY - the Azure Maps API Key. This can be set to "static" if you do not have one.
  • PCS_AUTH_WEBSERVICE_URL = the url for the Auth Webservice used for key value storage
  • PCS_OFFICE365_CONNECTION_URL (Optional) = the url for the Office 365 Logic App connector
  • PCS_SOLUTION_NAME (Optional) = The name of the resource group for the solution. Used only if using logic apps for actions.
  • PCS_SUBSCRIPTION_ID(Optional) = The subscription id for the solution. Used only if using logic apps for actions.
    • PCS_ARM_ENDPOINT_URL (Optional) = the url for the Azure management APIs. Used only if using logic apps for actions.

Running the service with Visual Studio or VS Code

  1. Make sure the Prerequisites are set up.
  2. Install .NET Core 2.x
  3. Install any recent edition of Visual Studio (Windows/MacOS) or Visual Studio Code (Windows/MacOS/Linux).
  4. Open the solution in Visual Studio or VS Code.
  5. Define the following environment variables. See Configuration and Environment variables for detailed information for setting these for your enviroment.
    1. PCS_STORAGEADAPTER_WEBSERVICE_URL = http://localhost:9022/v1
    2. PCS_DEVICESIMULATION_WEBSERVICE_URL = http://localhost:9003/v1
    3. PCS_TELEMETRY_WEBSERVICE_URL = http://localhost:9004/v1
    4. PCS_AZUREMAPS_KEY = static
    5. PCS_AUTH_WEBSERVICE_URL = http://localhost:9001/v1
    6. PCS_OFFICE365_CONNECTION_URL (Optional)
    7. PCS_SOLUTION_NAME (Optional)
    8. PCS_SUBSCRIPTION_ID(Optional)
    9. PCS_ARM_ENDPOINT_URL (Optional)
  6. Start the WebService project (e.g. press F5).
  7. Use an HTTP client such as Postman, to exercise the RESTful API.

Running the service from the command line

  1. Make sure the Prerequisites are set up.
  2. Set the following environment variables in your system. More information on environment variables here.
    1. PCS_STORAGEADAPTER_WEBSERVICE_URL = http://localhost:9022/v1
    2. PCS_DEVICESIMULATION_WEBSERVICE_URL = http://localhost:9003/v1
    3. PCS_TELEMETRY_WEBSERVICE_URL = http://localhost:9004/v1
    4. PCS_AZUREMAPS_KEY = static
    5. PCS_AUTH_WEBSERVICE_URL = http://localhost:9001/v1
    6. PCS_OFFICE365_CONNECTION_URL (Optional)
    7. PCS_SOLUTION_NAME (Optional)
    8. PCS_SUBSCRIPTION_ID(Optional)
    9. PCS_ARM_ENDPOINT_URL (Optional)
  3. Use the scripts in the scripts folder 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.

Project Structure

This microservice contains the following projects:

  • WebService.csproj - C# web service exposing REST interface for config functionality
  • WebService.Test.csproj - Unit tests for web services functionality
  • Services.csproj - C# assembly containining business logic for interacting with storage microserivce, telemetry microservice and device simulation microservice
  • Services.Test.csproj - Unit tests for services functionality
  • Solution/scripts - Contains build scripts, docker container creation scripts, and scripts for running the microservice from the command line

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 accessed via ASP.NET Core configuration adapters, and stored in appsettings.ini. The INI format allows to store values in a readable format, with comments.

The configuration also supports references to environment variables, e.g. to import credentials and network details. Environment variables are not mandatory though, you can for example edit appsettings.ini and write credentials directly in the file. Just be careful not sharing the changes, e.g. sending a Pull Request or checking in the changes in git.

The configuration file in the repository references some environment variables that need to be defined. Depending on the OS and the IDE used, there are several ways to manage environment variables.

  1. If you're using Visual Studio (Windows/MacOS), the environment variables are loaded from the project settings. Right click on WebService, and select Options/Properties, and find the section with the list of env vars. See WebService/Properties/launchSettings.json.
  2. Visual Studio Code (Windows/MacOS/Linux) loads the environment variables from .vscode/launch.json
  3. When running the service with Docker or from the command line, the application will inherit environment variables values from the system.

Contributing to the solution

Please follow our contribution guildelines and code style conventions.

Feedback

Please enter issues, bugs, or suggestions as GitHub Issues.

License

Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT License.