Pārlūkot izejas kodu

HPCC-13495 Use correct default target directory for despray

The existing ESP code calls the RemoteFilename::setPath()
to set the target directory for despray. If a user does
not specify the target directory, the setPath() uses the
/var/lib/HPCCSystems/myesp as default target directory. In
this fix, If a user does not specify the target directory,
I use the target IP to retrieve the drop zone directory on
that IP and use the drop zone directory to be default
target directory.

Signed-off-by: wangkx <kevin.wang@lexisnexis.com>
wangkx 10 gadi atpakaļ
vecāks
revīzija
bfaebbfeb6

+ 59 - 1
esp/services/ws_fs/ws_fsService.cpp

@@ -2278,6 +2278,55 @@ bool CFileSprayEx::onReplicate(IEspContext &context, IEspReplicate &req, IEspRep
     return true;
     return true;
 }
 }
 
 
+const char* CFileSprayEx::getDropZoneDirByIP(const char* ip, StringBuffer& dir)
+{
+    if (!ip || !*ip)
+        return NULL;
+
+    Owned<IEnvironmentFactory> factory = getEnvironmentFactory();
+    Owned<IConstEnvironment> env = factory->openEnvironment();
+    if (!env)
+        return NULL;
+
+    Owned<IPropertyTree> root = &env->getPTree();
+    VStringBuffer xPath("Hardware/Computer[@netAddress='%s']/@name", ip);
+    const char* computer = root->queryProp(xPath.str());
+    if (!computer || !*computer)
+    {
+        StringBuffer localHostIP;
+        queryHostIP().getIpText(localHostIP);
+        if (!strieq(".", ip) && !strieq("localhost", ip) && !strieq("127.0.0.1", ip) && !strieq(ip, localHostIP.str()))
+            return NULL;
+
+        StringArray possibleIPs;
+        if (!strieq(".", ip))
+            possibleIPs.append(".");
+        if (!strieq("localhost", ip))
+            possibleIPs.append("localhost");
+        if (!strieq("127.0.0.1", ip))
+            possibleIPs.append("127.0.0.1");
+        if (!strieq(localHostIP.str(), ip))
+            possibleIPs.append(localHostIP.str());
+
+        ForEachItemIn(i, possibleIPs)
+        {
+            xPath.setf("Hardware/Computer[@netAddress='%s']/@name", possibleIPs.item(i));
+            computer = root->queryProp(xPath.str());
+            if (computer && *computer)
+                break;
+        }
+        if (!computer || !*computer)
+            return NULL;
+    }
+
+    xPath.setf("Software/DropZone[@computer='%s']/@directory", computer);
+    const char* path = root->queryProp(xPath.str());
+    if (!path || !*path)
+        return NULL;
+
+    return dir.append(path).str();
+}
+
 bool CFileSprayEx::onDespray(IEspContext &context, IEspDespray &req, IEspDesprayResponse &resp)
 bool CFileSprayEx::onDespray(IEspContext &context, IEspDespray &req, IEspDesprayResponse &resp)
 {
 {
     try
     try
@@ -2325,7 +2374,16 @@ bool CFileSprayEx::onDespray(IEspContext &context, IEspDespray &req, IEspDespray
         {
         {
             RemoteFilename rfn;
             RemoteFilename rfn;
             SocketEndpoint ep(destip);
             SocketEndpoint ep(destip);
-            rfn.setPath(ep, destfile);
+            if (isAbsolutePath(destfile))
+                rfn.setPath(ep, destfile);
+            else
+            {
+                StringBuffer buf;
+                getDropZoneDirByIP(destip, buf);
+                if (buf.length() && buf.charAt(buf.length()-1) != PATHSEPCHAR)
+                    buf.append(PATHSEPCHAR);
+                rfn.setPath(ep, buf.append(destfile).str());
+            }
             destination->setSingleFilename(rfn);
             destination->setSingleFilename(rfn);
         }
         }
         else
         else

+ 1 - 0
esp/services/ws_fs/ws_fsService.hpp

@@ -114,6 +114,7 @@ protected:
     StringBuffer& getAcceptLanguage(IEspContext& context, StringBuffer& acceptLanguage);
     StringBuffer& getAcceptLanguage(IEspContext& context, StringBuffer& acceptLanguage);
     void appendGroupNode(IArrayOf<IEspGroupNode>& groupNodes, const char* nodeName, const char* clusterType, bool replicateOutputs);
     void appendGroupNode(IArrayOf<IEspGroupNode>& groupNodes, const char* nodeName, const char* clusterType, bool replicateOutputs);
     bool getOneDFUWorkunit(IEspContext& context, const char* wuid, IEspGetDFUWorkunitsResponse& resp);
     bool getOneDFUWorkunit(IEspContext& context, const char* wuid, IEspGetDFUWorkunitsResponse& resp);
+    const char* getDropZoneDirByIP(const char* destIP, StringBuffer& dir);
 };
 };
 
 
 #endif //_ESPWIZ_FileSpray_HPP__
 #endif //_ESPWIZ_FileSpray_HPP__