RolloutManagerImpl.java
57.9 KB
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.replication.ReplicationAction
* com.day.cq.replication.ReplicationActionType
* com.day.cq.wcm.api.Page
* com.day.cq.wcm.api.PageManager
* com.day.cq.wcm.api.PageModification
* com.day.cq.wcm.api.PageModification$ModificationType
* com.day.cq.wcm.api.WCMException
* com.day.cq.wcm.msm.api.LiveAction
* com.day.cq.wcm.msm.api.LiveCopy
* com.day.cq.wcm.msm.api.LiveRelationship
* com.day.cq.wcm.msm.api.LiveRelationshipManager
* com.day.cq.wcm.msm.api.LiveStatus
* com.day.cq.wcm.msm.api.ResourceNameRolloutConflictHandler
* com.day.cq.wcm.msm.api.RolloutConfig
* com.day.cq.wcm.msm.api.RolloutExceptionHandler
* com.day.cq.wcm.msm.api.RolloutExceptionHandler$RolloutInfo
* com.day.cq.wcm.msm.api.RolloutManager
* com.day.cq.wcm.msm.api.RolloutManager$RolloutParams
* com.day.cq.wcm.msm.api.RolloutManager$RolloutProgress
* com.day.cq.wcm.msm.api.RolloutManager$Trigger
* com.day.cq.wcm.msm.commons.BaseAction
* com.day.cq.wcm.msm.commons.BaseActionFactory
* com.day.text.Text
* javax.jcr.ItemNotFoundException
* javax.jcr.Node
* javax.jcr.NodeIterator
* javax.jcr.Property
* javax.jcr.RangeIterator
* javax.jcr.RepositoryException
* javax.jcr.Session
* javax.jcr.nodetype.NodeDefinition
* javax.jcr.nodetype.NodeType
* org.apache.commons.collections.IteratorUtils
* org.apache.commons.collections.Transformer
* org.apache.commons.lang.ArrayUtils
* org.apache.felix.scr.annotations.Activate
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.ConfigurationPolicy
* org.apache.felix.scr.annotations.Deactivate
* org.apache.felix.scr.annotations.Properties
* org.apache.felix.scr.annotations.Property
* org.apache.felix.scr.annotations.PropertyOption
* org.apache.felix.scr.annotations.PropertyUnbounded
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.ReferencePolicyOption
* org.apache.felix.scr.annotations.Service
* org.apache.sling.api.resource.NonExistingResource
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.resource.ResourceResolverFactory
* org.apache.sling.api.resource.ValueMap
* org.apache.sling.commons.osgi.PropertiesUtil
* org.osgi.framework.BundleContext
* org.osgi.framework.ServiceRegistration
* org.osgi.service.component.ComponentContext
* org.osgi.service.event.Event
* org.osgi.service.event.EventAdmin
* org.osgi.service.event.EventHandler
* org.osgi.util.tracker.ServiceTracker
* org.osgi.util.tracker.ServiceTrackerCustomizer
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.cq.wcm.msm.impl;
import com.day.cq.replication.ReplicationAction;
import com.day.cq.replication.ReplicationActionType;
import com.day.cq.wcm.api.Page;
import com.day.cq.wcm.api.PageManager;
import com.day.cq.wcm.api.PageModification;
import com.day.cq.wcm.api.WCMException;
import com.day.cq.wcm.msm.api.LiveAction;
import com.day.cq.wcm.msm.api.LiveCopy;
import com.day.cq.wcm.msm.api.LiveRelationship;
import com.day.cq.wcm.msm.api.LiveRelationshipManager;
import com.day.cq.wcm.msm.api.LiveStatus;
import com.day.cq.wcm.msm.api.ResourceNameRolloutConflictHandler;
import com.day.cq.wcm.msm.api.RolloutConfig;
import com.day.cq.wcm.msm.api.RolloutExceptionHandler;
import com.day.cq.wcm.msm.api.RolloutManager;
import com.day.cq.wcm.msm.commons.BaseAction;
import com.day.cq.wcm.msm.commons.BaseActionFactory;
import com.day.cq.wcm.msm.impl.BlueprintEvent;
import com.day.cq.wcm.msm.impl.LiveCopyManagerImpl;
import com.day.cq.wcm.msm.impl.LiveRelationshipManagerImpl;
import com.day.cq.wcm.msm.impl.MoveLiveCopyResourceConflictHandler;
import com.day.cq.wcm.msm.impl.PageEventList;
import com.day.cq.wcm.msm.impl.RolloutContextImpl;
import com.day.cq.wcm.msm.impl.StatusUtil;
import com.day.cq.wcm.msm.impl.Utils;
import com.day.text.Text;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
import java.util.Dictionary;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
import javax.jcr.ItemNotFoundException;
import javax.jcr.Node;
import javax.jcr.NodeIterator;
import javax.jcr.Property;
import javax.jcr.RangeIterator;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.nodetype.NodeDefinition;
import javax.jcr.nodetype.NodeType;
import org.apache.commons.collections.IteratorUtils;
import org.apache.commons.collections.Transformer;
import org.apache.commons.lang.ArrayUtils;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.ConfigurationPolicy;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.PropertyOption;
import org.apache.felix.scr.annotations.PropertyUnbounded;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferencePolicyOption;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.resource.NonExistingResource;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceResolverFactory;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.commons.osgi.PropertiesUtil;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.component.ComponentContext;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventAdmin;
import org.osgi.service.event.EventHandler;
import org.osgi.util.tracker.ServiceTracker;
import org.osgi.util.tracker.ServiceTrackerCustomizer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component(metatype=1, label="%rolloutmgr.name", description="%rolloutmgr.description", policy=ConfigurationPolicy.REQUIRE)
@Service
@org.apache.felix.scr.annotations.Properties(value={@org.apache.felix.scr.annotations.Property(name="event.topics", propertyPrivate=1, value={"com/day/cq/wcm/msm/blueprint/pageEvent", "com/day/cq/wcm/msm/blueprint/replication"}), @org.apache.felix.scr.annotations.Property(name="event.filter", value={"(!(event.application=*))"})})
public class RolloutManagerImpl
implements RolloutManager,
EventHandler {
private static final int DEFAULT_COMMIT_SIZE = 500;
private static final int DEFAULT_MAX_SHUTDOWN_WAITING_TIME = 10;
private static final boolean DEFAULT_MANUALLY_CREATION_CONFLICT_HANDLING = true;
@Deprecated
@org.apache.felix.scr.annotations.Property(value={"jcr:.*", "sling:.*", "cq:.*"}, unbounded=PropertyUnbounded.ARRAY)
public static final String DEFAULT_EXCLUDED_PROPERTIES = "rolloutmgr.excludedprops.default";
@Deprecated
@org.apache.felix.scr.annotations.Property(value={"cq:propertyInheritanceCancelled", "jcr:frozenUuid", "jcr:uuid"}, unbounded=PropertyUnbounded.ARRAY)
public static final String DEFAULT_EXCLUDED_PARAGRAPH_PROPERTIES = "rolloutmgr.excludedparagraphprops.default";
@org.apache.felix.scr.annotations.Property(value={"cq:LiveSyncAction", "cq:LiveSyncConfig", "cq:BlueprintSyncConfig", "cq:LiveCopy"}, unbounded=PropertyUnbounded.ARRAY)
private static final String DEFAULT_EXCLUDED_NODE_TYPES = "rolloutmgr.excludednodetypes.default";
@org.apache.felix.scr.annotations.Property(intValue={5})
private static final String DEFAULT_THREADPOOL_MAX_SIZE = "rolloutmgr.threadpool.maxsize";
@org.apache.felix.scr.annotations.Property(intValue={10})
private static final String MAX_SHUTDOWN_WAIT_TIME = "rolloutmgr.threadpool.maxshutdowntime";
@org.apache.felix.scr.annotations.Property(value={"MIN"}, options={@PropertyOption(name="NORM", value="%rolloutmgr.threadpool.priorityNormal"), @PropertyOption(name="MAX", value="%rolloutmgr.threadpool.priorityMaximal"), @PropertyOption(name="MIN", value="%rolloutmgr.threadpool.priorityMinimal")})
private static final String DEFAULT_THREADPOOL_PRIORITY = "rolloutmgr.threadpool.priority";
@org.apache.felix.scr.annotations.Property(intValue={500}, propertyPrivate=0)
private static final String COMMIT_SIZE = "rolloutmgr.commit.size";
@org.apache.felix.scr.annotations.Property(boolValue={1})
static final String HANDLE_MANUALLY_CREATED_CONFLICT = "rolloutmgr.conflicthandling.enabled";
@Reference
private ResourceResolverFactory resolverFactory = null;
@Reference
private LiveRelationshipManager relManager = null;
@Reference
private EventAdmin eventAdmin = null;
@Reference(policyOption=ReferencePolicyOption.GREEDY)
private RolloutExceptionHandler rolloutExceptionHandler = null;
private static final String PATH_UUID = "jcr:content/jcr:uuid";
private static final Logger log = LoggerFactory.getLogger(RolloutManagerImpl.class);
private Set<String> excludedPageProperties = new HashSet<String>();
private Set<String> excludedParagraphProperties = new HashSet<String>();
private Set<String> excludedNodeTypes = new HashSet<String>();
private Set<String> reservedProperties = new HashSet<String>();
private final BlockingQueue<Event> events = new LinkedBlockingQueue<Event>();
private volatile Thread processor;
private ExecutorService serviceExecutor;
private int commitSize;
private int maxShutdownWaitTime;
private ArrayList<LiveAction> preRolloutConfig;
private boolean handleNameConflict;
private ServiceTracker conflictHandlerTracker;
private ServiceRegistration defaultConflictHandler;
@Activate
protected void activate(ComponentContext context) throws Exception {
Dictionary props = context.getProperties();
Integer maxPoolSize = PropertiesUtil.toInteger(props.get("rolloutmgr.threadpool.maxsize"), (int)5);
final THREAD_PRIORITY threadPriority = THREAD_PRIORITY.valueOf(PropertiesUtil.toString(props.get("rolloutmgr.threadpool.priority"), (String)THREAD_PRIORITY.MIN.name()));
ThreadFactory threadFactory = new ThreadFactory(){
@Override
public Thread newThread(Runnable r) {
Thread thread = new Thread(r);
thread.setPriority(threadPriority.priority);
return thread;
}
};
this.serviceExecutor = Executors.newFixedThreadPool(maxPoolSize, threadFactory);
this.excludedPageProperties.clear();
if (props.get("rolloutmgr.excludedprops.default") != null) {
this.excludedPageProperties.addAll(Arrays.asList(PropertiesUtil.toStringArray(props.get("rolloutmgr.excludedprops.default"))));
}
this.excludedParagraphProperties.clear();
if (props.get("rolloutmgr.excludedparagraphprops.default") != null) {
this.excludedParagraphProperties.addAll(Arrays.asList(PropertiesUtil.toStringArray(props.get("rolloutmgr.excludedparagraphprops.default"))));
}
this.excludedNodeTypes.clear();
if (props.get("rolloutmgr.excludednodetypes.default") != null) {
this.excludedNodeTypes.addAll(Arrays.asList(PropertiesUtil.toStringArray(props.get("rolloutmgr.excludednodetypes.default"))));
}
this.reservedProperties.add("cq:isCancelledForChildren");
this.reservedProperties.add("cq:lastRolledout");
this.reservedProperties.add("cq:lastRolledoutBy");
this.commitSize = PropertiesUtil.toInteger(props.get("rolloutmgr.commit.size"), (int)500);
this.maxShutdownWaitTime = PropertiesUtil.toInteger(props.get("rolloutmgr.threadpool.maxshutdowntime"), (int)10);
this.preRolloutConfig = new ArrayList(1);
this.preRolloutConfig.add((LiveAction)new GhostCleanUpHandler());
this.handleNameConflict = PropertiesUtil.toBoolean(props.get("rolloutmgr.conflicthandling.enabled"), (boolean)true);
if (this.handleNameConflict) {
Properties registrationProps = new Properties();
registrationProps.put("component.name", MoveLiveCopyResourceConflictHandler.class.getName());
registrationProps.put("service.pid", MoveLiveCopyResourceConflictHandler.class.getName());
registrationProps.put("service.ranking", -2147440000);
registrationProps.put("service.vendor", "Adobe Systems Incorporated");
this.defaultConflictHandler = context.getBundleContext().registerService(ResourceNameRolloutConflictHandler.class.getName(), (Object)new MoveLiveCopyResourceConflictHandler(this, this.relManager, this.eventAdmin), (Dictionary)registrationProps);
this.conflictHandlerTracker = new ServiceTracker(context.getBundleContext(), ResourceNameRolloutConflictHandler.class.getName(), null);
this.conflictHandlerTracker.open();
}
this.start();
}
@Deactivate
protected void deactivate(ComponentContext context) {
if (this.conflictHandlerTracker != null) {
this.conflictHandlerTracker.close();
}
if (this.defaultConflictHandler != null) {
this.defaultConflictHandler.unregister();
}
if (this.serviceExecutor != null) {
try {
this.serviceExecutor.shutdown();
this.serviceExecutor.awaitTermination(this.maxShutdownWaitTime, TimeUnit.MINUTES);
}
catch (InterruptedException e) {
// empty catch block
}
}
this.stop();
}
public boolean isExcludedProperty(String propertyName) {
return this.isExcludedPageProperty(propertyName);
}
public boolean isExcludedProperty(boolean isPage, String propertyName) {
if (isPage) {
return this.isExcludedPageProperty(propertyName);
}
return this.isExcludedParagraphProperty(propertyName);
}
public boolean isExcludedPageProperty(String propertyName) {
for (String reg : this.excludedPageProperties) {
if (!propertyName.matches(reg)) continue;
return true;
}
return this.isReservedProperty(propertyName);
}
public boolean isExcludedParagraphProperty(String propertyName) {
for (String reg : this.excludedParagraphProperties) {
if (!propertyName.matches(reg)) continue;
return true;
}
return this.isReservedProperty(propertyName);
}
public boolean isExcludedNodeType(String nodeType) {
for (String reg : this.excludedNodeTypes) {
if (!nodeType.matches(reg)) continue;
return true;
}
return false;
}
public boolean isExcludedNode(Node node) throws RepositoryException {
if (node == null) {
return true;
}
if (node.getDefinition().isProtected()) {
return true;
}
if (this.isExcludedNodeType(node.getPrimaryNodeType().getName())) {
return true;
}
for (NodeType nt : node.getMixinNodeTypes()) {
if (!this.isExcludedNodeType(nt.getName())) continue;
return true;
}
return false;
}
public boolean isReservedProperty(String propertyName) {
for (String reg : this.reservedProperties) {
if (!propertyName.matches(reg)) continue;
return true;
}
return false;
}
public void updateRolloutInfo(Node node, boolean deepUpdate, boolean autoSave) throws WCMException {
block9 : {
RolloutExceptionHandler.RolloutInfo info = new RolloutExceptionHandler.RolloutInfo();
try {
info.operation = "updateRolloutInfo";
info.src = node.getPath();
info.target = node.getPath();
info.user = node.getSession().getUserID();
if (!this.isExcludedNode(node)) {
if (node.isNodeType("cq:LiveRelationship")) {
node.setProperty("cq:lastRolledout", Calendar.getInstance());
node.setProperty("cq:lastRolledoutBy", node.getSession().getUserID());
}
if (deepUpdate) {
NodeIterator iter = node.getNodes();
while (iter.hasNext()) {
Node child = (Node)iter.next();
this.updateRolloutInfo(child, true, autoSave);
}
}
if (autoSave) {
node.getSession().save();
}
}
}
catch (WCMException we) {
if (!this.rolloutExceptionHandler.handleException((Exception)we, info)) {
throw we;
}
}
catch (Exception re) {
if (this.rolloutExceptionHandler.handleException(re, info)) break block9;
log.error("Error while updating rollout info", (Throwable)re);
throw new WCMException("Error while updating rollout info", (Throwable)re);
}
}
}
public void rollout(RolloutManager.RolloutParams params) throws WCMException {
if (params.master == null || params.master.getContentResource() == null) {
if (params.master == null) {
log.warn("Roll-out failed: No Master Parameter given.");
} else {
log.warn("Roll-out ignored: given Source Page at {} does not have any content", (Object)params.master.getPath());
}
return;
}
RolloutSettings settings = RolloutSettings.fromParams(params);
if (!settings.isPage()) {
log.debug("Executing paragraphs rollout, params={}", (Object)params);
ResourceResolver resolver = ((Resource)params.master.adaptTo(Resource.class)).getResourceResolver();
for (String path : params.paragraphs) {
block12 : {
Resource source = resolver.getResource(path);
if (params.delete) {
Node sourceNode;
log.warn("Used deprecated Parameter: delete resource before roll-out");
Node node = sourceNode = source != null ? (Node)source.adaptTo(Node.class) : null;
if (sourceNode != null) {
try {
sourceNode.remove();
log.debug("Deleted paragraph for {}", (Object)source.getPath());
}
catch (Exception e) {
RolloutExceptionHandler.RolloutInfo info = settings.getRolloutInfo();
info.operation = "DELETE";
info.src = source.getPath();
if (this.rolloutExceptionHandler.handleException(e, info)) break block12;
try {
sourceNode.getSession().refresh(false);
}
catch (RepositoryException e1) {
log.error("Failed to rollback changes {}", (Throwable)e1);
throw new WCMException((Throwable)e1);
}
}
}
}
}
this.rolloutResourceRelations(settings);
}
} else {
log.debug("Executing page rollout, params={}", (Object)params);
this.rolloutPageRelations(settings, settings.createRootcontexts(this.relManager));
}
this.save(settings);
}
public void rollout(ResourceResolver resolver, LiveRelationship relation, boolean reset) throws WCMException {
this.rollout(resolver, relation, reset, true);
}
public void rollout(ResourceResolver resolver, LiveRelationship relation, boolean reset, boolean autoSave) throws WCMException {
RolloutSettings settings = null;
try {
settings = RolloutSettings.fromRelationship(resolver, relation, reset);
}
catch (RepositoryException e) {
throw new WCMException((Throwable)e);
}
Page sourcePage = null;
if (settings.isPage()) {
PageManager pm = (PageManager)resolver.adaptTo(PageManager.class);
Page page = sourcePage = pm == null ? null : pm.getContainingPage(relation.getSourcePath());
if (sourcePage == null) {
log.debug("Source of LiveRelationship that is a page-relation not found at {}: roll-out Relationships", (Object)relation.getSourcePath());
}
}
if (sourcePage != null) {
log.debug("Found Source of page-relation at {}: roll-out Page", (Object)relation.getSourcePath());
this.rolloutPageRelations(settings, settings.createRootcontexts(this.relManager));
} else {
this.rolloutResourceRelations(settings);
}
if (autoSave) {
this.save(resolver, null);
}
}
public static void removeMarker(Node targetNode) throws RepositoryException {
if (targetNode.hasProperty("cq:lastRolledout")) {
targetNode.getProperty("cq:lastRolledout").remove();
}
if (targetNode.hasProperty("cq:lastRolledoutBy")) {
targetNode.getProperty("cq:lastRolledoutBy").remove();
}
if (targetNode.isNodeType("cq:LiveRelationship")) {
targetNode.removeMixin("cq:LiveRelationship");
}
}
private void updateRolloutInfo(Resource resource) throws WCMException {
Node node;
if (resource != null && (node = (Node)resource.adaptTo(Node.class)) != null) {
this.updateRolloutInfo(node, false, false);
}
}
private int rolloutResourceRelations(RolloutSettings settings) throws WCMException {
int unSavedChanges = 0;
Iterator<RolloutContextImpl> itr = settings.createRootcontexts(this.relManager);
while (itr.hasNext()) {
RolloutContextImpl context = itr.next();
context.reportProgress("ROLLOUT");
while (context.hasNextRolloutConfig()) {
if ((unSavedChanges += this.rolloutResource(context.nextRolloutConfig())) < this.commitSize && !context.hasNextRolloutConfig()) continue;
unSavedChanges = 0;
this.save(context);
}
}
return unSavedChanges;
}
private void rolloutPageRelations(RolloutSettings setting, Iterator<RolloutContextImpl> contexts) throws WCMException {
int unsavedChanges = 0;
HashMap<String, RolloutContextImpl> configChanges = new HashMap<String, RolloutContextImpl>();
while (contexts.hasNext()) {
RolloutContextImpl pageContext = contexts.next();
while (pageContext.hasNextRolloutConfig()) {
RolloutContextImpl rolloutContext;
rolloutContext.setForceUpdate((rolloutContext = pageContext.nextRolloutConfig()).isForceUpdate() || !setting.isDeep());
log.debug("Process RolloutConfig {} on {} -> {}", (Object[])new String[]{pageContext.getCurrentRolloutConfig().getPath(), pageContext.getRelationship().getSourcePath(), pageContext.getRelationship().getTargetPath()});
configChanges.putAll(rolloutContext.getConfigChanges());
if (pageContext.hasNextRolloutConfig() || !configChanges.isEmpty() || (unsavedChanges += this.rolloutPage(rolloutContext)) >= this.commitSize) {
this.save(pageContext);
unsavedChanges = 0;
}
if (!pageContext.hasNextRolloutConfig()) continue;
LiveRelationship relation = pageContext.getRelationship();
Resource target = RolloutManagerImpl.getResourceForced(pageContext.getResourceResolver(), relation.getTargetPath());
LiveRelationship tmp = this.relManager.getLiveRelationship(target, true);
if (tmp == null) {
log.debug("Roll-out with config {} removed Relationship of {}: continue", (Object)pageContext.getCurrentRolloutConfig().getPath(), (Object)target.getPath());
continue;
}
if (pageContext.isSame(tmp)) continue;
log.debug("Roll-out with config {} changed Relationship of {}: recalculate definition", (Object)pageContext.getCurrentRolloutConfig().getPath(), (Object)target.getPath());
RolloutContextImpl changed = pageContext.forRelationship(tmp, true);
if (pageContext.contains(tmp)) {
pageContext = changed;
log.debug("changed Relationship still in same scope {}: recalculate definition", (Object)target.getPath());
continue;
}
if (pageContext.isMoved() && !changed.isMoved()) {
RangeIterator moved = this.relManager.getLiveRelationships(pageContext.getSource(true), ((LiveCopyManagerImpl.LiveCopyImpl)relation.getLiveCopy()).getMoveTarget(), null);
if (!moved.hasNext()) continue;
configChanges.clear();
LiveRelationship movedRelation = (LiveRelationship)moved.next();
RolloutContextImpl movedContext = pageContext.forRelationship(movedRelation, true);
movedContext.setForceUpdate(true);
configChanges.put(movedRelation.getTargetPath(), movedContext);
RolloutContextImpl old = pageContext.forRelationship(tmp, true);
old.setForceUpdate(true);
configChanges.put(tmp.getTargetPath(), old);
log.debug("Relation change moved resource at {} to {}", (Object)target.getPath(), (Object)movedRelation.getTargetPath());
break;
}
log.debug("Relation change moved resource at {} out of roll-out scope: abort", (Object)target.getPath());
break;
}
for (RolloutContextImpl changedContext : configChanges.values()) {
changedContext.loadTarget();
this.rolloutPageRelations(setting, Collections.singleton(changedContext).iterator());
}
if (!this.handleNameConflict || !pageContext.hasNameConflicts()) continue;
ResourceNameRolloutConflictHandler nameConflictHandler = this.getResourceNameConflictHandler();
for (RolloutContextImpl conflictingContext : pageContext.getAllNameConflicts()) {
ResourceResolver resolver = conflictingContext.getResourceResolver();
LiveRelationship conflictRelation = conflictingContext.getRelationship();
try {
log.debug("Try to resolver name conflict on {} with {}", (Object)conflictRelation.getTargetPath(), (Object)nameConflictHandler.getClass().getSimpleName());
if (nameConflictHandler.handleNameConflict(conflictRelation, resolver, setting.isReset())) {
Resource source = RolloutManagerImpl.getResourceForced(resolver, conflictRelation.getSourcePath());
String lcPath = Utils.getContainingPagePath(conflictRelation.getTargetPath());
RangeIterator resolvedRelations = this.relManager.getLiveRelationships(source, Text.getRelativeParent((String)lcPath, (int)1), conflictingContext.getTrigger());
while (resolvedRelations.hasNext()) {
LiveRelationship nextRelationship = (LiveRelationship)resolvedRelations.next();
RolloutSettings subSetting = RolloutSettings.fromRelationship(setting.getResourceResolver(), nextRelationship, setting.isReset());
subSetting.setIsDeep(setting.isDeep());
log.debug("Handler asked to roll-out resolved conflict again from {} to {}", (Object)conflictRelation.getSourcePath(), (Object)conflictRelation.getTargetPath());
if (nextRelationship.getStatus().isPage()) {
this.rolloutPageRelations(setting, subSetting.createRootcontexts(this.relManager));
continue;
}
this.rolloutResourceRelations(subSetting);
}
continue;
}
log.debug("ConflictHandler did finish normally");
continue;
}
catch (WCMException e) {
if (this.rolloutExceptionHandler.handleException((Exception)e, conflictingContext.getRolloutInfo())) continue;
throw e;
}
catch (RepositoryException e) {
if (this.rolloutExceptionHandler.handleException((Exception)e, conflictingContext.getRolloutInfo())) continue;
throw new WCMException((Throwable)e);
}
}
}
}
private int rolloutPage(RolloutContextImpl context) throws WCMException {
int unSavedChanges = 1;
LiveRelationship relation = context.getRelationship();
if (context.hasChangesToRollout() || context.isForceUpdate()) {
log.debug("Rolling out content for Page at {} to {}", (Object)Text.getRelativeParent((String)relation.getSourcePath(), (int)1), (Object)Text.getRelativeParent((String)relation.getTargetPath(), (int)1));
RolloutContextImpl contentContext = context.forRelationship(relation);
contentContext.setDeep(true);
unSavedChanges += this.rolloutResource(contentContext);
context.loadTarget();
} else {
log.debug("Source at {} has not been modified since last roll-out to {}: skip update", (Object)relation.getSourcePath(), (Object)relation.getTargetPath());
}
this.updateRolloutInfo(context.getTarget());
if (context.isDeep() && !context.hasNameConflicts()) {
Iterator<RolloutContextImpl> children = context.getChildren(this.relManager);
while (children.hasNext()) {
RolloutContextImpl childContext;
childContext.setForceUpdate((childContext = children.next()).getTarget() == null);
unSavedChanges += this.rolloutPage(childContext);
}
}
return unSavedChanges;
}
private int rolloutResource(RolloutContextImpl context) throws WCMException {
int unSavedChanges;
block19 : {
unSavedChanges = 1;
try {
if (context.isReset()) {
context = this.reenableInheritance(context);
}
ResourceResolver resolver = context.getResourceResolver();
LiveRelationship relationship = context.getRelationship();
if (!relationship.getStatus().isCancelled() && !relationship.getStatus().getAdvancedStatus("msm:isTargetSkipped").booleanValue()) {
Node checkNode = (Node)context.getSource(true).adaptTo(Node.class);
if (checkNode == null) {
context.loadTarget();
Node node = checkNode = context.getTarget() == null ? null : (Node)context.getTarget().adaptTo(Node.class);
}
if (checkNode == null) {
log.debug("Neither Source {} nor Target {} exists: nothing to roll-out", (Object)relationship.getSourcePath(), (Object)relationship.getTargetPath());
return 0;
}
if (this.isExcludedNode(checkNode)) {
log.debug("Relation on excluded NodeType {}: no update", (Object)relationship.getSourcePath());
} else {
Node targetNode;
LiveRelationship rolloutRelationship;
for (LiveAction action : this.preRolloutConfig) {
log.debug("Pre-roll-out config with LiveAction {}", (Object)action.getClass().getName());
Resource targetResource = context.getTarget();
action.execute(context.getSource(), targetResource, relationship, false, context.isReset());
context.loadTarget();
}
if (relationship.getStatus().isTargetExisting() == (resolver.getResource(relationship.getTargetPath()) == null)) {
log.debug("Pre-Rollout changed LiveRelationship at {}", (Object)relationship.getTargetPath());
rolloutRelationship = RolloutManagerImpl.updateLiveState(relationship, resolver);
context = context.forRelationship(rolloutRelationship);
} else {
rolloutRelationship = relationship;
}
Map checkStatus = rolloutRelationship.getStatus().getAdvancedStatus();
if (checkStatus.containsKey("msm:isTargetManuallyCreated") && ((Boolean)checkStatus.get("msm:isTargetManuallyCreated")).booleanValue()) {
if (context.getSource() != null || context.isReset()) {
context.addNameConflict(context);
log.debug("Postponed relation on manually created target at {}", (Object)rolloutRelationship.getTargetPath());
} else {
log.debug("Manually created target at {} but no conflict: skip roll-out", (Object)rolloutRelationship.getTargetPath());
}
return unSavedChanges;
}
RolloutConfig config = context.getCurrentRolloutConfig();
log.debug("Apply RolloutConfig {} from {} to {}", new Object[]{config.getPath(), rolloutRelationship.getSourcePath(), relationship.getTargetPath()});
context.reportProgress("ROLLOUT");
for (LiveAction action2 : config.getActions()) {
log.debug("Apply active LiveAction {}", (Object)action2.getClass().getName());
Resource target = context.getTarget();
action2.execute(context.getSource(), target, rolloutRelationship, false, context.isReset());
context.loadTarget();
}
Resource target = context.getTarget();
Node node = targetNode = target == null ? null : (Node)target.adaptTo(Node.class);
if (targetNode != null) {
this.addNewNodes(targetNode, rolloutRelationship.getStatus().isTargetExisting());
this.updateRolloutInfo(targetNode, false, false);
}
}
} else {
log.debug("Relation cancelled to roll-out source {} to {}: nothing done", (Object)relationship.getSourcePath(), (Object)relationship.getTargetPath());
}
if (context.isDeep() && !relationship.getStatus().isCancelledForChildren()) {
log.debug("Deep roll-out for resource{}", (Object)context.getSource(true).getPath());
RangeIterator children = this.relManager.getChildren(relationship, resolver);
while (children.hasNext()) {
LiveRelationship childShip = (LiveRelationship)children.next();
unSavedChanges += this.rolloutResource(context.forRelationship(childShip));
}
}
}
catch (Exception e) {
RolloutExceptionHandler.RolloutInfo info = new RolloutExceptionHandler.RolloutInfo();
LiveRelationship relationship = context.getRelationship();
info.src = relationship.getSourcePath();
info.target = relationship.getTargetPath();
info.operation = "ROLLOUT";
info.user = context.getResourceResolver().getUserID();
if (this.rolloutExceptionHandler.handleException(e, info)) break block19;
log.error("Failed to roll-out LiveRelationship from {} to {}: {}", new Object[]{relationship.getSourcePath(), relationship.getTargetPath(), e});
throw new WCMException((Throwable)e);
}
}
return unSavedChanges;
}
private static LiveRelationship updateLiveState(final LiveRelationship relationship, final ResourceResolver resourceResolver) throws RepositoryException {
InvocationHandler invocationHandler = new InvocationHandler(){
LiveStatus newStatus;
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
String name = method.getName();
if (name.equals("getStatus")) {
return this.newStatus;
}
return method.invoke((Object)relationship, args);
}
};
return (LiveRelationship)Proxy.newProxyInstance(RolloutManagerImpl.class.getClassLoader(), new Class[]{LiveRelationship.class}, invocationHandler);
}
private void addNewNodes(Node targetNode, boolean isRelationshipTargetExisting) throws RepositoryException {
if (targetNode.isNew() || !isRelationshipTargetExisting) {
log.debug("New Resource created by LiveAction at {}, try to add to relation", (Object)targetNode.getPath());
LiveRelationshipManagerImpl.markRelationship(targetNode, false);
}
NodeIterator itr = targetNode.getNodes();
while (itr.hasNext()) {
this.addNewNodes(itr.nextNode(), isRelationshipTargetExisting);
}
}
private void rolloutRelations(Resource master, RolloutManager.Trigger triggerFilter) throws WCMException {
RolloutSettings settings = RolloutSettings.fromSource(master, triggerFilter);
if (settings.isPage()) {
this.rolloutPageRelations(settings, settings.createRootcontexts(this.relManager));
} else {
this.rolloutResourceRelations(settings);
}
}
private void start() {
this.processor = new Thread(new EventProcessor());
this.processor.setDaemon(true);
this.processor.start();
}
private void stop() {
if (this.processor != null) {
Thread interrupter = this.processor;
this.processor = null;
interrupter.interrupt();
}
}
public void handleEvent(Event event) {
try {
this.events.put(event);
}
catch (InterruptedException e) {
log.error(e.getMessage(), (Throwable)e);
}
}
private static Resource getResourceForced(ResourceResolver resolver, String path) {
Resource result = resolver.getResource(path);
if (result == null) {
result = new NonExistingResource(resolver, path);
}
return result;
}
private RolloutContextImpl reenableInheritance(RolloutContextImpl context) throws WCMException, RepositoryException {
LiveRelationship relation = context.getRelationship();
List cancelledProps = relation.getStatus().getCanceledProperties();
if (relation.getStatus().isCancelled() || cancelledProps.size() > 0) {
ResourceResolver resolver = context.getResourceResolver();
if (relation.getStatus().isCancelled()) {
this.relManager.reenableRelationship(resolver, relation, false);
}
if (relation.getStatus().getCanceledProperties().size() > 0) {
this.relManager.reenablePropertyRelationship(resolver, relation, cancelledProps.toArray(new String[cancelledProps.size()]), false);
}
relation = RolloutManagerImpl.updateLiveState(relation, resolver);
log.debug("Re-enabled LiveRelationship from {} to {}", (Object)relation.getSourcePath(), (Object)relation.getTargetPath());
return context.forRelationship(relation);
}
return context;
}
private void save(RolloutContextImpl context) throws WCMException {
this.save(context.getResourceResolver(), context.getRolloutInfo());
}
private void save(RolloutSettings settings) throws WCMException {
this.save(settings.getResourceResolver(), settings.getRolloutInfo());
}
private void save(ResourceResolver resolver, RolloutExceptionHandler.RolloutInfo info) throws WCMException {
block4 : {
Session session = (Session)resolver.adaptTo(Session.class);
try {
session.save();
}
catch (Exception e) {
log.error("Failed to save changes {}, revert", (Throwable)e);
if (info != null && this.rolloutExceptionHandler.handleException(e, info)) break block4;
try {
session.refresh(false);
throw new WCMException((Throwable)e);
}
catch (RepositoryException e1) {
log.debug("Failed to rollback changes of failed commit:", (Throwable)e1);
throw new WCMException((Throwable)e1);
}
}
}
}
private ResourceNameRolloutConflictHandler getResourceNameConflictHandler() {
if (this.conflictHandlerTracker == null) {
throw new IllegalStateException("Activation did not set happen");
}
Object registeredService = this.conflictHandlerTracker.getService();
if (registeredService == null) {
return new MoveLiveCopyResourceConflictHandler(this, this.relManager, this.eventAdmin);
}
return (ResourceNameRolloutConflictHandler)registeredService;
}
protected void bindResolverFactory(ResourceResolverFactory resourceResolverFactory) {
this.resolverFactory = resourceResolverFactory;
}
protected void unbindResolverFactory(ResourceResolverFactory resourceResolverFactory) {
if (this.resolverFactory == resourceResolverFactory) {
this.resolverFactory = null;
}
}
protected void bindRelManager(LiveRelationshipManager liveRelationshipManager) {
this.relManager = liveRelationshipManager;
}
protected void unbindRelManager(LiveRelationshipManager liveRelationshipManager) {
if (this.relManager == liveRelationshipManager) {
this.relManager = null;
}
}
protected void bindEventAdmin(EventAdmin eventAdmin) {
this.eventAdmin = eventAdmin;
}
protected void unbindEventAdmin(EventAdmin eventAdmin) {
if (this.eventAdmin == eventAdmin) {
this.eventAdmin = null;
}
}
protected void bindRolloutExceptionHandler(RolloutExceptionHandler rolloutExceptionHandler) {
this.rolloutExceptionHandler = rolloutExceptionHandler;
}
protected void unbindRolloutExceptionHandler(RolloutExceptionHandler rolloutExceptionHandler) {
if (this.rolloutExceptionHandler == rolloutExceptionHandler) {
this.rolloutExceptionHandler = null;
}
}
private static final class GhostCleanUpHandler
extends BaseAction {
private GhostCleanUpHandler() {
super(null, null);
}
protected boolean handles(Resource source, Resource target, LiveRelationship relation, boolean resetRollout) throws RepositoryException, WCMException {
try {
return resetRollout && Utils.resourceHasNode(target) && Utils.isGhost(Utils.getWorkingNode((Node)target.adaptTo(Node.class)));
}
catch (ItemNotFoundException e) {
return false;
}
}
protected void doExecute(Resource source, Resource target, LiveRelationship relation, boolean resetRollout) throws RepositoryException, WCMException {
Node targetNode = Utils.getWorkingNode((Node)target.adaptTo(Node.class));
targetNode.remove();
log.debug("Removed orphaned Ghost Component at {}", (Object)relation.getTargetPath());
}
}
private static final class RolloutSettings
implements Transformer {
private final ResourceResolver resourceResolver;
private final RolloutManager.RolloutParams params;
private LiveRelationship relationship;
private boolean isDeep;
private RolloutSettings(RolloutManager.RolloutParams params, ResourceResolver resourceResolver) {
this.resourceResolver = resourceResolver;
this.params = params;
this.isDeep = params.isDeep;
}
static RolloutSettings fromRelationship(ResourceResolver resolver, LiveRelationship liveRelationship, boolean isReset) throws RepositoryException {
RolloutManager.RolloutParams params = new RolloutManager.RolloutParams();
params.isDeep = false;
params.reset = isReset;
params.targets = new String[]{Utils.getContainingPagePath(liveRelationship.getTargetPath())};
if (liveRelationship.getStatus().isPage()) {
params.master = ((PageManager)resolver.adaptTo(PageManager.class)).getPage(Utils.getContainingPagePath(liveRelationship.getSourcePath()));
} else {
params.paragraphs = new String[]{liveRelationship.getSourcePath()};
}
RolloutSettings result = new RolloutSettings(params, resolver);
if (liveRelationship.getStatus().getAdvancedStatus().size() == 0) {
liveRelationship = RolloutManagerImpl.updateLiveState(liveRelationship, resolver);
}
result.relationship = liveRelationship;
return result;
}
static RolloutSettings fromParams(RolloutManager.RolloutParams params) {
return new RolloutSettings(params, params.master.getContentResource().getResourceResolver());
}
static RolloutSettings fromSource(Resource resource, RolloutManager.Trigger triggerFilter) {
RolloutManager.RolloutParams params = new RolloutManager.RolloutParams();
params.master = (Page)resource.adaptTo(Page.class);
params.trigger = triggerFilter;
params.isDeep = false;
params.reset = false;
if (params.master == null) {
params.paragraphs = new String[]{resource.getPath()};
}
return new RolloutSettings(params, resource.getResourceResolver());
}
public boolean isPage() {
return ArrayUtils.isEmpty((Object[])this.params.paragraphs);
}
public ResourceResolver getResourceResolver() {
return this.resourceResolver;
}
public Iterator<RolloutContextImpl> createRootcontexts(LiveRelationshipManager relationshipManager) throws WCMException {
Iterator result;
if (this.relationship != null) {
result = Collections.singleton(this.relationship).iterator();
} else if (this.isPage() && this.params.master != null) {
Resource source;
Resource resource = source = this.params.master.hasContent() ? this.params.master.getContentResource() : (Resource)this.params.master.adaptTo(Resource.class);
if (this.params.targets == null) {
result = relationshipManager.getLiveRelationships(source, null, this.params.trigger);
} else {
HashSet<RangeIterator> all = new HashSet<RangeIterator>();
for (String target : this.params.targets) {
all.add(relationshipManager.getLiveRelationships(source, target, this.params.trigger));
}
result = IteratorUtils.chainedIterator(all);
}
} else {
HashSet<RangeIterator> all = new HashSet<RangeIterator>();
for (String sourcePath : this.params.paragraphs) {
Resource source = RolloutManagerImpl.getResourceForced(this.getResourceResolver(), sourcePath);
if (this.params.targets == null) {
all.add(relationshipManager.getLiveRelationships(source, null, this.params.trigger));
continue;
}
for (String target : this.params.targets) {
all.add(relationshipManager.getLiveRelationships(source, target, this.params.trigger));
}
}
result = IteratorUtils.chainedIterator(all);
}
return IteratorUtils.transformedIterator(result, (Transformer)this);
}
public RolloutExceptionHandler.RolloutInfo getRolloutInfo() {
return new RolloutExceptionHandler.RolloutInfo(){};
}
public RolloutManager.Trigger getTrigger() {
return this.params.trigger;
}
public boolean isReset() {
return this.params.reset;
}
public boolean isDeep() {
return this.isDeep;
}
public void setIsDeep(boolean isDeep) {
this.isDeep = isDeep;
}
public Object transform(Object input) {
return new RolloutContextImpl(this.getResourceResolver(), this.getTrigger(), this.isDeep(), this.isReset(), (LiveRelationship)input, this.params.rolloutProgress == null ? new LogProgress() : this.params.rolloutProgress);
}
static /* synthetic */ RolloutManager.RolloutParams access$1100(RolloutSettings x0) {
return x0.params;
}
static final class LogProgress
implements RolloutManager.RolloutProgress {
private static final Logger log = LoggerFactory.getLogger(RolloutContextImpl.class);
LogProgress() {
}
public void reportProgress(String path, String operation) {
log.debug("Roll-out on {} with {}", (Object)path, (Object)operation);
}
}
}
private class ReplicationActionProcessor
implements Runnable {
final ReplicationAction replicationAction;
ReplicationActionProcessor(ReplicationAction replicationAction) {
this.replicationAction = replicationAction;
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
* Enabled force condition propagation
* Lifted jumps to return sites
*/
@Override
public void run() {
ResourceResolver resolver = null;
try {
resolver = RolloutManagerImpl.this.resolverFactory.getServiceResourceResolver(null);
String masterPath = this.replicationAction.getPath();
switch (this.replicationAction.getType()) {
case ACTIVATE: {
RolloutManagerImpl.this.rolloutRelations(resolver.resolve(masterPath), RolloutManager.Trigger.PUBLICATION);
RolloutManagerImpl.this.save(resolver, null);
log.debug("Roll-out on Replication of Type {} for {}", (Object)this.replicationAction.getType().name(), (Object)masterPath);
return;
}
case DEACTIVATE: {
RolloutManagerImpl.this.rolloutRelations(resolver.resolve(masterPath), RolloutManager.Trigger.DEACTIVATION);
RolloutManagerImpl.this.save(resolver, null);
log.debug("Roll-out on Replication of Type {} for {}", (Object)this.replicationAction.getType().name(), (Object)masterPath);
return;
}
default: {
log.debug("No Roll-out on Replication of Type {} for {}", (Object)this.replicationAction.getType(), (Object)masterPath);
}
}
}
catch (Exception e) {
log.error("Exception during process of event {}", (Throwable)e);
}
finally {
if (resolver != null) {
resolver.close();
}
}
}
}
private class PageEventProcessor
implements Callable<Boolean> {
final Iterator<PageModification> pageModifications;
PageEventProcessor(Iterator<PageModification> pageModifications) {
this.pageModifications = pageModifications;
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
@Override
public Boolean call() {
ResourceResolver resolver = null;
try {
resolver = RolloutManagerImpl.this.resolverFactory.getServiceResourceResolver(null);
boolean hasChanges = false;
block9 : while (this.pageModifications.hasNext()) {
PageModification pm = this.pageModifications.next();
String masterPath = pm.getPath();
if (masterPath.equals(pm.getDestination())) {
log.debug("Skip Reorder Event for {}: will be notified as Modification on Parent", (Object)masterPath);
continue;
}
if (pm.getModificationPaths() != null && pm.getModificationPaths().contains("jcr:content/jcr:uuid")) {
log.debug("Skip Event on Restore of Version on {}: will be handled on Restored event", (Object)pm.getPath());
continue;
}
switch (pm.getType()) {
case MOVED: {
RolloutManagerImpl.this.rolloutRelations(resolver.resolve(pm.getDestination()), RolloutManager.Trigger.MODIFICATION);
log.debug("Rolled-out Move on movedPath at {}", (Object)pm.getDestination());
}
case MODIFIED:
case CREATED:
case DELETED:
case RESTORED: {
RolloutManagerImpl.this.rolloutRelations(resolver.resolve(pm.getPath()), RolloutManager.Trigger.MODIFICATION);
hasChanges = true;
log.debug("Rolled-out Modification on {} for event {}", (Object)pm.getDestination(), (Object)pm.getType());
continue block9;
}
}
log.debug("Received PageEvent of type {}: nothing to do", (Object)pm.getType());
}
if (hasChanges) {
RolloutManagerImpl.this.save(resolver, null);
}
}
catch (Exception e) {
log.error("Exception during process of event {}", (Throwable)e);
}
finally {
if (resolver != null) {
resolver.close();
}
}
return Boolean.TRUE;
}
}
private class EventProcessor
implements Runnable {
private EventProcessor() {
}
@Override
public void run() {
Thread currentThread = Thread.currentThread();
while (RolloutManagerImpl.this.processor == currentThread) {
try {
ArrayList evts = new ArrayList();
evts.add(RolloutManagerImpl.this.events.take());
RolloutManagerImpl.this.events.drainTo(evts);
PageEventList pageEvents = new PageEventList();
for (Event event : evts) {
BlueprintEvent bpEvent = BlueprintEvent.fromEvent(event);
if (bpEvent == null) {
log.warn("Event at {} does not build an BlueprintEvent: ignore", (Object)event.toString());
continue;
}
if (BlueprintEvent.EVENT_TYPE.PAGE == bpEvent.getType()) {
pageEvents.addEvent(bpEvent);
continue;
}
if (BlueprintEvent.EVENT_TYPE.REPLICATION != bpEvent.getType()) continue;
RolloutManagerImpl.this.serviceExecutor.submit(new ReplicationActionProcessor(bpEvent.getReplicationAction()));
}
Iterator<List<PageEventList.PageModificationList>> itr = pageEvents.getNonOverlapping();
while (itr.hasNext()) {
LinkedList futures = new LinkedList();
for (PageEventList.PageModificationList pms : itr.next()) {
futures.add(RolloutManagerImpl.this.serviceExecutor.submit(new PageEventProcessor(pms.iterator())));
}
for (Future future : futures) {
try {
future.get();
}
catch (Exception e) {
log.debug(e.getMessage(), (Throwable)e);
}
}
}
continue;
}
catch (InterruptedException e) {
continue;
}
catch (Exception e) {
log.error("Exception while processing the events.");
continue;
}
}
RolloutManagerImpl.this.serviceExecutor = null;
}
}
private static enum THREAD_PRIORITY {
NORM(5),
MIN(1),
Max(10);
final int priority;
private THREAD_PRIORITY(int priority) {
this.priority = priority;
}
}
}