ProcessAutomation2.ecl 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. //
  2. // Example code - use without restriction.
  3. //
  4. IMPORT $;
  5. IMPORT Std;
  6. Linux := TRUE;
  7. Slash := IF(Linux = TRUE,'/','\\'); //default is Linux. If the LZ is a Windows box, this must change to '\\'
  8. Layout_Sprays := MODULE
  9. export Layout_Names := RECORD
  10. STRING name;
  11. END;
  12. export ChildNames := RECORD
  13. STRING RemoteFilename;
  14. STRING ThorLogicalFilename;
  15. END;
  16. export Info := RECORD
  17. STRING SourceIP; // Landing Zone's IP address
  18. STRING SourceDirectory; // Absolute path of directory on Landing Zone where files are located
  19. STRING directory_filter := '*'; // Regular expression filter for files to be sprayed, default = '*'
  20. UNSIGNED4 RECORD_size := 0; // RECORD length of files to be sprayed (for fixed length files only)
  21. STRING Thor_filename_template; // template filename for files to be sprayed, ex. '~thor::in::@version@::cont'
  22. DATASET(Layout_Names) dSuperfilenames; // DATASET of superfiles to add the sprayed files to.
  23. STRING GroupName := '\'thor\''; // Thor Group (cluster) name
  24. STRING FileDate := ''; // version of all of the sprayed files (overrides the next field, dateregex).
  25. STRING date_regex := '[0-9]{8}'; // regular expression to get the date from the remote filenames.
  26. STRING file_type := 'FIXED'; // Type of file format. Possible types are 'FIXED', 'VARIABLE', OR 'XML'.
  27. STRING sourceRowTagXML := ''; // XML Row tag. Only used when file_type = 'XML'.
  28. INTEGER4 sourceMaxRecordSize := 8192; // Maximum RECORD size for Variable OR XML files.
  29. STRING sourceCsvSeparate := '\\,'; // Field separator for variable length RECORDs only.
  30. STRING sourceCsvTerminate := '\\n,\\r\\n'; // Record separator for variable length RECORDs only.
  31. STRING sourceCsvQuote := '"'; // Quoted Field delimiter for variable length RECORDs only.
  32. BOOLEAN compress := FALSE; // TRUE = Compress, FALSE = Don't compress.
  33. END;
  34. export InfoOut := RECORD
  35. STRING SourceIP;
  36. STRING SourceDirectory;
  37. STRING directory_filter := '*';
  38. UNSIGNED4 RECORD_size := 0;
  39. STRING Thor_filename_template;
  40. DATASET(ChildNames) dFilesToSpray;
  41. DATASET(Layout_Names) dSuperfilenames;
  42. STRING GroupName := '\'thor\'';
  43. STRING FileDate := '';
  44. STRING date_regex := '[0-9]{8}';
  45. STRING file_type := 'FIXED'; // CAN BE 'VARIABLE', OR 'XML'
  46. STRING sourceRowTagXML := '';
  47. INTEGER4 sourceMaxRecordSize := 8192;
  48. STRING sourceCsvSeparate := '\\,';
  49. STRING sourceCsvTerminate := '\\n,\\r\\n';
  50. STRING sourceCsvQuote := '"';
  51. BOOLEAN compress := TRUE;
  52. UNSIGNED4 remotefilescount := 0 ;
  53. END;
  54. END;
  55. fSprayInputFiles(DATASET(Layout_Sprays.Info) pSprayInformation,
  56. STRING pSprayRecordSuperfile = '',
  57. BOOLEAN pIsTesting = FALSE) := FUNCTION
  58. // -- Get directory listings using the passed filter for all RECORDs in passed DATASET
  59. layout_directory_listings := RECORD
  60. pSprayInformation;
  61. DATASET(Std.File.FsFileNameRecord) dDirectoryListing;
  62. UNSIGNED4 remotefilescount;
  63. END;
  64. layout_directory_listings tGetDirs(Layout_Sprays.Info l) := TRANSFORM
  65. SELF.dDirectoryListing := Std.File.remotedirectory(l.SourceIP, l.SourceDirectory, l.directory_filter);
  66. SELF.remotefilescount := COUNT(SELF.dDirectoryListing);
  67. SELF := l;
  68. END;
  69. directory_listings := PROJECT(pSprayInformation, tGetDirs(left));
  70. fSetLogicalFilenames(DATASET(Std.File.FsFileNameRecord) pRemotefilenames,
  71. STRING pTemplatefilename,
  72. STRING pDate,
  73. STRING1 pFlag,
  74. UNSIGNED4 pRemotefilesCount) := FUNCTION
  75. Layout_Sprays.ChildNames tSetLogicalFilenames(pRemotefilenames l, UNSIGNED4 pCounter) := TRANSFORM
  76. // first check to see if filedate is set
  77. // if not, then use regex if not blank
  78. // if not, use current date
  79. filenameversion := MAP(pFlag = 'F' AND pDate != '' => pDate,
  80. pFlag = 'R' AND pDate != '' AND REGEXFIND(pDate,l.name) => REGEXFIND(pDate,l.name, 0),
  81. WORKUNIT[2..9]);
  82. LogicalFilename := REGEXREPLACE( '@version@',pTemplatefilename,filenameversion);
  83. SELF.RemoteFilename := l.name;
  84. SELF.ThorLogicalFilename := IF(pRemotefilesCount = 1,
  85. LogicalFilename,
  86. LogicalFilename + '_' + (STRING) pCounter);
  87. END;
  88. RETURN PROJECT(pRemotefilenames, tSetLogicalFilenames(LEFT,COUNTER));
  89. END;
  90. // -- finalize DATASET before spray
  91. Layout_Sprays.InfoOut tGetReadyToSpray(layout_directory_listings l) := TRANSFORM
  92. lDate := MAP(l.FileDate != '' => l.Filedate,
  93. l.date_regex != '' => l.date_regex,
  94. '');
  95. lFlag := MAP(l.FileDate != '' => 'F',
  96. l.date_regex != '' => 'R',
  97. '');
  98. SELF.dFilesToSpray := fSetLogicalFilenames(l.dDirectoryListing,
  99. l.Thor_filename_template,
  100. lDate, lFlag, l.remotefilescount);
  101. SELF := l;
  102. END;
  103. dReadyToSpray := PROJECT(directory_listings, tGetReadyToSpray(LEFT));
  104. outputwork := OUTPUT(dReadyToSpray, ALL);
  105. // -- Spray Files
  106. SprayFixedFiles(STRING pSourceIP,
  107. STRING pSourcePath,
  108. DATASET(Layout_Sprays.childnames) pfilestospray,
  109. INTEGER4 pRecordLength,
  110. STRING pGroupName,
  111. BOOLEAN pCompress) :=
  112. APPLY(pfilestospray, IF(NOT(Std.File.FileExists(ThorLogicalFilename) OR
  113. Std.File.SuperFileExists(ThorLogicalFilename)),
  114. Std.File.SprayFixed(pSourceIP,
  115. pSourcePath + Slash + RemoteFilename,
  116. pRecordLength,
  117. pGroupName,
  118. ThorLogicalFilename,,,,,TRUE,
  119. pCompress),
  120. OUTPUT(ThorLogicalFilename + ' already exists, skipping spray.')));
  121. // AddSuperfile(DATASET(Layout_Sprays.childnames) plogicalnames, STRING pSuperfilename) :=
  122. // APPLY(plogicalnames, Std.File.addsuperfile(pSuperfilename, ThorLogicalFilename));
  123. AddSuperfile(DATASET(Layout_Sprays.childnames) plogicalnames, STRING pSuperfilename) :=
  124. SEQUENTIAL(Std.File.StartSuperfileTransaction(),
  125. APPLY(plogicalnames, Std.File.AddSuperfile(pSuperfilename, ThorLogicalFilename)),
  126. Std.File.FinishSuperfileTransaction());
  127. AddToSuperfiles(DATASET(Layout_Sprays.childnames) plogicalnames,
  128. DATASET(Layout_Sprays.Layout_Names) pSuperfilenames) :=
  129. APPLY(pSuperfilenames, AddSuperfile(plogicalnames, name));
  130. SprayVariableFiles(STRING pSourceIP,
  131. STRING pSourcePath,
  132. INTEGER4 pMaxRecordSize,
  133. VARSTRING pSourceCsvSeparate,
  134. VARSTRING pSourceCsvTerminate,
  135. VARSTRING pSourceCsvQuote,
  136. DATASET(Layout_Sprays.childnames) pfilestospray,
  137. STRING pGroupName,
  138. BOOLEAN pCompress) :=
  139. APPLY(pfilestospray, IF(NOT(Std.File.FileExists(ThorLogicalFilename) OR
  140. Std.File.SuperFileExists(ThorLogicalFilename)),
  141. Std.File.SprayVariable(pSourceIP,
  142. pSourcePath + Slash + RemoteFilename,
  143. pMaxRecordSize,
  144. pSourceCsvSeparate,
  145. pSourceCsvTerminate,
  146. pSourceCsvQuote,
  147. pGroupName,
  148. ThorLogicalFilename,,,,,
  149. TRUE,pCompress),
  150. OUTPUT(ThorLogicalFilename + ' already exists, skipping spray.')));
  151. SprayXMLFiles(STRING pSourceIP,
  152. STRING pSourcePath,
  153. INTEGER4 pMaxRecordSize,
  154. VARSTRING psourceRowTag,
  155. DATASET(Layout_Sprays.childnames) pfilestospray,
  156. STRING pGroupName,
  157. BOOLEAN pCompress) :=
  158. APPLY(pfilestospray, IF(NOT(Std.File.FileExists(ThorLogicalFilename) OR
  159. Std.File.SuperFileExists(ThorLogicalFilename)),
  160. Std.File.SprayXml(pSourceIP,
  161. pSourcePath + Slash + RemoteFilename,
  162. pMaxRecordSize,
  163. psourceRowTag,,
  164. pGroupName,
  165. ThorLogicalFilename,,,,,
  166. TRUE,
  167. pCompress),
  168. OUTPUT(ThorLogicalFilename + ' already exists, skipping spray.')));
  169. spray_files := APPLY(dReadyToSpray,
  170. SEQUENTIAL(CASE(file_type,
  171. 'FIXED' => SprayFixedFiles(SourceIP,
  172. SourceDirectory,
  173. dFilesToSpray,
  174. RECORD_size,
  175. GroupName,
  176. compress),
  177. 'VARIABLE' => SprayVariableFiles(SourceIP,
  178. SourceDirectory,
  179. sourceMaxRecordSize,
  180. sourceCsvSeparate,
  181. sourceCsvTerminate,
  182. sourceCsvQuote,
  183. dFilesToSpray,
  184. GroupName,
  185. compress),
  186. 'XML' => SprayXMLFiles(SourceIP,
  187. SourceDirectory,
  188. sourceMaxRecordSize,
  189. sourceRowTagXML,
  190. dFilesToSpray,
  191. GroupName,
  192. compress),
  193. OUTPUT('Bad File type: ' + file_type + ' on record')),
  194. AddToSuperfiles(dFilesToSpray, dSuperfilenames)));
  195. RETURN IF(pIsTesting = FALSE,
  196. SEQUENTIAL(OUTPUTwork,NOTHOR(spray_files)),
  197. SEQUENTIAL(OUTPUTwork));
  198. END;
  199. FilesToSpray := DATASET([
  200. {$.DeclareData.LZ_IP,
  201. $.DeclareData.LZ_Dir,
  202. 'People*.d00',
  203. 89,
  204. '~$.DeclareData::AUTOMATION::@version@::Fixed',
  205. [{'~$.DeclareData::AUTOMATION::Fixed'}],
  206. 'thor',
  207. '20061013',
  208. '[0-9]{8}',
  209. 'FIXED',
  210. '',
  211. 8192,
  212. '\\,',
  213. '\\n,\\r\\n',
  214. '"',
  215. FALSE
  216. }//,
  217. // {LZ_IP,
  218. // LZ_Dir,
  219. // 'People*.xml',
  220. // 0,
  221. // '~$.DeclareData::AUTOMATION::@version@::XML',
  222. // [{'~$.DeclareData::AUTOMATION::XML'}],
  223. // 'thor',
  224. // '20061013',
  225. // '',
  226. // 'XML',
  227. // 'Row'},
  228. // {LZ_IP,
  229. // LZ_Dir,
  230. // 'People*.csv',
  231. // 0,
  232. // '~$.DeclareData::AUTOMATION::@version@::CSV' ,
  233. // [{'~$.DeclareData::AUTOMATION::CSV'}],
  234. // 'thor',
  235. // '20061013',
  236. // '',
  237. // 'VARIABLE'}
  238. ], Layout_Sprays.Info);
  239. // output(FilesToSpray);
  240. fSprayInputFiles(FilesToSpray);