Merge branch 'OS-rework' into 'master'
Rework and document OS class See merge request sheepitrenderfarm/client!255
This commit is contained in:
@@ -73,7 +73,7 @@ public class Linux extends OS {
|
||||
}
|
||||
|
||||
List<String> actual_command = command;
|
||||
if (checkNiceAvailability()) {
|
||||
if (isNiceAvailable()) {
|
||||
// launch the process in lowest priority
|
||||
if (env_overight != null) {
|
||||
actual_command.add(0, env_overight.get("PRIORITY"));
|
||||
@@ -109,7 +109,7 @@ public class Linux extends OS {
|
||||
);
|
||||
}
|
||||
|
||||
@Override public boolean getSupportHighPriority() {
|
||||
@Override public boolean isHighPrioritySupported() {
|
||||
try {
|
||||
ProcessBuilder builder = new ProcessBuilder();
|
||||
builder.command("bash", "-c", ID_COMMAND_INVOCATION);
|
||||
@@ -123,7 +123,7 @@ public class Linux extends OS {
|
||||
if ((userLevel = reader.readLine()) != null) {
|
||||
// Root user in *ix systems -independently of the alias used to login- has a id value of 0. On top of being a user with root capabilities,
|
||||
// to support changing the priority the nice tool must be accessible from the current user
|
||||
return (userLevel.equals("0")) & checkNiceAvailability();
|
||||
return (userLevel.equals("0")) & isNiceAvailable();
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
@@ -133,7 +133,7 @@ public class Linux extends OS {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override public boolean checkNiceAvailability() {
|
||||
@Override public boolean isNiceAvailable() {
|
||||
ProcessBuilder builder = new ProcessBuilder();
|
||||
builder.command(NICE_BINARY_PATH);
|
||||
builder.redirectErrorStream(true);
|
||||
|
||||
@@ -46,7 +46,7 @@ public class Mac extends OS {
|
||||
|
||||
@Override public Process exec(List<String> command, Map<String, String> env) throws IOException {
|
||||
List<String> actual_command = command;
|
||||
if (checkNiceAvailability()) {
|
||||
if (isNiceAvailable()) {
|
||||
// launch the process in lowest priority
|
||||
if (env != null) {
|
||||
actual_command.add(0, env.get("PRIORITY"));
|
||||
@@ -78,7 +78,7 @@ public class Mac extends OS {
|
||||
return "/usr/local/cuda/lib/libcuda.dylib";
|
||||
}
|
||||
|
||||
@Override public boolean getSupportHighPriority() {
|
||||
@Override public boolean isHighPrioritySupported() {
|
||||
try {
|
||||
ProcessBuilder builder = new ProcessBuilder();
|
||||
builder.command("bash", "-c", ID_COMMAND_INVOCATION);
|
||||
@@ -92,7 +92,7 @@ public class Mac extends OS {
|
||||
if ((userLevel = reader.readLine()) != null) {
|
||||
// Root user in *ix systems -independently of the alias used to login- has a id value of 0. On top of being a user with root capabilities,
|
||||
// to support changing the priority the nice tool must be accessible from the current user
|
||||
return (userLevel.equals("0")) & checkNiceAvailability();
|
||||
return (userLevel.equals("0")) & isNiceAvailable();
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
@@ -102,7 +102,7 @@ public class Mac extends OS {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override public boolean checkNiceAvailability() {
|
||||
@Override public boolean isNiceAvailable() {
|
||||
ProcessBuilder builder = new ProcessBuilder();
|
||||
builder.command(NICE_BINARY_PATH);
|
||||
builder.redirectErrorStream(true);
|
||||
|
||||
@@ -38,45 +38,90 @@ public abstract class OS {
|
||||
|
||||
private static OS instance = null;
|
||||
|
||||
/**
|
||||
* Operating system name
|
||||
* @return a string representing the OS name.
|
||||
*/
|
||||
public abstract String name();
|
||||
|
||||
/**
|
||||
* Blender requires 64 bits
|
||||
* @return boolean if we are supported i.e. if we run on 64 bits
|
||||
*/
|
||||
public boolean isSupported() { return "64bit".equals(getCPU().getArch()); }
|
||||
|
||||
/** Get the full version of the os.
|
||||
/** Get the full version of the operating system.
|
||||
* For example windows, should give "windows 8.1"
|
||||
* @return a lowercassed string with the os name and the version info
|
||||
* @see OperatingSystem#getVersionInfo()
|
||||
*/
|
||||
public String getVersion() {
|
||||
return (name() + " " + operatingSystem.getVersionInfo()).toLowerCase();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see oshi.hardware.GlobalMemory#getTotal()
|
||||
* @return long of getTotal() in kilobytes
|
||||
*/
|
||||
public long getTotalMemory() {
|
||||
return hardwareAbstractionLayer.getMemory().getTotal() / 1024;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see oshi.hardware.GlobalMemory#getAvailable()
|
||||
* @return long of getAvailable() in kilobytes
|
||||
*/
|
||||
public long getFreeMemory() {
|
||||
return hardwareAbstractionLayer.getMemory().getAvailable() / 1024;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the path to the Blender executable
|
||||
* @return a string representing a path to Blender,
|
||||
* relative or absolute depends on the implementation
|
||||
*/
|
||||
public abstract String getRenderBinaryPath();
|
||||
|
||||
/**
|
||||
* Get the path to the CUDA library
|
||||
* @return a string representing a path the CUDA library,
|
||||
* relative or absolute depends on the implementation
|
||||
*/
|
||||
public String getCUDALib() {
|
||||
return null;
|
||||
}
|
||||
|
||||
//path to NVIDIA NVML lib
|
||||
/**
|
||||
* Get the path to the NVIDIA NVML library
|
||||
* @return a string representing a path the NVIDIA NVML library,
|
||||
* relative or absolute depends on the implementation
|
||||
*/
|
||||
public String getNVMLLib() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public abstract boolean getSupportHighPriority();
|
||||
|
||||
public abstract boolean checkNiceAvailability();
|
||||
/**
|
||||
* Determines if the platform supports setting a higher priority
|
||||
* @return a boolean representing if the platform supports setting a higher priority
|
||||
*/
|
||||
public abstract boolean isHighPrioritySupported();
|
||||
|
||||
/**
|
||||
* Shutdown the computer waiting delayInMinutes minutes to allow all SheepIt threads to close and exit the app
|
||||
* Determines if the platform supports being IO nice
|
||||
* @return a boolean representing if the platform supports being IO nice
|
||||
*/
|
||||
public abstract boolean isNiceAvailable();
|
||||
|
||||
/**
|
||||
* Shuts the computer down waiting allow all SheepIt threads to close and exit
|
||||
* @param delayInMinutes integer repressing the amount minutes to wait before shutting down
|
||||
*/
|
||||
public abstract void shutdownComputer(int delayInMinutes);
|
||||
|
||||
/**
|
||||
* Creates and populates a CPU object
|
||||
* @return a populated CPU object
|
||||
*/
|
||||
public CPU getCPU() {
|
||||
CentralProcessor.ProcessorIdentifier cpuID = hardwareAbstractionLayer.getProcessor().getProcessorIdentifier();
|
||||
CPU ret = new CPU();
|
||||
@@ -86,15 +131,20 @@ public abstract class OS {
|
||||
return ret;
|
||||
}
|
||||
|
||||
public Process exec(List<String> command, Map<String, String> env) throws IOException {
|
||||
ProcessBuilder builder = new ProcessBuilder(command);
|
||||
builder.redirectErrorStream(true);
|
||||
if (env != null) {
|
||||
builder.environment().putAll(env);
|
||||
}
|
||||
return builder.start();
|
||||
}
|
||||
/**
|
||||
* Executes a Process
|
||||
* @param command List of strings of the command and the respective command line arguments
|
||||
* @param env Map of strings of environment variables and their values for the execution
|
||||
* @return a Process object reflecting the execution of the command
|
||||
* @throws IOException if an I/O error occurs
|
||||
*/
|
||||
public abstract Process exec(List<String> command, Map<String, String> env) throws IOException;
|
||||
|
||||
/**
|
||||
* Terminates a process
|
||||
* @param proc Process to kill
|
||||
* @return true if proc wasn't null and was destroyed
|
||||
*/
|
||||
public boolean kill(Process proc) {
|
||||
if (proc != null) {
|
||||
proc.destroy();
|
||||
@@ -103,6 +153,10 @@ public abstract class OS {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the operating system currently in use
|
||||
* @return object instance of OS specific to the used operating system.
|
||||
*/
|
||||
public static OS getOS() {
|
||||
if (instance == null) {
|
||||
switch (operatingSystem.getManufacturer()){
|
||||
@@ -110,7 +164,7 @@ public abstract class OS {
|
||||
instance = new Windows();
|
||||
break;
|
||||
case "Apple":
|
||||
if ("aarch64".equalsIgnoreCase(System.getProperty("os.arch"))) { // ARM arch ?
|
||||
if ("aarch64".equalsIgnoreCase(System.getProperty("os.arch"))) { // Set as M1 Mac if we are on ARM64
|
||||
instance = new MacM1();
|
||||
}
|
||||
else {
|
||||
@@ -124,7 +178,13 @@ public abstract class OS {
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the default path that SheepIt would place the config file
|
||||
* This respects the XDG specification for Linux and macOS
|
||||
* @see <a href="https://www.freedesktop.org/wiki/Software/xdg-user-dirs/">XDG specification</a>
|
||||
* @return string representing the default path to the sheepit.conf
|
||||
*/
|
||||
public String getDefaultConfigFilePath() {
|
||||
String xdgConfigHome = System.getenv("XDG_CONFIG_HOME");
|
||||
String userHome = System.getProperty("user.home");
|
||||
|
||||
@@ -179,11 +179,11 @@ public class Windows extends OS {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override public boolean getSupportHighPriority() {
|
||||
@Override public boolean isHighPrioritySupported() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override public boolean checkNiceAvailability() {
|
||||
@Override public boolean isNiceAvailable() {
|
||||
// In windows, nice is not required and therefore we return always true to show the slider in the Settings GUI
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -391,7 +391,7 @@ public class Settings implements Activity {
|
||||
// priority
|
||||
// ui display low -> high but the actual values are reversed
|
||||
// -19 is highest priority
|
||||
boolean high_priority_support = os.getSupportHighPriority();
|
||||
boolean high_priority_support = os.isHighPrioritySupported();
|
||||
priority = new JSlider(high_priority_support ? -19 : 0, 19);
|
||||
Hashtable<Integer, JLabel> labelTablePriority = new Hashtable<>();
|
||||
labelTablePriority.put(high_priority_support ? -19 : 0, new JLabel("Low"));
|
||||
@@ -417,7 +417,7 @@ public class Settings implements Activity {
|
||||
JLabel priorityLabel = new JLabel("Priority");
|
||||
priorityLabel.setToolTipText(SwingTooltips.PRIORITY.getText());
|
||||
|
||||
boolean showPrioritySlider = os.checkNiceAvailability();
|
||||
boolean showPrioritySlider = os.isNiceAvailable();
|
||||
priority.setVisible(showPrioritySlider);
|
||||
priorityLabel.setVisible(showPrioritySlider);
|
||||
|
||||
@@ -745,7 +745,7 @@ public class Settings implements Activity {
|
||||
// ui display low -> high but the actual values are reversed
|
||||
// -19 is highest priority
|
||||
OS os = OS.getOS();
|
||||
boolean high_priority_support = os.getSupportHighPriority();
|
||||
boolean high_priority_support = os.isHighPrioritySupported();
|
||||
if (high_priority_support) {
|
||||
// inverse
|
||||
config.setPriority(-1 * priority.getValue());
|
||||
|
||||
Reference in New Issue
Block a user