From 9954bb5c396585add2b85a37bbf0312d6583f229 Mon Sep 17 00:00:00 2001 From: Orit Wasserman Date: Wed, 14 Oct 2015 15:00:06 +0200 Subject: [PATCH] rgw: add zone modify command to change master zone Signed-off-by: Orit Wasserman --- src/rgw/rgw_admin.cc | 61 +++++++++++++++++++++++++++++++++++++++++++- src/rgw/rgw_rados.cc | 4 ++- 2 files changed, 63 insertions(+), 2 deletions(-) diff --git a/src/rgw/rgw_admin.cc b/src/rgw/rgw_admin.cc index 86924ea1eac33..fb404910ae090 100644 --- a/src/rgw/rgw_admin.cc +++ b/src/rgw/rgw_admin.cc @@ -106,6 +106,7 @@ void _usage() cerr << " zone add add a zone to a zonegroup\n"; cerr << " zone create create a new zone\n"; cerr << " zone get show zone cluster params\n"; + cerr << " zone modify set/clear zone master status\n"; cerr << " zone set set zone cluster params (requires infile)\n"; cerr << " zone list list all zones set on this cluster\n"; cerr << " pool add add an existing pool for data placement\n"; @@ -307,6 +308,7 @@ enum { OPT_ZONE_CREATE, OPT_ZONE_DELETE, OPT_ZONE_GET, + OPT_ZONE_MODIFY, OPT_ZONE_SET, OPT_ZONE_LIST, OPT_ZONE_RENAME, @@ -599,6 +601,8 @@ static int get_cmd(const char *cmd, const char *prev_cmd, const char *prev_prev_ return OPT_ZONE_SET; if (strcmp(cmd, "list") == 0) return OPT_ZONE_LIST; + if (strcmp(cmd, "modify") == 0) + return OPT_ZONE_MODIFY; if (strcmp(cmd, "rename") == 0) return OPT_ZONE_RENAME; } else if (strcmp(prev_cmd, "zones") == 0) { @@ -1783,7 +1787,8 @@ int main(int argc, char **argv) opt_cmd == OPT_ZONEGROUPMAP_UPDATE || opt_cmd == OPT_ZONE_ADD || opt_cmd == OPT_ZONE_CREATE || opt_cmd == OPT_ZONE_DELETE || opt_cmd == OPT_ZONE_GET || opt_cmd == OPT_ZONE_SET || opt_cmd == OPT_ZONE_RENAME || - opt_cmd == OPT_ZONE_LIST || opt_cmd == OPT_REALM_CREATE || + opt_cmd == OPT_ZONE_LIST || opt_cmd == OPT_ZONE_MODIFY || + opt_cmd == OPT_REALM_CREATE || opt_cmd == OPT_PERIOD_PREPARE || opt_cmd == OPT_PERIOD_ACTIVATE || opt_cmd == OPT_PERIOD_DELETE || opt_cmd == OPT_PERIOD_GET || opt_cmd == OPT_PERIOD_GET_CURRENT || opt_cmd == OPT_PERIOD_LIST || @@ -2821,6 +2826,60 @@ int main(int argc, char **argv) cout << std::endl; } break; + case OPT_ZONE_MODIFY: + { + RGWZoneParams zone(zone_id, zone_name); + int ret = zone.init(g_ceph_context, store); + if (ret < 0) { + cerr << "failed to init zone: " << cpp_strerror(-ret) << std::endl; + return -ret; + } + + RGWRealm realm(realm_id, realm_name); + ret = realm.init(g_ceph_context, store); + if (ret < 0) { + cerr << "failed to init realm: " << cpp_strerror(-ret) << std::endl; + return -ret; + } + + RGWZoneGroup zonegroup(zonegroup_id, zonegroup_name); + ret = zonegroup.init(g_ceph_context, store); + if (ret < 0) { + cerr << "failed to init zonegroup: " << cpp_strerror(-ret) << std::endl; + return -ret; + } + + ret = zonegroup.add_zone(zone, is_master); + if (ret < 0) { + cerr << "failed to update zonegroup: " << cpp_strerror(-ret) << std::endl; + return -ret; + } + + ret = zonegroup.update(); + if (ret < 0) { + cerr << "failed to update zonegroup: " << cpp_strerror(-ret) << std::endl; + return -ret; + } + + RGWZoneGroupMap zonegroup_map; + ret = zonegroup_map.read(g_ceph_context, store); + if (ret < 0 && ret != -ENOENT) { + cerr << "ERROR: couldn't read zonegroup_map: " << cpp_strerror(-ret) << std::endl; + return ret; + } + + ret = zonegroup_map.update(g_ceph_context, store, realm, zonegroup); + if (ret < 0) { + cerr << "failed to update master zonegroup: " << cpp_strerror(-ret) << std::endl; + return -ret; + } + ret = zonegroup_map.store(g_ceph_context, store); + if (ret < 0) { + cerr << "failed to store zonegroup_map: " << cpp_strerror(-ret) << std::endl; + return -ret; + } + } + break; case OPT_ZONE_RENAME: { RGWZoneGroup zonegroup(zonegroup_id,zonegroup_name); diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc index fc93afbce356a..ddce9d660b9e3 100644 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@ -232,12 +232,14 @@ int RGWZoneGroup::equals(const string& other_zonegroup) const int RGWZoneGroup::add_zone(const RGWZoneParams& zone_params, bool is_master) { if (is_master) { - if (!master_zone.empty()) { + if (!master_zone.empty() && master_zone != zone_params.get_id()) { lderr(cct) << "Master zone already defined " << master_zone << " cannot add zone " << zone_params.get_id() << dendl; return -EINVAL; } master_zone = zone_params.get_id(); + } else if (master_zone == zone_params.get_id()) { + master_zone =""; } RGWZone& zone = zones[zone_params.get_id()]; -- 2.39.5