Github user kevdoran commented on a diff in the pull request:

    https://github.com/apache/nifi-minifi-cpp/pull/114#discussion_r126173718
  
    --- Diff: libminifi/src/RemoteProcessorGroupPort.cpp ---
    @@ -150,6 +194,87 @@ void 
RemoteProcessorGroupPort::onTrigger(core::ProcessContext *context, core::Pr
       return;
     }
     
    +void RemoteProcessorGroupPort::refreshRemoteSite2SiteInfo() {
    +  if (this->host_.empty() || this->port_ == -1 || this->protocol_.empty())
    +      return;
    +
    +  std::string fullUrl = this->protocol_ + this->host_ + ":" + 
std::to_string(this->port_) + "/nifi-api/controller/";
    +
    +  this->site2site_port_ = -1;
    +  CURL *http_session = curl_easy_init();
    +
    +  curl_easy_setopt(http_session, CURLOPT_URL, fullUrl.c_str());
    +
    +  utils::HTTPRequestResponse content;
    +  curl_easy_setopt(http_session, CURLOPT_WRITEFUNCTION,
    +      &utils::HTTPRequestResponse::recieve_write);
    +
    +  curl_easy_setopt(http_session, CURLOPT_WRITEDATA,
    +      static_cast<void*>(&content));
    +
    +  CURLcode res = curl_easy_perform(http_session);
    +
    +  if (res == CURLE_OK) {
    +    std::string response_body(content.data.begin(), content.data.end());
    +    int64_t http_code = 0;
    +    curl_easy_getinfo(http_session, CURLINFO_RESPONSE_CODE, &http_code);
    +    char *content_type;
    +    /* ask for the content-type */
    +    curl_easy_getinfo(http_session, CURLINFO_CONTENT_TYPE, &content_type);
    +
    +    bool isSuccess = ((int32_t) (http_code / 100)) == 2
    +        && res != CURLE_ABORTED_BY_CALLBACK;
    +    bool body_empty = IsNullOrEmpty(content.data);
    +
    +    if (isSuccess && !body_empty) {
    +      std::string controller = std::move(response_body);
    +      logger_->log_debug("controller config %s", controller.c_str());
    +      Json::Value value;
    +      Json::Reader reader;
    +      bool parsingSuccessful = reader.parse(controller, value);
    +      if (parsingSuccessful && !value.empty()) {
    +        Json::Value controllerValue = value["controller"];
    +        if (!controllerValue.empty()) {
    +          Json::Value port = controllerValue["remoteSiteListeningPort"];
    +          if (!port.empty())
    +            this->site2site_port_ = port.asInt();
    +          Json::Value secure = controllerValue["siteToSiteSecure"];
    +          if (!secure.empty())
    +            this->site2site_secure_ = secure.asBool();
    +        }
    +        logger_->log_info("process group remote site2site port %d, is 
secure %d", site2site_port_, site2site_secure_);
    +      }
    +    } else {
    +      logger_->log_error("Cannot output body to content for 
ProcessGroup::refreshRemoteSite2SiteInfo");
    +    }
    +  } else {
    +    logger_->log_error(
    +        "ProcessGroup::refreshRemoteSite2SiteInfo -- curl_easy_perform() 
failed %s\n",
    +        curl_easy_strerror(res));
    +  }
    +  curl_easy_cleanup(http_session);
    +}
    +
    +void RemoteProcessorGroupPort::refreshPeerList() {
    +  refreshRemoteSite2SiteInfo();
    +  if (site2site_port_ == -1)
    +    return;
    +
    +  this->site2site_peer_status_list_.clear();
    --- End diff --
    
    Can the logic below this fail under certain conditions? If so, is it work 
waiting to clear the current list until we are sure we have an updated list?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to