use of io.jpom.plugin.IPlugin in project Jpom by dromara.
the class DockerImagesController method list.
/**
* @return json
*/
@PostMapping(value = "list", produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.LIST)
public String list(@ValidatorItem String id) throws Exception {
DockerInfoModel dockerInfoModel = dockerInfoService.getByKey(id, getRequest());
IPlugin plugin = PluginFactory.getPlugin(DockerInfoService.DOCKER_PLUGIN_NAME);
Map<String, Object> parameter = dockerInfoModel.toParameter();
parameter.put("name", getParameter("name"));
parameter.put("showAll", getParameter("showAll"));
parameter.put("dangling", getParameter("dangling"));
List<JSONObject> listContainer = (List<JSONObject>) plugin.execute("listImages", parameter);
return JsonMessage.getString(200, "", listContainer);
}
use of io.jpom.plugin.IPlugin in project Jpom by dromara.
the class DockerImagesController method del.
/**
* @return json
*/
@GetMapping(value = "remove", produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.DEL)
public String del(@ValidatorItem String id, String imageId) throws Exception {
DockerInfoModel dockerInfoModel = dockerInfoService.getByKey(id, getRequest());
IPlugin plugin = PluginFactory.getPlugin(DockerInfoService.DOCKER_PLUGIN_NAME);
Map<String, Object> parameter = dockerInfoModel.toParameter();
parameter.put("imageId", imageId);
plugin.execute("removeImage", parameter);
return JsonMessage.getString(200, "执行成功");
}
use of io.jpom.plugin.IPlugin in project Jpom by dromara.
the class DockerImagesController method inspect.
/**
* @return json
*/
@GetMapping(value = "inspect", produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.LIST)
public String inspect(@ValidatorItem String id, String imageId) throws Exception {
DockerInfoModel dockerInfoModel = dockerInfoService.getByKey(id, getRequest());
IPlugin plugin = PluginFactory.getPlugin(DockerInfoService.DOCKER_PLUGIN_NAME);
Map<String, Object> parameter = dockerInfoModel.toParameter();
parameter.put("imageId", imageId);
JSONObject inspectImage = (JSONObject) plugin.execute("inspectImage", parameter);
return JsonMessage.getString(200, "", inspectImage);
}
use of io.jpom.plugin.IPlugin in project Jpom by dromara.
the class DockerInfoService method updateMonitor.
/**
* 监控 容器
*
* @param dockerInfoModel docker
*/
public boolean updateMonitor(DockerInfoModel dockerInfoModel) {
try {
IPlugin plugin = PluginFactory.getPlugin(DockerInfoService.DOCKER_CHECK_PLUGIN_NAME);
Map<String, Object> parameter = dockerInfoModel.toParameter();
parameter.put("timeout", dockerInfoModel.getHeartbeatTimeout());
//
JSONObject info = plugin.execute("info", parameter, JSONObject.class);
//
DockerInfoModel update = new DockerInfoModel();
update.setId(dockerInfoModel.getId());
update.setStatus(1);
update.setLastHeartbeatTime(SystemClock.now());
//
update.setDockerVersion(info.getString("serverVersion"));
JSONObject swarm = info.getJSONObject("swarm");
if (swarm != null) {
String nodeId = swarm.getString("nodeID");
update.setSwarmNodeId(nodeId);
if (StrUtil.isEmpty(nodeId)) {
// 集群退出
update.setSwarmId(StrUtil.EMPTY);
}
} else {
update.setSwarmNodeId(StrUtil.EMPTY);
update.setSwarmId(StrUtil.EMPTY);
}
update.setFailureMsg(StrUtil.EMPTY);
super.update(update);
//
this.updateSwarmStatus(dockerInfoModel.getId(), update.getStatus(), update.getFailureMsg());
return true;
} catch (Exception e) {
log.error("监控 docker 异常", e);
this.updateStatus(dockerInfoModel.getId(), 0, e.getMessage());
return false;
}
}
use of io.jpom.plugin.IPlugin in project Jpom by dromara.
the class DockerInfoService method localLocalDocker.
private void localLocalDocker() {
try {
IPlugin plugin = PluginFactory.getPlugin(DockerInfoService.DOCKER_CHECK_PLUGIN_NAME);
String dockerHost = (String) plugin.execute("testLocal", new HashMap<>(1));
Entity entity = Entity.create();
entity.set("host", dockerHost);
entity.set("workspaceId", Const.WORKSPACE_DEFAULT_ID);
boolean exists = this.exists(entity);
if (exists) {
return;
}
DockerInfoModel.DockerInfoModelBuilder builder = DockerInfoModel.builder();
builder.host(dockerHost).name("localhost").status(1);
DockerInfoModel dockerInfoModel = builder.build();
dockerInfoModel.setWorkspaceId(Const.WORKSPACE_DEFAULT_ID);
dockerInfoModel.setModifyUser(UserModel.SYSTEM_ADMIN);
this.insert(dockerInfoModel);
Console.log("Automatically add local docker host: {}", dockerHost);
} catch (Exception e) {
Console.error("There is no docker service local {}", e.getMessage());
}
}
Aggregations