Browse Source

HPCC-21784 Add option to ForeignLogicalFileName to suppress cluster prefix

Signed-off-by: Jake Smith <jake.smith@lexisnexisrisk.com>
Jake Smith 6 years ago
parent
commit
3946ebc4f2

+ 9 - 0
docs/EN_US/ECLStandardLibraryReference/SLR-Mods/ForeignLogicalFileName.xml

@@ -13,6 +13,7 @@
     </indexterm>(</emphasis> <emphasis>filename </emphasis> <emphasis
   role="bold">[,</emphasis> <emphasis>foreigndali </emphasis> <emphasis
   role="bold">] [,</emphasis> <emphasis>absolutepath</emphasis> <emphasis
+  role="bold">] [,</emphasis> <emphasis>omitClusterPrefix</emphasis> <emphasis
   role="bold">] )</emphasis></para>
 
   <informaltable colsep="1" frame="all" rowsep="1">
@@ -47,6 +48,14 @@
         </row>
 
         <row>
+          <entry><emphasis>omitClusterPreifx</emphasis></entry>
+
+          <entry>Optional. A boolean TRUE/FALSE to indicate whether the target
+          cluster's prefix should automatically be added if 'filename' is a
+          relative logical file name. If omitted, the default is FALSE.</entry>
+        </row>
+
+        <row>
           <entry>Return:<emphasis> </emphasis></entry>
 
           <entry>ForeignLogicalFileName returns returns a VARSTRING

+ 2 - 2
ecllibrary/std/File.ecl

@@ -149,8 +149,8 @@ EXPORT RenameLogicalFile(varstring oldname, varstring newname, boolean allowOver
  * @param abspath       Should a tilde (~) be prepended to the resulting logical file name.  Defaults to FALSE.
  */
 
-EXPORT varstring ForeignLogicalFileName(varstring name, varstring foreigndali='', boolean abspath=FALSE) :=
-    lib_fileservices.FileServices.ForeignLogicalFileName(name, foreigndali, abspath);
+EXPORT varstring ForeignLogicalFileName(varstring name, varstring foreigndali='', boolean abspath=FALSE, boolean omitClusterPrefix=FALSE) :=
+    lib_fileservices.FileServices.ForeignLogicalFileName(name, foreigndali, abspath, omitClusterPrefix);
 
 /**
  * Returns an encoded logical filename that can be used to refer to a external file.  Examples include directly

+ 17 - 3
plugins/fileservices/fileservices.cpp

@@ -92,7 +92,7 @@ static const char * EclDefinition =
 "  SwapSuperFile(const varstring lsuperfn1,const varstring lsuperfn2) : c,action,globalcontext,entrypoint='fsSwapSuperFile'; \n"
 "  ReplaceSuperFile(const varstring lsuperfn,const varstring lfn,const varstring bylfn) : c,action,globalcontext,entrypoint='fsReplaceSuperFile'; \n"
 "  FinishSuperFileTransaction(boolean rollback=false) : c,action,globalcontext,entrypoint='fsFinishSuperFileTransaction'; \n"
-"  varstring ForeignLogicalFileName(const varstring name, const varstring foreigndali='', boolean abspath=false) : c,context,entrypoint='fsForeignLogicalFileName'; \n"
+"  varstring ForeignLogicalFileName(const varstring name, const varstring foreigndali='', boolean abspath=false, boolean omitClusterPrefix=false) : c,context,entrypoint='fsForeignLogicalFileName_v2'; \n"
 "  varstring WaitDfuWorkunit(const varstring wuid, integer4 timeOut=-1,const varstring espServerIpPort=GETENV('ws_fs_server')) : c,action,globalcontext,entrypoint='fsWaitDfuWorkunit'; \n"
 "  AbortDfuWorkunit(const varstring wuid,const varstring espServerIpPort=GETENV('ws_fs_server')) : c,action,globalcontext,entrypoint='fsAbortDfuWorkunit'; \n"
 "  MonitorLogicalFileName(const varstring event_name, const varstring name, integer4 shotcount=1,const varstring espServerIpPort=GETENV('ws_fs_server')) : c,action,context,entrypoint='fsMonitorLogicalFileName'; \n"
@@ -1611,10 +1611,14 @@ FILESERVICES_API void FILESERVICES_CALL fslFinishSuperFileTransaction(ICodeConte
 }
 
 
-FILESERVICES_API char *  FILESERVICES_CALL fsForeignLogicalFileName(ICodeContext *ctx, const char *_lfn,const char *foreigndali,bool abspath)
+static char * implementForeignLogicalFileName(ICodeContext *ctx, const char *_lfn, const char *foreigndali, bool abspath, bool omitClusterPrefix)
 {
     StringBuffer lfns;
-    constructLogicalName(ctx, _lfn, lfns);
+
+    Owned<IConstWorkUnit> wu;
+    if (!omitClusterPrefix && _lfn&&(*_lfn != '~'))
+        wu.setown(getWorkunit(ctx));
+    constructLogicalName(wu, _lfn, lfns);
     CDfsLogicalFileName lfn;
     lfn.set(lfns.str());
     if (foreigndali&&*foreigndali) {
@@ -1630,6 +1634,16 @@ FILESERVICES_API char *  FILESERVICES_CALL fsForeignLogicalFileName(ICodeContext
     return ret.detach();
 }
 
+FILESERVICES_API char *  FILESERVICES_CALL fsForeignLogicalFileName(ICodeContext *ctx, const char *lfn, const char *foreigndali, bool abspath)
+{
+    return implementForeignLogicalFileName(ctx, lfn, foreigndali, abspath, false);
+}
+
+FILESERVICES_API char *  FILESERVICES_CALL fsForeignLogicalFileName_v2(ICodeContext *ctx, const char *lfn, const char *foreigndali, bool abspath, bool omitClusterPrefix)
+{
+    return implementForeignLogicalFileName(ctx, lfn, foreigndali, abspath, omitClusterPrefix);
+}
+
 
 FILESERVICES_API char *  FILESERVICES_CALL fsExternalLogicalFileName(const char *location,const char *path,bool abspath)
 {

+ 1 - 0
plugins/fileservices/fileservices.hpp

@@ -82,6 +82,7 @@ FILESERVICES_API void FILESERVICES_CALL fsSwapSuperFile(IGlobalCodeContext *ctx,
 FILESERVICES_API void FILESERVICES_CALL fsReplaceSuperFile(IGlobalCodeContext *ctx, const char *lsuperfn,const char *lfn,const char *bylfn);
 FILESERVICES_API void FILESERVICES_CALL fsFinishSuperFileTransaction(IGlobalCodeContext *ctx, bool rollback=false);
 FILESERVICES_API char *  FILESERVICES_CALL fsForeignLogicalFileName(ICodeContext *ctx, const char *_lfn,const char *foreigndali,bool abspath);
+FILESERVICES_API char *  FILESERVICES_CALL fsForeignLogicalFileName_v2(ICodeContext *ctx, const char *_lfn,const char *foreigndali,bool abspath,bool omitClusterPrefix);
 FILESERVICES_API char *  FILESERVICES_CALL fsWaitDfuWorkunit(IGlobalCodeContext *ctx, const char *wuid, int timeout, const char * espServerIpPort);
 FILESERVICES_API void FILESERVICES_CALL fsAbortDfuWorkunit(IGlobalCodeContext *ctx, const char *wuid, const char * espServerIpPort);
 FILESERVICES_API void  FILESERVICES_CALL fsMonitorLogicalFileName(ICodeContext *ctx, const char *eventname, const char *_lfn,int shotcount, const char * espServerIpPort);

+ 10 - 0
testing/regress/ecl/fileservice.ecl

@@ -16,6 +16,7 @@
 ############################################################################## */
 
 import Std.File;
+import Std.Str;
 import $.setup;
 prefix := setup.Files(false, false).QueryFilePrefix;
 
@@ -33,6 +34,11 @@ string compareDatasets(dataset(rec) ds1, dataset(rec) ds2) := FUNCTION
    RETURN if(result, 'Pass', 'Fail');
 END;
 
+RemovePrefix(string lfn, unsigned scopes) := FUNCTION
+  unsigned4 postPrefixPos := Str.Find(lfn, '::', scopes);
+  unsigned4 postScopePos := IF(postPrefixPos=0, 1, postPrefixPos+2); // ensures valid if mismatch
+  return lfn[postScopePos..];
+END;
 
 SEQUENTIAL(
   OUTPUT(ds, , prefix + 'renametest.d00', OVERWRITE),
@@ -47,4 +53,8 @@ SEQUENTIAL(
   File.RenameLogicalFile(prefix + 'renametest.d00', prefix + 'afterrename1.d00', true),
   output(compareDatasets(ds, ds2)),
   File.DeleteLogicalFile(prefix + 'afterrename1.d00'),
+  RemovePrefix(File.ForeignLogicalFileName('somescope::somefilename', '192.168.168.168', true), 3);
+  RemovePrefix(File.ForeignLogicalFileName('somescope::somefilename', '192.168.168.168', false), 3);
+  RemovePrefix(File.ForeignLogicalFileName('somescope::somefilename', '192.168.168.168', true, true), 2);
+  RemovePrefix(File.ForeignLogicalFileName('somescope::somefilename', '192.168.168.168', false, true), 2);
 );

+ 12 - 0
testing/regress/ecl/key/fileservice.xml

@@ -14,3 +14,15 @@
 <Dataset name='Result 5'>
  <Row><Result_5>Pass</Result_5></Row>
 </Dataset>
+<Dataset name='Result 6'>
+ <Row><Result_6>somescope::somefilename</Result_6></Row>
+</Dataset>
+<Dataset name='Result 7'>
+ <Row><Result_7>somescope::somefilename</Result_7></Row>
+</Dataset>
+<Dataset name='Result 8'>
+ <Row><Result_8>somescope::somefilename</Result_8></Row>
+</Dataset>
+<Dataset name='Result 9'>
+ <Row><Result_9>somescope::somefilename</Result_9></Row>
+</Dataset>