Skip to content

Commit

Permalink
rgw-admin: add option to configure redirect_zone
Browse files Browse the repository at this point in the history
Signed-off-by: Yehuda Sadeh <[email protected]>
  • Loading branch information
yehudasa committed Nov 28, 2017
1 parent 84ddc1f commit d94e9cc
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
18 changes: 15 additions & 3 deletions src/rgw/rgw_admin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ void usage()
cout << " --source-zone specify the source zone (for data sync)\n";
cout << " --default set entity (realm, zonegroup, zone) as default\n";
cout << " --read-only set zone as read-only (when adding to zonegroup)\n";
cout << " --redirect-zone specify zone id to redirect when response is 404 (not found)\n";
cout << " --placement-id placement id for zonegroup placement commands\n";
cout << " --tags=<list> list of tags for zonegroup placement add and modify commands\n";
cout << " --tags-add=<list> list of tags to add for zonegroup placement modify command\n";
Expand Down Expand Up @@ -2341,6 +2342,8 @@ int main(int argc, const char **argv)
std::string zonegroup_name, zonegroup_id, zonegroup_new_name;
std::string api_name;
std::string role_name, path, assume_role_doc, policy_name, perm_policy_doc, path_prefix;
std::string redirect_zone;
bool redirect_zone_set = false;
list<string> endpoints;
int tmp_int;
int sync_from_all_specified = false;
Expand Down Expand Up @@ -2703,6 +2706,9 @@ int main(int argc, const char **argv)
is_master_set = true;
} else if (ceph_argparse_binary_flag(args, i, &set_default, NULL, "--default", (char*)NULL)) {
/* do nothing */
} else if (ceph_argparse_witharg(args, i, &val, "--redirect-zone", (char*)NULL)) {
redirect_zone = val;
redirect_zone_set = true;
} else if (ceph_argparse_binary_flag(args, i, &read_only_int, NULL, "--read-only", (char*)NULL)) {
read_only = (bool)read_only_int;
is_read_only_set = true;
Expand Down Expand Up @@ -3470,12 +3476,14 @@ int main(int argc, const char **argv)
zone.tier_config = tier_config_add;

bool *psync_from_all = (sync_from_all_specified ? &sync_from_all : nullptr);
string *predirect_zone = (redirect_zone_set ? &redirect_zone : nullptr);

ret = zonegroup.add_zone(zone,
(is_master_set ? &is_master : NULL),
(is_read_only_set ? &read_only : NULL),
endpoints, ptier_type,
psync_from_all, sync_from, sync_from_rm);
psync_from_all, sync_from, sync_from_rm,
predirect_zone);
if (ret < 0) {
cerr << "failed to add zone " << zone_name << " to zonegroup " << zonegroup.get_name() << ": "
<< cpp_strerror(-ret) << std::endl;
Expand Down Expand Up @@ -3890,13 +3898,15 @@ int main(int argc, const char **argv)
if (!zonegroup_id.empty() || !zonegroup_name.empty()) {
string *ptier_type = (tier_type_specified ? &tier_type : nullptr);
bool *psync_from_all = (sync_from_all_specified ? &sync_from_all : nullptr);
string *predirect_zone = (redirect_zone_set ? &redirect_zone : nullptr);
ret = zonegroup.add_zone(zone,
(is_master_set ? &is_master : NULL),
(is_read_only_set ? &read_only : NULL),
endpoints,
ptier_type,
psync_from_all,
sync_from, sync_from_rm);
sync_from, sync_from_rm,
predirect_zone);
if (ret < 0) {
cerr << "failed to add zone " << zone_name << " to zonegroup " << zonegroup.get_name()
<< ": " << cpp_strerror(-ret) << std::endl;
Expand Down Expand Up @@ -4163,12 +4173,14 @@ int main(int argc, const char **argv)
string *ptier_type = (tier_type_specified ? &tier_type : nullptr);

bool *psync_from_all = (sync_from_all_specified ? &sync_from_all : nullptr);
string *predirect_zone = (redirect_zone_set ? &redirect_zone : nullptr);

ret = zonegroup.add_zone(zone,
(is_master_set ? &is_master : NULL),
(is_read_only_set ? &read_only : NULL),
endpoints, ptier_type,
psync_from_all, sync_from, sync_from_rm);
psync_from_all, sync_from, sync_from_rm,
predirect_zone);
if (ret < 0) {
cerr << "failed to update zonegroup: " << cpp_strerror(-ret) << std::endl;
return -ret;
Expand Down
7 changes: 6 additions & 1 deletion src/rgw/rgw_rados.cc
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,8 @@ int RGWZoneGroup::equals(const string& other_zonegroup) const

int RGWZoneGroup::add_zone(const RGWZoneParams& zone_params, bool *is_master, bool *read_only,
const list<string>& endpoints, const string *ptier_type,
bool *psync_from_all, list<string>& sync_from, list<string>& sync_from_rm)
bool *psync_from_all, list<string>& sync_from, list<string>& sync_from_rm,
string *predirect_zone)
{
auto& zone_id = zone_params.get_id();
auto& zone_name = zone_params.get_name();
Expand Down Expand Up @@ -400,6 +401,10 @@ int RGWZoneGroup::add_zone(const RGWZoneParams& zone_params, bool *is_master, bo
zone.sync_from_all = *psync_from_all;
}

if (predirect_zone) {
zone.redirect_zone = *predirect_zone;
}

for (auto add : sync_from) {
zone.sync_from.insert(add);
}
Expand Down
3 changes: 2 additions & 1 deletion src/rgw/rgw_rados.h
Original file line number Diff line number Diff line change
Expand Up @@ -1553,7 +1553,8 @@ struct RGWZoneGroup : public RGWSystemMetaObj {
int equals(const string& other_zonegroup) const;
int add_zone(const RGWZoneParams& zone_params, bool *is_master, bool *read_only,
const list<string>& endpoints, const string *ptier_type,
bool *psync_from_all, list<string>& sync_from, list<string>& sync_from_rm);
bool *psync_from_all, list<string>& sync_from, list<string>& sync_from_rm,
string *predirect_zone);
int remove_zone(const std::string& zone_id);
int rename_zone(const RGWZoneParams& zone_params);
rgw_pool get_pool(CephContext *cct);
Expand Down
1 change: 1 addition & 0 deletions src/test/cli/radosgw-admin/help.t
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@
--source-zone specify the source zone (for data sync)
--default set entity (realm, zonegroup, zone) as default
--read-only set zone as read-only (when adding to zonegroup)
--redirect-zone specify zone id to redirect when response is 404 (not found)
--placement-id placement id for zonegroup placement commands
--tags=<list> list of tags for zonegroup placement add and modify commands
--tags-add=<list> list of tags to add for zonegroup placement modify command
Expand Down

0 comments on commit d94e9cc

Please sign in to comment.