Commit 3ae93c72 authored by Kushal Pandya's avatar Kushal Pandya

Make Toggle, Repair and Remove actions async

parent 30227d7d
<script> <script>
import { s__ } from '~/locale';
import Flash from '~/flash';
import statusCodes from '~/lib/utils/http_status';
import loadingIcon from '~/vue_shared/components/loading_icon.vue'; import loadingIcon from '~/vue_shared/components/loading_icon.vue';
import modal from '~/vue_shared/components/modal.vue';
import SmartInterval from '~/smart_interval'; import SmartInterval from '~/smart_interval';
import eventHub from '../event_hub'; import eventHub from '../event_hub';
import { NODE_ACTIONS } from '../constants';
import geoNodesList from './geo_nodes_list.vue'; import geoNodesList from './geo_nodes_list.vue';
export default { export default {
components: { components: {
loadingIcon, loadingIcon,
modal,
geoNodesList, geoNodesList,
}, },
props: { props: {
...@@ -33,6 +40,12 @@ ...@@ -33,6 +40,12 @@
return { return {
isLoading: true, isLoading: true,
hasError: false, hasError: false,
showModal: false,
targetNode: null,
targetNodeActionType: '',
modalKind: 'warning',
modalMessage: '',
modalActionLabel: '',
errorMessage: '', errorMessage: '',
}; };
}, },
...@@ -43,17 +56,34 @@ ...@@ -43,17 +56,34 @@
}, },
created() { created() {
eventHub.$on('pollNodeDetails', this.initNodeDetailsPolling); eventHub.$on('pollNodeDetails', this.initNodeDetailsPolling);
eventHub.$on('showNodeActionModal', this.showNodeActionModal);
eventHub.$on('repairNode', this.repairNode);
}, },
mounted() { mounted() {
this.fetchGeoNodes(); this.fetchGeoNodes();
}, },
beforeDestroy() { beforeDestroy() {
eventHub.$off('pollNodeDetails', this.initNodeDetailsPolling); eventHub.$off('pollNodeDetails', this.initNodeDetailsPolling);
eventHub.$off('showNodeActionModal', this.showNodeActionModal);
eventHub.$off('repairNode', this.repairNode);
if (this.nodePollingInterval) { if (this.nodePollingInterval) {
this.nodePollingInterval.stopTimer(); this.nodePollingInterval.stopTimer();
} }
}, },
methods: { methods: {
setNodeActionStatus(node, status) {
Object.assign(node, { nodeActionActive: status });
},
initNodeDetailsPolling(node) {
this.nodePollingInterval = new SmartInterval({
callback: this.fetchNodeDetails.bind(this, node),
startingInterval: 30000,
maxInterval: 120000,
hiddenInterval: 240000,
incrementByFactorOf: 15000,
immediateExecution: true,
});
},
fetchGeoNodes() { fetchGeoNodes() {
this.hasError = false; this.hasError = false;
this.service.getGeoNodes() this.service.getGeoNodes()
...@@ -67,8 +97,9 @@ ...@@ -67,8 +97,9 @@
this.errorMessage = err; this.errorMessage = err;
}); });
}, },
fetchNodeDetails(nodeId) { fetchNodeDetails(node) {
return this.service.getGeoNodeDetails(nodeId) const nodeId = node.id;
return this.service.getGeoNodeDetails(node)
.then(res => res.data) .then(res => res.data)
.then((nodeDetails) => { .then((nodeDetails) => {
const primaryNodeVersion = this.store.getPrimaryNodeVersion(); const primaryNodeVersion = this.store.getPrimaryNodeVersion();
...@@ -80,18 +111,81 @@ ...@@ -80,18 +111,81 @@
eventHub.$emit('nodeDetailsLoaded', this.store.getNodeDetails(nodeId)); eventHub.$emit('nodeDetailsLoaded', this.store.getNodeDetails(nodeId));
}) })
.catch((err) => { .catch((err) => {
eventHub.$emit('nodeDetailsLoadFailed', nodeId, err); if (err.response && err.response.status === statusCodes.NOT_FOUND) {
this.store.setNodeDetails(nodeId, {
geo_node_id: nodeId,
health: err.message,
health_status: 'Unknown',
missing_oauth_application: false,
sync_status_unavailable: true,
storage_shards_match: null,
});
eventHub.$emit('nodeDetailsLoaded', this.store.getNodeDetails(nodeId));
} else {
eventHub.$emit('nodeDetailsLoadFailed', nodeId, err);
}
}); });
}, },
initNodeDetailsPolling(nodeId) { repairNode(targetNode) {
this.nodePollingInterval = new SmartInterval({ this.setNodeActionStatus(targetNode, true);
callback: this.fetchNodeDetails.bind(this, nodeId), this.service.repairNode(targetNode)
startingInterval: 30000, .then(() => {
maxInterval: 120000, this.setNodeActionStatus(targetNode, false);
hiddenInterval: 240000, Flash(s__('GeoNodes|Node Authentication was successfully repaired.'), 'notice');
incrementByFactorOf: 15000, })
immediateExecution: true, .catch(() => {
}); this.setNodeActionStatus(targetNode, false);
Flash(s__('GeoNodes|Something went wrong while repairing node'));
});
},
toggleNode(targetNode) {
this.setNodeActionStatus(targetNode, true);
this.service.toggleNode(targetNode)
.then(res => res.data)
.then((node) => {
Object.assign(targetNode, { enabled: node.enabled, nodeActionActive: false });
})
.catch(() => {
this.setNodeActionStatus(targetNode, false);
Flash(s__('GeoNodes|Something went wrong while changing node status'));
});
},
removeNode(targetNode) {
this.setNodeActionStatus(targetNode, true);
this.service.removeNode(targetNode)
.then(() => {
this.store.removeNode(targetNode);
Flash(s__('GeoNodes|Node was successfully removed.'), 'notice');
})
.catch(() => {
this.setNodeActionStatus(targetNode, false);
Flash(s__('GeoNodes|Something went wrong while removing node'));
});
},
handleNodeAction() {
this.showModal = false;
if (this.targetNodeActionType === NODE_ACTIONS.TOGGLE) {
this.toggleNode(this.targetNode);
} else if (this.targetNodeActionType === NODE_ACTIONS.REMOVE) {
this.removeNode(this.targetNode);
}
},
showNodeActionModal({ actionType, node, modalKind = 'warning', modalMessage, modalActionLabel }) {
this.targetNode = node;
this.targetNodeActionType = actionType;
this.modalKind = modalKind;
this.modalMessage = modalMessage;
this.modalActionLabel = modalActionLabel;
if (actionType === NODE_ACTIONS.TOGGLE && !node.enabled) {
this.toggleNode(this.targetNode);
} else {
this.showModal = true;
}
},
hideNodeActionModal() {
this.showModal = false;
}, },
}, },
}; };
...@@ -120,5 +214,14 @@ ...@@ -120,5 +214,14 @@
> >
{{ errorMessage }} {{ errorMessage }}
</p> </p>
<modal
v-show="showModal"
:title="__('Are you sure?')"
:kind="modalKind"
:text="modalMessage"
:primary-button-label="modalActionLabel"
@cancel="hideNodeActionModal"
@submit="handleNodeAction"
/>
</div> </div>
</template> </template>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment