feat(cli): 增加多jdk的支持

This commit is contained in:
v-zhangjc9
2025-05-20 14:42:51 +08:00
parent 5d49c82190
commit 778a6df984
13 changed files with 137 additions and 76 deletions

View File

@@ -138,7 +138,8 @@ public class RunnerApplication implements ApplicationRunner {
Path planPath = Paths.get(root.toString(), "deploy.plan");
Map<String, List<String>> deployPlans = new HashMap<>();
if (Files.exists(planPath) && !deployInformationProperties.getShuffler()) {
deployPlans = mapper.readValue(new String(Files.readAllBytes(planPath)), new TypeReference<Map<String, List<String>>>() {});
deployPlans = mapper.readValue(new String(Files.readAllBytes(planPath)), new TypeReference<Map<String, List<String>>>() {
});
}
for (ServiceInfoWrapper serviceInfo : serviceInfoList) {
@@ -168,8 +169,8 @@ public class RunnerApplication implements ApplicationRunner {
MapUtil.builder()
.put("currentPath", absolutRootPath)
.put("hosts", hostInfoList
.collect(HostInfoWrapper::getHostnameIp)
.toSortedList((o1, o2) -> Comparator.<String>naturalOrder().compare(o1.getIp(), o2.getIp())))
.collect(HostInfoWrapper::getHostnameIp)
.toSortedList((o1, o2) -> Comparator.<String>naturalOrder().compare(o1.getIp(), o2.getIp())))
.put("selectedHosts", selectedHosts)
.put("runtime", runtimeInfo)
.put("info", serviceInfo)
@@ -187,8 +188,8 @@ public class RunnerApplication implements ApplicationRunner {
MapUtil.builder()
.put("currentPath", absolutRootPath)
.put("hosts", hostInfoList
.collect(HostInfoWrapper::getHostnameIp)
.toSortedList((o1, o2) -> Comparator.<String>naturalOrder().compare(o1.getIp(), o2.getIp())))
.collect(HostInfoWrapper::getHostnameIp)
.toSortedList((o1, o2) -> Comparator.<String>naturalOrder().compare(o1.getIp(), o2.getIp())))
.put("runtime", runtimeInfo)
.put("info", serviceInfo)
.put("arguments", serviceInfo.getArguments())
@@ -199,13 +200,13 @@ public class RunnerApplication implements ApplicationRunner {
StrUtil.format("stop-{}.sh", serviceInfo.getName())
)
);
generateTemplate(
generateTemplate(
"cloud/log.ftl",
MapUtil.builder()
.put("currentPath", absolutRootPath)
.put("hosts", hostInfoList
.collect(HostInfoWrapper::getHostnameIp)
.toSortedList((o1, o2) -> Comparator.<String>naturalOrder().compare(o1.getIp(), o2.getIp())))
.collect(HostInfoWrapper::getHostnameIp)
.toSortedList((o1, o2) -> Comparator.<String>naturalOrder().compare(o1.getIp(), o2.getIp())))
.put("selectedHosts", selectedHosts)
.put("runtime", runtimeInfo)
.put("info", serviceInfo)
@@ -219,24 +220,15 @@ public class RunnerApplication implements ApplicationRunner {
);
}
generateTemplate(
"cloud/stop-script.ftl",
MapUtil.builder()
.put("currentPath", absolutRootPath)
.put("runtime", runtimeInfo)
.build(),
Paths.get(root.toString(), "stop.sh")
);
generateTemplate(
"cloud/ssh-script.ftl",
MapUtil.builder()
.put("currentPath", absolutRootPath)
.put("hosts", hostInfoList
.collect(HostInfoWrapper::getHostnameIp)
.toSortedList((o1, o2) -> Comparator.<String>naturalOrder().compare(o1.getIp(), o2.getIp())))
.put("runtime", runtimeInfo)
.build(),
.put("currentPath", absolutRootPath)
.put("hosts", hostInfoList
.collect(HostInfoWrapper::getHostnameIp)
.toSortedList((o1, o2) -> Comparator.<String>naturalOrder().compare(o1.getIp(), o2.getIp())))
.put("runtime", runtimeInfo)
.build(),
Paths.get(root.toString(), "ssh.sh")
);
@@ -338,14 +330,14 @@ public class RunnerApplication implements ApplicationRunner {
Paths.get(root.toString(), "update.sh")
);
Template stopTemplate = engine.getTemplate("cloud/stop-script.ftl");
String stopScript = stopTemplate.render(MapUtil.builder()
.put("currentPath", absolutRootPath)
.put("runtime", runtimeInfo)
.build());
// 一个魔法操作
stopScript = stopScript.replaceAll("application_name=\".*\"", "application_name=\"service-uploader.jar\"");
Files.write(Paths.get(root.toString(), "stop.sh"), stopScript.getBytes());
generateTemplate(
"uploader/stop.ftl",
MapUtil.builder()
.put("currentPath", absolutRootPath)
.put("runtime", runtimeInfo)
.build(),
Paths.get(root.toString(), "stop.sh")
);
}
private void generateUpdateJar(Path root) throws IOException {

View File

@@ -49,6 +49,10 @@ public class ServiceInfoWrapper {
return serviceInfo.getSourceJar();
}
public String getJdk() {
return serviceInfo.getJdk();
}
public List<String> getClasspath() {
return serviceInfo.getClasspath();
}

View File

@@ -7,7 +7,11 @@ deploy:
# 应用jar包
jar-path: /data/datalake/jars
# 主机jdk根目录
jdk-path: /opt/jdk8u252-b09
default-jdk: jdk8_arm
jdk-path:
"jdk8": /opt/jdk1.8.0_162
"jdk8_arm": /opt/jdk8u252-b09
"jdk17": /opt/jdk-17.0.15
# 应用日志
log-path: /data/datalake/logs
# 应用配置

View File

@@ -38,8 +38,6 @@ deploy:
"[connector.hadoop.kerberos-keytab-path]": ${deploy.runtime.kerberos-keytab-path}
"[connector.hudi.app-hdfs-path]": ${deploy.runtime.hudi.app-hdfs-path}
"[connector.hudi.app-test-hdfs-path]": ${deploy.runtime.hudi.app-test-hdfs-path}
"[connector.hudi.victoria-push-url]": ${deploy.runtime.hudi.victoria-push-url}
"[connector.hudi.loki-push-url]": ${deploy.runtime.hudi.loki-push-url}
arguments:
"[spring.application.name]": service-launcher-b1
"[connector.cluster.cluster]": b1
@@ -59,8 +57,6 @@ deploy:
"[connector.hadoop.kerberos-keytab-path]": ${deploy.runtime.kerberos-keytab-path}
"[connector.hudi.app-hdfs-path]": ${deploy.runtime.hudi.app-hdfs-path}
"[connector.hudi.app-test-hdfs-path]": ${deploy.runtime.hudi.app-test-hdfs-path}
"[connector.hudi.victoria-push-url]": ${deploy.runtime.hudi.victoria-push-url}
"[connector.hudi.loki-push-url]": ${deploy.runtime.hudi.loki-push-url}
arguments:
"[spring.application.name]": service-launcher-a4
"[connector.cluster.cluster]": a4
@@ -80,8 +76,6 @@ deploy:
"[connector.hadoop.kerberos-keytab-path]": ${deploy.runtime.kerberos-keytab-path}
"[connector.hudi.app-hdfs-path]": ${deploy.runtime.hudi.app-hdfs-path}
"[connector.hudi.app-test-hdfs-path]": ${deploy.runtime.hudi.app-test-hdfs-path}
"[connector.hudi.victoria-push-url]": ${deploy.runtime.hudi.victoria-push-url}
"[connector.hudi.loki-push-url]": ${deploy.runtime.hudi.loki-push-url}
arguments:
"[spring.application.name]": service-launcher-b12
"[connector.cluster.cluster]": b12
@@ -147,7 +141,6 @@ deploy:
"[connector.hadoop.kerberos-principal]": ${deploy.runtime.user}/$\{hostname}.hdp.dc@ECLD.COM
"[connector.hadoop.kerberos-keytab-path]": ${deploy.runtime.kerberos-keytab-path}
arguments:
"[executor.loki-push-url]": ${deploy.runtime.loki.hudi-push-url}
"[executor.task-jar-path]": ${deploy.runtime.executor.task-jar-path}
"[executor.task-result-path]": ${deploy.runtime.executor.task-result-path}
service-web:
@@ -168,3 +161,10 @@ deploy:
- "service"
source-jar: service-monitor-1.0.0-SNAPSHOT.jar
replicas: 1
service-ai-chat:
order: 6
groups:
- "ai"
source-jar: service-ai-chat-1.0.0-SNAPSHOT.jar
jdk: "jdk17"
replicas: 1

View File

@@ -1,4 +1,4 @@
#!/bin/bash
mkdir -p ${runtime.jarPath}
curl ${runtime.downloadUrl}/service-check-1.0.0-SNAPSHOT.jar -o ${runtime.jarPath}/service-check.jar
${runtime.jdkPath}/bin/java -jar ${runtime.jarPath}/service-check.jar
${runtime.jdkPath['jdk8']}/bin/java -jar ${runtime.jarPath}/service-check.jar

View File

@@ -13,7 +13,7 @@ hostname_full=`ssh $host 'hostname -f'`
<#-- 获取当前时间 -->
start_time=`date +%Y%m%d%H%M%S`
ssh $host "mkdir -p ${runtime.jarPath};curl ${runtime.downloadUrl}/${info.sourceJar} -o ${runtime.jarPath}/${info.name}.jar"
ssh $host "export JASYPT_ENCRYPTOR_PASSWORD='r#(R,P\"Dp^A47>WSn:Wn].gs/+\"v:q_Q*An~zF*g-@j@jtSTv5H/,S-3:R?r9R}.';nohup ${runtime.jdkPath}/bin/java <#list environments?keys as key>-D${key}=${environments[key]?string} </#list>-jar ${runtime.jarPath}/${info.name}.jar <#noparse>--deploy.datetime=${datetime} --deploy.ip=${host} --deploy.hostname=${hostname} --deploy.hostname-full=${hostname_full} --deploy.start-time=${start_time}</#noparse> --hudi-service.signature=${runtime.signature} --logging.parent=${runtime.logPath} --loki.url=${runtime.loki.servicePushUrl} --spring.cloud.zookeeper.connect-string=${runtime.zkUrl} --spring.security.meta.authority='${runtime.security.authority}' --spring.security.meta.username='${runtime.security.username}' --spring.security.meta.darkcode='${runtime.security.darkcode}' --yarn-cluster.sync-clusters=${runtime.yarn.syncClusters} --yarn-cluster.compaction-clusters=${runtime.yarn.compactionClusters} <#list arguments?keys as key>--${key}='${arguments[key]?string}' </#list>> /dev/null 2>&1 &"
ssh $host "export JASYPT_ENCRYPTOR_PASSWORD='r#(R,P\"Dp^A47>WSn:Wn].gs/+\"v:q_Q*An~zF*g-@j@jtSTv5H/,S-3:R?r9R}.';nohup ${runtime.jdkPath[info.jdk!(runtime.defaultJdk)]}/bin/java <#list environments?keys as key>-D${key}=${environments[key]?string} </#list>-jar ${runtime.jarPath}/${info.name}.jar <#noparse>--deploy.datetime=${datetime} --deploy.ip=${host} --deploy.hostname=${hostname} --deploy.hostname-full=${hostname_full} --deploy.start-time=${start_time}</#noparse> --hudi-service.signature=${runtime.signature} --logging.parent=${runtime.logPath} --spring.cloud.zookeeper.connect-string=${runtime.zkUrl} --spring.security.meta.authority='${runtime.security.authority}' --spring.security.meta.username='${runtime.security.username}' --spring.security.meta.darkcode='${runtime.security.darkcode}' --yarn-cluster.sync-clusters=${runtime.yarn.syncClusters} --yarn-cluster.compaction-clusters=${runtime.yarn.compactionClusters} <#list arguments?keys as key>--${key}='${arguments[key]?string}' </#list>> /dev/null 2>&1 &"
</#if>
echo ''
</#list>

View File

@@ -1,7 +1,46 @@
#!/bin/bash
<#list hosts as host>
host=${host.ip}
echo "${info.name} ${host.ip} ${host.hostname} $datetime"
ssh $host 'bash -s' < ${currentPath}/stop.sh ${runtime.jarPath}/${info.name}.jar
ssh ${host.ip} bash -s <<'EOF'
original_command="$0"
application_name="${runtime.jarPath}/${info.name}.jar"
function get_pid() {
ID=$(ps ef | grep "$application_name" | grep -v grep | grep -v $original_command | awk '{ print $2 }')
if [[ -z "$ID" ]]; then
ID=$(ps aux | grep "$application_name" | grep -v grep | grep -v $original_command | awk '{print $2}')
if [[ -z "$ID" ]]; then
ID=$(${runtime.jdkPath[info.jdk!(runtime.defaultJdk)]}/bin/jps -lmvV | grep "$application_name" | awk '{print $1}')
fi
fi
echo $ID
}
pid=$(get_pid)
if [[ -z "$pid" ]]; then
echo "Application is already stopped."
exit 0
fi
echo "Stopping $pid..."
kill $pid
LOOPS=0
while (true); do
cpid=$(get_pid)
if [[ -z "$cpid" ]]; then
echo "Oook! cost:$LOOPS"
break
fi
LOOPS=$(($LOOPS+1))
if [[ $(($LOOPS%15)) -eq 0 ]]; then
echo "Wait timeout, try to force kill $pid..."
kill -9 $pid
fi
sleep 1s
done
EOF
</#list>

View File

@@ -1,4 +1,4 @@
#!/bin/bash
mkdir -p ${runtime.jarPath}
export JASYPT_ENCRYPTOR_PASSWORD='r#(R,P\"Dp^A47>WSn:Wn].gs/+\"v:q_Q*An~zF*g-@j@jtSTv5H/,S-3:R?r9R}.'
${runtime.jdkPath}/bin/java <#noparse>-Ddeploy.datetime=$(date +%Y%m%d%H%M%S) -Ddeploy.hostname=$(hostname) -Ddeploy.hostname-full=$(hostname -f) -Ddeploy.start-time=$(date +%Y%m%d%H%M%S)</#noparse> -Dlogging.parent=${runtime.logPath} -Dloki.url=${runtime.loki.servicePushUrl} -Dspring.cloud.zookeeper.connect-string=${runtime.zkUrl} -Dyarn-cluster.sync-clusters=${runtime.yarn.syncClusters} -Dyarn-cluster.compaction-clusters=${runtime.yarn.compactionClusters} -jar ${runtime.jarPath}/service-command-pro.jar<#if directly> $@</#if>
${runtime.jdkPath['jdk8']}/bin/java <#noparse>-Ddeploy.datetime=$(date +%Y%m%d%H%M%S) -Ddeploy.hostname=$(hostname) -Ddeploy.hostname-full=$(hostname -f) -Ddeploy.start-time=$(date +%Y%m%d%H%M%S)</#noparse> -Dlogging.parent=${runtime.logPath} -Dloki.url=${runtime.loki.servicePushUrl} -Dspring.cloud.zookeeper.connect-string=${runtime.zkUrl} -Dyarn-cluster.sync-clusters=${runtime.yarn.syncClusters} -Dyarn-cluster.compaction-clusters=${runtime.yarn.compactionClusters} -jar ${runtime.jarPath}/service-command-pro.jar<#if directly> $@</#if>

View File

@@ -1,4 +1,4 @@
#!/bin/bash
mkdir -p ${runtime.jarPath}
export JASYPT_ENCRYPTOR_PASSWORD='r#(R,P\"Dp^A47>WSn:Wn].gs/+\"v:q_Q*An~zF*g-@j@jtSTv5H/,S-3:R?r9R}.'
${runtime.jdkPath}/bin/java <#noparse>-Ddeploy.datetime=$(date +%Y%m%d%H%M%S) -Ddeploy.hostname=$(hostname) -Ddeploy.hostname-full=$(hostname -f) -Ddeploy.start-time=$(date +%Y%m%d%H%M%S)</#noparse> -Dlogging.parent=${runtime.logPath} -Dloki.url=${runtime.loki.servicePushUrl} -Dspring.cloud.zookeeper.connect-string=${runtime.zkUrl} -Dyarn-cluster.sync-clusters=${runtime.yarn.syncClusters} -Dyarn-cluster.compaction-clusters=${runtime.yarn.compactionClusters} -jar ${runtime.jarPath}/service-command.jar<#if directly> $@</#if>
${runtime.jdkPath['jdk8']}/bin/java <#noparse>-Ddeploy.datetime=$(date +%Y%m%d%H%M%S) -Ddeploy.hostname=$(hostname) -Ddeploy.hostname-full=$(hostname -f) -Ddeploy.start-time=$(date +%Y%m%d%H%M%S)</#noparse> -Dlogging.parent=${runtime.logPath} -Dloki.url=${runtime.loki.servicePushUrl} -Dspring.cloud.zookeeper.connect-string=${runtime.zkUrl} -Dyarn-cluster.sync-clusters=${runtime.yarn.syncClusters} -Dyarn-cluster.compaction-clusters=${runtime.yarn.compactionClusters} -jar ${runtime.jarPath}/service-command.jar<#if directly> $@</#if>

View File

@@ -1,4 +1,4 @@
#!/bin/bash
mkdir -p ${runtime.jarPath}
export JASYPT_ENCRYPTOR_PASSWORD='r#(R,P"Dp^A47>WSn:Wn].gs/+"v:q_Q*An~zF*g-@j@jtSTv5H/,S-3:R?r9R}.'
nohup ${runtime.jdkPath}/bin/java -jar ${runtime.jarPath}/service-uploader.jar <#noparse>--deploy.datetime=$(date +%Y%m%d%H%M%S) --deploy.hostname=$(hostname) --deploy.hostname-full=$(hostname -f) --deploy.start-time=$(date +%Y%m%d%H%M%S)</#noparse> --logging.parent=${runtime.logPath} --loki.url=${runtime.loki.servicePushUrl} --spring.cloud.zookeeper.connect-string=${runtime.zkUrl} --uploader.backend=local --uploader.tmp-dir=${runtime.dataPath}/uploader --spring.security.meta.authority='${runtime.security.authority}' --spring.security.meta.username='${runtime.security.username}' --spring.security.meta.darkcode='${runtime.security.darkcode}' > /dev/null 2>&1 &
nohup ${runtime.jdkPath['jdk8']}/bin/java -jar ${runtime.jarPath}/service-uploader.jar <#noparse>--deploy.datetime=$(date +%Y%m%d%H%M%S) --deploy.hostname=$(hostname) --deploy.hostname-full=$(hostname -f) --deploy.start-time=$(date +%Y%m%d%H%M%S)</#noparse> --logging.parent=${runtime.logPath} --loki.url=${runtime.loki.servicePushUrl} --spring.cloud.zookeeper.connect-string=${runtime.zkUrl} --uploader.backend=local --uploader.tmp-dir=${runtime.dataPath}/uploader --spring.security.meta.authority='${runtime.security.authority}' --spring.security.meta.username='${runtime.security.username}' --spring.security.meta.darkcode='${runtime.security.darkcode}' > /dev/null 2>&1 &

View File

@@ -1,14 +1,14 @@
#!/bin/bash
original_command="$0"
application_name="$1"
application_name="service-uploader.jar"
function get_pid() {
ID=$(ps ef | grep "$application_name" | grep -v grep | grep -v $original_command | awk '{ print $2 }')
if [[ -z "$ID" ]]; then
ID=$(ps aux | grep "$application_name" | grep -v grep | grep -v $original_command | awk '{print $2}')
if [[ -z "$ID" ]]; then
ID=$(${runtime.jdkPath}/bin/jps -lmvV | grep "$application_name" | awk '{print $1}')
ID=$(${runtime.jdkPath['jdk8']}/bin/jps -lmvV | grep "$application_name" | awk '{print $1}')
fi
fi
echo $ID