Skip to content

Commit

Permalink
Merge branch 'dev' into 'master'
Browse files Browse the repository at this point in the history
Dev > Master

See merge request dbdev/dbaas!17
  • Loading branch information
Marcelo Rodrigues Da Silva Soares committed Jun 19, 2023
2 parents 33e6551 + 95b2eb0 commit 4519958
Show file tree
Hide file tree
Showing 19 changed files with 1,431 additions and 36 deletions.
41 changes: 36 additions & 5 deletions dbaas/drivers/mysqldb.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ def get_start_pty_default(self):
def create_db_params_changes(self, database):
from physical.models import DatabaseInfraParameter

parameter = self.get_max_connections_parameter()
parameter = self.get_parameter(parameter_name='max_connections')
value = self.get_max_connections_value(database)

LOG.info('Parameter {} will be set to {}'.format(parameter.name, value))
Expand All @@ -552,13 +552,27 @@ def create_db_params_changes(self, database):
parameter=parameter,
value=value
)

def create_static_db_params_changes(self, database):
from physical.models import DatabaseInfraParameter

parameter = self.get_parameter(parameter_name='innodb_buffer_pool_size')
value = self.get_innodb_buffer_pool_size_value(database)

LOG.info('Parameter {} will be set to {}'.format(parameter.name, value))

DatabaseInfraParameter.update_parameter_value(
databaseinfra=database.databaseinfra,
parameter=parameter,
value=value
)

def get_max_connections_parameter(self):
def get_parameter(self, parameter_name):
from physical.models import Parameter

param = Parameter.objects.filter(name='max_connections').first()
param = Parameter.objects.filter(name=parameter_name).first()
if not param:
raise ObjectDoesNotExist('Parametro max_connections nao foi encontrado')
raise ObjectDoesNotExist('Parametro {} nao foi encontrado'.format(parameter_name))

return param

Expand All @@ -572,7 +586,6 @@ def get_max_connections_value(self, database):
offering = database.databaseinfra.offering
return self.get_max_connections_value_from_steps(steps, offering)


def get_max_connections_value_from_steps(self, steps, offering):
# steps ~= "0:1000,32768:2000,65536:4000"
steps_list = steps.split(',')
Expand All @@ -590,6 +603,24 @@ def get_max_connections_value_from_steps(self, steps, offering):

return int(steps_map[ram])

def get_innodb_buffer_pool_size_value(self, database):
# TODO: duplicated on configurations.py, could be improved (?)
offering = database.databaseinfra.offering
ram = offering.memory_size_mb

# RAM -> 25% < 1GB - 60% < 16GB - 75%
if ram < 1024:
default = ram / 4
elif ram < 8192:
default = ram * 0.5
elif ram == 8192:
default = ram * 0.6
else:
default = (ram * 3) / 4

return int(default) * 1048576 # MB to Byte (this parameter needs to be set in bytes)


class MySQLFOXHA(MySQL):

@classmethod
Expand Down
3 changes: 3 additions & 0 deletions dbaas/drivers/replication_topologies/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,9 @@ def get_auto_upgrade_database_vm_offering(self):
def get_configure_db_params_steps(self):
raise NotImplementedError('Not implemented for topology')

def get_configure_static_db_params_steps(self):
raise NotImplementedError('Not implemented for topology')

def get_start_database_vm_steps(self):
return [{
'Starting VM': (
Expand Down
19 changes: 19 additions & 0 deletions dbaas/drivers/replication_topologies/mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,25 @@ def get_configure_db_params_steps(self):
'workflow.steps.util.database.UpdateKernelParameters',
)}] + self.get_change_parameter_steps_final()

def get_configure_static_db_params_steps(self):
return [{
'Configuring Static DB Params': (
'workflow.steps.util.database.CreateStaticParameterChange',
'workflow.steps.util.zabbix.DisableAlarms',
'workflow.steps.util.db_monitor.DisableMonitoring',
'workflow.steps.util.database.checkAndFixMySQLReplication',
'workflow.steps.util.vm.ChangeMaster',
'workflow.steps.util.database.CheckIfSwitchMaster',
'workflow.steps.util.database.Stop',
'workflow.steps.util.database.CheckIsDown',
'workflow.steps.util.plan.ConfigureOnlyDBConfigFile',
'workflow.steps.util.database.Start',
'workflow.steps.util.database.CheckIsUp',
'workflow.steps.util.db_monitor.EnableMonitoring',
'workflow.steps.util.zabbix.EnableAlarms',
)
}] + self.get_change_parameter_steps_final()

def get_host_migrate_steps(self):
return [{
'Migrating': (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,24 @@
<fieldset class="module aligned ">
<div class="panel-heading">
<h3 class="panel-title">Custom Parameters</h3>
{% if show_auto_configure_btn %}
<a href="#" data-toggle="modal" id="autoconfig_btn" data-target="#autoconfig_params" target="_blank" class="btn btn-primary">AutoConfigure DB Params</a>
<em>* Atualiza somente o max_connections (MySQL) e não gera downtime!</em>
{% endif %}

<div class="col-12">
<a href="#" data-toggle="modal" id="autoconfig_btn" data-target="#autoconfig_params" target="_blank" class="btn btn-primary">
AutoConfigure Dynamic Params
</a>
<span data-toggle="tooltip" data-placement="bottom" title="Atualiza somente o max_connections (MySQL) e não gera downtime!">
<i class="fa fa-info-circle"></i>
</span>

<a href="#" data-toggle="modal" id="autoconfig_btn" data-target="#autoconfig_static_params" target="_blank" class="btn btn-danger" style="margin-left: 3em">
AutoConfigure Static Params
</a>
<span data-toggle="tooltip" data-placement="bottom" title="Pode gerar DOWNTIME pois reinicia a DB!">
<i class="fa fa-info-circle"></i>
</span>
</div>


<div class="panel-body">
<table id="table-parameters" class="table table-striped table-hover" data-database-id="{{database.pk}}" >
<thead>
Expand Down Expand Up @@ -168,14 +180,19 @@ <h3 class="panel-title">Custom Parameters</h3>
{% endif %}
{% include "admin/confirmation_modal.html" with modal_id="autoconfig_params" confirmation_message="Are you sure you want to AutoConfigure database parameters now?" box_title="AutoConfigure Params" button_type="button" button_value="Auto Configure Parameters" button_name="autoconfig_params_confirm" id_optional="id=id_autoconfig_params" %}

{% include "admin/confirmation_modal.html" with modal_id="autoconfig_static_params" confirmation_message='Are you sure you want to AutoConfigure database static parameters now? <br> <u style="color: red">This will reboot the database and might lead to a temporary DOWNTIME!</u>' box_title="AutoConfigure Static Params" button_type="button" button_value="Auto Configure Parameters" button_name="autoconfig_static_params_confirm" id_optional="id=id_autoconfig_static_params" %}


{% endblock %}

{% block js_footer %}
{{ block.super }}

<script src="{% static "assets/js/bignumber.min.js" %}"></script>
<script src="{% static "js/parameters_validator.js" %}"></script>
<script type="text/javascript" src="{% static 'js/bootstrap-tooltip.js' %}"></script>
<script type="text/javascript">

var database_id = '{{ database.id }}';

function resetDefault(checkbox_control, id)
Expand Down Expand Up @@ -232,6 +249,7 @@ <h3 class="panel-title">Custom Parameters</h3>
}

jQuery(document).ready(function($) {
$('[data-toggle="tooltip"]').tooltip();

$("#id_change_parameter_yes").keyup(function() {
var btn = document.getElementById("id_change_parameter_btn_modal");
Expand Down Expand Up @@ -269,6 +287,27 @@ <h3 class="panel-title">Custom Parameters</h3>
});
});

$("#id_autoconfig_static_params").on("click", function() {
if (running_update){
return;
}
running_update = true;
$("#id_autoconfig_static_params").attr('disabled','disabled');
url = "/logical/autoconfigure_static_db_params/"+ database_id;

jQuery.ajax({
"dataType": "json",
"url": url,
"type": "GET"
}).success(function() {
running_update = false;
window.location.reload();

}).error(function() {
alert("invalid server response")
});
});

function check_static_parameter_changed()
{
var inputs = $("input, select");
Expand Down
9 changes: 7 additions & 2 deletions dbaas/logical/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from django.conf.urls import patterns, url
from .views import refresh_status, toggle_monitoring, start_database_vm, stop_database_vm, set_attention, funct_send_all_chg
from .views import (CredentialView, CredentialSSLView,
credential_parameter_by_name, check_offering_sizes, resize_vm_from_btn, auto_configure_db_params_btn)
credential_parameter_by_name, check_offering_sizes,
resize_vm_from_btn, auto_configure_db_params_btn,
auto_configure_static_db_params_btn)


urlpatterns = patterns(
Expand Down Expand Up @@ -41,5 +43,8 @@
name="resize_vm_from_btn"),
url(r"^autoconfigure_db_params/(?P<database_id>\d*[\w\-\_]+)",
auto_configure_db_params_btn,
name="auto_configure_db_params_btn")
name="auto_configure_db_params_btn"),
url(r"^autoconfigure_static_db_params/(?P<database_id>\d*[\w\-\_]+)",
auto_configure_static_db_params_btn,
name="auto_configure_static_db_params_btn")
)
34 changes: 18 additions & 16 deletions dbaas/logical/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -693,17 +693,6 @@ def get_context_data(self, **kwargs):
self.context['form_status'] = self.form_status
self.context['last_change_parameters'] = last_change_parameters

user_teams = self.request.user.team_set.all()
teams_names = []
for team in user_teams:
teams_names.append(team.name)

show_auto_configure_btn = False
if self.request.user.is_superuser or 'dbaas' in teams_names:
show_auto_configure_btn = True

self.context['show_auto_configure_btn'] = show_auto_configure_btn

return self.context

def post(self, request, *args, **kwargs):
Expand Down Expand Up @@ -1134,11 +1123,7 @@ def database_resizes(request, context, database):
for team in user_teams:
teams_names.append(team.name)

show_resize_btns = False
if (request.user.is_superuser or 'dbaas' in teams_names) and database.can_do_autoupgrade:
show_resize_btns = True

context['show_resize_btns'] = show_resize_btns
context['show_resize_btns'] = database.can_do_autoupgrade

return render_to_response(
"logical/database/details/resizes_tab.html",
Expand Down Expand Up @@ -2780,3 +2765,20 @@ def auto_configure_db_params_btn(request, database_id):
)

return HttpResponse(json.dumps({}), content_type="application/json")


@login_required()
@method_decorator(csrf_exempt)
def auto_configure_static_db_params_btn(request, database_id):
database = get_object_or_404(Database, pk=database_id)
user = request.user

from notification.tasks import TaskRegister

LOG.info("Starting auto configure STATIC DB Params: database {}, user: {}".format(database, user))

TaskRegister.configure_static_db_params(
database=database, user=user
)

return HttpResponse(json.dumps({}), content_type="application/json")
5 changes: 5 additions & 0 deletions dbaas/maintenance/admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from . database_stop_database_vm import DatabaseStopDatabaseVMAdmin
from . database_auto_upgrade_vm_offering import DatabaseAutoUpgradeVMOferringAdmin
from . database_configure_db_params import DatabaseConfigureDBParamsAdmin
from . database_configure_static_db_params import DatabaseConfigureStaticDBParamsAdmin


admin.site.register(models.Maintenance, MaintenanceAdmin)
Expand Down Expand Up @@ -84,3 +85,7 @@
admin.site.register(
models.DatabaseConfigureDBParams, DatabaseConfigureDBParamsAdmin
)

admin.site.register(
models.DatabaseConfigureStaticDBParams, DatabaseConfigureStaticDBParamsAdmin
)
93 changes: 93 additions & 0 deletions dbaas/maintenance/admin/database_configure_static_db_params.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals
from django.conf.urls import patterns, url
from django.contrib import messages
from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect
from django.shortcuts import get_object_or_404
from django.utils.html import format_html
from .database_maintenance_task import DatabaseMaintenanceTaskAdmin
from ..models import DatabaseConfigureStaticDBParams
from notification.tasks import TaskRegister


class DatabaseConfigureStaticDBParamsAdmin(DatabaseMaintenanceTaskAdmin):
search_fields = (
"database__name", "database__databaseinfra__name", "task__id", "task__task_id"
)

list_display = (
"database", "database_team", "current_step", "current_step_class", "friendly_status",
"maintenance_action", "link_task", "started_at", "finished_at"
)

readonly_fields = (
"database", "task", "started_at",
"link_task", "finished_at", "status",
"maintenance_action", "task_schedule",

)

def maintenance_action(self, maintenance):
if not maintenance.is_status_error:
return 'N/A'

if not maintenance.can_do_retry:
return 'N/A'

url = "/admin/maintenance/databaseconfigurestaticdbparams/{}/retry/".format(
maintenance.id
)
html = ("<a title='Retry' class='btn btn-info' "
"href='{}'>Retry</a>").format(url)
return format_html(html)

def get_urls(self):
base = super(DatabaseConfigureStaticDBParamsAdmin, self).get_urls()

admin = patterns(
'',
url(
r'^/?(?P<configure_static_db_params_id>\d+)/retry/$',
self.admin_site.admin_view(self.retry_view),
name="configure_static_db_params_retry"
),
)
return admin + base

def retry_view(self, request, configure_static_db_params_id):
retry_from = get_object_or_404(DatabaseConfigureStaticDBParams, pk=configure_static_db_params_id)

error = False
if not retry_from.is_status_error:
error = True
messages.add_message(
request, messages.ERROR,
"You can not do retry because configure static db params status is '{}'".format(
retry_from.get_status_display()
),
)

if not retry_from.can_do_retry:
error = True
messages.add_message(
request, messages.ERROR, "Configure Static DB Params retry is disabled"
)

if error:
return HttpResponseRedirect(
reverse(
'admin:maintenance_configurestaticdbparams_change',
args=(configure_static_db_params_id,)
)
)

TaskRegister.configure_static_db_params(
database=retry_from.database,
user=request.user,
retry_from=retry_from
)

url = reverse('admin:notification_taskhistory_changelist')
filters = "user={}".format(request.user.username)
return HttpResponseRedirect('{}?{}'.format(url, filters))

0 comments on commit 4519958

Please sign in to comment.