Commit c4ceb952 authored by Ard Schrijvers's avatar Ard Schrijvers

HSTTWO-4340 [Backport 11.2] Make sure the hst config nodes loading is resilient

During the loading of the hst configuration we can detect modifications.
If that happens, we need a retry of the loading of the config nodes.

If the exception happens to for example incorrect jcr session credentials,
still a ModelLoadingException is thrown resulting in a fail-fast and no
retry.

(cherry picked from commit 36159b70)
parent b059e823
/*
* Copyright 2010-2013 Hippo B.V. (http://www.onehippo.com)
* Copyright 2010-2018 Hippo B.V. (http://www.onehippo.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -28,8 +28,8 @@ import javax.jcr.RepositoryException;
import javax.jcr.Session;
import org.apache.commons.lang.StringUtils;
import org.hippoecm.hst.configuration.model.ConfigurationNodesLoadingException;
import org.hippoecm.hst.configuration.model.HstNode;
import org.hippoecm.hst.configuration.model.ModelLoadingException;
import org.hippoecm.hst.core.internal.StringPool;
import org.hippoecm.hst.provider.ValueProvider;
import org.hippoecm.hst.provider.jcr.JCRValueProvider;
......@@ -101,7 +101,7 @@ public class HstNodeImpl implements HstNode {
}
long iteratorSizeAfterLoop = nodes.getSize();
if (iteratorSizeBeforeLoop != iteratorSizeAfterLoop) {
throw new ModelLoadingException("During building the in memory HST model, the hst configuration jcr nodes have changed.");
throw new ConfigurationNodesLoadingException("During building the in memory HST model, the hst configuration jcr nodes have changed.");
}
}
......
/*
* Copyright 2013-2015 Hippo B.V. (http://www.onehippo.com)
* Copyright 2013-2018 Hippo B.V. (http://www.onehippo.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -26,6 +26,7 @@ import javax.jcr.RepositoryException;
import javax.jcr.Session;
import org.apache.commons.lang.StringUtils;
import org.hippoecm.hst.configuration.model.ConfigurationNodesLoadingException;
import org.hippoecm.hst.configuration.model.HstNode;
import org.hippoecm.hst.configuration.model.ModelLoadingException;
import org.hippoecm.hst.site.HstServices;
......@@ -102,7 +103,7 @@ public class HstNodeLoadingCache implements HstEventConsumer {
if (!lazyCloseableSession.getSession().nodeExists(rootPath)) {
// root config node is not present any more
rootNode = null;
throw new ModelLoadingException("Cannot load hst model since root config node " +
throw new ConfigurationNodesLoadingException("Cannot load hst model since root config node " +
"'"+rootPath+"' missing");
}
}
......@@ -131,7 +132,7 @@ public class HstNodeLoadingCache implements HstEventConsumer {
log.info("Updating root HstNode took '{}' ms.", (System.currentTimeMillis() - start));
}
} catch (RepositoryException e) {
throw new ModelLoadingException("Could not load hst node model due to RepositoryException : ", e);
throw new ConfigurationNodesLoadingException("Could not load hst node model due to RepositoryException : ", e);
}
HstNode result;
if (absPath.equals(rootPath)) {
......
/*
* Copyright 2018 Hippo B.V. (http://www.onehippo.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.hippoecm.hst.configuration.model;
public class ConfigurationNodesLoadingException extends ModelLoadingException {
public ConfigurationNodesLoadingException(final String message) {
super(message);
}
public ConfigurationNodesLoadingException(final String message, final Throwable cause) {
super(message, cause);
}
}
......@@ -37,6 +37,8 @@ import org.apache.commons.lang.BooleanUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.math.NumberUtils;
import org.hippoecm.hst.configuration.cache.HstNodeLoadingCache;
import org.hippoecm.hst.configuration.model.ConfigurationNodesLoadingException;
import org.hippoecm.hst.configuration.model.HstNode;
import org.hippoecm.hst.container.event.ComponentManagerBeforeReplacedEvent;
import org.hippoecm.hst.core.container.ComponentManager;
import org.hippoecm.hst.core.container.ContainerException;
......@@ -335,7 +337,18 @@ public class DefaultHstSiteConfigurer implements HstSiteConfigurer {
final long start = System.currentTimeMillis();
final HstNodeLoadingCache hstNodeLoadingCache = componentManager.getComponent(HstNodeLoadingCache.class);
// triggers the loading of all the hst configuration nodes
hstNodeLoadingCache.getNode(hstNodeLoadingCache.getRootPath());
HstNode root = null;
while (root == null) {
try {
root = hstNodeLoadingCache.getNode(hstNodeLoadingCache.getRootPath());
} catch (ConfigurationNodesLoadingException e) {
if (log.isDebugEnabled()) {
log.info("Exception while trying to load the HST configuration nodes. Try again.", e);
} else {
log.info("Exception while trying to load the HST configuration nodes. Try again. Reason: {}", e.getMessage());
}
}
}
log.info("Loaded all HST Configuraion JCR nodes in {} ms.", (System.currentTimeMillis() - start));
}
log.info(INIT_DONE_MSG);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment