]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
Merge pull request #25926 from linuxbox2/wip-rgw-lc-prefix
authorMatt Benjamin <mbenjamin@redhat.com>
Mon, 18 Feb 2019 16:15:27 +0000 (11:15 -0500)
committerGitHub <noreply@github.com>
Mon, 18 Feb 2019 16:15:27 +0000 (11:15 -0500)
rgw: lifcycle: don't reject compound rules with empty prefix

1  2 
src/rgw/rgw_lc.cc

index 8abb73a27a91da20df526c14da42b374fb38e65a,d4b558dbcf6321db1008d4872171e85724765629..cbabd41da29b23c6a8be07de25a36af71707ff13
@@@ -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<string, LCRule>(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<string, LCRule>(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;
    }