From ad42379fa4ed631400aa189ce56568eaaa4bdd04 Mon Sep 17 00:00:00 2001 From: Alfonso Altamirano Date: Wed, 28 Feb 2024 21:41:54 -0600 Subject: [PATCH] FISH-7364: making status sync when restarting instance --- .../v3/admin/cluster/RestartInstanceCommand.java | 13 ++++++++++--- .../v3/admin/cluster/StartInstanceCommand.java | 6 +++--- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/nucleus/cluster/admin/src/main/java/com/sun/enterprise/v3/admin/cluster/RestartInstanceCommand.java b/nucleus/cluster/admin/src/main/java/com/sun/enterprise/v3/admin/cluster/RestartInstanceCommand.java index 7213ea8f43b..e5fc3953d0f 100644 --- a/nucleus/cluster/admin/src/main/java/com/sun/enterprise/v3/admin/cluster/RestartInstanceCommand.java +++ b/nucleus/cluster/admin/src/main/java/com/sun/enterprise/v3/admin/cluster/RestartInstanceCommand.java @@ -37,7 +37,7 @@ * only if the new code is made subject to such option by the copyright * holder. */ -// Portions Copyright [2018-2022] [Payara Foundation and/or its affiliates] +// Portions Copyright [2018-2024] [Payara Foundation and/or its affiliates] package com.sun.enterprise.v3.admin.cluster; @@ -50,6 +50,7 @@ import com.sun.enterprise.util.OS; import com.sun.enterprise.util.ObjectAnalyzer; import com.sun.enterprise.util.StringUtils; +import fish.payara.nucleus.executorservice.PayaraExecutorService; import jakarta.inject.Inject; import jakarta.inject.Named; import org.glassfish.api.ActionReport; @@ -65,6 +66,8 @@ import java.util.logging.Level; import java.util.logging.Logger; +import static com.sun.enterprise.v3.admin.cluster.StartInstanceCommand.pollForLife; + /** * @author bnevins */ @@ -136,6 +139,9 @@ public class RestartInstanceCommand implements AdminCommand { private AdminCommandContext context; + @Inject + private PayaraExecutorService executor; + private static final long WAIT_TIME_MS = 600000; // 10 minutes @Override @@ -169,13 +175,14 @@ public void execute(AdminCommandContext ctx) { logger.log(Level.FINE, "Restart-instance old-pid = {0}", oldPid); callInstance(); checkForRestart(); - + pollForLife(instance, executor, timeout); + synchronizeInstance(); + if (!isError()) { String msg = Strings.get("restart.instance.success", instanceName); logger.info(msg); report.setMessage(msg); } - synchronizeInstance(); } catch (InstanceNotRunningException inre) { start(); } catch (CommandException ce) { diff --git a/nucleus/cluster/admin/src/main/java/com/sun/enterprise/v3/admin/cluster/StartInstanceCommand.java b/nucleus/cluster/admin/src/main/java/com/sun/enterprise/v3/admin/cluster/StartInstanceCommand.java index 24eb23aec12..48aa9ccda45 100644 --- a/nucleus/cluster/admin/src/main/java/com/sun/enterprise/v3/admin/cluster/StartInstanceCommand.java +++ b/nucleus/cluster/admin/src/main/java/com/sun/enterprise/v3/admin/cluster/StartInstanceCommand.java @@ -37,7 +37,7 @@ * only if the new code is made subject to such option by the copyright * holder. * - * Portions Copyright [2018-2019] [Payara Foundation and/or its affiliates] + * Portions Copyright [2018-2024] [Payara Foundation and/or its affiliates] */ package com.sun.enterprise.v3.admin.cluster; @@ -244,7 +244,7 @@ public void execute(AdminCommandContext ctx) { if (report.getActionExitCode() == SUCCESS) { // Make sure instance is really up - if (!pollForLife(instance)) { + if (!pollForLife(instance, executor, timeout)) { report.setMessage(Strings.get("start.instance.timeout", instanceName)); report.setActionExitCode(FAILURE); } @@ -330,7 +330,7 @@ private void startDockerContainer(AdminCommandContext adminCommandContext) { * * @return true if the instance started up, or false otherwise. */ - private boolean pollForLife(Server instance) { + static boolean pollForLife(Server instance, PayaraExecutorService executor, int timeout) { // Start a new thread to check when the instance has started CountDownLatch instanceTimeout = new CountDownLatch(1);