PostgreSQL-backed hosting environment

This page describes the steps how to install Thriot in fully PostgreSql (9.4+)-based runtime environment. It means that all management data, telemetry data and of course messages are stored in a PostgreSql 9.4+ database.

We will discuss the installation procedure of a single-box environment, where the responsibilities of the box are the following:

  • APIs and Services
    • Central website
    • Management API
    • Platform API
    • Platform Websocket Service
    • Reporting API
    • Messaging API (private)
  • Data storage
    • Management Database
    • Telemetry database
    • Messaging database

Based on this description with quite minimal phantasy you can find out how to install the system on multiple boxes or even scale it out to more servers. When scaling out please consider the following rules:

  • The APIs can be freely scaled out expect for the Messaging API
  • Messaging API should run in single instance mode (failover clustering is OK)
  • The Websocket service can be freely scaled out
  • The database can run in HA mode

For easier configuration please refer to the following page: http://portal.thriot.io/package-autoconfiguration/

Server names used in this tutorial

This tutorial assumes that the target server is the following:

thriotpgsql.cloudapp.net

Of course you will install servers with different names, these are just examples. Ensure to use the correct names in all configurations and settings.

Prerequisites

This tutorial supposes the release v0.6 of source code.

Having the source code you can use the following command the produce binaries with default PostgreSQL configuration:

src\Service\Build> .\build.ps1 -config pgsql -configtmt pgsql -configmsg pgsql -copyConfigs yes -linuxify no

The results will go to the output\{CURRENTDATE}_pgsql folder.

Please note that in case of upgrading (to be discussed in the Upgrading section below) the -copyConfigs parameter must not be used to ensure that no config files are accidentally overwritten.

The output folder contains the following subfolders:

Folder Description Type
api Management API REST API
msvc Messaging Service API REST API
papi Platform API REST API
rapi Reporting API REST API
web Central website Thin website
websocketservice Websocket Service Windows Service
install install\configtemplates – Configuration templates
install\storage\management – Program that initializes management storage
install\storage\messaging – Script to create Message database storage
Templates, scripts and applications
plugins Plugins for telemetry data and queueing Plugins

 

Install IIS

In Server Manager select Add roles and features.

Here tick the Web Server (IIS) Role.

image1

Select the following role services:

image2

image3

image4

image5

Hit Next and do the installation.

Install HttpPlatformHandler

Follow this page to add HttpPlatformHandler:

http://www.iis.net/downloads/microsoft/httpplatformhandler

On some environments it may be preinstalled.

Install PostgreSql

Download the Windows x64 installer of PostgreSql v 9.4+. The installers name must be something like this: postgresql-9.4.1-3-windows-x64.exe

Start the installer.

You can configure installation and database directory freely:

image6

Set the superuser’s (postgres) password:

image7

Assume that you leave the default 5432 port number and locale.

After successful installation, it’s optional to select anything from the stackbuilder.

Configuring databases

Start pgAdmin III and login using the postgres user account.

Create the following three users:

  • thriot
  • thriotmessaging
  • thriottelemetry

Choose secure password for the users.

image8

Create 3 database:

  • Thriot – for management (set owner to thriot)
  • ThriotTelemetry – for storing telemetry data (set owner to thriottelemetry)
  • ThriotMessaging – for messaging (set owner to thriotmessaging)

image9

You should see the following results after creating all tree users and databases (with the right owners):

image10

To create management database entities from the build output select the install\storage\management folder and change the management database connection parameters (Thriot database in our case) in the Thriot.CreateSqlStorage.exe.config:

image11

Execute the Thriot.CreateSqlStorage.exe:

image12

Add new connection for the thiotmessaging user:

image13

Login with the newly created connection and execute the install\messaging\CreateDb.sql script:

image14

Create a new connection for the Thriot user and navigate to the Setting table in the Thriot database.

Select view top 100 rows and edit the rows according to the figure and table below:

image15

Explanation of the configuration settings:

Category Setting Value
Connection TelemetryConnection Connection string for recording telemetry data in PostgreSQL.
e.g.
Server=*******;Port=5432;Database=****;User Id=******;Password=*****;
Microservice MessagingServiceApiKey Shared secret for authenticating to the messaging service.
It’s an automatically generated value.
Microservice MessagingServiceEndpoint Messaging service url.It can be localhost for now since we are running on a single box.e.g.
http://localhost/msvc/v1/messaging
Microservice TelemetrySetupServiceApiKey Shared secret for authenticating to the telemetry setup service.It’s an automatically generated value.
Microservice TelemetrySetupServiceEndpoint Telemetry setup service endpoint.
It can be localhost for now since we are running on a single box.
e.g.
http://localhost/papi/v1/telemetryDataSinkSetup
PublicUrl ManagementApiUrl Management API url.e.g.
http://thriotpgsql.cloudapp.net/api/v1
PublicUrl PlatformApiUrl Platform API url.e.g.
http://thriotpgsql.cloudapp.net/papi/v1
PublicUrl PlatformWsUrl Platform Websocket url.e.g.
ws://thriotpgsql.cloudapp.net:8080
PublicUrl ReportingApiUrl Reporting API url.e.g.
http://thriotpgsql.cloudapp.net/rapi/v1
PublicUrl WebsiteUrl Central website url.e.g.
http://thriotpgsql.cloudapp.net
Runtime EmailActivation Specify If email activation is required.For production environment should be true.
e.g.
true
Runtime ServiceProfile ServiceProvider, SingleCompany or SingleService.ServiceProvider

 

Installing the web applications

Copy the api, msvc, papi, rapi, web, websocketservice and plugins folders to a newly created Thriot folder.

image16

The configuration files folder is located at the following places respectively:
  1. c:\Thriot\api\approot\packages\Thriot.Management.WebApi\1.0.0\root\config\
  2. c:\Thriot\pap\approot\packages\Thriot.Platform.WebApi\1.0.0\root\config\
  3. c:\Thriot\rapi\approot\packages\Thriot.Reporting.WebApi\1.0.0\root\config\
  4. c:\Thriot\msvc\approot\packages\Thriot.Messaging.WebApi\1.0.0\root\config\
  5. c:\Thriot\web\wwwroot\config\
  6. c:\Thriot\websocketservice\config\

Prepare the config files in the following way:

connectionstring.json:

{
    "ConnectionString": {
        "ManagementConnection": {
            "ConnectionString": "Server=127.0.0.1;Port=5432;Database=Thriot;User Id=thriot;Password=****************",
            "ProviderName": "Npgsql"
        }
    }
}

Ensure to have the correct connection string instead of the examples above.

connectionstringmsg.jsong should look like this:

{
    "ConnectionString": {
        "MessagingConnection": "Server=127.0.0.1;Port=5432;Database=ThriotMessaging;User Id=thriotmessaging;Password=****************"
    }
}

Ensure to have the correct HTTP endpoints instead of the examples above.

 

siteroots.js (for the central website):

app.constant('siteRoots', {
   managementRoot: 'http://thriotpgsql.cloudapp.net/api/v1',
   reportingRoot: 'http://thriotpgsql.cloudapp.net/rapi/v1'
});

Ensure to have the correct HTTP endpoints instead of the examples above.

 

smtpsettings.json (for management api):

{
    "SmtpSettings": {
        "FromAddress": "no-reply@thriot.io",
        "FromName": "Thriot",
        "BouncesAddress": "bounces@thriot.io",
        "Host": "smtp.sendgrid.net",
        "Port": "587",
        "UserName": "***",
        "Password": "***"
    }
}

Ensure to have the correct SMTP settings instead of the examples above.

If you are running an asp.net5 rc1 app under a virtual directory in IIS you need to do some workaround to support virtual directories. Thriot implements this by vdir.json config files.

vdir.json shoud look like this:

{“VDIR”: “/api”}
{“VDIR”: “/papi”}
{“VDIR”: “/rapi”}
{“VDIR”: “/msvc”}

respectively for management, platform, reporting and messaging services (they are reachable under api,thriot.io/management, etc). The vdir.json has to be put under the regular config directory as the other configurations.

 

nlog.*.configs are fine for demoing if your working directory is C:\Thriot.

 

Create a website called Thriot and point it to the c:\Thriot\web\wwwroot folder. Ensure to delete or disable the Default Website first.

pw1

Create api Application for the Management API (right click the Thriot website / add application) – c:\Thriot\api\wwwroot:

api

 

Create papi Application for the Platform API- c:\Thriot\papi\wwwroot:

papi

 

Create rapi Application for the Reporting API- c:\Thriot\rapi\wwwroot:

rapi

 

Create the msvc Application for the Messaging Services API- c:\Thriot\msvc\wwwroot:

msvc

 

The final structure should look like this if you look at the website in IIS Manager:

siteaspnet5_2

 

Installing the Websocket service

In the c:\Thriot\websocketservice run

c:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe Thriot.Platform.WebsocketService.exe

image20

Setting up logging

Create a folder named c:\Thriot\log.

Add Modify permissions to this folder for iis apppool\thriot user.

image21

image22

Do the same for nt service\ThriotWebSocketService user.

image23

Final steps

HTTP endpoint will be opened by default on the firewall, you should open the 8080 port for the websocket service.

image24

To start the Windows service you can use the Service Control Manager (services.msc) or issue the following command from the command line:

net start ThriotWebSocketService

If you are running on Azure or behind a firewall do not forget to open the 80 and 8080 ports.

Testing if everything works fine

Now navigate to the address of the web frontend server, register a new user, accept the registration, login with the user, create new company, service, network and device. If everything works fine you can start using the .NET or Linux C++ client libraries.

Upgrading

To upgrade to a newer/newest version do the following steps:

  1. Get the latest source snapshot
  2. Do a full rebuild with the same parameters as for the first time but ensure that you specify -copyConfig no setting.
  3. Update the binaries
  4. Execute the Management storage creator application with the same connectionstring settings (CreateSqlStorage) which won’t delete any data just upgrade the DB schema
  5. For the Messaging storage execute the appropriate CreateDB.sql script, which won’t delete any data just upgrade the DB schema
  6. Do a smoke test
Advertisements