/
ConfigurationChangedDatabaseWriterFilter.java
599 lines (505 loc) · 28.1 KB
/
ConfigurationChangedDatabaseWriterFilter.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
/**
* Licensed to JumpMind Inc under one or more contributor
* license agreements. See the NOTICE file distributed
* with this work for additional information regarding
* copyright ownership. JumpMind Inc licenses this file
* to you under the GNU General Public License, version 3.0 (GPLv3)
* (the "License"); you may not use this file except in compliance
* with the License.
*
* You should have received a copy of the GNU General Public License,
* version 3.0 (GPLv3) along with this library; if not, see
* <http://www.gnu.org/licenses/>.
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jumpmind.symmetric.load;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.commons.lang3.StringUtils;
import org.jumpmind.db.model.Table;
import org.jumpmind.extension.IBuiltInExtensionPoint;
import org.jumpmind.symmetric.ISymmetricEngine;
import org.jumpmind.symmetric.Version;
import org.jumpmind.symmetric.common.Constants;
import org.jumpmind.symmetric.common.ParameterConstants;
import org.jumpmind.symmetric.common.TableConstants;
import org.jumpmind.symmetric.io.data.CsvData;
import org.jumpmind.symmetric.io.data.DataContext;
import org.jumpmind.symmetric.io.data.DataEventType;
import org.jumpmind.symmetric.io.data.writer.DatabaseWriterFilterAdapter;
import org.jumpmind.symmetric.job.IJobManager;
import org.jumpmind.symmetric.model.IncomingBatch;
import org.jumpmind.symmetric.model.Node;
import org.jumpmind.symmetric.model.NodeSecurity;
import org.jumpmind.symmetric.model.Trigger;
import org.jumpmind.symmetric.model.TriggerRouter;
import org.jumpmind.symmetric.service.INodeService;
import org.jumpmind.symmetric.service.IParameterService;
import org.jumpmind.symmetric.service.ITriggerRouterService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* An out of the box filter that checks to see if the SymmetricDS configuration
* has changed. If it has, it will take the correct action to apply the
* configuration change to the current node.
*/
public class ConfigurationChangedDatabaseWriterFilter extends DatabaseWriterFilterAdapter implements
IBuiltInExtensionPoint, ILoadSyncLifecycleListener {
static final Logger log = LoggerFactory.getLogger(ConfigurationChangedDatabaseWriterFilter.class);
final String CTX_KEY_RESYNC_NEEDED = "Resync."
+ ConfigurationChangedDatabaseWriterFilter.class.getSimpleName() + hashCode();
final String CTX_KEY_FLUSH_GROUPLETS_NEEDED = "FlushGrouplets."
+ ConfigurationChangedDatabaseWriterFilter.class.getSimpleName() + hashCode();
final String CTX_KEY_FLUSH_LOADFILTERS_NEEDED = "FlushLoadFilters."
+ ConfigurationChangedDatabaseWriterFilter.class.getSimpleName() + hashCode();
final String CTX_KEY_RESYNC_TABLE_NEEDED = "Resync.Table"
+ ConfigurationChangedDatabaseWriterFilter.class.getSimpleName() + hashCode();
final String CTX_KEY_FLUSH_CHANNELS_NEEDED = "FlushChannels."
+ ConfigurationChangedDatabaseWriterFilter.class.getSimpleName() + hashCode();
final String CTX_KEY_FLUSH_TRANSFORMS_NEEDED = "FlushTransforms."
+ ConfigurationChangedDatabaseWriterFilter.class.getSimpleName() + hashCode();
final String CTX_KEY_FLUSH_PARAMETERS_NEEDED = "FlushParameters."
+ ConfigurationChangedDatabaseWriterFilter.class.getSimpleName() + hashCode();
final String CTX_KEY_FLUSH_CONFLICTS_NEEDED = "FlushConflicts."
+ ConfigurationChangedDatabaseWriterFilter.class.getSimpleName() + hashCode();
final String CTX_KEY_FLUSH_EXTENSIONS_NEEDED = "FlushExtensions."
+ ConfigurationChangedDatabaseWriterFilter.class.getSimpleName() + hashCode();
final String CTX_KEY_FLUSH_NODE_SECURITY_NEEDED = "FlushNodeSecurity."
+ ConfigurationChangedDatabaseWriterFilter.class.getSimpleName() + hashCode();
final String CTX_KEY_FLUSH_NODE_NEEDED = "FlushNode."
+ ConfigurationChangedDatabaseWriterFilter.class.getSimpleName() + hashCode();
final String CTX_KEY_RESTART_JOBMANAGER_NEEDED = "RestartJobManager."
+ ConfigurationChangedDatabaseWriterFilter.class.getSimpleName() + hashCode();
final String CTX_KEY_REINITIALIZED = "Reinitialized."
+ ConfigurationChangedDatabaseWriterFilter.class.getSimpleName() + hashCode();
final String CTX_KEY_FILE_SYNC_ENABLED = "FileSyncEnabled."
+ ConfigurationChangedDatabaseWriterFilter.class.getSimpleName() + hashCode();
final String CTX_KEY_INITIAL_LOAD_COMPLETED = "InitialLoadCompleted."
+ ConfigurationChangedDatabaseWriterFilter.class.getSimpleName() + hashCode();
final String CTX_KEY_INITIAL_LOAD_LISTENER = "InitialLoadListener."
+ ConfigurationChangedDatabaseWriterFilter.class.getSimpleName() + hashCode();
final String CTX_KEY_MY_NODE_ID = "MyNodeId."
+ ConfigurationChangedDatabaseWriterFilter.class.getSimpleName() + hashCode();
final String CTX_KEY_MY_NODE_SECURITY = "MyNodeSecurity."
+ ConfigurationChangedDatabaseWriterFilter.class.getSimpleName() + hashCode();
private ISymmetricEngine engine;
public ConfigurationChangedDatabaseWriterFilter(ISymmetricEngine engine) {
this.engine = engine;
}
@Override
public boolean beforeWrite(DataContext context, Table table, CsvData data) {
IParameterService parameterService = engine.getParameterService();
if (context.getBatch().getBatchId() == Constants.VIRTUAL_BATCH_FOR_REGISTRATION) {
if (parameterService.is(ParameterConstants.REGISTRATION_REINITIALIZE_ENABLED)
&& !Boolean.TRUE.equals(context.get(CTX_KEY_REINITIALIZED))) {
log.info("Reinitializing the database because the {} parameter was set to true",
ParameterConstants.REGISTRATION_REINITIALIZE_ENABLED);
engine.uninstall();
engine.setupDatabase(true);
engine.start();
context.put(CTX_KEY_REINITIALIZED, Boolean.TRUE);
}
}
checkReloadStarted(context, table, data);
return true;
}
@Override
public void afterWrite(DataContext context, Table table, CsvData data) {
recordSyncNeeded(context, table, data);
recordGroupletFlushNeeded(context, table);
recordLoadFilterFlushNeeded(context, table);
recordChannelFlushNeeded(context, table);
recordTransformFlushNeeded(context, table);
recordParametersFlushNeeded(context, table);
recordJobManagerRestartNeeded(context, table, data);
recordConflictFlushNeeded(context, table);
recordExtensionFlushNeeded(context, table);
recordNodeSecurityFlushNeeded(context, table);
recordNodeFlushNeeded(context, table, data);
recordFileSyncEnabled(context, table, data);
}
private void checkReloadStarted(DataContext context, Table table, CsvData data) {
if (data.getDataEventType() == DataEventType.INSERT || data.getDataEventType() == DataEventType.UPDATE) {
if (matchesTable(table, TableConstants.SYM_NODE_SECURITY)) {
Map<String, String> newData = data.toColumnNameValuePairs(table.getColumnNames(), CsvData.ROW_DATA);
String initialLoadTime = newData.get("INITIAL_LOAD_TIME");
String initialLoadEndTime = newData.get("INITIAL_LOAD_END_TIME");
String nodeId = newData.get("NODE_ID");
String identityId = (String) context.get(CTX_KEY_MY_NODE_ID);
NodeSecurity nodeSecurity = (NodeSecurity) context.get(CTX_KEY_MY_NODE_SECURITY);
if (nodeId.equals(identityId) || identityId == null) {
if (nodeSecurity != null && (nodeSecurity.getInitialLoadTime() == null || nodeSecurity.getInitialLoadEndTime() != null) &&
StringUtils.isNotBlank(initialLoadTime) && StringUtils.isBlank(initialLoadEndTime)) {
log.info("Initial load started for me");
if (hasClientReloadListener(context)) {
List<IClientReloadListener> listeners = engine.getExtensionService().getExtensionPointList(IClientReloadListener.class);
for (IClientReloadListener listener : listeners) {
listener.reloadStarted();
}
}
}
}
}
}
}
private boolean hasClientReloadListener(DataContext context) {
Boolean hasListener = (Boolean) context.get(CTX_KEY_INITIAL_LOAD_LISTENER);
if (hasListener == null) {
hasListener = engine.getExtensionService().getExtensionPointList(IClientReloadListener.class).size() > 0;
context.put(CTX_KEY_INITIAL_LOAD_LISTENER, hasListener);
}
return hasListener && engine.getDatabasePlatform().supportsMultiThreadedTransactions();
}
private void recordGroupletFlushNeeded(DataContext context, Table table) {
if (isGroupletFlushNeeded(table)) {
context.put(CTX_KEY_FLUSH_GROUPLETS_NEEDED, true);
}
}
private void recordLoadFilterFlushNeeded(DataContext context, Table table) {
if (isLoadFilterFlushNeeded(table)) {
context.put(CTX_KEY_FLUSH_LOADFILTERS_NEEDED, true);
}
}
private void recordSyncNeeded(DataContext context, Table table, CsvData data) {
if (engine.getParameterService().is(ParameterConstants.AUTO_SYNC_TRIGGERS_AFTER_CONFIG_LOADED) ||
context.getBatch().getBatchId() == Constants.VIRTUAL_BATCH_FOR_REGISTRATION) {
queueSyncTriggers(context, table, data);
}
if (data.getDataEventType() == DataEventType.CREATE) {
@SuppressWarnings("unchecked")
Set<Table> tables = (Set<Table>)context.get(CTX_KEY_RESYNC_TABLE_NEEDED);
if (tables == null) {
tables = new HashSet<Table>();
context.put(CTX_KEY_RESYNC_TABLE_NEEDED, tables);
}
tables.add(table);
}
if (data.getDataEventType() == DataEventType.UPDATE) {
if (matchesTable(table, TableConstants.SYM_NODE_SECURITY)) {
Map<String, String> newData = data.toColumnNameValuePairs(table.getColumnNames(), CsvData.ROW_DATA);
String initialLoadEnabled = newData.get("INITIAL_LOAD_ENABLED");
String initialLoadTime = newData.get("INITIAL_LOAD_TIME");
String initialLoadEndTime = newData.get("INITIAL_LOAD_END_TIME");
String nodeId = newData.get("NODE_ID");
NodeSecurity nodeSecurity = (NodeSecurity) context.get(CTX_KEY_MY_NODE_SECURITY);
boolean isInitialLoadComplete = nodeId != null && nodeId.equals(context.getBatch().getTargetNodeId()) &&
nodeSecurity != null && nodeSecurity.getInitialLoadEndTime() == null &&
StringUtils.isNotBlank(initialLoadTime) && StringUtils.isNotBlank(initialLoadEndTime) && "0".equals(initialLoadEnabled);
if (isInitialLoadComplete && !engine.getParameterService().is(ParameterConstants.TRIGGER_CREATE_BEFORE_INITIAL_LOAD)) {
log.info("Requesting syncTriggers because {} is false and sym_node_security changed to indicate that an initial load has completed",
ParameterConstants.TRIGGER_CREATE_BEFORE_INITIAL_LOAD);
context.put(CTX_KEY_RESYNC_NEEDED, true);
engine.getRegistrationService().setAllowClientRegistration(false);
}
if (isInitialLoadComplete) {
context.put(CTX_KEY_INITIAL_LOAD_COMPLETED, true);
}
}
}
}
@SuppressWarnings("unchecked")
private void queueSyncTriggers(DataContext context, Table table, CsvData data) {
if ((matchesTable(table, TableConstants.SYM_TRIGGER) || matchesTable(table, TableConstants.SYM_TRIGGER_ROUTER))) {
Object needResync = context.get(CTX_KEY_RESYNC_NEEDED);
if (needResync == null || needResync instanceof Set) {
if (needResync == null) {
needResync = new HashSet<Object>();
context.put(CTX_KEY_RESYNC_NEEDED, needResync);
}
Map<String, String> columnValues = null;
if (data.getDataEventType() == DataEventType.DELETE) {
columnValues = data.toColumnNameValuePairs(table.getPrimaryKeyColumnNames(), CsvData.PK_DATA);
} else {
columnValues = data.toColumnNameValuePairs(table.getColumnNames(), CsvData.ROW_DATA);
}
String triggerId = columnValues.get("TRIGGER_ID");
if (matchesTable(table, TableConstants.SYM_TRIGGER_ROUTER)) {
String routerId = columnValues.get("ROUTER_ID");
TriggerRouter triggerRouter = new TriggerRouter();
triggerRouter.setTriggerId(triggerId);
triggerRouter.setRouterId(routerId);
((Set<Object>) needResync).add(triggerRouter);
} else {
Trigger trigger = new Trigger();
trigger.setTriggerId(triggerId);
((Set<Object>) needResync).add(trigger);
}
}
} else if (matchesTable(table, TableConstants.SYM_ROUTER) || matchesTable(table, TableConstants.SYM_NODE_GROUP_LINK)
|| matchesTable(table, TableConstants.SYM_TRIGGER_ROUTER_GROUPLET) || matchesTable(table, TableConstants.SYM_GROUPLET_LINK)) {
context.put(CTX_KEY_RESYNC_NEEDED, Boolean.TRUE);
}
}
@SuppressWarnings("unchecked")
private List<Trigger> convertNeedsSynced(Object needsSynced) {
if (needsSynced instanceof Set) {
Set<Trigger> triggers = new HashSet<Trigger>();
ITriggerRouterService triggerRouterService = engine.getTriggerRouterService();
triggerRouterService.clearCache();
for (Object object : (Set<Object>) needsSynced) {
Trigger trigger = null;
if (object instanceof Trigger) {
trigger = (Trigger) object;
trigger = triggerRouterService.getTriggerById(trigger.getTriggerId(), false);
} else if (object instanceof TriggerRouter) {
TriggerRouter tr = (TriggerRouter) object;
tr = triggerRouterService.findTriggerRouterById(tr.getTriggerId(), tr.getRouterId(), false);
if (tr != null) {
trigger = tr.getTrigger();
}
}
if (trigger != null) {
triggers.add(trigger);
} else {
return null;
}
}
return new ArrayList<Trigger>(triggers);
}
return null;
}
private void recordJobManagerRestartNeeded(DataContext context, Table table, CsvData data) {
if (isJobManagerRestartNeeded(table, data)) {
context.put(CTX_KEY_RESTART_JOBMANAGER_NEEDED, true);
}
}
private void recordConflictFlushNeeded(DataContext context, Table table) {
if (isConflictFlushNeeded(table)) {
context.put(CTX_KEY_FLUSH_CONFLICTS_NEEDED, true);
}
}
private void recordParametersFlushNeeded(DataContext context, Table table) {
if (isParameterFlushNeeded(table)) {
context.put(CTX_KEY_FLUSH_PARAMETERS_NEEDED, true);
}
}
private void recordChannelFlushNeeded(DataContext context, Table table) {
if (isChannelFlushNeeded(table)) {
context.put(CTX_KEY_FLUSH_CHANNELS_NEEDED, true);
}
}
private void recordTransformFlushNeeded(DataContext context, Table table) {
if (isTransformFlushNeeded(table)) {
context.put(CTX_KEY_FLUSH_TRANSFORMS_NEEDED, true);
}
}
private void recordExtensionFlushNeeded(DataContext context, Table table) {
if (isExtensionFlushNeeded(table)) {
context.put(CTX_KEY_FLUSH_EXTENSIONS_NEEDED, true);
}
}
private void recordNodeSecurityFlushNeeded(DataContext context, Table table) {
if (matchesTable(table, TableConstants.SYM_NODE_SECURITY)) {
context.put(CTX_KEY_FLUSH_NODE_SECURITY_NEEDED, true);
}
}
private void recordNodeFlushNeeded(DataContext context, Table table, CsvData data) {
if (matchesTable(table, TableConstants.SYM_NODE) &&
context.getBatch().getBatchId() != Constants.VIRTUAL_BATCH_FOR_REGISTRATION) {
Map<String, String> newData = data.toColumnNameValuePairs(table.getColumnNames(), CsvData.ROW_DATA);
String nodeId = newData.get("NODE_ID");
Node node = engine.getNodeService().findNodeInCacheOnly(nodeId);
if (node == null || data.getDataEventType() == DataEventType.INSERT || !node.isSyncEnabled()) {
context.put(CTX_KEY_FLUSH_NODE_NEEDED, true);
}
}
}
private void recordFileSyncEnabled(DataContext context, Table table, CsvData data) {
if (isFileSyncEnabled(table, data)) {
context.put(CTX_KEY_FILE_SYNC_ENABLED, true);
}
}
private boolean isGroupletFlushNeeded(Table table) {
return matchesTable(table, TableConstants.SYM_GROUPLET_LINK) ||
matchesTable(table, TableConstants.SYM_TRIGGER_ROUTER_GROUPLET) ||
matchesTable(table, TableConstants.SYM_GROUPLET);
}
private boolean isLoadFilterFlushNeeded(Table table) {
return matchesTable(table, TableConstants.SYM_LOAD_FILTER);
}
private boolean isChannelFlushNeeded(Table table) {
return matchesTable(table, TableConstants.SYM_CHANNEL);
}
private boolean isConflictFlushNeeded(Table table) {
return matchesTable(table, TableConstants.SYM_CONFLICT);
}
private boolean isParameterFlushNeeded(Table table) {
return matchesTable(table, TableConstants.SYM_PARAMETER);
}
private boolean isJobManagerRestartNeeded(Table table, CsvData data) {
return matchesTable(table, TableConstants.SYM_PARAMETER)
&& data.getCsvData(CsvData.ROW_DATA) != null
&& data.getCsvData(CsvData.ROW_DATA).contains("job.");
}
private boolean isFileSyncEnabled(Table table, CsvData data) {
return matchesTable(table, TableConstants.SYM_PARAMETER)
&& data.getCsvData(CsvData.ROW_DATA) != null
&& data.getCsvData(CsvData.ROW_DATA).contains(ParameterConstants.FILE_SYNC_ENABLE)
&& data.getCsvData(CsvData.ROW_DATA).contains("true");
}
private boolean isTransformFlushNeeded(Table table) {
return matchesTable(table, TableConstants.SYM_TRANSFORM_COLUMN)
|| matchesTable(table, TableConstants.SYM_TRANSFORM_TABLE) || matchesTable(table, TableConstants.SYM_NODE_GROUP_LINK);
}
private boolean isExtensionFlushNeeded(Table table) {
return matchesTable(table, TableConstants.SYM_EXTENSION);
}
private boolean matchesTable(Table table, String tableSuffix) {
if (table != null && table.getName() != null) {
return table.getName().equalsIgnoreCase(
TableConstants.getTableName(engine.getParameterService().getTablePrefix(),
tableSuffix));
} else {
return false;
}
}
public void syncStarted(DataContext context) {
putNodeIdentityIntoContext(context);
putNodeSecurityIntoContext(context);
}
public void syncEnded(DataContext context, List<IncomingBatch> batchesProcessed, Throwable ex) {
IParameterService parameterService = engine.getParameterService();
INodeService nodeService = engine.getNodeService();
if (context.get(CTX_KEY_FLUSH_TRANSFORMS_NEEDED) != null) {
log.info("About to refresh the cache of transformation because new configuration came through the data loader");
engine.getTransformService().clearCache();
log.info("About to clear the staging area because new transform configuration came through the data loader");
engine.getStagingManager().clean(0);
context.remove(CTX_KEY_FLUSH_TRANSFORMS_NEEDED);
}
if (context.get(CTX_KEY_RESTART_JOBMANAGER_NEEDED) != null
|| context.get(CTX_KEY_FILE_SYNC_ENABLED) != null) {
IJobManager jobManager = engine.getJobManager();
if (jobManager != null && jobManager.isStarted()) {
log.info("About to restart jobs because new configuration came through the data loader");
jobManager.restartJobs();
}
context.remove(CTX_KEY_RESTART_JOBMANAGER_NEEDED);
}
/**
* No need to sync triggers until the entire sync process has finished just in case there
* are multiple batches that contain configuration changes
*/
Object needsSynced = context.get(CTX_KEY_RESYNC_NEEDED);
if (needsSynced != null && parameterService.is(ParameterConstants.AUTO_SYNC_TRIGGERS)) {
log.info("About to syncTriggers because new configuration came through the data loader");
List<Trigger> triggers = convertNeedsSynced(needsSynced);
if (triggers != null && triggers.size() > 0) {
engine.getTriggerRouterService().syncTriggers(triggers, null, false, true);
} else {
engine.getClusterService().refreshLockEntries(); // Needed in case cluster.lock.enabled changed during config change.
engine.getTriggerRouterService().syncTriggers();
engine.getRegistrationService().setAllowClientRegistration(true);
}
context.remove(CTX_KEY_RESYNC_NEEDED);
}
if (context.get(CTX_KEY_RESYNC_TABLE_NEEDED) != null
&& parameterService.is(ParameterConstants.AUTO_SYNC_TRIGGERS)
&& (parameterService.is(ParameterConstants.TRIGGER_CREATE_BEFORE_INITIAL_LOAD)
|| nodeService.findNodeSecurity(nodeService.findIdentityNodeId(), true).hasInitialLoaded())) {
@SuppressWarnings("unchecked")
Set<Table> tables = (Set<Table>)context.get(CTX_KEY_RESYNC_TABLE_NEEDED);
for (Table table : tables) {
if (engine.getSymmetricDialect().getPlatform().equals(engine.getTargetDialect().getPlatform())) {
engine.getTriggerRouterService().syncTriggers(table, false);
}
}
context.remove(CTX_KEY_RESYNC_TABLE_NEEDED);
}
if (context.get(CTX_KEY_FILE_SYNC_ENABLED) != null
&& parameterService.is(ParameterConstants.AUTO_SYNC_TRIGGERS)) {
log.info("About to syncTriggers for file snapshot because the file sync parameter has changed");
engine.clearCaches();
engine.getFileSyncService().clearCache();
Table fileSnapshotTable = engine.getDatabasePlatform()
.getTableFromCache(TableConstants.getTableName(engine.getTablePrefix(), TableConstants.SYM_FILE_SNAPSHOT), false);
engine.getTriggerRouterService().syncTriggers(fileSnapshotTable, false);
context.remove(CTX_KEY_FILE_SYNC_ENABLED);
}
if (context.get(CTX_KEY_INITIAL_LOAD_COMPLETED) != null) {
log.info("Initial load ended for me");
if (hasClientReloadListener(context)) {
List<IClientReloadListener> listeners = engine.getExtensionService().getExtensionPointList(IClientReloadListener.class);
for (IClientReloadListener listener : listeners) {
listener.reloadCompleted();
}
}
context.remove(CTX_KEY_INITIAL_LOAD_COMPLETED);
}
}
@Override
public void batchCommitted(DataContext context) {
IParameterService parameterService = engine.getParameterService();
INodeService nodeService = engine.getNodeService();
if (context.getBatch().getBatchId() == Constants.VIRTUAL_BATCH_FOR_REGISTRATION) {
String nodeId = nodeService.findIdentityNodeId();
Node sourceNode = nodeService.findNode(context.getBatch().getSourceNodeId());
if (nodeId != null && sourceNode != null && Version.isOlderThanVersion(sourceNode.getSymmetricVersion(), "3.12.0")) {
NodeSecurity security = nodeService.findNodeSecurity(nodeId);
if (security != null && (security.isRegistrationEnabled() || security.getRegistrationTime() == null)) {
engine.getRegistrationService().markNodeAsRegistered(nodeId);
}
}
}
if (context.get(CTX_KEY_FLUSH_GROUPLETS_NEEDED) != null) {
log.info("Grouplets flushed because new grouplet config came through the data loader");
engine.getGroupletService().clearCache();
context.remove(CTX_KEY_FLUSH_GROUPLETS_NEEDED);
}
if (context.get(CTX_KEY_FLUSH_LOADFILTERS_NEEDED) != null) {
log.info("Load filters flushed because new filter config came through the data loader");
engine.getLoadFilterService().clearCache();
context.remove(CTX_KEY_FLUSH_LOADFILTERS_NEEDED);
}
if (context.get(CTX_KEY_FLUSH_CHANNELS_NEEDED) != null) {
log.info("Channels flushed because new channels came through the data loader");
engine.getConfigurationService().clearCache();
context.remove(CTX_KEY_FLUSH_CHANNELS_NEEDED);
}
if (context.get(CTX_KEY_FLUSH_CONFLICTS_NEEDED) != null) {
log.info("About to refresh the cache of conflict settings because new configuration came through the data loader");
engine.getDataLoaderService().clearCache();
context.remove(CTX_KEY_FLUSH_CONFLICTS_NEEDED);
}
if (context.get(CTX_KEY_FLUSH_PARAMETERS_NEEDED) != null) {
log.info("About to refresh the cache of parameters because new configuration came through the data loader");
parameterService.rereadParameters();
context.remove(CTX_KEY_FLUSH_PARAMETERS_NEEDED);
}
if (context.get(CTX_KEY_FLUSH_EXTENSIONS_NEEDED) != null) {
log.info("Extensions flushed because new extensions came through the data loader");
engine.getExtensionService().refresh();
context.remove(CTX_KEY_FLUSH_EXTENSIONS_NEEDED);
}
if (context.get(CTX_KEY_FLUSH_NODE_SECURITY_NEEDED) != null) {
log.info("About to refresh the cache of node security because new configuration came through the data loader");
nodeService.flushNodeAuthorizedCache();
context.remove(CTX_KEY_FLUSH_NODE_SECURITY_NEEDED);
putNodeSecurityIntoContext(context);
}
if (context.get(CTX_KEY_FLUSH_NODE_NEEDED) != null) {
log.info("About to refresh the cache of nodes because new configuration came through the data loader");
nodeService.flushNodeCache();
nodeService.flushNodeGroupCache();
context.remove(CTX_KEY_FLUSH_NODE_NEEDED);
}
}
protected void putNodeIdentityIntoContext(DataContext context) {
context.put(CTX_KEY_MY_NODE_ID, engine.getNodeService().findIdentityNodeId());
}
protected void putNodeSecurityIntoContext(DataContext context) {
String myNodeId = engine.getNodeService().findIdentityNodeId();
if (myNodeId != null) {
context.put(CTX_KEY_MY_NODE_SECURITY, engine.getNodeService().findNodeSecurity(myNodeId, true));
}
}
}