-
Notifications
You must be signed in to change notification settings - Fork 343
/
Copy pathupgrade-2.10.xsl
2569 lines (2472 loc) · 108 KB
/
upgrade-2.10.xsl
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
<!--
Copyright 2018 Red Hat, Inc.
Author: Jan Pokorny <jpokorny@redhat.com>
Part of pacemaker project
SPDX-License-Identifier: GPL-2.0-or-later
-->
<!--
Not compatible with @id-ref occurrences! Normalize generic 2.X-compatible
instances with upgrade-2.10-enter.xsl (optionally denormalize back akin
to the original with upgrade-2.10-leave.xsl once the upgrade is finished).
-->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:cibtr="http://clusterlabs.org/ns/pacemaker/cibtr-2"
exclude-result-prefixes="cibtr">
<xsl:output method="xml" encoding="UTF-8" indent="yes" omit-xml-declaration="yes"/>
<xsl:param name="cibtr:cib-min-ver" select="'3.0'"/>
<xsl:param name="cibtr:label-warning" select="'WARNING: '"/>
<xsl:param name="cibtr:label-info" select="'INFO: '"/>
<xsl:param name="cibtr:label-debug" select="'DEBUG: '"/>
<!--
HELPER DEFINITIONS
-->
<cibtr:map>
<!--
Target tag: cluster_property_set
Object: ./nvpair/@name
Selector ctxt: ./nvpair/@value
Move ctxt: op_defaults ~ /cib/configuration/op_defaults
rsc_defaults ~ /cib/configuration/rsc_defaults
Related commit: c1c66fe13
+
7a9891f29
7d0d1b0eb
1f643d610
73a5d63a8
+
642a09b22
0c03e366d
a28a558f9
-->
<cibtr:table for="cluster-properties" msg-prefix="Cluster properties"
where-cases="op_defaults|rsc_defaults">
<cibtr:replace what="cluster-infrastructure"
with=""
in-case-of="heartbeat|openais|classic openais|classic openais (with plugin)|cman"
msg-extra="corosync (2+) infrastructure can be used instead, though the value is not of significance"/>
<cibtr:replace what="cluster_recheck_interval"
with="cluster-recheck-interval"/>
<cibtr:replace what="dc_deadtime"
with="dc-deadtime"/>
<cibtr:replace what="default-action-timeout"
with="timeout"
where="op_defaults"/>
<cibtr:replace what="default_action_timeout"
with="timeout"
where="op_defaults"/>
<cibtr:replace what="default-migration-threshold"
with=""
msg-extra="migration-threshold in rsc_defaults can be configured instead"/>
<cibtr:replace what="default_migration_threshold"
with=""
msg-extra="migration-threshold in rsc_defaults can be configured instead"/>
<cibtr:replace what="default-resource-stickiness"
with="resource-stickiness"
where="rsc_defaults"/>
<cibtr:replace what="default_resource_stickiness"
with="resource-stickiness"
where="rsc_defaults"/>
<cibtr:replace what="default-resource-failure-stickiness"
with="migration-threshold"
where="rsc_defaults"
in-case-of="-INFINITY"
redefined-as="1"/>
<cibtr:replace what="default-resource-failure-stickiness"
with=""
msg-extra="migration-threshold in rsc_defaults can be configured instead"/>
<cibtr:replace what="default_resource_failure_stickiness"
with="migration-threshold"
where="rsc_defaults"
in-case-of="-INFINITY"
redefined-as="1"/>
<cibtr:replace what="default_resource_failure_stickiness"
with=""
msg-extra="migration-threshold in rsc_defaults can be configured instead"/>
<cibtr:replace what="election_timeout"
with="election-timeout"/>
<cibtr:replace what="expected-quorum-votes"
with=""
msg-extra="corosync (2+) infrastructure tracks quorum on its own"/>
<cibtr:replace what="is-managed-default"
with="is-managed"
where="rsc_defaults"/>
<cibtr:replace what="is_managed_default"
with="is-managed"
where="rsc_defaults"/>
<cibtr:replace what="no_quorum_policy"
with="no-quorum-policy"/>
<cibtr:replace what="notification-agent"
with=""
msg-extra="standalone alerts can be configured instead"/>
<cibtr:replace what="notification-recipient"
with=""
msg-extra="standalone alerts can be configured instead"/>
<cibtr:replace what="remove_after_stop"
with="remove-after-stop"/>
<cibtr:replace what="shutdown_escalation"
with="shutdown-escalation"/>
<cibtr:replace what="startup_fencing"
with="startup-fencing"/>
<cibtr:replace what="stonith_action"
with="stonith-action"/>
<cibtr:replace what="stonith_enabled"
with="stonith-enabled"/>
<cibtr:replace what="stop_orphan_actions"
with="stop-orphan-actions"/>
<cibtr:replace what="stop_orphan_resources"
with="stop-orphan-resources"/>
<cibtr:replace what="symmetric_cluster"
with="symmetric-cluster"/>
<cibtr:replace what="transition_idle_timeout"
with="cluster-delay"/>
</cibtr:table>
<!--
Target tag: node
Object: ./@*
Selector ctxt: ./@*
Move ctxt: N/A
Related commit: 55ab749bf
-->
<cibtr:table for="cluster-node" msg-prefix="Cluster node">
<cibtr:replace what="type"
with="type"
in-case-of="normal"
redefined-as="member"/>
</cibtr:table>
<!--
Target tag: primitive
template
Object: ./instance_attributes/nvpair/@name
Selector ctxt: N/A
Move ctxt: N/A
Related commit: 06d4559cb
+
6c8e0be20
-->
<cibtr:table for="resource-instance-attributes" msg-prefix="Resource instance_attributes">
<cibtr:replace what="pcmk_arg_map"
with=""/>
<!-- simplified as pcmk_arg_map can encode multiple
comma-separated pairs (everything would be dropped then,
except for a single dangling case: "port" coming first) -->
<cibtr:replace what="pcmk_arg_map"
with="pcmk_host_argument"
in-case-of-droppable-prefix="port:"/>
<cibtr:replace what="pcmk_list_cmd"
with="pcmk_list_action"/>
<cibtr:replace what="pcmk_monitor_cmd"
with="pcmk_monitor_action"/>
<cibtr:replace what="pcmk_off_cmd"
with="pcmk_off_action"/>
<cibtr:replace what="pcmk_on_cmd"
with="pcmk_on_action"/>
<cibtr:replace what="pcmk_reboot_cmd"
with="pcmk_reboot_action"/>
<cibtr:replace what="pcmk_status_cmd"
with="pcmk_status_action"/>
</cibtr:table>
<!--
Target tag: primitive
template
Object: ./meta_attributes/nvpair/@name
Selector ctxt: N/A
Move ctxt: N/A
Related commit: c713bbe39
+
6052ad6da
-->
<cibtr:table for="resource-meta-attributes" msg-prefix="Resource meta_attributes">
<cibtr:replace what="isolation"
with="target-role"
redefined-as="Stopped"
msg-extra="i.e. resource at hand disabled; isolation wrappers obsoleted with bundle resources"
msg-severity="WARNING"/>
<cibtr:replace what="isolation-host"
with="target-role"
redefined-as="Stopped"
msg-extra="i.e. resource at hand disabled; isolation wrappers obsoleted with bundle resources"
msg-severity="WARNING"/>
<cibtr:replace what="isolation-instance"
with="target-role"
redefined-as="Stopped"
msg-extra="i.e. resource at hand disabled; isolation wrappers obsoleted with bundle resources"
msg-severity="WARNING"/>
<cibtr:replace what="isolation-wrapper"
with="target-role"
redefined-as="Stopped"
msg-extra="i.e. resource at hand disabled; isolation wrappers obsoleted with bundle resources"
msg-severity="WARNING"/>
<cibtr:replace what="resource-failure-stickiness"
with="migration-threshold"
in-case-of="-INFINITY"
redefined-as="1"/>
<cibtr:replace what="resource-failure-stickiness"
with=""
msg-extra="migration-threshold can be configured instead"/>
<cibtr:replace what="resource_failure_stickiness"
with="migration-threshold"
in-case-of="-INFINITY"
redefined-as="1"/>
<cibtr:replace what="resource_failure_stickiness"
with=""
msg-extra="migration-threshold can be configured instead"/>
</cibtr:table>
<!--
Target tag: primitive
template
Object: ./operations/op/@*
./operations/op/meta_attributes/nvpair/@name
./operations/op/instance_attributes/nvpair/@name
Selector ctxt: ./operations/op/@name
Move ctxt: meta_attributes ~ ./meta_attributes/nvpair
Related commit: 014a543d5
-->
<cibtr:table for="resources-operation" msg-prefix="Resources-operation"
where-cases="meta_attributes">
<!-- keep this in sync with resource-operation-instance-attributes table -->
<cibtr:replace what="requires"
with=""
msg-extra="only start/promote operation taken into account"/>
<cibtr:replace what="requires"
with="requires"
in-case-of="start|promote"
where="meta_attributes"/>
</cibtr:table>
<!--
Target tag: primitive
template
Object: ./operations/op/instance_attributes/nvpair/@name
Selector ctxt: ./operations/op/@name
Move ctxt: per-resource-meta_attributes ~ ./meta_attributes/nvpair
meta_attributes ~ ./operations/op/meta_attributes/nvpair
Related commit: 023897afc
3100c0e8b
-->
<cibtr:table for="resource-operation-instance-attributes"
msg-prefix="Resources-operation instance_attributes"
where-cases="meta_attributes|per-resource-meta_attributes">
<!-- this is easier to solve through resources-operation table handling,
in the inverse mode, but for compatibility purposes, we need to have
it tracked here, so mark it the same way as if we were moving it over
to sibling per-op meta_attributes (while in fact we move it up to
per-resource meta_attributes, as if it was specified in per-op
meta_attributes already), just use a dedicated "where-case" other
than "meta_attributes" reserved for proper local move as mentioned;
otherwise keep it in sync with said table -->
<cibtr:replace what="requires"
with=""
msg-extra="only start/promote operation taken into account"/>
<cibtr:replace what="requires"
with="requires"
in-case-of="start|promote"
where="per-resource-meta_attributes"/>
<!-- these must have been, due to the value sourcing predence arrangement,
shadowed by immediate op's attributes, so simply preserve their
non-meta meaning -->
<!--
<cibtr:replace what="name"
with="name"
where="meta_attributes"/>
<cibtr:replace what="interval"
with="interval"
where="meta_attributes"/>
-->
<cibtr:replace what="interval-origin"
with="interval-origin"
where="meta_attributes"/>
<cibtr:replace what="start-delay"
with="start-delay"
where="meta_attributes"/>
<cibtr:replace what="enabled"
with="enabled"
where="meta_attributes"/>
<cibtr:replace what="on-fail"
with="on-fail"
where="meta_attributes"/>
<cibtr:replace what="record-pending"
with="record-pending"
where="meta_attributes"/>
<cibtr:replace what="role"
with="role"
where="meta_attributes"/>
<cibtr:replace what="timeout"
with="timeout"
where="meta_attributes"/>
</cibtr:table>
<!--
Target tag: rsc_colocation
Object: ./@*
Selector ctxt: N/A
Move ctxt: N/A
Related commit: 96d7ffedf
-->
<cibtr:table for="constraints-colocation" msg-prefix="Constraints-colocation">
<cibtr:replace what="score-attribute"
with=""
msg-extra="was actually never in effect"/>
<cibtr:replace what="score-attribute-mangle"
with=""
msg-extra="was actually never in effect"/>
</cibtr:table>
</cibtr:map>
<xsl:variable name="cibtr:MapClusterProperties"
select="document('')/xsl:stylesheet
/cibtr:map/cibtr:table[
@for = 'cluster-properties'
]"/>
<xsl:variable name="cibtr:MapClusterNode"
select="document('')/xsl:stylesheet
/cibtr:map/cibtr:table[
@for = 'cluster-node'
]"/>
<xsl:variable name="cibtr:MapResourceInstanceAttributes"
select="document('')/xsl:stylesheet
/cibtr:map/cibtr:table[
@for = 'resource-instance-attributes'
]"/>
<xsl:variable name="cibtr:MapResourceMetaAttributes"
select="document('')/xsl:stylesheet
/cibtr:map/cibtr:table[
@for = 'resource-meta-attributes'
]"/>
<xsl:variable name="cibtr:MapResourcesOperation"
select="document('')/xsl:stylesheet
/cibtr:map/cibtr:table[
@for = 'resources-operation'
]"/>
<xsl:variable name="cibtr:MapResourcesOperationInstanceAttributes"
select="document('')/xsl:stylesheet
/cibtr:map/cibtr:table[
@for = 'resource-operation-instance-attributes'
]"/>
<xsl:variable name="cibtr:MapConstraintsColocation"
select="document('')/xsl:stylesheet
/cibtr:map/cibtr:table[
@for = 'constraints-colocation'
]"/>
<!--
GENERIC UTILITIES
-->
<!--
Plain identity template
Merely implicit-context-driven, no arguments.
-->
<xsl:template name="cibtr:HelperIdentity">
<xsl:copy>
<xsl:apply-templates select="@*|node()"
mode="cibtr:main"/>
</xsl:copy>
</xsl:template>
<!--
Emit an message about the replacement, sanity checking the source definitions
Merely parameter driven, no implicit context taken into account:
- Context: optional message prefix
- Replacement: selected subset of cibtr:map's leaves
(it's considered a hard error if consists of more than 1 item)
Explanation wrt. how target severity gets selected, ordered by priority:
- $Replacement/@msg-severity (WARNING/INFO/DEBUG)
- $Replacement/@msg-extra defined -> INFO
- otherwise -> DEBUG
-->
<xsl:template name="cibtr:MapMsg">
<xsl:param name="Context" select="''"/>
<xsl:param name="Replacement"/>
<xsl:choose>
<xsl:when test="not($Replacement)"/>
<xsl:when test="count($Replacement) != 1">
<xsl:message terminate="yes">
<xsl:value-of select="concat('INTERNAL ERROR: ',
$Replacement/../@msg-prefix,
': count($Replacement) != 1',
' does not hold (',
count($Replacement), ')')"/>
</xsl:message>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="MsgPrefix" select="concat(
($Replacement|$Replacement/..)
/@msg-prefix, ': '
)"/>
<xsl:variable name="MsgSeverity">
<xsl:choose>
<xsl:when test="$Replacement/@msg-severity">
<xsl:value-of select="$Replacement/@msg-severity"/>
</xsl:when>
<xsl:when test="$Replacement/@msg-extra">
<xsl:value-of select="'INFO'"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="'DEBUG'"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="MsgSeverityLabel">
<xsl:choose>
<xsl:when test="$MsgSeverity = 'WARNING'">
<xsl:value-of select="$cibtr:label-warning"/>
</xsl:when>
<xsl:when test="$MsgSeverity = 'INFO'">
<xsl:value-of select="$cibtr:label-info"/>
</xsl:when>
<xsl:when test="$MsgSeverity = 'DEBUG'">
<xsl:value-of select="$cibtr:label-debug"/>
</xsl:when>
<xsl:otherwise>
<xsl:message terminate="yes">
<xsl:value-of select="concat('INTERNAL ERROR: not a valid',
' severity specification: ',
$MsgSeverity)"/>
</xsl:message>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:if test="string($MsgSeverityLabel) != string(false())">
<xsl:message>
<xsl:value-of select="concat($MsgSeverityLabel, $MsgPrefix)"/>
<xsl:if test="$Context">
<xsl:value-of select="concat($Context, ': ')"/>
</xsl:if>
<xsl:choose>
<xsl:when test="string($Replacement/@with)">
<xsl:choose>
<xsl:when test="string($Replacement/@where)">
<xsl:if test="not(
contains(
concat('|', $Replacement/../@where-cases, '|'),
concat('|', $Replacement/@where, '|')
)
)">
<xsl:message terminate="yes">
<xsl:value-of select="concat('INTERNAL ERROR:',
$Replacement/../@msg-prefix,
': $Replacement/@where (',
$Replacement/@where, ') not in ',
concat('|',
$Replacement/../@where-cases,
'|'))"/>
</xsl:message>
</xsl:if>
<xsl:value-of select="concat('moving ', $Replacement/@what,
' under ', $Replacement/@where)"/>
</xsl:when>
<xsl:when test="$Replacement/@with = $Replacement/@what">
<xsl:value-of select="concat('keeping ', $Replacement/@what)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat('renaming ', $Replacement/@what)"/>
</xsl:otherwise>
</xsl:choose>
<xsl:value-of select="concat(' as ', $Replacement/@with)"/>
<xsl:if test="$Replacement/@where">
<xsl:value-of select="' unless already defined there'"/>
</xsl:if>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat('dropping ', $Replacement/@what)"/>
</xsl:otherwise>
</xsl:choose>
<xsl:if test="string($Replacement/@redefined-as)">
<xsl:value-of select="concat(', redefined as ',
$Replacement/@redefined-as)"/>
<xsl:if test="$Replacement/@in-case-of">
<xsl:value-of select="','"/>
</xsl:if>
</xsl:if>
<xsl:choose>
<xsl:when test="string($Replacement/@in-case-of)">
<xsl:value-of select="concat(' for matching ',
$Replacement/@in-case-of)"/>
</xsl:when>
<xsl:when test="$Replacement/@in-case-of">
<xsl:value-of select="' for matching "empty string"'"/>
</xsl:when>
<xsl:when test="$Replacement/@in-case-of-droppable-prefix">
<xsl:value-of select="concat(' for matching ',
$Replacement/@in-case-of-droppable-prefix,
' prefix that will, meanwhile, get dropped'
)"/>
</xsl:when>
</xsl:choose>
</xsl:message>
<xsl:if test="$Replacement/@msg-extra">
<xsl:message>
<xsl:value-of select="concat($MsgSeverityLabel, $MsgPrefix, '... ',
$Replacement/@msg-extra)"/>
</xsl:message>
</xsl:if>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!--
Produce a denormalized space if not present in the input (cf. trick A.)
Merely parameter driven, no implicit context taken into account:
- Source: input selection or result tree fragment to evaluate
- ResultTreeFragment: optional self-explanatory flag related to Source
-->
<xsl:template name="cibtr:HelperDenormalizedSpace">
<xsl:param name="Source"/>
<xsl:param name="ResultTreeFragment" select="false()"/>
<xsl:param name="InnerSimulation" select="false()"/>
<xsl:choose>
<xsl:when test="not($ResultTreeFragment)">
<!-- intention here is that immediately surrounding text (mostly expected
to be just indenting whitespace) and comments will be preserved;
in case no denormalized space is present, " " is injected -->
<xsl:variable name="ExistingSpace"
select="$Source/preceding-sibling::node()[
(
self::comment()
or
self::text()
)
and
generate-id(following-sibling::*[1])
= generate-id($Source)
]"/>
<xsl:copy-of select="$ExistingSpace"/>
<xsl:if test="not(
$ExistingSpace/self::text()[
normalize-space(.) != string(.)
]
) and $InnerSimulation">
<xsl:text> </xsl:text>
</xsl:if>
</xsl:when>
<xsl:when test="normalize-space($Source)
!= string($Source)">
<xsl:text> </xsl:text>
</xsl:when>
</xsl:choose>
</xsl:template>
<!--
TRANSFORMATION HELPERS
considerations, limitations, etc.:
1. the transformations tries to preserve as much of the original XML
as possible, incl. whitespace text/indentation and comments, but
at times (corner cases of tricks A. + B. below), this needs to be
sacrificed, e.g., distorting nice indentation, hence if the
perfection is the goal:
- user of the transformation can feed the minimized version of
the XML (no denormalized/any white-space present)
- user of the transformation can (re-)pretty-print the outcome
afterwards
tricks and conventions used:
A. callable templates only return Result Tree Fragments, which means
the only operations allowed are those looking at the underlying,
virtual node-set, and since we need to discern their non-void
production (i.e. on successful match/es), we use this trick:
- ensure the template will not propagate any denormalized whitespace
- inject denormalized whitespace (superfluous space) artificially
to mark successful production (but see B. below)
- with the template production, here stored as Var variable,
we test "normalize-space($Var) != $Var" condition to detect
non-void production, mainly intended to see whether to emit
the enclosing element at all (with the goal of not leaving
superfluous elements behind needlessly)
B. [extension over A.] to eliminate distorted indentation
(cf. consideration 1.), additional reuse of these callable
templates is introduced: the template can recursively call
itself with a special flag (InnerSimulation) as an oracle to
see to whether non-void production will ensue (all pre-existing
denormalized whitespace is forcefully removed in this mode),
and if positive, all such inner pre-existing whitespace is
then preserved in this outer=main invocation
C. [extension over B.] when checking the non-void production
(via InnerSimulation), beside the injected denormalized whitespace,
we can also inject particular strings, which the callsite of such
simulation can, in addition, inspect for paricular string
occurrences, e.g. to prevent clashes on the production coming
from multiple sources
D. not only to honour DRY principle and to avoid inner entropy, it's
often useful to make callable template bimodal, e.g., when the
production is generated in the "what's to stay in place" vs.
"what's to be propagated (combined with previous, effectively
moved) at this other part of the tree" contexts; for such cases,
there's usually InverseMode parameter to be assigned true()
(implicit default) and false(), respectively
E. the common idiom that emerges is: evaluate simulation value,
depending on the presence of the "success mark" (cf. A.),
possibly emit non-simulation value; since it would (likely)
re-evaluate the simulation anew (wastefully) or perhaps
this sort of dependency injection can just come handy,
common transformation helpers below offer InnerPass
parameter to be optionally passed, either as a string (when
no-denormalized-space is an internal criterium for the template)
or, conventionally, the result tree fragment representing the
output of the template at hand called with a simulation flag
* established signaling strings accompanying InnerSimulation=true:
- TRIGGER-MSG ... make the template execution emit messages
describing changes being performed
- TRIGGER-RECURSION
... currently used in the oracle-like evaluation
of what's the situation with the sibling
elements as a recursion guard so that such
nested runs won't revisit the new set of
siblings per the respective nested context
-->
<!--
Source ctxt: cluster_property_set
Target ctxt: cluster_property_set
Target-inv ctxt:/cib/configuration/(op_defaults|rsc_defaults)
[cluster_property_set -> meta_attributes]
Dependencies: N/A
-->
<xsl:template name="cibtr:ProcessClusterProperties">
<xsl:param name="Source"/>
<xsl:param name="InverseMode" select="false()"/>
<xsl:param name="InnerSimulation" select="false()"/>
<xsl:param name="InnerPass">
<xsl:choose>
<xsl:when test="$InnerSimulation">
<xsl:value-of select="''"/>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="cibtr:ProcessClusterProperties">
<xsl:with-param name="Source" select="$Source"/>
<xsl:with-param name="InverseMode" select="$InverseMode"/>
<xsl:with-param name="InnerSimulation" select="true()"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:param>
<xsl:for-each select="$Source/node()">
<xsl:choose>
<xsl:when test="self::text()">
<!-- cf. trick A. (consideration 1.) -->
<xsl:choose>
<xsl:when test="normalize-space($InnerPass)
!= $InnerPass
and
(
not(following-sibling::nvpair)
or
generate-id(following-sibling::nvpair[1])
!= generate-id(following-sibling::*[1])
)">
<xsl:value-of select="."/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="normalize-space(.)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="self::nvpair">
<xsl:variable name="Replacement"
select="$cibtr:MapClusterProperties/cibtr:replace[
@what = current()/@name
and
(
(
@in-case-of
and
contains(concat('|', @in-case-of, '|'),
concat('|', current()/@value, '|'))
)
or
(
not(@in-case-of)
and
not(
$cibtr:MapClusterProperties/cibtr:replace[
@what = current()/@name
and
@in-case-of
and
contains(concat('|', @in-case-of, '|'),
concat('|', current()/@value, '|'))
]
)
)
)
]"/>
<xsl:if test="$InnerPass = 'TRIGGER-MSG'">
<xsl:call-template name="cibtr:MapMsg">
<xsl:with-param name="Context" select="@id"/>
<xsl:with-param name="Replacement" select="$Replacement"/>
</xsl:call-template>
</xsl:if>
<xsl:choose>
<xsl:when test="$Replacement
and
(
not(string($Replacement/@with))
or
$Replacement/@where
)">
<!-- drop (possibly just move over) -->
<xsl:if test="$Replacement/@where
and
(
(
normalize-space($InverseMode)
and
$Replacement/@where = $InverseMode
)
or
(
not(normalize-space($InverseMode))
and
(true() or count($InverseMode))
and
not(
$InverseMode/nvpair[
@name = $Replacement/@with
]
)
and
$Replacement/@where = name($InverseMode/..)
)
)">
<xsl:call-template name="cibtr:HelperDenormalizedSpace">
<xsl:with-param name="Source" select="."/>
<xsl:with-param name="InnerSimulation" select="$InnerSimulation"/>
</xsl:call-template>
<xsl:copy>
<xsl:for-each select="@*">
<xsl:choose>
<xsl:when test="name() = 'name'">
<xsl:attribute name="{name()}">
<xsl:value-of select="$Replacement/@with"/>
</xsl:attribute>
</xsl:when>
<xsl:when test="string($Replacement/@redefined-as)
and
name() = 'value'">
<xsl:attribute name="{name()}">
<xsl:value-of select="$Replacement/@redefined-as"/>
</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:copy/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:copy>
</xsl:if>
</xsl:when>
<xsl:when test="$InverseMode"/>
<xsl:when test="$Replacement">
<xsl:call-template name="cibtr:HelperDenormalizedSpace">
<xsl:with-param name="Source" select="."/>
<xsl:with-param name="InnerSimulation" select="$InnerSimulation"/>
</xsl:call-template>
<xsl:copy>
<xsl:for-each select="@*">
<xsl:choose>
<xsl:when test="name() = 'name'">
<xsl:attribute name="{name()}">
<xsl:value-of select="$Replacement/@with"/>
</xsl:attribute>
</xsl:when>
<xsl:when test="string($Replacement/@redefined-as)
and
name() = 'value'">
<xsl:attribute name="{name()}">
<xsl:value-of select="$Replacement/@redefined-as"/>
</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:copy/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:copy>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="cibtr:HelperDenormalizedSpace">
<xsl:with-param name="Source" select="."/>
<xsl:with-param name="InnerSimulation" select="$InnerSimulation"/>
</xsl:call-template>
<xsl:call-template name="cibtr:HelperIdentity"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="$InverseMode
or
self::comment()">
<!-- drop -->
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="cibtr:HelperIdentity"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:template>
<!--
Source ctxt: (primitive|template)/instance_attributes
Target ctxt: (primitive|template)/instance_attributes
Target-inv ctxt:N/A
Dependencies: N/A
-->
<xsl:template name="cibtr:ProcessRscInstanceAttributes">
<xsl:param name="Source"/>
<xsl:param name="InnerSimulation" select="false()"/>
<xsl:param name="InnerPass">
<xsl:choose>
<xsl:when test="$InnerSimulation">
<xsl:value-of select="''"/>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="cibtr:ProcessRscInstanceAttributes">
<xsl:with-param name="Source" select="$Source"/>
<xsl:with-param name="InnerSimulation" select="true()"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:param>
<!-- B: special-casing nvpair -->
<xsl:for-each select="$Source/node()">
<xsl:choose>
<xsl:when test="self::text()">
<!-- cf. trick A. (consideration 1.) -->
<xsl:choose>
<xsl:when test="normalize-space($InnerPass)
!= $InnerPass
and
(
not(following-sibling::nvpair)
or
generate-id(following-sibling::nvpair[1])
!= generate-id(following-sibling::*[1])
)">
<xsl:value-of select="."/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="normalize-space(.)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="self::nvpair">
<xsl:variable name="Replacement"
select="$cibtr:MapResourceInstanceAttributes/cibtr:replace[
@what = current()/@name
and
(
(
@in-case-of
and
contains(concat('|', @in-case-of, '|'),
concat('|', current()/@value, '|'))
)
or
(
@in-case-of-droppable-prefix
and
starts-with(current()/@value,
@in-case-of-droppable-prefix)
and
not(
contains(current()/@value, ',')
)
)
or
(
not(@in-case-of)
and
not(@in-case-of-droppable-prefix)
and
not(
$cibtr:MapResourceInstanceAttributes/cibtr:replace[
@what = current()/@name
and
(
(
@in-case-of
and
contains(concat('|', @in-case-of, '|'),
concat('|', current()/@value, '|'))
)
or
(
@in-case-of-droppable-prefix
and
starts-with(current()/@value,
@in-case-of-droppable-prefix)
and
not(
contains(current()/@value, ',')
)
)
)
]
)
)
)
]"/>
<xsl:if test="$InnerPass = 'TRIGGER-MSG'">
<xsl:call-template name="cibtr:MapMsg">
<xsl:with-param name="Context" select="@id"/>
<xsl:with-param name="Replacement" select="$Replacement"/>
</xsl:call-template>
</xsl:if>
<xsl:choose>
<xsl:when test="$Replacement
and
not(string($Replacement/@with))">
<!-- drop (move-over code missing) -->
</xsl:when>
<xsl:when test="$Replacement">
<!-- plain rename -->
<xsl:call-template name="cibtr:HelperDenormalizedSpace">
<xsl:with-param name="Source" select="."/>
<xsl:with-param name="InnerSimulation" select="$InnerSimulation"/>
</xsl:call-template>
<xsl:copy>
<xsl:for-each select="@*">
<xsl:choose>
<xsl:when test="name() = 'name'">
<xsl:attribute name="{name()}">
<xsl:value-of select="$Replacement/@with"/>
</xsl:attribute>
</xsl:when>
<xsl:when test="string($Replacement/@redefined-as)
and
name() = 'value'">
<xsl:attribute name="{name()}">
<xsl:value-of select="$Replacement/@redefined-as"/>
</xsl:attribute>
</xsl:when>
<xsl:when test="string($Replacement/@in-case-of-droppable-prefix)
and
name() = 'value'">
<xsl:attribute name="{name()}">
<xsl:value-of select="substring-after(
., $Replacement/@in-case-of-droppable-prefix
)"/>
</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:copy/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:copy>
</xsl:when>