25e18eb233487065841a7f56747b735a981d3070
[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 IndexConfigService implements AutoCloseable {
32
33     private static final Logger LOG = LoggerFactory.getLogger(IndexConfigService.class);
34
35     /** Index name to be used */
36     private static final String INDEX = "config";
37     /** Location of configuration data **/
38     private static final String MODELDATA = "/elasticsearch/index/config";
39
40     private final HtDatabaseClientAbstract client;
41
42     // --- Construct and initialize
43
44     public IndexConfigService(HtDatabaseNode database) throws Exception {
45         LOG.info("Create {} start", this.getClass().getSimpleName());
46
47         IndexClientBuilder clientBuilder = IndexClientBuilder.getBuilder(INDEX).setModelDataDirectory(MODELDATA);
48         client = clientBuilder.create(database);
49         clientBuilder.close();
50         LOG.info("Create {} finished. DB Service sucessfully started.", this.getClass().getSimpleName());
51     }
52
53     @Override
54     public void close() throws Exception {
55         client.close();
56     }
57
58 }