|
10 | 10 |
|
11 | 11 | import java.io.File;
|
12 | 12 | import java.text.SimpleDateFormat;
|
13 |
| -import java.util.ArrayList; |
14 |
| -import java.util.Arrays; |
15 |
| -import java.util.Date; |
16 |
| -import java.util.List; |
| 13 | +import java.util.*; |
17 | 14 |
|
18 | 15 | import static com.wugui.datatx.core.util.Constants.SPLIT_COMMA;
|
19 | 16 | import static com.wugui.datax.executor.service.jobhandler.DataXConstant.*;
|
@@ -53,54 +50,64 @@ public static String[] buildDataXExecutorCmd(TriggerParam tgParam, String tmpFil
|
53 | 50 | private static String buildDataXParam(TriggerParam tgParam) {
|
54 | 51 | StringBuilder doc = new StringBuilder();
|
55 | 52 | String jvmParam = StringUtils.isNotBlank(tgParam.getJvmParam()) ? tgParam.getJvmParam().trim() : tgParam.getJvmParam();
|
56 |
| - String partitionStr = tgParam.getPartitionInfo(); |
57 | 53 | if (StringUtils.isNotBlank(jvmParam)) {
|
58 | 54 | doc.append(JVM_CM).append(TRANSFORM_QUOTES).append(jvmParam).append(TRANSFORM_QUOTES);
|
59 | 55 | }
|
| 56 | + return doc.toString(); |
| 57 | + } |
60 | 58 |
|
| 59 | + public static HashMap<String, String> buildDataXParamToMap(TriggerParam tgParam) { |
| 60 | + String partitionStr = tgParam.getPartitionInfo(); |
61 | 61 | Integer incrementType = tgParam.getIncrementType();
|
62 | 62 | String replaceParam = StringUtils.isNotBlank(tgParam.getReplaceParam()) ? tgParam.getReplaceParam().trim() : null;
|
63 |
| - |
64 | 63 | if (incrementType != null && replaceParam != null) {
|
65 |
| - |
66 |
| - if (IncrementTypeEnum.TIME.getCode() == incrementType) { |
67 |
| - if (doc.length() > 0) doc.append(SPLIT_SPACE); |
| 64 | + if (IncrementTypeEnum.ID.getCode() == incrementType) { |
| 65 | + long startId = tgParam.getStartId(); |
| 66 | + long endId = tgParam.getEndId(); |
| 67 | + String formatParam = String.format(replaceParam, startId, endId); |
| 68 | + return getKeyValue(formatParam); |
| 69 | + } else if (IncrementTypeEnum.TIME.getCode() == incrementType) { |
68 | 70 | String replaceParamType = tgParam.getReplaceParamType();
|
69 |
| - |
70 |
| - if (StringUtils.isBlank(replaceParamType) || replaceParamType.equals("Timestamp")) { |
| 71 | + if (StringUtils.isBlank(replaceParamType) || "Timestamp".equals(replaceParamType)) { |
71 | 72 | long startTime = tgParam.getStartTime().getTime() / 1000;
|
72 | 73 | long endTime = tgParam.getTriggerTime().getTime() / 1000;
|
73 |
| - doc.append(PARAMS_CM).append(TRANSFORM_QUOTES).append(String.format(replaceParam, startTime, endTime)); |
| 74 | + String formatParam = String.format(replaceParam, startTime, endTime); |
| 75 | + return getKeyValue(formatParam); |
74 | 76 | } else {
|
75 | 77 | SimpleDateFormat sdf = new SimpleDateFormat(replaceParamType);
|
76 |
| - String endTime = sdf.format(tgParam.getTriggerTime()).replaceAll(SPLIT_SPACE, PERCENT); |
77 |
| - String startTime = sdf.format(tgParam.getStartTime()).replaceAll(SPLIT_SPACE, PERCENT); |
78 |
| - doc.append(PARAMS_CM).append(TRANSFORM_QUOTES).append(String.format(replaceParam, startTime, endTime)); |
79 |
| - } |
80 |
| - //buildPartitionCM(doc, partitionStr); |
81 |
| - doc.append(TRANSFORM_QUOTES); |
| 78 | + String endTime = sdf.format(tgParam.getTriggerTime()); |
| 79 | + String startTime = sdf.format(tgParam.getStartTime()); |
82 | 80 |
|
83 |
| - } else if (IncrementTypeEnum.ID.getCode() == incrementType) { |
84 |
| - long startId = tgParam.getStartId(); |
85 |
| - long endId = tgParam.getEndId(); |
86 |
| - if (doc.length() > 0) doc.append(SPLIT_SPACE); |
87 |
| - doc.append(PARAMS_CM).append(TRANSFORM_QUOTES).append(String.format(replaceParam, startId, endId)); |
88 |
| - doc.append(TRANSFORM_QUOTES); |
| 81 | + String formatParam = String.format(replaceParam, startTime, endTime); |
| 82 | + return getKeyValue(formatParam); |
| 83 | + } |
89 | 84 | }
|
90 | 85 | }
|
91 | 86 |
|
92 | 87 | if (incrementType != null && IncrementTypeEnum.PARTITION.getCode() == incrementType) {
|
93 | 88 | if (StringUtils.isNotBlank(partitionStr)) {
|
94 | 89 | List<String> partitionInfo = Arrays.asList(partitionStr.split(SPLIT_COMMA));
|
95 |
| - if (doc.length() > 0) doc.append(SPLIT_SPACE); |
96 |
| - doc.append(PARAMS_CM).append(TRANSFORM_QUOTES).append(String.format(PARAMS_CM_V_PT, buildPartition(partitionInfo))).append(TRANSFORM_QUOTES); |
| 90 | + String formatParam = String.format(PARAMS_CM_V_PT, buildPartition(partitionInfo)); |
| 91 | + return getKeyValue(formatParam); |
97 | 92 | }
|
98 |
| - } |
99 | 93 |
|
100 |
| - JobLogger.log("------------------Command parameters:" + doc); |
101 |
| - return doc.toString(); |
| 94 | + } |
| 95 | + return null; |
102 | 96 | }
|
103 | 97 |
|
| 98 | + private static HashMap<String, String> getKeyValue(String formatParam) { |
| 99 | + String[] paramArr = formatParam.split(PARAMS_SYSTEM); |
| 100 | + HashMap<String, String> map = new HashMap<String, String>(); |
| 101 | + |
| 102 | + for (String param : paramArr) { |
| 103 | + if (StringUtils.isNotBlank(param)) { |
| 104 | + param = param.trim(); |
| 105 | + String[] keyValue = param.split(PARAMS_EQUALS); |
| 106 | + map.put(keyValue[0], keyValue[1]); |
| 107 | + } |
| 108 | + } |
| 109 | + return map; |
| 110 | + } |
104 | 111 |
|
105 | 112 | private void buildPartitionCM(StringBuilder doc, String partitionStr) {
|
106 | 113 | if (StringUtils.isNotBlank(partitionStr)) {
|
|
0 commit comments