Skip to content

Commit

Permalink
Unused waitForReaderThreads removed
Browse files Browse the repository at this point in the history
- it was an old hack for windows to avoid an old fixed bug (issue numbers lost)

Signed-off-by: David Matějček <david.matejcek@omnifish.ee>
  • Loading branch information
dmatej committed Jun 11, 2023
1 parent 96ec5e5 commit 6e50598
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 92 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (c) 2023 Contributors to the Eclipse Foundation
* Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand All @@ -25,15 +26,6 @@
import com.sun.enterprise.util.StringUtils;
import com.sun.enterprise.util.cluster.RemoteType;
import com.sun.enterprise.util.net.NetUtils;
import org.glassfish.api.ActionReport;
import org.glassfish.api.admin.AdminCommandContext;
import org.glassfish.api.admin.CommandValidationException;
import org.glassfish.api.admin.ParameterMap;
import org.glassfish.api.admin.SSHCommandExecutionException;
import org.glassfish.cluster.ssh.connect.NodeRunner;
import org.glassfish.cluster.ssh.launcher.SSHLauncher;
import org.glassfish.hk2.api.ServiceLocator;
import org.glassfish.internal.api.RelativePathResolver;

import java.io.File;
import java.io.FileNotFoundException;
Expand All @@ -46,6 +38,16 @@
import java.util.Map;
import java.util.logging.Logger;

import org.glassfish.api.ActionReport;
import org.glassfish.api.admin.AdminCommandContext;
import org.glassfish.api.admin.CommandValidationException;
import org.glassfish.api.admin.ParameterMap;
import org.glassfish.api.admin.SSHCommandExecutionException;
import org.glassfish.cluster.ssh.connect.NodeRunner;
import org.glassfish.cluster.ssh.launcher.SSHLauncher;
import org.glassfish.hk2.api.ServiceLocator;
import org.glassfish.internal.api.RelativePathResolver;

/**
* Utility methods for operating on Nodes
*
Expand All @@ -71,7 +73,7 @@ public class NodeUtils {
static final String PARAM_INSTALL = "install";
public static final String PARAM_WINDOWS_DOMAIN = "windowsdomain";
static final String LANDMARK_FILE = "glassfish/modules/admin-cli.jar";
private static final String NL = System.getProperty("line.separator");
private static final String NL = System.lineSeparator();
private TokenResolver resolver = null;
private Logger logger = null;
private ServiceLocator habitat = null;
Expand All @@ -89,8 +91,9 @@ public class NodeUtils {
}

static boolean isSSHNode(Node node) {
if (node == null)
if (node == null) {
return false;
}
return node.getType().equals("SSH");
}

Expand All @@ -100,10 +103,11 @@ static boolean isSSHNode(Node node) {
* @return version string
*/
String getGlassFishVersionOnNode(Node node, AdminCommandContext context) throws CommandValidationException {
if (node == null)
if (node == null) {
return "";
}

List<String> command = new ArrayList<String>();
List<String> command = new ArrayList<>();
command.add("version");
command.add("--local");
command.add("--terse");
Expand Down Expand Up @@ -170,8 +174,9 @@ private void validateRemote(ParameterMap map, String nodehost) throws
// guaranteed to either get a valid type -- or a CommandValidationException
RemoteType type = parseType(map);

if (type == RemoteType.SSH)
if (type == RemoteType.SSH) {
validateSsh(map, nodehost);
}

// bn: shouldn't this be something more sophisticated than just the standard string?!?
// i.e. check to see if the hostname is this machine?
Expand All @@ -181,8 +186,9 @@ private void validateRemote(ParameterMap map, String nodehost) throws
}

// BN says: Shouldn't this be a fatal error?!? TODO
if (sshL == null)
if (sshL == null) {
return;
}

validateRemoteConnection(map);
}
Expand Down Expand Up @@ -314,8 +320,9 @@ private void validateRemoteConnection(ParameterMap map) throws
RemoteType type = parseType(map);

// just too difficult to refactor now...
if (type == RemoteType.SSH)
if (type == RemoteType.SSH) {
validateSSHConnection(map);
}
}

private void validateSSHConnection(ParameterMap map) throws
Expand Down Expand Up @@ -444,8 +451,7 @@ void runAdminCommandOnNode(Node node, List<String> command,

NodeRunner nr = new NodeRunner(habitat, logger);
try {
int status = nr.runAdminCommandOnNode(node, output, waitForReaderThreads,
command, context);
int status = nr.runAdminCommandOnNode(node, output, command, context);
if (status != 0) {
// Command ran, but didn't succeed. Log full information
msg2 = Strings.get("node.command.failed", nodeName,
Expand Down Expand Up @@ -502,8 +508,7 @@ void runAdminCommandOnNode(Node node, List<String> command,
AdminCommandContext context, String firstErrorMessage,
String humanCommand, StringBuilder output) {

runAdminCommandOnNode(node, command, context, firstErrorMessage,
humanCommand, output, true);
runAdminCommandOnNode(node, command, context, firstErrorMessage, humanCommand, output);
}

private RemoteType parseType(ParameterMap map) throws CommandValidationException {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (c) 2023 Contributors to the Eclipse Foundation
* Copyright (c) 2008, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand All @@ -16,32 +17,36 @@

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

import com.sun.enterprise.config.serverbeans.*;
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.config.serverbeans.Servers;
import com.sun.enterprise.util.StringUtils;
import java.util.logging.Logger;

import com.sun.enterprise.util.SystemPropertyConstants;
import com.sun.enterprise.util.OS;
import org.glassfish.api.ActionReport;
import org.glassfish.api.I18n;
import org.glassfish.api.Param;
import org.glassfish.api.admin.*;
import jakarta.inject.Inject;

import org.jvnet.hk2.annotations.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;

import org.glassfish.api.ActionReport;
import org.glassfish.api.I18n;
import org.glassfish.api.Param;
import org.glassfish.api.admin.AdminCommand;
import org.glassfish.api.admin.AdminCommandContext;
import org.glassfish.api.admin.CommandLock;
import org.glassfish.api.admin.RestEndpoint;
import org.glassfish.api.admin.RestEndpoints;
import org.glassfish.api.admin.RestParam;
import org.glassfish.api.admin.ServerEnvironment;
import org.glassfish.hk2.api.PerLookup;
import org.glassfish.hk2.api.ServiceLocator;

import com.sun.enterprise.config.serverbeans.Node;
import org.jvnet.hk2.annotations.Service;


/**
* AdminCommand to start the instance
* server.
* AdminCommand to start the instance server.
* <p>
* If this is DAS -- we call the instance
* If this is an instance we start it
*
Expand Down Expand Up @@ -77,7 +82,7 @@ public class StartInstanceCommand implements AdminCommand {
private String instanceName;

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

@Param(optional = true, defaultValue = "false")
private boolean debug;
Expand All @@ -96,7 +101,7 @@ public class StartInstanceCommand implements AdminCommand {
private String nodeHost;
private Server instance;

private static final String NL = System.getProperty("line.separator");
private static final String NL = System.lineSeparator();

/**
* restart-instance needs to try to start the instance from scratch if it is not
Expand Down Expand Up @@ -196,7 +201,7 @@ public void execute(AdminCommandContext ctx) {

private void startInstance(AdminCommandContext ctx) {
NodeUtils nodeUtils = new NodeUtils(habitat, logger);
ArrayList<String> command = new ArrayList<String>();
ArrayList<String> command = new ArrayList<>();
String humanCommand = null;

command.add("start-local-instance");
Expand Down Expand Up @@ -228,16 +233,8 @@ private void startInstance(AdminCommandContext ctx) {

StringBuilder output = new StringBuilder();

// There is a problem on Windows waiting for IO to complete on a
// child process which runs a long running grandchild. See IT 12777.
boolean waitForReaderThreads = true;
if (OS.isWindows()) {
waitForReaderThreads = false;
}

// Run the command on the node and handle errors.
nodeUtils.runAdminCommandOnNode(node, command, ctx, firstErrorMessage,
humanCommand, output, waitForReaderThreads);
nodeUtils.runAdminCommandOnNode(node, command, ctx, firstErrorMessage, humanCommand, output);

ActionReport report = ctx.getActionReport();
if (report.getActionExitCode() == ActionReport.ExitCode.SUCCESS) {
Expand All @@ -257,8 +254,9 @@ private String pollForLife(Server instance) {
int counter = 0; // 120 seconds

while (++counter < 240) {
if (instance.isRunning())
if (instance.isRunning()) {
return null;
}

try {
Thread.sleep(500);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Contributors to the Eclipse Foundation
* Copyright (c) 2022, 2023 Contributors to the Eclipse Foundation
* Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -100,18 +100,6 @@ public int runAdminCommandOnNode(Node node, StringBuilder output,
UnsupportedOperationException,
IllegalArgumentException {

return runAdminCommandOnNode(node, output, false, args, context);
}

public int runAdminCommandOnNode(Node node, StringBuilder output,
boolean waitForReaderThreads,
List<String> args,
AdminCommandContext context) throws
SSHCommandExecutionException,
ProcessManagerException,
UnsupportedOperationException,
IllegalArgumentException {


if (node == null) {
throw new IllegalArgumentException("Node is null");
Expand All @@ -123,16 +111,13 @@ public int runAdminCommandOnNode(Node node, StringBuilder output,
args.add(0, "--interactive=false"); // No prompting!

if (node.isLocal()) {
return runAdminCommandOnLocalNode(node, output, waitForReaderThreads,
args, stdinLines);
}
else {
return runAdminCommandOnLocalNode(node, output, args, stdinLines);
} else {
return runAdminCommandOnRemoteNode(node, output, args, stdinLines);
}
}

private int runAdminCommandOnLocalNode(Node node, StringBuilder output,
boolean waitForReaderThreads,
List<String> args,
List<String> stdinLines) throws
ProcessManagerException {
Expand All @@ -159,8 +144,6 @@ private int runAdminCommandOnLocalNode(Node node, StringBuilder output,
ProcessManager pm = new ProcessManager(fullcommand);
pm.setStdinLines(stdinLines);

// XXX should not need this after fix for 12777, but we seem to
pm.waitForReaderThreads(waitForReaderThreads);
int exitValue = pm.execute(); // blocks until command is complete

String stdout = pm.getStdout();
Expand Down Expand Up @@ -214,22 +197,4 @@ private String commandListToString(List<String> command) {

return fullCommand.toString();
}

/* hack TODO do not know how to get int status back from Windows
*/
private int determineStatus(List<String> args, StringBuilder output) {
if (isDeleteFS(args) && output.toString().indexOf("UTIL6046") >= 0) {
return 1;
}
return 0;
}

private boolean isDeleteFS(List<String> args) {
for (String arg : args) {
if ("_delete-instance-filesystem".equals(arg)) {
return true;
}
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@


/**
* ProcessManager.java
* Use this class for painless process spawning.
* <p>
* This class was originally written to be compatible with JDK 1.4, using Runtime.exec(),
* but has been refactored to use ProcessBuilder for better control and configurability.
*
Expand All @@ -50,7 +50,6 @@ public class ProcessManager {
private int timeout;
private boolean echo = true;
private String[] stdinLines;
private boolean waitForReaderThreads = true;

public ProcessManager(String... cmds) {
builder = new ProcessBuilder(cmds);
Expand Down Expand Up @@ -84,12 +83,9 @@ public void setStdinLines(List<String> list) {
}
}

public void waitForReaderThreads(boolean b) {
waitForReaderThreads = b;
}


/** Should the output of the process be echoed to stdout?
/**
* Should the output of the process be echoed to stdout?
*
* @param newEcho
*/
Expand Down

0 comments on commit 6e50598

Please sign in to comment.