You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by al...@apache.org on 2018/11/06 18:29:02 UTC
nifi-minifi-cpp git commit: MINIFICPP-664: Require C2 agent class to
be defined
Repository: nifi-minifi-cpp
Updated Branches:
refs/heads/master 23c5c197a -> 1f2e60061
MINIFICPP-664: Require C2 agent class to be defined
This closes #434.
Signed-off-by: Aldrin Piri <al...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/repo
Commit: http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/commit/1f2e6006
Tree: http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/tree/1f2e6006
Diff: http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/diff/1f2e6006
Branch: refs/heads/master
Commit: 1f2e600614d8a85c3abf9ea621a8f6c27793ccd7
Parents: 23c5c19
Author: Marc Parisi <ph...@apache.org>
Authored: Tue Nov 6 11:17:31 2018 -0500
Committer: Aldrin Piri <al...@apache.org>
Committed: Tue Nov 6 13:28:35 2018 -0500
----------------------------------------------------------------------
C2.md | 2 +-
OPS.md | 3 +-
conf/minifi.properties | 5 +--
.../http-curl/tests/C2FailedUpdateTest.cpp | 2 ++
.../http-curl/tests/C2NullConfiguration.cpp | 3 +-
.../http-curl/tests/C2UpdateAgentTest.cpp | 4 ++-
extensions/http-curl/tests/C2UpdateTest.cpp | 4 ++-
.../tests/C2VerifyHeartbeatAndStop.cpp | 2 ++
.../http-curl/tests/C2VerifyServeResults.cpp | 10 +++---
libminifi/src/FlowController.cpp | 34 ++++++++++++++------
10 files changed, 46 insertions(+), 23 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/1f2e6006/C2.md
----------------------------------------------------------------------
diff --git a/C2.md b/C2.md
index fdd12b8..c6c1572 100644
--- a/C2.md
+++ b/C2.md
@@ -76,7 +76,7 @@ an alternate key, but you are encouraged to switch your configuration options as
# c2 agent identifier
nifi.c2.agent.identifier=<your identifier>
- # c2 agent class
+ # c2 agent class -- must be defined to run agent
nifi.c2.agent.class=<your agent class>
# configure SSL Context service for REST Protocol
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/1f2e6006/OPS.md
----------------------------------------------------------------------
diff --git a/OPS.md b/OPS.md
index c993785..923de64 100644
--- a/OPS.md
+++ b/OPS.md
@@ -27,7 +27,8 @@ This readme defines operational commands for managing instances.
## Description
Apache NiFi MiNiFi C++ can be managed through our [C2 protocol](https://cwiki.apache.org/confluence/display/MINIFI/C2+Design+Proposal)
-or through a local interface called the MiNiFi Controller
+or through a local interface called the MiNiFi Controller. This feature is disabled by default, and requires that C2 be enabled
+and configured with an agent class before using the MiNiFi controller features outlined here.
## Managing MiNiFi
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/1f2e6006/conf/minifi.properties
----------------------------------------------------------------------
diff --git a/conf/minifi.properties b/conf/minifi.properties
index b32708b..568669a 100644
--- a/conf/minifi.properties
+++ b/conf/minifi.properties
@@ -38,5 +38,6 @@ nifi.database.content.repository.directory.default=${MINIFI_HOME}/content_reposi
#nifi.rest.api.password=password
## enable the controller socket provider on port 9998
-controller.socket.host=localhost
-controller.socket.port=9998
+## off by default. C2 must be enabled to support these
+#controller.socket.host=localhost
+#controller.socket.port=9998
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/1f2e6006/extensions/http-curl/tests/C2FailedUpdateTest.cpp
----------------------------------------------------------------------
diff --git a/extensions/http-curl/tests/C2FailedUpdateTest.cpp b/extensions/http-curl/tests/C2FailedUpdateTest.cpp
index fc3e79a..904d931 100644
--- a/extensions/http-curl/tests/C2FailedUpdateTest.cpp
+++ b/extensions/http-curl/tests/C2FailedUpdateTest.cpp
@@ -142,6 +142,8 @@ int main(int argc, char **argv) {
std::shared_ptr<minifi::Configure> configuration = std::make_shared<minifi::Configure>();
+ configuration->set("c2.enable", "true");
+ configuration->set("c2.agent.class", "test");
configuration->set("c2.rest.url", "http://localhost:7071/update");
configuration->set("c2.agent.heartbeat.period", "1000");
mkdir("content_repository", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/1f2e6006/extensions/http-curl/tests/C2NullConfiguration.cpp
----------------------------------------------------------------------
diff --git a/extensions/http-curl/tests/C2NullConfiguration.cpp b/extensions/http-curl/tests/C2NullConfiguration.cpp
index 934cf02..02474d1 100644
--- a/extensions/http-curl/tests/C2NullConfiguration.cpp
+++ b/extensions/http-curl/tests/C2NullConfiguration.cpp
@@ -94,9 +94,10 @@ class VerifyC2Server : public HTTPIntegrationBase {
std::string url = "";
inv->getProperty(minifi::processors::InvokeHTTP::URL.getName(), url);
-
std::string port, scheme, path;
parse_http_components(url, port, scheme, path);
+ configuration->set("c2.enable", "true");
+ configuration->set("c2.agent.class", "test");
configuration->set("c2.agent.protocol.class", "null");
configuration->set("c2.rest.url", "");
configuration->set("c2.rest.url.ack", "");
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/1f2e6006/extensions/http-curl/tests/C2UpdateAgentTest.cpp
----------------------------------------------------------------------
diff --git a/extensions/http-curl/tests/C2UpdateAgentTest.cpp b/extensions/http-curl/tests/C2UpdateAgentTest.cpp
index 8bb7b22..d1e83aa 100644
--- a/extensions/http-curl/tests/C2UpdateAgentTest.cpp
+++ b/extensions/http-curl/tests/C2UpdateAgentTest.cpp
@@ -140,6 +140,8 @@ int main(int argc, char **argv) {
std::shared_ptr<minifi::Configure> configuration = std::make_shared<minifi::Configure>();
+ configuration->set("c2.enable", "true");
+ configuration->set("c2.agent.class", "test");
configuration->set("c2.rest.url", "http://localhost:7072/update");
configuration->set("c2.agent.heartbeat.period", "1000");
mkdir("content_repository", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
@@ -157,7 +159,7 @@ int main(int argc, char **argv) {
std::shared_ptr<TestRepository> repo = std::static_pointer_cast<TestRepository>(test_repo);
std::shared_ptr<minifi::FlowController> controller = std::make_shared<minifi::FlowController>(test_repo, test_flow_repo, configuration, std::move(yaml_ptr), content_repo, DEFAULT_ROOT_GROUP_NAME,
- true);
+ true);
core::YamlConfiguration yaml_config(test_repo, test_repo, content_repo, stream_factory, configuration, test_file_location);
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/1f2e6006/extensions/http-curl/tests/C2UpdateTest.cpp
----------------------------------------------------------------------
diff --git a/extensions/http-curl/tests/C2UpdateTest.cpp b/extensions/http-curl/tests/C2UpdateTest.cpp
index c51376d..a5166f3 100644
--- a/extensions/http-curl/tests/C2UpdateTest.cpp
+++ b/extensions/http-curl/tests/C2UpdateTest.cpp
@@ -140,6 +140,8 @@ int main(int argc, char **argv) {
std::shared_ptr<minifi::Configure> configuration = std::make_shared<minifi::Configure>();
+ configuration->set("c2.enable", "true");
+ configuration->set("c2.agent.class", "test");
configuration->set("c2.rest.url", "http://localhost:7070/update");
configuration->set("c2.agent.heartbeat.period", "1000");
mkdir("content_repository", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
@@ -156,7 +158,7 @@ int main(int argc, char **argv) {
std::shared_ptr<TestRepository> repo = std::static_pointer_cast<TestRepository>(test_repo);
std::shared_ptr<minifi::FlowController> controller = std::make_shared<minifi::FlowController>(test_repo, test_flow_repo, configuration, std::move(yaml_ptr), content_repo, DEFAULT_ROOT_GROUP_NAME,
- true);
+ true);
core::YamlConfiguration yaml_config(test_repo, test_repo, content_repo, stream_factory, configuration, test_file_location);
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/1f2e6006/extensions/http-curl/tests/C2VerifyHeartbeatAndStop.cpp
----------------------------------------------------------------------
diff --git a/extensions/http-curl/tests/C2VerifyHeartbeatAndStop.cpp b/extensions/http-curl/tests/C2VerifyHeartbeatAndStop.cpp
index b31fc51..60738e4 100644
--- a/extensions/http-curl/tests/C2VerifyHeartbeatAndStop.cpp
+++ b/extensions/http-curl/tests/C2VerifyHeartbeatAndStop.cpp
@@ -162,6 +162,8 @@ class VerifyC2Heartbeat : public HTTPIntegrationBase {
std::string url = "";
inv->getProperty(minifi::processors::InvokeHTTP::URL.getName(), url);
+ configuration->set("c2.enable", "true");
+ configuration->set("c2.agent.class", "test");
configuration->set("c2.rest.url", "http://localhost:8888/api/heartbeat");
configuration->set("c2.agent.heartbeat.period", "1000");
configuration->set("c2.rest.url.ack", "http://localhost:8888/api/heartbeat");
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/1f2e6006/extensions/http-curl/tests/C2VerifyServeResults.cpp
----------------------------------------------------------------------
diff --git a/extensions/http-curl/tests/C2VerifyServeResults.cpp b/extensions/http-curl/tests/C2VerifyServeResults.cpp
index 69afb29..1d3e03f 100644
--- a/extensions/http-curl/tests/C2VerifyServeResults.cpp
+++ b/extensions/http-curl/tests/C2VerifyServeResults.cpp
@@ -51,15 +51,13 @@
#include "HTTPIntegrationBase.h"
#include "processors/LogAttribute.h"
-
class Responder : public CivetHandler {
public:
explicit Responder(bool isSecure)
: isSecure(isSecure) {
}
bool handlePost(CivetServer *server, struct mg_connection *conn) {
- std::string resp =
- "{\"operation\" : \"heartbeat\", \"requested_operations\" : [{ \"operationid\" : 41, \"operation\" : \"stop\", \"name\" : \"invoke\" }, "
+ std::string resp = "{\"operation\" : \"heartbeat\", \"requested_operations\" : [{ \"operationid\" : 41, \"operation\" : \"stop\", \"name\" : \"invoke\" }, "
"{ \"operationid\" : 42, \"operation\" : \"stop\", \"name\" : \"FlowController\" } ]}";
mg_printf(conn, "HTTP/1.1 200 OK\r\nContent-Type: "
"text/plain\r\nContent-Length: %lu\r\nConnection: close\r\n\r\n",
@@ -72,7 +70,6 @@ class Responder : public CivetHandler {
bool isSecure;
};
-
class VerifyC2Server : public HTTPIntegrationBase {
public:
explicit VerifyC2Server(bool isSecure)
@@ -85,7 +82,7 @@ class VerifyC2Server : public HTTPIntegrationBase {
LogTestController::getInstance().setDebug<utils::HTTPClient>();
LogTestController::getInstance().setDebug<processors::InvokeHTTP>();
LogTestController::getInstance().setDebug<minifi::c2::RESTReceiver>();
- LogTestController::getInstance().setDebug<minifi::c2::C2Agent>();
+ LogTestController::getInstance().setDebug<minifi::c2::C2Agent>();
LogTestController::getInstance().setDebug<processors::LogAttribute>();
LogTestController::getInstance().setDebug<minifi::core::ProcessSession>();
std::fstream file;
@@ -116,9 +113,10 @@ class VerifyC2Server : public HTTPIntegrationBase {
std::string url = "";
inv->getProperty(minifi::processors::InvokeHTTP::URL.getName(), url);
-
std::string port, scheme, path;
parse_http_components(url, port, scheme, path);
+ configuration->set("c2.enable", "true");
+ configuration->set("c2.agent.class", "test");
configuration->set("c2.agent.heartbeat.reporter.classes", "RESTReceiver");
configuration->set("c2.rest.listener.port", port);
configuration->set("c2.agent.heartbeat.period", "10");
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/1f2e6006/libminifi/src/FlowController.cpp
----------------------------------------------------------------------
diff --git a/libminifi/src/FlowController.cpp b/libminifi/src/FlowController.cpp
index 80f883a..8ee15d4 100644
--- a/libminifi/src/FlowController.cpp
+++ b/libminifi/src/FlowController.cpp
@@ -356,16 +356,36 @@ void FlowController::initializeC2() {
return;
std::string c2_enable_str;
+ std::string class_str;
+
+ // don't need to worry about the return code, only whether class_str is defined.
+ configuration_->get("nifi.c2.agent.class", "c2.agent.class", class_str);
if (configuration_->get(Configure::nifi_c2_enable, "c2.enable", c2_enable_str)) {
bool enable_c2 = true;
utils::StringUtils::StringToBool(c2_enable_str, enable_c2);
c2_enabled_ = enable_c2;
- if (!c2_enabled_) {
- return;
+ if (c2_enabled_ && class_str.empty()) {
+ logger_->log_error("Class name must be defined when C2 is enabled");
+ std::cerr << "Class name must be defined when C2 is enabled" << std::endl;
+ stop(true);
+ exit(1);
}
} else {
- c2_enabled_ = true;
+ /**
+ * To require a C2 agent class we will disable C2 by default. If a registration process
+ * is implemented we can re-enable. The reason for always enabling C2 is because this allows the controller
+ * mechanism that can be used for local config/access to be used. Without this agent information cannot be
+ * gathered even if a remote C2 server is enabled.
+ *
+ * The ticket that impacts this, MINIFICPP-664, should be reversed in the event that agent registration
+ * can be performed and agent classes needn't be defined a priori.
+ */
+ c2_enabled_ = false;
+ }
+
+ if (!c2_enabled_) {
+ return;
}
std::string identifier_str;
@@ -424,13 +444,7 @@ void FlowController::initializeC2() {
if (identifier != nullptr) {
identifier->setIdentifier(identifier_str);
- std::string class_str;
- if (configuration_->get("nifi.c2.agent.class", class_str) && !class_str.empty()) {
- identifier->setAgentClass(class_str);
- } else {
- // set to the flow controller's identifier
- identifier->setAgentClass("default");
- }
+ identifier->setAgentClass(class_str);
}
auto monitor = std::dynamic_pointer_cast<state::response::AgentMonitor>(processor);