/
AbstractSymmetricEngine.java
858 lines (705 loc) · 32.7 KB
/
AbstractSymmetricEngine.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
package org.jumpmind.symmetric;
import java.io.File;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import org.apache.commons.lang.StringUtils;
import org.jumpmind.db.io.DatabaseIO;
import org.jumpmind.db.model.Database;
import org.jumpmind.db.model.Table;
import org.jumpmind.db.platform.IDatabasePlatform;
import org.jumpmind.db.sql.ISqlTemplate;
import org.jumpmind.db.sql.SqlScript;
import org.jumpmind.db.sql.SqlScriptReader;
import org.jumpmind.properties.TypedProperties;
import org.jumpmind.symmetric.common.Constants;
import org.jumpmind.symmetric.common.ParameterConstants;
import org.jumpmind.symmetric.common.TableConstants;
import org.jumpmind.symmetric.db.ISymmetricDialect;
import org.jumpmind.symmetric.ext.IExtensionPointManager;
import org.jumpmind.symmetric.io.DefaultOfflineClientListener;
import org.jumpmind.symmetric.io.IOfflineClientListener;
import org.jumpmind.symmetric.io.stage.IStagingManager;
import org.jumpmind.symmetric.job.DefaultOfflineServerListener;
import org.jumpmind.symmetric.job.IJobManager;
import org.jumpmind.symmetric.model.Node;
import org.jumpmind.symmetric.model.NodeSecurity;
import org.jumpmind.symmetric.model.NodeStatus;
import org.jumpmind.symmetric.model.RemoteNodeStatuses;
import org.jumpmind.symmetric.service.IAcknowledgeService;
import org.jumpmind.symmetric.service.IBandwidthService;
import org.jumpmind.symmetric.service.IClusterService;
import org.jumpmind.symmetric.service.IConfigurationService;
import org.jumpmind.symmetric.service.IDataExtractorService;
import org.jumpmind.symmetric.service.IDataLoaderService;
import org.jumpmind.symmetric.service.IDataService;
import org.jumpmind.symmetric.service.IIncomingBatchService;
import org.jumpmind.symmetric.service.ILoadFilterService;
import org.jumpmind.symmetric.service.INodeCommunicationService;
import org.jumpmind.symmetric.service.INodeService;
import org.jumpmind.symmetric.service.IOutgoingBatchService;
import org.jumpmind.symmetric.service.IParameterService;
import org.jumpmind.symmetric.service.IPullService;
import org.jumpmind.symmetric.service.IPurgeService;
import org.jumpmind.symmetric.service.IPushService;
import org.jumpmind.symmetric.service.IRegistrationService;
import org.jumpmind.symmetric.service.IRouterService;
import org.jumpmind.symmetric.service.ISecurityService;
import org.jumpmind.symmetric.service.ISequenceService;
import org.jumpmind.symmetric.service.IStatisticService;
import org.jumpmind.symmetric.service.ITransformService;
import org.jumpmind.symmetric.service.ITriggerRouterService;
import org.jumpmind.symmetric.service.impl.AcknowledgeService;
import org.jumpmind.symmetric.service.impl.BandwidthService;
import org.jumpmind.symmetric.service.impl.ClusterService;
import org.jumpmind.symmetric.service.impl.ConfigurationService;
import org.jumpmind.symmetric.service.impl.DataExtractorService;
import org.jumpmind.symmetric.service.impl.DataLoaderService;
import org.jumpmind.symmetric.service.impl.DataService;
import org.jumpmind.symmetric.service.impl.IncomingBatchService;
import org.jumpmind.symmetric.service.impl.LoadFilterService;
import org.jumpmind.symmetric.service.impl.NodeCommunicationService;
import org.jumpmind.symmetric.service.impl.NodeService;
import org.jumpmind.symmetric.service.impl.OutgoingBatchService;
import org.jumpmind.symmetric.service.impl.ParameterService;
import org.jumpmind.symmetric.service.impl.PullService;
import org.jumpmind.symmetric.service.impl.PurgeService;
import org.jumpmind.symmetric.service.impl.PushService;
import org.jumpmind.symmetric.service.impl.RegistrationService;
import org.jumpmind.symmetric.service.impl.RouterService;
import org.jumpmind.symmetric.service.impl.SecurityService;
import org.jumpmind.symmetric.service.impl.SequenceService;
import org.jumpmind.symmetric.service.impl.StatisticService;
import org.jumpmind.symmetric.service.impl.TransformService;
import org.jumpmind.symmetric.service.impl.TriggerRouterService;
import org.jumpmind.symmetric.statistic.IStatisticManager;
import org.jumpmind.symmetric.statistic.StatisticManager;
import org.jumpmind.symmetric.transport.ConcurrentConnectionManager;
import org.jumpmind.symmetric.transport.IConcurrentConnectionManager;
import org.jumpmind.symmetric.transport.ITransportManager;
import org.jumpmind.symmetric.transport.TransportManagerFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
abstract public class AbstractSymmetricEngine implements ISymmetricEngine {
private static Map<String, ISymmetricEngine> registeredEnginesByUrl = new HashMap<String, ISymmetricEngine>();
private static Map<String, ISymmetricEngine> registeredEnginesByName = new HashMap<String, ISymmetricEngine>();
protected static final Logger log = LoggerFactory.getLogger(AbstractSymmetricEngine.class);
private boolean started = false;
private boolean starting = false;
private boolean setup = false;
protected String deploymentType;
protected ITypedPropertiesFactory propertiesFactory;
protected IDatabasePlatform platform;
protected ISecurityService securityService;
protected IParameterService parameterService;
protected ISymmetricDialect symmetricDialect;
protected INodeService nodeService;
protected IConfigurationService configurationService;
protected IBandwidthService bandwidthService;
protected IStatisticService statisticService;
protected IStatisticManager statisticManager;
protected IConcurrentConnectionManager concurrentConnectionManager;
protected ITransportManager transportManager;
protected IClusterService clusterService;
protected IPurgeService purgeService;
protected ITransformService transformService;
protected ILoadFilterService loadFilterService;
protected ITriggerRouterService triggerRouterService;
protected IOutgoingBatchService outgoingBatchService;
protected IDataService dataService;
protected IRouterService routerService;
protected IDataExtractorService dataExtractorService;
protected IRegistrationService registrationService;
protected IDataLoaderService dataLoaderService;
protected IIncomingBatchService incomingBatchService;
protected IAcknowledgeService acknowledgeService;
protected IPushService pushService;
protected IPullService pullService;
protected IJobManager jobManager;
protected ISequenceService sequenceService;
protected IExtensionPointManager extensionPointManger;
protected IStagingManager stagingManager;
protected INodeCommunicationService nodeCommunicationService;
protected Date lastRestartTime = null;
abstract protected ITypedPropertiesFactory createTypedPropertiesFactory();
abstract protected IDatabasePlatform createDatabasePlatform(TypedProperties properties);
protected boolean registerEngine = true;
protected AbstractSymmetricEngine(boolean registerEngine) {
this.registerEngine = registerEngine;
}
/**
* Locate a {@link StandaloneSymmetricEngine} in the same JVM
*/
public static ISymmetricEngine findEngineByUrl(String url) {
if (registeredEnginesByUrl != null && url != null) {
return registeredEnginesByUrl.get(url);
} else {
return null;
}
}
/**
* Locate a {@link StandaloneSymmetricEngine} in the same JVM
*/
public static ISymmetricEngine findEngineByName(String name) {
if (registeredEnginesByName != null && name != null) {
return registeredEnginesByName.get(name);
} else {
return null;
}
}
public void setDeploymentType(String deploymentType) {
this.deploymentType = deploymentType;
}
protected void init() {
this.propertiesFactory = createTypedPropertiesFactory();
this.securityService = createSecurityService(propertiesFactory.reload());
TypedProperties properties = this.propertiesFactory.reload();
this.platform = createDatabasePlatform(properties);
this.parameterService = new ParameterService(platform, propertiesFactory, properties.get(
ParameterConstants.RUNTIME_CONFIG_TABLE_PREFIX, "sym"));
MDC.put("engineName", this.parameterService.getEngineName());
this.platform.setMetadataIgnoreCase(this.parameterService
.is(ParameterConstants.DB_METADATA_IGNORE_CASE));
this.platform.setClearCacheModelTimeoutInMs(parameterService
.getLong(ParameterConstants.CACHE_TIMEOUT_TABLES_IN_MS));
this.bandwidthService = new BandwidthService(parameterService);
this.symmetricDialect = createSymmetricDialect();
this.sequenceService = new SequenceService(parameterService, symmetricDialect);
this.stagingManager = createStagingManager();
this.nodeService = new NodeService(parameterService, symmetricDialect);
this.configurationService = new ConfigurationService(parameterService, symmetricDialect,
nodeService);
this.statisticService = new StatisticService(parameterService, symmetricDialect);
this.statisticManager = new StatisticManager(parameterService, nodeService,
configurationService, statisticService);
this.concurrentConnectionManager = new ConcurrentConnectionManager(parameterService,
statisticManager);
this.clusterService = new ClusterService(parameterService, symmetricDialect);
this.purgeService = new PurgeService(parameterService, symmetricDialect, clusterService,
statisticManager);
this.transformService = new TransformService(parameterService, symmetricDialect,
configurationService);
this.loadFilterService = new LoadFilterService(parameterService, symmetricDialect,
configurationService);
this.triggerRouterService = new TriggerRouterService(parameterService, symmetricDialect,
clusterService, configurationService, statisticManager);
this.outgoingBatchService = new OutgoingBatchService(parameterService, symmetricDialect,
nodeService, configurationService, sequenceService);
this.dataService = new DataService(this);
this.routerService = buildRouterService();
this.dataExtractorService = new DataExtractorService(parameterService, symmetricDialect,
outgoingBatchService, routerService, configurationService, triggerRouterService,
nodeService, dataService, transformService, statisticManager, stagingManager);
this.incomingBatchService = new IncomingBatchService(parameterService, symmetricDialect);
this.transportManager = new TransportManagerFactory(this).create();
this.dataLoaderService = new DataLoaderService(this);
this.registrationService = new RegistrationService(parameterService, symmetricDialect,
nodeService, dataExtractorService, dataService, dataLoaderService,
transportManager, statisticManager);
this.acknowledgeService = new AcknowledgeService(parameterService, symmetricDialect,
outgoingBatchService, registrationService, stagingManager);
this.nodeCommunicationService = buildNodeCommunicationService();
this.pushService = new PushService(parameterService, symmetricDialect,
dataExtractorService, acknowledgeService, transportManager, nodeService,
clusterService, nodeCommunicationService);
this.pullService = new PullService(parameterService, symmetricDialect, nodeService,
dataLoaderService, registrationService, clusterService, nodeCommunicationService);
this.jobManager = createJobManager();
this.nodeService.addOfflineServerListener(new DefaultOfflineServerListener(
statisticManager, nodeService, outgoingBatchService));
IOfflineClientListener defaultlistener = new DefaultOfflineClientListener(parameterService,
nodeService);
this.pullService.addOfflineListener(defaultlistener);
this.pushService.addOfflineListener(defaultlistener);
if (registerEngine) {
registerHandleToEngine();
}
}
protected IRouterService buildRouterService() {
return new RouterService(this);
}
protected INodeCommunicationService buildNodeCommunicationService() {
return new NodeCommunicationService(nodeService, parameterService, symmetricDialect);
}
public static ISecurityService createSecurityService(TypedProperties properties) {
try {
String className = properties.get(ParameterConstants.CLASS_NAME_SECURITY_SERVICE,
SecurityService.class.getName());
ISecurityService securityService = (ISecurityService) Class.forName(className).newInstance();
securityService.init();
return securityService;
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
abstract protected IStagingManager createStagingManager();
abstract protected ISymmetricDialect createSymmetricDialect();
abstract protected IJobManager createJobManager();
public String getSyncUrl() {
return parameterService.getSyncUrl();
}
public Properties getProperties() {
Properties p = new Properties();
p.putAll(parameterService.getAllParameters());
return p;
}
public String getEngineName() {
return parameterService.getString(ParameterConstants.ENGINE_NAME);
}
public void setup() {
getParameterService().rereadParameters();
if (!setup) {
setupDatabase(false);
setup = true;
}
}
public void setupDatabase(boolean force) {
log.info("Initializing SymmetricDS database");
if (parameterService.is(ParameterConstants.AUTO_CONFIGURE_DATABASE) || force) {
symmetricDialect.initTablesAndFunctions();
} else {
log.info("SymmetricDS is not configured to auto-create the database");
}
configurationService.initDefaultChannels();
clusterService.init();
sequenceService.init();
autoConfigRegistrationServer();
parameterService.rereadParameters();
log.info("Done initializing SymmetricDS database");
}
protected void autoConfigRegistrationServer() {
Node node = nodeService.findIdentity();
if (node == null) {
buildTablesFromDdlUtilXmlIfProvided();
loadFromScriptIfProvided();
}
node = nodeService.findIdentity();
if (node == null && StringUtils.isBlank(parameterService.getRegistrationUrl())
&& parameterService.is(ParameterConstants.AUTO_INSERT_REG_SVR_IF_NOT_FOUND, false)) {
log.info("Inserting rows for node, security, identity and group for registration server");
String nodeId = parameterService.getExternalId();
node = new Node(parameterService, symmetricDialect);
node.setNodeId(node.getExternalId());
nodeService.save(node);
nodeService.insertNodeIdentity(nodeId);
node = nodeService.findIdentity();
nodeService.insertNodeGroup(node.getNodeGroupId(), null);
NodeSecurity nodeSecurity = nodeService.findNodeSecurity(nodeId, true);
nodeSecurity.setInitialLoadTime(new Date());
nodeSecurity.setRegistrationTime(new Date());
nodeSecurity.setInitialLoadEnabled(false);
nodeSecurity.setRegistrationEnabled(false);
nodeService.updateNodeSecurity(nodeSecurity);
}
}
protected boolean buildTablesFromDdlUtilXmlIfProvided() {
boolean loaded = false;
String xml = parameterService
.getString(ParameterConstants.AUTO_CONFIGURE_REG_SVR_DDLUTIL_XML);
if (!StringUtils.isBlank(xml)) {
File file = new File(xml);
URL fileUrl = null;
if (file.isFile()) {
try {
fileUrl = file.toURI().toURL();
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
} else {
fileUrl = getClass().getResource(xml);
}
if (fileUrl != null) {
try {
log.info("Building database schema from: {}", xml);
Database database = new DatabaseIO().read(new InputStreamReader(fileUrl
.openStream()));
IDatabasePlatform platform = symmetricDialect.getPlatform();
platform.createDatabase(database, true, true);
loaded = true;
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
}
return loaded;
}
/**
* Give the end user the option to provide a script that will load a
* registration server with an initial SymmetricDS setup.
*
* Look first on the file system, then in the classpath for the SQL file.
*
* @return true if the script was executed
*/
protected boolean loadFromScriptIfProvided() {
boolean loaded = false;
String sqlScripts = parameterService
.getString(ParameterConstants.AUTO_CONFIGURE_REG_SVR_SQL_SCRIPT);
if (!StringUtils.isBlank(sqlScripts)) {
String[] sqlScriptList = sqlScripts.split(",");
for (String sqlScript : sqlScriptList) {
sqlScript = sqlScript.trim();
if (StringUtils.isNotBlank(sqlScript)) {
File file = new File(sqlScript);
URL fileUrl = null;
if (file.isFile()) {
try {
fileUrl = file.toURI().toURL();
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
} else {
fileUrl = getClass().getResource(sqlScript);
if (fileUrl == null) {
fileUrl = Thread.currentThread().getContextClassLoader()
.getResource(sqlScript);
}
}
if (fileUrl != null) {
new SqlScript(fileUrl, symmetricDialect.getPlatform().getSqlTemplate(),
true, SqlScriptReader.QUERY_ENDS, getSymmetricDialect().getPlatform()
.getSqlScriptReplacementTokens()).execute();
loaded = true;
} else {
log.info("Could not find the sql script: {} to execute. We would have run it if we had found it");
}
}
}
}
return loaded;
}
public synchronized boolean start() {
return start(true);
}
public synchronized boolean start(boolean startJobs) {
setup();
if (isConfigured()) {
if (!starting && !started) {
try {
starting = true;
Node node = nodeService.findIdentity();
if (node != null) {
log.info(
"Starting registered node [group={}, id={}, externalId={}]",
new Object[] { node.getNodeGroupId(), node.getNodeId(),
node.getExternalId() });
} else {
log.info("Starting unregistered node [group={}, externalId={}]",
parameterService.getNodeGroupId(), parameterService.getExternalId());
}
triggerRouterService.syncTriggers();
heartbeat(false);
if (startJobs && jobManager != null) {
jobManager.startJobs();
}
log.info("Started SymmetricDS");
lastRestartTime = new Date();
started = true;
} finally {
starting = false;
}
}
} else {
log.warn("Did not start SymmetricDS. It has not been configured properly");
}
log.info(
"SymmetricDS: type={}, name={}, version={}, groupId={}, externalId={}, databaseName={}, databaseVersion={}, driverName={}, driverVersion={}",
new Object[] { getDeploymentType(), getEngineName(), Version.version(),
getParameterService().getNodeGroupId(),
getParameterService().getExternalId(), symmetricDialect.getName(),
symmetricDialect.getVersion(), symmetricDialect.getDriverName(),
symmetricDialect.getDriverVersion() });
return started;
}
public synchronized void stop() {
log.info("Closing SymmetricDS externalId={} version={} database={}",
new Object[] { parameterService == null ? "?" : parameterService.getExternalId(), Version.version(),
symmetricDialect == null? "?":symmetricDialect.getName() });
if (jobManager != null) {
jobManager.stopJobs();
}
if (routerService != null) {
routerService.stop();
}
if (nodeCommunicationService != null) {
nodeCommunicationService.stop();
}
started = false;
starting = false;
}
public synchronized void destroy() {
stop();
if (jobManager != null) {
jobManager.destroy();
}
removeMeFromMap(registeredEnginesByName);
removeMeFromMap(registeredEnginesByUrl);
}
public String reloadNode(String nodeId) {
return dataService.reloadNode(nodeId);
}
public String sendSQL(String nodeId, String catalogName, String schemaName, String tableName,
String sql) {
return dataService.sendSQL(nodeId, catalogName, schemaName, tableName, sql, false);
}
public RemoteNodeStatuses push() {
MDC.put("engineName", getEngineName());
return pushService.pushData(true);
}
public void syncTriggers() {
MDC.put("engineName", getEngineName());
triggerRouterService.syncTriggers();
}
public void forceTriggerRebuild() {
MDC.put("engineName", getEngineName());
triggerRouterService.syncTriggers(true);
}
public NodeStatus getNodeStatus() {
return nodeService.getNodeStatus();
}
public RemoteNodeStatuses pull() {
MDC.put("engineName", getEngineName());
return pullService.pullData(true);
}
public void route() {
MDC.put("engineName", getEngineName());
routerService.routeData(true);
}
public void purge() {
MDC.put("engineName", getEngineName());
purgeService.purgeOutgoing(true);
purgeService.purgeIncoming(true);
purgeService.purgeDataGaps(true);
}
public boolean isConfigured() {
boolean configurationValid = false;
boolean isRegistrationServer = getNodeService().isRegistrationServer();
boolean isSelfConfigurable = isRegistrationServer
&& (getParameterService().is(ParameterConstants.AUTO_INSERT_REG_SVR_IF_NOT_FOUND,
false) || StringUtils.isNotBlank(getParameterService().getString(
ParameterConstants.AUTO_CONFIGURE_REG_SVR_SQL_SCRIPT)));
Table symNodeTable = symmetricDialect.getPlatform().getTableFromCache(
TableConstants.getTableName(parameterService.getTablePrefix(),
TableConstants.SYM_NODE), true);
Node node = symNodeTable != null ? getNodeService().findIdentity() : null;
long offlineNodeDetectionPeriodSeconds = getParameterService().getLong(
ParameterConstants.OFFLINE_NODE_DETECTION_PERIOD_MINUTES) * 60;
long heartbeatSeconds = getParameterService().getLong(
ParameterConstants.HEARTBEAT_SYNC_ON_PUSH_PERIOD_SEC);
String registrationUrl = getParameterService().getRegistrationUrl();
if (!isSelfConfigurable && node == null && isRegistrationServer) {
log.warn(
"This node is configured as a registration server, but it is missing its node_identity. It probably needs configured.",
ParameterConstants.REGISTRATION_URL);
} else if (!isSelfConfigurable && node == null
&& StringUtils.isBlank(getParameterService().getRegistrationUrl())) {
log.warn(
"Please set the property {} so this node may pull registration or manually insert configuration into the configuration tables",
ParameterConstants.REGISTRATION_URL);
} else if (Constants.PLEASE_SET_ME.equals(getParameterService().getExternalId())
|| Constants.PLEASE_SET_ME.equals(registrationUrl)
|| Constants.PLEASE_SET_ME.equals(getParameterService().getNodeGroupId())) {
log.warn("Please set the registration.url, node.group.id, and external.id for the node");
} else if (node != null
&& (!node.getExternalId().equals(getParameterService().getExternalId()) || !node
.getNodeGroupId().equals(getParameterService().getNodeGroupId()))) {
log.warn(
"The configured state does not match recorded database state. The recorded external id is {} while the configured external id is {}. The recorded node group id is {} while the configured node group id is {}",
new Object[] { node.getExternalId(), getParameterService().getExternalId(),
node.getNodeGroupId(), getParameterService().getNodeGroupId() });
} else if (node != null && StringUtils.isBlank(getParameterService().getRegistrationUrl())
&& StringUtils.isBlank(getParameterService().getSyncUrl())) {
log.warn("The sync.url property must be set for the registration server. Otherwise, registering nodes will not be able to sync with it");
} else if (offlineNodeDetectionPeriodSeconds > 0
&& offlineNodeDetectionPeriodSeconds <= heartbeatSeconds) {
// Offline node detection is not disabled (-1) and the value is too
// small (less than the heartbeat)
log.warn(
"The {} property must be a longer period of time than the {} property. Otherwise, nodes will be taken offline before the heartbeat job has a chance to run",
ParameterConstants.OFFLINE_NODE_DETECTION_PERIOD_MINUTES,
ParameterConstants.HEARTBEAT_SYNC_ON_PUSH_PERIOD_SEC);
} else {
configurationValid = true;
}
// TODO Add more validation checks to make sure that the system is
// configured correctly
// TODO Add method to configuration service to validate triggers and
// call from here.
// Make sure there are not duplicate trigger rows with the same name
return configurationValid;
}
public void heartbeat(boolean force) {
MDC.put("engineName", getEngineName());
dataService.heartbeat(true);
}
public void openRegistration(String nodeGroupId, String externalId) {
MDC.put("engineName", getEngineName());
registrationService.openRegistration(nodeGroupId, externalId);
}
public void reOpenRegistration(String nodeId) {
MDC.put("engineName", getEngineName());
registrationService.reOpenRegistration(nodeId);
}
public boolean isRegistered() {
return nodeService.findIdentity() != null;
}
public boolean isStarted() {
return started;
}
public boolean isStarting() {
return starting;
}
public IConfigurationService getConfigurationService() {
return configurationService;
}
public IParameterService getParameterService() {
return parameterService;
}
public INodeService getNodeService() {
return nodeService;
}
public IRegistrationService getRegistrationService() {
return registrationService;
}
public IClusterService getClusterService() {
return clusterService;
}
public IPurgeService getPurgeService() {
return purgeService;
}
public IDataService getDataService() {
return dataService;
}
public ISymmetricDialect getSymmetricDialect() {
return symmetricDialect;
}
public IJobManager getJobManager() {
return this.jobManager;
}
public IOutgoingBatchService getOutgoingBatchService() {
return outgoingBatchService;
}
public IAcknowledgeService getAcknowledgeService() {
return this.acknowledgeService;
}
public IBandwidthService getBandwidthService() {
return bandwidthService;
}
public IDataExtractorService getDataExtractorService() {
return this.dataExtractorService;
}
public IDataLoaderService getDataLoaderService() {
return this.dataLoaderService;
}
public IIncomingBatchService getIncomingBatchService() {
return this.incomingBatchService;
}
public IPullService getPullService() {
return this.pullService;
}
public IPushService getPushService() {
return this.pushService;
}
public IRouterService getRouterService() {
return this.routerService;
}
public ISecurityService getSecurityService() {
return securityService;
}
public IStatisticService getStatisticService() {
return statisticService;
}
public IStatisticManager getStatisticManager() {
return statisticManager;
}
public ITriggerRouterService getTriggerRouterService() {
return triggerRouterService;
}
public String getDeploymentType() {
return deploymentType;
}
public ITransformService getTransformService() {
return this.transformService;
}
public ILoadFilterService getLoadFilterService() {
return this.loadFilterService;
}
public IConcurrentConnectionManager getConcurrentConnectionManager() {
return concurrentConnectionManager;
}
public String getTablePrefix() {
return parameterService.getTablePrefix();
}
public ITransportManager getTransportManager() {
return transportManager;
}
public IExtensionPointManager getExtensionPointManager() {
return extensionPointManger;
}
public IStagingManager getStagingManager() {
return stagingManager;
}
public ISequenceService getSequenceService() {
return sequenceService;
}
public INodeCommunicationService getNodeCommunicationService() {
return nodeCommunicationService;
}
private void removeMeFromMap(Map<String, ISymmetricEngine> map) {
Set<String> keys = new HashSet<String>(map.keySet());
for (String key : keys) {
if (map.get(key).equals(this)) {
map.remove(key);
}
}
}
/**
* Register this instance of the engine so it can be found by other
* processes in the JVM.
*
* @see #findEngineByUrl(String)
*/
private void registerHandleToEngine() {
String url = getSyncUrl();
ISymmetricEngine alreadyRegister = registeredEnginesByUrl.get(url);
if (alreadyRegister == null || alreadyRegister.equals(this)) {
if (url != null) {
registeredEnginesByUrl.put(url, this);
}
} else {
throw new EngineAlreadyRegisteredException(
"Could not register engine. There was already an engine registered under the url: "
+ getSyncUrl());
}
alreadyRegister = registeredEnginesByName.get(getEngineName());
if (alreadyRegister == null || alreadyRegister.equals(this)) {
registeredEnginesByName.put(getEngineName(), this);
} else {
throw new EngineAlreadyRegisteredException(
"Could not register engine. There was already an engine registered under the name: "
+ getEngineName());
}
}
public Date getLastRestartTime() {
return lastRestartTime;
}
public ISqlTemplate getSqlTemplate() {
return getSymmetricDialect().getPlatform().getSqlTemplate();
}
public Logger getLog() {
return log;
}
@SuppressWarnings("unchecked")
public <T> T getDataSource() {
return (T) getSymmetricDialect().getPlatform().getDataSource();
}
}