8900fec469ee5a761979ae33c952c15bba7ccc25
[ccsdk/apps.git] / sdnr / wireless-transport / code-Carbon-SR1 / apps / devicemanager / impl / src / main / java / org / opendaylight / mwtn / index / impl / IndexMwtnService.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 IndexMwtnService implements AutoCloseable {
15
16     private static final Logger LOG = LoggerFactory.getLogger(IndexMwtnService.class);
17
18     /** Index name to be used */
19     private static final String INDEX = "mwtn";
20     /** Location of mapping data **/
21     private static final String MAPPING = "/elasticsearch/index/mwtn/mwtnMapping.json";
22     /** Location of configuration data **/
23     private static final String MODELDATA = "/elasticsearch/index/mwtn/modelDescription";
24
25     private HtDatabaseClientAbstract client;
26
27     // --- Construct and initialize
28
29     public IndexMwtnService(HtDatabaseNode database) {
30         LOG.info("Create {} start", this.getClass().getSimpleName());
31
32         IndexClientBuilder clientBuilder = IndexClientBuilder.getBuilder(INDEX)
33                         .setMappingSettingJsonFileName(MAPPING)
34                         .setModelDataDirectory(MODELDATA);
35         client = clientBuilder.create(database);
36         LOG.info("Create {} finished. DB Service {} started.", this.getClass().getSimpleName(),  client != null ? "sucessfully" : "not" );
37     }
38
39         @Override
40         public void close() throws Exception {
41                 client.close();
42         }
43 }