فهرست منبع

Merge pull request #15017 from wangkx/h25819

HPCC-25819 Implement WsFileIO.CheckServerAccess in container mode

Reviewed-By: Anthony Fishbeck <anthony.fishbeck@lexisnexis.com>
Reviewed-By: Gavin Halliday <gavin.halliday@lexisnexis.com>
Reviewed-By: Richard Chapman <rchapman@hpccsystems.com>
Richard Chapman 4 سال پیش
والد
کامیت
bf79a44f9b

+ 4 - 1
esp/scm/ws_fileio.ecm

@@ -21,6 +21,7 @@ ESPrequest CreateFileRequest
 {
     string DestDropZone;        //name or IP address
     string DestRelativePath;    //file name and/or path; related to the predefined directory of the dropzone
+    [min_ver("1.01")] string DestNetAddress;
     bool   Overwrite(false);
 };
 
@@ -38,6 +39,7 @@ ESPrequest WriteFileDataRequest
     binary Data;
     string DestDropZone;        //name or IP address; 
     string DestRelativePath;    //file name and/or path;
+    [min_ver("1.01")] string DestNetAddress;
     int64  Offset(0);
     bool   Append(false);
 };
@@ -56,6 +58,7 @@ ESPrequest ReadFileDataRequest
 {
     string DestDropZone;        //name or IP address; 
     string DestRelativePath;    //file name and/or path;
+    [min_ver("1.01")] string DestNetAddress;
     int64  Offset(0);
     int64  DataSize;        
 };
@@ -72,7 +75,7 @@ ReadFileDataResponse
 };
 
 
-ESPservice [auth_feature("DEFERRED"), exceptions_inline("./smc_xslt/exceptions.xslt")] WsFileIO
+ESPservice [auth_feature("DEFERRED"), version("1.01"), default_client_version("1.01"), exceptions_inline("./smc_xslt/exceptions.xslt")] WsFileIO
 {
     ESPmethod CreateFile(CreateFileRequest, CreateFileResponse);
     ESPmethod WriteFileData(WriteFileDataRequest, WriteFileDataResponse);

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

@@ -58,6 +58,7 @@ include_directories (
          ./../../smc/SMCLib 
          ./../../bindings/SOAP/xpp 
          ${HPCC_SOURCE_DIR}/common/thorhelper
+         ${HPCC_SOURCE_DIR}/dali/sasha
     )
 
 ADD_DEFINITIONS( -D_USRDLL )
@@ -74,6 +75,7 @@ target_link_libraries ( ws_fileio
          ${XALAN_LIBRARIES} ${XERCES_LIBRARIES}
          xmllib 
          esphttp 
+         SMCLib
     )
 
 if (NOT CONTAINERIZED)

+ 36 - 6
esp/services/ws_fileio/ws_fileioservice.cpp

@@ -30,15 +30,45 @@
 
 void CWsFileIOEx::init(IPropertyTree *cfg, const char *process, const char *service)
 {
+    CTpWrapper tpWrapper;
+    tpWrapper.getTpDropZones(9999, nullptr, false, allTpDropZones); //version 9999: get the latest information about dropzone
 }
 
-bool CWsFileIOEx::CheckServerAccess(const char* targetDZNameOrAddress, const char* relPath, StringBuffer& netAddr, StringBuffer& absPath)
+bool CWsFileIOEx::CheckServerAccess(const char* targetDZNameOrAddress, const char* netAddrReq, const char* relPath, StringBuffer& netAddr, StringBuffer& absPath)
 {
     if (!targetDZNameOrAddress || (targetDZNameOrAddress[0] == 0) || !relPath || (relPath[0] == 0))
         return false;
 
 #ifdef _CONTAINERIZED
-    UNIMPLEMENTED_X("CONTAINERIZED(CWsFileIOEx::CheckServerAccess)");
+    bool isIp4Req = isIPAddress(netAddrReq);
+    ForEachItemIn(i, allTpDropZones)
+    {
+        IConstTpDropZone& dropZone = allTpDropZones.item(i);
+        if (!dropZone.getECLWatchVisible())
+            continue;
+
+        const char* name = dropZone.getName();
+        if (isEmptyString(name) || !streq(targetDZNameOrAddress, name))
+            continue;
+
+        const char* prefix = dropZone.getPath();
+        if (isEmptyString(prefix))
+            continue;
+
+        IArrayOf<IConstTpMachine>& tpMachines = dropZone.getTpMachines();
+        ForEachItemIn(ii, tpMachines)
+        {
+            IConstTpMachine& tpMachine = tpMachines.item(ii);
+            if (!isEmptyString(netAddrReq) && !matchNetAddressRequest(netAddrReq, isIp4Req, tpMachine))
+                continue;
+
+            netAddr.set(tpMachine.getNetaddress());
+            absPath.set(prefix);
+            addPathSepChar(absPath);
+            absPath.append(relPath);
+            return true;
+        }
+    }
 #else
     netAddr.clear();
     Owned<IEnvironmentFactory> factory = getEnvironmentFactory(true);
@@ -120,9 +150,9 @@ bool CWsFileIOEx::CheckServerAccess(const char* targetDZNameOrAddress, const cha
         }
 
     }
+#endif
 
     return false;
-#endif
 }
 
 bool CWsFileIOEx::onCreateFile(IEspContext &context, IEspCreateFileRequest &req, IEspCreateFileResponse &resp)
@@ -149,7 +179,7 @@ bool CWsFileIOEx::onCreateFile(IEspContext &context, IEspCreateFileRequest &req,
 
     StringBuffer destAbsPath;
     StringBuffer destNetAddr;
-    if (!CheckServerAccess(server, destRelativePath, destNetAddr, destAbsPath))
+    if (!CheckServerAccess(server, req.getDestNetAddress(), destRelativePath, destNetAddr, destAbsPath))
     {
         result.appendf("Failed to access the destination: %s %s.", server, destRelativePath);
         resp.setResult(result.str());
@@ -207,7 +237,7 @@ bool CWsFileIOEx::onReadFileData(IEspContext &context, IEspReadFileDataRequest &
 
     StringBuffer destAbsPath;
     StringBuffer destNetAddr;
-    if (!CheckServerAccess(server, destRelativePath, destNetAddr, destAbsPath))
+    if (!CheckServerAccess(server, req.getDestNetAddress(), destRelativePath, destNetAddr, destAbsPath))
     {
         result.appendf("Failed to access the destination: %s %s.", server, destRelativePath);
         resp.setResult(result.str());
@@ -318,7 +348,7 @@ bool CWsFileIOEx::onWriteFileData(IEspContext &context, IEspWriteFileDataRequest
 
     StringBuffer destAbsPath;
     StringBuffer destNetAddr;
-    if (!CheckServerAccess(server, destRelativePath, destNetAddr, destAbsPath))
+    if (!CheckServerAccess(server, req.getDestNetAddress(), destRelativePath, destNetAddr, destAbsPath))
     {
         result.appendf("Failed to access the destination: %s %s.", server, destRelativePath);
         resp.setResult(result.str());

+ 3 - 1
esp/services/ws_fileio/ws_fileioservice.hpp

@@ -19,6 +19,7 @@
 #define _ESPWIZ_WsFileIO_HPP__
 
 #include "ws_fileio_esp.ipp"
+#include "TpWrapper.hpp"
 
 class CWsFileIOSoapBindingEx : public CWsFileIOSoapBinding
 {
@@ -37,6 +38,7 @@ public:
 
 class CWsFileIOEx : public CWsFileIO
 {
+    IArrayOf<IConstTpDropZone> allTpDropZones;
 public:
     virtual void init(IPropertyTree *cfg, const char *process, const char *service);
 
@@ -45,7 +47,7 @@ public:
     virtual bool onReadFileData(IEspContext &context,     IEspReadFileDataRequest &req,   IEspReadFileDataResponse &resp);
 
 protected:
-    bool CheckServerAccess(const char* server, const char* relPath, StringBuffer& netAddr, StringBuffer& absPath);
+    bool CheckServerAccess(const char* server, const char* netAddrIn, const char* relPath, StringBuffer& netAddrOut, StringBuffer& absPath);
 };
 
 #endif //_ESPWIZ_WsFileIO_HPP__

+ 7 - 0
esp/smc/SMCLib/TpCommon.cpp

@@ -97,3 +97,10 @@ extern TPWRAPPER_API IStringIterator* getContainerTargetClusters(const char* pro
     }
     return ret.getClear();
 }
+
+extern TPWRAPPER_API bool matchNetAddressRequest(const char* netAddressReg, bool ipReq, IConstTpMachine& tpMachine)
+{
+    if (ipReq)
+        return streq(netAddressReg, tpMachine.getNetaddress());
+    return streq(netAddressReg, tpMachine.getConfigNetaddress());
+}

+ 1 - 0
esp/smc/SMCLib/TpWrapper.hpp

@@ -224,6 +224,7 @@ extern TPWRAPPER_API bool getSashaServiceEP(SocketEndpoint &serviceEndpoint, con
 
 extern TPWRAPPER_API StringBuffer & getRoxieDefaultPlane(StringBuffer & plane, const char * roxieName);
 extern TPWRAPPER_API bool validateDataPlaneName(const char *remoteDali, const char * name);
+extern TPWRAPPER_API bool matchNetAddressRequest(const char* netAddressReg, bool ipReq, IConstTpMachine& tpMachine);
 
 #endif //_ESPWIZ_TpWrapper_HPP__