Merge pull request #1308 from scm-manager/bugfix/wait_before_restart

wait before restart if system property "sonia.scm.restart.wait" is set
This commit is contained in:
Sebastian Sdorra
2020-09-01 15:39:10 +02:00
committed by GitHub
5 changed files with 84 additions and 10 deletions

View File

@@ -31,9 +31,8 @@ import javax.inject.Singleton;
@Singleton
public class DefaultRestarter implements Restarter {
private ScmEventBus eventBus;
private RestartStrategy strategy;
private final ScmEventBus eventBus;
private final RestartStrategy strategy;
@Inject
public DefaultRestarter() {

View File

@@ -61,6 +61,7 @@ import static java.util.Comparator.comparing;
class MigrationWizardServlet extends HttpServlet {
private static final Logger LOG = LoggerFactory.getLogger(MigrationWizardServlet.class);
static final String PROPERTY_WAIT_TIME = "sonia.scm.restart-migration.wait";
private final XmlRepositoryV1UpdateStep repositoryV1UpdateStep;
private final DefaultMigrationStrategyDAO migrationStrategyDao;
@@ -129,7 +130,7 @@ class MigrationWizardServlet extends HttpServlet {
repositoryLineEntries.stream()
.forEach(
entry-> {
entry -> {
String id = entry.getId();
String protocol = entry.getType();
String originalName = entry.getOriginalName();
@@ -145,7 +146,7 @@ class MigrationWizardServlet extends HttpServlet {
if (restarter.isSupported()) {
respondWithTemplate(resp, model, "templates/repository-migration-restart.mustache");
restarter.restart(MigrationWizardServlet.class, "wrote migration data");
new Thread(this::restart).start();
} else {
respondWithTemplate(resp, model, "templates/repository-migration-manual-restart.mustache");
LOG.error("Restarting is not supported on this platform.");
@@ -153,6 +154,19 @@ class MigrationWizardServlet extends HttpServlet {
}
}
private void restart() {
String wait = System.getProperty(PROPERTY_WAIT_TIME);
if (!Strings.isNullOrEmpty(wait)) {
try {
Thread.sleep(Long.parseLong(wait));
} catch (InterruptedException e) {
LOG.error("error on waiting before restart", e);
Thread.currentThread().interrupt();
}
}
restarter.restart(MigrationWizardServlet.class, "wrote migration data");
}
private List<RepositoryLineEntry> getRepositoryLineEntries() {
List<V1Repository> repositoriesWithoutMigrationStrategies =
repositoryV1UpdateStep.getRepositoriesWithoutMigrationStrategies();