Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0


## [Unreleased]
### Fixed
- [SYSTEM] [CLUSTER] Wrongly displayed error on Mongodb step down


## [2.27.1] - 2025-06-13
Expand Down
30 changes: 23 additions & 7 deletions vulture_os/system/cluster/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,29 @@
__doc__ = 'Cluster View'


from django.http import (HttpResponseForbidden, HttpResponseRedirect, JsonResponse, HttpResponseBadRequest)
# Django system imports
from django.conf import settings
from system.cluster.form import NodeForm
from toolkit.mongodb.mongo_base import MongoBase
from django.http import (HttpResponseForbidden, HttpResponseRedirect, JsonResponse, HttpResponseBadRequest)
from django.shortcuts import render
from django.utils.translation import gettext_lazy as _

# Django project imports
from gui.forms.form_utils import DivErrorList
from services.pf.pf import PFService
from system.cluster.form import NodeForm
from system.cluster.models import Cluster, Node
from gui.forms.form_utils import DivErrorList
from django.utils.translation import gettext_lazy as _
from toolkit.api.responses import build_response
from toolkit.mongodb.mongo_base import MongoBase

# Required exceptions imports
from django.core.exceptions import ObjectDoesNotExist

# Extern modules imports
from time import sleep

import logging
logging.config.dictConfig(settings.LOG_SETTINGS)
logger = logging.getLogger('system')

def cluster_stepdown(request, object_id, api=False):
"""
Expand Down Expand Up @@ -67,9 +77,15 @@ def cluster_stepdown(request, object_id, api=False):

status, message = c.repl_set_step_down() # Automagically connect to the primary node

c = MongoBase()
c.connect()
if message.get("ok"):
message['operationTime'] = message['operationTime'].as_datetime().isoformat()
message.pop('$clusterTime')

while not c.get_primary():
logger.debug("Waiting for primary to be elected")
sleep(2)

sleep(10)
return JsonResponse({'status': status, 'message': message})


Expand Down
24 changes: 20 additions & 4 deletions vulture_os/system/templates/system/cluster.html
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ <h4 class="modal-title">{% translate "Cluster configuration" %}</h4>

/* REPL Step DOWN */
$(nRow).find("#stepdown").on("click", function(e) {
ProcessQueueCanRedraw = false;
datatableCanRedraw = false;
e.stopPropagation();

$('#node_msg').html('<i class="fas fa-spinner fa-spin"></i>{% translate "Please wait ..." %}');
Expand All @@ -220,12 +222,26 @@ <h4 class="modal-title">{% translate "Cluster configuration" %}</h4>
type : "GET",
url : url,
}).fail( function( jqXHR, textStatus ) {
$('#node_msg').html("<b style='color:red;'>{% translate 'Failure: '%}" + textStatus + "</b></br>" +
"Status code : " + jqXHR.status + "</br>" +
"Message : " + jqXHR.responseJSON.error);
if (jqXHR.responseJSON) {
$('#node_msg').html("<b style='color:red;'>{% translate 'Failure: '%}" + textStatus + "</b></br>" +
"Status code : " + jqXHR.status + "</br>" +
"Message : " + jqXHR.responseJSON.error);
} else if (jqXHR.status === 400) { // connection dropped due to mongodb disconnect
$('#node_msg').html("<b style='color:green;'>{% translate 'Success: '%}</b><br>" +
"node " + id + " stepped down");
} else {
$('#node_msg').html("<b style='color:red;'>{% translate 'Failure: '%}" + textStatus + "</b></br>" +
"Status code : " + jqXHR.status + "</br>" +
"Message : " + jqXHR.statusText);
}
ProcessQueueCanRedraw = true;
datatableCanRedraw = true;
}).done( function( msg ) {
$('#node_msg').html("<b style='color:green;'>{% translate 'Success: '%}</b><br>" +
"node " + id + " stepped down" );
"node " + id + " stepped down" + "</br>" +
"output: " + JSON.stringify(msg.message));
ProcessQueueCanRedraw = true;
datatableCanRedraw = true;
});
});

Expand Down