Skip to content

Commit

Permalink
FISH-7454 Add timeout option for domain commands
Browse files Browse the repository at this point in the history
  • Loading branch information
kalinchan committed Oct 3, 2023
1 parent f4e93c7 commit e7e0716
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 12 deletions.
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 @@ -104,7 +104,7 @@ protected void doCommand()
else
cmd.executeAndReturnOutput("restart-domain");

waitForRestart(oldServerPid);
waitForRestart(oldServerPid, (super.getTimeout() * 1000));

logger.info(STRINGS.get("restartDomain.success"));
}
Expand Down Expand Up @@ -151,4 +151,6 @@ protected int dasNotRunning() throws CommandException {

return cmd.execute(opts.toArray(new String[opts.size()]));
}


}
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)
private 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 = "600")
private 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 @@ -253,12 +259,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 Expand Up @@ -286,4 +292,8 @@ protected int kill() throws CommandException {
}
return 0;
}

protected int getTimeout() {
return timeout;
}
}
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.

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.

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.

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

0 comments on commit e7e0716

Please sign in to comment.