Browse Source

Merge pull request #14767 from wangkx/wsdali2

HPCC-25643 Support the get() and set() functions to WsDali

Reviewed-By: Jake Smith <jake.smith@lexisnexis.com>
Reviewed-By: Richard Chapman <rchapman@hpccsystems.com>
Richard Chapman 4 năm trước cách đây
mục cha
commit
f0f7af9c17

+ 5 - 10
dali/daliadmin/daadmin.cpp

@@ -258,7 +258,7 @@ void _delete_(const char *path,bool backup)
 
 //=============================================================================
 
-void set(const char *path,const char *val)
+StringBuffer &setValue(const char *path,const char *val,StringBuffer &oldVal)
 {
     StringBuffer head;
     StringBuffer tmp;
@@ -266,22 +266,19 @@ void set(const char *path,const char *val)
     Owned<IRemoteConnection> conn = querySDS().connect(head.str(),myProcessSession(),RTM_LOCK_WRITE, daliConnectTimeoutMs);
     if (!conn) {
         UERRLOG("Could not connect to %s",path);
-        return;
+        return oldVal;
     }
     Owned<IPropertyTree> root = conn->getRoot();
-    StringBuffer oldv;
-    StringBuffer newv;
-    root->getProp(tail,oldv);
+    root->getProp(tail,oldVal);
     root->setProp(tail,val);
     conn->commit();
-    root->getProp(tail,newv);
-    OUTLOG("Changed %s from '%s' to '%s'",path,oldv.str(),newv.str());
     conn->close();
+    return oldVal;
 }
 
 //=============================================================================
 
-void get(const char *path)
+void getValue(const char *path,StringBuffer &val)
 {
     StringBuffer head;
     StringBuffer tmp;
@@ -292,9 +289,7 @@ void get(const char *path)
         return;
     }
     Owned<IPropertyTree> root = conn->getRoot();
-    StringBuffer val;
     root->getProp(tail,val);
-    OUTLOG("Value of %s is: '%s'",path,val.str());
     conn->close();
 }
 

+ 2 - 2
dali/daliadmin/daadmin.hpp

@@ -30,8 +30,8 @@ extern DALIADMIN_API void translateToXpath(const char *logicalfile, DfsXmlBranch
 extern DALIADMIN_API void _export_(const char *path, const char *dst, bool safe = false);
 extern DALIADMIN_API void import(const char *path, const char *src, bool add);
 extern DALIADMIN_API void _delete_(const char *path, bool backup);
-extern DALIADMIN_API void set(const char *path, const char *val);
-extern DALIADMIN_API void get(const char *path);
+extern DALIADMIN_API StringBuffer &setValue(const char *path, const char *val, StringBuffer &oldVal);
+extern DALIADMIN_API void getValue(const char *path, StringBuffer& out);
 extern DALIADMIN_API void bget(const char *path, const char *outfn);
 extern DALIADMIN_API void wget(const char *path);
 extern DALIADMIN_API void add(const char *path, const char *val);

+ 5 - 2
dali/daliadmin/daliadmin.cpp

@@ -249,6 +249,7 @@ int main(int argc, const char* argv[])
                         userDesc->set(tmps.str(),ps.str());
                         queryDistributedFileDirectory().setDefaultUser(userDesc);
                     }
+                    StringBuffer out;
                     setDaliConnectTimeoutMs(1000 * props->getPropInt("timeout", DEFAULT_DALICONNECT_TIMEOUT));
                     if (strieq(cmd,"export")) {
                         CHECKPARAMS(2,2);
@@ -269,11 +270,13 @@ int main(int argc, const char* argv[])
                     }
                     else if (strieq(cmd,"set")) {
                         CHECKPARAMS(2,2);
-                        set(params.item(1),params.item(2));
+                        setValue(params.item(1),params.item(2),out);
+                        PROGLOG("Changed %s from '%s' to '%s'",params.item(1),out.str(),params.item(2));
                     }
                     else if (strieq(cmd,"get")) {
                         CHECKPARAMS(1,1);
-                        get(params.item(1));
+                        getValue(params.item(1),out);
+                        PROGLOG("Value of %s is: '%s'",params.item(1),out.str());
                     }
                     else if (strieq(cmd,"bget")) {
                         CHECKPARAMS(2,2);

+ 19 - 1
esp/scm/ws_dali.ecm

@@ -17,9 +17,27 @@
 
 EspInclude(common);
 
+ESPrequest [nil_remove] SetValueRequest
+{
+    string Path;
+    string Value;
+};
+
+ESPresponse [exceptions_inline, nil_remove] ValueResponse
+{
+    string Result;
+};
+
+ESPrequest [nil_remove] GetValueRequest
+{
+    string Path;
+};
+
 ESPservice [auth_feature("NONE"), //This declares that the method logic handles feature level authorization
-    version("1.00"), default_client_version("1.00"), exceptions_inline("./smc_xslt/exceptions.xslt")] WSDali
+    version("1.01"), default_client_version("1.01"), exceptions_inline("./smc_xslt/exceptions.xslt")] WSDali
 {
+    ESPmethod [min_ver("1.01")] SetValue(SetValueRequest, ValueResponse);
+    ESPmethod [min_ver("1.01")] GetValue(GetValueRequest, ValueResponse);
 };
 
 SCMexportdef(WSDali);

+ 2 - 0
esp/services/ws_dali/CMakeLists.txt

@@ -46,6 +46,7 @@ include_directories (
          ${HPCC_SOURCE_DIR}/system/mp 
          ${HPCC_SOURCE_DIR}/common/thorhelper
          ${HPCC_SOURCE_DIR}/dali/base
+         ${HPCC_SOURCE_DIR}/dali/daliadmin
     )
 
 ADD_DEFINITIONS( -D_USRDLL )
@@ -55,6 +56,7 @@ install ( TARGETS ws_dali RUNTIME DESTINATION ${EXEC_DIR} LIBRARY DESTINATION ${
 target_link_libraries ( ws_dali
          jlib
          xmllib
+         daliadminlib
          esphttp
     )
     

+ 59 - 0
esp/services/ws_dali/ws_daliservice.cpp

@@ -23,6 +23,7 @@
 #include "jlib.hpp"
 #include "dautils.hpp"
 #include "dasds.hpp"
+#include "daadmin.hpp"
 
 #define REQPATH_EXPORTSDSDATA "/WSDali/Export"
 
@@ -96,3 +97,61 @@ void CWSDaliSoapBindingEx::exportSDSData(CHttpRequest* request, CHttpResponse* r
     io.clear();
     removeFileTraceIfFail(outFileNameWithPath);
 }
+
+void CWSDaliEx::checkAccess(IEspContext& context)
+{
+#ifdef _USE_OPENLDAP
+    context.ensureSuperUser(ECLWATCH_SUPER_USER_ACCESS_DENIED, "Access denied, administrators only.");
+#endif
+    if (isDaliDetached())
+        throw makeStringException(ECLWATCH_CANNOT_CONNECT_DALI, "Dali detached.");
+}
+
+bool CWSDaliEx::onSetValue(IEspContext& context, IEspSetValueRequest& req, IEspValueResponse& resp)
+{
+    try
+    {
+        checkAccess(context);
+
+        const char* path = req.getPath();
+        if (isEmptyString(path))
+            throw makeStringException(ECLWATCH_INVALID_INPUT, "Data path not specified.");
+        const char* value = req.getValue();
+        if (isEmptyString(value))
+            throw makeStringException(ECLWATCH_INVALID_INPUT, "Data value not specified.");
+
+        StringBuffer oldValue, result;
+        setValue(path, value, oldValue);
+        if (oldValue.isEmpty())
+            result.appendf("Changed %s to '%s'", path, value);
+        else
+            result.appendf("Changed %s from '%s' to '%s'", path, oldValue.str(), value);
+        resp.setResult(result);
+    }
+    catch(IException* e)
+    {
+        FORWARDEXCEPTION(context, e,  ECLWATCH_INTERNAL_ERROR);
+    }
+    return true;
+}
+
+bool CWSDaliEx::onGetValue(IEspContext& context, IEspGetValueRequest& req, IEspValueResponse& resp)
+{
+    try
+    {
+        checkAccess(context);
+
+        const char* path = req.getPath();
+        if (isEmptyString(path))
+            throw makeStringException(ECLWATCH_INVALID_INPUT, "Data path not specified.");
+
+        StringBuffer value;
+        getValue(path, value);
+        resp.setResult(value);
+    }
+    catch(IException* e)
+    {
+        FORWARDEXCEPTION(context, e,  ECLWATCH_INTERNAL_ERROR);
+    }
+    return true;
+}

+ 3 - 0
esp/services/ws_dali/ws_daliservice.hpp

@@ -26,6 +26,7 @@ class CWSDaliEx : public CWSDali
     StringAttr espProcess;
     std::atomic<bool> daliDetached{false};
 
+    void checkAccess(IEspContext& context);
 public:
     IMPLEMENT_IINTERFACE;
 
@@ -47,6 +48,8 @@ public:
     }
 
     virtual void init(IPropertyTree* cfg, const char* process, const char* service) override;
+    virtual bool onSetValue(IEspContext& context, IEspSetValueRequest& req, IEspValueResponse& resp) override;
+    virtual bool onGetValue(IEspContext& context, IEspGetValueRequest& req, IEspValueResponse& resp) override;
 };
 
 class CWSDaliSoapBindingEx : public CWSDaliSoapBinding