Fixing linting & adding documentation
This commit is contained in:
parent
0d098b0958
commit
e356d5f623
|
@ -122,6 +122,11 @@ async function sendInfo(socket) {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Send list of docker hosts to client
|
||||
* @param {Socket} socket Socket.io socket instance
|
||||
* @returns {Promise<Bean[]>}
|
||||
*/
|
||||
async function sendDockerHostList(socket) {
|
||||
const timeLogger = new TimeLogger();
|
||||
|
||||
|
|
|
@ -4,6 +4,13 @@ const version = require("../package.json").version;
|
|||
const https = require("https");
|
||||
|
||||
class DockerHost {
|
||||
/**
|
||||
* Save a docker host
|
||||
* @param {Object} dockerHost Docker host to save
|
||||
* @param {?number} dockerHostID ID of the docker host to update
|
||||
* @param {number} userID ID of the user who adds the docker host
|
||||
* @returns {Promise<Bean>}
|
||||
*/
|
||||
static async save(dockerHost, dockerHostID, userID) {
|
||||
let bean;
|
||||
|
||||
|
@ -28,6 +35,12 @@ class DockerHost {
|
|||
return bean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a Docker host
|
||||
* @param {number} dockerHostID ID of the Docker host to delete
|
||||
* @param {number} userID ID of the user who created the Docker host
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
static async delete(dockerHostID, userID) {
|
||||
let bean = await R.findOne("docker_host", " id = ? AND user_id = ? ", [ dockerHostID, userID ]);
|
||||
|
||||
|
@ -38,6 +51,11 @@ class DockerHost {
|
|||
await R.trash(bean);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the amount of containers on the Docker host
|
||||
* @param {Object} dockerHost Docker host to check for
|
||||
* @returns {number} Total amount of containers on the host
|
||||
*/
|
||||
static async getAmountContainer(dockerHost) {
|
||||
const options = {
|
||||
url: "/containers/json?all=true",
|
||||
|
@ -64,4 +82,4 @@ class DockerHost {
|
|||
|
||||
module.exports = {
|
||||
DockerHost,
|
||||
}
|
||||
};
|
||||
|
|
|
@ -12,8 +12,8 @@ class DockerHost extends BeanModel {
|
|||
daemon: this._dockerDaemon,
|
||||
type: this._dockerType,
|
||||
name: this._name,
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = DockerHost;
|
||||
module.exports = DockerHost;
|
||||
|
|
|
@ -470,7 +470,7 @@ class Monitor extends BeanModel {
|
|||
} else if (this.type === "docker") {
|
||||
log.debug(`[${this.name}] Prepare Options for Axios`);
|
||||
|
||||
const docker_host = await R.load("docker_host", this.docker_host);
|
||||
const dockerHost = await R.load("docker_host", this.docker_host);
|
||||
|
||||
const options = {
|
||||
url: `/containers/${this.docker_container}/json`,
|
||||
|
@ -484,10 +484,10 @@ class Monitor extends BeanModel {
|
|||
}),
|
||||
};
|
||||
|
||||
if (docker_host._dockerType === "socket") {
|
||||
options.socketPath = docker_host._dockerDaemon;
|
||||
} else if (docker_host._dockerType === "tcp") {
|
||||
options.baseURL = docker_host._dockerDaemon;
|
||||
if (dockerHost._dockerType === "socket") {
|
||||
options.socketPath = dockerHost._dockerDaemon;
|
||||
} else if (dockerHost._dockerType === "tcp") {
|
||||
options.baseURL = dockerHost._dockerDaemon;
|
||||
}
|
||||
|
||||
log.debug(`[${this.name}] Axios Request`);
|
||||
|
|
|
@ -2,6 +2,10 @@ const { sendDockerHostList } = require("../client");
|
|||
const { checkLogin } = require("../util-server");
|
||||
const { DockerHost } = require("../docker");
|
||||
|
||||
/**
|
||||
* Handlers for docker hosts
|
||||
* @param {Socket} socket Socket.io instance
|
||||
*/
|
||||
module.exports.dockerSocketHandler = (socket) => {
|
||||
socket.on("addDockerHost", async (dockerHost, dockerHostID, callback) => {
|
||||
try {
|
||||
|
@ -20,7 +24,7 @@ module.exports.dockerSocketHandler = (socket) => {
|
|||
callback({
|
||||
ok: false,
|
||||
msg: e.message,
|
||||
})
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -40,7 +44,7 @@ module.exports.dockerSocketHandler = (socket) => {
|
|||
callback({
|
||||
ok: false,
|
||||
msg: e.message,
|
||||
})
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -61,7 +65,7 @@ module.exports.dockerSocketHandler = (socket) => {
|
|||
callback({
|
||||
ok: false,
|
||||
msg: e.message,
|
||||
})
|
||||
});
|
||||
}
|
||||
})
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
|
@ -66,7 +66,7 @@ export default {
|
|||
model: null,
|
||||
processing: false,
|
||||
id: null,
|
||||
connectionTypes: ["socket", "tcp"],
|
||||
connectionTypes: [ "socket", "tcp" ],
|
||||
dockerHost: {
|
||||
name: "",
|
||||
dockerDaemon: "",
|
||||
|
|
|
@ -144,7 +144,7 @@ export default {
|
|||
|
||||
socket.on("dockerHostList", (data) => {
|
||||
this.dockerHostList = data;
|
||||
})
|
||||
});
|
||||
|
||||
socket.on("heartbeat", (data) => {
|
||||
if (! (data.monitorID in this.heartbeatList)) {
|
||||
|
|
Loading…
Reference in New Issue