Skip to content
This repository was archived by the owner on Oct 11, 2023. It is now read-only.

Commit f3fbc22

Browse files
peterfeltshathind-ms
authored andcommitted
Storage settings (#237)
* Adding new storage config settings
1 parent b8dab03 commit f3fbc22

File tree

5 files changed

+101
-1
lines changed

5 files changed

+101
-1
lines changed

Services/Runtime/ServicesConfig.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft. All rights reserved.
22

33
using System.IO;
4+
using Microsoft.Azure.IoTSolutions.DeviceSimulation.Services.Storage;
45

56
namespace Microsoft.Azure.IoTSolutions.DeviceSimulation.Services.Runtime
67
{
@@ -14,6 +15,11 @@ public interface IServicesConfig
1415
string StorageAdapterApiUrl { get; }
1516
int StorageAdapterApiTimeout { get; }
1617
bool TwinReadWriteEnabled { get; }
18+
StorageConfig MainStorage { get; }
19+
StorageConfig NodesStorage { get; set; }
20+
StorageConfig SimulationsStorage { get; set; }
21+
StorageConfig DevicesStorage { get; set; }
22+
StorageConfig PartitionsStorage { get; set; }
1723
}
1824

1925
// TODO: test Windows/Linux folder separator
@@ -61,6 +67,16 @@ public string IoTHubDataFolder
6167

6268
public bool TwinReadWriteEnabled { get; set; }
6369

70+
public StorageConfig MainStorage { get; set; }
71+
72+
public StorageConfig NodesStorage { get; set; }
73+
74+
public StorageConfig SimulationsStorage { get; set; }
75+
76+
public StorageConfig DevicesStorage { get; set; }
77+
78+
public StorageConfig PartitionsStorage { get; set; }
79+
6480
private string NormalizePath(string path)
6581
{
6682
return path

Services/Storage/StorageConfig.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
3+
namespace Microsoft.Azure.IoTSolutions.DeviceSimulation.Services.Storage
4+
{
5+
public class StorageConfig
6+
{
7+
public string StorageType { get; set; }
8+
public string DocumentDbConnString { get; set; }
9+
public string DocumentDbDatabase { get; set; }
10+
public string DocumentDbCollection { get; set; }
11+
public int DocumentDbRUs { get; set; }
12+
}
13+
}

WebService/Runtime/Config.cs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Microsoft.Azure.IoTSolutions.DeviceSimulation.Services.Concurrency;
77
using Microsoft.Azure.IoTSolutions.DeviceSimulation.Services.Diagnostics;
88
using Microsoft.Azure.IoTSolutions.DeviceSimulation.Services.Runtime;
9+
using Microsoft.Azure.IoTSolutions.DeviceSimulation.Services.Storage;
910
using Microsoft.Azure.IoTSolutions.DeviceSimulation.WebService.Auth;
1011

1112
// TODO: tests
@@ -70,6 +71,18 @@ public class Config : IConfig
7071
private const string STORAGE_ADAPTER_API_URL_KEY = STORAGE_ADAPTER_KEY + "webservice_url";
7172
private const string STORAGE_ADAPTER_API_TIMEOUT_KEY = STORAGE_ADAPTER_KEY + "webservice_timeout";
7273

74+
private const string MAIN_STORAGE_KEY = APPLICATION_KEY + "Storage:Main:";
75+
private const string NODES_STORAGE_KEY = APPLICATION_KEY + "Storage:Nodes:";
76+
private const string SIMULATIONS_STORAGE_KEY = APPLICATION_KEY + "Storage:Simulations:";
77+
private const string DEVICES_STORAGE_KEY = APPLICATION_KEY + "Storage:Devices:";
78+
private const string PARTITIONS_STORAGE_KEY = APPLICATION_KEY + "Storage:Partitions:";
79+
80+
private const string STORAGE_TYPE_KEY = "type";
81+
private const string DOCUMENTDB_CONNECTION_STRING_KEY = "documentdb_connstring";
82+
private const string DOCUMENTDB_DATABASE_KEY = "documentdb_database";
83+
private const string DOCUMENTDB_COLLECTION_KEY = "documentdb_collection";
84+
private const string DOCUMENTDB_RUS_KEY = "documentdb_collection_RUs";
85+
7386
private const string LOGGING_KEY = APPLICATION_KEY + "Logging:";
7487
private const string LOGGING_LOGLEVEL_KEY = LOGGING_KEY + "LogLevel";
7588
private const string LOGGING_INCLUDEPROCESSID_KEY = LOGGING_KEY + "IncludeProcessId";
@@ -193,7 +206,24 @@ private static IServicesConfig GetServicesConfig(IConfigData configData)
193206
IoTHubSdkDeviceClientTimeout = configData.GetOptionalUInt(IOTHUB_SDK_DEVICE_CLIENT_TIMEOUT_KEY),
194207
StorageAdapterApiUrl = configData.GetString(STORAGE_ADAPTER_API_URL_KEY),
195208
StorageAdapterApiTimeout = configData.GetInt(STORAGE_ADAPTER_API_TIMEOUT_KEY),
196-
TwinReadWriteEnabled = configData.GetBool(TWIN_READ_WRITE_ENABLED_KEY, true)
209+
TwinReadWriteEnabled = configData.GetBool(TWIN_READ_WRITE_ENABLED_KEY, true),
210+
MainStorage = GetStorageConfig(configData, MAIN_STORAGE_KEY),
211+
NodesStorage = GetStorageConfig(configData, NODES_STORAGE_KEY),
212+
SimulationsStorage = GetStorageConfig(configData, SIMULATIONS_STORAGE_KEY),
213+
DevicesStorage = GetStorageConfig(configData, DEVICES_STORAGE_KEY),
214+
PartitionsStorage = GetStorageConfig(configData, PARTITIONS_STORAGE_KEY)
215+
};
216+
}
217+
218+
private static StorageConfig GetStorageConfig(IConfigData configData, string prefix)
219+
{
220+
return new StorageConfig
221+
{
222+
StorageType = configData.GetString(prefix + STORAGE_TYPE_KEY),
223+
DocumentDbConnString = configData.GetString(prefix + DOCUMENTDB_CONNECTION_STRING_KEY),
224+
DocumentDbDatabase = configData.GetString(prefix + DOCUMENTDB_DATABASE_KEY),
225+
DocumentDbCollection = configData.GetString(prefix + DOCUMENTDB_COLLECTION_KEY),
226+
DocumentDbRUs = configData.GetInt(prefix + DOCUMENTDB_RUS_KEY)
197227
};
198228
}
199229

WebService/appsettings.ini

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,46 @@ webservice_url = "${PCS_STORAGEADAPTER_WEBSERVICE_URL}"
3232
webservice_timeout = 10000
3333

3434

35+
[DeviceSimulationService:Storage:Main]
36+
type = "documentDb"
37+
documentdb_connstring = "${PCS_STORAGEADAPTER_DOCUMENTDB_CONNSTRING}"
38+
documentdb_database = "devicesimulation"
39+
documentdb_collection = "main"
40+
documentdb_collection_RUs = 400
41+
42+
43+
[DeviceSimulationService:Storage:Nodes]
44+
type = "documentDb"
45+
documentdb_connstring = "${PCS_STORAGEADAPTER_DOCUMENTDB_CONNSTRING}"
46+
documentdb_database = "devicesimulation"
47+
documentdb_collection = "nodes"
48+
documentdb_collection_RUs = 400
49+
50+
51+
[DeviceSimulationService:Storage:Simulations]
52+
type = "documentDb"
53+
documentdb_connstring = "${PCS_STORAGEADAPTER_DOCUMENTDB_CONNSTRING}"
54+
documentdb_database = "devicesimulation"
55+
documentdb_collection = "simulations"
56+
documentdb_collection_RUs = 400
57+
58+
59+
[DeviceSimulationService:Storage:Devices]
60+
type = "documentDb"
61+
documentdb_connstring = "${PCS_STORAGEADAPTER_DOCUMENTDB_CONNSTRING}"
62+
documentdb_database = "devicesimulation"
63+
documentdb_collection = "devices"
64+
documentdb_collection_RUs = 2500
65+
66+
67+
[DeviceSimulationService:Storage:Partitions]
68+
type = "documentDb"
69+
documentdb_connstring = "${PCS_STORAGEADAPTER_DOCUMENTDB_CONNSTRING}"
70+
documentdb_database = "devicesimulation"
71+
documentdb_collection = "partitions"
72+
documentdb_collection_RUs = 2500
73+
74+
3575
[DeviceSimulationService:Deployment]
3676
# AAD Domain of the Azure subscription where the Azure IoT Hub is deployed.
3777
# The value is optional because the service can be deployed without a hub.

scripts/docker/docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ services:
1717
environment:
1818
- PCS_IOTHUB_CONNSTRING
1919
- PCS_STORAGEADAPTER_WEBSERVICE_URL=http://storageadapter:9022/v1
20+
- PCS_STORAGEADAPTER_DOCUMENTDB_CONNSTRING
2021
- PCS_AUTH_REQUIRED
2122
- PCS_CORS_WHITELIST
2223
- PCS_AUTH_ISSUER

0 commit comments

Comments
 (0)