Skip to content

Commit 7cddce6

Browse files
authored
Merge pull request #843 from globocom/dev
dev > master
2 parents 137ff54 + 9a9ccf6 commit 7cddce6

File tree

3 files changed

+37
-24
lines changed

3 files changed

+37
-24
lines changed

dbaas/logical/static/js/migrate.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,15 @@
7070
*/
7171
migrate_database: function(database_id, new_environment_id, new_offering_id, hosts_zones) {
7272
var self = this;
73-
if (new_offering_id===0 && hosts_zones===0) {
73+
if (new_offering_id===0) {
7474
$.ajax({
7575
"url": "/admin/logical/database/" + database_id + "/migrate/",
7676
"type": "POST",
7777
"data": {
7878
"database_id": database_id,
7979
"new_environment_region": new_environment_id,
8080
"is_region_migrate": true,
81+
"hosts_zones": JSON.stringify(hosts_zones)
8182
},
8283
}).complete(function() {
8384
location.reload();

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,9 +336,14 @@ <h3>Regions</h3>
336336

337337
$("#migrate_region_btn_modal").click(function() {
338338
var $select = $("#migrate_region");
339-
window.MigrateManager.migrate_database({{database.id}}, $("#migrate_region").val(), 0, 0);
339+
var hosts_zones_region = {}
340+
$(".host-zone").each(function(id, obj) {
341+
hosts_zones_region[obj.dataset['hostId'].toString()] = obj.value;
342+
})
343+
window.MigrateManager.migrate_database({{database.id}}, $("#migrate_region").val(), 0, hosts_zones_region);
340344
});
341345

346+
342347
$("#full_rollback_migrate_stage_btn_modal").click(function() {
343348
//window.MigrateManager.full_rollback_migrate_stage({{database.id}}, 10);
344349
window.MigrateManager.full_rollback_migrate_stage({{database.id}}, {{current_stage|add:"-1"}});
@@ -366,6 +371,15 @@ <h3>Regions</h3>
366371
});
367372
$("#migrate_environment").change()
368373

374+
$("#migrate_region").on("change", function() {
375+
var $environment = $(this);
376+
control_migrate_button();
377+
load_offerings($environment.val())
378+
load_zones($environment.val());
379+
load_region($environment.val());
380+
});
381+
$("#migrate_region").change()
382+
369383
function check_offering(new_offering, old_offering, modal_id){
370384
$.ajax({
371385
url: "/logical/check_offering_sizes/",

dbaas/logical/views.py

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2302,33 +2302,31 @@ def database_migrate(request, context, database):
23022302
hp = Provider(database.infra.instances.first(), environment)
23032303
hp_zones = sorted(hp.list_zones())
23042304

2305-
if len(hp_zones) > 0:
2306-
zone = hp_zones[0]['name']
2307-
2308-
instances = database.infra.instances.all().order_by('shard', 'id')
2309-
for instance in instances:
2310-
host_id = instance.hostname.id
2311-
break
2312-
2313-
if environment not in current_offering.environments.all():
2314-
messages.add_message(
2315-
request, messages.ERROR, "There is no offering {} to {} environment".format(current_offering, environment)
2316-
)
2317-
return
2305+
hp_zones_list = []
2306+
for hp_zone in hp_zones:
2307+
hp_zones_list.append(hp_zone.get('name'))
23182308

23192309
hosts_zones = OrderedDict()
2320-
host = get_object_or_404(Host, pk=host_id)
2321-
hosts_zones[host] = zone
2310+
data = json.loads(request.POST.get('hosts_zones'))
2311+
for host_id, zone in data.items():
2312+
if zone not in hp_zones_list and database.infra.migration_stage == database.infra.NOT_STARTED:
2313+
error = "Zone {} isn't available in {} environment".format(zone, environment)
2314+
messages.add_message(request, messages.ERROR, error)
2315+
return
23222316

2323-
if not database.infra.migration_stage == database.infra.NOT_STARTED:
2324-
error = "Zone {} isn't available in {} environment".format(zone, environment)
2325-
messages.add_message(request, messages.ERROR, error)
2326-
return
2317+
host = get_object_or_404(Host, pk=host_id)
2318+
hosts_zones[host] = zone
2319+
if environment not in current_offering.environments.all():
2320+
messages.add_message(
2321+
request, messages.ERROR,
2322+
"There is no offering {} to {} environment".format(current_offering, environment)
2323+
)
2324+
return
23272325

2328-
if hosts_zones and 'gcp' in environment.name:
2329-
TaskRegister.region_migrate(database, environment, current_offering, request.user, hosts_zones, flag_region)
2330-
else:
2326+
if not hosts_zones and not ('gcp' in environment.name):
23312327
messages.add_message(request, messages.ERROR, "There is no host to migrate")
2328+
else:
2329+
TaskRegister.region_migrate(database, environment, current_offering, request.user, hosts_zones, flag_region)
23322330
return
23332331

23342332
hosts = set()

0 commit comments

Comments
 (0)