control: Support state parameter on net decrease target action

The net increase target action supports the use of a parameter to
determine the state at which group members must be at to request an
increase delta. The net decrease target action should also support the
use of a parameter to determine the state for decreases.

Change-Id: Ied883c70566b19bacfa1f76cc2a6c738c1cea85a
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/control/json/actions/net_target_decrease.cpp b/control/json/actions/net_target_decrease.cpp
index 39e5521..393a273 100644
--- a/control/json/actions/net_target_decrease.cpp
+++ b/control/json/actions/net_target_decrease.cpp
@@ -44,6 +44,20 @@
 
 void NetTargetDecrease::run(Zone& zone)
 {
+    if (!_stateParameter.empty())
+    {
+        auto s = Manager::getParameter(_stateParameter);
+        if (!s)
+        {
+            log<level::DEBUG>(
+                fmt::format("Action {}: State parameter {} not found",
+                            ActionBase::getName(), _stateParameter)
+                    .c_str());
+            return;
+        }
+        _state = *s;
+    }
+
     auto netDelta = zone.getDecDelta();
     for (const auto& group : _groups)
     {
@@ -135,12 +149,20 @@
 
 void NetTargetDecrease::setState(const json& jsonObj)
 {
-    if (!jsonObj.contains("state"))
+    if (jsonObj.contains("state"))
     {
-        throw ActionParseError{ActionBase::getName(),
-                               "Missing required state value"};
+        _state = getJsonValue(jsonObj["state"]);
     }
-    _state = getJsonValue(jsonObj["state"]);
+    else if (jsonObj.contains("state_parameter_name"))
+    {
+        _stateParameter = jsonObj["state_parameter_name"].get<std::string>();
+    }
+    else
+    {
+        throw ActionParseError{
+            ActionBase::getName(),
+            "Missing required state or state_parameter_name value"};
+    }
 }
 
 void NetTargetDecrease::setDelta(const json& jsonObj)
diff --git a/control/json/actions/net_target_decrease.hpp b/control/json/actions/net_target_decrease.hpp
index 76a7f44..a0e1790 100644
--- a/control/json/actions/net_target_decrease.hpp
+++ b/control/json/actions/net_target_decrease.hpp
@@ -75,6 +75,9 @@
      * dbus objects are processed, the minimum net target decrease calculated is
      * requested on the zone.
      *
+     * The state value can be specified in the JSON, or as a Manager parameter
+     * that another action will have set.
+     *
      * @param[in] zone - Zone to run the action on
      */
     void run(Zone& zone) override;
@@ -83,6 +86,12 @@
     /* State the members must be at to decrease the target */
     PropertyVariantType _state;
 
+    /**
+     * The Manager parameter to use to get the state value if that
+     * was the method specified in the JSON.
+     */
+    std::string _stateParameter;
+
     /* Decrease delta for this action */
     uint64_t _delta;