blob: 045ac5cafd59f420599eccf88719c6081c592357 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
package org.openecomp.sdc.asdctool.simulator.tenant;
import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.common.api.ConfigurationSource;
import org.openecomp.sdc.common.impl.ExternalConfiguration;
import org.openecomp.sdc.common.impl.FSConfigurationSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Consumer;
/**
* Main class of utility imports CSV file into the specified table
* The old stuff of the table is removed.
*
* Accepts 3 mandatory arguments:
* 1. Path to configuration folder
* 2. Name of the table
* 3. Path to the CSV file
*
* Example of usage:
* \src\main\resources\config\ operationalenvironment "C:\Users\dr2032\Documents\env.csv"
*
* See relevant import handler for example of csv file line.
*
* The list of supported tables:
* 1. operationalenvironment
*
*
* @author dr2032
*
*/
public class ImportCassandraTableTool {
private static final Logger LOGGER = LoggerFactory.getLogger(ImportCassandraTableTool.class);
private static Map<String, Consumer<String>> mapHandlers = new HashMap<>();
static {
mapHandlers.put(OperationalEvnironmentImportHandler.getTableName().toLowerCase(), OperationalEvnironmentImportHandler::execute);
}
public static void main(String[] args) {
if(args.length == 3) {
String appConfigDir = args[0];
String tableName = args[1];
String fileName = args[2];
ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), appConfigDir);
new ConfigurationManager(configurationSource);
Consumer<String> executor = mapHandlers.get(tableName.toLowerCase());
if (executor != null) {
executor.accept(fileName);
}
else {
LOGGER.warn("Import to table [{}] is not supported yet!", tableName);
}
}
else {
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.");
}
System.exit(0);
}
}
|