-
Notifications
You must be signed in to change notification settings - Fork 612
/
InfinispanSubsystemXMLReader.java
2907 lines (2655 loc) · 132 KB
/
InfinispanSubsystemXMLReader.java
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
/*
* JBoss, Home of Professional Open Source.
* Copyright 2012, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.infinispan.subsystem;
import static org.jboss.as.clustering.infinispan.InfinispanLogger.ROOT_LOGGER;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ADD;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR;
import java.util.Collections;
import java.util.EnumSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Stream;
import javax.xml.stream.Location;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import org.infinispan.eviction.EvictionStrategy;
import org.infinispan.eviction.EvictionType;
import org.infinispan.globalstate.ConfigurationStorage;
import org.infinispan.partitionhandling.PartitionHandling;
import org.infinispan.security.impl.ClusterRoleMapper;
import org.infinispan.security.impl.CommonNameRoleMapper;
import org.infinispan.security.impl.IdentityRoleMapper;
import org.infinispan.server.jgroups.subsystem.ChannelResourceDefinition;
import org.infinispan.server.jgroups.subsystem.JGroupsSubsystemResourceDefinition;
import org.jboss.as.controller.AttributeDefinition;
import org.jboss.as.controller.ObjectTypeAttributeDefinition;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.SimpleAttributeDefinition;
import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
import org.jboss.as.controller.operations.common.Util;
import org.jboss.as.controller.parsing.ParseUtils;
import org.jboss.dmr.ModelNode;
import org.jboss.logging.Logger;
import org.jboss.staxmapper.XMLElementReader;
import org.jboss.staxmapper.XMLExtendedStreamReader;
/**
* Infinispan subsystem parsing code.
*
* @author Paul Ferraro
* @author Richard Achmatowicz
* @author Tristan Tarrant
* @author Radoslav Husar
* @author William Burns
* @author Martin Gencur
*/
public final class InfinispanSubsystemXMLReader implements XMLElementReader<List<ModelNode>> {
private static final Logger log = Logger.getLogger(InfinispanSubsystemXMLReader.class);
private final Namespace namespace;
public InfinispanSubsystemXMLReader(Namespace namespace) {
this.namespace = namespace;
}
/**
* {@inheritDoc}
* @see org.jboss.staxmapper.XMLElementReader#readElement(org.jboss.staxmapper.XMLExtendedStreamReader, Object)
*/
@Override
public void readElement(XMLExtendedStreamReader reader, List<ModelNode> result) throws XMLStreamException {
Map<PathAddress, ModelNode> operations = new LinkedHashMap<>();
PathAddress subsystemAddress = PathAddress.pathAddress(InfinispanExtension.SUBSYSTEM_PATH);
ModelNode subsystem = Util.createAddOperation(subsystemAddress);
// command to add the subsystem
operations.put(subsystemAddress, subsystem);
while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
Element element = Element.forName(reader.getLocalName());
switch (element) {
case CACHE_CONTAINER: {
parseContainer(reader, subsystemAddress, operations);
break;
}
default: {
throw ParseUtils.unexpectedElement(reader);
}
}
}
result.addAll(operations.values());
}
private void parseContainer(XMLExtendedStreamReader reader, PathAddress subsystemAddress, Map<PathAddress, ModelNode> operations) throws XMLStreamException {
ModelNode container = Util.getEmptyOperation(ADD, null);
String name = null;
final Set<Attribute> required = EnumSet.of(Attribute.NAME);
for (int i = 0; i < reader.getAttributeCount(); i++) {
ParseUtils.requireNoNamespaceAttribute(reader, i);
String value = reader.getAttributeValue(i);
Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
required.remove(attribute);
switch (attribute) {
case NAME: {
name = value;
break;
}
case ALIASES: {
for (String alias: reader.getListAttributeValue(i)) {
container.get(ModelKeys.ALIASES).add(alias);
}
break;
}
case DEFAULT_CACHE: {
CacheContainerResource.DEFAULT_CACHE.parseAndSetParameter(value, container, reader);
break;
}
case JNDI_NAME: {
CacheContainerResource.JNDI_NAME.parseAndSetParameter(value, container, reader);
break;
}
case START: {
CacheContainerResource.START.parseAndSetParameter(value, container, reader);
break;
}
case LISTENER_EXECUTOR: {
if (namespace.since(Namespace.INFINISPAN_SERVER_8_0)) {
throw ParseUtils.unexpectedAttribute(reader, i);
} else {
ROOT_LOGGER.deprecatedExecutor(ModelKeys.LISTENER_EXECUTOR, ModelKeys.LISTENER_THREAD_POOL);
}
break;
}
case ASYNC_EXECUTOR: {
if (namespace.since(Namespace.INFINISPAN_SERVER_8_0)) {
throw ParseUtils.unexpectedAttribute(reader, i);
} else {
ROOT_LOGGER.deprecatedExecutor(ModelKeys.ASYNC_EXECUTOR, ModelKeys.ASYNC_OPERATIONS_THREAD_POOL);
}
break;
}
case EVICTION_EXECUTOR: {
if (namespace.since(Namespace.INFINISPAN_SERVER_8_0)) {
throw ParseUtils.unexpectedAttribute(reader, i);
} else {
ROOT_LOGGER.deprecatedExecutor(ModelKeys.EVICTION_EXECUTOR, ModelKeys.EXPIRATION_THREAD_POOL);
}
break;
}
case EXPIRATION_EXECUTOR: {
if (namespace.since(Namespace.INFINISPAN_SERVER_8_0)) {
throw ParseUtils.unexpectedAttribute(reader, i);
} else {
ROOT_LOGGER.deprecatedExecutor(ModelKeys.EXPIRATION_EXECUTOR, ModelKeys.EXPIRATION_THREAD_POOL);
}
break;
}
case REPLICATION_QUEUE_EXECUTOR: {
if (namespace.since(Namespace.INFINISPAN_SERVER_8_0)) {
throw ParseUtils.unexpectedAttribute(reader, i);
} else {
ROOT_LOGGER.deprecatedExecutor(ModelKeys.REPLICATION_QUEUE_EXECUTOR, ModelKeys.REPLICATION_QUEUE_THREAD_POOL);
}
break;
}
case STATE_TRANSFER_EXECUTOR: {
if (namespace.since(Namespace.INFINISPAN_SERVER_8_0)) {
throw ParseUtils.unexpectedAttribute(reader, i);
} else {
ROOT_LOGGER.deprecatedExecutor(ModelKeys.STATE_TRANSFER_EXECUTOR, ModelKeys.STATE_TRANSFER_THREAD_POOL);
}
break;
}
case MODULE: {
CacheContainerResource.CACHE_CONTAINER_MODULE.parseAndSetParameter(value, container, reader);
break;
}
case STATISTICS: {
CacheContainerResource.STATISTICS.parseAndSetParameter(value, container, reader);
break;
}
default: {
throw ParseUtils.unexpectedAttribute(reader, i);
}
}
}
if (!required.isEmpty()) {
throw ParseUtils.missingRequired(reader, required);
}
PathAddress containerAddress = subsystemAddress.append(ModelKeys.CACHE_CONTAINER, name);
container.get(OP_ADDR).set(containerAddress.toModelNode());
operations.put(containerAddress, container);
PathAddress configurationsAddress = containerAddress.append(CacheContainerConfigurationsResource.PATH);
operations.put(configurationsAddress, Util.getEmptyOperation(ADD, configurationsAddress.toModelNode()));
Stream.of(ThreadPoolResource.values()).forEach(
pool -> operations.put(containerAddress.append(pool.getPathElement()), Util.createAddOperation(containerAddress.append(pool.getPathElement())))
);
Stream.of(ScheduledThreadPoolResource.values()).forEach(
pool -> operations.put(containerAddress.append(pool.getPathElement()), Util.createAddOperation(containerAddress.append(pool.getPathElement())))
);
while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
Element element = Element.forName(reader.getLocalName());
switch (element) {
case TRANSPORT: {
parseTransport(reader, containerAddress, operations);
break;
}
case SECURITY: {
if (namespace.since(Namespace.INFINISPAN_SERVER_7_0)) {
parseGlobalSecurity(reader, containerAddress, operations);
} else {
throw ParseUtils.unexpectedElement(reader);
}
break;
}
case GLOBAL_STATE: {
if (namespace.since(Namespace.INFINISPAN_SERVER_8_1)) {
parseGlobalState(reader, containerAddress, operations);
} else {
throw ParseUtils.unexpectedElement(reader);
}
break;
}
case MODULES: {
if (namespace.since(Namespace.INFINISPAN_SERVER_9_2)) {
parseModules(reader, containerAddress, operations);
} else {
throw ParseUtils.unexpectedElement(reader);
}
break;
}
case LOCAL_CACHE: {
parseLocalCache(reader, containerAddress, operations, false);
break;
}
case LOCAL_CACHE_CONFIGURATION: {
if (namespace.since(Namespace.INFINISPAN_SERVER_8_0)) {
parseLocalCache(reader, containerAddress, operations, true);
} else {
throw ParseUtils.unexpectedElement(reader);
}
break;
}
case INVALIDATION_CACHE: {
parseInvalidationCache(reader, containerAddress, operations, false);
break;
}
case INVALIDATION_CACHE_CONFIGURATION: {
if (namespace.since(Namespace.INFINISPAN_SERVER_8_0)) {
parseInvalidationCache(reader, containerAddress, operations, true);
} else {
throw ParseUtils.unexpectedElement(reader);
}
break;
}
case REPLICATED_CACHE: {
parseReplicatedCache(reader, containerAddress, operations, false);
break;
}
case REPLICATED_CACHE_CONFIGURATION: {
if (namespace.since(Namespace.INFINISPAN_SERVER_8_0)) {
parseReplicatedCache(reader, containerAddress, operations, true);
} else {
throw ParseUtils.unexpectedElement(reader);
}
break;
}
case DISTRIBUTED_CACHE: {
parseDistributedCache(reader, containerAddress, operations, false);
break;
}
case DISTRIBUTED_CACHE_CONFIGURATION: {
if (namespace.since(Namespace.INFINISPAN_SERVER_8_0)) {
parseDistributedCache(reader, containerAddress, operations, true);
} else {
throw ParseUtils.unexpectedElement(reader);
}
break;
}
case ASYNC_OPERATIONS_THREAD_POOL: {
if (namespace.since(Namespace.INFINISPAN_SERVER_8_0)) {
this.parseThreadPool(ThreadPoolResource.ASYNC_OPERATIONS, reader, containerAddress, operations);
break;
}
}
case EXPIRATION_THREAD_POOL: {
if (namespace.since(Namespace.INFINISPAN_SERVER_8_0)) {
this.parseScheduledThreadPool(ScheduledThreadPoolResource.EXPIRATION, reader, containerAddress, operations);
break;
}
}
case LISTENER_THREAD_POOL: {
if (namespace.since(Namespace.INFINISPAN_SERVER_8_0)) {
this.parseThreadPool(ThreadPoolResource.LISTENER, reader, containerAddress, operations);
break;
}
}
case PERSISTENCE_THREAD_POOL: {
if (namespace.since(Namespace.INFINISPAN_SERVER_8_0)) {
this.parseThreadPool(ThreadPoolResource.PERSISTENCE, reader, containerAddress, operations);
break;
}
}
case REMOTE_COMMAND_THREAD_POOL: {
if (namespace.since(Namespace.INFINISPAN_SERVER_8_0)) {
this.parseThreadPool(ThreadPoolResource.REMOTE_COMMAND, reader, containerAddress, operations);
break;
}
}
case REPLICATION_QUEUE_THREAD_POOL: {
if (namespace.since(Namespace.INFINISPAN_SERVER_8_0)) {
this.parseScheduledThreadPool(ScheduledThreadPoolResource.REPLICATION_QUEUE, reader, containerAddress, operations);
break;
}
}
case STATE_TRANSFER_THREAD_POOL: {
if (namespace.since(Namespace.INFINISPAN_SERVER_8_0)) {
this.parseThreadPool(ThreadPoolResource.STATE_TRANSFER, reader, containerAddress, operations);
break;
}
}
case TRANSPORT_THREAD_POOL: {
if (namespace.since(Namespace.INFINISPAN_SERVER_8_0)) {
this.parseThreadPool(ThreadPoolResource.TRANSPORT, reader, containerAddress, operations);
break;
}
}
case COUNTERS: {
if (namespace.since(Namespace.INFINISPAN_SERVER_9_2)) {
PathAddress countersAddress = containerAddress.append(CacheContainerCountersResource.PATH);
operations.put(countersAddress, Util.getEmptyOperation(ADD, countersAddress.toModelNode()));
this.parseCounters(reader, countersAddress, operations);
break;
}
}
default: {
throw ParseUtils.unexpectedElement(reader);
}
}
}
}
private void parseCounters(XMLExtendedStreamReader reader, PathAddress countersAddress,
Map<PathAddress, ModelNode> operations) throws XMLStreamException {
ModelNode counters = operations.get(countersAddress);
for (int i = 0; i < reader.getAttributeCount(); i++) {
String value = reader.getAttributeValue(i);
Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
switch (attribute) {
case NUM_OWNERS: {
CacheContainerCountersResource.NUM_OWNERS.parseAndSetParameter(value, counters, reader);
break;
}
case RELIABILITY: {
CacheContainerCountersResource.RELIABILITY.parseAndSetParameter(value, counters, reader);
break;
}
default: {
throw ParseUtils.unexpectedAttribute(reader, i);
}
}
}
while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
Element element = Element.forName(reader.getLocalName());
switch (element) {
case STRONG_COUNTER: {
parseStrongCounterElement(reader, countersAddress, operations);
break;
}
case WEAK_COUNTER: {
parseWeakCounterElement(reader, countersAddress, operations);
break;
}
default: {
throw ParseUtils.unexpectedElement(reader);
}
}
}
}
private void parseStrongCounterElement(XMLExtendedStreamReader reader,
PathAddress countersConfigurationAddress, Map<PathAddress, ModelNode> operations)
throws XMLStreamException {
PathAddress strongCounterAddress = countersConfigurationAddress;
ModelNode counter = Util.createAddOperation(strongCounterAddress);
for (int i = 0; i < reader.getAttributeCount(); i++) {
String value = reader.getAttributeValue(i);
Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
switch (attribute) {
case INITIAL_VALUE: {
StrongCounterResource.INITIAL_VALUE.parseAndSetParameter(value, counter, reader);
break;
}
case NAME: {
StrongCounterResource.COUNTER_NAME.parseAndSetParameter(value, counter, reader);
strongCounterAddress = strongCounterAddress.append(StrongCounterResource.PATH.getKey(),
value);
counter.get(OP_ADDR).set(strongCounterAddress.toModelNode());
break;
}
case STORAGE: {
StrongCounterResource.STORAGE.parseAndSetParameter(value, counter, reader);
break;
}
default: {
throw ParseUtils.unexpectedAttribute(reader, i);
}
}
}
while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
Element e = Element.forName(reader.getLocalName());
switch (e) {
case LOWER_BOUND: {
parseCounterBound(reader, e, counter);
break;
}
case UPPER_BOUND: {
parseCounterBound(reader, e, counter);
break;
}
default: {
throw ParseUtils.unexpectedElement(reader);
}
}
}
operations.put(strongCounterAddress, counter);
}
private void parseWeakCounterElement(XMLExtendedStreamReader reader,
PathAddress countersConfigurationAddress, Map<PathAddress, ModelNode> operations)
throws XMLStreamException {
PathAddress weakCountersAddress = countersConfigurationAddress;
ModelNode counter = Util.createAddOperation(weakCountersAddress);
for (int i = 0; i < reader.getAttributeCount(); i++) {
String value = reader.getAttributeValue(i);
Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
switch (attribute) {
case INITIAL_VALUE: {
WeakCounterResource.INITIAL_VALUE.parseAndSetParameter(value,
counter, reader);
break;
}
case NAME: {
WeakCounterResource.COUNTER_NAME.parseAndSetParameter(value,
counter, reader);
weakCountersAddress = weakCountersAddress.append(WeakCounterResource.PATH.getKey(),
value);
counter.get(OP_ADDR).set(weakCountersAddress.toModelNode());
break;
}
case STORAGE: {
WeakCounterResource.STORAGE.parseAndSetParameter(value,
counter, reader);
break;
}
case CONCURRENCY_LEVEL: {
WeakCounterResource.CONCURRENCY_LEVEL.parseAndSetParameter(value,
counter, reader);
break;
}
default: {
throw ParseUtils.unexpectedAttribute(reader, i);
}
}
}
if (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
throw ParseUtils.unexpectedElement(reader);
}
operations.put(weakCountersAddress, counter);
}
private void parseCounterBound(XMLExtendedStreamReader reader, Element element, ModelNode counter)
throws XMLStreamException {
for (int i = 0; i < reader.getAttributeCount(); i++) {
String value = reader.getAttributeValue(i);
Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
switch (attribute) {
case VALUE: {
if (element.equals(Element.LOWER_BOUND)) {
StrongCounterResource.LOWER_BOUND.parseAndSetParameter(value, counter, reader);
}
if (element.equals(Element.UPPER_BOUND)) {
StrongCounterResource.UPPER_BOUND.parseAndSetParameter(value, counter, reader);
}
break;
}
default: {
throw ParseUtils.unexpectedAttribute(reader, i);
}
}
}
if (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
throw ParseUtils.unexpectedElement(reader);
}
}
private void parseGlobalState(XMLExtendedStreamReader reader, PathAddress containerAddress,
Map<PathAddress, ModelNode> operations) throws XMLStreamException {
ConfigurationStorage storage = null;
PathAddress globalStateAddress = containerAddress.append(ModelKeys.GLOBAL_STATE, ModelKeys.GLOBAL_STATE_NAME);
ModelNode globalState = Util.createAddOperation(globalStateAddress);
while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
Element element = Element.forName(reader.getLocalName());
switch (element) {
case PERSISTENT_LOCATION: {
parseGlobalStatePath(reader, globalState, GlobalStateResource.PERSISTENT_LOCATION_PATH);
break;
}
case TEMPORARY_LOCATION: {
parseGlobalStatePath(reader, globalState, GlobalStateResource.TEMPORARY_STATE_PATH);
break;
}
case VOLATILE_CONFIGURATION_STORAGE: {
if (storage != null) {
throw ParseUtils.unexpectedElement(reader);
}
storage = ConfigurationStorage.VOLATILE;
break;
}
case OVERLAY_CONFIGURATION_STORAGE: {
if (storage != null) {
throw ParseUtils.unexpectedElement(reader);
}
storage = ConfigurationStorage.OVERLAY;
break;
}
case MANAGED_CONFIGURATION_STORAGE: {
if (storage != null) {
throw ParseUtils.unexpectedElement(reader);
}
storage = ConfigurationStorage.MANAGED;
break;
}
case CUSTOM_CONFIGURATION_STORAGE: {
if (storage != null) {
throw ParseUtils.unexpectedElement(reader);
}
storage = ConfigurationStorage.CUSTOM;
String klass = ParseUtils.readStringAttributeElement(reader, Attribute.CLASS.getLocalName());
GlobalStateResource.CONFIGURATION_STORAGE_CLASS.parseAndSetParameter(klass, globalState, reader);
break;
}
default: {
throw ParseUtils.unexpectedElement(reader);
}
}
}
if (storage != null) {
GlobalStateResource.CONFIGURATION_STORAGE.parseAndSetParameter(storage.name(), globalState, reader);
}
operations.put(globalStateAddress, globalState);
}
private void parseGlobalStatePath(XMLExtendedStreamReader reader, ModelNode operation,
ObjectTypeAttributeDefinition statePath) throws XMLStreamException {
ModelNode model = operation.get(statePath.getName());
for (int i = 0; i < reader.getAttributeCount(); i++) {
String value = reader.getAttributeValue(i);
Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
switch (attribute) {
case RELATIVE_TO: {
GlobalStateResource.TEMPORARY_RELATIVE_TO.parseAndSetParameter(value, model, reader);
break;
}
case PATH: {
GlobalStateResource.PATH.parseAndSetParameter(value, model, reader);
break;
}
default: {
throw ParseUtils.unexpectedAttribute(reader, i);
}
}
}
ParseUtils.requireNoContent(reader);
}
private void parseModules(XMLExtendedStreamReader reader, PathAddress containerAddress, Map<PathAddress, ModelNode> operations) throws XMLStreamException {
PathAddress modulesAddress = containerAddress.append(ModelKeys.MODULES, ModelKeys.MODULES_NAME);
ModelNode modules = Util.createAddOperation(modulesAddress);
ParseUtils.requireNoAttributes(reader);
Map<PathAddress, ModelNode> additionalConfigurationOperations = new LinkedHashMap<>();
while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
Element element = Element.forName(reader.getLocalName());
switch (element) {
case MODULE: {
parseModule(reader, modulesAddress, additionalConfigurationOperations);
break;
}
default: {
throw ParseUtils.unexpectedElement(reader);
}
}
}
operations.put(modulesAddress, modules);
operations.putAll(additionalConfigurationOperations);
}
private void parseModule(XMLExtendedStreamReader reader, PathAddress modulesAddress, Map<PathAddress, ModelNode> operations) throws XMLStreamException {
ParseUtils.requireAttributes(reader, Attribute.NAME.getLocalName());
String name = reader.getAttributeValue(null, Attribute.NAME.getLocalName());
String slot = reader.getAttributeValue(null, Attribute.SLOT.getLocalName());
PathAddress moduleAddress = modulesAddress.append(ModelKeys.MODULE, name);
ModelNode moduleNode = Util.createAddOperation(moduleAddress);
CacheContainerModuleResource.NAME.parseAndSetParameter(name, moduleNode, reader);
if (slot != null) {
CacheContainerModuleResource.SLOT.parseAndSetParameter(slot, moduleNode, reader);
}
ParseUtils.requireNoContent(reader);
operations.put(moduleAddress, moduleNode);
}
private void parseTransport(XMLExtendedStreamReader reader, PathAddress containerAddress, Map<PathAddress, ModelNode> operations) throws XMLStreamException {
PathAddress transportAddress = containerAddress.append(ModelKeys.TRANSPORT, ModelKeys.TRANSPORT_NAME);
ModelNode transport = Util.createAddOperation(transportAddress);
String stack = null;
String cluster = null;
for (int i = 0; i < reader.getAttributeCount(); i++) {
String value = reader.getAttributeValue(i);
Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
switch (attribute) {
case CHANNEL: {
TransportResource.CHANNEL.parseAndSetParameter(value, transport, reader);
break;
}
case EXECUTOR: {
if (namespace.since(Namespace.INFINISPAN_SERVER_8_0)) {
throw ParseUtils.unexpectedAttribute(reader, i);
} else {
ROOT_LOGGER.deprecatedExecutor(ModelKeys.EXECUTOR, ModelKeys.TRANSPORT_THREAD_POOL);
}
break;
}
case LOCK_TIMEOUT: {
TransportResource.LOCK_TIMEOUT.parseAndSetParameter(value, transport, reader);
break;
}
case REMOTE_COMMAND_EXECUTOR: {
if (namespace.since(Namespace.INFINISPAN_SERVER_8_0)) {
throw ParseUtils.unexpectedAttribute(reader, i);
} else {
ROOT_LOGGER.deprecatedExecutor(ModelKeys.REMOTE_COMMAND_EXECUTOR, ModelKeys.REMOTE_COMMAND_THREAD_POOL);
}
break;
}
case STRICT_PEER_TO_PEER: {
TransportResource.STRICT_PEER_TO_PEER.parseAndSetParameter(value, transport, reader);
break;
}
case TOTAL_ORDER_EXECUTOR: {
if (!namespace.since(Namespace.INFINISPAN_SERVER_8_0)) {
log.warn("The xml element total-order-executor has been removed and has no effect, please update your configuration file.");
break;
}
}
case STACK: {
if (!namespace.since(Namespace.INFINISPAN_SERVER_8_0)) {
stack = value;
break;
}
}
case CLUSTER: {
if (!namespace.since(Namespace.INFINISPAN_SERVER_8_0)) {
cluster = value;
break;
}
}
case INITIAL_CLUSTER_SIZE: {
if (namespace.since(Namespace.INFINISPAN_SERVER_8_2)) {
TransportResource.INITIAL_CLUSTER_SIZE.parseAndSetParameter(value, transport, reader);
break;
} else {
throw ParseUtils.unexpectedAttribute(reader, i);
}
}
case INITIAL_CLUSTER_TIMEOUT: {
if (namespace.since(Namespace.INFINISPAN_SERVER_8_2)) {
TransportResource.INITIAL_CLUSTER_TIMEOUT.parseAndSetParameter(value, transport, reader);
break;
} else {
throw ParseUtils.unexpectedAttribute(reader, i);
}
}
default: {
throw ParseUtils.unexpectedAttribute(reader, i);
}
}
}
if (!namespace.since(Namespace.INFINISPAN_SERVER_8_0)) {
// We need to create a corresponding channel add operation
String channel = (cluster != null) ? cluster : ("cluster-" + containerAddress.getLastElement().getValue());
TransportResource.CHANNEL.parseAndSetParameter(channel, transport, reader);
PathAddress channelAddress = PathAddress.pathAddress(JGroupsSubsystemResourceDefinition.PATH, ChannelResourceDefinition.pathElement(channel));
ModelNode channelOperation = Util.createAddOperation(channelAddress);
if (stack != null) {
ChannelResourceDefinition.STACK.parseAndSetParameter(stack, channelOperation, reader);
}
operations.put(channelAddress, channelOperation);
}
ParseUtils.requireNoContent(reader);
operations.put(transportAddress, transport);
}
private void parseGlobalSecurity(XMLExtendedStreamReader reader, PathAddress containerAddress, Map<PathAddress, ModelNode> operations) throws XMLStreamException {
PathAddress securityAddress = containerAddress.append(ModelKeys.SECURITY, ModelKeys.SECURITY_NAME);
ModelNode security = Util.createAddOperation(securityAddress);
ParseUtils.requireNoAttributes(reader);
Map<PathAddress, ModelNode> additionalConfigurationOperations = new LinkedHashMap<>();
while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
Element element = Element.forName(reader.getLocalName());
switch (element) {
case AUTHORIZATION: {
this.parseGlobalAuthorization(reader, securityAddress, additionalConfigurationOperations);
break;
}
default: {
throw ParseUtils.unexpectedElement(reader);
}
}
}
operations.put(securityAddress, security);
operations.putAll(additionalConfigurationOperations);
}
private void parseGlobalAuthorization(XMLExtendedStreamReader reader, PathAddress securityAddress, Map<PathAddress, ModelNode> operations) throws XMLStreamException {
PathAddress authorizationAddress = securityAddress.append(ModelKeys.AUTHORIZATION, ModelKeys.AUTHORIZATION_NAME);
ModelNode authorization = Util.createAddOperation(authorizationAddress);
String auditLogger = null;
for (int i = 0; i < reader.getAttributeCount(); i++) {
Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
switch (attribute) {
case AUDIT_LOGGER: {
if (auditLogger != null) {
throw ParseUtils.unexpectedElement(reader);
}
auditLogger = reader.getAttributeValue(i);
break;
}
default: {
throw ParseUtils.unexpectedAttribute(reader, i);
}
}
}
CacheContainerAuthorizationResource.AUDIT_LOGGER.parseAndSetParameter(auditLogger, authorization, reader);
Map<PathAddress, ModelNode> additionalConfigurationOperations = new LinkedHashMap<>();
String roleMapper = null;
while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
Element element = Element.forName(reader.getLocalName());
switch (element) {
case IDENTITY_ROLE_MAPPER:
if (roleMapper != null) {
throw ParseUtils.unexpectedElement(reader);
}
ParseUtils.requireNoAttributes(reader);
ParseUtils.requireNoContent(reader);
roleMapper = IdentityRoleMapper.class.getName();
break;
case COMMON_NAME_ROLE_MAPPER:
if (roleMapper != null) {
throw ParseUtils.unexpectedElement(reader);
}
ParseUtils.requireNoAttributes(reader);
ParseUtils.requireNoContent(reader);
roleMapper = CommonNameRoleMapper.class.getName();
break;
case CLUSTER_ROLE_MAPPER:
if (roleMapper != null) {
throw ParseUtils.unexpectedElement(reader);
}
ParseUtils.requireNoAttributes(reader);
ParseUtils.requireNoContent(reader);
roleMapper = ClusterRoleMapper.class.getName();
break;
case CUSTOM_ROLE_MAPPER:
if (roleMapper != null) {
throw ParseUtils.unexpectedElement(reader);
}
roleMapper = ParseUtils.readStringAttributeElement(reader, Attribute.CLASS.getLocalName());
break;
case ROLE: {
this.parseGlobalRole(reader, authorizationAddress, additionalConfigurationOperations);
break;
}
default: {
throw ParseUtils.unexpectedElement(reader);
}
}
}
CacheContainerAuthorizationResource.MAPPER.parseAndSetParameter(roleMapper, authorization, reader);
operations.put(authorizationAddress, authorization);
operations.putAll(additionalConfigurationOperations);
}
private void parseGlobalRole(XMLExtendedStreamReader reader, PathAddress authorizationAddress, Map<PathAddress, ModelNode> operations) throws XMLStreamException {
String[] attributes = ParseUtils.requireAttributes(reader, Attribute.NAME.getLocalName(), Attribute.PERMISSIONS.getLocalName());
String name = attributes[0];
PathAddress roleAddress = authorizationAddress.append(ModelKeys.ROLE, name);
ModelNode role = Util.createAddOperation(roleAddress);
AuthorizationRoleResource.NAME.parseAndSetParameter(name, role, reader);
for(String perm : attributes[1].split("\\s+")) {
AuthorizationRoleResource.PERMISSIONS.parseAndAddParameterElement(perm, role, reader);
}
ParseUtils.requireNoContent(reader);
operations.put(roleAddress, role);
}
private void parseCacheAttribute(XMLExtendedStreamReader reader, int index, Attribute attribute, String value, ModelNode cache) throws XMLStreamException {
switch (attribute) {
case NAME: {
CacheConfigurationResource.NAME.parseAndSetParameter(value, cache, reader);
break;
}
case START: {
CacheConfigurationResource.START.parseAndSetParameter(value, cache, reader);
if (!value.equalsIgnoreCase("EAGER")) {
Location location = reader.getLocation();
log.warnf("Ignoring start mode [%s] at [row,col] [%s, %s], as EAGER is the only supported mode", value,
location.getLineNumber(), location.getColumnNumber());
cache.get(CacheConfigurationResource.START.getName()).set("EAGER");
}
break;
}
case CONFIGURATION: {
CacheConfigurationResource.CONFIGURATION.parseAndSetParameter(value, cache, reader);
break;
}
case JNDI_NAME: {
CacheConfigurationResource.JNDI_NAME.parseAndSetParameter(value, cache, reader);
break;
}
case BATCHING: {
CacheConfigurationResource.BATCHING.parseAndSetParameter(value, cache, reader);
break;
}
case MODULE: {
CacheConfigurationResource.CACHE_MODULE.parseAndSetParameter(value, cache, reader);
Location location = reader.getLocation();
ROOT_LOGGER.cacheModuleDeprecated(location.getLineNumber(), location.getColumnNumber());
break;
}
case SIMPLE_CACHE: {
CacheConfigurationResource.SIMPLE_CACHE.parseAndSetParameter(value, cache, reader);
break;
}
case STATISTICS: {
CacheConfigurationResource.STATISTICS.parseAndSetParameter(value, cache, reader);
break;
}
case STATISTICS_AVAILABLE: {
CacheConfigurationResource.STATISTICS_AVAILABLE.parseAndSetParameter(value, cache, reader);
break;
}
default: {
throw ParseUtils.unexpectedAttribute(reader, index);
}
}
}
private void parseClusteredCacheAttribute(XMLExtendedStreamReader reader, int index, Attribute attribute, String value, ModelNode cache) throws XMLStreamException {
switch (attribute) {
case ASYNC_MARSHALLING: {
if (namespace.since(Namespace.INFINISPAN_SERVER_8_0)) {
throw ParseUtils.unexpectedAttribute(reader, index);
} else {
log.warn("The async-marshalling attribute has been deprecated and has no effect, please update your configuration file.");
break;
}
}
case MODE: {
ClusteredCacheConfigurationResource.MODE.parseAndSetParameter(value, cache, reader);
break;
}
case QUEUE_SIZE: {
if (namespace.since(Namespace.INFINISPAN_SERVER_9_0)) {
throw ParseUtils.unexpectedAttribute(reader, index);
} else {
log.warn("The queue-size attribute has been deprecated and has no effect, please update your configuration file.");
break;
}
}
case QUEUE_FLUSH_INTERVAL: {
if (namespace.since(Namespace.INFINISPAN_SERVER_9_0)) {
throw ParseUtils.unexpectedAttribute(reader, index);
} else {
log.warn("The queue-flush-interval attribute has been deprecated and has no effect, please update your configuration file.");
break;
}
}
case REMOTE_TIMEOUT: {
ClusteredCacheConfigurationResource.REMOTE_TIMEOUT.parseAndSetParameter(value, cache, reader);
break;
}
default: {
this.parseCacheAttribute(reader, index, attribute, value, cache);
}
}
}
private void addCacheForConfiguration(ModelNode cacheConfiguration, String configurationName, PathAddress containerAddress, String type, Map<PathAddress, ModelNode> operations) {
String name = PathAddress.pathAddress(cacheConfiguration.get(OP_ADDR)).getLastElement().getValue();
PathAddress cacheAddress = containerAddress.append(type, name);
ModelNode cache = Util.getEmptyOperation(ADD, cacheAddress.toModelNode());
cache.get(ModelKeys.CONFIGURATION).set(configurationName == null ? name : configurationName);
operations.put(cacheAddress, cache);
}
private void parseLocalCache(XMLExtendedStreamReader reader, PathAddress containerAddress, Map<PathAddress, ModelNode> operations, boolean configurationOnly) throws XMLStreamException {
// ModelNode for the cache add operation
ModelNode cacheConfiguration = Util.getEmptyOperation(ADD, null);
// NOTE: this list is used to avoid lost attribute updates to the cache
// object once it has been added to the operations list
Map<PathAddress, ModelNode> additionalConfigurationOperations = new LinkedHashMap<>();
for (int i = 0; i < reader.getAttributeCount(); i++) {
String value = reader.getAttributeValue(i);
Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
this.parseCacheAttribute(reader, i, attribute, value, cacheConfiguration);
}
if (!cacheConfiguration.hasDefined(ModelKeys.NAME)) {
throw ParseUtils.missingRequired(reader, EnumSet.of(Attribute.NAME));
}
// update the cache configuration address with the cache name
PathAddress cacheConfigurationAddress = addNameToAddress(cacheConfiguration, containerAddress, ModelKeys.LOCAL_CACHE) ;
while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
Element element = Element.forName(reader.getLocalName());
this.parseCacheElement(reader, element, cacheConfiguration, additionalConfigurationOperations);
}
addCacheConfiguration(ModelKeys.LOCAL_CACHE, containerAddress, operations, configurationOnly, cacheConfiguration,
additionalConfigurationOperations, cacheConfigurationAddress);
}
private void addCacheConfiguration(String cacheType, PathAddress containerAddress, Map<PathAddress, ModelNode> operations,
boolean configurationOnly, ModelNode cacheConfiguration,
Map<PathAddress, ModelNode> additionalConfigurationOperations, PathAddress cacheConfigurationAddress) {
cacheConfiguration.get(CacheConfigurationResource.TEMPLATE.getName()).set(configurationOnly);
if (configurationOnly) {
// just create the configuration
operations.put(cacheConfigurationAddress, cacheConfiguration);
operations.putAll(additionalConfigurationOperations);
} else {
if (cacheConfiguration.hasDefined(ModelKeys.CONFIGURATION) && additionalConfigurationOperations.size() == 0) {