Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/3.10' into 3.11
Browse files Browse the repository at this point in the history
  • Loading branch information
erilong committed Oct 25, 2019
2 parents 6edb0bc + d297dbf commit 891ba92
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 5 deletions.
@@ -0,0 +1,27 @@
/**
* 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.service;

public class RegistrationPendingException extends RuntimeException {

private static final long serialVersionUID = 1L;

}
Expand Up @@ -40,6 +40,7 @@
import org.jumpmind.symmetric.service.IOfflineDetectorService;
import org.jumpmind.symmetric.service.IParameterService;
import org.jumpmind.symmetric.service.RegistrationNotOpenException;
import org.jumpmind.symmetric.service.RegistrationPendingException;
import org.jumpmind.symmetric.service.RegistrationRequiredException;
import org.jumpmind.symmetric.transport.AuthenticationException;
import org.jumpmind.symmetric.transport.ConnectionRejectedException;
Expand Down Expand Up @@ -116,6 +117,9 @@ protected void fireOffline(Exception exception, Node remoteNode, RemoteNodeStatu
} else if (isRegistrationRequired(exception)) {
log.warn("Registration is needed before communicating with {} at {}", new Object[] {remoteNode, syncUrl});
status.setStatus(Status.REGISTRATION_REQUIRED);
} else if (isRegistrationPending(exception)) {
log.info("Registration is still pending");
status.setStatus(Status.REGISTRATION_REQUIRED);
} else if (isNoReservation(exception)) {
log.warn("Missing reservation during push with {}", new Object[] { remoteNode });
status.setStatus(Status.BUSY);
Expand Down Expand Up @@ -255,6 +259,18 @@ protected boolean isRegistrationRequired(Exception ex) {
return registrationRequired;
}

protected boolean isRegistrationPending(Exception ex) {
boolean registrationPending = false;
if (ex != null) {
Throwable cause = getRootCause(ex);
registrationPending = cause instanceof RegistrationPendingException;
if (registrationPending == false && (ex instanceof RegistrationPendingException)) {
registrationPending = true;
}
}
return registrationPending;
}

protected boolean isRegistrationNotOpen(Exception ex) {
boolean registrationNotOpen = false;
if (ex != null) {
Expand Down
Expand Up @@ -296,6 +296,7 @@ public void save(Node node) {

flushNodeGroupCache();
}
flushNodeCache();
}

public boolean updateNode(Node node) {
Expand Down Expand Up @@ -933,9 +934,9 @@ public AuthenticationStatus getAuthenticationStatus(String nodeId, String securi
if (node == null) {
retVal = AuthenticationStatus.REGISTRATION_REQUIRED;
} else if (!syncEnabled(node)) {
if(registrationOpen(node)){
if (registrationOpen(node)) {
retVal = AuthenticationStatus.REGISTRATION_REQUIRED;
}else{
} else {
retVal = AuthenticationStatus.SYNC_DISABLED;
}
} else if (!isNodeAuthorized(nodeId, securityToken)) {
Expand All @@ -952,12 +953,12 @@ protected boolean syncEnabled(Node node) {
return syncEnabled;
}

protected boolean registrationOpen(Node node){
protected boolean registrationOpen(Node node) {
NodeSecurity security = findNodeSecurity(node.getNodeId());
if(security != null){
if (security != null) {
return security.isRegistrationEnabled();
}
return false;
}
}

}
Expand Up @@ -271,6 +271,7 @@ protected Node processRegistration(Node nodePriorToRegistration, String remoteHo

saveRegistrationRequest(new RegistrationRequest(foundNode, RegistrationStatus.OK,
remoteHost, remoteAddress));
markNodeAsRegistrationPending(nodeId);

statisticManager.incrementNodesRegistered(1);

Expand Down Expand Up @@ -427,6 +428,30 @@ public void markNodeAsRegistered(String nodeId) {
}
}

protected void markNodeAsRegistrationPending(String nodeId) {
ISqlTransaction transaction = null;
try {
transaction = sqlTemplate.startSqlTransaction();
symmetricDialect.disableSyncTriggers(transaction, nodeId);
transaction.prepareAndExecute(getSql("registrationPendingSql"), nodeId);
transaction.commit();
nodeService.flushNodeAuthorizedCache();
} catch (Error ex) {
if (transaction != null) {
transaction.rollback();
}
throw ex;
} catch (RuntimeException ex) {
if (transaction != null) {
transaction.rollback();
}
throw ex;
} finally {
symmetricDialect.enableSyncTriggers(transaction);
close(transaction);
}
}

private void sleepBeforeRegistrationRetry() {
long sleepTimeInMs = DateUtils.MILLIS_PER_SECOND
* randomTimeSlot.getRandomValueSeededByExternalId();
Expand Down
Expand Up @@ -41,6 +41,8 @@ public RegistrationServiceSqlMap(IDatabasePlatform platform,
+ "update $(node_security) set registration_enabled = 0, registration_time = "
+ " current_timestamp where node_id = ? ");

putSql("registrationPendingSql", "update $(node_security) set registration_time = current_timestamp where node_id = ?");

putSql("reopenRegistrationSql", ""
+ "update $(node_security) set node_password = ?, registration_enabled = 1, "
+ " registration_time = null where node_id = ? and registration_enabled = 0 ");
Expand Down
Expand Up @@ -33,6 +33,7 @@
import org.jumpmind.symmetric.common.ParameterConstants;
import org.jumpmind.symmetric.service.IParameterService;
import org.jumpmind.symmetric.service.RegistrationNotOpenException;
import org.jumpmind.symmetric.service.RegistrationPendingException;
import org.jumpmind.symmetric.service.RegistrationRequiredException;
import org.jumpmind.symmetric.transport.AuthenticationException;
import org.jumpmind.symmetric.transport.ConnectionRejectedException;
Expand Down Expand Up @@ -125,6 +126,8 @@ public InputStream openStream() throws IOException {
throw new RegistrationNotOpenException();
case WebConstants.REGISTRATION_REQUIRED:
throw new RegistrationRequiredException();
case WebConstants.REGISTRATION_PENDING:
throw new RegistrationPendingException();
case WebConstants.SYNC_DISABLED:
throw new SyncDisabledException();
case WebConstants.SC_SERVICE_BUSY:
Expand Down
Expand Up @@ -39,6 +39,7 @@
import org.jumpmind.symmetric.model.ChannelMap;
import org.jumpmind.symmetric.model.Node;
import org.jumpmind.symmetric.service.IConfigurationService;
import org.jumpmind.symmetric.service.RegistrationPendingException;
import org.jumpmind.symmetric.service.RegistrationRequiredException;
import org.jumpmind.symmetric.transport.AuthenticationException;
import org.jumpmind.symmetric.transport.ConnectionRejectedException;
Expand Down Expand Up @@ -306,6 +307,8 @@ private void analyzeResponseCode(int code) throws IOException {
throw new SyncDisabledException();
} else if (WebConstants.REGISTRATION_REQUIRED == code) {
throw new RegistrationRequiredException();
} else if (WebConstants.REGISTRATION_PENDING == code) {
throw new RegistrationPendingException();
} else if (code != WebConstants.SC_OK) {
throw new HttpException(code, "Received an unexpected response code of " + code + " from the server");
}
Expand Down
Expand Up @@ -51,6 +51,8 @@ public class WebConstants {

public static final int REGISTRATION_REQUIRED = 657;

public static final int REGISTRATION_PENDING = 667;

public static final int SYNC_DISABLED = 658;

public static final int SC_FORBIDDEN = 659;
Expand Down
Expand Up @@ -85,6 +85,9 @@ protected int push(String sourceNodeId, String channelId, InputStream inputStrea
if (nodeSecurity != null) {
String createdAtNodeId = nodeSecurity.getCreatedAtNodeId();
if (nodeSecurity.isRegistrationEnabled() && (createdAtNodeId == null || createdAtNodeId.equals(nodeService.findIdentityNodeId()))) {
if (nodeSecurity.getRegistrationTime() != null) {
return WebConstants.REGISTRATION_PENDING;
}
return WebConstants.REGISTRATION_REQUIRED;
}
}
Expand Down

0 comments on commit 891ba92

Please sign in to comment.