refactor(executor-manager): 使用sync同款jar更新方式
This commit is contained in:
@@ -78,6 +78,7 @@ public class DeployInformationProperties {
|
||||
private Boolean cloud = true;
|
||||
private Boolean command = true;
|
||||
private Boolean uploader = true;
|
||||
private Boolean updateJar = true;
|
||||
|
||||
public Boolean getCloud() {
|
||||
return cloud;
|
||||
@@ -103,12 +104,21 @@ public class DeployInformationProperties {
|
||||
this.uploader = uploader;
|
||||
}
|
||||
|
||||
public Boolean getUpdateJar() {
|
||||
return updateJar;
|
||||
}
|
||||
|
||||
public void setUpdateJar(Boolean updateJar) {
|
||||
this.updateJar = updateJar;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Generate{" +
|
||||
"cloud=" + cloud +
|
||||
", command=" + command +
|
||||
", uploader=" + uploader +
|
||||
", updateJar=" + updateJar +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ import org.eclipse.collections.api.list.MutableList;
|
||||
import org.eclipse.collections.api.map.MutableMap;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
@@ -50,6 +51,8 @@ public class RunnerApplication implements ApplicationRunner {
|
||||
private final ImmutableList<ServiceInfoWrapper> serviceInfoList;
|
||||
private final ImmutableList<HostInfoWrapper> hostInfoList;
|
||||
private final ObjectMapper mapper;
|
||||
@Value("${deploy.runtime.executor.task-jar-path}")
|
||||
private String taskJarPath;
|
||||
|
||||
public RunnerApplication(DeployInformationProperties deployInformationProperties) {
|
||||
this.deployInformationProperties = deployInformationProperties;
|
||||
@@ -95,9 +98,10 @@ public class RunnerApplication implements ApplicationRunner {
|
||||
generateCloud(Paths.get("cloud"));
|
||||
if (deployInformationProperties.getGenerate().getCommand())
|
||||
generateCommand(Paths.get("command"));
|
||||
if (deployInformationProperties.getGenerate().getUploader()) {
|
||||
if (deployInformationProperties.getGenerate().getUploader())
|
||||
generateUploader(Paths.get("uploader"));
|
||||
}
|
||||
if (deployInformationProperties.getGenerate().getUpdateJar())
|
||||
generateUpdateJar(Paths.get(""));
|
||||
}
|
||||
|
||||
private void generateCloud(Path root) throws IOException {
|
||||
@@ -302,4 +306,34 @@ public class RunnerApplication implements ApplicationRunner {
|
||||
stopScript = stopScript.replaceAll("\\$1", "service-uploader.jar");
|
||||
Files.write(Paths.get(root.toString(), "stop.sh"), stopScript.getBytes());
|
||||
}
|
||||
|
||||
private void generateUpdateJar(Path root) throws IOException {
|
||||
String absolutRootPath = root.toAbsolutePath().toString();
|
||||
logger.info("Current path: {}", absolutRootPath);
|
||||
|
||||
TemplateEngine engine = TemplateUtil.createEngine(new TemplateConfig("template", TemplateConfig.ResourceMode.CLASSPATH));
|
||||
Template syncTemplate = engine.getTemplate("update-jar.ftl");
|
||||
String syncScript = syncTemplate.render(MapUtil.builder()
|
||||
.put("currentPath", absolutRootPath)
|
||||
.put("runtime", runtimeInfo)
|
||||
.put("jarPrefix", "sync")
|
||||
.put("jarName", "sync-1.0.0-SNAPSHOT.jar")
|
||||
.put("uploadPath", runtimeInfo.getHudi().getAppHdfsPath())
|
||||
.build());
|
||||
Path syncScriptFile = Paths.get(root.toString(), "update-sync.sh");
|
||||
Files.deleteIfExists(syncScriptFile);
|
||||
Files.write(syncScriptFile, syncScript.getBytes());
|
||||
|
||||
Template taskTemplate = engine.getTemplate("update-jar.ftl");
|
||||
String taskScript = taskTemplate.render(MapUtil.builder()
|
||||
.put("currentPath", absolutRootPath)
|
||||
.put("runtime", runtimeInfo)
|
||||
.put("jarPrefix", "task")
|
||||
.put("jarName", "service-executor-task-1.0.0-SNAPSHOT.jar")
|
||||
.put("uploadPath", taskJarPath)
|
||||
.build());
|
||||
Path taskScriptFile = Paths.get(root.toString(), "update-task.sh");
|
||||
Files.deleteIfExists(taskScriptFile);
|
||||
Files.write(taskScriptFile, taskScript.getBytes());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
#!/bin/bash
|
||||
timestamp=`date +%s%N`
|
||||
jar_prefix=${jarPrefix}
|
||||
jar_name=${jarName}
|
||||
echo "Now version: <#noparse>${timestamp}</#noparse>"
|
||||
curl ${runtime.downloadUrl}/<#noparse>${jar_name}</#noparse> -o <#noparse>/tmp/${jar_prefix}-${timestamp}.jar</#noparse>
|
||||
hadoop fs -put <#noparse>/tmp/${jar_prefix}-${timestamp}.jar</#noparse> ${uploadPath}
|
||||
Reference in New Issue
Block a user