Browse Source

Merge pull request #12163 from rpastrana/my6.4

HPCC-21294 Ensure WsFILEIO handles newer Dropzone config structure

Reviewed-By: Kevin Wang <kevin.wang@lexisnexis.com>
Reviewed-By: Richard Chapman <rchapman@hpccsystems.com>
Richard Chapman 6 years ago
parent
commit
56f8c3559a
2 changed files with 66 additions and 82 deletions
  1. 1 1
      esp/scm/ws_fileio.ecm
  2. 65 81
      esp/services/ws_fileio/ws_fileioservice.cpp

+ 1 - 1
esp/scm/ws_fileio.ecm

@@ -19,7 +19,7 @@
 
 ESPrequest CreateFileRequest
 {
-    string DestDropZone;        //name or IP address; 
+    string DestDropZone;        //name or IP address
     string DestRelativePath;    //file name and/or path; related to the predefined directory of the dropzone
     bool   Overwrite(false);
 };

+ 65 - 81
esp/services/ws_fileio/ws_fileioservice.cpp

@@ -25,106 +25,90 @@
 #include "windows.h"
 #endif
 
-///#define FILE_DESPRAY_URL "FileDesprayAccess"
 #define FILE_IO_URL     "FileIOAccess"
 
 void CWsFileIOEx::init(IPropertyTree *cfg, const char *process, const char *service)
 {
 }
 
-bool CWsFileIOEx::CheckServerAccess(const char* server, const char* relPath, StringBuffer& netAddr, StringBuffer& absPath)
+bool CWsFileIOEx::CheckServerAccess(const char* targetDZNameOrAddress, const char* relPath, StringBuffer& netAddr, StringBuffer& absPath)
 {
-    if (!server || (server[0] == 0) || !relPath || (relPath[0] == 0))
+    if (!targetDZNameOrAddress || (targetDZNameOrAddress[0] == 0) || !relPath || (relPath[0] == 0))
         return false;
+
+    netAddr.clear();
     Owned<IEnvironmentFactory> factory = getEnvironmentFactory();
+    Owned<IConstEnvironment> env = factory->openEnvironment();
+    Owned<IConstDropZoneInfo> dropZoneInfo = env->getDropZone(targetDZNameOrAddress);
+    if (!dropZoneInfo || !dropZoneInfo->isECLWatchVisible())
+    {
+        if (stricmp(targetDZNameOrAddress, "localhost")==0)
+            targetDZNameOrAddress = ".";
 
-    Owned<IConstEnvironment> env;
-    env.setown(factory->openEnvironment());
+        Owned<IConstDropZoneInfoIterator> dropZoneItr = env->getDropZoneIteratorByAddress(targetDZNameOrAddress);
+        ForEach(*dropZoneItr)
+        {
+            IConstDropZoneInfo & dz = dropZoneItr->query();
+            if (dz.isECLWatchVisible())
+            {
+                dropZoneInfo.set(&dropZoneItr->query());
+                netAddr.set(targetDZNameOrAddress);
+                break;
+            }
+        }
+    }
 
-    Owned<IPropertyTree> pEnvRoot = &env->getPTree();
-    IPropertyTree* pEnvSoftware = pEnvRoot->queryPropTree("Software");
-    Owned<IPropertyTree> pRoot = createPTreeFromXMLString("<Environment/>");
-    IPropertyTree* pSoftware = pRoot->addPropTree("Software", createPTree("Software"));
-    if (pEnvSoftware && pSoftware)
+    if (dropZoneInfo)
     {
-        Owned<IPropertyTreeIterator> it = pEnvSoftware->getElements("DropZone");
-        ForEach(*it)
+        SCMStringBuffer directory, computerName, computerAddress;
+        if (netAddr.isEmpty())
         {
-            const char *zonename = it->query().queryProp("@computer");
-            if (!strcmp(zonename, "."))
-                zonename = "localhost";
-
-            if (zonename && *zonename)
+            dropZoneInfo->getComputerName(computerName); //legacy structure
+            if(computerName.length() != 0)
             {
-                StringBuffer xpath;
-                xpath.appendf("Hardware/Computer[@name='%s']/@netAddress", zonename);
-                char* addr = (char*) pEnvRoot->queryProp(xpath.str());
-                if (addr && *addr)
-                {           
-                    StringBuffer sNetAddr;
-                    if (strcmp(addr, "."))
-                    {       
-                        sNetAddr.append(addr);
-                    }
-                    else
+                Owned<IConstMachineInfo> machine = env->getMachine(computerName.str());
+                if (machine)
+                {
+                    machine->getNetAddress(computerAddress);
+                    if (computerAddress.length() != 0)
                     {
-                        StringBuffer ipStr;
-                        IpAddress ipaddr = queryHostIP();
-                        ipaddr.getIpText(ipStr);
-                        if (ipStr.length() > 0)
-                        {
-//#define MACHINE_IP "10.239.219.9"
-#ifdef MACHINE_IP
-                            sNetAddr.append(MACHINE_IP);
-#else
-                            sNetAddr.append(ipStr.str());
-#endif
-                        }
-                    }
-                    bool dropzoneFound = false;
-                    if (!stricmp(zonename, server))
-                    {
-                        dropzoneFound = true;
-                    }
-                    else if (!stricmp(sNetAddr.str(), server))
-                    {
-                        dropzoneFound = true;
-                    }
-                    
-                    if (!dropzoneFound)
-                    {
-                        continue;
-                    }
-
-                    char ch = '\\';
-                    Owned<IConstMachineInfo> machine = env->getMachineByAddress(addr);
-                    //Owned<IConstEnvironment> env = factory->openEnvironment();
-                    //Owned<IConstMachineInfo> machine = getMachineByAddress(pEnvRoot, env, addr);
-
-                    if (machine && (machine->getOS() == MachineOsLinux || machine->getOS() == MachineOsSolaris))
-                    {
-                        ch = '/';
-                    }
-                    
-                    StringBuffer dir;
-                    IPropertyTree* pDropZone = pSoftware->addPropTree("DropZone", &it->get());
-                    pDropZone->getProp("@directory", dir);
-                    if (dir.length() > 0)
-                    {
-                        if (relPath[0] != ch)
-                        {
-                            absPath.appendf("%s%c%s", dir.str(), ch, relPath);
-                        }
-                        else
-                        {
-                            absPath.appendf("%s%s", dir.str(), relPath);
-                        }
-                        netAddr = sNetAddr;
-                        return true;
+                        netAddr.set(computerAddress.str());
                     }
                 }
             }
+            else
+            {
+                Owned<IConstDropZoneServerInfoIterator> serverIter = dropZoneInfo->getServers();
+                ForEach(*serverIter)
+                {
+                    IConstDropZoneServerInfo &serverElem = serverIter->query();
+                    serverElem.getServer(netAddr.clear());
+                    if (!netAddr.isEmpty())
+                        break;
+                }
+            }
         }
+
+        dropZoneInfo->getDirectory(directory);
+        if (directory.length() != 0)
+        {
+            const char ch = getPathSepChar(directory.str());
+            if (relPath[0] != ch)
+            {
+                absPath.appendf("%s%c%s", directory.str(), ch, relPath);
+            }
+            else
+            {
+                absPath.appendf("%s%s", directory.str(), relPath);
+            }
+            return true;
+        }
+        else
+        {
+            SCMStringBuffer dropZoneName;
+            ESPLOG(LogMin, "Found LZ '%s' without a directory attribute!", dropZoneInfo->getName(dropZoneName).str());
+        }
+
     }
 
     return false;