Skip to content

Commit

Permalink
FISH-898 Added timeout option to instance commands
Browse files Browse the repository at this point in the history
  • Loading branch information
kalinchan committed Mar 2, 2022
1 parent ed8037e commit c6cfba2
Show file tree
Hide file tree
Showing 9 changed files with 323 additions and 171 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,18 @@ start.dg.command=Start a deployment group
start.dg=Starting deployment group {0}
stop.dg=Stopping deployment group {0}
restart.dg=Restarting deployment group {0}
start.dg.timeout=Timed out while waiting for deployment group {0} to start
stop.dg.timeout=Timed out while waiting for deployment group {0} to stop
restart.dg.timeout=Timed out while waiting for deployment group {0} to restart
## StartClusterCommand
start.cluster.command=Start a cluster
start.cluster=Starting cluster {0}
stop.cluster.command=Stop a cluster
stop.cluster=Stopping cluster {0}
restart.cluster=Restarting cluster {0}
start.cluster.timeout=Timed out while waiting for cluster {0} to start
stop.cluster.timeout=Timed out while waiting for cluster {0} to stop
restart.cluster.timeout=Timed out while waiting for cluster {0} to restart
cluster.command.notDas=This is a Payara server instance and {0} can only run on DAS.
cluster.command.instancesSucceeded=The command {0} executed successfully for: {1}
cluster.command.instancesFailed=The command {0} failed for: {1}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,28 @@
* only if the new code is made subject to such option by the copyright
* holder.
*
* Portions Copyright [2016-2018] [Payara Foundation and/or its affiliates]
* Portions Copyright [2016-2022] [Payara Foundation and/or its affiliates]
*
*/

package com.sun.enterprise.v3.admin.cluster;

import com.sun.enterprise.config.serverbeans.Cluster;
import java.util.logging.Logger;

import org.glassfish.api.admin.*;
import javax.inject.Inject;


import org.jvnet.hk2.annotations.Service;
import org.glassfish.api.Param;
import com.sun.enterprise.config.serverbeans.Domain;
import org.glassfish.api.ActionReport;
import org.glassfish.api.ActionReport.ExitCode;
import org.glassfish.api.Param;
import org.glassfish.api.admin.*;
import org.glassfish.hk2.api.PerLookup;
import org.jvnet.hk2.annotations.Service;

import com.sun.enterprise.config.serverbeans.Domain;
import javax.inject.Inject;
import javax.validation.constraints.Min;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.logging.Logger;

@Service(name = "restart-cluster")
@ExecuteOn(value={RuntimeType.DAS})
Expand Down Expand Up @@ -88,17 +90,40 @@ public class RestartClusterCommand implements AdminCommand {

@Param(optional = true, defaultValue = "false")
private boolean verbose;

@Param(optional = true, defaultValue = "true")
private boolean rolling;

@Param(optional = true, defaultValue = "0")
private String delay;

@Min(message = "Timeout must be at least 1 second long.", value = 1)
@Param(optional = true, defaultValue = "600")
private int timeout;

private ActionReport report;

@Override
public void execute(AdminCommandContext context) {
report = context.getActionReport();;
CompletableFuture<Void> future = CompletableFuture.runAsync(() -> restartCluster(context));

try {
future.get(timeout, TimeUnit.SECONDS);
} catch (InterruptedException | ExecutionException e) {
// Do Nothing
} catch (TimeoutException e) {
//Time has exceeded timeout value.
String msg = Strings.get("restart.cluster.timeout", clusterName);
report.setActionExitCode(ExitCode.FAILURE);
report.setMessage(msg);
} finally {
future.cancel(true);
return;
}
}

ActionReport report = context.getActionReport();
private void restartCluster(AdminCommandContext context) {
Logger logger = context.getLogger();

logger.info(Strings.get("restart.cluster", clusterName));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,34 +37,33 @@
* only if the new code is made subject to such option by the copyright
* holder.
*/
// Portions Copyright [2018] [Payara Foundation and/or its affiliates]
// Portions Copyright [2018-2022] [Payara Foundation and/or its affiliates]

package com.sun.enterprise.v3.admin.cluster;

import com.sun.enterprise.admin.remote.RemoteRestAdminCommand;
import com.sun.enterprise.admin.remote.ServerRemoteRestAdminCommand;
import com.sun.enterprise.admin.util.*;
import com.sun.enterprise.config.serverbeans.Config;
import com.sun.enterprise.config.serverbeans.Domain;
import com.sun.enterprise.config.serverbeans.Node;
import com.sun.enterprise.config.serverbeans.Nodes;
import com.sun.enterprise.config.serverbeans.Server;
import com.sun.enterprise.admin.util.InstanceStateService;
import com.sun.enterprise.admin.util.RemoteInstanceCommandHelper;
import com.sun.enterprise.config.serverbeans.*;
import com.sun.enterprise.util.OS;
import com.sun.enterprise.util.ObjectAnalyzer;
import com.sun.enterprise.util.StringUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
import java.util.logging.Level;
import org.glassfish.api.*;
import org.glassfish.api.ActionReport;
import org.glassfish.api.I18n;
import org.glassfish.api.Param;
import org.glassfish.api.admin.*;

import org.jvnet.hk2.annotations.Service;
import org.glassfish.hk2.api.PerLookup;
import org.glassfish.hk2.api.ServiceLocator;
import org.jvnet.hk2.annotations.Service;

import javax.inject.Inject;
import javax.inject.Named;
import javax.validation.constraints.Min;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
*
Expand Down Expand Up @@ -115,10 +114,14 @@ public class RestartInstanceCommand implements AdminCommand {

@Param(name = "sync", optional = true, defaultValue = "normal", acceptableValues = "none, normal, full")
private String sync;
@Param(name="delay", optional = true, defaultValue = "0")

@Param(name = "delay", optional = true, defaultValue = "0")
private int delay;

@Min(message = "Timeout must be at least 1 second long.", value = 1)
@Param(optional = true, defaultValue = "600")
private int timeout;

private Logger logger;

private RemoteInstanceCommandHelper helper;
Expand All @@ -134,9 +137,7 @@ public class RestartInstanceCommand implements AdminCommand {
private String oldPid;

private AdminCommandContext context;

private static final long WAIT_TIME_MS = 600000; // 10 minutes


@Override
public void execute(AdminCommandContext ctx) {
try {
Expand Down Expand Up @@ -323,7 +324,7 @@ private void waitForRestart() {
if (isError())
return;

long deadline = System.currentTimeMillis() + WAIT_TIME_MS;
long deadline = System.currentTimeMillis() + (timeout * 1000);

while (System.currentTimeMillis() < deadline) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,26 @@
* only if the new code is made subject to such option by the copyright
* holder.
*/
// Portions Copyright [2018] [Payara Foundation and/or its affiliates]
// Portions Copyright [2018-2022] [Payara Foundation and/or its affiliates]
package com.sun.enterprise.v3.admin.cluster;

import com.sun.enterprise.config.serverbeans.Cluster;
import java.util.logging.Logger;

import org.glassfish.api.admin.*;
import javax.inject.Inject;


import org.jvnet.hk2.annotations.Service;
import org.glassfish.api.I18n;
import org.glassfish.api.Param;
import com.sun.enterprise.config.serverbeans.Domain;
import org.glassfish.api.ActionReport;
import org.glassfish.api.ActionReport.ExitCode;
import org.glassfish.api.I18n;
import org.glassfish.api.Param;
import org.glassfish.api.admin.*;
import org.glassfish.hk2.api.PerLookup;
import org.jvnet.hk2.annotations.Service;

import com.sun.enterprise.config.serverbeans.Domain;
import javax.inject.Inject;
import javax.validation.constraints.Min;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.logging.Logger;

@I18n("start.cluster.command")
@Service(name = "start-cluster")
Expand Down Expand Up @@ -87,11 +89,34 @@ public class StartClusterCommand implements AdminCommand {

@Param(optional = true, defaultValue = "false")
private boolean verbose;


@Min(message = "Timeout must be at least 1 second long.", value = 1)
@Param(optional = true, defaultValue = "600")
private int timeout;

private ActionReport report;

@Override
public void execute(AdminCommandContext context) {

ActionReport report = context.getActionReport();
report = context.getActionReport();
CompletableFuture<Void> future = CompletableFuture.runAsync(() -> startCluster(context));

try {
future.get(timeout, TimeUnit.SECONDS);
} catch (InterruptedException | ExecutionException e) {
// Do Nothing
} catch (TimeoutException e) {
//Time has exceeded timeout value.
String msg = Strings.get("start.cluster.timeout", clusterName);
report.setActionExitCode(ExitCode.FAILURE);
report.setMessage(msg);
} finally {
future.cancel(true);
return;
}
}

private void startCluster(AdminCommandContext context) {
Logger logger = context.getLogger();

logger.info(Strings.get("start.cluster", clusterName));
Expand All @@ -107,12 +132,12 @@ public void execute(AdminCommandContext context) {

ClusterCommandHelper clusterHelper = new ClusterCommandHelper(domain,
runner);

try {
// Run start-instance against each instance in the cluster
String commandName = "start-instance";
String commandName = "start-instance";
clusterHelper.runCommand(commandName, null, clusterName, context,
verbose);
verbose);
}
catch (CommandException e) {
String msg = e.getLocalizedMessage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,27 @@
* holder.
*/

// Portions Copyright [2018] [Payara Foundation and/or its affiliates]
// Portions Copyright [2018-2022] [Payara Foundation and/or its affiliates]

package com.sun.enterprise.v3.admin.cluster;

import com.sun.enterprise.config.serverbeans.Cluster;
import java.util.logging.Logger;
import javax.inject.Inject;


import org.jvnet.hk2.annotations.Service;
import org.glassfish.api.I18n;
import org.glassfish.api.Param;
import com.sun.enterprise.config.serverbeans.Domain;
import org.glassfish.api.ActionReport;
import org.glassfish.api.ActionReport.ExitCode;
import com.sun.enterprise.config.serverbeans.Domain;
import org.glassfish.api.I18n;
import org.glassfish.api.Param;
import org.glassfish.api.admin.*;
import org.glassfish.hk2.api.PerLookup;
import org.jvnet.hk2.annotations.Service;

import javax.inject.Inject;
import javax.validation.constraints.Min;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.logging.Logger;

@I18n("stop.cluster.command")
@Service(name="stop-cluster")
Expand Down Expand Up @@ -89,16 +93,39 @@ public class StopClusterCommand implements AdminCommand {
@Param(optional = true, defaultValue = "false")
private boolean verbose;

@Min(message = "Timeout must be at least 1 second long.", value = 1)
@Param(optional = true, defaultValue = "600")
private int timeout;

private ActionReport report;

@Override
public void execute(AdminCommandContext context) {
report = context.getActionReport();
CompletableFuture<Void> future = CompletableFuture.runAsync(() -> stopCluster(context));

try {
future.get(timeout, TimeUnit.SECONDS);
} catch (InterruptedException | ExecutionException e) {
// Do Nothing
} catch (TimeoutException e) {
//Time has exceeded timeout value.
String msg = Strings.get("stop.cluster.timeout", clusterName);
report.setActionExitCode(ExitCode.FAILURE);
report.setMessage(msg);
} finally {
future.cancel(true);
return;
}
}

ActionReport report = context.getActionReport();
private void stopCluster(AdminCommandContext context) {
Logger logger = context.getLogger();

logger.info(Strings.get("stop.cluster", clusterName));

// Require that we be a DAS
if(!env.isDas()) {
if (!env.isDas()) {
String msg = Strings.get("cluster.command.notDas");
logger.warning(msg);
report.setActionExitCode(ExitCode.FAILURE);
Expand Down
Loading

0 comments on commit c6cfba2

Please sign in to comment.