Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FISH-7454 Add timeout option for domain commands #6428

Merged
merged 4 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
* only if the new code is made subject to such option by the copyright
* holder.
*/
// Portions Copyright [2018-2021] Payara Foundation and/or affiliates
// Portions Copyright [2018-2023] Payara Foundation and/or affiliates

package com.sun.enterprise.admin.servermgmt.cli;

Expand Down Expand Up @@ -78,6 +78,9 @@ public class RestartDomainCommand extends StopDomainCommand {
@Param(name = "debug", optional = true)
private Boolean debug;

@Param(optional = true, defaultValue = "600")
protected int timeout;

@Inject
private ServiceLocator habitat;
private static final LocalStringsImpl STRINGS = new LocalStringsImpl(RestartDomainCommand.class);
Expand All @@ -98,13 +101,14 @@ protected void doCommand()
// run the remote restart-domain command and throw away the output
RemoteCLICommand cmd =
new RemoteCLICommand("restart-domain", programOpts, env);
cmd.setReadTimeout(timeout * 1000);

if (debug != null)
cmd.executeAndReturnOutput("restart-domain", "--debug", debug.toString());
else
cmd.executeAndReturnOutput("restart-domain");

waitForRestart(oldServerPid);
waitForRestart(oldServerPid, (timeout * 1000));

logger.info(STRINGS.get("restartDomain.success"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
* only if the new code is made subject to such option by the copyright
* holder.
*/
//Portions Copyright [2017-2021] Payara Foundation and/or affiliates
//Portions Copyright [2017-2023] Payara Foundation and/or affiliates

package com.sun.enterprise.admin.servermgmt.cli;

Expand All @@ -64,6 +64,8 @@
import com.sun.enterprise.universal.xml.MiniXmlParserException;
import org.glassfish.security.common.FileRealmStorageManager;

import static java.util.concurrent.TimeUnit.SECONDS;

/**
* The start-domain command.
*
Expand Down Expand Up @@ -95,6 +97,9 @@ public class StartDomainCommand extends LocalDomainCommand implements StartServe
private String preBootCommand;
@Param(name = "postbootcommandfile", optional = true)
private String postBootCommand;

@Param(defaultValue = "600", optional = true)
protected int timeout;

@Inject
ServerEnvironment senv;
Expand Down Expand Up @@ -132,6 +137,9 @@ protected void validate()
throw new CommandValidationException("postboot commands file does not exist: "+ postbootFile.getAbsolutePath());
}
}
if (timeout < 1) {
throw new CommandValidationException("Timeout must be at least 1 second long.");
}
super.validate();
}

Expand Down Expand Up @@ -206,7 +214,7 @@ protected int executeCommand() throws CommandException {

}
else {
helper.waitForServer();
helper.waitForServer(timeout, SECONDS);
helper.report();
return SUCCESS;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,10 @@
* only if the new code is made subject to such option by the copyright
* holder.
*
* Portions Copyright [2017-2021] [Payara Foundation and/or its affiliates]
* Portions Copyright [2017-2023] [Payara Foundation and/or its affiliates]
*/
package com.sun.enterprise.admin.servermgmt.cli;

import com.sun.enterprise.admin.cli.CLIConstants;
import com.sun.enterprise.admin.cli.remote.DASUtils;
import com.sun.enterprise.admin.cli.remote.RemoteCLICommand;
import com.sun.enterprise.universal.process.ProcessUtils;
Expand Down Expand Up @@ -77,12 +76,19 @@ public class StopDomainCommand extends LocalDomainCommand {
Boolean force;
@Param(optional = true, defaultValue = "false")
Boolean kill;
private static final long WAIT_FOR_DAS_TIME_MS = 60000; // 1 minute

@Param(optional = true, defaultValue = "60")
protected int timeout;

@Override
protected void validate()
throws CommandException {
setDomainName(userArgDomainName);

if (timeout < 1) {
throw new CommandValidationException("Timeout must be at least 1 second long.");
}

super.validate(); // which calls initDomain() !!
}

Expand Down Expand Up @@ -200,6 +206,7 @@ protected int dasNotRunning() throws CommandException {
protected void doCommand() throws CommandException {
// run the remote stop-domain command and throw away the output
RemoteCLICommand cmd = new RemoteCLICommand(getName(), programOpts, env);
cmd.setReadTimeout(timeout * 1000);
try {
cmd.executeAndReturnOutput("stop-domain", "--force", force.toString());
} catch (Exception e) {
Expand Down Expand Up @@ -253,12 +260,12 @@ protected void waitForDeath() throws CommandException {

if (alive) {
throw new CommandException(Strings.get("StopDomain.DASNotDead",
(WAIT_FOR_DAS_TIME_MS / 1000)));
timeout));
}
}

private boolean timedOut(long startTime) {
return (System.currentTimeMillis() - startTime) > WAIT_FOR_DAS_TIME_MS;
return (System.currentTimeMillis() - startTime) > (timeout * 1000);
}

protected int kill() throws CommandException {
Expand Down
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should command should have the same setup as the start-deployment-group and start-cluster commands where there are two timeout parameters:

  • timeout - overall timeout for the command
  • domainTimeout - timeout for each individual domain

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) [2017-2018] Payara Foundation and/or its affiliates. All rights reserved.
* Copyright (c) [2017-2023] Payara Foundation and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
Expand Down Expand Up @@ -65,6 +65,9 @@ public class RestartDomainsCommand extends RestartDomainCommand {
@Override
protected void validate()
throws CommandException, CommandValidationException {
if (timeout < 1) {
throw new CommandValidationException("Timeout must be at least 1 second long.");
}
}

@Override
Expand Down
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should command should have the same setup as the start-deployment-group and start-cluster commands where there are two timeout parameters:

  • timeout - overall timeout for the command
  • domainTimeout - timeout for each individual domain

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) [2017] Payara Foundation and/or its affiliates. All rights reserved.
* Copyright (c) [2017-2023] Payara Foundation and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
Expand Down Expand Up @@ -92,6 +92,10 @@ protected void validate()
throw new CommandValidationException("postboot commands file does not exist: "+ postbootFile.getAbsolutePath());
}
}

if (timeout < 1) {
throw new CommandValidationException("Timeout must be at least 1 second long.");
}
}

@Override
Expand Down
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should command should have the same setup as the stop-deployment-group and stop-cluster commands where there are two timeout parameters:

  • timeout - overall timeout for the command
  • domainTimeout - timeout for each individual domain

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) [2017-2018] Payara Foundation and/or its affiliates. All rights reserved.
* Copyright (c) [2017-2023] Payara Foundation and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
Expand Down Expand Up @@ -85,6 +85,9 @@ protected void prevalidate() throws CommandException {
protected void validate()
throws CommandException, CommandValidationException {
// no-op to prevent initDomain being called
if (timeout < 1) {
throw new CommandValidationException("Timeout must be at least 1 second long.");
}
}

@Override
Expand All @@ -95,7 +98,11 @@ protected int executeCommand() throws CommandException {
String[] domainsList = getDomains();
for (String domain : domainsList) {
setConfig(domain);
ParameterMap parameterMap = new ParameterMap();
parameterMap.insert("timeout", String.valueOf(timeout));
programOpts.updateOptions(parameterMap);
RemoteCLICommand cmd = new RemoteCLICommand("stop-domain", programOpts, env);
cmd.setReadTimeout(timeout * 1000);
logger.log(Level.FINE, "Stopping domain {0}", domain);
try {
cmd.executeAndReturnOutput("stop-domain", "--force", force.toString());
Expand Down
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should command should have the same setup as the stop-deployment-group and stop-cluster commands where there are two timeout parameters:

  • timeout - overall timeout for the command
  • domainTimeout - timeout for each individual domain

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) [2017-2018] Payara Foundation and/or its affiliates. All rights reserved.
*
*
* Copyright (c) [2017-2023] Payara Foundation and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
Expand Down Expand Up @@ -46,6 +46,7 @@
import org.glassfish.api.Param;
import org.glassfish.api.admin.CommandException;
import org.glassfish.api.admin.CommandValidationException;
import org.glassfish.api.admin.ParameterMap;
import org.glassfish.hk2.api.MultiException;
import org.glassfish.hk2.api.PerLookup;
import org.jvnet.hk2.annotations.Service;
Expand All @@ -71,6 +72,9 @@ public class StopDomainsCommand extends StopDomainCommand {
protected void validate()
throws CommandException, CommandValidationException {
// no-op to prevent initDomain being called
if (timeout < 1) {
throw new CommandValidationException("Timeout must be at least 1 second long.");
}
}

@Override
Expand All @@ -81,7 +85,11 @@ protected int executeCommand() throws CommandException {
String[] domains = userArgDomainName.split(",");
for (String domainName : domains) {
setConfig(domainName);
ParameterMap parameterMap = new ParameterMap();
parameterMap.insert("timeout", String.valueOf(timeout));
programOpts.updateOptions(parameterMap);
RemoteCLICommand cmd = new RemoteCLICommand("stop-domain", programOpts, env);
cmd.setReadTimeout(timeout * 1000);
logger.log(Level.FINE, "Stopping domain {0}", domainName);
try {
cmd.executeAndReturnOutput("stop-domain");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ SYNOPSIS
restart-domain [--help] [--debug ={true|false}]
[--domaindir domaindir]
[--force={true|false}] [--kill={false|true}]
[domain-name]
[--timeout timeout] [domain-name]

DESCRIPTION
The restart-domain subcommand stops and then restarts the domain
Expand Down Expand Up @@ -85,6 +85,10 @@ OPTIONS
The domain is killed. The subcommand uses functionality of the
operating system to terminate the domain process.

--timeout
Specifies the amount of time in seconds the command will run for
before timing out. Default is 600 seconds.

OPERANDS
domain-name
The name of the domain you want to restart. Default is the name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ SYNOPSIS
[--debug={true|false}] [--domaindir domain-dir]
[--dry-run={true|false}] [--upgrade={true|false}]
[--verbose={true|false}] [--watchdog={true|false}]
[domain-name]
[--timeout timeout] [domain-name]

DESCRIPTION
The start-domain subcommand starts the domain administration server
Expand Down Expand Up @@ -148,6 +148,10 @@ OPTIONS
Limited information is not displayed in the console window
(default).

--timeout
Specifies the amount of time in seconds the command will run for
before timing out. Default is 600 seconds.

OPERANDS
domain-name
The unique name of the domain you want to start.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ NAME
SYNOPSIS
stop-domain [--help] [--domaindir domaindir]
[--force={true|false}] [--kill={false|true}]
[domain-name]
[--timeout timeout][domain-name]

DESCRIPTION
The stop-domain subcommand stops the Domain Administration Server (DAS)
Expand Down Expand Up @@ -61,6 +61,10 @@ OPTIONS
The domain is killed. The subcommand uses functionality of the
operating system to terminate the domain process.

--timeout
Specifies the amount of time in seconds the command will run for
before timing out. Default is 60 seconds.

OPERANDS
domain-name
The name of the domain you want to stop. Default is the name
Expand Down