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

PAYARA-2113 Made stop-domain a little more descriptive #2169

Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -51,8 +51,8 @@
import com.sun.enterprise.util.io.DomainDirs;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.HashMap;
import java.util.Map;
import org.glassfish.api.Param;
import org.glassfish.api.admin.*;
import org.glassfish.hk2.api.PerLookup;
Expand All @@ -65,7 +65,7 @@
@PerLookup
public final class ListDomainsCommand extends LocalDomainCommand {

private static final LocalStringsImpl strings = new LocalStringsImpl(ListDomainsCommand.class);
private static final LocalStringsImpl Strings = new LocalStringsImpl(ListDomainsCommand.class);
Copy link
Contributor

Choose a reason for hiding this comment

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

This should follow naming conventions of all capitals

private String domainsRoot = null;

@Param(name = "long", shortName = "l", optional = true)
Expand Down Expand Up @@ -112,16 +112,23 @@ protected int executeCommand() throws CommandException, CommandValidationExcepti
}
}
} else {
logger.fine(strings.get("NoDomainsToList"));
logger.fine(Strings.get("NoDomainsToList"));
}
} catch (Exception ex) {
throw new CommandException(ex.getLocalizedMessage());
}
return 0;
}

protected List<String> getRunningDomains() throws IOException, DomainException, CommandException {
List<String> runningDomains = new ArrayList<>();
/**
* Get a list of domains and their status
* @return Map<String, Boolean> of domain and status
* @throws IOException
* @throws DomainException
* @throws CommandException
*/
protected Map<String, Boolean> getDomains() throws IOException, DomainException, CommandException {
Map<String, Boolean> runningDomains = new HashMap<>();
File domainsDirFile = ok(domainDirParam) ? new File(domainDirParam) : DomainDirs.getDefaultDomainsDir();

DomainConfig domainConfig = new DomainConfig(null, domainsDirFile.getAbsolutePath());
Expand All @@ -130,9 +137,7 @@ protected List<String> getRunningDomains() throws IOException, DomainException,
programOpts.setInteractive(false); // no prompting for passwords

for (String domain : domainsList) {
if (getStatus(domain).status) {
runningDomains.add(domain);
}
runningDomains.put(domain, getStatus(domain).status);
}
return runningDomains;
}
Expand All @@ -154,18 +159,18 @@ private DomainInfo getStatus(String dn) throws IOException, CommandException {
di.status = isThisDAS(getDomainRootDir());

if (di.status) {
di.statusMsg = strings.get("list.domains.StatusRunning", dn);
di.statusMsg = Strings.get("list.domains.StatusRunning", dn);
try {
RemoteCLICommand cmd = new RemoteCLICommand("_get-restart-required", programOpts, env);
String restartRequired = cmd.executeAndReturnOutput("_get-restart-required");
di.restartRequired = Boolean.parseBoolean(restartRequired.trim());
if (di.restartRequired) {
di.statusMsg = strings.get("list.domains.StatusRestartRequired", dn);
di.statusMsg = Strings.get("list.domains.StatusRestartRequired", dn);
}
} catch (Exception ex) {
}
} else {
di.statusMsg = strings.get("list.domains.StatusNotRunning", dn);
di.statusMsg = Strings.get("list.domains.StatusNotRunning", dn);
}
return di;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,7 @@ Domain.badDomainDir=CLI301: There is no such domain directory: {0}
Domain.noDomainXml=CLI304: Cannot find domain.xml. It should be here: {0}

## stop-domain command
StopDomain.dasNotRunning=CLI306: Warning - The server located at {0} is not running.\n\
Please specify one of the currently running domains:\n\
{1}
StopDomain.dasNotRunning=CLI306: Warning - The server located at {0} is not running.{1}
StopDomain.dasNotRunningRemotely=CLI307: Warning - remote server is not running, unable to force it to stop.\n\
Try running stop-domain on the remote server.
StopDomain.WaitDASDeath=Waiting for the domain to stop
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import com.sun.enterprise.universal.process.ProcessUtils;
import com.sun.enterprise.util.io.FileUtils;
import java.io.File;
import java.util.Map;
import javax.inject.Inject;
import org.glassfish.api.Param;
import org.glassfish.api.admin.*;
Expand Down Expand Up @@ -170,11 +171,18 @@ protected int dasNotRunning() throws CommandException {
ListDomainsCommand listDomains = serviceLocator.getService(ListDomainsCommand.class);
String runningDomains = "";
try {
for (String domain : listDomains.getRunningDomains()) {
runningDomains = runningDomains + domain + "\n";
Map<String, Boolean> domains = listDomains.getDomains();
for (String domain : domains.keySet()) {
if (domains.get(domain)) {
runningDomains += "\n" + domain;
}
}
} catch(Exception e) {
}
runningDomains =
(runningDomains.length() < 1)
? "\nNo domains are currently running."
Copy link
Contributor

Choose a reason for hiding this comment

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

I like this change, but could it be implemented using a different message name in the LocalString.properties?

: "\nPlease specify one of the currently running domains:" + runningDomains;
logger.warning(Strings.get("StopDomain.dasNotRunning", getDomainRootDir(), runningDomains));
} else {
logger.warning(Strings.get("StopDomain.dasNotRunningRemotely"));
Expand Down