Update command and dataprovider components
[ccsdk/features.git] / sdnr / wt / data-provider / setup / src / main / java / org / onap / ccsdk / features / sdnr / wt / dataprovider / setup / data / MavenDatabasePluginInitFile.java
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="\"settings\":{\"index\":{\"number_of_shards\":%d,\"number_of_replicas\":%d},\"analysis\":{\"analyzer\":{\"content\":"+
45     "{\"type\":\"custom\",\"tokenizer\":\"whitespace\"}}}}";
46
47         public static void create(Release release, String filename) throws IOException {
48
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)));
55                 }
56
57                 File filePath = new File(filename);
58                 if (filePath.getParentFile() != null && !filePath.getParentFile().exists()){
59                         //Crate Directory if missing
60                         filePath.getParentFile().mkdirs();
61                 }
62                 Files.write(filePath.toPath(), lines);
63         }
64 }