Convert FileModuleShardConfigProvider to OSGi DS
[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 import org.osgi.service.component.annotations.Activate;
13 import org.osgi.service.component.annotations.Component;
14 import org.osgi.service.component.annotations.Deactivate;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
17
18 /**
19  * Implementation of ModuleShardConfigProvider that reads the module and shard configuration from files.
20  *
21  * @author Thomas Pantelis
22  */
23 @Component(immediate = true, service = ModuleShardConfigProvider.class)
24 public class FileModuleShardConfigProvider extends AbstractModuleShardConfigProvider {
25     private static final Logger LOG = LoggerFactory.getLogger(FileModuleShardConfigProvider.class);
26
27     private final String moduleShardsConfigPath;
28     private final String modulesConfigPath;
29
30     public FileModuleShardConfigProvider() {
31         this("./configuration/initial/module-shards.conf", "./configuration/initial/modules.conf");
32     }
33
34     public FileModuleShardConfigProvider(final String moduleShardsConfigPath, final String modulesConfigPath) {
35         this.moduleShardsConfigPath = moduleShardsConfigPath;
36         this.modulesConfigPath = modulesConfigPath;
37     }
38
39     @Override
40     public Map<String, ModuleConfig.Builder> retrieveModuleConfigs(final Configuration configuration) {
41         Config moduleShardsConfig = loadConfigFromPath(moduleShardsConfigPath);
42         Config modulesConfig = loadConfigFromPath(modulesConfigPath);
43
44         final Map<String, ModuleConfig.Builder> moduleConfigMap = readModuleShardsConfig(moduleShardsConfig);
45         readModulesConfig(modulesConfig, moduleConfigMap, configuration);
46         return moduleConfigMap;
47     }
48
49     @Activate
50     void activate() {
51         LOG.info("Shard configuration provider started");
52     }
53
54     @Deactivate
55     void deactivate() {
56         LOG.info("Shard configuration provider stopped");
57     }
58 }