static bool parse()

in libminifi/include/sitetosite/PeersEntity.h [40:114]


  static bool parse(const std::shared_ptr<core::logging::Logger> &logger, const std::string &entity, const utils::Identifier &id, std::vector<PeerStatus> &peer_statuses) {
    try {
      rapidjson::Document root;
      rapidjson::ParseResult ok = root.Parse(entity.c_str());

      if (!ok) {
          std::stringstream ss;
          ss << "Failed to parse archive lens stack from JSON string with reason: "
             << rapidjson::GetParseError_En(ok.Code())
             << " at offset " << ok.Offset();

          throw Exception(ExceptionType::GENERAL_EXCEPTION, ss.str());
      }

      if (root.HasMember("peers") && root["peers"].IsArray() && root["peers"].Size() > 0) {
        for (const auto &peer : root["peers"].GetArray()) {
          std::string hostname;
          int port = 0, flowFileCount = 0;
          bool secure = false;

          if (peer.HasMember("hostname") && peer["hostname"].IsString() &&
              peer.HasMember("port") && peer["port"].IsNumber()) {
            hostname = peer["hostname"].GetString();
            port = peer["port"].GetInt();
          }

          if (peer.HasMember("secure")) {
            if (peer["secure"].IsBool()) {
              secure = peer["secure"].GetBool();
            } else if (peer["secure"].IsString()) {
              std::string secureStr = peer["secure"].GetString();

              if (utils::string::equalsIgnoreCase(secureStr, "true")) {
                secure = true;
              } else if (utils::string::equalsIgnoreCase(secureStr, "false")) {
                secure = false;
              } else {
                const auto err = utils::string::join_pack("could not parse secure string ", secureStr);
                logger->log_error("{}", err);
                throw std::logic_error{err};
              }
            } else {
              logger->log_warn("Invalid value type for secure, assuming false (rapidjson type id {})",
                  magic_enum::enum_underlying(peer["secure"].GetType()));
            }
          }

          if (peer.HasMember("flowFileCount")) {
            if (peer["flowFileCount"].IsNumber()) {
              flowFileCount = gsl::narrow<int>(peer["flowFileCount"].GetInt64());
            } else {
              logger->log_debug("Could not parse flowFileCount, so we're going to continue without it");
            }
          }

          // host name and port are required.
          if (!IsNullOrEmpty(hostname) && port > 0) {
            sitetosite::PeerStatus status(std::make_shared<sitetosite::Peer>(id, hostname, port, secure), flowFileCount, true);
            peer_statuses.push_back(std::move(status));
          } else {
            logger->log_debug("hostname empty or port is zero. hostname: {}, port: {}", hostname, port);
          }
        }
      } else {
        logger->log_debug("Peers is either not a member or is empty. String to analyze: {}", entity);
      }
      return true;
    } catch (Exception &exception) {
      logger->log_debug("Caught Exception {}", exception.what());
      return false;
    } catch (...) {
      logger->log_debug("General exception occurred");
      return false;
    }
  }