Skip to content

Commit

Permalink
APPNG-2481
Browse files Browse the repository at this point in the history
  • Loading branch information
madness-inc committed Jun 22, 2023
1 parent cd67200 commit 27125dc
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
import lombok.Setter;

/**
* An {@link Event} that holds information about the current status of an node (system properties and environment,memory
* usage, state of sites).
* An {@link Event} that holds information about the current status of an node (system properties and environment,
* memory usage, state of sites).
*
* @author Matthias Müller
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public void waitForClusterState(Environment env, Site site, Logger logger) {
"Site {} is active on {} of {} nodes, waiting {}s for site to start on {} nodes.",
site.getName(), activeNodes, numNodes, waitTime, minActiveNodes - activeNodes);
waited += waitTime;
Thread.sleep(TimeUnit.SECONDS.toMillis(waitTime));
TimeUnit.SECONDS.sleep(waitTime);
} catch (InterruptedException e) {
//
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
import org.appng.api.support.environment.EnvironmentKeys;
import org.appng.core.controller.RepositoryWatcher;
import org.appng.core.controller.handler.GuiHandler;
import org.appng.core.controller.messaging.NodeEvent;
import org.appng.core.controller.messaging.ReloadSiteEvent;
import org.appng.core.controller.rest.RestPostProcessor;
import org.appng.core.controller.rest.openapi.OpenApiPostProcessor;
Expand Down Expand Up @@ -944,31 +945,34 @@ public Runnable getSiteLoader(SiteImpl siteToLoad, Environment env, boolean send

private void handleReload(Environment env, boolean sendReloadEvent, SiteImpl currentSite)
throws InterruptedException {
Properties siteProps = currentSite.getProperties();
int siteSuspendOffset = siteProps.getInteger(SiteProperties.SUSPEND_ON_RELOAD, SITE_SUSPEND_DEFAULT);
if (siteSuspendOffset > 0) {
((SiteImpl) currentSite).setState(SiteState.SUSPENDED, env);
LOGGER.info("Setting state to {} for site {}, waiting {}s before reloading.", currentSite.getState(),
currentSite.getName(), siteSuspendOffset);
Thread.sleep(TimeUnit.SECONDS.toMillis(siteSuspendOffset));

int suspendMaxWait = siteProps.getInteger(SiteProperties.SUSPEND_MAX_WAIT, SITE_SUSPEND_MAXWAIT);
int waited = 0;
int requests = 0;
int maxRequest = sendReloadEvent ? 1 : 0;
while ((requests = currentSite.getRequests()) > maxRequest && waited < suspendMaxWait) {
LOGGER.info("Site {} is still processing {} requests, waiting 1s.", currentSite.getName(), requests);
Thread.sleep(TimeUnit.SECONDS.toMillis(1));
waited += 1;
}
if (waited >= suspendMaxWait) {
LOGGER.warn(
"Waited {}s for {} site {} to finish request processing, but there are {} requests remaining.",
suspendMaxWait, currentSite.getState(), currentSite.getName(), requests);
if (NodeEvent.clusterState(env, Messaging.getNodeId()).size() > 1) {
Properties siteProps = currentSite.getProperties();
int siteSuspendOffset = siteProps.getInteger(SiteProperties.SUSPEND_ON_RELOAD, SITE_SUSPEND_DEFAULT);
if (siteSuspendOffset > 0) {
((SiteImpl) currentSite).setState(SiteState.SUSPENDED, env);
LOGGER.info("Setting state to {} for site {}, waiting {}s before reloading.", currentSite.getState(),
currentSite.getName(), siteSuspendOffset);
TimeUnit.SECONDS.sleep(siteSuspendOffset);

int suspendMaxWait = siteProps.getInteger(SiteProperties.SUSPEND_MAX_WAIT, SITE_SUSPEND_MAXWAIT);
int waited = 0;
int requests = 0;
int maxRequest = sendReloadEvent ? 1 : 0;
while ((requests = currentSite.getRequests()) > maxRequest && waited < suspendMaxWait) {
LOGGER.info("Site {} is still processing {} requests, waiting 1s.", currentSite.getName(),
requests);
TimeUnit.SECONDS.sleep(1);
waited += 1;
}
if (waited >= suspendMaxWait) {
LOGGER.warn(
"Waited {}s for {} site {} to finish request processing, but there are {} requests remaining.",
suspendMaxWait, currentSite.getState(), currentSite.getName(), requests);
}
}
}

LOGGER.info("prepare reload of site {}, shutting down first", currentSite);
LOGGER.info("Preparing reload of site {}, shutting down first.", currentSite);
shutDownSite(env, currentSite, false);
}

Expand Down

0 comments on commit 27125dc

Please sign in to comment.