BSONObj MemberConfig::toBSON(const ReplicaSetTagConfig& tagConfig) const { BSONObjBuilder configBuilder; configBuilder.append("_id", _id); configBuilder.append("host", _host.toString()); configBuilder.append("arbiterOnly", _arbiterOnly); configBuilder.append("buildIndexes", _buildIndexes); configBuilder.append("hidden", _hidden); configBuilder.append("priority", _priority); BSONObjBuilder tags(configBuilder.subobjStart("tags")); for (std::vector<ReplicaSetTag>::const_iterator tag = _tags.begin(); tag != _tags.end(); tag++) { std::string tagKey = tagConfig.getTagKey(*tag); if (tagKey[0] == '$') { // Filter out internal tags continue; } tags.append(tagKey, tagConfig.getTagValue(*tag)); } tags.done(); configBuilder.append("slaveDelay", durationCount<Seconds>(_slaveDelay)); configBuilder.append("votes", getNumVotes()); return configBuilder.obj(); }
bool MemberConfig::hasTags(const ReplicaSetTagConfig& tagConfig) const { for (std::vector<ReplicaSetTag>::const_iterator tag = _tags.begin(); tag != _tags.end(); tag++) { std::string tagKey = tagConfig.getTagKey(*tag); if (tagKey[0] == '$') { // Filter out internal tags continue; } return true; } return false; }
BSONObj MemberConfig::toBSON(const ReplicaSetTagConfig& tagConfig) const { BSONObjBuilder configBuilder; configBuilder.append("_id", _id); configBuilder.append("host", _host.toString()); configBuilder.append("arbiterOnly", _arbiterOnly); configBuilder.append("buildIndexes", _buildIndexes); configBuilder.append("hidden", _hidden); configBuilder.append("priority", _priority); BSONObjBuilder tags(configBuilder.subobjStart("tags")); for (std::vector<ReplicaSetTag>::const_iterator tag = _tags.begin(); tag != _tags.end(); tag++) { tags.append(tagConfig.getTagKey(*tag), tagConfig.getTagValue(*tag)); } tags.done(); configBuilder.append("slaveDelay", _slaveDelay.total_seconds()); configBuilder.append("votes", getNumVotes()); return configBuilder.obj(); }
void MockReplicaSet::mockIsMasterCmd() { for (ReplNodeMap::iterator nodeIter = _nodeMap.begin(); nodeIter != _nodeMap.end(); ++nodeIter) { const string& hostAndPort = nodeIter->first; BSONObjBuilder builder; builder.append("setName", _setName); const MemberConfig* member = _replConfig.findMemberByHostAndPort(HostAndPort(hostAndPort)); if (!member) { builder.append("ismaster", false); builder.append("secondary", false); vector<string> hostList; builder.append("hosts", hostList); } else { const bool isPrimary = hostAndPort == getPrimary(); builder.append("ismaster", isPrimary); builder.append("secondary", !isPrimary); { // TODO: add passives & arbiters vector<string> hostList; hostList.push_back(getPrimary()); const vector<string> secondaries = getSecondaries(); for (vector<string>::const_iterator secIter = secondaries.begin(); secIter != secondaries.end(); ++secIter) { hostList.push_back(*secIter); } builder.append("hosts", hostList); } builder.append("primary", getPrimary()); if (member->isArbiter()) { builder.append("arbiterOnly", true); } if (member->getPriority() == 0 && !member->isArbiter()) { builder.append("passive", true); } if (member->getSlaveDelay().count()) { builder.appendIntOrLL("slaveDelay", durationCount<Seconds>(member->getSlaveDelay())); } if (member->isHidden()) { builder.append("hidden", true); } if (!member->shouldBuildIndexes()) { builder.append("buildIndexes", false); } const ReplicaSetTagConfig tagConfig = _replConfig.getTagConfig(); if (member->hasTags(tagConfig)) { BSONObjBuilder tagBuilder; for (MemberConfig::TagIterator tag = member->tagsBegin(); tag != member->tagsEnd(); ++tag) { std::string tagKey = tagConfig.getTagKey(*tag); if (tagKey[0] == '$') { // Filter out internal tags continue; } tagBuilder.append(tagKey, tagConfig.getTagValue(*tag)); } builder.append("tags", tagBuilder.done()); } } builder.append("me", hostAndPort); builder.append("ok", true); nodeIter->second->setCommandReply("ismaster", builder.done()); } }