Allow programmatic module sharding configuration
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / config / HybridModuleShardConfigProvider.java
1 /*
2  * Copyright (c) 2019 PANTHEON.tech, s.r.o. 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 static java.util.Objects.requireNonNull;
11
12 import com.typesafe.config.Config;
13 import java.util.Map;
14
15 public class HybridModuleShardConfigProvider extends AbstractModuleShardConfigProvider {
16     private final Config moduleShardsConfig;
17     private final String modulesConfigPath;
18
19     public HybridModuleShardConfigProvider(final Config moduleShardsConfig, final String modulesConfigPath) {
20         this.moduleShardsConfig = requireNonNull(moduleShardsConfig, "ModuleShardsConfig can't be null");
21         this.modulesConfigPath = modulesConfigPath;
22     }
23
24     @Override
25     public Map<String, ModuleConfig.Builder> retrieveModuleConfigs(final Configuration configuration) {
26         Config modulesConfig = loadConfigFromPath(modulesConfigPath);
27
28         final Map<String, ModuleConfig.Builder> moduleConfigMap = readModuleShardsConfig(this.moduleShardsConfig);
29         readModulesConfig(modulesConfig, moduleConfigMap, configuration);
30         return moduleConfigMap;
31     }
32 }