mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-13 00:45:44 +01:00
Implemented handling of concurrent modification of objects
based on lastModified date
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra All rights reserved.
|
||||
*
|
||||
* <p>
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* <p>
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer. 2. Redistributions in
|
||||
* binary form must reproduce the above copyright notice, this list of
|
||||
@@ -11,7 +11,7 @@
|
||||
* materials provided with the distribution. 3. Neither the name of SCM-Manager;
|
||||
* nor the names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
@@ -22,17 +22,12 @@
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* <p>
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.repository;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.github.sdorra.ssp.PermissionActionCheck;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.inject.Inject;
|
||||
@@ -43,47 +38,29 @@ import sonia.scm.NotFoundException;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public final class HealthChecker
|
||||
{
|
||||
public final class HealthChecker {
|
||||
|
||||
/**
|
||||
* the logger for HealthChecker
|
||||
*/
|
||||
private static final Logger logger =
|
||||
LoggerFactory.getLogger(HealthChecker.class);
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
private final Set<HealthCheck> checks;
|
||||
|
||||
private final RepositoryManager repositoryManager;
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param checks
|
||||
* @param repositoryManager
|
||||
*/
|
||||
@Inject
|
||||
public HealthChecker(Set<HealthCheck> checks,
|
||||
RepositoryManager repositoryManager)
|
||||
{
|
||||
RepositoryManager repositoryManager) {
|
||||
this.checks = checks;
|
||||
this.repositoryManager = repositoryManager;
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
public void check(String id) throws NotFoundException {
|
||||
RepositoryPermissions.healthCheck(id).check();
|
||||
|
||||
Repository repository = repositoryManager.get(id);
|
||||
|
||||
if (repository == null)
|
||||
{
|
||||
if (repository == null) {
|
||||
throw new RepositoryNotFoundException(
|
||||
"could not find repository with id ".concat(id));
|
||||
}
|
||||
@@ -98,27 +75,19 @@ public final class HealthChecker
|
||||
doCheck(repository);
|
||||
}
|
||||
|
||||
public void checkAll()
|
||||
{
|
||||
public void checkAll() {
|
||||
logger.debug("check health of all repositories");
|
||||
|
||||
PermissionActionCheck<Repository> check = RepositoryPermissions.healthCheck();
|
||||
|
||||
for (Repository repository : repositoryManager.getAll())
|
||||
{
|
||||
if (check.isPermitted(repository))
|
||||
{
|
||||
try
|
||||
{
|
||||
for (Repository repository : repositoryManager.getAll()) {
|
||||
if (check.isPermitted(repository)) {
|
||||
try {
|
||||
check(repository);
|
||||
}
|
||||
catch (ConcurrentModificationException | NotFoundException ex)
|
||||
{
|
||||
} catch (ConcurrentModificationException | NotFoundException ex) {
|
||||
logger.error("health check ends with exception", ex);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
logger.debug(
|
||||
"no permissions to execute health check for repository {}",
|
||||
repository.getId());
|
||||
@@ -131,25 +100,20 @@ public final class HealthChecker
|
||||
|
||||
HealthCheckResult result = HealthCheckResult.healthy();
|
||||
|
||||
for (HealthCheck check : checks)
|
||||
{
|
||||
for (HealthCheck check : checks) {
|
||||
logger.trace("execute health check {} for repository {}",
|
||||
check.getClass(), repository.getName());
|
||||
result = result.merge(check.check(repository));
|
||||
}
|
||||
|
||||
if (result.isUnhealthy())
|
||||
{
|
||||
if (result.isUnhealthy()) {
|
||||
logger.warn("repository {} is unhealthy: {}", repository.getName(),
|
||||
result);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
logger.info("repository {} is healthy", repository.getName());
|
||||
}
|
||||
|
||||
if (!(repository.isHealthy() && result.isHealthy()))
|
||||
{
|
||||
if (!(repository.isHealthy() && result.isHealthy())) {
|
||||
logger.trace("store health check results for repository {}",
|
||||
repository.getName());
|
||||
repository.setHealthCheckFailures(
|
||||
@@ -158,11 +122,5 @@ public final class HealthChecker
|
||||
}
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private final Set<HealthCheck> checks;
|
||||
|
||||
/** Field description */
|
||||
private final RepositoryManager repositoryManager;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user