4a9ac98811d1f14a09d72559f7d7c6e15b296111
[ccsdk/features.git] /
1 /*******************************************************************************
2  * ============LICENSE_START========================================================================
3  * ONAP : ccsdk feature sdnr wt
4  * =================================================================================================
5  * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6  * =================================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8  * in compliance with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software distributed under the License
13  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14  * or implied. See the License for the specific language governing permissions and limitations under
15  * the License.
16  * ============LICENSE_END==========================================================================
17  ******************************************************************************/
18 package org.onap.ccsdk.features.sdnr.wt.devicemanager.index.impl;
19
20 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.database.HtDatabaseClientAbstract;
21 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.database.HtDatabaseNode;
22 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.database.IndexClientBuilder;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25
26 /**
27  * Setup index mwtn in the database
28  * @author herbert
29  *
30  */
31 public class IndexMwtnService implements AutoCloseable {
32
33     private static final Logger LOG = LoggerFactory.getLogger(IndexMwtnService.class);
34
35     /** Index name to be used */
36     public static final String INDEX = "mwtn";
37     /** Location of mapping data **/
38     private static final String MAPPING = "/elasticsearch/index/mwtn/mwtnMapping.json";
39     /** Location of configuration data **/
40     private static final String MODELDATA = "/elasticsearch/index/mwtn/modelDescription";
41
42     private final HtDatabaseClientAbstract client;
43
44     // --- Construct and initialize
45
46     public IndexMwtnService(HtDatabaseNode database) throws Exception {
47         LOG.info("Create {} start", this.getClass().getSimpleName());
48
49         IndexClientBuilder clientBuilder = IndexClientBuilder.getBuilder(INDEX)
50                 .setMappingSettingJsonFileName(MAPPING)
51                 .setModelDataDirectory(MODELDATA);
52         client = clientBuilder.create(database);
53         clientBuilder.close();
54         LOG.info("Create {} finished. DB Service sucessfully started.", this.getClass().getSimpleName());
55     }
56
57     /**
58      * Get client to be used in other services
59      * @return client
60      */
61     public HtDatabaseClientAbstract getClient() {
62         return client;
63     }
64
65
66
67     @Override
68     public void close() throws Exception {
69         client.close();
70     }
71 }