Add support for routines; state messages
This commit is contained in:
@@ -19,6 +19,14 @@ class State extends Injectable {
|
||||
async reverse() {
|
||||
throw new ImplementationError()
|
||||
}
|
||||
|
||||
failure_message() {
|
||||
throw new ImplementationError()
|
||||
}
|
||||
|
||||
check_message() {
|
||||
throw new ImplementationError()
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = exports = State
|
||||
|
||||
@@ -26,6 +26,14 @@ class DirectoryState extends State {
|
||||
async _path() {
|
||||
return this._host.get_path(this._config.path)
|
||||
}
|
||||
|
||||
failure_message() {
|
||||
return `The path "${this._config.path}" does not exist on host "${this._host.name}."`
|
||||
}
|
||||
|
||||
check_message() {
|
||||
return this.failure_message()
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = exports = DirectoryState
|
||||
|
||||
@@ -46,6 +46,14 @@ class DownloadState extends State {
|
||||
if ( !this._config.path ) throw new Error('Missing path config for DownloadState.')
|
||||
return this._host.get_path(this._config.path)
|
||||
}
|
||||
|
||||
failure_message() {
|
||||
return `The downloaded file "${this._config.path}" does not exist on host "${this._host.name}."`
|
||||
}
|
||||
|
||||
check_message() {
|
||||
return this.failure_message()
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = exports = DownloadState
|
||||
|
||||
@@ -31,6 +31,14 @@ class FileState extends State {
|
||||
if ( !this._config.path ) throw new Error('Missing path config for FileState.')
|
||||
return this._host.get_path(this._config.path)
|
||||
}
|
||||
|
||||
failure_message() {
|
||||
return `The file "${this._config.path}" does not exist on the host "${this._host.name}."`
|
||||
}
|
||||
|
||||
check_message() {
|
||||
return this.failure_message()
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = exports = FileState
|
||||
|
||||
@@ -39,6 +39,13 @@ class OwnerState extends State {
|
||||
return path
|
||||
}
|
||||
|
||||
failure_message() {
|
||||
return `The ownership state of the file "${this._config.path}" on host "${this._host.name}" is invalid.`
|
||||
}
|
||||
|
||||
check_message() {
|
||||
return this.failure_message()
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = exports = OwnerState
|
||||
|
||||
@@ -55,6 +55,14 @@ class PackState extends State {
|
||||
if ( !path.is_valid() ) throw new Error(`Invalid path for PathState: ${path}`)
|
||||
return path
|
||||
}
|
||||
|
||||
failure_message() {
|
||||
return `The archive "${this._config.destination}" does not exist on the host "${this._host.name}."`
|
||||
}
|
||||
|
||||
check_message() {
|
||||
return this.failure_message()
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = exports = PackState
|
||||
|
||||
@@ -34,6 +34,14 @@ class PermissionState extends State {
|
||||
if ( !path.is_valid() ) throw new Error(`Invalid path for PermissionState: ${path}`)
|
||||
return path
|
||||
}
|
||||
|
||||
failure_message() {
|
||||
return `The resource permissions for "${this._config.path}" on host "${this._host.name}" are invalid.`
|
||||
}
|
||||
|
||||
check_message() {
|
||||
return this.failure_message()
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = exports = PermissionState
|
||||
|
||||
@@ -58,6 +58,14 @@ class UnpackState extends State {
|
||||
if ( !path.is_directory() ) throw new Error(`Invalid extraction path. Must be a directory: ${path}`)
|
||||
return path
|
||||
}
|
||||
|
||||
failure_message() {
|
||||
return `The unpacked archive does not exist at the path "${this._config.destination}" on host "${this._host.name}."`
|
||||
}
|
||||
|
||||
check_message() {
|
||||
return this.failure_message()
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = exports = UnpackState
|
||||
|
||||
@@ -33,6 +33,13 @@ class CheckoutState extends AbstractGitState {
|
||||
}
|
||||
}
|
||||
|
||||
failure_message() {
|
||||
return `The Git repo at "${this._config.path}" on host "${this._host.name}" is not checked out to the correct ref (${this._config.target}).`
|
||||
}
|
||||
|
||||
check_message() {
|
||||
return this.failure_message()
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = exports = CheckoutState
|
||||
|
||||
@@ -21,6 +21,13 @@ class CloneState extends AbstractGitState {
|
||||
}
|
||||
}
|
||||
|
||||
failure_message() {
|
||||
return `Could not find the cloned Git repo at "${this._config.path}" on host "${this._host.name}."`
|
||||
}
|
||||
|
||||
check_message() {
|
||||
return this.failure_message()
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = exports = CloneState
|
||||
|
||||
@@ -26,6 +26,13 @@ class TagState extends AbstractGitState {
|
||||
}
|
||||
}
|
||||
|
||||
failure_message() {
|
||||
return `The tag "${this._config.tag}" does not exist in the Git repo "${this._config.path}" on host "${this._host.name}."`
|
||||
}
|
||||
|
||||
check_message() {
|
||||
return this.failure_message()
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = exports = TagState
|
||||
|
||||
@@ -23,6 +23,13 @@ class CommandState extends State {
|
||||
}
|
||||
}
|
||||
|
||||
failure_message() {
|
||||
return `Failed to execute the command "${this._config.cmd}" on host "${this._host.name}."`
|
||||
}
|
||||
|
||||
check_message() {
|
||||
return `The command check was not successful.`
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = exports = CommandState
|
||||
|
||||
25
app/classes/state/os/IsAliveState.js
Normal file
25
app/classes/state/os/IsAliveState.js
Normal file
@@ -0,0 +1,25 @@
|
||||
const State = require('../State')
|
||||
|
||||
class IsAliveState extends State {
|
||||
async apply() {
|
||||
throw new Error('IsAliveState cannot be applied. It is a check measure only.')
|
||||
}
|
||||
|
||||
async check() {
|
||||
return this._host.is_alive()
|
||||
}
|
||||
|
||||
async reverse() {
|
||||
throw new Error('IsAliveState cannot be reversed. It is a check measure only.')
|
||||
}
|
||||
|
||||
failure_message() {
|
||||
return `Unable to connect to host "${this._host.name}".`
|
||||
}
|
||||
|
||||
check_message() {
|
||||
return this.failure_message()
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = exports = IsAliveState
|
||||
@@ -19,6 +19,14 @@ class PackageAbsentState extends State {
|
||||
async apply() {
|
||||
return this._host.packages.uninstall(this._config.package)
|
||||
}
|
||||
|
||||
failure_message() {
|
||||
return `The package "${this._config.package}" still exists on host "${this._host.name}."`
|
||||
}
|
||||
|
||||
check_message() {
|
||||
return this.failure_message()
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = exports = PackageAbsentState
|
||||
|
||||
@@ -23,6 +23,14 @@ class PackageCacheClearedState extends State {
|
||||
async reverse() {
|
||||
this.output.warn(`Package cache cleared state does not currently support reversal. (Host: ${this._host.name})`)
|
||||
}
|
||||
|
||||
failure_message() {
|
||||
return `Failed to clear package cache on host "${this._host.name}."`
|
||||
}
|
||||
|
||||
check_message() {
|
||||
return `The package cache on host "${this._host.name}" has not been cleared.`
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = exports = PackageCacheClearedState
|
||||
|
||||
@@ -19,6 +19,14 @@ class PackageState extends State {
|
||||
async reverse() {
|
||||
return this._host.packages.uninstall(this._config.package)
|
||||
}
|
||||
|
||||
failure_message() {
|
||||
return `The package "${this._config.package}" is not installed on host "${this._host.name}."`
|
||||
}
|
||||
|
||||
check_message() {
|
||||
return this.failure_message()
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = exports = PackageState
|
||||
|
||||
@@ -23,6 +23,14 @@ class ServiceDaemonReloadState extends State {
|
||||
async reverse() {
|
||||
this.output.warn(`Service daemon reload state does not currently support reversal. (Host: ${this._host.name})`)
|
||||
}
|
||||
|
||||
failure_message() {
|
||||
return `Unable to reload service daemon on host "${this._host.name}."`
|
||||
}
|
||||
|
||||
check_message() {
|
||||
return `The service daemon on host "${this._host.name}" has not been reloaded.`
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = exports = ServiceDaemonReloadState
|
||||
|
||||
@@ -24,6 +24,14 @@ class ServiceRestartState extends State {
|
||||
async reverse() {
|
||||
this.output.warn(`Service restart state does not currently support reversal. (Host: ${this._host.name})`)
|
||||
}
|
||||
|
||||
failure_message() {
|
||||
return `Unable to restart service "${this._config.service}" on host "${this._host.name}."`
|
||||
}
|
||||
|
||||
check_message() {
|
||||
return `The service "${this._config.service}" on host "${this._host.name}" has not been restarted.`
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = exports = ServiceRestartState
|
||||
|
||||
@@ -24,6 +24,15 @@ class ServiceState extends State {
|
||||
const services = Array.isArray(this._config.service) ? this._config.service : [this._config.service]
|
||||
return this._host.services.stop(...services)
|
||||
}
|
||||
|
||||
failure_message() {
|
||||
const services = Array.isArray(this._config.service) ? this._config.service : [this._config.service]
|
||||
return `The service(s) ${services.join(', ')} do not all exist on the host "${this._host.name}."`
|
||||
}
|
||||
|
||||
check_message() {
|
||||
return this.failure_message()
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = exports = ServiceState
|
||||
|
||||
@@ -24,6 +24,14 @@ class ServiceStoppedState extends State {
|
||||
const services = Array.isArray(this._config.service) ? this._config.service : [this._config.service]
|
||||
return this._host.services.stop(...services)
|
||||
}
|
||||
|
||||
failure_message() {
|
||||
return `Unable to stop service "${this._config.service}" on host "${this._host.name}."`
|
||||
}
|
||||
|
||||
check_message() {
|
||||
return `The service "${this._config.service}" on host "${this._host.name}" has not been stopped.`
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = exports = ServiceStoppedState
|
||||
|
||||
@@ -24,6 +24,14 @@ class UpdateState extends State {
|
||||
async reverse() {
|
||||
this.output.warn(`Update state does not currently support reversing package updates. (Host: ${this._host.name})`)
|
||||
}
|
||||
|
||||
failure_message() {
|
||||
return `Unable to update packages on host "${this._host.name}."`
|
||||
}
|
||||
|
||||
check_message() {
|
||||
return `There are package updates pending on the host "${this._host.name}."`
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = exports = UpdateState
|
||||
|
||||
Reference in New Issue
Block a user