Step-By-Step Guide to Configuring Applications

This post will guide you through creating a new suite and configuring it.  To familiarize with KonfDB, please read through KonfDB Configuration Model.  We will create the same suite mentioned in the post KonfDB Configuration Model

New Suite

This step needs to be created by an authorized user on KonfDB.  If you do not have a user-id, you can request one with your KonfDB administrator (who has super user access to the server), or to another KonfDB user.

Once you are authorized user, you can run KonfDBRC with right settings and type following commands.  In this sample, we will be executing this command with user konfdbuser_ro

NewSuite /name:Customer

This command NewSuite will create a suite and give you an output as under

{
  "SuiteId": 2,
  "SuiteName": "Customer",
  "IsActive": true,
  "UsesSysEncryption": true,
  "PublicKey": "BgIAAACkAABSU0ExAAQAAAEAAQC9hfzwaMJgopLTDErTUIGcdsrJPbTYMJNAarK09vnhWYhlknNRdPSdlBy/cvTbeQjn/tdspIDiqKWx8ms1uxhIFetABY+1QHpfMFoWdOhITWXqbWqrXvq/HC+aSqAQEH0MjVztXQ484Q/cWzSngQp/KiXPQkSuheSGaBlAamgT5Q==",
  "Environments": [
    {
      "EnvironmentName": "*",
      "EnvironmentType": "PROD",
      "EnvironmentId": 5
    }
  ],
  "Applications": [
    {
      "ApplicationName": "*",
      "Description": "All Applications in Suite Customer",
      "ApplicationId": 3
    }
  ],
  "Regions": [
    {
      "RegionId": 4,
      "RegionName": "*",
      "Description": "All Regions in Suite Customer"
    }
  ],
  "Servers": [
    {
      "ServerId": 3,
      "ServerName": "*",
      "Description": "All Servers in Suite Customer"
    }
  ],
  "Users": [
    {
      "Role": "Admin",
      "Username": "konfdbuser_ro"
    }
  ]
}

Please note down the suite-id number ‘2’ as that will be used in all other commands

Adding Applications

To add 2 applications i.e. CustomerServicePortal and BackendService using NewApp command, execute following 2 commands.  Here we will reference the suite id (/sid) 2 to indicate the suite in which the applications need to be created

NewApp /sid:2 /name:CustomerServicePortal
NewApp /sid:2 /name:BackendService

These commands will give output as

{
  "ApplicationName": "CustomerServicePortal",
  "ApplicationId": 5
}
{
  "ApplicationName": "BackendService",
  "ApplicationId": 6
}

Adding Environments

To add multiple environments (Development, User Testing and Production) to the suite, you can type following commands

NewEnv /sid:2 /name:Development /type:DEV
NewEnv /sid:2 /name:"User Testing" /type:UAT
NewEnv /sid:2 /name:Production /type:PROD

 

Adding Regions

To add multiple regions (APAC, US and EUROPE) to the suite, you can type following commands

NewRegion /sid:2 /name:APAC
NewRegion /sid:2 /name:US
NewRegion /sid:2 /name:EUROPE

 

Adding Servers

To add multiple servers (Server.01…. Server.0N) to the suite, you can type following commands

NewServer /sid:2 /name:SERVER.01
NewServer /sid:2 /name:SERVER.02
NewServer /sid:2 /name:SERVER.03
NewServer /sid:2 /name:SERVER.04
NewServer /sid:2 /name:SERVER.05
NewServer /sid:2 /name:SERVER.06
NewServer /sid:2 /name:SERVER.07
NewServer /sid:2 /name:SERVER.08
NewServer /sid:2 /name:SERVER.09
NewServer /sid:2 /name:SERVER.10

 

Adding Configuration Parameters

As described in KonfDB Configuration Model, we will add 4 parameters.  While adding these 4 parameters, it is important to note the parameter-id

NewParam /sid:2 /name:CertificateKey /val:KEY.DEV.1
NewParam /sid:2 /name:CertificateKey /val:KEY.UAT.2
NewParam /sid:2 /name:CertificateKey /val:KEY.PROD.1
NewParam /sid:2 /name:CertificateKey /val:KEY.PROD.2

These commands will provide an output such as,

{
  "ParameterId": 8,
  "ParameterName": "CertificateKey",
  "ParameterValue": "KEY.DEV.1",
  "IsEncrypted": false
}
{
  "ParameterId": 9,
  "ParameterName": "CertificateKey",
  "ParameterValue": "KEY.UAT.2",
  "IsEncrypted": false
}
{
  "ParameterId": 10,
  "ParameterName": "CertificateKey",
  "ParameterValue": "KEY.PROD.1",
  "IsEncrypted": false
}
{
  "ParameterId": 11,
  "ParameterName": "CertificateKey",
  "ParameterValue": "KEY.PROD.2",
  "IsEncrypted": false
}

 

These parameters are added to KonfDB, but these are not still added to our suite.  To add these to the suite, we need to add mapping.

Mapping Parameters to Applications, Environment, Regions and Servers

Based on the IDs of Applications, Environments, Servers, Regions and Parameters, the mapping required (as per example in KonfDB Configuration Model) is shown in the table below

Parameter ID Parameter Value Application ID Environment ID Server ID Region ID
8 KEY.DEV.1 5 7 5 6
8 KEY.DEV.1 6 7 6 6
9 KEY.UAT.2 5 8 7 7
9 KEY.UAT.2 6 8 8 7
9 KEY.UAT.2 6 8 9 8
10 KEY.PROD.1 5 9 10 6
10 KEY.PROD.1 5 9 11 7
11 KEY.PROD.2 6 9 12 6
11 KEY.PROD.2 6 9 13 8
11 KEY.PROD.2 6 9 14 7

The commands to create mapping as per the table above will be

NewMap /sid:2 /pid:8 /srid:5 /aid:5 /eid:7 /rid:6
NewMap /sid:2 /pid:8 /srid:6 /aid:6 /eid:7 /rid:6
NewMap /sid:2 /pid:9 /srid:7 /aid:5 /eid:8 /rid:7
NewMap /sid:2 /pid:9 /srid:8 /aid:6 /eid:8 /rid:7
NewMap /sid:2 /pid:9 /srid:9 /aid:6 /eid:8 /rid:8
NewMap /sid:2 /pid:10 /srid:10 /aid:5 /eid:9 /rid:6
NewMap /sid:2 /pid:10 /srid:11 /aid:5 /eid:9 /rid:7
NewMap /sid:2 /pid:11 /srid:12 /aid:6 /eid:9 /rid:6
NewMap /sid:2 /pid:11 /srid:13 /aid:6 /eid:9 /rid:8
NewMap /sid:2 /pid:11 /srid:14 /aid:6 /eid:9 /rid:7

Verify Application Configuration

To verify the configuration mappings created, you can execute following commands

getmap /sid:2

The output will be

[
  {
    "SuiteId": 2,
    "EnvironmentId": 7,
    "ApplicationId": 5,
    "RegionId": 6,
    "ServerId": 5,
    "ParameterId": 8
  },
  {
    "SuiteId": 2,
    "EnvironmentId": 7,
    "ApplicationId": 6,
    "RegionId": 6,
    "ServerId": 6,
    "ParameterId": 8
  },
  {
    "SuiteId": 2,
    "EnvironmentId": 8,
    "ApplicationId": 5,
    "RegionId": 7,
    "ServerId": 7,
    "ParameterId": 9
  },
  {
    "SuiteId": 2,
    "EnvironmentId": 8,
    "ApplicationId": 6,
    "RegionId": 7,
    "ServerId": 8,
    "ParameterId": 9
  },
  {
    "SuiteId": 2,
    "EnvironmentId": 8,
    "ApplicationId": 6,
    "RegionId": 8,
    "ServerId": 9,
    "ParameterId": 9
  },
  {
    "SuiteId": 2,
    "EnvironmentId": 9,
    "ApplicationId": 5,
    "RegionId": 6,
    "ServerId": 10,
    "ParameterId": 10
  },
  {
    "SuiteId": 2,
    "EnvironmentId": 9,
    "ApplicationId": 5,
    "RegionId": 7,
    "ServerId": 11,
    "ParameterId": 10
  },
  {
    "SuiteId": 2,
    "EnvironmentId": 9,
    "ApplicationId": 6,
    "RegionId": 6,
    "ServerId": 12,
    "ParameterId": 11
  },
  {
    "SuiteId": 2,
    "EnvironmentId": 9,
    "ApplicationId": 6,
    "RegionId": 8,
    "ServerId": 13,
    "ParameterId": 11
  },
  {
    "SuiteId": 2,
    "EnvironmentId": 9,
    "ApplicationId": 6,
    "RegionId": 7,
    "ServerId": 14,
    "ParameterId": 11
  }
]

Alternatively, you can also get exact parameter values for a suite

getparams /sid:2

which will give you an output as

[
  {
    "ParameterId": 8,
    "ParameterName": "CertificateKey",
    "ParameterValue": "KEY.DEV.1",
    "IsEncrypted": false
  },
  {
    "ParameterId": 8,
    "ParameterName": "CertificateKey",
    "ParameterValue": "KEY.DEV.1",
    "IsEncrypted": false
  },
  {
    "ParameterId": 9,
    "ParameterName": "CertificateKey",
    "ParameterValue": "KEY.UAT.2",
    "IsEncrypted": false
  },
  {
    "ParameterId": 9,
    "ParameterName": "CertificateKey",
    "ParameterValue": "KEY.UAT.2",
    "IsEncrypted": false
  },
  {
    "ParameterId": 9,
    "ParameterName": "CertificateKey",
    "ParameterValue": "KEY.UAT.2",
    "IsEncrypted": false
  },
  {
    "ParameterId": 10,
    "ParameterName": "CertificateKey",
    "ParameterValue": "KEY.PROD.1",
    "IsEncrypted": false
  },
  {
    "ParameterId": 10,
    "ParameterName": "CertificateKey",
    "ParameterValue": "KEY.PROD.1",
    "IsEncrypted": false
  },
  {
    "ParameterId": 11,
    "ParameterName": "CertificateKey",
    "ParameterValue": "KEY.PROD.2",
    "IsEncrypted": false
  },
  {
    "ParameterId": 11,
    "ParameterName": "CertificateKey",
    "ParameterValue": "KEY.PROD.2",
    "IsEncrypted": false
  },
  {
    "ParameterId": 11,
    "ParameterName": "CertificateKey",
    "ParameterValue": "KEY.PROD.2",
    "IsEncrypted": false
  }
]

 

How will application get configuration?

Let’s assume that application BackendService (app id: 6) running in Region US (region id: 7) in UAT environment (env id: 8), the command will be

get /app:6 /env:8 /region:8 /server:9

The output to the API will be

[
  {
    "ParameterName": "CertificateKey",
    "ParameterValue": "KEY.UAT.2",
    "MatchProfile": "ParamId:9|App:6|Server:9|Env:8|Region:8|Suite:2",
    "IsEncrypted": false
  }
]

With .NET framework using KonfDBCF, your code will look like

class Program
    {
        static void Main(string[] args)
        {
            try
            {
                // Create connection to Command Service of KonfDB based on settings
                // in app.config file
                ICommandService commandService = ConnectionFactory.GetInstance();

                // Get the user token if authenticated
                var userToken = ConnectionFactory.GetUserToken();

                // var commands = commandService.GetCommandsStartingWith("");

                // If we got back a token, means user was authenticated
                if (userToken != null)
                {
                    var output = commandService.ExecuteCommand("get /app:6 /env:8 /region:8 /server:9", userToken);
                    if (output != null)
                    {
                        var parameters = (List<ConfigurationModel>)output.Data;
                        parameters.ForEach(param =>
                        {
                            Console.WriteLine(param.ParameterName + "=" + param.ParameterValue);
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }

            Console.WriteLine("Press any key to exit..");
            Console.ReadKey();
        }
    }

The output of this .NET program will be

CertificateKey=KEY.UAT.2