From: Matt Benjamin Date: Mon, 18 Feb 2019 16:15:27 +0000 (-0500) Subject: Merge pull request #25926 from linuxbox2/wip-rgw-lc-prefix X-Git-Tag: v14.1.0~75 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=e87113afa125f61f19949f2776f7edcd24e099b1;p=ceph.git Merge pull request #25926 from linuxbox2/wip-rgw-lc-prefix rgw: lifcycle: don't reject compound rules with empty prefix --- e87113afa125f61f19949f2776f7edcd24e099b1 diff --cc src/rgw/rgw_lc.cc index 8abb73a27a91,d4b558dbcf63..cbabd41da29b --- a/src/rgw/rgw_lc.cc +++ b/src/rgw/rgw_lc.cc @@@ -76,66 -55,58 +76,72 @@@ void LCRule::init_simple_days_rule(std: set_enabled(true); } -void RGWLifecycleConfiguration::add_rule(LCRule *rule) +void RGWLifecycleConfiguration::add_rule(const LCRule& rule) { - string id; - rule->get_id(id); // note that this will return false for groups, but that's ok, we won't search groups - rule_map.insert(pair(id, *rule)); + auto& id = rule.get_id(); // note that this will return false for groups, but that's ok, we won't search groups + rule_map.insert(pair(id, rule)); } -bool RGWLifecycleConfiguration::_add_rule(LCRule *rule) +bool RGWLifecycleConfiguration::_add_rule(const LCRule& rule) { lc_op op; - op.status = rule->is_enabled(); - if (rule->get_expiration().has_days()) { - op.expiration = rule->get_expiration().get_days(); + op.status = rule.is_enabled(); + if (rule.get_expiration().has_days()) { + op.expiration = rule.get_expiration().get_days(); } - if (rule->get_expiration().has_date()) { - op.expiration_date = ceph::from_iso_8601(rule->get_expiration().get_date()); + if (rule.get_expiration().has_date()) { + op.expiration_date = ceph::from_iso_8601(rule.get_expiration().get_date()); } - if (rule->get_noncur_expiration().has_days()) { - op.noncur_expiration = rule->get_noncur_expiration().get_days(); + if (rule.get_noncur_expiration().has_days()) { + op.noncur_expiration = rule.get_noncur_expiration().get_days(); } - if (rule->get_mp_expiration().has_days()) { - op.mp_expiration = rule->get_mp_expiration().get_days(); + if (rule.get_mp_expiration().has_days()) { + op.mp_expiration = rule.get_mp_expiration().get_days(); + } + op.dm_expiration = rule.get_dm_expiration(); + for (const auto &elem : rule.get_transitions()) { + transition_action action; + if (elem.second.has_days()) { + action.days = elem.second.get_days(); + } else { + action.date = ceph::from_iso_8601(elem.second.get_date()); + } + action.storage_class = rgw_placement_rule::get_canonical_storage_class(elem.first); + op.transitions.emplace(elem.first, std::move(action)); + } + for (const auto &elem : rule.get_noncur_transitions()) { + transition_action action; + action.days = elem.second.get_days(); + action.date = ceph::from_iso_8601(elem.second.get_date()); + action.storage_class = elem.first; + op.noncur_transitions.emplace(elem.first, std::move(action)); } - op.dm_expiration = rule->get_dm_expiration(); - std::string prefix; - if (rule->get_filter().has_prefix()){ - prefix = rule->get_filter().get_prefix(); + if (rule.get_filter().has_prefix()){ + prefix = rule.get_filter().get_prefix(); } else { - prefix = rule->get_prefix(); + prefix = rule.get_prefix(); } - if (rule->get_filter().has_tags()){ - op.obj_tags = rule->get_filter().get_tags(); + if (rule.get_filter().has_tags()){ + op.obj_tags = rule.get_filter().get_tags(); } - auto ret = prefix_map.emplace(std::move(prefix), std::move(op)); - return ret.second; + + /* prefix is optional, update prefix map only if prefix...exists */ + if (!prefix.empty()) { + auto ret = prefix_map.emplace(std::move(prefix), std::move(op)); + return ret.second; + } + + return true; } -int RGWLifecycleConfiguration::check_and_add_rule(LCRule *rule) +int RGWLifecycleConfiguration::check_and_add_rule(const LCRule& rule) { - if (!rule->valid()) { + if (!rule.valid()) { return -EINVAL; } - string id; - rule->get_id(id); + auto& id = rule.get_id(); if (rule_map.find(id) != rule_map.end()) { //id shouldn't be the same return -EINVAL; }