Explorar el Código

Merge pull request #14227 from wangkx/h24260

HPCC-24260 Common up ESP code for file/group lookup

Reviewed-By: Anthony Fishbeck <anthony.fishbeck@lexisnexis.com>
Reviewed-By: Richard Chapman <rchapman@hpccsystems.com>
Richard Chapman hace 4 años
padre
commit
268f806f08

+ 4 - 35
esp/services/ws_dfu/ws_dfuService.cpp

@@ -1823,14 +1823,7 @@ bool CWsDfuEx::onDFURecordTypeInfo(IEspContext &context, IEspDFURecordTypeInfoRe
             throw MakeStringException(ECLWATCH_MISSING_PARAMS, "File name required");
         PROGLOG("DFURecordTypeInfo file: %s", fileName);
 
-        const char* userId = context.queryUserId();
-        Owned<IUserDescriptor> userdesc;
-        if (userId && *userId)
-        {
-            userdesc.setown(createUserDescriptor());
-            userdesc->set(userId, context.queryPassword(), context.querySignature());
-        }
-        Owned<IDistributedFile> df = queryDistributedFileDirectory().lookup(fileName, userdesc, false, false, false, nullptr, defaultPrivilegedUser);
+        Owned<IDistributedFile> df = lookupLogicalName(context, fileName, false, false, false, nullptr, defaultPrivilegedUser);
         if (!df)
             throw MakeStringException(ECLWATCH_FILE_NOT_EXIST,"Cannot find file %s.",fileName);
 
@@ -5035,22 +5028,13 @@ bool CWsDfuEx::onListHistory(IEspContext &context, IEspListHistoryRequest &req,
 {
     try
     {
-        StringBuffer username;
-        context.getUserID(username);
-        Owned<IUserDescriptor> userdesc;
-        if (username.length() > 0)
-        {
-            userdesc.setown(createUserDescriptor());
-            userdesc->set(username.str(), context.queryPassword(), context.querySignature());
-        }
-
         if (!req.getName() || !*req.getName())
             throw MakeStringException(ECLWATCH_MISSING_PARAMS, "Name required");
         PROGLOG("onListHistory: %s", req.getName());
 
         MemoryBuffer xmlmap;
         IArrayOf<IEspHistory> arrHistory;
-        Owned<IDistributedFile> file = queryDistributedFileDirectory().lookup(req.getName(),userdesc.get(), false, false, false, nullptr, defaultPrivilegedUser);
+        Owned<IDistributedFile> file = lookupLogicalName(context, req.getName(), false, false, false, nullptr, defaultPrivilegedUser);
         if (file)
         {
             IPropertyTree *history = file->queryHistory();
@@ -5083,22 +5067,13 @@ bool CWsDfuEx::onEraseHistory(IEspContext &context, IEspEraseHistoryRequest &req
     {
         context.ensureFeatureAccess(FEATURE_URL, SecAccess_Full, ECLWATCH_DFU_ACCESS_DENIED, "WsDfu::EraseHistory: Permission denied.");
 
-        StringBuffer username;
-        context.getUserID(username);
-        Owned<IUserDescriptor> userdesc;
-        if (username.length() > 0)
-        {
-            userdesc.setown(createUserDescriptor());
-            userdesc->set(username.str(), context.queryPassword(), context.querySignature());
-        }
-
         if (!req.getName() || !*req.getName())
             throw MakeStringException(ECLWATCH_MISSING_PARAMS, "Name required");
         PROGLOG("onEraseHistory: %s", req.getName());
 
         MemoryBuffer xmlmap;
         IArrayOf<IEspHistory> arrHistory;
-        Owned<IDistributedFile> file = queryDistributedFileDirectory().lookup(req.getName(),userdesc.get(),false,false,false,nullptr,defaultPrivilegedUser);
+        Owned<IDistributedFile> file = lookupLogicalName(context, req.getName(), false, false, false, nullptr, defaultPrivilegedUser);
         if (file)
         {
             IPropertyTree *history = file->queryHistory();
@@ -5694,18 +5669,12 @@ int CWsDfuEx::GetIndexData(IEspContext &context, bool bSchemaOnly, const char* i
 
     double version = context.getClientVersion();
 
-    StringBuffer username;
-    context.getUserID(username);
-
     StringBuffer cluster;
-    Owned<IUserDescriptor> userdesc;
     bool disableUppercaseTranslation = false;
     Owned<IDistributedFile> df;
     try
     {
-        userdesc.setown(createUserDescriptor());
-        userdesc->set(username.str(), context.queryPassword(), context.querySignature());
-        df.setown(queryDistributedFileDirectory().lookup(indexName, userdesc, false, false, false, nullptr, defaultPrivilegedUser));
+        df.setown(lookupLogicalName(context, indexName, false, false, false, nullptr, defaultPrivilegedUser));
         if(!df)
             throw MakeStringException(ECLWATCH_FILE_NOT_EXIST,"Could not find file %s.", indexName);
 

+ 2 - 16
esp/services/ws_fs/ws_fsService.cpp

@@ -39,6 +39,7 @@
 #include "portlist.h"
 #include "sacmd.hpp"
 #include "exception_util.hpp"
+#include "LogicFileWrapper.hpp"
 
 #define DFU_WU_URL          "DfuWorkunitsAccess"
 #define DFU_EX_URL          "DfuExceptionsAccess"
@@ -636,21 +637,6 @@ void setRoxieClusterPartDiskMapping(const char *clusterName, const char *default
     wuOptions->setReplicate(replicate);
 }
 
-StringBuffer& getNodeGroupFromLFN(StringBuffer& nodeGroup, const char* lfn, const char* username, const char* passwd)
-{
-    Owned<IUserDescriptor> udesc;
-    if(username != NULL && *username != '\0')
-    {
-        udesc.setown(createUserDescriptor());
-        udesc->set(username, passwd);
-    }
-
-    Owned<IDistributedFile> df = queryDistributedFileDirectory().lookup(lfn, udesc, false, false, false, nullptr, defaultPrivilegedUser);
-    if (!df)
-        throw MakeStringException(ECLWATCH_FILE_NOT_EXIST, "Failed to find file: %s", lfn);
-    return df->getClusterGroupName(0, nodeGroup);
-}
-
 StringBuffer& constructFileMask(const char* filename, StringBuffer& filemask)
 {
     filemask.clear().append(filename).toLowerCase().append("._$P$_of_$N$");
@@ -2476,7 +2462,7 @@ bool CFileSprayEx::onCopy(IEspContext &context, IEspCopy &req, IEspCopyResponse
         const char* destNodeGroupReq = req.getDestGroup();
         if(!destNodeGroupReq || !*destNodeGroupReq)
         {
-            getNodeGroupFromLFN(destNodeGroup, srcname, context.queryUserId(), context.queryPassword());
+            getNodeGroupFromLFN(context, srcname, destNodeGroup);
             DBGLOG("Destination node group not specified, using source node group %s", destNodeGroup.str());
         }
         else

+ 1 - 0
esp/services/ws_sql/CMakeLists.txt

@@ -83,6 +83,7 @@ if(WSSQL_SERVICE)
         ${HPCC_SOURCE_DIR}/dali/dfu
         ${HPCC_SOURCE_DIR}/dali/base/
         ${HPCC_SOURCE_DIR}/dali/sasha
+        ${HPCC_SOURCE_DIR}/dali/ft
         ${HPCC_SOURCE_DIR}/common/workunit
         ${HPCC_SOURCE_DIR}/common/remote
         ${HPCC_SOURCE_DIR}/common/environment

+ 1 - 0
esp/services/ws_workunits/CMakeLists.txt

@@ -89,6 +89,7 @@ include_directories (
          ./../../smc/SMCLib
          ./../../bindings/SOAP/xpp
          ${HPCC_SOURCE_DIR}/dali/dfu
+         ${HPCC_SOURCE_DIR}/dali/ft
          ./../../../testing/unittests
     )
 

+ 5 - 10
esp/services/ws_workunits/ws_workunitsHelpers.cpp

@@ -30,6 +30,7 @@
 #include "wujobq.hpp"
 #include "hqlexpr.hpp"
 #include "rmtsmtp.hpp"
+#include "LogicFileWrapper.hpp"
 
 #ifndef _NO_LDAP
 #include "ldapsecurity.ipp"
@@ -135,11 +136,9 @@ void ensureWsCreateWorkunitAccess(IEspContext& ctx)
 
 StringBuffer &getWuidFromLogicalFileName(IEspContext &context, const char *logicalName, StringBuffer &wuid)
 {
-    Owned<IUserDescriptor> userdesc = createUserDescriptor();
-    userdesc->set(context.queryUserId(), context.queryPassword(), context.querySignature());
-    Owned<IDistributedFile> df = queryDistributedFileDirectory().lookup(logicalName, userdesc, false, false, false, nullptr, defaultPrivilegedUser);
+    Owned<IDistributedFile> df = lookupLogicalName(context, logicalName, false, false, false, nullptr, defaultPrivilegedUser);
     if (!df)
-        throw MakeStringException(ECLWATCH_FILE_NOT_EXIST,"Cannot find file %s.",logicalName);
+        throw makeStringExceptionV(ECLWATCH_FILE_NOT_EXIST, "Cannot find file %s.", logicalName);
     return wuid.append(df->queryAttributes().queryProp("@workunit"));
 }
 
@@ -1360,13 +1359,9 @@ void WsWuInfo::getWorkflow(IEspECLWorkunit &info, unsigned long flags)
 
 IDistributedFile* WsWuInfo::getLogicalFileData(IEspContext& context, const char* logicalName, bool& showFileContent)
 {
-    StringBuffer username;
-    context.getUserID(username);
-    Owned<IUserDescriptor> userdesc(createUserDescriptor());
-    userdesc->set(username.str(), context.queryPassword(), context.querySignature());
-    Owned<IDistributedFile> df = queryDistributedFileDirectory().lookup(logicalName, userdesc, false, false, false, nullptr, defaultPrivilegedUser);
+    Owned<IDistributedFile> df = lookupLogicalName(context, logicalName, false, false, false, nullptr, defaultPrivilegedUser);
     if (!df)
-        return NULL;
+        return nullptr;
 
     bool blocked;
     if (df->isCompressed(&blocked) && !blocked)

+ 3 - 18
esp/services/ws_workunits/ws_workunitsService.cpp

@@ -48,6 +48,7 @@
 #include "ws_wudetails.hpp"
 #include "wuerror.hpp"
 #include "TpWrapper.hpp"
+#include "LogicFileWrapper.hpp"
 
 #include "rtlformat.hpp"
 
@@ -2912,7 +2913,7 @@ void CWsWorkunitsEx::getWsWuResult(IEspContext &context, const char *wuid, const
             result->getResultFilename(logicalName);
         if (logicalName.length())
         {
-            Owned<IDistributedFile> df = lookupLogicalName(context, logicalName.str());
+            Owned<IDistributedFile> df = lookupLogicalName(context, logicalName.str(), false, false, false, nullptr, defaultPrivilegedUser);
             if (!df)
                 throw makeStringExceptionV(ECLWATCH_FILE_NOT_EXIST, "Cannot find file %s.", logicalName.str());
             resultSz = df->getDiskSize(true, false);
@@ -3244,26 +3245,10 @@ void getWorkunitCluster(IEspContext &context, const char *wuid, SCMStringBuffer
     }
 }
 
-IDistributedFile *CWsWorkunitsEx::lookupLogicalName(IEspContext &context, const char *logicalName)
-{
-    StringBuffer userID;
-    context.getUserID(userID);
-    Owned<IUserDescriptor> userDesc;
-    if (!userID.isEmpty())
-    {
-        userDesc.setown(createUserDescriptor());
-        userDesc->set(userID, context.queryPassword(), context.querySignature());
-    }
-
-    Owned<IDistributedFile> df = queryDistributedFileDirectory().lookup(logicalName, userDesc, false,
-        false, false, nullptr, defaultPrivilegedUser);
-    return df.getClear();
-}
-
 void CWsWorkunitsEx::getFileResults(IEspContext &context, const char *logicalName, const char *cluster, __int64 start, unsigned &count, __int64 &total,
     IStringVal &resname, bool bin, IArrayOf<IConstNamedValue> *filterBy, MemoryBuffer &buf, bool xsd)
 {
-    Owned<IDistributedFile> df = lookupLogicalName(context, logicalName);
+    Owned<IDistributedFile> df = lookupLogicalName(context, logicalName, false, false, false, nullptr, defaultPrivilegedUser);
     if (!df)
         throw makeStringExceptionV(ECLWATCH_FILE_NOT_EXIST, "Cannot find file %s.", logicalName);
 

+ 0 - 1
esp/services/ws_workunits/ws_workunitsService.hpp

@@ -392,7 +392,6 @@ private:
         WUState &wuState, bool xsd=true);
     void getFileResults(IEspContext &context, const char *logicalName, const char *cluster, __int64 start, unsigned &count, __int64 &total,
         IStringVal &resname, bool bin, IArrayOf<IConstNamedValue> *filterBy, MemoryBuffer &buf, bool xsd);
-    IDistributedFile *lookupLogicalName(IEspContext &contcontext, const char *logicalName);
     void getSuspendedQueriesByCluster(MapStringTo<bool> &suspendedByCluster, const char *querySet, const char *queryID, bool checkAllNodes);
     void addSuspendedQueryIDs(MapStringTo<bool> &suspendedQueryIDs, IPropertyTree *queriesOnCluster, const char *target);
     void getWUQueryDetails(IEspContext &context, CWUQueryDetailsReq &req, IEspWUQueryDetailsResponse &resp);

+ 26 - 0
esp/smc/SMCLib/LogicFileWrapper.cpp

@@ -21,6 +21,7 @@
 
 #include "LogicFileWrapper.hpp"
 #include "dautils.hpp"
+#include "exception_util.hpp"
 
 //////////////////////////////////////////////////////////////////////
 // Construction/Destruction
@@ -126,3 +127,28 @@ bool LogicFileWrapper::doCompressFile(const char* name,StringBuffer& returnStr,
 
     return true; 
 }
+
+IDistributedFile* lookupLogicalName(IEspContext& context, const char* logicalName, bool writeattr, bool hold,
+    bool lockSuperOwner, IDistributedFileTransaction* transaction, bool privilegedUser, unsigned timeout)
+{
+    StringBuffer userID;
+    context.getUserID(userID);
+    Owned<IUserDescriptor> userDesc;
+    if (!userID.isEmpty())
+    {
+        userDesc.setown(createUserDescriptor());
+        userDesc->set(userID, context.queryPassword(), context.querySignature());
+    }
+
+    Owned<IDistributedFile> df = queryDistributedFileDirectory().lookup(logicalName, userDesc, writeattr,
+        hold, lockSuperOwner, transaction, privilegedUser, timeout);
+    return df.getClear();
+}
+
+void getNodeGroupFromLFN(IEspContext& context, const char* lfn, StringBuffer& nodeGroup)
+{
+    Owned<IDistributedFile> df = lookupLogicalName(context, lfn, false, false, false, nullptr, defaultPrivilegedUser);
+    if (!df)
+        throw makeStringExceptionV(ECLWATCH_FILE_NOT_EXIST, "Failed to find file: %s", lfn);
+    df->getClusterGroupName(0, nodeGroup);
+}

+ 5 - 0
esp/smc/SMCLib/LogicFileWrapper.hpp

@@ -35,6 +35,7 @@
 #include "daft.hpp"
 #include "dalienv.hpp"
 #include "jpqueue.hpp"
+#include "esp.hpp"
 
 class LFWRAPPER_API LogicFileWrapper : public CInterface  
 {
@@ -159,4 +160,8 @@ struct CompressTask: public CInterface, implements ITask
     Linked<IDistributedFilePart> part;
 };
 
+extern LFWRAPPER_API IDistributedFile* lookupLogicalName(IEspContext& contcontext, const char* logicalName, bool writeattr,
+    bool hold, bool lockSuperOwner, IDistributedFileTransaction* transaction, bool privilegedUser, unsigned timeout=INFINITE);
+extern LFWRAPPER_API void getNodeGroupFromLFN(IEspContext& context, const char* lfn, StringBuffer& nodeGroup);
+
 #endif //__DFUWrapper_HPP__