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="\"settings\":{\"index\":{\"number_of_shards\":%d,\"number_of_replicas\":%d},\"analysis\":{\"analyzer\":{\"content\":"+
45 "{\"type\":\"custom\",\"tokenizer\":\"whitespace\"}}}}";
47 public static void create(Release release, String filename) throws IOException {
49 ReleaseInformation ri = ReleaseInformation.getInstance(release);
50 Set<ComponentName> comps=ri.getComponents();
51 List<String> lines = new ArrayList<>();
52 for(ComponentName c:comps) {
53 lines.add(String.format("PUT:%s/:{"+settings+","+mappings+"}",ri.getIndex(c),shards,replicas,ri.getDatabaseMapping(c)));
54 lines.add(String.format("PUT:%s/_alias/%s/:{}", ri.getIndex(c),ri.getAlias(c)));
57 File filePath = new File(filename);
58 if (filePath.getParentFile() != null && !filePath.getParentFile().exists()){
59 //Crate Directory if missing
60 filePath.getParentFile().mkdirs();
62 Files.write(filePath.toPath(), lines);