mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-09 06:55:47 +01:00
allow rerun of healthchecks
This commit is contained in:
@@ -54,6 +54,7 @@ import sonia.scm.repository.Branches;
|
||||
import sonia.scm.repository.BrowserResult;
|
||||
import sonia.scm.repository.Changeset;
|
||||
import sonia.scm.repository.ChangesetPagingResult;
|
||||
import sonia.scm.repository.HealthChecker;
|
||||
import sonia.scm.repository.Permission;
|
||||
import sonia.scm.repository.PermissionType;
|
||||
import sonia.scm.repository.Repository;
|
||||
@@ -131,16 +132,18 @@ public class RepositoryResource
|
||||
* @param configuration
|
||||
* @param repositoryManager
|
||||
* @param servicefactory
|
||||
* @param healthChecker
|
||||
*/
|
||||
@Inject
|
||||
public RepositoryResource(ScmConfiguration configuration,
|
||||
RepositoryManager repositoryManager,
|
||||
RepositoryServiceFactory servicefactory)
|
||||
RepositoryServiceFactory servicefactory, HealthChecker healthChecker)
|
||||
{
|
||||
super(repositoryManager);
|
||||
this.configuration = configuration;
|
||||
this.repositoryManager = repositoryManager;
|
||||
this.servicefactory = servicefactory;
|
||||
this.healthChecker = healthChecker;
|
||||
setDisableCache(false);
|
||||
}
|
||||
|
||||
@@ -213,7 +216,7 @@ public class RepositoryResource
|
||||
}
|
||||
catch (ScmSecurityException ex)
|
||||
{
|
||||
logger.warn("delete not allowd", ex);
|
||||
logger.warn("delete not allowed", ex);
|
||||
response = Response.status(Response.Status.FORBIDDEN).build();
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -231,6 +234,50 @@ public class RepositoryResource
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Re run repository health checks.<br />
|
||||
* Status codes:
|
||||
* <ul>
|
||||
* <li>201 re run success</li>
|
||||
* <li>403 forbidden, the current user has no owner privileges</li>
|
||||
* <li>404 could not find repository</li>
|
||||
* <li>500 internal server error</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param id id of the repository
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@POST
|
||||
@Path("{id}/healthcheck")
|
||||
public Response runHealthChecks(@PathParam("id") String id)
|
||||
{
|
||||
Response response;
|
||||
|
||||
try
|
||||
{
|
||||
healthChecker.check(id);
|
||||
response = Response.ok().build();
|
||||
}
|
||||
catch (RepositoryNotFoundException ex)
|
||||
{
|
||||
logger.warn("could not find repository ".concat(id), ex);
|
||||
response = Response.status(Status.NOT_FOUND).build();
|
||||
}
|
||||
catch (RepositoryException ex)
|
||||
{
|
||||
logger.error("error occured during health check", ex);
|
||||
response = Response.serverError().build();
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
logger.error("error occured during health check", ex);
|
||||
response = Response.serverError().build();
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Modifies the given repository.<br />
|
||||
* This method requires owner privileges.<br />
|
||||
@@ -1138,6 +1185,9 @@ public class RepositoryResource
|
||||
/** Field description */
|
||||
private final ScmConfiguration configuration;
|
||||
|
||||
/** Field description */
|
||||
private final HealthChecker healthChecker;
|
||||
|
||||
/** Field description */
|
||||
private final RepositoryManager repositoryManager;
|
||||
|
||||
|
||||
@@ -81,6 +81,33 @@ public final class HealthChecker
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param id
|
||||
*
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryException
|
||||
* @throws RepositoryNotFoundException
|
||||
*/
|
||||
public void check(String id)
|
||||
throws RepositoryNotFoundException, RepositoryException, IOException
|
||||
{
|
||||
SecurityUtils.getSubject().checkRole(Role.ADMIN);
|
||||
|
||||
Repository repository = repositoryManager.get(id);
|
||||
|
||||
if (repository == null)
|
||||
{
|
||||
throw new RepositoryNotFoundException(
|
||||
"could not find repository with id ".concat(id));
|
||||
}
|
||||
|
||||
check(repository);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user