Skip to content

Commit 4519958

Browse files
author
Marcelo Rodrigues Da Silva Soares
committed
Merge branch 'dev' into 'master'
Dev > Master See merge request dbdev/dbaas!17
2 parents 33e6551 + 95b2eb0 commit 4519958

File tree

19 files changed

+1431
-36
lines changed

19 files changed

+1431
-36
lines changed

dbaas/drivers/mysqldb.py

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ def get_start_pty_default(self):
542542
def create_db_params_changes(self, database):
543543
from physical.models import DatabaseInfraParameter
544544

545-
parameter = self.get_max_connections_parameter()
545+
parameter = self.get_parameter(parameter_name='max_connections')
546546
value = self.get_max_connections_value(database)
547547

548548
LOG.info('Parameter {} will be set to {}'.format(parameter.name, value))
@@ -552,13 +552,27 @@ def create_db_params_changes(self, database):
552552
parameter=parameter,
553553
value=value
554554
)
555+
556+
def create_static_db_params_changes(self, database):
557+
from physical.models import DatabaseInfraParameter
558+
559+
parameter = self.get_parameter(parameter_name='innodb_buffer_pool_size')
560+
value = self.get_innodb_buffer_pool_size_value(database)
561+
562+
LOG.info('Parameter {} will be set to {}'.format(parameter.name, value))
563+
564+
DatabaseInfraParameter.update_parameter_value(
565+
databaseinfra=database.databaseinfra,
566+
parameter=parameter,
567+
value=value
568+
)
555569

556-
def get_max_connections_parameter(self):
570+
def get_parameter(self, parameter_name):
557571
from physical.models import Parameter
558572

559-
param = Parameter.objects.filter(name='max_connections').first()
573+
param = Parameter.objects.filter(name=parameter_name).first()
560574
if not param:
561-
raise ObjectDoesNotExist('Parametro max_connections nao foi encontrado')
575+
raise ObjectDoesNotExist('Parametro {} nao foi encontrado'.format(parameter_name))
562576

563577
return param
564578

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

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

591604
return int(steps_map[ram])
592605

606+
def get_innodb_buffer_pool_size_value(self, database):
607+
# TODO: duplicated on configurations.py, could be improved (?)
608+
offering = database.databaseinfra.offering
609+
ram = offering.memory_size_mb
610+
611+
# RAM -> 25% < 1GB - 60% < 16GB - 75%
612+
if ram < 1024:
613+
default = ram / 4
614+
elif ram < 8192:
615+
default = ram * 0.5
616+
elif ram == 8192:
617+
default = ram * 0.6
618+
else:
619+
default = (ram * 3) / 4
620+
621+
return int(default) * 1048576 # MB to Byte (this parameter needs to be set in bytes)
622+
623+
593624
class MySQLFOXHA(MySQL):
594625

595626
@classmethod

dbaas/drivers/replication_topologies/base.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,9 @@ def get_auto_upgrade_database_vm_offering(self):
740740
def get_configure_db_params_steps(self):
741741
raise NotImplementedError('Not implemented for topology')
742742

743+
def get_configure_static_db_params_steps(self):
744+
raise NotImplementedError('Not implemented for topology')
745+
743746
def get_start_database_vm_steps(self):
744747
return [{
745748
'Starting VM': (

dbaas/drivers/replication_topologies/mysql.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,25 @@ def get_configure_db_params_steps(self):
220220
'workflow.steps.util.database.UpdateKernelParameters',
221221
)}] + self.get_change_parameter_steps_final()
222222

223+
def get_configure_static_db_params_steps(self):
224+
return [{
225+
'Configuring Static DB Params': (
226+
'workflow.steps.util.database.CreateStaticParameterChange',
227+
'workflow.steps.util.zabbix.DisableAlarms',
228+
'workflow.steps.util.db_monitor.DisableMonitoring',
229+
'workflow.steps.util.database.checkAndFixMySQLReplication',
230+
'workflow.steps.util.vm.ChangeMaster',
231+
'workflow.steps.util.database.CheckIfSwitchMaster',
232+
'workflow.steps.util.database.Stop',
233+
'workflow.steps.util.database.CheckIsDown',
234+
'workflow.steps.util.plan.ConfigureOnlyDBConfigFile',
235+
'workflow.steps.util.database.Start',
236+
'workflow.steps.util.database.CheckIsUp',
237+
'workflow.steps.util.db_monitor.EnableMonitoring',
238+
'workflow.steps.util.zabbix.EnableAlarms',
239+
)
240+
}] + self.get_change_parameter_steps_final()
241+
223242
def get_host_migrate_steps(self):
224243
return [{
225244
'Migrating': (

dbaas/logical/templates/logical/database/details/parameters_tab.html

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,24 @@
55
<fieldset class="module aligned ">
66
<div class="panel-heading">
77
<h3 class="panel-title">Custom Parameters</h3>
8-
{% if show_auto_configure_btn %}
9-
<a href="#" data-toggle="modal" id="autoconfig_btn" data-target="#autoconfig_params" target="_blank" class="btn btn-primary">AutoConfigure DB Params</a>
10-
<em>* Atualiza somente o max_connections (MySQL) e não gera downtime!</em>
11-
{% endif %}
8+
9+
<div class="col-12">
10+
<a href="#" data-toggle="modal" id="autoconfig_btn" data-target="#autoconfig_params" target="_blank" class="btn btn-primary">
11+
AutoConfigure Dynamic Params
12+
</a>
13+
<span data-toggle="tooltip" data-placement="bottom" title="Atualiza somente o max_connections (MySQL) e não gera downtime!">
14+
<i class="fa fa-info-circle"></i>
15+
</span>
16+
17+
<a href="#" data-toggle="modal" id="autoconfig_btn" data-target="#autoconfig_static_params" target="_blank" class="btn btn-danger" style="margin-left: 3em">
18+
AutoConfigure Static Params
19+
</a>
20+
<span data-toggle="tooltip" data-placement="bottom" title="Pode gerar DOWNTIME pois reinicia a DB!">
21+
<i class="fa fa-info-circle"></i>
22+
</span>
1223
</div>
1324

25+
1426
<div class="panel-body">
1527
<table id="table-parameters" class="table table-striped table-hover" data-database-id="{{database.pk}}" >
1628
<thead>
@@ -168,14 +180,19 @@ <h3 class="panel-title">Custom Parameters</h3>
168180
{% endif %}
169181
{% 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" %}
170182

183+
{% 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" %}
184+
185+
171186
{% endblock %}
172187

173188
{% block js_footer %}
174189
{{ block.super }}
175190

176191
<script src="{% static "assets/js/bignumber.min.js" %}"></script>
177192
<script src="{% static "js/parameters_validator.js" %}"></script>
193+
<script type="text/javascript" src="{% static 'js/bootstrap-tooltip.js' %}"></script>
178194
<script type="text/javascript">
195+
179196
var database_id = '{{ database.id }}';
180197

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

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

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

290+
$("#id_autoconfig_static_params").on("click", function() {
291+
if (running_update){
292+
return;
293+
}
294+
running_update = true;
295+
$("#id_autoconfig_static_params").attr('disabled','disabled');
296+
url = "/logical/autoconfigure_static_db_params/"+ database_id;
297+
298+
jQuery.ajax({
299+
"dataType": "json",
300+
"url": url,
301+
"type": "GET"
302+
}).success(function() {
303+
running_update = false;
304+
window.location.reload();
305+
306+
}).error(function() {
307+
alert("invalid server response")
308+
});
309+
});
310+
272311
function check_static_parameter_changed()
273312
{
274313
var inputs = $("input, select");

dbaas/logical/urls.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
from django.conf.urls import patterns, url
22
from .views import refresh_status, toggle_monitoring, start_database_vm, stop_database_vm, set_attention, funct_send_all_chg
33
from .views import (CredentialView, CredentialSSLView,
4-
credential_parameter_by_name, check_offering_sizes, resize_vm_from_btn, auto_configure_db_params_btn)
4+
credential_parameter_by_name, check_offering_sizes,
5+
resize_vm_from_btn, auto_configure_db_params_btn,
6+
auto_configure_static_db_params_btn)
57

68

79
urlpatterns = patterns(
@@ -41,5 +43,8 @@
4143
name="resize_vm_from_btn"),
4244
url(r"^autoconfigure_db_params/(?P<database_id>\d*[\w\-\_]+)",
4345
auto_configure_db_params_btn,
44-
name="auto_configure_db_params_btn")
46+
name="auto_configure_db_params_btn"),
47+
url(r"^autoconfigure_static_db_params/(?P<database_id>\d*[\w\-\_]+)",
48+
auto_configure_static_db_params_btn,
49+
name="auto_configure_static_db_params_btn")
4550
)

dbaas/logical/views.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -693,17 +693,6 @@ def get_context_data(self, **kwargs):
693693
self.context['form_status'] = self.form_status
694694
self.context['last_change_parameters'] = last_change_parameters
695695

696-
user_teams = self.request.user.team_set.all()
697-
teams_names = []
698-
for team in user_teams:
699-
teams_names.append(team.name)
700-
701-
show_auto_configure_btn = False
702-
if self.request.user.is_superuser or 'dbaas' in teams_names:
703-
show_auto_configure_btn = True
704-
705-
self.context['show_auto_configure_btn'] = show_auto_configure_btn
706-
707696
return self.context
708697

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

1137-
show_resize_btns = False
1138-
if (request.user.is_superuser or 'dbaas' in teams_names) and database.can_do_autoupgrade:
1139-
show_resize_btns = True
1140-
1141-
context['show_resize_btns'] = show_resize_btns
1126+
context['show_resize_btns'] = database.can_do_autoupgrade
11421127

11431128
return render_to_response(
11441129
"logical/database/details/resizes_tab.html",
@@ -2780,3 +2765,20 @@ def auto_configure_db_params_btn(request, database_id):
27802765
)
27812766

27822767
return HttpResponse(json.dumps({}), content_type="application/json")
2768+
2769+
2770+
@login_required()
2771+
@method_decorator(csrf_exempt)
2772+
def auto_configure_static_db_params_btn(request, database_id):
2773+
database = get_object_or_404(Database, pk=database_id)
2774+
user = request.user
2775+
2776+
from notification.tasks import TaskRegister
2777+
2778+
LOG.info("Starting auto configure STATIC DB Params: database {}, user: {}".format(database, user))
2779+
2780+
TaskRegister.configure_static_db_params(
2781+
database=database, user=user
2782+
)
2783+
2784+
return HttpResponse(json.dumps({}), content_type="application/json")

dbaas/maintenance/admin/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from . database_stop_database_vm import DatabaseStopDatabaseVMAdmin
3131
from . database_auto_upgrade_vm_offering import DatabaseAutoUpgradeVMOferringAdmin
3232
from . database_configure_db_params import DatabaseConfigureDBParamsAdmin
33+
from . database_configure_static_db_params import DatabaseConfigureStaticDBParamsAdmin
3334

3435

3536
admin.site.register(models.Maintenance, MaintenanceAdmin)
@@ -84,3 +85,7 @@
8485
admin.site.register(
8586
models.DatabaseConfigureDBParams, DatabaseConfigureDBParamsAdmin
8687
)
88+
89+
admin.site.register(
90+
models.DatabaseConfigureStaticDBParams, DatabaseConfigureStaticDBParamsAdmin
91+
)
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# -*- coding: utf-8 -*-
2+
from __future__ import absolute_import, unicode_literals
3+
from django.conf.urls import patterns, url
4+
from django.contrib import messages
5+
from django.core.urlresolvers import reverse
6+
from django.http import HttpResponseRedirect
7+
from django.shortcuts import get_object_or_404
8+
from django.utils.html import format_html
9+
from .database_maintenance_task import DatabaseMaintenanceTaskAdmin
10+
from ..models import DatabaseConfigureStaticDBParams
11+
from notification.tasks import TaskRegister
12+
13+
14+
class DatabaseConfigureStaticDBParamsAdmin(DatabaseMaintenanceTaskAdmin):
15+
search_fields = (
16+
"database__name", "database__databaseinfra__name", "task__id", "task__task_id"
17+
)
18+
19+
list_display = (
20+
"database", "database_team", "current_step", "current_step_class", "friendly_status",
21+
"maintenance_action", "link_task", "started_at", "finished_at"
22+
)
23+
24+
readonly_fields = (
25+
"database", "task", "started_at",
26+
"link_task", "finished_at", "status",
27+
"maintenance_action", "task_schedule",
28+
29+
)
30+
31+
def maintenance_action(self, maintenance):
32+
if not maintenance.is_status_error:
33+
return 'N/A'
34+
35+
if not maintenance.can_do_retry:
36+
return 'N/A'
37+
38+
url = "/admin/maintenance/databaseconfigurestaticdbparams/{}/retry/".format(
39+
maintenance.id
40+
)
41+
html = ("<a title='Retry' class='btn btn-info' "
42+
"href='{}'>Retry</a>").format(url)
43+
return format_html(html)
44+
45+
def get_urls(self):
46+
base = super(DatabaseConfigureStaticDBParamsAdmin, self).get_urls()
47+
48+
admin = patterns(
49+
'',
50+
url(
51+
r'^/?(?P<configure_static_db_params_id>\d+)/retry/$',
52+
self.admin_site.admin_view(self.retry_view),
53+
name="configure_static_db_params_retry"
54+
),
55+
)
56+
return admin + base
57+
58+
def retry_view(self, request, configure_static_db_params_id):
59+
retry_from = get_object_or_404(DatabaseConfigureStaticDBParams, pk=configure_static_db_params_id)
60+
61+
error = False
62+
if not retry_from.is_status_error:
63+
error = True
64+
messages.add_message(
65+
request, messages.ERROR,
66+
"You can not do retry because configure static db params status is '{}'".format(
67+
retry_from.get_status_display()
68+
),
69+
)
70+
71+
if not retry_from.can_do_retry:
72+
error = True
73+
messages.add_message(
74+
request, messages.ERROR, "Configure Static DB Params retry is disabled"
75+
)
76+
77+
if error:
78+
return HttpResponseRedirect(
79+
reverse(
80+
'admin:maintenance_configurestaticdbparams_change',
81+
args=(configure_static_db_params_id,)
82+
)
83+
)
84+
85+
TaskRegister.configure_static_db_params(
86+
database=retry_from.database,
87+
user=request.user,
88+
retry_from=retry_from
89+
)
90+
91+
url = reverse('admin:notification_taskhistory_changelist')
92+
filters = "user={}".format(request.user.username)
93+
return HttpResponseRedirect('{}?{}'.format(url, filters))

0 commit comments

Comments
 (0)