Allow programmatic module sharding configuration
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / config / FileModuleShardConfigProvider.java
1 /*
2  * Copyright (c) 2015 Brocade Communications Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.cluster.datastore.config;
9
10 import com.typesafe.config.Config;
11 import java.util.Map;
12
13 /**
14  * Implementation of ModuleShardConfigProvider that reads the module and shard configuration from files.
15  *
16  * @author Thomas Pantelis
17  */
18 public class FileModuleShardConfigProvider extends AbstractModuleShardConfigProvider {
19     private final String moduleShardsConfigPath;
20     private final String modulesConfigPath;
21
22     public FileModuleShardConfigProvider(final String moduleShardsConfigPath, final String modulesConfigPath) {
23         this.moduleShardsConfigPath = moduleShardsConfigPath;
24         this.modulesConfigPath = modulesConfigPath;
25     }
26
27     @Override
28     public Map<String, ModuleConfig.Builder> retrieveModuleConfigs(final Configuration configuration) {
29         Config moduleShardsConfig = loadConfigFromPath(moduleShardsConfigPath);
30         Config modulesConfig = loadConfigFromPath(modulesConfigPath);
31
32         final Map<String, ModuleConfig.Builder> moduleConfigMap = readModuleShardsConfig(moduleShardsConfig);
33         readModulesConfig(modulesConfig, moduleConfigMap, configuration);
34         return moduleConfigMap;
35     }
36 }