Переглянути джерело

HPCC-18819 Add drop zone(s) discovery/listing features to fileservices for ECL programmers.

Implement GetDefaultDropZone() and GetDropZones() functions into Std.File

Update spray_test.ecl to use GetDefaultDropZone() function to eliminate hardwired path usage.

Signed-off-by: Attila Vamos <attila.vamos@gmail.com>
Attila Vamos 5 роки тому
батько
коміт
8d131e68da

+ 30 - 0
ecllibrary/std/File.ecl

@@ -97,6 +97,10 @@ EXPORT INTEGER4 PREFIX_VARIABLE_RECSIZE := lib_fileservices.PREFIX_VARIABLE_RECS
 
 EXPORT INTEGER4 PREFIX_VARIABLE_BIGENDIAN_RECSIZE := lib_fileservices.PREFIX_VARIABLE_BIGENDIAN_RECSIZE;
 
+EXPORT FsDropZone := lib_fileservices.FsDropZone;
+
+EXPORT FsDropZoneRecord := lib_fileservices.FsDropZoneRecord;
+
 /*------------------------------------- Spray functions -----------------------------------------------------------*/
 
 /**
@@ -959,4 +963,30 @@ EXPORT PromoteSuperFileList(set of varstring superNames, varstring addHead='', b
 EXPORT varstring GetEspURL(const varstring username = '', const varstring userPW = '') :=
     lib_fileservices.FileServices.GetEspURL(username, userPW);
 
+
+ /**
+ * Returns the path to the default Drop Zone
+ *
+ *
+ * @return              A string containing the path to the default Drop Zone.
+ *                      If more than one Drop Zone
+ *                      process is defined then the first found will
+ *                      be returned; will return an empty string if a Drop Zone
+ *                      cannot be found
+ */
+EXPORT varstring GetDefaultDropZone() :=
+    lib_fileservices.FileServices.GetDefaultDropZone();
+
+ /**
+ * Returns a dataset with full paths to all Drop Zones
+ *
+ *
+ * @return              A dataset containing all defined Drop Zone paths.
+ *                      Will return an empty dataset if a Drop Zone
+ *                      cannot be found
+ */
+
+EXPORT dataset(FsDropZoneRecord) GetDropZones() :=
+    lib_fileservices.FileServices.GetDropZones();
+
 END;

+ 32 - 0
plugins/fileservices/fileservices.cpp

@@ -60,6 +60,8 @@ static const char * EclDefinition =
 "export integer4 RECFMVB_RECSIZE := -1; // special value for SprayFixed record size \n"
 "export integer4 PREFIX_VARIABLE_RECSIZE := -3; // special value for SprayFixed record size \n"
 "export integer4 PREFIX_VARIABLE_BIGENDIAN_RECSIZE := -4; // special value for SprayFixed record size \n"
+"export FsDropZone := string; \n"
+"export FsDropZoneRecord := record FsDropZone dropzone; end; \n"
 "export FileServices := SERVICE : time\n"
 "  boolean FileExists(const varstring lfn, boolean physical=false) : c,context,entrypoint='fsFileExists'; \n"
 "  DeleteLogicalFile(const varstring lfn,boolean ifexists=false) : c,action,context,entrypoint='fsDeleteLogicalFile'; \n"
@@ -136,6 +138,8 @@ static const char * EclDefinition =
 "  ProtectLogicalFile(const varstring lfn,boolean set=true) : c,context,entrypoint='fsProtectLogicalFile'; \n"
 "  DfuPlusExec(const varstring cmdline) : c,context,entrypoint='fsDfuPlusExec'; \n"
 "  varstring GetEspURL(const varstring username = '', const varstring userPW = '') : c,once,entrypoint='fsGetEspURL'; \n"
+"  varstring GetDefaultDropZone() : c,once,entrypoint='fsGetDefaultDropZone'; \n"
+"  dataset(FsDropZoneRecord) GetDropZones() : c,context,entrypoint='fsGetDropZones'; \n"
 "END;";
 
 #define WAIT_SECONDS 30
@@ -2763,4 +2767,32 @@ FILESERVICES_API char * FILESERVICES_CALL fsGetEspURL(const char *username, cons
     return strdup("");
 }
 
+FILESERVICES_API char * FILESERVICES_CALL fsGetDefaultDropZone()
+{
+    Owned<IEnvironmentFactory> envFactory = getEnvironmentFactory(true);
+    Owned<IConstEnvironment> constEnv = envFactory-> openEnvironment();
+    Owned<IConstDropZoneInfoIterator> dropZoneIt = constEnv->getDropZoneIterator();
+    SCMStringBuffer dropZoneDir;
+    if (dropZoneIt->first())
+        dropZoneIt->query().getDirectory(dropZoneDir);
+
+    return strdup(dropZoneDir.str());
+}
 
+FILESERVICES_API void FILESERVICES_CALL fsGetDropZones(ICodeContext *ctx, size32_t & __lenResult, void * & __result)
+{
+    MemoryBuffer mb;
+    Owned<IEnvironmentFactory> envFactory = getEnvironmentFactory(true);
+    Owned<IConstEnvironment> constEnv = envFactory-> openEnvironment();
+    Owned<IConstDropZoneInfoIterator> dropZoneIt = constEnv->getDropZoneIterator();
+    ForEach(*dropZoneIt)
+    {
+        SCMStringBuffer dropZoneDir;
+        dropZoneIt->query().getDirectory(dropZoneDir);
+        size32_t sz = dropZoneDir.length();
+        mb.append(sz).append(sz,dropZoneDir.str());
+    }
+
+    __lenResult = mb.length();
+    __result = mb.detach();
+}

+ 2 - 0
plugins/fileservices/fileservices.hpp

@@ -161,6 +161,8 @@ FILESERVICES_API char * FILESERVICES_CALL fsfGetLogicalFileAttribute(ICodeContex
 FILESERVICES_API void FILESERVICES_CALL fsProtectLogicalFile(ICodeContext * ctx,const char *lfn,bool set);
 FILESERVICES_API void FILESERVICES_CALL fsDfuPlusExec(ICodeContext * ctx,const char *_cmd);
 FILESERVICES_API char * FILESERVICES_CALL fsGetEspURL(const char *username, const char *userPW);
+FILESERVICES_API char * FILESERVICES_CALL fsGetDefaultDropZone();
+FILESERVICES_API void FILESERVICES_CALL fsGetDropZones(ICodeContext *ctx,size32_t & __lenResult,void * & __result);
 
 }
 

+ 24 - 0
testing/regress/ecl/dropzone_query_test.ecl

@@ -0,0 +1,24 @@
+/*##############################################################################
+
+    Copyright (C) 2019 HPCC Systems®.
+
+    Licensed under the Apache License, Version 2.0 (the "License");
+    you may not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+############################################################################## */
+
+//nokey
+
+import Std.File AS FileServices;
+
+output(NOTHOR(FileServices.GetDefaultDropZone()));
+
+output(NOTHOR(FileServices.GetDropZones()));

+ 1 - 1
testing/regress/ecl/spray_test.ecl

@@ -34,7 +34,7 @@ prefix := setup.Files(false, false).QueryFilePrefix;
 boolean sprayFixed := #IFDEFINED(root.sprayFixed, true);
 boolean sprayEmpty := #IFDEFINED(root.sprayEmpty, false);
 
-dropzonePath := '/var/lib/HPCCSystems/mydropzone/' : STORED('dropzonePath');
+dropzonePath := FileServices.GetDefaultDropZone() +'/' : STORED('dropzonePath');
 
 unsigned VERBOSE := 0;