|
|
@@ -9,6 +9,7 @@ import cn.reghao.autodop.common.dagent.app.api.data.log.LogType;
|
|
|
import cn.reghao.autodop.common.docker.Docker;
|
|
|
import cn.reghao.autodop.common.docker.exception.DockerException;
|
|
|
import cn.reghao.autodop.common.docker.pojo.Config;
|
|
|
+import cn.reghao.autodop.common.docker.pojo.HostConfig;
|
|
|
import cn.reghao.autodop.common.docker.pojo.State;
|
|
|
import cn.reghao.autodop.common.docker.pojo.result.ContainerInfo;
|
|
|
import cn.reghao.autodop.common.utils.DateTimeConverter;
|
|
|
@@ -37,10 +38,18 @@ public class DockerAppServiceImpl implements AppService {
|
|
|
String appId = appDeployArgs.getAppId();
|
|
|
String packagePath = appDeployArgs.getPackagePath();
|
|
|
Config dockerConfig = JsonConverter.jsonToObject(appDeployArgs.getStartScript(), Config.class);
|
|
|
+ if (dockerConfig == null) {
|
|
|
+ dockerConfig = new Config(packagePath);
|
|
|
+ } else {
|
|
|
+ dockerConfig.setImage(packagePath);
|
|
|
+ if (dockerConfig.getHostConfig() == null) {
|
|
|
+ dockerConfig.setHostConfig(new HostConfig());
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
try (Docker docker = new Docker()) {
|
|
|
docker.pull(packagePath);
|
|
|
- String containerId = docker.run(appId, packagePath, dockerConfig);
|
|
|
+ String containerId = docker.run(appId, dockerConfig);
|
|
|
Thread.sleep(sleep);
|
|
|
|
|
|
ContainerInfo containerInfo = docker.inspectContainer(containerId);
|
|
|
@@ -69,6 +78,57 @@ public class DockerAppServiceImpl implements AppService {
|
|
|
return appStatus;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public AppStatus status(String appId) throws DockerException {
|
|
|
+ try (Docker docker = new Docker()) {
|
|
|
+ String containerId = docker.getIdByName(appId);
|
|
|
+ if (containerId == null) {
|
|
|
+ throw new DockerException("没有和 " + appId + " 关联的容器");
|
|
|
+ }
|
|
|
+ ContainerInfo containerInfo = docker.inspectContainer(containerId);
|
|
|
+ return getAppStatus(appId, containerInfo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public AppStatus restart(String appId) throws DockerException {
|
|
|
+ try (Docker docker = new Docker()) {
|
|
|
+ String containerId = docker.getIdByName(appId);
|
|
|
+ docker.restart(containerId);
|
|
|
+ Thread.sleep(sleep);
|
|
|
+
|
|
|
+ ContainerInfo containerInfo = docker.inspectContainer(containerId);
|
|
|
+ return getAppStatus(appId, containerInfo);
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ throw new DockerException(ExceptionUtil.errorMsg(e));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public AppStatus stop(String appId) throws DockerException {
|
|
|
+ try (Docker docker = new Docker()) {
|
|
|
+ String containerId = docker.getIdByName(appId);
|
|
|
+ docker.stop(containerId);
|
|
|
+
|
|
|
+ ContainerInfo containerInfo = docker.inspectContainer(containerId);
|
|
|
+ return getAppStatus(appId, containerInfo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public AppStatus start(String appId) throws DockerException {
|
|
|
+ try (Docker docker = new Docker()) {
|
|
|
+ String containerId = docker.getIdByName(appId);
|
|
|
+ docker.start(containerId);
|
|
|
+ Thread.sleep(sleep);
|
|
|
+
|
|
|
+ ContainerInfo containerInfo = docker.inspectContainer(containerId);
|
|
|
+ return getAppStatus(appId, containerInfo);
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ throw new DockerException(ExceptionUtil.errorMsg(e));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public List<LogFile> logFiles(AppLogArgs appLogArgs) throws DockerException {
|
|
|
String appId = appLogArgs.getAppId();
|
|
|
@@ -120,55 +180,4 @@ public class DockerAppServiceImpl implements AppService {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- @Override
|
|
|
- public AppStatus status(String appId) throws DockerException {
|
|
|
- try (Docker docker = new Docker()) {
|
|
|
- String containerId = docker.getIdByName(appId);
|
|
|
- if (containerId == null) {
|
|
|
- throw new DockerException("没有和 " + appId + " 关联的容器");
|
|
|
- }
|
|
|
- ContainerInfo containerInfo = docker.inspectContainer(containerId);
|
|
|
- return getAppStatus(appId, containerInfo);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public AppStatus restart(String appId) throws DockerException {
|
|
|
- try (Docker docker = new Docker()) {
|
|
|
- String containerId = docker.getIdByName(appId);
|
|
|
- docker.restart(containerId);
|
|
|
- Thread.sleep(sleep);
|
|
|
-
|
|
|
- ContainerInfo containerInfo = docker.inspectContainer(containerId);
|
|
|
- return getAppStatus(appId, containerInfo);
|
|
|
- } catch (InterruptedException e) {
|
|
|
- throw new DockerException(ExceptionUtil.errorMsg(e));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public AppStatus stop(String appId) throws DockerException {
|
|
|
- try (Docker docker = new Docker()) {
|
|
|
- String containerId = docker.getIdByName(appId);
|
|
|
- docker.stop(containerId);
|
|
|
-
|
|
|
- ContainerInfo containerInfo = docker.inspectContainer(containerId);
|
|
|
- return getAppStatus(appId, containerInfo);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public AppStatus start(String appId) throws DockerException {
|
|
|
- try (Docker docker = new Docker()) {
|
|
|
- String containerId = docker.getIdByName(appId);
|
|
|
- docker.start(containerId);
|
|
|
- Thread.sleep(sleep);
|
|
|
-
|
|
|
- ContainerInfo containerInfo = docker.inspectContainer(containerId);
|
|
|
- return getAppStatus(appId, containerInfo);
|
|
|
- } catch (InterruptedException e) {
|
|
|
- throw new DockerException(ExceptionUtil.errorMsg(e));
|
|
|
- }
|
|
|
- }
|
|
|
}
|