2 * ============LICENSE_START=======================================================
3 * ONAP : ccsdk features
4 * ================================================================================
5 * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property.
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
14 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
24 package org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data;
27 import java.io.IOException;
28 import java.nio.file.Files;
29 import java.util.ArrayList;
30 import java.util.List;
33 import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.ReleaseInformation;
37 * @author Michael Dürre
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\"}}}}";
48 public static void create(Release release, String filename) throws IOException {
50 ReleaseInformation ri = ReleaseInformation.getInstance(release);
51 Set<ComponentName> comps = ri.getComponents();
52 List<String> lines = new ArrayList<>();
53 lines.add("PUT:_cluster/settings/:{\"persistent\":{\"action.auto_create_index\":\"true\"}}");
54 for (ComponentName c : comps) {
55 lines.add(String.format("PUT:%s/:{" + settings + "," + mappings + "}", ri.getIndex(c), shards, replicas,
56 ri.getDatabaseMapping(c)));
57 lines.add(String.format("PUT:%s/_alias/%s/:{}", ri.getIndex(c), ri.getAlias(c)));
60 File filePath = new File(filename);
61 if (filePath.getParentFile() != null && !filePath.getParentFile().exists()) {
62 //Crate Directory if missing
63 filePath.getParentFile().mkdirs();
65 Files.write(filePath.toPath(), lines);