Skip to content

Commit

Permalink
Replace 'ditto.info' config by service info, vm-args and env variables.
Browse files Browse the repository at this point in the history
Signed-off-by: Cai Yufei (INST/ECS1) <yufei.cai@bosch-si.com>
  • Loading branch information
yufei-cai committed Jun 25, 2019
1 parent 83f7284 commit 8f877b6
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 16 deletions.
Expand Up @@ -220,7 +220,8 @@ Retrieve the configuration at the path `ditto.info` thus:
It is recommended to not omit the query parameter `path`. Otherwise the full configurations of all services are
aggregated in the response, which can become megabytes big.

Response example:
The path `ditto.info` points to information on service name, service instance index, JVM arguments and environment
variables. Response example:

```json
{
Expand All @@ -229,16 +230,32 @@ Response example:
"type": "common.responses:retrieveConfig",
"status": 200,
"config": {
"instance-index": "1",
"service-name": "gateway"
"env": {
"PATH": "/usr/games:/usr/local/games"
},
"service": {
"instance-index": "1",
"service-name": "gateway"
},
"vm-args": [
"-Dfile.encoding=UTF-8"
]
}
},
"?1": {
"type": "common.responses:retrieveConfig",
"status": 200,
"config": {
"instance-index": "1",
"service-name": "connectivity"
"env": {
"CONNECTIVITY_FLUSH_PENDING_RESPONSES_TIMEOUT": "3d"
},
"service": {
"instance-index": "1",
"service-name": "connectivity"
},
"vm-args": [
"-Dditto.connectivity.connection.snapshot.threshold=2"
]
}
}
}
Expand Down
Expand Up @@ -54,6 +54,8 @@
import com.typesafe.config.ConfigException;
import com.typesafe.config.ConfigFactory;
import com.typesafe.config.ConfigRenderOptions;
import com.typesafe.config.ConfigValue;
import com.typesafe.config.ConfigValueFactory;

import akka.Done;
import akka.actor.ActorRef;
Expand Down Expand Up @@ -148,10 +150,33 @@ protected DittoService(final Logger logger, final String serviceName, final Stri
protected Config determineRawConfig() {
final Config loadedConfig = RawConfigSupplier.of(serviceName).get();

logger.debug("Using config <{}>", loadedConfig.root().render(ConfigRenderOptions.concise()));
if (logger.isDebugEnabled()) {
logger.debug("Using config <{}>", loadedConfig.root().render(ConfigRenderOptions.concise()));
}
return loadedConfig;
}

private Config appendDittoInfo(final Config config) {
final String instanceId = InstanceIdentifierSupplier.getInstance().get();

final ConfigValue service = ConfigFactory.empty()
.withValue("name", ConfigValueFactory.fromAnyRef(serviceName))
.withValue("instance-id", ConfigValueFactory.fromAnyRef(instanceId))
.root();

final ConfigValue vmArgs =
ConfigValueFactory.fromIterable(ManagementFactory.getRuntimeMXBean().getInputArguments());

final ConfigValue env = ConfigValueFactory.fromMap(System.getenv());

return config.withValue("ditto.info",
ConfigFactory.empty()
.withValue("service", service)
.withValue("vm-args", vmArgs)
.withValue("env", env)
.root());
}

private static ScopedConfig tryToGetDittoConfigOrEmpty(final Config rawConfig) {
try {
return getDittoConfigOrEmpty(rawConfig);
Expand Down Expand Up @@ -191,11 +216,12 @@ public ActorSystem start() {
* May be overridden to <em>completely</em> change the way how this service is started.
* <em>Note: If this method is overridden, no other method of this class will be called automatically.</em>
* </p>
*
* @return the created ActorSystem during startup
*/
protected ActorSystem doStart() {
logRuntimeParameters();
final Config actorSystemConfig = appendAkkaPersistenceMongoUriToRawConfig();
final Config actorSystemConfig = appendDittoInfo(appendAkkaPersistenceMongoUriToRawConfig());
configureMongoDbSuffixBuilder();
startKamon();
final ActorSystem actorSystem = createActorSystem(actorSystemConfig);
Expand All @@ -211,7 +237,7 @@ private Config appendAkkaPersistenceMongoUriToRawConfig() {
final String configPath = "akka.contrib.persistence.mongodb.mongo.mongouri";
final MongoDbConfig mongoDbConfig = ((WithMongoDbConfig) serviceSpecificConfig).getMongoDbConfig();
final String mongoDbUri = mongoDbConfig.getMongoDbUri();
return ConfigFactory.parseMap(Collections.singletonMap(configPath, mongoDbUri)).withFallback(rawConfig);
return rawConfig.withValue(configPath, ConfigValueFactory.fromAnyRef(mongoDbUri));
}

private boolean isServiceWithMongoDbConfig() {
Expand Down
@@ -1,5 +1,4 @@
// Common configurations of Ditto services
include "ditto-service-info.conf"
include "ditto-akka-config.conf"
include "ditto-cluster.conf"
include "ditto-devops.conf"
Expand Down

This file was deleted.

0 comments on commit 8f877b6

Please sign in to comment.