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

Commit

Permalink
Storage settings (#237)
Browse files Browse the repository at this point in the history
* Adding new storage config settings
  • Loading branch information
peterfelts authored and hathind-ms committed Aug 28, 2018
1 parent b8dab03 commit f3fbc22
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 1 deletion.
16 changes: 16 additions & 0 deletions Services/Runtime/ServicesConfig.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.

using System.IO;
using Microsoft.Azure.IoTSolutions.DeviceSimulation.Services.Storage;

namespace Microsoft.Azure.IoTSolutions.DeviceSimulation.Services.Runtime
{
Expand All @@ -14,6 +15,11 @@ public interface IServicesConfig
string StorageAdapterApiUrl { get; }
int StorageAdapterApiTimeout { get; }
bool TwinReadWriteEnabled { get; }
StorageConfig MainStorage { get; }
StorageConfig NodesStorage { get; set; }
StorageConfig SimulationsStorage { get; set; }
StorageConfig DevicesStorage { get; set; }
StorageConfig PartitionsStorage { get; set; }
}

// TODO: test Windows/Linux folder separator
Expand Down Expand Up @@ -61,6 +67,16 @@ public string IoTHubDataFolder

public bool TwinReadWriteEnabled { get; set; }

public StorageConfig MainStorage { get; set; }

public StorageConfig NodesStorage { get; set; }

public StorageConfig SimulationsStorage { get; set; }

public StorageConfig DevicesStorage { get; set; }

public StorageConfig PartitionsStorage { get; set; }

private string NormalizePath(string path)
{
return path
Expand Down
13 changes: 13 additions & 0 deletions Services/Storage/StorageConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) Microsoft. All rights reserved.

namespace Microsoft.Azure.IoTSolutions.DeviceSimulation.Services.Storage
{
public class StorageConfig
{
public string StorageType { get; set; }
public string DocumentDbConnString { get; set; }
public string DocumentDbDatabase { get; set; }
public string DocumentDbCollection { get; set; }
public int DocumentDbRUs { get; set; }
}
}
32 changes: 31 additions & 1 deletion WebService/Runtime/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Microsoft.Azure.IoTSolutions.DeviceSimulation.Services.Concurrency;
using Microsoft.Azure.IoTSolutions.DeviceSimulation.Services.Diagnostics;
using Microsoft.Azure.IoTSolutions.DeviceSimulation.Services.Runtime;
using Microsoft.Azure.IoTSolutions.DeviceSimulation.Services.Storage;
using Microsoft.Azure.IoTSolutions.DeviceSimulation.WebService.Auth;

// TODO: tests
Expand Down Expand Up @@ -70,6 +71,18 @@ public class Config : IConfig
private const string STORAGE_ADAPTER_API_URL_KEY = STORAGE_ADAPTER_KEY + "webservice_url";
private const string STORAGE_ADAPTER_API_TIMEOUT_KEY = STORAGE_ADAPTER_KEY + "webservice_timeout";

private const string MAIN_STORAGE_KEY = APPLICATION_KEY + "Storage:Main:";
private const string NODES_STORAGE_KEY = APPLICATION_KEY + "Storage:Nodes:";
private const string SIMULATIONS_STORAGE_KEY = APPLICATION_KEY + "Storage:Simulations:";
private const string DEVICES_STORAGE_KEY = APPLICATION_KEY + "Storage:Devices:";
private const string PARTITIONS_STORAGE_KEY = APPLICATION_KEY + "Storage:Partitions:";

private const string STORAGE_TYPE_KEY = "type";
private const string DOCUMENTDB_CONNECTION_STRING_KEY = "documentdb_connstring";
private const string DOCUMENTDB_DATABASE_KEY = "documentdb_database";
private const string DOCUMENTDB_COLLECTION_KEY = "documentdb_collection";
private const string DOCUMENTDB_RUS_KEY = "documentdb_collection_RUs";

private const string LOGGING_KEY = APPLICATION_KEY + "Logging:";
private const string LOGGING_LOGLEVEL_KEY = LOGGING_KEY + "LogLevel";
private const string LOGGING_INCLUDEPROCESSID_KEY = LOGGING_KEY + "IncludeProcessId";
Expand Down Expand Up @@ -193,7 +206,24 @@ private static IServicesConfig GetServicesConfig(IConfigData configData)
IoTHubSdkDeviceClientTimeout = configData.GetOptionalUInt(IOTHUB_SDK_DEVICE_CLIENT_TIMEOUT_KEY),
StorageAdapterApiUrl = configData.GetString(STORAGE_ADAPTER_API_URL_KEY),
StorageAdapterApiTimeout = configData.GetInt(STORAGE_ADAPTER_API_TIMEOUT_KEY),
TwinReadWriteEnabled = configData.GetBool(TWIN_READ_WRITE_ENABLED_KEY, true)
TwinReadWriteEnabled = configData.GetBool(TWIN_READ_WRITE_ENABLED_KEY, true),
MainStorage = GetStorageConfig(configData, MAIN_STORAGE_KEY),
NodesStorage = GetStorageConfig(configData, NODES_STORAGE_KEY),
SimulationsStorage = GetStorageConfig(configData, SIMULATIONS_STORAGE_KEY),
DevicesStorage = GetStorageConfig(configData, DEVICES_STORAGE_KEY),
PartitionsStorage = GetStorageConfig(configData, PARTITIONS_STORAGE_KEY)
};
}

private static StorageConfig GetStorageConfig(IConfigData configData, string prefix)
{
return new StorageConfig
{
StorageType = configData.GetString(prefix + STORAGE_TYPE_KEY),
DocumentDbConnString = configData.GetString(prefix + DOCUMENTDB_CONNECTION_STRING_KEY),
DocumentDbDatabase = configData.GetString(prefix + DOCUMENTDB_DATABASE_KEY),
DocumentDbCollection = configData.GetString(prefix + DOCUMENTDB_COLLECTION_KEY),
DocumentDbRUs = configData.GetInt(prefix + DOCUMENTDB_RUS_KEY)
};
}

Expand Down
40 changes: 40 additions & 0 deletions WebService/appsettings.ini
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,46 @@ webservice_url = "${PCS_STORAGEADAPTER_WEBSERVICE_URL}"
webservice_timeout = 10000


[DeviceSimulationService:Storage:Main]
type = "documentDb"
documentdb_connstring = "${PCS_STORAGEADAPTER_DOCUMENTDB_CONNSTRING}"
documentdb_database = "devicesimulation"
documentdb_collection = "main"
documentdb_collection_RUs = 400


[DeviceSimulationService:Storage:Nodes]
type = "documentDb"
documentdb_connstring = "${PCS_STORAGEADAPTER_DOCUMENTDB_CONNSTRING}"
documentdb_database = "devicesimulation"
documentdb_collection = "nodes"
documentdb_collection_RUs = 400


[DeviceSimulationService:Storage:Simulations]
type = "documentDb"
documentdb_connstring = "${PCS_STORAGEADAPTER_DOCUMENTDB_CONNSTRING}"
documentdb_database = "devicesimulation"
documentdb_collection = "simulations"
documentdb_collection_RUs = 400


[DeviceSimulationService:Storage:Devices]
type = "documentDb"
documentdb_connstring = "${PCS_STORAGEADAPTER_DOCUMENTDB_CONNSTRING}"
documentdb_database = "devicesimulation"
documentdb_collection = "devices"
documentdb_collection_RUs = 2500


[DeviceSimulationService:Storage:Partitions]
type = "documentDb"
documentdb_connstring = "${PCS_STORAGEADAPTER_DOCUMENTDB_CONNSTRING}"
documentdb_database = "devicesimulation"
documentdb_collection = "partitions"
documentdb_collection_RUs = 2500


[DeviceSimulationService:Deployment]
# AAD Domain of the Azure subscription where the Azure IoT Hub is deployed.
# The value is optional because the service can be deployed without a hub.
Expand Down
1 change: 1 addition & 0 deletions scripts/docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ services:
environment:
- PCS_IOTHUB_CONNSTRING
- PCS_STORAGEADAPTER_WEBSERVICE_URL=http://storageadapter:9022/v1
- PCS_STORAGEADAPTER_DOCUMENTDB_CONNSTRING
- PCS_AUTH_REQUIRED
- PCS_CORS_WHITELIST
- PCS_AUTH_ISSUER
Expand Down

0 comments on commit f3fbc22

Please sign in to comment.