Skip to content

Commit

Permalink
TESTING NOTIF REMOVE
Browse files Browse the repository at this point in the history
Signed-off-by: Ali Masarwa <ali.saed.masarwa@gmail.com>
  • Loading branch information
AliMasarweh committed May 11, 2023
1 parent cc91a21 commit 77e6190
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 4 deletions.
27 changes: 26 additions & 1 deletion src/rgw/rgw_admin.cc
Expand Up @@ -10526,7 +10526,7 @@ int main(int argc, const char **argv)
formatter->flush(cout);
}

if (opt_cmd == OPT::PUBSUB_TOPIC_RM || opt_cmd == OPT::PUBSUB_NOTIFICATION_RM) {
if (opt_cmd == OPT::PUBSUB_TOPIC_RM) {
if (topic_name.empty()) {
cerr << "ERROR: topic name was not provided (via --topic)" << std::endl;
return EINVAL;
Expand All @@ -10541,6 +10541,31 @@ int main(int argc, const char **argv)
}
}

if (opt_cmd == OPT::PUBSUB_NOTIFICATION_RM) {
int ret = init_bucket(user.get(), tenant, bucket_name, bucket_id, &bucket);
if (ret < 0) {
cerr << "ERROR: could not init bucket: " << cpp_strerror(-ret) << std::endl;
return -ret;
}

RGWPubSub ps(driver, tenant);

rgw_pubsub_bucket_topics bucket_topics;
const RGWPubSub::Bucket b(ps, bucket.get());
ret = b.get_topics(dpp(), bucket_topics, null_yield);
if (ret < 0 && ret != -ENOENT) {
cerr << "ERROR: could not get bucket notifications: " << cpp_strerror(-ret) << std::endl;
return -ret;
}

rgw_pubsub_topic_filter bucket_topic;
if(notification_id.empty()) {
ret = b.remove_notifications(dpp(), null_yield);
} else {
ret = b.remove_notification_by_id(dpp(), notification_id, null_yield);
}
}

if (opt_cmd == OPT::SCRIPT_PUT) {
if (!str_script_ctx) {
cerr << "ERROR: context was not provided (via --context)" << std::endl;
Expand Down
26 changes: 24 additions & 2 deletions src/rgw/rgw_pubsub.cc
Expand Up @@ -533,7 +533,7 @@ int RGWPubSub::Bucket::get_notification_by_id(const DoutPrefixProvider *dpp, con

auto iter = find_unique_topic(bucket_topics, notification_id);
if (!iter) {
ldpp_dout(dpp, 1) << "ERROR: notification-id={" << notification_id << "} not found" << dendl;
ldpp_dout(dpp, 1) << "ERROR: notification was not found" << dendl;
return -ENOENT;
}

Expand Down Expand Up @@ -590,6 +590,12 @@ int RGWPubSub::Bucket::create_notification(const DoutPrefixProvider *dpp, const
}

int RGWPubSub::Bucket::remove_notification(const DoutPrefixProvider *dpp, const std::string& topic_name, optional_yield y) const
{
return remove_notification_inner(dpp, topic_name, false, y);
}

int RGWPubSub::Bucket::remove_notification_inner(const DoutPrefixProvider *dpp, const std::string& notification_id,
bool is_notification_id, optional_yield y) const
{
RGWObjVersionTracker objv_tracker;
rgw_pubsub_bucket_topics bucket_topics;
Expand All @@ -600,7 +606,18 @@ int RGWPubSub::Bucket::remove_notification(const DoutPrefixProvider *dpp, const
return ret;
}

if (bucket_topics.topics.erase(topic_name) == 0) {

std::unique_ptr<std::string> topic_name = std::make_unique<std::string>(notification_id);
if(is_notification_id) {
auto iter = find_unique_topic(bucket_topics, notification_id);
if (!iter) {
ldpp_dout(dpp, 1) << "ERROR: notification was not found" << dendl;
return -ENOENT;
}
topic_name = std::make_unique<std::string>(iter->get().topic.name);
}

if (bucket_topics.topics.erase(*topic_name) == 0) {
ldpp_dout(dpp, 1) << "INFO: no need to remove, topic does not exist" << dendl;
return 0;
}
Expand All @@ -625,6 +642,11 @@ int RGWPubSub::Bucket::remove_notification(const DoutPrefixProvider *dpp, const
return 0;
}

int RGWPubSub::Bucket::remove_notification_by_id(const DoutPrefixProvider *dpp, const std::string& notif_id, optional_yield y) const
{
return remove_notification_inner(dpp, notif_id, true, y);
}

int RGWPubSub::Bucket::remove_notifications(const DoutPrefixProvider *dpp, optional_yield y) const
{
// get all topics on a bucket
Expand Down
5 changes: 4 additions & 1 deletion src/rgw/rgw_pubsub.h
Expand Up @@ -566,6 +566,8 @@ class RGWPubSub
// return 0 on success, error code otherwise
int write_topics(const DoutPrefixProvider *dpp, const rgw_pubsub_bucket_topics& topics,
RGWObjVersionTracker* objv_tracker, optional_yield y) const;
int remove_notification_inner(const DoutPrefixProvider *dpp, const std::string& notification_id,
bool notif_id_or_topic, optional_yield y) const;
public:
Bucket(const RGWPubSub& _ps, rgw::sal::Bucket* _bucket) :
ps(_ps), bucket(_bucket)
Expand All @@ -592,8 +594,9 @@ class RGWPubSub
const rgw::notify::EventTypeList& events, OptionalFilter s3_filter, const std::string& notif_name, optional_yield y) const;
// remove a topic and filter from bucket
// if the topic does not exists on the bucket it is a no-op (considered success)
// return -ENOENT if the topic does not exists
// return -ENOENT if the notification-id/topic does not exists
// return 0 on success, error code otherwise
int remove_notification_by_id(const DoutPrefixProvider *dpp, const std::string& notif_id, optional_yield y) const;
int remove_notification(const DoutPrefixProvider *dpp, const std::string& topic_name, optional_yield y) const;
// remove all notifications (and autogenerated topics) associated with the bucket
// return 0 on success or if no topic was associated with the bucket, error code otherwise
Expand Down

0 comments on commit 77e6190

Please sign in to comment.