Skip to content

Commit b5d8136

Browse files
authored
Merge pull request #43 from aliyun/feature/release-v1.1.7-4-tookits-structure
add client-toolkits module, re-align client project modules structure
2 parents 2b10776 + 2bad3b1 commit b5d8136

File tree

940 files changed

+10227
-740
lines changed

Some content is hidden

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

940 files changed

+10227
-740
lines changed

client/client-common/pom.xml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<parent>
5+
<groupId>com.aliyun.dataworks</groupId>
6+
<artifactId>client</artifactId>
7+
<version>1.1.7-4</version>
8+
<relativePath>../pom.xml</relativePath>
9+
</parent>
10+
11+
<artifactId>client-common</artifactId>
12+
<packaging>jar</packaging>
13+
14+
<name>client-common</name>
15+
16+
<properties>
17+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
18+
</properties>
19+
20+
<dependencies>
21+
<dependency>
22+
<groupId>ch.qos.logback</groupId>
23+
<artifactId>logback-classic</artifactId>
24+
</dependency>
25+
<dependency>
26+
<groupId>org.slf4j</groupId>
27+
<artifactId>slf4j-api</artifactId>
28+
</dependency>
29+
<dependency>
30+
<groupId>com.google.guava</groupId>
31+
<artifactId>guava</artifactId>
32+
</dependency>
33+
<dependency>
34+
<groupId>org.apache.commons</groupId>
35+
<artifactId>commons-collections4</artifactId>
36+
</dependency>
37+
<dependency>
38+
<groupId>commons-io</groupId>
39+
<artifactId>commons-io</artifactId>
40+
</dependency>
41+
<dependency>
42+
<groupId>org.apache.commons</groupId>
43+
<artifactId>commons-lang3</artifactId>
44+
</dependency>
45+
<dependency>
46+
<groupId>commons-cli</groupId>
47+
<artifactId>commons-cli</artifactId>
48+
</dependency>
49+
<dependency>
50+
<groupId>com.alibaba.fastjson2</groupId>
51+
<artifactId>fastjson2</artifactId>
52+
</dependency>
53+
<dependency>
54+
<groupId>org.projectlombok</groupId>
55+
<artifactId>lombok</artifactId>
56+
</dependency>
57+
<dependency>
58+
<groupId>junit</groupId>
59+
<artifactId>junit</artifactId>
60+
<version>3.8.1</version>
61+
<scope>test</scope>
62+
</dependency>
63+
</dependencies>
64+
65+
<build>
66+
<plugins>
67+
<plugin>
68+
<groupId>org.apache.maven.plugins</groupId>
69+
<artifactId>maven-source-plugin</artifactId>
70+
<version>3.0.1</version>
71+
<executions>
72+
<execution>
73+
<id>attach-sources</id>
74+
<goals>
75+
<goal>jar</goal>
76+
</goals>
77+
</execution>
78+
</executions>
79+
</plugin>
80+
</plugins>
81+
</build>
82+
</project>

client/src/main/bin/common.py renamed to client/client-common/src/main/bin/common.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os
2-
import sys
32
import re
43
import subprocess
4+
import sys
55

66

77
def get_cur_path():
@@ -61,14 +61,15 @@ def run_command(app_type, main_class=None):
6161
"java", "-cp", get_classpath(app_type),
6262
"-DcurrentDir=" + os.path.abspath(os.path.join(get_cur_path(), "..")),
6363
"-DappType=" + app_type,
64-
"com.aliyun.migrationx.common.command.appbase.CommandAppEntrance" if not main_class else main_class
64+
"com.aliyun.dataworks.client.command.CommandAppEntrance" if not main_class else main_class
6565
]
6666

67-
verbose = True if 'MIGRATIONX_VERBOSE' not in os.environ else bool(os.environ['MIGRATIONX_VERBOSE'])
67+
verbose = True if 'CLIENT_VERBOSE' not in os.environ else bool(os.environ['CLIENT_VERBOSE'])
6868
if verbose:
6969
logging_file = os.path.abspath(os.path.join(get_log_path(), app_type + ".log"))
7070
logback_xml = os.path.abspath(os.path.join(get_conf_path(), "logback.xml"))
7171
print("Logging file refer to: " + logging_file)
72+
print("Logback file refer to: " + logback_xml)
7273
cmd.insert(3, "-Dlogging.file=" + logging_file)
7374
cmd.insert(4, "-Dlogging.appenderRef=CONSOLE")
7475
cmd.insert(5, "-Dlogback.configurationFile=" + logback_xml)
File renamed without changes.
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,17 @@
1313
* limitations under the License.
1414
*/
1515

16-
package com.aliyun.migrationx.common.command.appbase;
16+
package com.aliyun.dataworks.client.command;
17+
18+
import com.alibaba.fastjson2.JSONObject;
1719

18-
import com.google.gson.JsonObject;
1920
import lombok.Data;
2021
import lombok.ToString;
2122
import lombok.experimental.Accessors;
2223

2324
/**
2425
* App Meta Info
26+
*
2527
* @author 聿剑
2628
* @date 2023/03/08
2729
*/
@@ -32,5 +34,5 @@ public class AppMeta {
3234
private String name;
3335
private AppType type;
3436
private String appClass;
35-
private JsonObject config;
37+
private JSONObject config;
3638
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313
* limitations under the License.
1414
*/
1515

16-
package com.aliyun.migrationx.common.command.appbase;
16+
package com.aliyun.dataworks.client.command;
1717

1818
/**
19-
*
2019
* @author 聿剑
2120
* @date 2023/9/14
2221
*/
2322
public enum AppType {
2423
reader,
2524
transformer,
26-
writer
25+
writer,
26+
spec
2727
}
Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@
1313
* limitations under the License.
1414
*/
1515

16-
package com.aliyun.migrationx.common.command.appbase;
16+
package com.aliyun.dataworks.client.command;
1717

1818
import java.util.Arrays;
1919
import java.util.Locale;
2020
import java.util.Optional;
2121

22+
import lombok.Setter;
2223
import lombok.extern.slf4j.Slf4j;
2324
import org.apache.commons.cli.CommandLine;
2425
import org.apache.commons.cli.CommandLineParser;
@@ -32,26 +33,28 @@
3233
* @author 聿剑
3334
* @date 2022/10/20
3435
*/
36+
@Setter
3537
@Slf4j
3638
public abstract class CommandApp {
39+
/**
40+
* -- SETTER --
41+
* set app meta
42+
*/
3743
protected AppMeta appMeta;
3844

3945
/**
4046
* run app
4147
*
4248
* @param args String[]
4349
*/
44-
public abstract void run(String[] args) throws Exception;
45-
46-
/**
47-
* set app meta
48-
*
49-
* @param appMeta AppMeta
50-
*/
51-
public void setAppMeta(AppMeta appMeta) {
52-
this.appMeta = appMeta;
50+
public void run(String[] args) throws Exception {
51+
Options options = getOptions();
52+
CommandLine cli = getCommandLine(options, args);
53+
doCommandRun(options, cli, args);
5354
}
5455

56+
protected void doCommandRun(Options options, CommandLine cli, String[] args) {}
57+
5558
protected CommandLine getCommandLine(Options options, String[] args) throws Exception {
5659
HelpFormatter helpFormatter = new HelpFormatter();
5760
try {
Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@
1313
* limitations under the License.
1414
*/
1515

16-
package com.aliyun.migrationx.common.command.appbase;
16+
package com.aliyun.dataworks.client.command;
1717

1818
import java.io.File;
1919
import java.io.IOException;
2020
import java.nio.charset.StandardCharsets;
2121
import java.util.Map;
22+
import java.util.Objects;
23+
import java.util.stream.Stream;
2224

23-
import com.aliyun.migrationx.common.exception.BizException;
24-
import com.aliyun.migrationx.common.exception.ErrorCode;
25-
import com.aliyun.migrationx.common.utils.GsonUtils;
25+
import com.alibaba.fastjson2.JSON;
2626

2727
import com.google.common.base.Joiner;
28-
import com.google.gson.reflect.TypeToken;
28+
import com.google.common.reflect.TypeToken;
2929
import lombok.extern.slf4j.Slf4j;
3030
import org.apache.commons.cli.CommandLine;
3131
import org.apache.commons.cli.CommandLineParser;
@@ -46,7 +46,7 @@ public static void main(String[] args) throws IOException {
4646
String currentDir = System.getProperty("currentDir");
4747
AppType appType = AppType.valueOf(System.getProperty("appType"));
4848

49-
Map<AppType, Map<String, AppMeta>> apps = loadApps(Joiner.on(File.separator).join(currentDir, "conf"));
49+
Map<AppType, Map<String, AppMeta>> apps = loadApps(Joiner.on(File.separator).join(currentDir, "conf"), appType);
5050

5151
Options options = new Options();
5252
options.addRequiredOption("a", "app", true, "app name");
@@ -58,7 +58,7 @@ public static void main(String[] args) throws IOException {
5858
String appName = commandLine.getOptionValue("a");
5959

6060
if (!apps.get(appType).containsKey(appName)) {
61-
throw new BizException(ErrorCode.UNKNOWN_COMMAND_APP).with(appName);
61+
throw new RuntimeException("unknown app: " + appName);
6262
}
6363

6464
CommandApp app = CommandAppFactory.create(appType, appName);
@@ -68,7 +68,7 @@ public static void main(String[] args) throws IOException {
6868
log.info("app command success");
6969
} catch (ParseException e) {
7070
log.error("app command parse error: {}", e.getMessage());
71-
String footer = Joiner.on(" ").join("\nAvailable apps: \n", GsonUtils.toJsonString(CommandAppFactory.getApps()));
71+
String footer = Joiner.on(" ").join("\nAvailable apps: \n", JSON.toJSONString(CommandAppFactory.getApps()));
7272
helpFormatter.printHelp("Options", "migrationx", options, footer);
7373
} catch (Exception e) {
7474
log.error("app command failed: ", e);
@@ -77,28 +77,32 @@ public static void main(String[] args) throws IOException {
7777
}
7878

7979
@SuppressWarnings("unchecked")
80-
private static Map<AppType, Map<String, AppMeta>> loadApps(String conf) throws IOException {
80+
private static Map<AppType, Map<String, AppMeta>> loadApps(String conf, AppType... appTypes) throws IOException {
8181
File config = new File(conf);
8282
File appsJson = config;
8383
if (config.isDirectory()) {
8484
appsJson = new File(config, "apps.json");
8585
}
8686

8787
String json = FileUtils.readFileToString(appsJson, StandardCharsets.UTF_8);
88-
Map<AppType, Map<String, AppMeta>> apps = GsonUtils.fromJsonString(json, new TypeToken<Map<AppType, Map<String, AppMeta>>>() {}.getType());
88+
Map<AppType, Map<String, AppMeta>> apps = JSON.parseObject(json, new TypeToken<Map<AppType, Map<String, AppMeta>>>() {}.getType());
8989
MapUtils.emptyIfNull(apps).forEach((appType, map) -> MapUtils.emptyIfNull(map).forEach((appName, appMeta) -> {
90+
if (appTypes != null && Stream.of(appTypes).noneMatch(t -> Objects.equals(t, appType))) {
91+
log.info("skip load app type: {}, appType needs load: {}", appType, appTypes);
92+
return;
93+
}
94+
9095
try {
9196
appMeta.setName(appName);
9297
appMeta.setType(appType);
9398
log.info("register command app type: {}, name: {}, class: {}", appType, appName, appMeta.getAppClass());
94-
CommandAppFactory.register(appType, appName, (Class<? extends CommandApp>) Class.forName(appMeta.getAppClass()));
99+
CommandAppFactory.register(appType, appName, (Class<? extends CommandApp>)Class.forName(appMeta.getAppClass()));
95100
} catch (ClassNotFoundException e) {
96-
log.info("register command app failed, appType: {}, appName: {}, class: {}, error: {}",
97-
appType, appName, appMeta.getAppClass(), e);
101+
log.info("register command app failed, appType: {}, appName: {}, class: {}, error: ", appType, appName, appMeta.getAppClass(), e);
98102
}
99103
}));
100104

101-
log.info("apps map: {}", GsonUtils.toJsonString(apps));
105+
log.info("apps map: {}", JSON.toJSONString(apps));
102106
return apps;
103107
}
104108
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,12 @@
1313
* limitations under the License.
1414
*/
1515

16-
package com.aliyun.migrationx.common.command.appbase;
16+
package com.aliyun.dataworks.client.command;
1717

1818
import java.util.ArrayList;
1919
import java.util.HashMap;
2020
import java.util.List;
2121
import java.util.Map;
22-
import java.util.function.Function;
2322
import java.util.stream.Collectors;
2423

2524
import lombok.extern.slf4j.Slf4j;

client/client-toolkits/package.xml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<!--
2+
~ Copyright (c) 2024, Alibaba Cloud;
3+
~ Licensed under the Apache License, Version 2.0 (the "License");
4+
~ you may not use this file except in compliance with the License.
5+
~ You may obtain a copy of the License at
6+
~
7+
~ http://www.apache.org/licenses/LICENSE-2.0
8+
~
9+
~ Unless required by applicable law or agreed to in writing, software
10+
~ distributed under the License is distributed on an "AS IS" BASIS,
11+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
~ See the License for the specific language governing permissions and
13+
~ limitations under the License.
14+
-->
15+
16+
<assembly
17+
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
18+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19+
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
20+
<formats>
21+
<format>tar.gz</format>
22+
</formats>
23+
<id>all</id>
24+
<includeBaseDirectory>true</includeBaseDirectory>
25+
<fileSets>
26+
<!-- script bin conf -->
27+
<fileSet>
28+
<directory>${project.basedir}/../client-common/src/main/bin</directory>
29+
<includes>
30+
<include>**/*</include>
31+
</includes>
32+
<outputDirectory>bin</outputDirectory>
33+
<fileMode>755</fileMode>
34+
</fileSet>
35+
<fileSet>
36+
<directory>${project.basedir}/../client-common/src/main/conf</directory>
37+
<includes>
38+
<include>**/*</include>
39+
</includes>
40+
<outputDirectory>conf</outputDirectory>
41+
</fileSet>
42+
43+
<fileSet>
44+
<directory>${project.basedir}/src/main/bin</directory>
45+
<includes>
46+
<include>**/*</include>
47+
</includes>
48+
<outputDirectory>bin</outputDirectory>
49+
<fileMode>755</fileMode>
50+
</fileSet>
51+
<fileSet>
52+
<directory>${project.basedir}/src/main/conf</directory>
53+
<includes>
54+
<include>**/*</include>
55+
</includes>
56+
<outputDirectory>conf</outputDirectory>
57+
</fileSet>
58+
59+
<fileSet>
60+
<directory>${project.basedir}/target/lib/common</directory>
61+
<includes>
62+
<include>*.jar</include>
63+
</includes>
64+
<outputDirectory>lib/common</outputDirectory>
65+
</fileSet>
66+
67+
<fileSet>
68+
<directory>${project.basedir}/target</directory>
69+
<includes>
70+
<include>*jar</include>
71+
</includes>
72+
<outputDirectory>lib/common</outputDirectory>
73+
</fileSet>
74+
75+
</fileSets>
76+
</assembly>

0 commit comments

Comments
 (0)