Skip to content

Commit

Permalink
0002313: When SymmetricDS is stopped via REST or jmx auto.start.engin…
Browse files Browse the repository at this point in the history
…e should be set to false so the node won't restart automatically
  • Loading branch information
chenson42 committed Jul 31, 2015
1 parent f3f19ea commit 7afd44e
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 9 deletions.
Expand Up @@ -37,6 +37,7 @@
import org.jumpmind.extension.IBuiltInExtensionPoint;
import org.jumpmind.security.SecurityConstants;
import org.jumpmind.symmetric.ISymmetricEngine;
import org.jumpmind.symmetric.common.Constants;
import org.jumpmind.symmetric.common.ParameterConstants;
import org.jumpmind.symmetric.ext.ISymmetricEngineAware;
import org.jumpmind.symmetric.model.Node;
Expand Down Expand Up @@ -78,6 +79,7 @@ public boolean isStarted() {
public boolean start() {
try {
if (engine != null) {
engine.getParameterService().saveParameter(ParameterConstants.AUTO_START_ENGINE, "true", Constants.SYSTEM_USER);
return engine.start();
} else {
return false;
Expand All @@ -93,6 +95,7 @@ public void stop() {
try {
if (engine != null) {
engine.stop();
engine.getParameterService().saveParameter(ParameterConstants.AUTO_START_ENGINE, "false", Constants.SYSTEM_USER);
}
} catch (Exception ex) {
log.error("", ex);
Expand Down
Expand Up @@ -570,10 +570,10 @@ public synchronized boolean start(boolean startJobs) {
} else {
log.error("Did not start SymmetricDS. It has not been configured properly");
}
} catch (SymmetricException ex) {
log.error(ex.getMessage());
} catch (Throwable ex) {
log.error("An error occurred while starting SymmetricDS", ex);
/* Don't leave SymmetricDS in a half started state */
stop();
} finally {
starting = false;
}
Expand Down Expand Up @@ -736,6 +736,7 @@ public synchronized void stop() {

started = false;
starting = false;

}

public synchronized void destroy() {
Expand Down
Expand Up @@ -41,6 +41,8 @@ final public class ParameterConstants {

private ParameterConstants() {
}

public final static String AUTO_START_ENGINE = "auto.start.engine";

public final static String JDBC_EXECUTE_BATCH_SIZE = "db.jdbc.execute.batch.size";
public final static String JDBC_READ_STRINGS_AS_BYTES = "db.read.strings.as.bytes";
Expand Down
Expand Up @@ -336,6 +336,13 @@ transport.type=http
# Tags: transport
transport.max.bytes.to.sync=1048576

# This indicates whether this node engine should be started when the instance is restarted
#
# DatabaseOverridable: true
# Tags: general
# Type: boolean
auto.start.engine=true

# If this is true, when symmetric starts up it will try to create the necessary tables.
#
# Tags: general
Expand Down
Expand Up @@ -336,7 +336,7 @@ public ISymmetricEngine install(Properties passedInProperties) throws Exception
}

engine = create(symmetricProperties.getAbsolutePath());
if (engine != null && autoStart) {
if (engine != null) {
engineCount++;
engine.start();
} else {
Expand Down Expand Up @@ -441,7 +441,8 @@ public EngineStarter(String propertiesFile) {
@Override
public void run() {
ISymmetricEngine engine = create(propertiesFile);
if (engine != null && autoStart) {
if (engine != null && autoStart &&
engine.getParameterService().is(ParameterConstants.AUTO_START_ENGINE)) {
engine.start();
}
enginesStarting.remove(this);
Expand Down
Expand Up @@ -82,7 +82,7 @@ protected void service(HttpServletRequest req, HttpServletResponse res)
new Object[] { ServletUtils.normalizeRequestUri(req), req.getRemoteHost(),
req.getRemoteAddr(), req.getQueryString() });
}
ServletUtils.sendError(res, HttpServletResponse.SC_SERVICE_UNAVAILABLE);
ServletUtils.sendError(res, WebConstants.SC_SERVICE_UNAVAILABLE);

} else if (engine.isStarted()) {
IUriHandler handler = findMatchingHandler(engine, req);
Expand Down Expand Up @@ -126,13 +126,19 @@ protected void service(HttpServletRequest req, HttpServletResponse res)
"The client node request is being rejected because the server node is currently starting. Please be patient. The request was {} from the host {} with an ip address of {} will not be processed. The query string was: {}",
new Object[] { ServletUtils.normalizeRequestUri(req), req.getRemoteHost(),
req.getRemoteAddr(), req.getQueryString() });
ServletUtils.sendError(res, HttpServletResponse.SC_SERVICE_UNAVAILABLE);
ServletUtils.sendError(res, WebConstants.SC_SERVICE_UNAVAILABLE);
} else if (!engine.isStarted() && !engine.isConfigured()) {
log.warn(
log.info(
"The client node request is being rejected because the server node was not started because it is not configured properly. The request {} from the host {} with an ip address of {} will not be processed. The query string was: {}",
new Object[] { ServletUtils.normalizeRequestUri(req), req.getRemoteHost(),
req.getRemoteAddr(), req.getQueryString() });
ServletUtils.sendError(res, HttpServletResponse.SC_SERVICE_UNAVAILABLE);
ServletUtils.sendError(res, WebConstants.SC_SERVICE_UNAVAILABLE);
} else {
log.debug(
"The client node request is being rejected because the server node is not started. The request {} from the host {} with an ip address of {} will not be processed. The query string was: {}",
new Object[] { ServletUtils.normalizeRequestUri(req), req.getRemoteHost(),
req.getRemoteAddr(), req.getQueryString() });
ServletUtils.sendError(res, WebConstants.SC_SERVICE_UNAVAILABLE);
}

}
Expand Down
Expand Up @@ -49,6 +49,7 @@
import org.jumpmind.db.sql.Row;
import org.jumpmind.exception.IoException;
import org.jumpmind.symmetric.ISymmetricEngine;
import org.jumpmind.symmetric.common.Constants;
import org.jumpmind.symmetric.common.ParameterConstants;
import org.jumpmind.symmetric.io.data.writer.StructureDataWriter.PayloadType;
import org.jumpmind.symmetric.model.BatchAck;
Expand Down Expand Up @@ -1277,13 +1278,16 @@ public RestError handleError(Exception ex, HttpServletRequest req) {
}

private void startImpl(ISymmetricEngine engine) {
if (!engine.start()) {
engine.getParameterService().saveParameter(ParameterConstants.AUTO_START_ENGINE, "true", Constants.SYSTEM_USER);
if (engine.start()) {
throw new InternalServerErrorException();
}
}

private void stopImpl(ISymmetricEngine engine) {
engine.stop();
engine.getParameterService().saveParameter(ParameterConstants.AUTO_START_ENGINE, "false", Constants.SYSTEM_USER);

}

private void syncTriggersImpl(ISymmetricEngine engine, boolean force) {
Expand Down

0 comments on commit 7afd44e

Please sign in to comment.