Selaa lähdekoodia

docker exec water

huangxingxing 8 kuukautta sitten
vanhempi
säilyke
08079c3f2c

+ 4 - 3
src/main/java/com/miniframe/bisiness/system/D00008Service.java

@@ -375,11 +375,12 @@ public class D00008Service extends D00008BaseModel implements ExecProcessFlow {
 	public void exeWater2(Integer aid,Integer jid){
 		CompletableFuture<Void> cf = CompletableFuture.supplyAsync(()-> {
 			try {
+				LogService.addLog(aid,jid,"Water","求解——————————————————开始");
+				DockerExe.stopDocker(aid,"Water");
 				DockerExe.waterExec(aid, jid,"Water");
 				DockerExe.getDockerLogs(aid,"Water",new ResultCallback.Adapter<Frame>() {
 					@Override
 					public void onNext(Frame frame) {
-						LogService.addLog(aid,jid,"Water","求解——————————————————开始");
 						LogService.addLog(aid,jid,"Water",new String(frame.getPayload()));
 						System.out.print(new String(frame.getPayload()));
 						super.onNext(frame);
@@ -390,14 +391,14 @@ public class D00008Service extends D00008BaseModel implements ExecProcessFlow {
 						throwable.printStackTrace();
 						super.onError(throwable);
 					}
-
 					@Override
 					public void onComplete() {
-						LogService.addLog(aid,jid,"Water","求解——————————————————成功");
+//						LogService.addLog(aid,jid,"Water","求解——————————————————成功");
 						System.out.println("日志获取完成");
 						super.onComplete();
 					}
 				});
+				LogService.addLog(aid,jid,"Water","求解——————————————————成功");
 				saveMonitorValue(aid,jid);
 				//路径保存
 				saveWayValue(aid,jid);

+ 4 - 5
src/main/java/com/miniframe/solverjob/DockerExe.java

@@ -21,7 +21,7 @@ public class DockerExe {
     public static final String DOCKERHOST="tcp://192.168.0.132:2375/";
     public static final String APIVERSION="1.13.1";
     // 获取容器信息
-    public static String getDocker(Integer aid){
+    public static String getDocker(Integer aid,String stype){
         DockerClientConfig config = DefaultDockerClientConfig.createDefaultConfigBuilder()
                 .withDockerHost(DOCKERHOST) // 设置 Docker 主机地址
                 .withDockerTlsVerify(false) // 启用 TLS 验证
@@ -34,7 +34,7 @@ public class DockerExe {
         DockerClient dockerClient = DockerClientBuilder.getInstance(config)
                 .withDockerHttpClient(httpClient)
                 .build();
-        InspectContainerResponse containerInfo = dockerClient.inspectContainerCmd(aid.toString()).exec();
+        InspectContainerResponse containerInfo = dockerClient.inspectContainerCmd(stype+"_"+aid.toString()).exec();
         //exited 停止  running  运行
         try{
             return containerInfo.getState().getStatus();
@@ -44,7 +44,7 @@ public class DockerExe {
 
 
     }
-    private static void stopDocker(Integer aid){
+    public static void stopDocker(Integer aid, String stype){
         DockerClientConfig config = DefaultDockerClientConfig.createDefaultConfigBuilder()
                 .withDockerHost(DOCKERHOST) // 设置 Docker 主机地址
                 .withDockerTlsVerify(false) // 启用 TLS 验证
@@ -58,7 +58,7 @@ public class DockerExe {
                 .withDockerHttpClient(httpClient)
                 .build();
         try {
-            dockerClient.stopContainerCmd(aid.toString())
+            dockerClient.stopContainerCmd(stype+"_"+aid.toString())
                     .withTimeout(1000)
                     .exec();
             dockerClient.removeConfigCmd(aid.toString())
@@ -87,7 +87,6 @@ public class DockerExe {
                 .withStdOut(true)
                 .withStdErr(true)
                 .withFollowStream(true);
-
         // 使用 ResultCallback.Adapter 处理日志
         logContainerCmd.exec(logsexe).awaitCompletion();
     }