Skip to content

Commit 20d9f1b

Browse files
committed
[--sync not dropping table on right when left is missing. #189](#189)
[When doing a Schema Sync for 'VIEWS', there aren't being dropped. #190](#190) [SHADOW table schema for partitioned tables are creating ALTER TABLE ... PARTITION location details with LEFT locations. #191](#191) [Add ability to save a comment for a run and record it in the report. #192](#192) [Themeleaf syntax causing excessive logging. #193](#193) - Removed Spring Autowiring - Function Documentation
1 parent 30ae374 commit 20d9f1b

File tree

326 files changed

+4427
-4392
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

326 files changed

+4427
-4392
lines changed

.gitignore

-1.6 KB
Binary file not shown.

Writerside/topics/cli-options.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
| -c, --concurrency | <threads> | Set application concurrency, default is 10 |
1010
| -cfg, --config | <filename> | Config with details for the HMS-Mirror. Default: $HOME/.hms-mirror/cfg/default.yaml |
1111
| -cine, --create-if-not-exist | | CREATE table/partition statements will be adjusted to include 'IF NOT EXISTS'. This will ensure all remaining sql statements will be run. This can be used to sync partition definitions for existing tables. |
12+
| -com, --comment | <comment> | Comment to add to report output |
1213
| -cs, --common-storage | <storage-path> | Common Storage used with Data Strategy HYBRID, SQL, EXPORT_IMPORT. This will change the way these methods are implemented by using the specified storage location as an 'common' storage point between two clusters. In this case, the cluster do NOT need to be 'linked'. Each cluster DOES need to have access to the location and authorization to interact with the location. This may mean additional configuration requirements for 'hdfs' to ensure this seamless access. |
1314
| -cto, --compress-text-output | | Data movement (SQL/STORAGE_MIGRATION) of TEXT based file formats will be compressed in the new table. |
1415
| -d, --data-strategy | <strategy> | Specify how the data will follow the schema. [DUMP, SCHEMA_ONLY, LINKED, SQL, EXPORT_IMPORT, HYBRID, CONVERT_LINKED, STORAGE_MIGRATION, COMMON, ICEBERG_CONVERSION] |

Writerside/writerside.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
<ihp version="2.0">
55
<topics dir="topics" web-path="topics"/>
66
<images dir="images" web-path="images"/>
7-
<instance src="hms-mirror.tree" web-path="/hms-mirror" version="v2.3.1.x"/>
7+
<instance src="hms-mirror.tree" web-path="/hms-mirror" version="v3.x"/>
88
</ihp>

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<parent>
2323
<groupId>com.cloudera.utils</groupId>
2424
<artifactId>hadoop.parent</artifactId>
25-
<version>1.3.0.1</version>
25+
<version>1.4.0.0</version>
2626
<relativePath>../cloudera-utils</relativePath>
2727
</parent>
2828

src/main/java/com/cloudera/utils/hms/mirror/cli/CliReporter.java

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import lombok.Getter;
3131
import lombok.Setter;
3232
import lombok.extern.slf4j.Slf4j;
33-
import org.springframework.beans.factory.annotation.Autowired;
3433
import org.springframework.boot.CommandLineRunner;
3534
import org.springframework.context.annotation.Bean;
3635
import org.springframework.core.annotation.Order;
@@ -59,27 +58,24 @@ public class CliReporter {
5958
private final List<String> reportTemplateOutput = new ArrayList<>();
6059
private final Map<String, String> varMap = new TreeMap<>();
6160
private final List<TableMirror> startedTables = new ArrayList<>();
61+
private final ConfigService configService;
62+
private final ExecuteSessionService executeSessionService;
63+
6264
private Thread worker;
6365
private Boolean retry = Boolean.FALSE;
6466
private Boolean quiet = Boolean.FALSE;
65-
66-
private ConfigService configService;
67-
private ExecuteSessionService executeSessionService;
68-
6967
private boolean tiktok = false;
7068

71-
@Autowired
72-
public void setConfigService(ConfigService configService) {
69+
// Constructor injection for dependencies
70+
public CliReporter(ConfigService configService, ExecuteSessionService executeSessionService) {
7371
this.configService = configService;
72+
this.executeSessionService = executeSessionService;
7473
}
7574

76-
7775
@Bean
7876
@Order(20)
7977
CommandLineRunner configQuiet(HmsMirrorConfig hmsMirrorConfig) {
80-
return args -> {
81-
setQuiet(hmsMirrorConfig.isQuiet());
82-
};
78+
return args -> setQuiet(hmsMirrorConfig.isQuiet());
8379
}
8480

8581
protected void displayReport(Boolean showAll) {
@@ -303,13 +299,8 @@ public void run() {
303299
}
304300
}
305301

306-
@Autowired
307-
public void setExecuteSessionService(ExecuteSessionService executeSessionService) {
308-
this.executeSessionService = executeSessionService;
309-
}
310-
311302
public void setVariable(String key, String value) {
312303
varMap.put(key, value);
313304
}
314305

315-
}
306+
}

src/main/java/com/cloudera/utils/hms/mirror/cli/CliReporterConfig.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import lombok.Getter;
2121
import lombok.Setter;
2222
import lombok.extern.slf4j.Slf4j;
23-
import org.springframework.beans.factory.annotation.Autowired;
2423
import org.springframework.boot.CommandLineRunner;
2524
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
2625
import org.springframework.context.annotation.Bean;
@@ -32,9 +31,8 @@
3231
@Setter
3332
@Slf4j
3433
public class CliReporterConfig {
35-
private CliReporter cliReporter;
34+
private final CliReporter cliReporter;
3635

37-
@Autowired
3836
public CliReporterConfig(CliReporter cliReporter) {
3937
this.cliReporter = cliReporter;
4038
}
@@ -48,9 +46,7 @@ public CliReporterConfig(CliReporter cliReporter) {
4846
public CommandLineRunner launchCliReporting() {
4947
return args -> {
5048
log.info("Launching CLI Reporting");
51-
getCliReporter().run();
49+
cliReporter.run();
5250
};
5351
}
54-
55-
56-
}
52+
}

src/main/java/com/cloudera/utils/hms/mirror/cli/HmsMirrorCommandLineOptions.java

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import lombok.extern.slf4j.Slf4j;
2929
import org.apache.commons.cli.*;
3030
import org.apache.logging.log4j.util.Strings;
31-
import org.springframework.beans.factory.annotation.Autowired;
3231
import org.springframework.beans.factory.annotation.Value;
3332
import org.springframework.boot.CommandLineRunner;
3433
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
@@ -51,19 +50,25 @@
5150
public class HmsMirrorCommandLineOptions {
5251
public static String SPRING_CONFIG_PREFIX = "hms-mirror.config";
5352

54-
private ConfigService configService;
53+
private final ConfigService configService;
5554

56-
@Autowired
57-
public void setConfigService(ConfigService configService) {
55+
/**
56+
* Constructor injection for HmsMirrorCommandLineOptions.
57+
*
58+
* @param configService the injected config service
59+
* @param log injected logger
60+
*/
61+
public HmsMirrorCommandLineOptions(ConfigService configService) {
5862
this.configService = configService;
5963
}
6064

61-
public static void main(String[] args) {
62-
HmsMirrorCommandLineOptions pcli = new HmsMirrorCommandLineOptions();
63-
String[] convertedArgs = pcli.toSpringBootOption(Boolean.TRUE, args);
64-
String newCmdLn = String.join(" ", convertedArgs);
65-
System.out.println(newCmdLn);
66-
}
65+
66+
// public static void main(String[] args) {
67+
// HmsMirrorCommandLineOptions pcli = new HmsMirrorCommandLineOptions();
68+
// String[] convertedArgs = pcli.toSpringBootOption(Boolean.TRUE, args);
69+
// String newCmdLn = String.join(" ", convertedArgs);
70+
// System.out.println(newCmdLn);
71+
// }
6772

6873
@Bean
6974
@Order(1)
@@ -244,6 +249,18 @@ CommandLineRunner configCompressTextOutputFalse(HmsMirrorConfig hmsMirrorConfig)
244249
};
245250
}
246251

252+
@Bean
253+
@Order(1)
254+
@ConditionalOnProperty(
255+
name = "hms-mirror.config.comment"
256+
)
257+
CommandLineRunner configComment(HmsMirrorConfig hmsMirrorConfig, @Value("${hms-mirror.config.comment}") String value){
258+
return args -> {
259+
log.info("comment: {}", value);
260+
hmsMirrorConfig.setComment(value);
261+
};
262+
}
263+
247264
@Bean
248265
@Order(1)
249266
@ConditionalOnProperty(
@@ -1506,7 +1523,7 @@ CommandLineRunner configWarehousePlans(HmsMirrorConfig config, @Value("${hms-mir
15061523
}
15071524

15081525

1509-
public CommandLine getCommandLine(String[] args) {
1526+
public static CommandLine getCommandLine(String[] args) {
15101527
Options options = getOptions();
15111528

15121529
CommandLineParser parser = new PosixParser();
@@ -1534,7 +1551,7 @@ public CommandLine getCommandLine(String[] args) {
15341551
return cmd;
15351552
}
15361553

1537-
private Options getOptions() {
1554+
private static Options getOptions() {
15381555
// create Options object
15391556
Options options = new Options();
15401557

@@ -1544,6 +1561,11 @@ private Options getOptions() {
15441561
quietOutput.setRequired(Boolean.FALSE);
15451562
options.addOption(quietOutput);
15461563

1564+
Option commentOption = new Option("com", "comment", true, "Comment to add to report output");
1565+
commentOption.setRequired(Boolean.FALSE);
1566+
commentOption.setType(String.class);
1567+
options.addOption(commentOption);
1568+
15471569
Option concurrencyOption = new Option("c", "concurrency", true,
15481570
"Set application concurrency, default is 10");
15491571
concurrencyOption.setOptionalArg(Boolean.TRUE);
@@ -2142,7 +2164,7 @@ CommandLineRunner initializeConnectionsAfterConfigSetup(ConnectionPoolService co
21422164
};
21432165
}
21442166

2145-
public String[] toSpringBootOption(Boolean withoutWeb, String[] args) {
2167+
public static String[] toSpringBootOption(Boolean withoutWeb, String[] args) {
21462168
CommandLine cmd = getCommandLine(args);
21472169
List<String> springOptions = new ArrayList<>();
21482170
// Turn off web ui

src/main/java/com/cloudera/utils/hms/mirror/cli/HmsMirrorCommandLineOptionsEnum.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public enum HmsMirrorCommandLineOptionsEnum {
2626
AUTO_TUNE("at", "auto-tune", null, ""),
2727
BETA("b", "beta", null, ""),
2828
CFG("cfg", "config", "filename", ""),
29+
COMMENT("com", "comment", null, "Comments to add to report output."),
2930
CONCURRENCY("c", "concurrency", "threads", ""),
3031
CONSOLIDATE_TABLES_FOR_DISTCP("ctfd", "consolidate-tables-for-distcp", null, ""),
3132
CREATE_IF_NOT_EXIST("cine", "create-if-not-exist", null, ""),

src/main/java/com/cloudera/utils/hms/mirror/cli/Mirror.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ public static void main(String[] args) {
4747
// Translate the legacy command line arguments to Spring Boot arguments
4848
// before starting the application.
4949
log.info("Translating command line arguments to Spring Boot arguments");
50-
HmsMirrorCommandLineOptions hmsMirrorCommandLineOptions = new HmsMirrorCommandLineOptions();
51-
String[] springArgs = hmsMirrorCommandLineOptions.toSpringBootOption(Boolean.TRUE, args);
50+
// HmsMirrorCommandLineOptions hmsMirrorCommandLineOptions = new HmsMirrorCommandLineOptions();
51+
String[] springArgs = HmsMirrorCommandLineOptions.toSpringBootOption(Boolean.TRUE, args);
5252
log.info("Translated Spring Boot arguments: {}", String.join(" ", springArgs));
5353
log.info("STARTING THE APPLICATION");
5454

src/main/java/com/cloudera/utils/hms/mirror/cli/config/CliInit.java

Lines changed: 35 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@
3232
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
3333
import lombok.extern.slf4j.Slf4j;
3434
import org.apache.commons.io.IOUtils;
35-
import org.springframework.beans.factory.annotation.Autowired;
35+
import org.slf4j.Logger;
3636
import org.springframework.beans.factory.annotation.Value;
3737
import org.springframework.boot.CommandLineRunner;
3838
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
3939
import org.springframework.context.annotation.Bean;
40-
import org.springframework.context.annotation.Configuration;
4140
import org.springframework.core.annotation.Order;
41+
import org.springframework.stereotype.Component;
4242

4343
import java.io.File;
4444
import java.io.IOException;
@@ -53,37 +53,45 @@
5353
import static java.util.Objects.isNull;
5454
import static java.util.Objects.nonNull;
5555

56-
@Configuration
56+
@Component
5757
@Slf4j
5858
public class CliInit {
5959

60-
private ConfigService configService;
61-
private DomainService domainService;
62-
private ExecuteSessionService executeSessionService;
63-
private ObjectMapper yamlMapper;
60+
private final DomainService domainService;
61+
private final ExecuteSessionService executeSessionService;
62+
private final ObjectMapper yamlMapper;
6463

65-
@Autowired
66-
public void setConfigService(ConfigService configService) {
67-
this.configService = configService;
68-
}
69-
70-
@Autowired
71-
public void setDomainService(DomainService domainService) {
64+
/**
65+
* Initializes the CliInit class with required services and utilities.
66+
*
67+
* @param domainService the service responsible for managing domain-specific logic.
68+
* @param executeSessionService the service responsible for managing execution sessions.
69+
* @param yamlMapper the object mapper for parsing and generating YAML files.
70+
*/
71+
public CliInit(
72+
DomainService domainService,
73+
ExecuteSessionService executeSessionService,
74+
ObjectMapper yamlMapper
75+
) {
7276
this.domainService = domainService;
73-
}
74-
75-
@Autowired
76-
public void setExecuteSessionService(ExecuteSessionService executeSessionService) {
7777
this.executeSessionService = executeSessionService;
78-
}
79-
80-
@Autowired
81-
public void setYamlMapper(ObjectMapper yamlMapper) {
8278
this.yamlMapper = yamlMapper;
8379
}
8480

81+
/**
82+
* Initializes the HmsMirrorConfig object by loading the configuration information
83+
* from the specified YAML file. This method attempts to locate the configuration file
84+
* first from the filesystem and then from the classpath, providing compatibility for
85+
* various runtime environments.
86+
*
87+
* @param configFilename the name of the configuration file to load; it can be a file path
88+
* or a resource name on the classpath.
89+
* @return the initialized HmsMirrorConfig object created from the provided configuration file.
90+
* @throws RuntimeException if the configuration file cannot be found or if an I/O error
91+
* occurs while reading or parsing the file.
92+
*/
8593
private HmsMirrorConfig initializeConfig(String configFilename) {
86-
HmsMirrorConfig hmsMirrorConfig;
94+
HmsMirrorConfig config;
8795
log.info("Initializing Config.");
8896
ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
8997
mapper.enable(SerializationFeature.INDENT_OUTPUT);
@@ -111,14 +119,14 @@ private HmsMirrorConfig initializeConfig(String configFilename) {
111119
}
112120

113121
String yamlCfgFile = IOUtils.toString(cfgUrl, StandardCharsets.UTF_8);
114-
hmsMirrorConfig = mapper.readerFor(HmsMirrorConfig.class).readValue(yamlCfgFile);
115-
hmsMirrorConfig.setConfigFilename(configFilename);
122+
config = mapper.readerFor(HmsMirrorConfig.class).readValue(yamlCfgFile);
123+
config.setConfigFilename(configFilename);
116124
} catch (IOException e) {
117125
log.error("IO Exception", e);
118126
throw new RuntimeException(e);
119127
}
120128
log.info("Config loaded.");
121-
return hmsMirrorConfig;
129+
return config;
122130
}
123131

124132
@Bean
@@ -157,9 +165,6 @@ public HmsMirrorConfig loadHmsMirrorConfigWithSetup() {
157165
return new HmsMirrorConfig();
158166
}
159167

160-
/*
161-
162-
*/
163168
@Bean
164169
@Order(5)
165170
@ConditionalOnProperty(
@@ -403,15 +408,6 @@ CommandLineRunner configOutputDirInternal(HmsMirrorConfig hmsMirrorConfig, boole
403408
// Identify it as being set by the user.
404409
hmsMirrorConfig.setUserSetOutputDirectory(userSetOutputDir);
405410
executeSessionService.setReportOutputDirectory(value, false);
406-
// File reportPathDir = new File(value);
407-
// if (!reportPathDir.exists()) {
408-
// reportPathDir.mkdirs();
409-
// }
410-
// reporter.setReportOutputFile(value + FileSystems.getDefault().getSeparator() + "<db>_hms-mirror.md|html|yaml");
411-
// reporter.setLeftExecuteFile(value + FileSystems.getDefault().getSeparator() + "<db>_LEFT_execute.sql");
412-
// reporter.setLeftCleanUpFile(value + FileSystems.getDefault().getSeparator() + "<db>_LEFT_CleanUp_execute.sql");
413-
// reporter.setRightExecuteFile(value + FileSystems.getDefault().getSeparator() + "<db>_RIGHT_execute.sql");
414-
// reporter.setRightCleanUpFile(value + FileSystems.getDefault().getSeparator() + "<db>_RIGHT_CleanUp_execute.sql");
415411

416412
File testFile = new File(value + FileSystems.getDefault().getSeparator() + ".dir-check");
417413

@@ -422,14 +418,6 @@ CommandLineRunner configOutputDirInternal(HmsMirrorConfig hmsMirrorConfig, boole
422418
retryPath.mkdirs();
423419
}
424420

425-
// Test file to ensure we can write to it for the report.
426-
// try {
427-
// new FileOutputStream(testFile).close();
428-
// } catch (IOException e) {
429-
// throw new RuntimeException("Can't write to output directory: " + value, e);
430-
// }
431-
432421
};
433422
}
434-
435-
}
423+
}

0 commit comments

Comments
 (0)