Added oparent to sdc main
[sdc.git] / asdctool / src / main / java / org / openecomp / sdc / asdctool / simulator / tenant / ImportCassandraTableTool.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.sdc.asdctool.simulator.tenant;
22
23 import org.openecomp.sdc.be.config.ConfigurationManager;
24 import org.openecomp.sdc.common.api.ConfigurationSource;
25 import org.openecomp.sdc.common.impl.ExternalConfiguration;
26 import org.openecomp.sdc.common.impl.FSConfigurationSource;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29
30 import java.util.HashMap;
31 import java.util.Map;
32 import java.util.function.Consumer;
33
34 /**
35  * Main class of utility imports CSV file into the specified table
36  * The old stuff of the table is removed.
37  * 
38  * Accepts 3 mandatory arguments:
39  *                      1. Path to configuration folder
40  *                      2. Name of the table
41  *                      3. Path to the CSV file
42  *   
43  *  Example of usage:
44  *              \src\main\resources\config\ operationalenvironment "C:\Users\dr2032\Documents\env.csv"
45  *  
46  *  See relevant import handler for example of csv file line. 
47  *  
48  *  The list of supported tables:
49  *              1. operationalenvironment
50  *  
51  *  
52  * @author dr2032
53  *
54  */
55 public class ImportCassandraTableTool {
56         private static final Logger LOGGER = LoggerFactory.getLogger(ImportCassandraTableTool.class);
57         
58         private static Map<String, Consumer<String>> mapHandlers = new HashMap<>();
59         
60         static {
61                 mapHandlers.put(OperationalEvnironmentImportHandler.getTableName().toLowerCase(), OperationalEvnironmentImportHandler::execute);
62         }
63         
64         public static void main(String[] args) {
65                 if(args.length == 3) {
66                         String appConfigDir = args[0];
67                         String tableName = args[1];
68                         String fileName = args[2];
69                         
70                         ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), appConfigDir);
71                         new ConfigurationManager(configurationSource);
72                 
73                         Consumer<String> executor = mapHandlers.get(tableName.toLowerCase());
74                         if (executor != null) {
75                                 executor.accept(fileName);
76                         } 
77                         else {
78                                 LOGGER.warn("Import to table [{}] is not supported yet!", tableName);
79                         }
80                 }
81                 else {
82                         LOGGER.warn("Invalid number of arguments. The 1st shoduld be path to config dir, the 2nd - table name and the 3rd - path to CSV file.");
83                 }
84                 
85                 
86                 System.exit(0);
87         }
88         
89 }