Skip to content

Commit

Permalink
release oz ref #777
Browse files Browse the repository at this point in the history
  • Loading branch information
shanwb committed Jan 15, 2024
1 parent 2647c3d commit fff9a43
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 37 deletions.
11 changes: 6 additions & 5 deletions jcommon/docean-plugin/docean-plugin-k8s/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<version>1.5.0-jdk21</version>
</parent>
<artifactId>docean-plugin-k8s</artifactId>
<version>1.5.1-jdk21</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<version.fabric8.client>5.11.2</version.fabric8.client>
Expand All @@ -23,10 +24,10 @@
<artifactId>kubernetes-client</artifactId>
<version>${version.fabric8.client}</version>
</dependency>
<dependency>
<groupId>io.kubernetes</groupId>
<artifactId>client-java</artifactId>
<version>15.0.1</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>io.kubernetes</groupId>-->
<!-- <artifactId>client-java</artifactId>-->
<!-- <version>15.0.1</version>-->
<!-- </dependency>-->
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,12 @@
import io.fabric8.kubernetes.api.model.batch.v1.JobList;
import io.fabric8.kubernetes.client.DefaultKubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.dsl.ExecWatch;
import io.fabric8.kubernetes.client.dsl.MixedOperation;
import io.fabric8.kubernetes.client.informers.ResourceEventHandler;
import io.fabric8.kubernetes.client.informers.SharedIndexInformer;
import io.fabric8.kubernetes.client.informers.SharedInformerFactory;
import io.kubernetes.client.Exec;
import io.kubernetes.client.openapi.ApiClient;
import io.fabric8.kubernetes.api.model.autoscaling.v1.HorizontalPodAutoscaler;
import io.kubernetes.client.util.Streams;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;

Expand All @@ -60,14 +58,10 @@
public class K8sPlugin implements IPlugin {

private KubernetesClient client;
private static final ApiClient cli;
private static final KubernetesClient DEFAULT_CLIENT;

static {
try {
cli = io.kubernetes.client.util.Config.defaultClient();
} catch (IOException e) {
throw new RuntimeException(e);
}
DEFAULT_CLIENT = new DefaultKubernetesClient();
}

/**
Expand Down Expand Up @@ -162,35 +156,31 @@ public boolean start(Ioc ioc) {
}

@SneakyThrows
private static Pair<Integer, String> execContainer(String ns, String name, String container, String[] command) {
final Process proc = new Exec(cli).exec(ns, name, command, container, false, false);
ByteArrayOutputStream sb = new ByteArrayOutputStream();
Thread out =
new Thread(
() -> {
try {
Streams.copy(proc.getInputStream(), sb);
} catch (IOException ex) {
ex.printStackTrace();
}
});
out.start();

proc.waitFor();

// wait for any last output; no need to wait for input thread
out.join();

proc.destroy();
return Pair.of(proc.exitValue(), sb.toString());
private static Pair<Integer, String> execContainer(KubernetesClient client, String ns, String name, String container, String[] command) {
ByteArrayOutputStream out = new ByteArrayOutputStream();
ByteArrayOutputStream error = new ByteArrayOutputStream();
try (ExecWatch execWatch = client.pods().inNamespace(ns).withName(name)
.inContainer(container)
.writingOutput(out)
.writingError(error)
.exec(command)) {
// 等待命令执行完成
execWatch.close();
}
// 返回执行结果
String result = out.toString();
System.out.println("result:" + result);
// 这里没有直接的退出值,你可能需要根据输出结果来判断命令是否成功执行
return Pair.of(0, result);

}

@SneakyThrows
public static Pair<Integer, String> KillContainer(String ns, String name, String container) {
String[] shs = new String[]{"bash", "ash", "sh"};
Pair<Integer, String> end = null;
for (String sh : shs) {
end = execContainer(ns, name, container, new String[]{sh, "-c", "trap \"exit\" SIGINT SIGTERM ; kill -s SIGINT 1"});
end = execContainer(DEFAULT_CLIENT, ns, name, container, new String[]{sh, "-c", "trap \"exit\" SIGINT SIGTERM ; kill -s SIGINT 1"});
if (end.getKey().equals(0)) {
break;
}
Expand Down
2 changes: 1 addition & 1 deletion jcommon/file/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<version>1.4-jdk20-SNAPSHOT</version>
</parent>
<artifactId>file</artifactId>
<version>1.4-jdk21-SNAPSHOT</version>
<version>${submodule-release.version}</version>

<dependencies>

Expand Down
1 change: 1 addition & 0 deletions jcommon/hera/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<version>1.4-jdk20-SNAPSHOT</version>
</parent>
<artifactId>hera</artifactId>
<version>${submodule-release.version}</version>
<packaging>pom</packaging>
<modules>
<module>hera-trace</module>
Expand Down

0 comments on commit fff9a43

Please sign in to comment.