4c3f2156ef1ae05117618d61043110f5ef9cd8bc
[ccsdk/apps.git] / sdnr / wireless-transport / code-Carbon-SR1 / apps / devicemanager / impl / src / main / java / org / opendaylight / mwtn / index / impl / IndexConfigService.java
1 package org.opendaylight.mwtn.index.impl;
2
3 import org.opendaylight.mwtn.base.database.HtDatabaseClientAbstract;
4 import org.opendaylight.mwtn.base.database.HtDatabaseNode;
5 import org.opendaylight.mwtn.base.database.IndexClientBuilder;
6 import org.slf4j.Logger;
7 import org.slf4j.LoggerFactory;
8
9 /**
10  * Setup index mwtn in the database
11  * @author herbert
12  *
13  */
14 public class IndexConfigService implements AutoCloseable {
15
16     private static final Logger LOG = LoggerFactory.getLogger(IndexConfigService.class);
17
18     /** Index name to be used */
19     private static final String INDEX = "config";
20     /** Location of configuration data **/
21     private static final String MODELDATA = "/elasticsearch/index/config";
22
23     private HtDatabaseClientAbstract client;
24
25     // --- Construct and initialize
26
27     public IndexConfigService(HtDatabaseNode database) {
28         LOG.info("Create {} start", this.getClass().getSimpleName());
29
30         IndexClientBuilder clientBuilder = IndexClientBuilder.getBuilder(INDEX).setModelDataDirectory(MODELDATA);
31         client = clientBuilder.create(database);
32         LOG.info("Create {} finished. DB Service {} started.", this.getClass().getSimpleName(),  client != null ? "sucessfully" : "not" );
33     }
34
35         @Override
36         public void close() throws Exception {
37                 client.close();
38         }
39
40 }