use of org.jumpmind.symmetric.service.IConfigurationService in project symmetric-ds by JumpMind.
the class ConfigurationChangedDataRouter method routeNodeTables.
protected void routeNodeTables(Set<String> nodeIds, Map<String, String> columnValues, NetworkedNode rootNetworkedNode, Node me, SimpleRouterContext routingContext, DataMetaData dataMetaData, Set<Node> possibleTargetNodes, boolean initialLoad) {
String nodeIdForRecordBeingRouted = columnValues.get("NODE_ID");
if (dataMetaData.getData().getDataEventType() == DataEventType.DELETE) {
String createAtNodeId = columnValues.get("CREATED_AT_NODE_ID");
for (Node nodeThatMayBeRoutedTo : possibleTargetNodes) {
if (!Constants.DEPLOYMENT_TYPE_REST.equals(nodeThatMayBeRoutedTo.getDeploymentType()) && !nodeIdForRecordBeingRouted.equals(nodeThatMayBeRoutedTo.getNodeId()) && !nodeThatMayBeRoutedTo.getNodeId().equals(createAtNodeId) && (nodeThatMayBeRoutedTo.getCreatedAtNodeId() == null || !nodeThatMayBeRoutedTo.getCreatedAtNodeId().equals(nodeIdForRecordBeingRouted))) {
nodeIds.add(nodeThatMayBeRoutedTo.getNodeId());
}
}
} else {
IConfigurationService configurationService = engine.getConfigurationService();
List<NodeGroupLink> nodeGroupLinks = getNodeGroupLinksFromContext(routingContext);
for (Node nodeThatMayBeRoutedTo : possibleTargetNodes) {
if (!Constants.DEPLOYMENT_TYPE_REST.equals(nodeThatMayBeRoutedTo.getDeploymentType()) && !nodeThatMayBeRoutedTo.requires13Compatiblity() && isLinked(nodeIdForRecordBeingRouted, nodeThatMayBeRoutedTo, rootNetworkedNode, me, nodeGroupLinks) && (!isSameNumberOfLinksAwayFromRoot(nodeThatMayBeRoutedTo, rootNetworkedNode, me) || configurationService.isMasterToMaster()) || (nodeThatMayBeRoutedTo.getNodeId().equals(me.getNodeId()) && initialLoad)) {
nodeIds.add(nodeThatMayBeRoutedTo.getNodeId());
}
}
if (!initialLoad && nodeIds != null) {
if (tableMatches(dataMetaData, TableConstants.SYM_NODE_SECURITY)) {
routeSymNodeSecurity(me, nodeIdForRecordBeingRouted, dataMetaData, nodeIds, columnValues);
}
/*
* Don't route insert events for a node to itself. They will be
* loaded during registration. If we route them, then an old
* state can override the correct state
*
* Don't send deletes to a node. A node should be responsible
* for deleting itself.
*/
if (dataMetaData.getData().getDataEventType() == DataEventType.INSERT) {
nodeIds.remove(nodeIdForRecordBeingRouted);
}
}
}
}
use of org.jumpmind.symmetric.service.IConfigurationService in project symmetric-ds by JumpMind.
the class SymmetricEngineHolder method install.
public ISymmetricEngine install(Properties passedInProperties) throws Exception {
TypedProperties properties = new TypedProperties(passedInProperties);
String password = properties.getProperty(BasicDataSourcePropertyConstants.DB_POOL_PASSWORD);
if (StringUtils.isNotBlank(password) && !password.startsWith(SecurityConstants.PREFIX_ENC)) {
try {
ISecurityService service = SecurityServiceFactory.create(SecurityServiceType.CLIENT, properties);
properties.setProperty(BasicDataSourcePropertyConstants.DB_POOL_PASSWORD, SecurityConstants.PREFIX_ENC + service.encrypt(password));
} catch (Exception ex) {
log.warn("Could not encrypt password", ex);
}
}
String engineName = validateRequiredProperties(properties);
passedInProperties.setProperty(ParameterConstants.ENGINE_NAME, engineName);
if (engines.get(engineName) != null) {
try {
engines.get(engineName).stop();
} catch (Exception e) {
log.error("", e);
}
engines.remove(engineName);
}
File enginesDir = new File(AbstractCommandLauncher.getEnginesDir());
File symmetricProperties = new File(enginesDir, engineName + ".properties");
FileOutputStream fileOs = null;
try {
fileOs = new FileOutputStream(symmetricProperties);
properties.store(fileOs, "Updated by SymmetricDS Pro");
} catch (IOException ex) {
throw new RuntimeException("Failed to write symmetric.properties to engine directory", ex);
} finally {
IOUtils.closeQuietly(fileOs);
}
ISymmetricEngine engine = null;
try {
String registrationUrl = properties.getProperty(ParameterConstants.REGISTRATION_URL);
if (StringUtils.isNotBlank(registrationUrl)) {
Collection<ServerSymmetricEngine> all = getEngines().values();
for (ISymmetricEngine currentEngine : all) {
if (currentEngine.getParameterService().getSyncUrl().equals(registrationUrl)) {
String serverNodeGroupId = currentEngine.getParameterService().getNodeGroupId();
String clientNodeGroupId = properties.getProperty(ParameterConstants.NODE_GROUP_ID);
String externalId = properties.getProperty(ParameterConstants.EXTERNAL_ID);
IConfigurationService configurationService = currentEngine.getConfigurationService();
ITriggerRouterService triggerRouterService = currentEngine.getTriggerRouterService();
List<NodeGroup> groups = configurationService.getNodeGroups();
boolean foundGroup = false;
for (NodeGroup nodeGroup : groups) {
if (nodeGroup.getNodeGroupId().equals(clientNodeGroupId)) {
foundGroup = true;
}
}
if (!foundGroup) {
configurationService.saveNodeGroup(new NodeGroup(clientNodeGroupId));
}
boolean foundLink = false;
List<NodeGroupLink> links = configurationService.getNodeGroupLinksFor(serverNodeGroupId, false);
for (NodeGroupLink nodeGroupLink : links) {
if (nodeGroupLink.getTargetNodeGroupId().equals(clientNodeGroupId)) {
foundLink = true;
}
}
if (!foundLink) {
configurationService.saveNodeGroupLink(new NodeGroupLink(serverNodeGroupId, clientNodeGroupId, NodeGroupLinkAction.W));
triggerRouterService.syncTriggers();
}
IRegistrationService registrationService = currentEngine.getRegistrationService();
if (!registrationService.isAutoRegistration() && !registrationService.isRegistrationOpen(clientNodeGroupId, externalId)) {
Node node = new Node(properties);
registrationService.openRegistration(node);
}
}
}
}
engine = create(symmetricProperties.getAbsolutePath());
if (engine != null) {
engineCount++;
engine.start();
} else {
FileUtils.deleteQuietly(symmetricProperties);
log.warn("The engine could not be created. It will not be started");
}
return engine;
} catch (RuntimeException ex) {
if (engine != null) {
engine.destroy();
}
FileUtils.deleteQuietly(symmetricProperties);
throw ex;
}
}
use of org.jumpmind.symmetric.service.IConfigurationService in project symmetric-ds by JumpMind.
the class RouterService method findNodesThatAreReadyForInitialLoad.
public List<NodeSecurity> findNodesThatAreReadyForInitialLoad() {
INodeService nodeService = engine.getNodeService();
IConfigurationService configurationService = engine.getConfigurationService();
String me = nodeService.findIdentityNodeId();
List<NodeSecurity> toReturn = new ArrayList<NodeSecurity>();
List<NodeSecurity> securities = nodeService.findNodeSecurityWithLoadEnabled();
for (NodeSecurity nodeSecurity : securities) {
if (((!nodeSecurity.getNodeId().equals(me) && nodeSecurity.isInitialLoadEnabled()) || (!nodeSecurity.getNodeId().equals(me) && configurationService.isMasterToMaster()) || (nodeSecurity.getNodeId().equals(me) && nodeSecurity.isRevInitialLoadEnabled()))) {
toReturn.add(nodeSecurity);
}
}
return toReturn;
}
use of org.jumpmind.symmetric.service.IConfigurationService in project symmetric-ds by JumpMind.
the class PushService method push.
public synchronized RemoteNodeStatuses push(boolean force) {
IConfigurationService configurationService = engine.getConfigurationService();
IOutgoingBatchService outgoingBatchService = engine.getOutgoingBatchService();
INodeService nodeService = engine.getNodeService();
IClusterService clusterService = engine.getClusterService();
int availableThreadPairs = parameterService.getInt(ParameterConstants.PUSH_THREAD_COUNT_PER_SERVER);
long minimumPeriodBetweenPushesMs = parameterService.getLong(ParameterConstants.PUSH_MINIMUM_PERIOD_MS, -1);
RemoteNodeStatuses statuses = new RemoteNodeStatuses(configurationService.getChannels(false));
Node identityNode = nodeService.findIdentity(false);
if (identityNode != null && identityNode.isSyncEnabled()) {
List<NodeHost> hosts = nodeService.findNodeHosts(identityNode.getNodeId());
int clusterInstanceCount = hosts != null && hosts.size() > 0 ? hosts.size() : 1;
NodeSecurity identitySecurity = nodeService.findNodeSecurity(identityNode.getNodeId());
if (identitySecurity != null && (force || !clusterService.isInfiniteLocked(ClusterConstants.PUSH))) {
Iterator<OutgoingBatchByNodeChannelCount> nodeChannels = outgoingBatchService.getOutgoingBatchByNodeChannelCount(availableThreadPairs * clusterInstanceCount, NodeGroupLinkAction.P, true).iterator();
// based on percentage
while (nodeChannels.hasNext() && pushWorkersWorking.size() < availableThreadPairs) {
OutgoingBatchByNodeChannelCount batchCount = nodeChannels.next();
String nodeId = batchCount.getNodeId();
String channelId = batchCount.getChannelId();
Node remoteNode = nodeService.findNode(nodeId);
NodeChannel nodeChannel = configurationService.getNodeChannel(channelId, nodeId, false);
if (nodeChannel != null && !nodeChannel.isFileSyncFlag() && !pushWorkersWorking.contains(nodeChannel)) {
boolean meetsMinimumTime = true;
// TODO error backoff logic
if (minimumPeriodBetweenPushesMs > 0 && nodeChannel.getLastExtractTime() != null && (System.currentTimeMillis() - nodeChannel.getLastExtractTime().getTime()) < minimumPeriodBetweenPushesMs) {
meetsMinimumTime = false;
}
if (meetsMinimumTime && clusterService.lockNodeChannel(ClusterConstants.PUSH, nodeId, channelId)) {
NodeChannelExtractForPushWorker worker = new NodeChannelExtractForPushWorker(remoteNode, identityNode, identitySecurity, nodeChannel, statuses.add(nodeId, channelId));
pushWorkersWorking.add(nodeChannel);
nodeChannelExtractForPushWorker.execute(worker);
}
}
}
}
}
return statuses;
}
use of org.jumpmind.symmetric.service.IConfigurationService in project symmetric-ds by JumpMind.
the class RestService method sendSchemaImpl.
private SendSchemaResponse sendSchemaImpl(ISymmetricEngine engine, SendSchemaRequest request) {
IConfigurationService configurationService = engine.getConfigurationService();
INodeService nodeService = engine.getNodeService();
ITriggerRouterService triggerRouterService = engine.getTriggerRouterService();
IDataService dataService = engine.getDataService();
SendSchemaResponse response = new SendSchemaResponse();
org.jumpmind.symmetric.model.Node identity = nodeService.findIdentity();
if (identity != null) {
List<org.jumpmind.symmetric.model.Node> nodesToSendTo = new ArrayList<org.jumpmind.symmetric.model.Node>();
List<String> nodeIds = request.getNodeIdsToSendTo();
if (nodeIds == null || nodeIds.size() == 0) {
nodeIds = new ArrayList<String>();
String nodeGroupIdToSendTo = request.getNodeGroupIdToSendTo();
if (isNotBlank(nodeGroupIdToSendTo)) {
NodeGroupLink link = configurationService.getNodeGroupLinkFor(identity.getNodeGroupId(), nodeGroupIdToSendTo, false);
if (link != null) {
Collection<org.jumpmind.symmetric.model.Node> nodes = nodeService.findEnabledNodesFromNodeGroup(nodeGroupIdToSendTo);
nodesToSendTo.addAll(nodes);
} else {
log.warn("Could not send schema to all nodes in the '" + nodeGroupIdToSendTo + "' node group. No node group link exists");
}
} else {
log.warn("Could not send schema to nodes. There are none that were provided and the nodeGroupIdToSendTo was also not provided");
}
} else {
for (String nodeIdToValidate : nodeIds) {
org.jumpmind.symmetric.model.Node node = nodeService.findNode(nodeIdToValidate);
if (node != null) {
NodeGroupLink link = configurationService.getNodeGroupLinkFor(identity.getNodeGroupId(), node.getNodeGroupId(), false);
if (link != null) {
nodesToSendTo.add(node);
} else {
log.warn("Could not send schema to node '" + nodeIdToValidate + "'. No node group link exists");
}
} else {
log.warn("Could not send schema to node '" + nodeIdToValidate + "'. It was not present in the database");
}
}
}
Map<String, List<TableName>> results = response.getNodeIdsSentTo();
List<String> nodeIdsToSendTo = toNodeIds(nodesToSendTo);
for (String nodeId : nodeIdsToSendTo) {
results.put(nodeId, new ArrayList<TableName>());
}
if (nodesToSendTo.size() > 0) {
List<TableName> tablesToSend = request.getTablesToSend();
List<TriggerRouter> triggerRouters = triggerRouterService.getTriggerRouters(true, false);
for (TriggerRouter triggerRouter : triggerRouters) {
Trigger trigger = triggerRouter.getTrigger();
NodeGroupLink link = triggerRouter.getRouter().getNodeGroupLink();
if (link.getSourceNodeGroupId().equals(identity.getNodeGroupId())) {
for (org.jumpmind.symmetric.model.Node node : nodesToSendTo) {
if (link.getTargetNodeGroupId().equals(node.getNodeGroupId())) {
if (tablesToSend == null || tablesToSend.size() == 0 || contains(trigger, tablesToSend)) {
dataService.sendSchema(node.getNodeId(), trigger.getSourceCatalogName(), trigger.getSourceSchemaName(), trigger.getSourceTableName(), false);
results.get(node.getNodeId()).add(new TableName(trigger.getSourceCatalogName(), trigger.getSourceSchemaName(), trigger.getSourceTableName()));
}
}
}
}
}
}
}
return response;
}
Aggregations