use of org.jumpmind.symmetric.model.Node in project symmetric-ds by JumpMind.
the class AbstractSymmetricEngine method autoConfigRegistrationServer.
protected void autoConfigRegistrationServer() {
Node node = nodeService.findIdentity();
if (node == null) {
buildTablesFromDdlUtilXmlIfProvided();
loadFromScriptIfProvided();
parameterService.rereadParameters();
}
node = nodeService.findIdentity();
if (node == null && parameterService.isRegistrationServer() && 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.findOrCreateNodeSecurity(nodeId);
nodeSecurity.setInitialLoadTime(new Date());
nodeSecurity.setRegistrationTime(new Date());
nodeSecurity.setInitialLoadEnabled(false);
nodeSecurity.setRegistrationEnabled(false);
nodeService.updateNodeSecurity(nodeSecurity);
}
}
use of org.jumpmind.symmetric.model.Node in project symmetric-ds by JumpMind.
the class FileSyncZipDataWriter method write.
public void write(CsvData data) {
DataEventType eventType = data.getDataEventType();
if (eventType == DataEventType.INSERT || eventType == DataEventType.UPDATE) {
Map<String, String> columnData = data.toColumnNameValuePairs(snapshotTable.getColumnNames(), CsvData.ROW_DATA);
Map<String, String> oldColumnData = data.toColumnNameValuePairs(snapshotTable.getColumnNames(), CsvData.OLD_DATA);
FileSnapshot snapshot = new FileSnapshot();
snapshot.setTriggerId(columnData.get("TRIGGER_ID"));
snapshot.setRouterId(columnData.get("ROUTER_ID"));
snapshot.setFileModifiedTime(Long.parseLong(columnData.get("FILE_MODIFIED_TIME")));
snapshot.setCrc32Checksum(Long.parseLong(columnData.get("CRC32_CHECKSUM")));
String oldChecksum = oldColumnData.get("CRC32_CHECKSUM");
if (StringUtils.isNotBlank(oldChecksum)) {
snapshot.setOldCrc32Checksum(Long.parseLong(oldChecksum));
}
snapshot.setFileSize(Long.parseLong(columnData.get("FILE_SIZE")));
snapshot.setLastUpdateBy(columnData.get("LAST_UPDATE_BY"));
snapshot.setFileName(columnData.get("FILE_NAME"));
snapshot.setRelativeDir(columnData.get("RELATIVE_DIR"));
snapshot.setLastEventType(LastEventType.fromCode(columnData.get("LAST_EVENT_TYPE")));
snapshotEvents.add(snapshot);
} else if (eventType == DataEventType.RELOAD) {
String targetNodeId = context.getBatch().getTargetNodeId();
Node targetNode = nodeService.findNode(targetNodeId);
List<FileTriggerRouter> fileTriggerRouters = fileSyncService.getFileTriggerRoutersForCurrentNode();
for (FileTriggerRouter fileTriggerRouter : fileTriggerRouters) {
if (fileTriggerRouter.isEnabled() && fileTriggerRouter.isInitialLoadEnabled() && fileTriggerRouter.getRouter().getNodeGroupLink().getTargetNodeGroupId().equals(targetNode.getNodeGroupId())) {
DirectorySnapshot directorySnapshot = fileSyncService.getDirectorySnapshot(fileTriggerRouter);
snapshotEvents.addAll(directorySnapshot);
}
}
}
}
use of org.jumpmind.symmetric.model.Node in project symmetric-ds by JumpMind.
the class PushHeartbeatListener method heartbeat.
public void heartbeat(Node me) {
IParameterService parameterService = engine.getParameterService();
if (parameterService.is(ParameterConstants.HEARTBEAT_ENABLED)) {
ISymmetricDialect symmetricDialect = engine.getSymmetricDialect();
boolean updateWithBatchStatus = parameterService.is(ParameterConstants.HEARTBEAT_UPDATE_NODE_WITH_BATCH_STATUS, false);
int outgoingErrorCount = -1;
int outgoingUnsentCount = -1;
if (updateWithBatchStatus) {
outgoingUnsentCount = engine.getOutgoingBatchService().countOutgoingBatchesUnsent();
outgoingErrorCount = engine.getOutgoingBatchService().countOutgoingBatchesInError();
}
if (!parameterService.getExternalId().equals(me.getExternalId()) || !parameterService.getNodeGroupId().equals(me.getNodeGroupId()) || (parameterService.getSyncUrl() != null && !parameterService.getSyncUrl().equals(me.getSyncUrl())) || !parameterService.getString(ParameterConstants.SCHEMA_VERSION, "").equals(me.getSchemaVersion()) || (engine.getDeploymentType() != null && !engine.getDeploymentType().equals(me.getDeploymentType())) || !Version.version().equals(me.getSymmetricVersion()) || !symmetricDialect.getName().equals(me.getDatabaseType()) || !symmetricDialect.getVersion().equals(me.getDatabaseVersion()) || me.getBatchInErrorCount() != outgoingErrorCount || me.getBatchToSendCount() != outgoingUnsentCount) {
log.info("Some attribute(s) of node changed. Recording changes");
me.setDeploymentType(engine.getDeploymentType());
me.setSymmetricVersion(Version.version());
me.setDatabaseType(symmetricDialect.getName());
me.setDatabaseVersion(symmetricDialect.getVersion());
me.setBatchInErrorCount(outgoingErrorCount);
me.setBatchToSendCount(outgoingUnsentCount);
me.setSchemaVersion(parameterService.getString(ParameterConstants.SCHEMA_VERSION));
if (parameterService.is(ParameterConstants.AUTO_UPDATE_NODE_VALUES)) {
log.info("Updating my node configuration info according to the symmetric properties");
me.setExternalId(parameterService.getExternalId());
me.setNodeGroupId(parameterService.getNodeGroupId());
if (!StringUtils.isBlank(parameterService.getSyncUrl())) {
me.setSyncUrl(parameterService.getSyncUrl());
}
}
engine.getNodeService().save(me);
}
log.debug("Updating my node info");
engine.getOutgoingBatchService().markAllChannelAsSent(Constants.CHANNEL_HEARTBEAT, getTableName());
engine.getNodeService().updateNodeHostForCurrentNode();
log.debug("Done updating my node info");
if (!engine.getNodeService().isRegistrationServer()) {
if (!symmetricDialect.getPlatform().getDatabaseInfo().isTriggersSupported()) {
engine.getDataService().insertHeartbeatEvent(me, false);
Set<Node> children = engine.getNodeService().findNodesThatOriginatedFromNodeId(me.getNodeId());
for (Node node : children) {
engine.getDataService().insertHeartbeatEvent(node, false);
}
}
}
}
}
use of org.jumpmind.symmetric.model.Node in project symmetric-ds by JumpMind.
the class ConfigurationChangedDatabaseWriterFilter method recordNodeFlushNeeded.
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);
}
}
}
use of org.jumpmind.symmetric.model.Node in project symmetric-ds by JumpMind.
the class NotificationTypeLog method notify.
public void notify(Notification notification, List<MonitorEvent> monitorEvents) {
Map<String, Node> nodes = engine.getNodeService().findAllNodesAsMap();
for (MonitorEvent monitorEvent : monitorEvents) {
Node node = nodes.get(monitorEvent.getNodeId());
String nodeString = node != null ? node.toString() : monitorEvent.getNodeId();
String message = "Monitor " + monitorEvent.getType() + " on " + nodeString + " reached threshold of " + monitorEvent.getThreshold() + " with a value of " + monitorEvent.getValue();
if (monitorEvent.getSeverityLevel() >= Monitor.SEVERE) {
log.error(message);
} else if (monitorEvent.getSeverityLevel() >= Monitor.WARNING) {
log.warn(message);
} else {
log.info(message);
}
}
}
Aggregations