OPT_PERIOD_PULL,
OPT_PERIOD_PUSH,
OPT_PERIOD_LIST,
+ OPT_PERIOD_UPDATE,
};
static int get_cmd(const char *cmd, const char *prev_cmd, const char *prev_prev_cmd, bool *need_more)
return OPT_PERIOD_PUSH;
if (strcmp(cmd, "list") == 0)
return OPT_PERIOD_LIST;
+ if (strcmp(cmd, "update") == 0)
+ return OPT_PERIOD_UPDATE;
} else if (strcmp(prev_cmd, "realm") == 0) {
if (strcmp(cmd, "create") == 0)
return 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 ||
+ opt_cmd == OPT_PERIOD_UPDATE ||
opt_cmd == OPT_REALM_DELETE || opt_cmd == OPT_REALM_GET || opt_cmd == OPT_REALM_LIST ||
opt_cmd == OPT_REALM_LIST_PERIODS ||
opt_cmd == OPT_REALM_GET_DEFAULT || opt_cmd == OPT_REALM_REMOVE ||
cout << std::endl;
}
break;
+ case OPT_PERIOD_UPDATE:
+ {
+ RGWRealm realm(realm_id, realm_name);
+ int ret = realm.init(g_ceph_context, store);
+ if (ret < 0 ) {
+ cerr << "Error initializing realm " << cpp_strerror(-ret) << std::endl;
+ return ret;
+ }
+ RGWPeriod period(realm.get_current_period(), 0);
+ ret = period.init(g_ceph_context, store, realm.get_id(), realm.get_name());
+ if (ret < 0) {
+ cerr << "period init failed: " << cpp_strerror(-ret) << std::endl;
+ return -ret;
+ }
+ period.fork();
+ period.update();
+ period.store_info(false);
+ }
+ break;
case OPT_REALM_CREATE:
{
if (realm_name.empty()) {
int RGWPeriod::add_zonegroup(const RGWZoneGroup& zonegroup)
{
+ if (zonegroup.realm_id != realm_id) {
+ return 0;
+ }
int ret = period_map.update(zonegroup);
if (ret < 0) {
ldout(cct, 0) << "ERROR: updating period map: " << cpp_strerror(-ret) << dendl;
return store_info(false);
}
+int RGWPeriod::update()
+{
+ list<string> zonegroups;
+ int ret = store->list_zonegroups(zonegroups);
+ if (ret < 0) {
+ ldout(cct, 0) << "ERROR: failed to list zonegroups: " << cpp_strerror(-ret) << dendl;
+ return ret;
+ }
+
+ for (auto iter : zonegroups) {
+ RGWZoneGroup zg(string(), iter);
+cerr << __FILE__ << ":" << __LINE__ << " iter=" << iter << std::endl;
+ ret = zg.init(cct, store);
+ if (ret < 0) {
+ ldout(cct, 0) << "WARNING: zg.init() failed: " << cpp_strerror(-ret) << dendl;
+ continue;
+ }
+
+ if (zg.realm_id != realm_id) {
+ ldout(cct, 20) << "skippinh zonegroup " << zg.get_name() << ", not on our realm" << dendl;
+ continue;
+ }
+
+ int ret = period_map.update(zg);
+ if (ret < 0) {
+ ldout(cct, 0) << "ERROR: updating period map: " << cpp_strerror(-ret) << dendl;
+ return ret;
+ }
+ }
+
+ return 0;
+}
+
+void RGWPeriod::fork()
+{
+ epoch = 1;
+ id = realm_id + ":staging";
+ period_map.reset();
+}
+
int RGWZoneParams::create_default(bool old_format)
{
name = default_zone_name;
void dump(Formatter *f) const;
void decode_json(JSONObj *obj);
+
+ void reset() {
+ zonegroups.clear();
+ zonegroups_by_api.clear();
+ }
};
WRITE_CLASS_ENCODER(RGWPeriodMap)
int store_info(bool exclusive);
int add_zonegroup(const RGWZoneGroup& zonegroup);
+ void fork();
+ int update();
+
void encode(bufferlist& bl) const {
ENCODE_START(1, 1, bl);
::encode(id, bl);