Skip to content
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
4 changes: 2 additions & 2 deletions core/src/main/groovy/noe/common/newcmd/KillCmdBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ public KillCmdBuilder addProcessId(final String... processIds) {
* @param processIds process ids to kill as integer
* @return this
*/
public KillCmdBuilder addProcessId(final int... processIds) {
for(int processId: processIds) {
public KillCmdBuilder addProcessId(final long... processIds) {
for(long processId: processIds) {
String stringProcessId = String.valueOf(processId);
addProcessId(stringProcessId);
}
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/groovy/noe/common/newcmd/ListProcess.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public Collection<Integer> listParentPids(final int processId) throws IOExceptio
* @return list of map where information about processes in the tree is saved
* @throws IOException when not possible to run the process list command
*/
public List<Map<PsCmdFormat, String>> listProcessTree(final int processId) throws IOException {
public List<Map<PsCmdFormat, String>> listProcessTree(final long processId) throws IOException {
ListProcessData data = listAll(PsCmdFormat.PROCESS_ID, PsCmdFormat.PARENT_PROCESS_ID, PsCmdFormat.COMMAND);

ImmutableList.Builder<Map<PsCmdFormat, String>> psTreeBuilder = ImmutableList.<Map<PsCmdFormat, String>>builder();
Expand All @@ -196,7 +196,7 @@ public List<Map<PsCmdFormat, String>> listProcessTree(final int processId) throw

List<String> listOfIdsToCheck = new ArrayList<String>();
List<String> listOfIdsInProgress = new ArrayList<String>();
listOfIdsToCheck.add(Integer.toString(processId));
listOfIdsToCheck.add(Long.toString(processId));

// passing through ps results to get all the process three (filter returns filtered copy of data)
while (!listOfIdsToCheck.isEmpty()) {
Expand Down Expand Up @@ -246,7 +246,7 @@ public ListProcessData listProcessInfo(final int processId) throws IOException {
* @return process info
* @throws IOException when some error on execution happens
*/
public String printProcessInfo(final int processId) throws IOException, InterruptedException {
public String printProcessInfo(final long processId) throws IOException, InterruptedException {
CmdBuilder<SimpleCmdBuilder> builder = new CmdBuilder<SimpleCmdBuilder>("");
if (platform.isWindows()) {
builder.setBaseCommand("wmic");
Expand Down
29 changes: 25 additions & 4 deletions core/src/main/groovy/noe/common/newcmd/ListProcessData.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public int size() {
* @param processId process id that should be search in data
* @return info on data
*/
public Map<PsCmdFormat,String> get(final int processId) {
public Map<PsCmdFormat,String> get(final long processId) {
String processIdAsString = String.valueOf(processId);
if(listing.get(processIdAsString) == null) {
return null;
Expand Down Expand Up @@ -328,15 +328,36 @@ public int compare(final Map<PsCmdFormat, String> left, final Map<PsCmdFormat, S
int2 = Integer.valueOf(str2);
} catch (NumberFormatException nfe) {
// if string from left is not possible to convert to int
// then in case of right is not possible to convert do string comparision
// otherwise left was possible to convert but right is not posible to convert (returns 1)
// then in case of right is not possible to convert do string comparison
// otherwise left was possible to convert but right is not possible to convert (returns 1)
return int1error ? str1.compareTo(str2) : 1;
}
// if string from left is not possible to convert to int
// then we know that right was converted fine and we return -1
// otherwise both were converted without problem and returning integer comparision
// otherwise both were converted without problem and returning integer comparison
return int1error ? -1 : int1.compareTo(int2);
}
if(dataType.isInstance(Long.valueOf(0))) {
boolean long1error = false;
Long long1 = null, long2 = null;
try {
long1 = Long.valueOf(str1);
} catch (NumberFormatException nfe) {
long1error = true;
}
try {
long2 = Long.valueOf(str2);
} catch (NumberFormatException nfe) {
// if string from left is not possible to convert to long
// then in case of right is not possible to convert do string comparison
// otherwise left was possible to convert but right is not possible to convert (returns 1)
return long1error ? str1.compareTo(str2) : 1;
}
// if string from left is not possible to convert to long
// then we know that right was converted fine and we return -1
// otherwise both were converted without problem and returning integer comparison
return long1error ? -1 : long1.compareTo(long2);
}
return str1.compareTo(str2);
}
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/groovy/noe/common/newcmd/PsCmdFormat.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ public enum PsCmdFormat {
/**
* Id of process.
*/
PROCESS_ID(false, Integer.class),
PROCESS_ID(false, Long.class),
/**
* Pid of process parent.
*/
PARENT_PROCESS_ID(false, Integer.class),
PARENT_PROCESS_ID(false, Long.class),
/**
* Priority (nice) of the process.
*/
Expand Down
56 changes: 28 additions & 28 deletions core/src/main/groovy/noe/common/utils/Cmd.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ public class Cmd {
* @param id ... unique identificator of the java process
* @return pid of the java process or null if such process isn't found
*/
static Integer getJavaPid(String id) {
static Long getJavaPid(String id) {
if (!platform.isWindows()) {
def p
def jps = DefaultProperties.JAVA_HOME + "${platform.sep}bin${platform.sep}jps"
Expand All @@ -465,7 +465,7 @@ public class Cmd {
}
String o = t.nextElement()
// expects format pid ....
return Integer.valueOf(o)
return Long.valueOf(o)
}
}

Expand All @@ -475,7 +475,7 @@ public class Cmd {
* TODO variant only for PID
*
*/
static int kill(Integer pid, winappname) {
static int kill(Long pid, winappname) {
log.debug("Forcibly killing process with PID=${pid}, Window title=${winappname}")
// TODO: Get rid of black magic :-(
if (platform.isRHEL()) {
Expand All @@ -495,7 +495,7 @@ public class Cmd {
* returns kill process exit code. If PID is not defined on non-windows platform, -1 is returned
* TODO: properly implement it for Unix/Linux systems as pkill -P kills only processes with given parent PID, it doesn't go recursively killing from bottom to top
*/
static int killTree(Integer pid, winappname) {
static int killTree(Long pid, winappname) {
if (platform.isWindows()) {
if (pid != null) {
log.debug("killtree(): MS Windows taskkill command: taskkill /PID ${pid} /f /t")
Expand Down Expand Up @@ -564,7 +564,7 @@ public class Cmd {
log.debug("Process {} is already dead", process)
return false
}
int pid = ProcessUtils.getProcessId(process)
long pid = ProcessUtils.getProcessId(process)
if (pid == ProcessUtils.UNDEFINED_PROCESS_ID) {
log.warn("Failed to extract pid from process")
return false
Expand All @@ -573,7 +573,7 @@ public class Cmd {
return destroyProcessWithTree(pid)
}

private static synchronized boolean destroyProcessWithTree(final Integer pid) {
private static synchronized boolean destroyProcessWithTree(final Long pid) {
// getting tree of processes running under launched cmd
ListProcess listProcessUtil = new ListProcess();
List<Map<PsCmdFormat, String>> processTree = listProcessUtil.listProcessTree(pid);
Expand All @@ -594,10 +594,10 @@ public class Cmd {
killBuilder.addProcessId(pid);
return Cmd.executeCommand(killBuilder.build().getCommandLine(), new File(".")) != null
} else {
int[] processTreePidArray = new int[processTree.size()];
long[] processTreePidArray = new long[processTree.size()];
int i = 0;
for(Map<PsCmdFormat, String> processTreeRecord: processTree) {
processTreePidArray[i++] = Integer.valueOf(processTreeRecord.get(PsCmdFormat.PROCESS_ID));
processTreePidArray[i++] = Long.valueOf(processTreeRecord.get(PsCmdFormat.PROCESS_ID));
}
log.debug("*nix platform: destroying process tree of {} as list of pids {}",
pid, processTreePidArray);
Expand Down Expand Up @@ -742,16 +742,16 @@ public class Cmd {
}


static Set<Integer> retrievePidsByRegexpFromProcOutput(Process proc, regexp) {
Set<Integer> pids = new HashSet<>()
static Set<Long> retrievePidsByRegexpFromProcOutput(Process proc, regexp) {
Set<Long> pids = new HashSet<>()

proc.in.eachLine { line ->
log.debug("Found process to matching ${regexp}: ${line}")
def match = line =~ regexp
if (match.groupCount() > 0 && match.size() > 0 && match[0].size() > 0) {
String pid = match[0][1]
try {
pids.add(Integer.parseInt(pid))
pids.add(Long.parseLong(pid))
} catch (NumberFormatException ex) {
log.debug("We don't care that line contained an invalid processCode to parse: ${pid}. Continuing...")
}
Expand All @@ -761,9 +761,9 @@ public class Cmd {
}


static Integer extractPid(identifier) {
static Long extractPid(identifier) {
log.debug("Extracting pid using identifier ${identifier}")
List<Integer> pids = extractPids(identifier, false)
List<Long> pids = extractPids(identifier, false)
if (pids.isEmpty()) {
return null
}
Expand All @@ -788,8 +788,8 @@ public class Cmd {
}
}

static List<Integer> extractUNIXPids(identifier, getAll = true) {
List<Integer> pids = []
static List<Long> extractUNIXPids(identifier, getAll = true) {
List<Long> pids = []
final String ALL_FAILED = "All pid extraction options have failed, including the last resort 'pargs' one. This means that the application the pid of which we were trying to" +
"extract hadn't been started in a supported way. Hint: domain.sh? any custom launch script?"
/**
Expand Down Expand Up @@ -841,7 +841,7 @@ public class Cmd {
/**
* Now, we will collect all java processes.
*/
List<Integer> javaPids = []
List<Long> javaPids = []
proc2.in.eachLine { line ->
def match = line =~ psRegExp
log.trace("Java processes match.groupCount(): ${match.groupCount()}")
Expand All @@ -852,7 +852,7 @@ public class Cmd {
}
String pid = match[0][1]
try {
javaPids.add(Integer.parseInt(pid))
javaPids.add(Long.parseLong(pid))
} catch (NumberFormatException ex) {
log.error("Error trying to parse process ID from: \"${pid}\"")
throw ex
Expand Down Expand Up @@ -896,7 +896,7 @@ public class Cmd {
log.trace("1) match proc4.text: ${line}")
String pid = match[0][1]
try {
pids.add(Integer.parseInt(pid))
pids.add(Long.parseLong(pid))
} catch (NumberFormatException ex) {
log.error("Error trying to parse process ID from: \"${pid}\"")
throw ex
Expand All @@ -906,8 +906,8 @@ public class Cmd {
return pids
}

static List<Integer> extractWindowsPids(identifier, getAll = true) {
List<Integer> pids = []
static List<Long> extractWindowsPids(identifier, getAll = true) {
List<Long> pids = []

/**
* WINDOWS STUFF
Expand Down Expand Up @@ -952,7 +952,7 @@ public class Cmd {
if (match.size() > 0 && match[0].size() >= 2 && possibleWindowTitlesIds.any { it == match[0][2]}) {
String pid = match[0][1]
try {
pids.add(Integer.parseInt(pid))
pids.add(Long.parseLong(pid))
} catch (NumberFormatException ex) {
log.error("Error trying to parse process ID from: \"${pid}\"")
throw ex
Expand All @@ -968,7 +968,7 @@ public class Cmd {
return pids
}

static boolean killSpecifiedProcesses(Collection<Integer> pidList = []) {
static boolean killSpecifiedProcesses(Collection<Long> pidList = []) {
if (!pidList) {
log.debug("No process IDs given => nothing to kill")
return false
Expand Down Expand Up @@ -1012,7 +1012,7 @@ public class Cmd {
/**
* Wait until is PID removed from system - at max. timeout
*/
static boolean waitForPidRemoved(Integer pid, int timeout = 30) {
static boolean waitForPidRemoved(Long pid, int timeout = 30) {
if (!pid) return true
int now = 0

Expand All @@ -1036,11 +1036,11 @@ public class Cmd {
/**
* Check if PID exists in a system - process is present in system
*/
static boolean pidExists(Integer pid) {
static boolean pidExists(Long pid) {
def res = false

try {
res = getPidList().contains(Integer.valueOf(pid))
res = getPidList().contains(pid)
}
catch (e) {
}
Expand All @@ -1054,7 +1054,7 @@ public class Cmd {
*
* @return true if none of the pids provided exist in the system, false otherwise
*/
static boolean waitForPidsRemoved(List<Integer> pids, int timeout, TimeUnit timeUnit) {
static boolean waitForPidsRemoved(List<Long> pids, int timeout, TimeUnit timeUnit) {
long maxTime = System.currentTimeMillis() + timeUnit.toMillis(timeout)
boolean anyPidExist = !getPidList().intersect(pids).isEmpty()
while (anyPidExist && System.currentTimeMillis() <= maxTime) {
Expand Down Expand Up @@ -1096,7 +1096,7 @@ public class Cmd {
/**
* Extract all PIDS from the underlying system
*/
static List<Integer> getPidList() {
static List<Long> getPidList() {
def res = []
def row = []
def command
Expand All @@ -1118,7 +1118,7 @@ public class Cmd {
else row = line.split() as List

// on all tested system is PID in 2nd col
if (!row[1].contains("PID")) res << Integer.parseInt(row[1].replaceAll('"', ''))
if (!row[1].contains("PID")) res << Long.parseLong(row[1].replaceAll('"', ''))
}

return res
Expand Down
Loading