-
Notifications
You must be signed in to change notification settings - Fork 398
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DDH Manager Ping Worker, Worker State Checked (#248)
* 调整 JVM 参数适应高版本 JDK,移除内存优化参数,不分不适用,移除 DS copy * 调整ui的打包,使无需copy dist到api resource;增加versions-maven-plugin * 支持优先从worker templates下加载配置模版,其次从component根目录下加载 * remove spec comments * BugFix: 修复 workerjar 打包所有 resource 下资源导致jar太大,修复没有正常日志文件输出 * Manager Ping Worker, Worker State Check * when start service, read shell first line, use bash or sh exec scripts * upgrade ant depend to highest version * merge origin code,check md5 use java api
- Loading branch information
Showing
11 changed files
with
370 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
datasophon-common/src/main/java/com/datasophon/common/command/PingCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.datasophon.common.command; | ||
|
||
import lombok.Data; | ||
|
||
import java.io.Serializable; | ||
|
||
/** | ||
* | ||
* | ||
* @author zhenqin | ||
*/ | ||
@Data | ||
public class PingCommand implements Serializable { | ||
|
||
private String message; | ||
|
||
} |
132 changes: 132 additions & 0 deletions
132
datasophon-common/src/main/java/com/datasophon/common/utils/FileUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.datasophon.common.utils; | ||
|
||
import com.google.common.io.CharStreams; | ||
import com.google.common.io.LineProcessor; | ||
import org.apache.commons.codec.binary.Hex; | ||
import org.apache.commons.lang.StringUtils; | ||
import org.apache.tools.tar.TarEntry; | ||
import org.apache.tools.tar.TarInputStream; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.FileReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.nio.charset.Charset; | ||
import java.security.MessageDigest; | ||
import java.util.zip.GZIPInputStream; | ||
/** | ||
* | ||
* 基本文件的特殊操作,文件MD5,从 targz 压缩包不解压读取一个文本文件,读取一个文件的第一行 等 | ||
* | ||
* <pre> | ||
* | ||
* Created by zhenqin. | ||
* User: zhenqin | ||
* Date: 2023/4/21 | ||
* Time: 下午9:58 | ||
* | ||
* </pre> | ||
* | ||
* @author zhenqin | ||
*/ | ||
public class FileUtils { | ||
|
||
|
||
/** | ||
* 获取一个文件的md5值(可处理大文件) | ||
* @return md5 value | ||
*/ | ||
public static String md5(File file) { | ||
try (FileInputStream fileInputStream = new FileInputStream(file);) { | ||
MessageDigest MD5 = MessageDigest.getInstance("MD5"); | ||
|
||
byte[] buffer = new byte[8192]; | ||
int length; | ||
while ((length = fileInputStream.read(buffer)) != -1) { | ||
MD5.update(buffer, 0, length); | ||
} | ||
return new String(Hex.encodeHex(MD5.digest())); | ||
} catch (Exception e) { | ||
throw new IllegalStateException(e); | ||
} | ||
} | ||
|
||
|
||
/** | ||
* 从 tar.gz 的压缩包内读取一个 文本文件 | ||
* @param targz | ||
* @param name | ||
* @return | ||
* @throws IOException | ||
*/ | ||
public static String readTargzTextFile(File targz, String name, Charset charset) throws IOException { | ||
String content = null; | ||
TarEntry tarEntry = null; | ||
try (TarInputStream tarInputStream = new TarInputStream(new GZIPInputStream(new FileInputStream(targz))); | ||
BufferedReader reader = new BufferedReader(new InputStreamReader(tarInputStream, charset));){ | ||
boolean hasNext = reader.readLine() != null; | ||
if(hasNext) { | ||
return null; | ||
} | ||
while ((tarEntry = tarInputStream.getNextEntry()) != null ) { | ||
String entryName = tarEntry.getName(); | ||
if (tarEntry.isDirectory()) { | ||
// 如果是文件夹,创建文件夹并加速循环 | ||
continue; | ||
} | ||
if(entryName.endsWith(name)) { | ||
// 找到第一个文件就结束 | ||
content = CharStreams.toString(reader); | ||
break; | ||
} | ||
} | ||
} | ||
return content; | ||
} | ||
|
||
|
||
/** | ||
* 读取文件第一行,第一行的非空行 | ||
* @param file | ||
* @return | ||
* @throws Exception | ||
*/ | ||
public static String readFirstLine(File file) throws Exception { | ||
final String firstLine = CharStreams.readLines(new FileReader(file), new LineProcessor<String>() { | ||
|
||
String firstLine = null; | ||
|
||
@Override | ||
public boolean processLine(String line) throws IOException { | ||
this.firstLine = line; | ||
// 第一行非空则返回 | ||
return StringUtils.trimToNull(line) == null; | ||
} | ||
|
||
@Override | ||
public String getResult() { | ||
return firstLine; | ||
} | ||
}); | ||
return firstLine; | ||
} | ||
} |
Oops, something went wrong.