Commit 5a759320 authored by zskycode's avatar zskycode

<dev> 修改配置文件加载

parent d81193c5
Pipeline #51371 passed with stages
in 2 minutes and 43 seconds
......@@ -55,24 +55,26 @@ public class HdfsLogDesensitization implements Serializable {
desensitizationHdfsLog(this.jobConfig);
}
public JobConf config(String jobName, String path) {
JobConf conf = new JobConf(HdfsLogDesensitization.class);
conf.setJobName(jobName);
conf.addResource("classpath:" + path + "/core-site.xml");
  • 🚫 Define a constant instead of duplicating this literal "classpath:" 4 times. 📘

Please register or sign in to reply
conf.addResource("classpath:" + path + "/hdfs-site.xml");
/// conf.addResource("classpath:" + path + "/mapred-site.xml");
  • This block of commented-out lines of code should be removed. 📘

Please register or sign in to reply
log.info("配置文件加载:"+"classpath:" + path + "/core-site.xml");
log.info("配置文件加载:"+"classpath:" + path + "/hdfs-site.xml");
return conf;
}
public void desensitizationHdfsLog(JobConfig jobConfig) {
// 初始化flink job env
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
JobConf jobConfInput = new JobConf();
if (!StringUtils.isEmpty(jobConfig.getHdfsSourcePath())) {
jobConfInput.addResource(new Path("file://" + jobConfig.getHdfsSourcePath() + "/core-site.xml"));
jobConfInput.addResource(new Path("file://" + jobConfig.getHdfsSourcePath() + "/hdfs-site.xml"));
/// jobConfInput.addResource(new Path("file://" + jobConfig.getHdfsSourcePath() + "/mapred-site.xml"));
}
JobConf jobConfOutput = new JobConf();
if (!StringUtils.isEmpty(jobConfig.getHdfsSinkPath())) {
jobConfOutput.addResource(new Path("file://" + jobConfig.getHdfsSinkPath() + "/core-site.xml"));
jobConfOutput.addResource(new Path("file://" + jobConfig.getHdfsSinkPath() + "/hdfs-site.xml"));
/// jobConfInput.addResource(new Path("file://" + jobConfig.getHdfsSinkPath() + "/mapred-site.xml"));
jobConfInput = config("jobConfInput", jobConfig.getHdfsSourcePath());
}
jobConfInput.set(AVRO_OUTPUT_SCHEMA, jobConfig.getAvroOutputSchema());
jobConfOutput.set(AVRO_OUTPUT_SCHEMA, jobConfig.getAvroOutputSchema());
// source部分
// 1、通过时间获取文件夹信息
List<String> logFiles = filterHdfsLogFiles(jobConfig.getHdfsSrc(), jobConfig.getHdfsUri(), jobConfig.getHdfsUser());
......@@ -88,6 +90,12 @@ public class HdfsLogDesensitization implements Serializable {
hdfsLogInput.flatMap(new DesensitizationFunction<Tuple2<Object, Object>, LogData>(jobConfig));
// sink部分
// 获取目标hdfs的输出目录
JobConf jobConfOutput = new JobConf();
if (!StringUtils.isEmpty(jobConfig.getHdfsSinkPath())) {
jobConfOutput = config("jobConfOutput", jobConfig.getHdfsSinkPath());
}
jobConfOutput.set(AVRO_OUTPUT_SCHEMA, jobConfig.getAvroOutputSchema());
String filePath = jobConfig.getHdfsDest();
HadoopOutputFormat hadoopOutputFormat = new HadoopOutputFormat<>(new AvroOutputFormat(), jobConfOutput);
FileOutputFormat.setOutputPath(jobConfOutput, new Path(filePath));
......
  • SonarQube analysis reported 205 issues

    • 7 blocker
    • 🚫 38 critical
    • 137 major
    • 🔽 20 minor
    • 3 info

    Watch the comments in this conversation to review them.

    Top 30 extra issues

    Note: The following issues were found on lines that were not modified in the commit. Because these issues can't be reported as line comments, they are summarized here:

    1. Remove this hard-coded password. 📘
    2. Remove this hard-coded password. 📘
    3. Remove this hard-coded password. 📘
    4. Remove this hard-coded password. 📘
    5. Remove this hard-coded password. 📘
    6. Remove this hard-coded password. 📘
    7. Remove this hard-coded password. 📘
    8. 🚫 Define a constant instead of duplicating this literal " {\n" 11 times. 📘
    9. 🚫 [Define a constant instead of duplicating this literal " "type": \n" 11 times. 📘
    10. 🚫 Define a constant instead of duplicating this literal " "string",\n" 6 times. 📘
    11. 🚫 Define a constant instead of duplicating this literal " "null"\n" 6 times. 📘
    12. 🚫 [Define a constant instead of duplicating this literal " ]\n" 11 times.](https://git.zorkdata.com/liaomingtao/transaction-log-desensitization/blob/5a759320a85f2789774f87d56f5ce5e5fe8508d2/src/main/java/com/zorkdata/desensitization/avro/AvroSchemaDef.java#L23) 📘
    13. 🚫 Define a constant instead of duplicating this literal " },\n" 9 times. 📘
    14. 🚫 Define a constant instead of duplicating this literal " "null",\n" 5 times. 📘
    15. 🚫 Define a constant instead of duplicating this literal " {\n" 5 times. 📘
    16. 🚫 Define a constant instead of duplicating this literal " "type": "map",\n" 5 times. 📘
    17. 🚫 Define a constant instead of duplicating this literal " "values": "string"\n" 3 times. 📘
    18. 🚫 Define a constant instead of duplicating this literal " }\n" 5 times. 📘
    19. 🚫 Define a constant instead of duplicating this literal "序列化失败" 13 times. 📘
    20. 🚫 Refactor this method to reduce its Cognitive Complexity from 22 to the 15 allowed. 📘
    21. 🚫 Refactor this method to reduce its Cognitive Complexity from 161 to the 15 allowed. 📘
    22. 🚫 Refactor this method to reduce its Cognitive Complexity from 22 to the 15 allowed. 📘
    23. 🚫 Refactor this method to reduce its Cognitive Complexity from 22 to the 15 allowed. 📘
    24. 🚫 Refactor this method to reduce its Cognitive Complexity from 19 to the 15 allowed. 📘
    25. 🚫 Change this "try" to a try-with-resources. (sonar.java.source not set. Assuming 7 or greater.) 📘
    26. 🚫 Refactor this code to not throw exceptions in finally blocks. 📘
    27. 🚫 Refactor this code to not throw exceptions in finally blocks. 📘
    28. 🚫 Change this "try" to a try-with-resources. (sonar.java.source not set. Assuming 7 or greater.) 📘
    29. 🚫 Define a constant instead of duplicating this literal "jobName" 8 times. 📘
    30. 🚫 Define a constant instead of duplicating this literal "2020-11-07 21:22:20" 8 times. 📘
    • ... 173 more
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment