-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathOmpareCacheClient.xml
6343 lines (5821 loc) · 234 KB
/
OmpareCacheClient.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?xml version="1.0" encoding="UTF-8"?>
<Export generator="Cache" version="24" zv="Cache for Windows (x86-64) 2010.2.8 (Build 1104U)" ts="2023-01-28 08:43:59">
<Class name="ompare.Schedule">
<Description><![CDATA[
<pre>
Copyright (c) Alex Woodhead 2020
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
License MIT
Source: https://github.com/alexatwoodhead/ompare
Version: 1.0
</pre>]]></Description>
<Super>%SYS.Task.Definition</Super>
<TimeChanged>66487,51930.541105</TimeChanged>
<TimeCreated>64118,65813.451823</TimeCreated>
<Property name="Environment">
<Description>
Logical development pipeline environment eg: "BASE","TEST","UAT","LIVE"
For example development is implemented in "BASE", deployed to "TEST" for user testing,
the patch is validated in "UAT", before being published to "LIVE"
Environment may also include platform versioning for example as a migration
project from Cache2010_BASE to IRIS2019_BASE</Description>
<Type>%String</Type>
<Required>1</Required>
<Parameter name="MINLEN" value="1"/>
</Property>
<Property name="Namespaces">
<Description>
Comma seperated list of Available Namespaces to execute runners within
Supports trailing wild-cards for example INST-* will match "INST-MARS" and "INST-LUNAR"
"*" on its own would match ALL namesapces
Supports leading "-" (minus character) to exclude items in list
For example: *,-INST-LUNAR
eg: "USER,OBSERVER,INTEG-MARS,INTEG-LUNAR,INST-MARS"</Description>
<Type>%String</Type>
<Required>1</Required>
<Parameter name="MAXLEN" value="1500"/>
<Parameter name="MINLEN" value="3"/>
</Property>
<Property name="RunSourceHandlers">
<Description>
When the schedule runs should is profile the selected namespaces for Classes, Routines, Ensemble Lookup Tables, etc
to generate "Signature" / "Fingerprint" of content</Description>
<Type>%Boolean</Type>
</Property>
<Property name="ExportToFile">
<Description>
When the schedule runs should the current "Signatures" for content be exported to the filesystem</Description>
<Type>%Boolean</Type>
</Property>
<Property name="ExportDirectory">
<Description>
The directory where files for "Signatures" and "Source" are exported to</Description>
<Type>%String</Type>
<Parameter name="MAXLEN" value="220"/>
</Property>
<Property name="ExportCompression">
<Type>%Boolean</Type>
<InitialExpression>1</InitialExpression>
</Property>
<Property name="OverwriteSourceOnReLoad">
<Description>
In completed development a signature should match content it is generated from
However when developing new or extending existing SourceHandlers
inconsistent Source can get introduced to reporting server
This flag allows Source for a signature to be "corrected"
as SourceHandler implementation is itterated and tested on the reporting server.</Description>
<Type>%Boolean</Type>
<InitialExpression>0</InitialExpression>
</Property>
<Method name="ExportDirectorySet">
<Description>
Correct the Path set via Task Schedule Web Page</Description>
<FormalSpec>val</FormalSpec>
<ReturnType>%Status</ReturnType>
<Implementation><![CDATA[
if val="" set i%ImportDirectory=val Quit $$$OK
if $zcvt($SYSTEM.Version.GetOS(),"U")="UNIX" {
if $E(val,*)'="/" {
// Unix / Linux without trailing directory character
set val=val_"/"
}
} elseif $E(val,*)'="\" {
// Assume windows without trailing directory character
set val=val_"\"
}
set i%ExportDirectory=val
Q $$$OK
]]></Implementation>
</Method>
<Property name="BackupSourceCode">
<Description>
Flag to indicate whether a standard export of source code should be taken from each namespace of interest </Description>
<Type>%Boolean</Type>
</Property>
<Property name="ImportFromFile">
<Description>
When the schedule runs should signatures and source be imported (from remote systems).</Description>
<Type>%Boolean</Type>
</Property>
<Property name="ImportDirectory">
<Description>
The directory where files for "Signatures" and "Source" are imported from</Description>
<Type>%String</Type>
<Parameter name="MAXLEN" value="220"/>
</Property>
<Property name="DiscardProfileData">
<Description>
For a non-reporting instance
Clear SourceCode profile signatures and data prior to running the schedule
Clear SourceCode profile signatures and data prior to running the schedule
ie: After export files for signatures and source code has been written
Caution - When Enabled on a Reporting Server this will
Also clear Signature data collected from other systems</Description>
<Type>%Boolean</Type>
</Property>
<Method name="ImportDirectorySet">
<Description>
Correct the Path set via Task Schedule Web Page</Description>
<FormalSpec>val</FormalSpec>
<ReturnType>%Status</ReturnType>
<Implementation><![CDATA[
if val="" set i%ImportDirectory=val Quit $$$OK
if $zcvt($SYSTEM.Version.GetOS(),"U")="UNIX" {
if $E(val,*)'="/" {
// Unix / Linux without trailing directory character
set val=val_"/"
}
} elseif $E(val,*)'="\" {
// Assume windows without trailing directory character
set val=val_"\"
}
set i%ImportDirectory=val
Q $$$OK
]]></Implementation>
</Method>
<Property name="ReImportUpdatedFiles">
<Description>
Flag to control whether files that have been imported previously should be reprocessed IF the filesystem timestamp has a newer modified datetime.</Description>
<Type>%Boolean</Type>
</Property>
<Property name="DeleteImportedFiles">
<Description>
Flag to control whether files that have been processed for import should be deleted from the Import Directory</Description>
<Type>%Boolean</Type>
</Property>
<Property name="RetainExportDays">
<Description>
Number of days to retain files containing "Signatures" and "Source" that have been exported to the Export Directory</Description>
<Type>%Integer</Type>
</Property>
<Property name="RetainSigSrcHistoricVersions">
<Description><![CDATA[
Number of historic versions to retain of global data for Signatures and Source snapshots
Set to "0" if we do not wish to hold historic data in globals for this system.<br/>
Set to "-1" to prevent analysis to discard obsolete source code entries. Useful for ECP mapped systems.]]></Description>
<Type>%Integer</Type>
</Property>
<Property name="EnableLogging">
<Description>
Switch to control whether SourceHandlers provide verbose logging during analysis of namespaces
Where a source handler generates "Signatures" and "Source" snapshots.</Description>
<Type>%Boolean</Type>
<InitialExpression>0</InitialExpression>
<Required>1</Required>
</Property>
<Property name="IncludeSourceCode">
<Description>
Switch used by SourceHandlers to control whether to include Source Information. ie: Data that can be exported into "Source" Files</Description>
<Type>%Boolean</Type>
<InitialExpression>0</InitialExpression>
<Required>1</Required>
</Property>
<Property name="Debug">
<Description>
Use by Schedule for verbose logging during Task Processing
A Cache schedule can be configured to send output to a file</Description>
<Type>%Boolean</Type>
</Property>
<Parameter name="ExportSignaturePrefix">
<Description>
The file prefix use for Exporting "Signature" files
The file prefix used to identify Import "Signature" files for processing</Description>
<Default>SrcUtilDataSig</Default>
</Parameter>
<Parameter name="ExportSourcePrefix">
<Description>
The file prefix use for Exporting "Source" files
The file prefix used to identify Import "Source" files for processing </Description>
<Default>SrcUtilDataSrc</Default>
</Parameter>
<Property name="STDOUT">
<Description>
Device to send debugging information to</Description>
<Type>%String</Type>
<Internal>1</Internal>
<Private>1</Private>
</Property>
<Property name="%PerNamespaceSourceHandlers">
<Description>
Enforced list SourceHandlers to run in each namespace
If set this list is used instead of searching for subclasses of SourceHandler Base
Useful for Mirrored environments when run on Backup Mirror</Description>
<Type>%String</Type>
<MultiDimensional>1</MultiDimensional>
</Property>
<Property name="%SystemSourceHandlers">
<Description>
Enforced list SourceHandlers to run once
If set this list is used instead of searching for subclasses of SourceHandler Base
Useful for Mirrored environments when run on Backup Mirror</Description>
<Type>%String</Type>
<MultiDimensional>1</MultiDimensional>
</Property>
<Property name="SrcVersionTokenStart">
<Description>
Source control systems may update a token in source code
with the brahc and version of code being checked-in
To filter out this sequence set the token start sequence used </Description>
<Type>%String</Type>
<InitialExpression>"$I"_"d"</InitialExpression>
</Property>
<Property name="SrcVersionTokenEnd">
<Description>
As with property SrcVersionTokenStart, to filter out version string added to code
by source control system set the token end sequence</Description>
<Type>%String</Type>
<InitialExpression>"$"</InitialExpression>
</Property>
<Property name="SrcVersionParameter">
<Type>%String</Type>
<InitialExpression>"SrcVer"</InitialExpression>
</Property>
<Parameter name="ExportItemTypes">
<Description>
Used by GenerateBackupSourceCode</Description>
<Default>*.CLS,*.MAC,*.INC,*.RUL,*.HL7,*.AST</Default>
</Parameter>
<Method name="OnTask">
<Description><![CDATA[
Entry method called by IRIS TaskScheduler for processing.<br/>
<h3>Profiling Source code</h3>
<p>Searches for Classes that implement ompare.SourceHandler.Base.
For each namespace configured on the Schedule, run each SourceHandler.
Each source handler is responsible for building and storing signatures and optionally an extract of source code (eg: Content of a method)
</p>
<p>
<h3>Exporting Signatures</h3>
Builds a Signature file in the Export Directory that can be imported into other systems for reporting.</br>
Builds a Source file in the Export Directory that can be imported into other systems for Source Comparison details.</br>
Exported files are gzip compressed for efficent transfer between systems.</br>
Export Signature files have the filename convention
<example>
[ExportSignaturePrefix] + [Environment] + [CCYYMMDDHHMM] + ".gz"
SrcUtilDataSigTESTX201608011247.gz
Where:
ExportSignaturePrefix = "SrcUtilDataSig"
Environment = "TESTX"
CCYYMMDDHHMM = 2016-08-01 12:47
</example>
Export Source files have the filename convention
<example>
[ExportSourcePrefix] + [Environment] + [CCYYMMDDHHMM] + ".gz"
SrcUtilDataSrcTESTX201607291247.gz
Where:
ExportSignaturePrefix = "SrcUtilDataSrc"
Environment = "TESTX"
CCYYMMDDHHMM = 2016-07-29 12:47
</example>
</p>
<h3>Purge Exports</h3>
Files older than the configured numnber of days will be automatically deleted from the Export directory.
Controls the volume of data left on the filesystem by the schedule.
</p>
<h3>Importing Signatures</h3>
Identifies Signatures file in the Import Directory for import.
<h4>Rules of import</h4><li>
<li>If data is newer in time but for the same day as Current information, then the current information will be overwritten</li>
<li>If data is older in time but for the same day as Current information, the import data will be discarded</li>
<li>If data is for a newer day than the Current information. The current information will be moved to a historic view and new data imported as Current.</li>
<li>If data is older than current and where there is no historic record for the day, the data will be imported to the historic view and current data is unchanged</li>
<li>If data is older than current but where there is already historic data and the import data is newer in time, the historic data will be overwritten</li>
<li>If data is older than current but where there is already historic data and the import data is older in time, the import data is discarded and the historic data is unchanged</li>
</ul>]]></Description>
<ReturnType>%Status</ReturnType>
<Implementation><![CDATA[
set stdout=$IO
set tSC=$$$OK
// Initialise process
Kill ^||Data,^||DataSrc
// Check that this task is not already running
Lock +^ompare.Schedule:2
Quit:'$T $$$ERROR(5001,"Task already running") // Task already running so exit
do ..DebugLine("******************************************")
do ..DebugLine(" Schedule Starting "_$ZDT($H,3))
do ..DebugLine("******************************************")
// Delete all previous reporting data
if ..DiscardProfileData {
do ..DebugLine("Initialise... Remove previous Profile Data requested")
Do ..PurgeProfileData()
}
// Convenience syntax. Reformat Namespace List
// Expand "*" to all namespaces
// Expand "-[Namespace]" to strip the namespace from the list
// Tests each namespace exists
do ..DebugLine("Configured Namespace List = "_..Namespaces)
set nslen=$L(..Namespaces,",")
kill nslist
for i=1:1:nslen {
set ns=$ZSTRIP($Piece(..Namespaces,",",i),"<>W")
continue:ns=""
set nsprefix=$Piece(ns,"*")
if $E(ns,*)="*",$E(ns,1)'="-" {
if ns="*" {
do ..DebugLine("Expanding namespace list for ALL (""*"")")
} else {
do ..DebugLine("Expanding namespace list starting with prefix ("""_nsprefix_""")")
}
// ADD ALL namespaces to the list
set nsrs=##class(%ResultSet).%New("%SYS.Namespace:List")
if nsrs.Execute(0,1) // Exclude remote and do not connect
{
for {
quit:'nsrs.Next()
set ns=nsrs.Data("Nsp")
continue:ns=""
if nsprefix="" {
set nslist(ns)=""
continue
}
if nsprefix=$Extract(ns,1,$Length(nsprefix)) {
set nslist(ns)=""
continue
}
}
}
set nsrs=""
continue
}
// Minus prefix = Remove Namespace from List
if $E(ns,1)="-" {
// Removed the leading minus sign
set ns=$E(ns,2,*)
// Prefix has no leading minus sign or trailing wild card
set nsprefix=$Piece(ns,"*")
continue:ns=""
// Exact Match for Namespace
if $E(ns,*)'="*" {
if '##class(%SYS.Namespace).Exists(ns) {
do ..DebugLine("Ignoring Exclude namespace rule ""-"_ns_""". Namespace does not exist.")
continue
} else {
do ..DebugLine("Excluding namespace """_ns_"""")
kill nslist(ns) // remove a previously added entry
continue
}
} elseif $E(ns,*)="*",nsprefix'="" {
// Wild Card processing
do ..DebugLine("Wild Card Proceesing for rule -"_ns)
set nsrs=##class(%ResultSet).%New("%SYS.Namespace:List")
if nsrs.Execute(0,1) // Exclude remote and do not connect
{
for {
quit:'nsrs.Next()
set nsq=nsrs.Data("Nsp")
continue:nsq=""
if nsprefix=$Extract(nsq,1,$Length(nsprefix)) {
// Delete previous entry
do ..DebugLine("Excluding namespace """_nsq_"""")
kill nslist(nsq)
continue
}
}
}
set nsrs=""
}
continue
}
// Exact Match for namespace
if '##class(%SYS.Namespace).Exists(ns) {
do ..DebugLine("Ignoring Include namespace rule "_ns_""". Namespace does not exist.")
continue
}
do ..DebugLine("Including namespace """_ns_"""")
set nslist(ns)=""
}
// Now reassemble namespace list for normal processing
set (ns,nslist)=""
for {
set ns=$Order(nslist(ns))
quit:ns=""
set nslist=nslist_ns_","
}
do ..DebugLine("Expanded / Resolved Namespace List = "_nslist)
if ..RunSourceHandlers {
if $O(..%PerNamespaceSourceHandlers(""))="",$O(..%SystemSourceHandlers(""))="" {
// Discover deployed Source handlers
set rs=##class(%ResultSet).%New()
set rs.ClassName="%Dictionary.ClassDefinition"
set rs.QueryName="SubclassOf"
if rs.Execute("ompare.SourceHandler.Base") {
while rs.Next() {
set sourceHandler=rs.Data("Name")
do ..DebugLine("Query SubclassOf SourceHandler.Base: "_sourceHandler)
continue:sourceHandler=""
// Check whether this is a per-namespace
//InvokePerNamespace
set perNamespace=1 // default to true if not overriden in sub-class
set perNamespace=$PARAMETER(sourceHandler,"InvokePerNamespace")
if perNamespace=1 {
do ..DebugLine("Register per Namespace SourceHandler "_sourceHandler)
set perNamespaceSourceHandlers(sourceHandler)=""
} else {
do ..DebugLine("Register per System SourceHandler "_sourceHandler)
set systemSourceHandlers(sourceHandler)=""
}
set parameter=""
}
}
do rs.Close()
set rs=""
} else {
set sourceHandler=""
for {
set sourceHandler=$O(..%PerNamespaceSourceHandlers(sourceHandler))
quit:sourceHandler=""
if ##class(%Dictionary.CompiledClass).%ExistsId(sourceHandler) {
set perNamespaceSourceHandlers(sourceHandler)=""
} else {
do ..DebugLine("Skipping unknown PerNamespaceSourceHandlers """_sourceHandler_"""")
}
}
set sourceHandler=""
for {
set sourceHandler=$O(..%SystemSourceHandlers(sourceHandler))
quit:sourceHandler=""
if ##class(%Dictionary.CompiledClass).%ExistsId(sourceHandler) {
set systemSourceHandlers(sourceHandler)=""
} else {
do ..DebugLine("Skipping unknown SystemSourceHandlers """_sourceHandler_"""")
}
}
}
if ..RetainSigSrcHistoricVersions>0 {
// Also initialises current Data
Do ..SaveHistoricData(..Environment)
} else {
// Initialise Current Data
// Delete ALL current Data in expectation of new
// We don't want a combination of OLD + NEW
Kill ^ompare("Data",..Environment)
// Initalise DateTime for new Data
// Format
// Date
// Time
// Server
// Instance
set ^ompare("Data",..Environment)=$TR($P($H,"."),",","^")_"^"_$TR($SYSTEM,":","^")
}
if ..OverwriteSourceOnReLoad {
do ..DebugLine("Skipping BuildExistingDataSrcList - OverwriteSourceOnReLoad flag is set")
} else {
Do ..BuildExistingDataSrcList()
}
set ns=""
for {
set ns=$Order(nslist(ns))
quit:ns=""
// For each Sub-classes of ompare.SourceHandler.Base"
set sourceHandler=""
for {
set sourceHandler=$Order(perNamespaceSourceHandlers(sourceHandler))
quit:sourceHandler=""
try {
Kill ^||Data
// Build up new ^||Data for signatures and update ^||DataSrc
do ..DebugLine("Running SourceHandler "_sourceHandler_" in namespace "_ns_" IncludeSourceCode="_..IncludeSourceCode)
Do $CLASSMETHOD(sourceHandler,"IndexNamespace",ns,..EnableLogging,..IncludeSourceCode)
Merge ^ompare("Data",..Environment,ns)=^||Data
} catch errobj {
// Error in BACKUP
// Catches intentional <ENDOFFILE>
if ..Debug {
u stdout WRITE "In Catch block standard export of source code",!
u stdout WRITE " Error Name:",errobj.Name,!
u stdout WRITE " Error code: ",errobj.Code,!
u stdout WRITE " Error location: ",errobj.Location,!
u stdout WRITE " Error data:",errobj.Data,!
}
}
Kill ^||Data
}
}
// Now run system wide Source Handlers
set sourceHandler=""
for {
set sourceHandler=$Order(systemSourceHandlers(sourceHandler))
quit:sourceHandler=""
try {
Kill ^||Data
do ..DebugLine("Running System Wide Source Handlers SourceHandler "_sourceHandler_" for system context ")
Do $CLASSMETHOD(sourceHandler,"IndexNamespace",ns,..EnableLogging,..IncludeSourceCode,..SrcVersionTokenStart,..SrcVersionTokenEnd)
Merge ^ompare("Data",..Environment,ns)=^||Data
} catch errobj {
// Error in BACKUP
// Catches intentional <ENDOFFILE>
do ..DebugLine("In Catch block System Wide Source Handlers")
do ..DebugLine(" Error Name:"_errobj.Name)
do ..DebugLine(" Error code: "_errobj.Code)
do ..DebugLine(" Error location: "_errobj.Location)
do ..DebugLine(" Error data:"_errobj.Data)
}
Kill ^||Data
}
Do ..ApplyChangesDataSrc(..OverwriteSourceOnReLoad)
Kill ^||DataSrc
// Truncate Obsolete Historic Signatures
// Truncate Obsolete Src entries no longer needed because they are no longer referenced by a signature on this system
Do ..PurgeSigSource(..RetainSigSrcHistoricVersions,..Debug)
// End RunSourceHandlers - Processing
}
// Generate Export Files if necessary
do {
Quit:'..ExportToFile
if '##class(%File).DirectoryExists(..ExportDirectory)
{
set tSC=$$$ERROR(5001,"ExportDirectory "_..ExportDirectory_" not found")
Quit
}
// CCYYMMDDHHSS
set dateh=$TR($ZDT($H,8,2,4,0)," :")
set datafile=..ExportDirectory_$S($E(..ExportDirectory,*)'?1(1"/",1"\"):$Select($SYSTEM.Version.GetBuildOS()="UNIX":"/",1:"\"),1:"")_..#ExportSignaturePrefix_..Environment_dateh_$S(..ExportCompression:".gz",1:".tx")
do ..DebugLine("Exporting Signatures to filepath "_datafile)
set opened=0
if ..ExportCompression {
Open datafile:("NWS":/GZIP=1):2
set opened=$T
} else {
Open datafile:("NWS"):2
set opened=$T
}
if opened {
use datafile Do ..ExportDataToDevice(..Environment)
} else {
do ..DebugLine("Unable to create file "_datafile)
}
close datafile
set datafile=..ExportDirectory_$S($E(..ExportDirectory,*)'?1(1"/",1"\"):$Select($SYSTEM.Version.GetBuildOS()="UNIX":"/",1:"\"),1:"")_..#ExportSourcePrefix_..Environment_dateh_$S(..ExportCompression:".gz",1:".tx")
do ..DebugLine("Exporting Source to filepath "_datafile)
set opened=0
if ..ExportCompression {
Open datafile:("NWS":/GZIP=1):2
set opened=$T
} else {
Open datafile:("NWS"):2
set opened=$T
}
if opened {
use datafile Do ..ExportDataSrcToDevice()
} else {
do ..DebugLine("Unable to create file "_datafile)
}
close datafile
} while (0)
// Purge old export files based on schedule policy
if ..RetainExportDays?1.2N,($L(..ExportDirectory)>2),##class(%File).DirectoryExists(..ExportDirectory) {
Do ..PurgeOldFiles(..ExportDirectory,..RetainExportDays,..Debug)
}
do {
Quit:'..ImportFromFile
if $L(..ImportDirectory)<2 {
do ..DebugLine("ImportDirectory parameter is Empty")
Quit
}
if '##class(%File).DirectoryExists(..ImportDirectory) {
do ..DebugLine("Import Directory "_..ImportDirectory_" not accessible")
Quit
}
Do ..ProcessImportDirectory()
} while (0)
// Do we require a standard export of source code from each named namespace
if ..BackupSourceCode {
set ns=""
for {
set ns=$Order(nslist(ns))
quit:ns=""
try {
// Build up new ^||Data for signatures and update ^||DataSrc
do ..DebugLine("Backing up source code in namespace "_ns)
set tSC=..GenerateBackupSourceCode(ns,..ExportDirectory,..Environment)
if $$$ISERR(tSC) {
do ..DebugLine("Error generating Backup for Source code in namespace "_ns)
do ..DebugLine($SYSTEM.Status.GetOneErrorText(tSC))
}
} catch errobj {
// Error in BACKUP
// Catches intentional <ENDOFFILE>
do ..DebugLine("In Catch block Backup Source Code")
do ..DebugLine(" Error Name:"_errobj.Name)
do ..DebugLine(" Error code: "_errobj.Code)
do ..DebugLine(" Error location: "_errobj.Location)
do ..DebugLine(" Error data:"_errobj.Data)
}
}
}
// Delete any reporting data generated by this schedule
if ..DiscardProfileData {
do ..DebugLine("Clean Up... Remove Profile Data requested")
Do ..PurgeProfileData()
}
do ..DebugLine("*******************************************")
do ..DebugLine(" Schedule Completed "_$ZDT($H,3))
do ..DebugLine("*******************************************")
// The unlocking is useful when a schedule is run
// programatically from a command line or process that
// does not exit after completion.
Lock -^ompare.Schedule
Quit $$$OK
]]></Implementation>
</Method>
<Method name="SaveHistoricData">
<Description><![CDATA[
Back-up current data if older than new generated / imported data
Truncates current or historic data to be replaced
If a newer version of data exists for the current day - this will simply be overwritten with latest data
Return Values<ul>
<li>0 = Abandon the Import. Data in file is obsolete</li>
<li>1 = Continue with Export / Import. Write to Current Data</li>
<li>2 = Continue with Import. Write to Historic Data</li>
</ul>]]></Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>environment="",dateOfData=+$H,timeOfData=$P($H,",",2),serverAndInstance=$TR($SYSTEM,":","^")</FormalSpec>
<Implementation><![CDATA[
quit:environment="" 0
quit:dateOfData="" 0
// Defaults: dateOfData, timeOfData and serverAndInstance
set previousDate=+$P($G(^ompare("Data",environment)),"^")
set previousTime=+$P($G(^ompare("Data",environment)),"^",2)
set historicTime=+$P($G(^ompare("History",dateOfData,environment)),"^",2)
set previousServerAndInstance=$P($G(^ompare("Data",environment)),"^",3,99)
if previousDate<dateOfData {
//W !,"SaveHistoricData = previousDate<dateOfData"
// Trucate any previous historic data for this date
kill ^ompare("History",previousDate,environment)
// Move to historic if current data exists
// Copies both date and time to historic node
merge ^ompare("History",previousDate,environment)=^ompare("Data",environment)
// Delete current Data in expectation of new
Kill ^ompare("Data",environment)
// Initalise DateTime for new Data
set ^ompare("Data",environment)=dateOfData_"^"_timeOfData_"^"_serverAndInstance
// Proceed with Export / Import
Quit 1
} elseif previousDate=dateOfData {
//W !,"SaveHistoricData = previousDate=dateOfData"
if previousTime<timeOfData {
// Overwrite current Data
// Delete current data in expectation of new
Kill ^ompare("Data",environment)
// Initalise DateTime for new Data
set ^ompare("Data",environment)=dateOfData_"^"_timeOfData_"^"_serverAndInstance
Quit 1
} else {
// Abandon Import - Data saved in database is newer than import file
Quit 0
}
} elseif previousDate>dateOfData {
//W !,"SaveHistoricData = previousDate>dateOfData"
// Write historic records
if historicTime<timeOfData {
// Overwrite historic Data
Kill ^ompare("History",dateOfData,environment)
// Initalise DateTime for historic Data
set ^ompare("History",dateOfData,environment)=dateOfData_"^"_timeOfData_"^"_previousServerAndInstance
Quit 2
} else {
//W !,"H4"
// Abandon Import
Quit 0
}
}
Quit 0
]]></Implementation>
</Method>
<Method name="BuildExistingDataSrcList">
<Description>
Build a process private list of existing code signatures and their last know active date</Description>
<ClassMethod>1</ClassMethod>
<Implementation><![CDATA[
Kill ^||DataSrc
set sig=""
for {
set sig=$Order(^ompare("DataSrc",sig))
quit:sig=""
// By default if any previously existing signatures do not exist apply todays date
set date=$G(^ompare("DataSrc",sig),+$H)
set ^||DataSrc(sig)=date
}
]]></Implementation>
</Method>
<Method name="ApplyChangesDataSrc">
<Description>
Updates the current date held against source code signatures
Saves additional new source code</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>overwriteSourceOnReLoad=0</FormalSpec>
<Implementation><![CDATA[
// Using iterate instead of block merge to reduce Journal impact
set sig=""
for {
set sig=$O(^||DataSrc(sig))
quit:sig=""
// remove / truncate if required
kill:overwriteSourceOnReLoad ^ompare("DataSrc",sig)
if $Data(^ompare("DataSrc",sig))=0 {
merge ^ompare("DataSrc",sig)=^||DataSrc(sig) // New data
} elseif ($G(^ompare("DataSrc",sig))<^||DataSrc(sig)){
set ^ompare("DataSrc",sig)=^||DataSrc(sig) // Update still in use date
} else {
// No change in date used.
// Obsolete information from current date but still maybe relavent for historic data
}
}
]]></Implementation>
</Method>
<Method name="ExportDataToDevice">
<Description>
Output Source Signatures to the open device (gzip file or Terminal)</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>environment=""</FormalSpec>
<Implementation><![CDATA[
quit:environment=""
W "ENV|",$TR(environment,"|"),"|",$TR($G(^ompare("Data",environment)),"^","|"),!
set namespace=""
for {
set data=""
set namespace=$Order(^ompare("Data",environment,namespace),+1,data)
quit:namespace=""
W "NSP|",$TR(namespace,"|"),"|",$TR(data,"^","|"),! // Append as pipe delimted data from global
set type=""
for {
set type=$Order(^ompare("Data",environment,namespace,type))
quit:type=""
set typename=""
for {
set typename=$Order(^ompare("Data",environment,namespace,type,typename),+1,data)
quit:typename=""
W "TYP|",$TR(type,"|"),"|",$TR(typename,"|"),"|",data,!
set subtype=""
for {
set subtype=$Order(^ompare("Data",environment,namespace,type,typename,subtype))
quit:subtype=""
set subtypename=""
for {
set subtypename=$Order(^ompare("Data",environment,namespace,type,typename,subtype,subtypename),+1,data)
quit:subtypename=""
W "SUB|",$TR(subtype,"|"),"|",$TR(subtypename,"|"),"|",data,!
}
}
}
}
}
W "END|||",!
]]></Implementation>
</Method>
<Method name="ExportDataSrcToDevice">
<Description>
Output Source snapshot to the open device (gzip file or Terminal)</Description>
<ClassMethod>1</ClassMethod>
<Implementation><![CDATA[
set sig=""
for {
set data=""
set sig=$O(^ompare("DataSrc",sig),+1,data)
quit:sig=""
W "S|",sig,"|",data,!
set line=""
for {
set data=""
set line=$O(^ompare("DataSrc",sig,line),+1,data)
quit:line=""
W "L|",data,!
}
}
W "END|||",!
]]></Implementation>
</Method>
<Method name="PurgeOldFiles">
<Description><![CDATA[
Removes old export files from the filesystem
Expects files in format
<example>
ExportSignaturePrefix + Environment + CCYYMMDDHHMM + ".gz"
ExportSourcePrefix + Environment + CCYYMMDDHHMM + ".gz"
</example>
For example
<example>
SrcUtilDataSigUAT201601011023.gz
SrcUtilDataSrcUAT201601011245.gz
</example>]]></Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>directory,retain=5,debug=0</FormalSpec>
<ReturnType>%Status</ReturnType>
<Implementation><![CDATA[
if debug {
W !,"PurgeOldFiles called."
W !," >> Directory=",directory
W !," >> Retain Days=",retain
}
set tSC=$$$OK
set deleteBeforeHorolog=$H-retain
for prefix=..#ExportSignaturePrefix,..#ExportSourcePrefix {
// File ResultSet
set rs=##class(%ResultSet).%New()
set rs.ClassName="%File"
set rs.QueryName="FileSet"
set tSC=rs.Execute(directory,prefix_"*.gz;"_prefix_"*.tx",0)
// Expect prefix + Environment + CCYYMMDDHHMM
set tSC=$$$OK
for {
Quit:'rs.Next(.tSC)
Quit:$$$ISERR(tSC)
set path=rs.Data("Name")
set filename=##class(%File).GetFilename(path)
// Extracts the date part of the filename for comparison with todays date
// Don't trust filesystem timestamp
set ccyymmdd=$E(filename,*-14,*-7)
if ccyymmdd'?8N {
w:debug !,"Skipping file ",filename," invalid format"
continue
}
set hd=$ZDH(ccyymmdd,8,,4,,,,,"")
if hd<1 {
w:debug !,"Skipping file ",filename," invalid format"
continue
}
// Ignore files that should be retained
if hd>=deleteBeforeHorolog {
W:debug !,"Retaining file ",filename,". Within Retain ",retain," days."
continue
}
W:debug !,"Deleting file ",filename
do ##class(%File).Delete(path)
}
}
quit tSC
]]></Implementation>
</Method>
<Method name="Test1">
<ClassMethod>1</ClassMethod>
<Implementation><![CDATA[
set o=##class(ompare.Schedule).%New()
set o.Environment="VAL"
set o.Namespaces="INTEG-TCL"
set o.ExportToFile=1
set o.ExportDirectory="/trak/lab/traktemp"
set o.RetainExportDays=5
set o.EnableLogging=0
set o.IncludeSourceCode=1
set o.Debug=0
set tSC=o.OnTask()
do $SYSTEM.Status.DisplayError(tSC)
]]></Implementation>
</Method>
<Method name="Test2">
<ClassMethod>1</ClassMethod>
<Implementation><![CDATA[
set directory="/trak/lab/traktemp/"
set extension=".gz"
// Normal format test Signature
set datetime=$TR($ZDT($H,8,2,0,,4)," :")
set path=directory_..#ExportSignaturePrefix_"1_SIG_PASS"_datetime_extension
Open path:("NWS":/GZIP=1):2
Quit:'$T
Use path W !
Close path
//set dateh=$TR($ZDT($H,8,2,4,0)," :")
// Normal format test Source code
set path=directory_..#ExportSourcePrefix_"2SRC_PASS"_datetime_extension
Open path:("NWS":/GZIP=1):2
Quit:'$T
Use path W !
Close path
// Abnormal prefix test
//set datetime=$TR($ZDT($H,8,,0,,4)," :")
set path=directory_"ABC"_..#ExportSourcePrefix_"3PrefixFail"_datetime_extension
Open path:("NWS":/GZIP=1):2
Quit:'$T
Use path W !
Close path