2014-11-20 13:21:19 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2010-2014 Laurent CLOUET
|
|
|
|
|
* Author Laurent CLOUET <laurent.clouet@nopnop.net>
|
|
|
|
|
*
|
2020-05-28 13:28:42 +02:00
|
|
|
* This program is free software; you can redistribute it and/or
|
2014-11-20 13:21:19 +00:00
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
|
* as published by the Free Software Foundation; version 2
|
|
|
|
|
* of the License.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
*/
|
|
|
|
|
|
2024-12-14 13:54:56 +00:00
|
|
|
package com.sheepit.client.config;
|
2014-11-20 13:21:19 +00:00
|
|
|
|
|
|
|
|
import java.io.BufferedReader;
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
import java.io.InputStreamReader;
|
2017-05-08 01:35:08 +02:00
|
|
|
import java.net.InetAddress;
|
|
|
|
|
import java.net.UnknownHostException;
|
2014-11-20 13:21:19 +00:00
|
|
|
import java.util.Calendar;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
2024-12-14 13:54:56 +00:00
|
|
|
import com.sheepit.client.Client;
|
2014-12-17 21:47:31 +00:00
|
|
|
import com.sheepit.client.hardware.cpu.CPU;
|
2014-11-20 13:21:19 +00:00
|
|
|
import com.sheepit.client.hardware.gpu.GPUDevice;
|
2014-12-17 21:47:31 +00:00
|
|
|
import com.sheepit.client.os.OS;
|
2024-12-14 13:54:56 +00:00
|
|
|
import com.sheepit.client.utils.Pair;
|
2021-07-16 23:37:24 +00:00
|
|
|
import lombok.AllArgsConstructor;
|
2019-08-07 22:17:59 +02:00
|
|
|
import lombok.Data;
|
2014-11-20 13:21:19 +00:00
|
|
|
|
2023-10-19 10:33:48 +00:00
|
|
|
/**
|
|
|
|
|
* Provides facilities regarding the configuration of the SheepIt client
|
|
|
|
|
*/
|
2021-07-16 23:37:24 +00:00
|
|
|
@AllArgsConstructor
|
2020-05-28 13:28:42 +02:00
|
|
|
@Data public class Configuration {
|
2024-10-31 13:30:37 +00:00
|
|
|
public static final String WORKING_DIRNAME = "sheepit";
|
|
|
|
|
public static final String WOOL_CACHE_DIRNAME = "sheepit_wool_cache";
|
2021-07-07 16:18:45 +00:00
|
|
|
|
2021-12-30 17:46:20 +00:00
|
|
|
public static final String jarVersion = getJarVersion();
|
|
|
|
|
|
2014-11-20 13:21:19 +00:00
|
|
|
public enum ComputeType {
|
2015-04-07 20:05:48 +01:00
|
|
|
CPU_GPU, CPU, GPU
|
2015-01-25 18:26:21 +00:00
|
|
|
} // accept job for ...
|
2014-11-20 13:21:19 +00:00
|
|
|
|
2018-12-18 22:53:01 +01:00
|
|
|
private String configFilePath;
|
2024-04-14 09:27:52 +00:00
|
|
|
private String logDirectory;
|
2019-08-07 22:17:59 +02:00
|
|
|
private File workingDirectory;
|
2020-10-21 22:03:09 +11:00
|
|
|
private File sharedDownloadsDirectory;
|
2024-11-20 13:05:20 +00:00
|
|
|
private File woolCacheDirectory; // store all the chunks (project and blender)
|
2019-08-07 22:17:59 +02:00
|
|
|
private boolean userHasSpecifiedACacheDir;
|
2014-11-20 13:21:19 +00:00
|
|
|
private String login;
|
|
|
|
|
private String password;
|
2015-07-06 18:41:28 +01:00
|
|
|
private String proxy;
|
2014-11-20 13:21:19 +00:00
|
|
|
private int maxUploadingJob;
|
|
|
|
|
private int nbCores;
|
2021-11-16 14:51:53 +00:00
|
|
|
private long maxAllowedMemory; // in KiB, max memory allowed for render
|
2017-04-25 13:06:23 +02:00
|
|
|
private int maxRenderTime; // max render time per frame allowed
|
2017-01-05 09:58:27 +01:00
|
|
|
private int priority;
|
2014-11-20 13:21:19 +00:00
|
|
|
private ComputeType computeMethod;
|
|
|
|
|
private GPUDevice GPUDevice;
|
2018-08-24 19:46:03 +02:00
|
|
|
private boolean detectGPUs;
|
2014-11-20 13:21:19 +00:00
|
|
|
private boolean printLog;
|
2024-05-05 10:55:46 +00:00
|
|
|
private boolean debugLevel;
|
2019-08-07 22:17:59 +02:00
|
|
|
private List<Pair<Calendar, Calendar>> requestTime;
|
2020-07-28 00:49:36 +10:00
|
|
|
private long shutdownTime;
|
|
|
|
|
private String shutdownMode;
|
2014-11-20 13:21:19 +00:00
|
|
|
private String extras;
|
2015-04-03 19:50:58 +01:00
|
|
|
private boolean autoSignIn;
|
2020-06-09 14:47:39 +10:00
|
|
|
private boolean useSysTray;
|
2021-07-16 23:37:24 +00:00
|
|
|
private boolean headless;
|
2015-04-08 20:37:53 +01:00
|
|
|
private String UIType;
|
2017-05-08 01:35:08 +02:00
|
|
|
private String hostname;
|
2020-04-14 23:24:28 +10:00
|
|
|
private String theme;
|
2024-03-26 14:08:46 +00:00
|
|
|
private boolean disableLargeDownloads;
|
2024-06-08 03:21:33 +00:00
|
|
|
private String incompatibleProcess;
|
2014-11-20 13:21:19 +00:00
|
|
|
|
|
|
|
|
public Configuration(File cache_dir_, String login_, String password_) {
|
2018-12-18 22:53:01 +01:00
|
|
|
this.configFilePath = null;
|
2024-04-14 09:27:52 +00:00
|
|
|
this.logDirectory = null;
|
2014-11-20 13:21:19 +00:00
|
|
|
this.login = login_;
|
|
|
|
|
this.password = password_;
|
2015-07-06 18:41:28 +01:00
|
|
|
this.proxy = null;
|
2017-05-08 01:35:08 +02:00
|
|
|
this.hostname = this.getDefaultHostname();
|
2014-11-20 13:21:19 +00:00
|
|
|
this.maxUploadingJob = 1;
|
|
|
|
|
this.nbCores = -1; // ie not set
|
2021-11-16 14:51:53 +00:00
|
|
|
this.maxAllowedMemory = -1; // ie not set
|
2017-04-25 13:06:23 +02:00
|
|
|
this.maxRenderTime = -1; // ie not set
|
2017-03-19 17:38:22 +01:00
|
|
|
this.priority = 19; // default lowest
|
2015-03-31 23:06:21 +01:00
|
|
|
this.computeMethod = null;
|
2014-11-20 13:21:19 +00:00
|
|
|
this.GPUDevice = null;
|
2018-08-18 01:44:40 +02:00
|
|
|
this.userHasSpecifiedACacheDir = false;
|
2018-08-24 19:46:03 +02:00
|
|
|
this.detectGPUs = true;
|
2014-11-20 13:21:19 +00:00
|
|
|
this.workingDirectory = null;
|
2020-10-21 22:03:09 +11:00
|
|
|
this.sharedDownloadsDirectory = null;
|
2024-10-31 13:30:37 +00:00
|
|
|
this.woolCacheDirectory = null;
|
2014-11-20 13:21:19 +00:00
|
|
|
this.setCacheDir(cache_dir_);
|
|
|
|
|
this.printLog = false;
|
2024-05-05 10:55:46 +00:00
|
|
|
this.debugLevel = false;
|
2014-11-20 13:21:19 +00:00
|
|
|
this.requestTime = null;
|
2020-07-28 00:49:36 +10:00
|
|
|
this.shutdownTime = -1;
|
|
|
|
|
this.shutdownMode = "soft";
|
2014-11-20 13:21:19 +00:00
|
|
|
this.extras = "";
|
2015-04-03 19:50:58 +01:00
|
|
|
this.autoSignIn = false;
|
2021-05-15 16:47:20 +02:00
|
|
|
this.useSysTray = false;
|
2021-07-16 23:37:24 +00:00
|
|
|
this.headless = java.awt.GraphicsEnvironment.isHeadless();
|
2015-04-08 20:37:53 +01:00
|
|
|
this.UIType = null;
|
2020-04-14 23:24:28 +10:00
|
|
|
this.theme = null;
|
2024-03-26 14:08:46 +00:00
|
|
|
this.disableLargeDownloads = false;
|
2024-06-08 03:21:33 +00:00
|
|
|
this.incompatibleProcess = null;
|
2014-11-20 13:21:19 +00:00
|
|
|
}
|
|
|
|
|
|
2023-10-19 10:33:48 +00:00
|
|
|
/**
|
|
|
|
|
* @return string formatted with SheepIt Admin Log Viewer in mind
|
|
|
|
|
*/
|
2024-06-07 14:30:24 +00:00
|
|
|
@Override public String toString() {
|
2024-06-06 03:04:34 +02:00
|
|
|
String c = " CFG: ";
|
|
|
|
|
String n ="\n";
|
2022-09-10 10:10:57 +00:00
|
|
|
return
|
2023-07-30 21:36:27 +00:00
|
|
|
c + "version: " + getJarVersion() + n +
|
|
|
|
|
c + "configFilePath: " + configFilePath + n +
|
2024-04-14 09:27:52 +00:00
|
|
|
c + "logDir: " + (logDirectory == null ? "NULL" : logDirectory) + n +
|
2022-09-10 10:10:57 +00:00
|
|
|
c + "workingDirectory: " + workingDirectory + n +
|
|
|
|
|
c + "sharedDownloadsDirectory: " + sharedDownloadsDirectory + n +
|
2024-10-31 13:30:37 +00:00
|
|
|
c + "woolCacheDirectory: " + woolCacheDirectory + n +
|
2022-09-10 10:10:57 +00:00
|
|
|
c + "userHasSpecifiedACacheDir: " + userHasSpecifiedACacheDir + n +
|
|
|
|
|
c + "login: " + login + n +
|
|
|
|
|
c + "proxy: " + proxy + n +
|
|
|
|
|
c + "maxUploadingJob: " + maxUploadingJob + n +
|
|
|
|
|
c + "nbCores: " + nbCores + n +
|
|
|
|
|
c + "maxAllowedMemory: " + maxAllowedMemory + n +
|
|
|
|
|
c + "maxRenderTime: " + maxRenderTime + n +
|
|
|
|
|
c + "priority: " + priority + n +
|
|
|
|
|
c + "computeMethod: " + computeMethod + n +
|
|
|
|
|
c + "GPUDevice: " + GPUDevice + n +
|
|
|
|
|
c + "detectGPUs: " + detectGPUs + n +
|
|
|
|
|
c + "printLog: " + printLog + n +
|
2024-05-05 10:55:46 +00:00
|
|
|
c + "debugLog: " + debugLevel + n +
|
2022-09-10 10:10:57 +00:00
|
|
|
c + "requestTime: " + requestTime + n +
|
|
|
|
|
c + "shutdownTime: " + shutdownTime + n +
|
|
|
|
|
c + "shutdownMode: " + shutdownMode + n +
|
|
|
|
|
c + "extras: " + extras + n +
|
|
|
|
|
c + "autoSignIn: " + autoSignIn + n +
|
|
|
|
|
c + "useSysTray: " + useSysTray + n +
|
|
|
|
|
c + "headless: " + headless + n +
|
|
|
|
|
c + "UIType: " + UIType + n +
|
|
|
|
|
c + "hostname: " + hostname + n +
|
2024-03-26 14:08:46 +00:00
|
|
|
c + "theme: " + theme + n +
|
2024-06-08 03:21:33 +00:00
|
|
|
c + "incompatibleProcess: " + incompatibleProcess + n +
|
2024-03-26 14:08:46 +00:00
|
|
|
c + "disableLargeDownloads: " + disableLargeDownloads;
|
2014-11-20 13:21:19 +00:00
|
|
|
}
|
2020-05-28 13:28:42 +02:00
|
|
|
|
2023-10-19 10:33:48 +00:00
|
|
|
/**
|
|
|
|
|
* Sets the priority that Blender will be started with
|
|
|
|
|
* @param priority integer that will be clamped between 19 and -19,
|
|
|
|
|
* lowest to highest in terms of priority
|
|
|
|
|
*/
|
2023-10-19 11:09:08 +00:00
|
|
|
public void setPriority(int priority) {
|
2017-01-05 09:58:27 +01:00
|
|
|
if (priority > 19)
|
|
|
|
|
priority = 19;
|
2023-10-19 11:09:08 +00:00
|
|
|
else if (priority < -19)
|
2017-01-05 09:58:27 +01:00
|
|
|
priority = -19;
|
|
|
|
|
|
|
|
|
|
this.priority = priority;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-19 10:33:48 +00:00
|
|
|
/**
|
|
|
|
|
* Returns ordinal integer of the computeMethod enum
|
|
|
|
|
* @return ordinal integer of the computeMethod enum
|
|
|
|
|
*/
|
2014-11-20 13:21:19 +00:00
|
|
|
public int computeMethodToInt() {
|
|
|
|
|
return this.computeMethod.ordinal();
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-19 10:33:48 +00:00
|
|
|
/**
|
|
|
|
|
* Sets and optionally creates cache directory
|
|
|
|
|
* @param cache_dir_ File representing cache directory
|
|
|
|
|
*/
|
2014-11-20 13:21:19 +00:00
|
|
|
public void setCacheDir(File cache_dir_) {
|
|
|
|
|
if (cache_dir_ == null) {
|
2018-08-18 01:44:40 +02:00
|
|
|
this.userHasSpecifiedACacheDir = false;
|
2014-11-20 13:21:19 +00:00
|
|
|
try {
|
|
|
|
|
this.workingDirectory = File.createTempFile("farm_", "");
|
|
|
|
|
this.workingDirectory.createNewFile(); // hoho...
|
|
|
|
|
this.workingDirectory.delete(); // hoho
|
|
|
|
|
}
|
|
|
|
|
catch (IOException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
2024-11-20 22:51:06 +00:00
|
|
|
|
|
|
|
|
// since there is no working directory and the client will be working in the system temp directory,
|
|
|
|
|
// we can also set up a 'permanent' directory for immutable files (like renderer binary)
|
|
|
|
|
this.woolCacheDirectory = new File(this.workingDirectory.getParent() + File.separator + WOOL_CACHE_DIRNAME);
|
|
|
|
|
|
2014-11-20 13:21:19 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2018-08-18 01:44:40 +02:00
|
|
|
this.userHasSpecifiedACacheDir = true;
|
2024-10-31 13:30:37 +00:00
|
|
|
this.workingDirectory = new File(cache_dir_.getAbsolutePath() + File.separator + WORKING_DIRNAME);
|
|
|
|
|
this.woolCacheDirectory = new File(cache_dir_.getAbsolutePath() + File.separator + WOOL_CACHE_DIRNAME);
|
2020-10-21 22:03:09 +11:00
|
|
|
}
|
2014-11-20 13:21:19 +00:00
|
|
|
}
|
|
|
|
|
|
2023-10-19 10:33:48 +00:00
|
|
|
/**
|
|
|
|
|
* @return the user specified cache directory or null if it hasn't been specified
|
|
|
|
|
*/
|
2018-08-18 02:03:51 +02:00
|
|
|
public File getCacheDirForSettings() {
|
2023-11-22 17:10:16 +00:00
|
|
|
// when the user has a cache directory specified,
|
2024-10-31 13:30:37 +00:00
|
|
|
// a "sheepit" and "wool_cache" directory is to be automatically created
|
2023-11-22 17:10:16 +00:00
|
|
|
return this.userHasSpecifiedACacheDir == false ? null : this.workingDirectory.getParentFile();
|
2018-08-18 02:03:51 +02:00
|
|
|
}
|
|
|
|
|
|
2023-10-19 10:33:48 +00:00
|
|
|
/**
|
|
|
|
|
* @return string-representation of the hostname or an empty string if an error was encountered
|
|
|
|
|
*/
|
2017-05-08 01:35:08 +02:00
|
|
|
public String getDefaultHostname() {
|
|
|
|
|
try {
|
|
|
|
|
return InetAddress.getLocalHost().getHostName();
|
|
|
|
|
}
|
|
|
|
|
catch (UnknownHostException e) {
|
2017-07-22 12:20:28 +02:00
|
|
|
return "";
|
2017-05-08 01:35:08 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-19 10:33:48 +00:00
|
|
|
/**
|
|
|
|
|
* @return a string representing the version of the jar or
|
|
|
|
|
* {@code 6.0.0} if on error is encountered or the VERSION file doesn't exist
|
|
|
|
|
*/
|
2021-12-30 17:46:20 +00:00
|
|
|
private static String getJarVersion() {
|
2014-11-20 13:21:19 +00:00
|
|
|
String versionPath = "/VERSION";
|
2021-12-30 17:46:20 +00:00
|
|
|
String version = "6.0.0";
|
2014-11-20 13:21:19 +00:00
|
|
|
|
|
|
|
|
InputStream versionStream = Client.class.getResourceAsStream(versionPath);
|
2021-12-30 17:46:20 +00:00
|
|
|
if (versionStream != null) {
|
|
|
|
|
try {
|
|
|
|
|
BufferedReader in = new BufferedReader(new InputStreamReader(versionStream));
|
|
|
|
|
version = in.readLine();
|
|
|
|
|
}
|
|
|
|
|
catch (IOException ex) {
|
|
|
|
|
System.err.println("Configuration::getJarVersion error while reading manifest file (" + versionPath + "): " + ex.getMessage());
|
|
|
|
|
}
|
2014-11-20 13:21:19 +00:00
|
|
|
}
|
2021-12-30 17:46:20 +00:00
|
|
|
else {
|
|
|
|
|
System.err.println("Configuration::getJarVersion Failed to get version file");
|
2014-11-20 13:21:19 +00:00
|
|
|
}
|
2021-12-30 17:46:20 +00:00
|
|
|
return version;
|
2014-11-20 13:21:19 +00:00
|
|
|
}
|
2014-12-17 21:47:31 +00:00
|
|
|
|
2023-10-19 10:33:48 +00:00
|
|
|
/**
|
|
|
|
|
* @return true if operating system is in among the supported platforms
|
|
|
|
|
* and is running in a compatible configuration
|
|
|
|
|
* false otherwise
|
|
|
|
|
* @see OS#isSupported()
|
|
|
|
|
*/
|
2014-12-17 21:47:31 +00:00
|
|
|
public boolean checkOSisSupported() {
|
2021-09-10 00:23:57 +00:00
|
|
|
return OS.getOS() != null && OS.getOS().isSupported();
|
2014-12-17 21:47:31 +00:00
|
|
|
}
|
|
|
|
|
|
2023-10-19 10:33:48 +00:00
|
|
|
/**
|
|
|
|
|
* @return true if operating system is in among the supported platforms
|
|
|
|
|
* and if we have data on the cpu
|
|
|
|
|
* false otherwise
|
|
|
|
|
* @see CPU#haveData()
|
|
|
|
|
*/
|
2015-01-05 23:04:38 +01:00
|
|
|
public boolean checkCPUisSupported() {
|
2014-12-17 21:47:31 +00:00
|
|
|
OS os = OS.getOS();
|
|
|
|
|
if (os != null) {
|
|
|
|
|
CPU cpu = os.getCPU();
|
|
|
|
|
return cpu != null && cpu.haveData();
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2014-11-20 13:21:19 +00:00
|
|
|
}
|