66a5e16d0374bcf946acee9485fec917dd20c257
[ccsdk/features.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : ccsdk features
4  * ================================================================================
5  * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property.
6  * All rights reserved.
7  * ================================================================================
8  * Update Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
9  * ================================================================================
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  *     http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  * ============LICENSE_END=========================================================
22  *
23  */
24 package org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data;
25
26 import java.io.File;
27 import java.io.IOException;
28 import java.nio.file.Files;
29 import java.util.ArrayList;
30 import java.util.List;
31 import java.util.Set;
32
33 import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.ReleaseInformation;
34
35
36 /**
37  * @author Michael Dürre
38  *
39  */
40 public class MavenDatabasePluginInitFile {
41     private static final int replicas = 1;
42     private static final int shards = 5;
43     private static final String mappings = "\"mappings\":%s";
44     private static final String settings =
45             "\"settings\":{\"index\":{\"number_of_shards\":%d,\"number_of_replicas\":%d},\"analysis\":{\"analyzer\":{\"content\":"
46                     + "{\"type\":\"custom\",\"tokenizer\":\"whitespace\"}}}}";
47
48     public static void create(Release release, String filename) throws IOException {
49
50         ReleaseInformation ri = ReleaseInformation.getInstance(release);
51         Set<ComponentName> comps = ri.getComponents();
52         List<String> lines = new ArrayList<>();
53         for (ComponentName c : comps) {
54             lines.add(String.format("PUT:%s/:{" + settings + "," + mappings + "}", ri.getIndex(c), shards, replicas,
55                     ri.getDatabaseMapping(c)));
56             lines.add(String.format("PUT:%s/_alias/%s/:{}", ri.getIndex(c), ri.getAlias(c)));
57         }
58
59         File filePath = new File(filename);
60         if (filePath.getParentFile() != null && !filePath.getParentFile().exists()) {
61             //Crate Directory if missing
62             filePath.getParentFile().mkdirs();
63         }
64         Files.write(filePath.toPath(), lines);
65     }
66 }