From 4449474365373c95d559e1cfeea4438b596bace1 Mon Sep 17 00:00:00 2001 From: Darren Satkunas Date: Fri, 9 Dec 2022 05:53:01 -0800 Subject: [PATCH] add systemd update button --- .../new/BaseButtonSystemService.vue | 2 +- .../new/BaseButtonSystemdUpdate.vue | 173 ++++++++++++++++++ .../src/components/new/BaseSystemdUpdate.vue | 96 ++++++++++ .../root/src/components/new/index.js | 2 + .../pfappserver/root/src/globals/pfLocales.js | 3 + .../root/src/store/modules/cluster.js | 161 ++++++++++++++-- .../eventLoggers/_components/TheSearch.vue | 8 + 7 files changed, 429 insertions(+), 16 deletions(-) create mode 100644 html/pfappserver/root/src/components/new/BaseButtonSystemdUpdate.vue create mode 100644 html/pfappserver/root/src/components/new/BaseSystemdUpdate.vue diff --git a/html/pfappserver/root/src/components/new/BaseButtonSystemService.vue b/html/pfappserver/root/src/components/new/BaseButtonSystemService.vue index bd01d5ffa811..60042d47b01a 100644 --- a/html/pfappserver/root/src/components/new/BaseButtonSystemService.vue +++ b/html/pfappserver/root/src/components/new/BaseButtonSystemService.vue @@ -91,7 +91,7 @@ const props = { }, acl: { type: String, - default: 'SERVICES_READ' + default: 'SYSTEM_READ' } } diff --git a/html/pfappserver/root/src/components/new/BaseButtonSystemdUpdate.vue b/html/pfappserver/root/src/components/new/BaseButtonSystemdUpdate.vue new file mode 100644 index 000000000000..a1fb4788e0ab --- /dev/null +++ b/html/pfappserver/root/src/components/new/BaseButtonSystemdUpdate.vue @@ -0,0 +1,173 @@ + + diff --git a/html/pfappserver/root/src/components/new/BaseSystemdUpdate.vue b/html/pfappserver/root/src/components/new/BaseSystemdUpdate.vue new file mode 100644 index 000000000000..a6c7ffa39f05 --- /dev/null +++ b/html/pfappserver/root/src/components/new/BaseSystemdUpdate.vue @@ -0,0 +1,96 @@ + + diff --git a/html/pfappserver/root/src/components/new/index.js b/html/pfappserver/root/src/components/new/index.js index 26f7400be800..4e057d938cc6 100644 --- a/html/pfappserver/root/src/components/new/index.js +++ b/html/pfappserver/root/src/components/new/index.js @@ -7,6 +7,7 @@ import BaseButtonSave from './BaseButtonSave' import BaseButtonSaveSearch from './BaseButtonSaveSearch' import BaseButtonService from './BaseButtonService' import BaseButtonSystemService from './BaseButtonSystemService' +import BaseButtonSystemdUpdate from './BaseButtonSystemdUpdate' import BaseButtonUpload from './BaseButtonUpload' import BaseContainerLoading from './BaseContainerLoading' import BaseCsvImport from './BaseCsvImport' @@ -154,6 +155,7 @@ export { BaseButtonSaveSearch, BaseButtonService, BaseButtonSystemService, + BaseButtonSystemdUpdate, BaseButtonUpload, // containers diff --git a/html/pfappserver/root/src/globals/pfLocales.js b/html/pfappserver/root/src/globals/pfLocales.js index 7b08ac0d9f39..ea01886eecbf 100644 --- a/html/pfappserver/root/src/globals/pfLocales.js +++ b/html/pfappserver/root/src/globals/pfLocales.js @@ -32,4 +32,7 @@ export const localeStrings = { SERVICES_STOPPED_SUCCESS: 'Stopped services {services}.', // i18n defer SERVICES_STOPPED_ERROR: 'Failed to stop services {services}. See the server error logs for more information.', // i18n defer + + SYSTEMD_UPDATED_SUCCESS: 'Updated systemd for {service}.', // i18n defer + SYSTEMD_UPDATED_ERROR: 'Failed to update systemd for {service}. See the server error logs for more information.', // i18n defer } diff --git a/html/pfappserver/root/src/store/modules/cluster.js b/html/pfappserver/root/src/store/modules/cluster.js index af8f22c33b25..26a583addeb7 100644 --- a/html/pfappserver/root/src/store/modules/cluster.js +++ b/html/pfappserver/root/src/store/modules/cluster.js @@ -155,6 +155,7 @@ const types = { RESTARTING: 'restarting', STARTING: 'starting', STOPPING: 'stopping', + UPDATING: 'updating', SUCCESS: 'success', ERROR: 'error' } @@ -227,14 +228,30 @@ const getters = { }, hasAlive: Object.values(state.servers).findIndex(({ services: { [id]: service } }) => service && service.alive && service.pid) > -1, hasDead: Object.values(state.servers).findIndex(({ services: { [id]: service } }) => service && !(service.alive || service.pid)) > -1, - hasEnabled: Object.values(state.servers).findIndex(({ services: { [id]: service } }) => service && service.enabled) > -1, - hasDisabled: Object.values(state.servers).findIndex(({ services: { [id]: service } }) => service && !service.enabled) > -1, - isProtected: !!protectedServices.find(listed => listed === id), } } }, sorted) }, {}) - } + }, + systemdByServer: state => { + return Object.entries(state.servers).reduce((sorted, [server, {systemd = {}}]) => { + return Object.entries(systemd).reduce((sorted, [id, service]) => { + return { + ...sorted, + [id]: { + servers: { + ...((id in sorted) ? sorted[id].servers : {} ), + [server]: { + ...service, + isUpdating: service.status === types.UPDATING, + } + } + } + } + }, sorted) + }, {}) + }, + servers: state => Object.keys(state.servers), } const actions = { @@ -323,7 +340,7 @@ const actions = { disableServiceCluster: ({ state, dispatch }, id) => { return new Promise((resolve, reject) => { dispatch('getConfig').then(() => { - // async requests + // serialize async requests const async = (idx = 0) => { const server = Object.keys(state.servers)[idx] const next = () => { @@ -363,7 +380,7 @@ const actions = { enableServiceCluster: ({ state, dispatch }, id) => { return new Promise((resolve, reject) => { dispatch('getConfig').then(() => { - // async requests + // serialize async requests const async = (idx = 0) => { const server = Object.keys(state.servers)[idx] const next = () => { @@ -403,7 +420,7 @@ const actions = { restartServiceCluster: ({ state, dispatch }, id) => { return new Promise((resolve, reject) => { dispatch('getConfig').then(() => { - // async requests + // serialize async requests const async = (idx = 0) => { const server = Object.keys(state.servers)[idx] const next = () => { @@ -443,7 +460,7 @@ const actions = { startServiceCluster: ({ state, dispatch }, id) => { return new Promise((resolve, reject) => { dispatch('getConfig').then(() => { - // async requests + // serialize async requests const async = (idx = 0) => { const server = Object.keys(state.servers)[idx] const next = () => { @@ -483,7 +500,7 @@ const actions = { stopServiceCluster: ({ state, dispatch }, id) => { return new Promise((resolve, reject) => { dispatch('getConfig').then(() => { - // async requests + // serialize async requests const async = (idx = 0) => { const server = Object.keys(state.servers)[idx] const next = () => { @@ -509,6 +526,7 @@ const actions = { }) }, + getSystemService: ({ state, commit }, { server, id }) => { commit('SYSTEM_SERVICE_REQUEST', { server, id }) return api(state, server).systemService(id).then(service => { @@ -546,6 +564,34 @@ const actions = { throw err }).finally(() => dispatch('getSystemService', { server, id })) }, + restartSystemServiceCluster: ({ state, dispatch }, id) => { + return new Promise((resolve, reject) => { + dispatch('getConfig').then(() => { + // serialize async requests + const async = (idx = 0) => { + const server = Object.keys(state.servers)[idx] + const next = () => { + if (idx < Object.keys(state.servers).length-1) { + async(++idx) + } + else { + resolve() + } + } + const { [server]: { system_services: { [id]: { alive = false, pid = false } = {} } = {} } = {} } = state.servers + if (alive && pid) { + dispatch('restartSystemService', { server, id }) + .catch(err => reject(err)) + .then(() => next()) + } + else { + next() + } + } + async() + }) + }) + }, startSystemService: ({ state, commit, dispatch }, { id, server = store.state.system.hostname }) => { commit('SYSTEM_SERVICE_REQUEST', { server, id }) commit('SYSTEM_SERVICE_STARTING', { server, id }) @@ -558,6 +604,34 @@ const actions = { throw err }).finally(() => dispatch('getSystemService', { server, id })) }, + startSystemServiceCluster: ({ state, dispatch }, id) => { + return new Promise((resolve, reject) => { + dispatch('getConfig').then(() => { + // serialize async requests + const async = (idx = 0) => { + const server = Object.keys(state.servers)[idx] + const next = () => { + if (idx < Object.keys(state.servers).length - 1) { + async(++idx) + } + else { + resolve() + } + } + const { [server]: { system_services: { [id]: { alive = false, pid = false } = {} } = {} } = {} } = state.servers + if (!(alive && pid)) { + dispatch('startSystemService', { server, id }) + .catch(err => reject(err)) + .then(() => next()) + } + else { + next() + } + } + async() + }) + }) + }, stopSystemService: ({ state, commit, dispatch }, { id, server = store.state.system.hostname }) => { commit('SYSTEM_SERVICE_REQUEST', { server, id }) commit('SYSTEM_SERVICE_STOPPING', { server, id }) @@ -570,6 +644,35 @@ const actions = { throw err }).finally(() => dispatch('getSystemService', { server, id })) }, + stopSystemServiceCluster: ({ state, dispatch }, id) => { + return new Promise((resolve, reject) => { + dispatch('getConfig').then(() => { + // serialize async requests + const async = (idx = 0) => { + const server = Object.keys(state.servers)[idx] + const next = () => { + if (idx < Object.keys(state.servers).length - 1) { + async(++idx) + } + else { + resolve() + } + } + const { [server]: { system_services: { [id]: { alive = false, pid = false } = {} } = {} } = {} } = state.servers + if (alive && pid) { + dispatch('stopSystemService', { server, id }) + .catch(err => reject(err)) + .then(() => next()) + } + else { + next() + } + } + async() + }) + }) + }, + updateSystemd: ({ state, commit }, { id, server = store.state.system.hostname }) => { commit('SYSTEMD_REQUEST', { server, id }) @@ -582,6 +685,28 @@ const actions = { throw err }) }, + updateSystemdCluster: ({ state, dispatch }, id) => { + return new Promise((resolve, reject) => { + dispatch('getConfig').then(() => { + // serialize async requests + const async = (idx = 0) => { + const server = Object.keys(state.servers)[idx] + const next = () => { + if (idx < Object.keys(state.servers).length - 1) { + async(++idx) + } + else { + resolve() + } + } + dispatch('updateSystemd', { server, id }) + .catch(err => reject(err)) + .then(() => next()) + } + async() + }) + }) + }, } const mutations = { @@ -593,7 +718,7 @@ const mutations = { }, CONFIG_SUCCESS: (state, items) => { items.map(server => { - Vue.set(state.servers, server.host, { services: {}, system_services: {}, ...state.servers[server.host], ...server }) + Vue.set(state.servers, server.host, { services: {}, system_services: {}, systemd: {}, ...state.servers[server.host], ...server }) }) state.status = types.SUCCESS state.message = '' @@ -625,7 +750,7 @@ const mutations = { SERVICE_REQUEST: (state, { server, id }) => { state.status = types.LOADING - Vue.set(state.servers, server, state.servers[server] || { services: {}, system_services: {} }) + Vue.set(state.servers, server, state.servers[server] || { services: {}, system_services: {}, systemd: {} }) Vue.set(state.servers[server].services, id, state.servers[server].services[id] || {}) Vue.set(state.servers[server].services[id], 'status', types.LOADING) }, @@ -703,7 +828,7 @@ const mutations = { SYSTEM_SERVICE_REQUEST: (state, { server, id }) => { state.status = types.LOADING - Vue.set(state.servers, server, state.servers[server] || { services: {}, system_services: {} }) + Vue.set(state.servers, server, state.servers[server] || { services: {}, system_services: {}, systemd: {} }) Vue.set(state.servers[server].system_services, id, state.servers[server].system_services[id] || {}) Vue.set(state.servers[server].system_services[id], 'status', types.LOADING) }, @@ -746,17 +871,23 @@ const mutations = { Vue.set(state.servers[server].system_services[id], 'status', types.ERROR) }, - SYSTEMD_REQUEST: state => { + SYSTEMD_REQUEST: (state, { server, id }) => { state.status = types.LOADING + Vue.set(state.servers, server, state.servers[server] || { services: {}, system_services: {}, systemd: {} }) + Vue.set(state.servers[server].systemd, id, state.servers[server].systemd[id] || {}) + Vue.set(state.servers[server].systemd[id], 'status', types.UPDATING) }, - SYSTEMD_SUCCESS: state => { + SYSTEMD_SUCCESS: (state, { server, id }) => { state.status = types.SUCCESS state.message = '' + Vue.set(state.servers[server].systemd, id, { ...state.servers[server].systemd[id], status: types.SUCCESS }) }, - SYSTEMD_ERROR: (state, error) => { + SYSTEMD_ERROR: (state, { server, id, error }) => { state.status = types.ERROR state.message = error + Vue.set(state.servers[server].systemd[id], 'status', types.ERROR) }, + $RESET: (state) => { // eslint-disable-next-line no-unused-vars state = initialState() diff --git a/html/pfappserver/root/src/views/Configuration/eventLoggers/_components/TheSearch.vue b/html/pfappserver/root/src/views/Configuration/eventLoggers/_components/TheSearch.vue index a54d35166b55..425830dde0c6 100644 --- a/html/pfappserver/root/src/views/Configuration/eventLoggers/_components/TheSearch.vue +++ b/html/pfappserver/root/src/views/Configuration/eventLoggers/_components/TheSearch.vue @@ -13,6 +13,10 @@ :to="{ name: 'newEventLogger', params: { eventLoggerType: value } }" >{{ text }} + +