Repository: nifi-minifi-cpp
Updated Branches:
  refs/heads/master 8b952e9dd -> 3d9fad569


MINIFICPP-411: Resolve issues with command reporting. Show the size before 
clear, and fix docs to clarify that a response isn't immediate

This closes #269.

Signed-off-by: Aldrin Piri <[email protected]>


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/3d9fad56
Tree: http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/tree/3d9fad56
Diff: http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/diff/3d9fad56

Branch: refs/heads/master
Commit: 3d9fad56966ec070ba226458e57d12104fa1fe05
Parents: 8b952e9
Author: Marc Parisi <[email protected]>
Authored: Thu Feb 22 10:04:38 2018 -0500
Committer: Aldrin Piri <[email protected]>
Committed: Wed Feb 28 09:28:22 2018 -0500

----------------------------------------------------------------------
 README.md                                     |  3 ++-
 controller/Controller.h                       |  8 ++++----
 controller/MiNiFiController.cpp               | 13 ++++++++-----
 libminifi/src/c2/ControllerSocketProtocol.cpp |  1 +
 4 files changed, 15 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/3d9fad56/README.md
----------------------------------------------------------------------
diff --git a/README.md b/README.md
index c5b59f3..40dfd4a 100644
--- a/README.md
+++ b/README.md
@@ -665,7 +665,7 @@ Additionally, a unique hexadecimal 
uid.minifi.device.segment should be assigned
   Simply provide the capacity path and status path along with your threshold 
for the trigger and low battery alarm and you can monitor your battery and 
throttle
   the threadpools within MiNiFi C++. Note that the name is identified must be 
ThreadPoolManager.
 
-   Controller Services:
+    Controller Services:
     - name: ThreadPoolManager
       id: 2438e3c8-015a-1000-79ca-83af40ec1888
       class: LinuxPowerManagerService
@@ -712,6 +712,7 @@ These are defined by default to the above values. If the 
port option is left und
 will be disabled in your deployment.
 
  The executable is stored in the bin directory and is titled minificontroller. 
Available commands are listed below.
+ Note that with all commands an immediate response by the agent isn't 
guaranteed. In all cases the agent assumes the role of validating that a 
response was received, but execution of said command may take some time 
depending on a number of factors to include persistent storage type, size of 
queues, and speed of hardware. 
  
  #### Specifying connecting information
  

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/3d9fad56/controller/Controller.h
----------------------------------------------------------------------
diff --git a/controller/Controller.h b/controller/Controller.h
index 809e74c..95e05b1 100644
--- a/controller/Controller.h
+++ b/controller/Controller.h
@@ -35,8 +35,7 @@ bool sendSingleCommand(std::unique_ptr<minifi::io::Socket> 
socket, uint8_t op, c
   minifi::io::BaseStream stream;
   stream.writeData(&op, 1);
   stream.writeUTF(value);
-  socket->writeData(const_cast<uint8_t*>(stream.getBuffer()), 
stream.getSize());
-  return true;
+  return socket->writeData(const_cast<uint8_t*>(stream.getBuffer()), 
stream.getSize()) == stream.getSize();
 }
 
 /**
@@ -169,9 +168,10 @@ int listComponents(std::unique_ptr<minifi::io::Socket> 
socket, std::ostream &out
     out << "Components:" << std::endl;
 
   for (int i = 0; i < responses; i++) {
-    std::string name;
+    std::string name,status;
     socket->readUTF(name, false);
-    out << name << std::endl;
+    socket->readUTF(status, false);
+    out << name << ", running: " << status << std::endl;
   }
   return 0;
 }

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/3d9fad56/controller/MiNiFiController.cpp
----------------------------------------------------------------------
diff --git a/controller/MiNiFiController.cpp b/controller/MiNiFiController.cpp
index 811aa07..98acd15 100644
--- a/controller/MiNiFiController.cpp
+++ b/controller/MiNiFiController.cpp
@@ -103,7 +103,6 @@ int main(int argc, char **argv) {
     std::string secureStr;
     bool is_secure = false;
     if (configuration->get(minifi::Configure::nifi_remote_input_secure, 
secureStr) && 
org::apache::nifi::minifi::utils::StringUtils::StringToBool(secureStr, 
is_secure)) {
-      std::cout << "Creating secure context" << std::endl;
       secure_context = 
std::make_shared<minifi::controllers::SSLContextService>("ControllerSocketProtocolSSL",
 configuration);
       secure_context->onEnable();
     }
@@ -178,7 +177,7 @@ int main(int argc, char **argv) {
       auto& components = result["stop"].as<std::vector<std::string>>();
       for (const auto& component : components) {
         auto socket = secure_context != nullptr ? 
stream_factory_->createSecureSocket(host, port, secure_context) : 
stream_factory_->createSocket(host, port);
-        if (!stopComponent(std::move(socket), component))
+        if (stopComponent(std::move(socket), component))
           std::cout << component << " requested to stop" << std::endl;
         else
           std::cout << "Could not connect to remote host " << host << ":" << 
port << std::endl;
@@ -189,7 +188,7 @@ int main(int argc, char **argv) {
       auto& components = result["start"].as<std::vector<std::string>>();
       for (const auto& component : components) {
         auto socket = secure_context != nullptr ? 
stream_factory_->createSecureSocket(host, port, secure_context) : 
stream_factory_->createSocket(host, port);
-        if (!startComponent(std::move(socket), component))
+        if (startComponent(std::move(socket), component))
           std::cout << component << " requested to start" << std::endl;
         else
           std::cout << "Could not connect to remote host " << host << ":" << 
port << std::endl;
@@ -200,8 +199,12 @@ int main(int argc, char **argv) {
       auto& components = result["c"].as<std::vector<std::string>>();
       for (const auto& connection : components) {
         auto socket = secure_context != nullptr ? 
stream_factory_->createSecureSocket(host, port, secure_context) : 
stream_factory_->createSocket(host, port);
-        if (!clearConnection(std::move(socket), connection))
-          std::cout << "Cleared " << connection << std::endl;
+        if (clearConnection(std::move(socket), connection)){
+          std::cout << "Sent clear command to " << connection << ". Size 
before clear operation sent: " << std::endl;
+          socket = secure_context != nullptr ? 
stream_factory_->createSecureSocket(host, port, secure_context) : 
stream_factory_->createSocket(host, port);
+          if (getConnectionSize(std::move(socket), std::cout, connection) < 0)
+                    std::cout << "Could not connect to remote host " << host 
<< ":" << port << std::endl;
+        }
         else
           std::cout << "Could not connect to remote host " << host << ":" << 
port << std::endl;
       }

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/3d9fad56/libminifi/src/c2/ControllerSocketProtocol.cpp
----------------------------------------------------------------------
diff --git a/libminifi/src/c2/ControllerSocketProtocol.cpp 
b/libminifi/src/c2/ControllerSocketProtocol.cpp
index ae84c1c..fb5be6d 100644
--- a/libminifi/src/c2/ControllerSocketProtocol.cpp
+++ b/libminifi/src/c2/ControllerSocketProtocol.cpp
@@ -193,6 +193,7 @@ void ControllerSocketProtocol::initialize(const 
std::shared_ptr<core::controller
             resp.write(size);
             for (const auto &component : update_sink_->getAllComponents()) {
               resp.writeUTF(component->getComponentName());
+              resp.writeUTF(component->isRunning() ? "true" : "false");
             }
             stream->writeData(const_cast<uint8_t*>(resp.getBuffer()), 
resp.getSize());
           } else if (what == "connections") {

Reply via email to