in frontend/server/src/main/java/org/pytorch/serve/util/ConfigManager.java [135:232]
private ConfigManager(Arguments args) throws IOException {
prop = new Properties();
this.snapshotDisabled = args.isSnapshotDisabled();
String version = readFile(getModelServerHome() + "/ts/version.txt");
if (version != null) {
version = version.replaceAll("[\\n\\t ]", "");
prop.setProperty(VERSION, version);
}
String logLocation = System.getenv("LOG_LOCATION");
if (logLocation != null) {
System.setProperty("LOG_LOCATION", logLocation);
} else if (System.getProperty("LOG_LOCATION") == null) {
System.setProperty("LOG_LOCATION", "logs");
}
String metricsLocation = System.getenv("METRICS_LOCATION");
if (metricsLocation != null) {
System.setProperty("METRICS_LOCATION", metricsLocation);
} else if (System.getProperty("METRICS_LOCATION") == null) {
System.setProperty("METRICS_LOCATION", "logs");
}
String filePath = System.getenv("TS_CONFIG_FILE");
Properties snapshotConfig = null;
if (filePath == null) {
filePath = args.getTsConfigFile();
if (filePath == null) {
snapshotConfig = getLastSnapshot();
if (snapshotConfig == null) {
filePath = System.getProperty("tsConfigFile", "config.properties");
} else {
prop.putAll(snapshotConfig);
}
}
}
if (filePath != null) {
File tsConfigFile = new File(filePath);
if (tsConfigFile.exists()) {
try (InputStream stream = Files.newInputStream(tsConfigFile.toPath())) {
prop.load(stream);
prop.put("tsConfigFile", filePath);
} catch (IOException e) {
throw new IllegalStateException("Unable to read configuration file", e);
}
}
}
resolveEnvVarVals(prop);
String modelStore = args.getModelStore();
if (modelStore != null) {
prop.setProperty(TS_MODEL_STORE, modelStore);
}
String workflowStore = args.getWorkflowStore();
if (workflowStore != null) {
prop.setProperty(TS_WORKFLOW_STORE, workflowStore);
}
String[] models = args.getModels();
if (models != null) {
prop.setProperty(TS_LOAD_MODELS, String.join(",", models));
}
prop.setProperty(
TS_NUMBER_OF_GPU,
String.valueOf(
Integer.min(
getAvailableGpu(),
getIntProperty(TS_NUMBER_OF_GPU, Integer.MAX_VALUE))));
String pythonExecutable = args.getPythonExecutable();
if (pythonExecutable != null) {
prop.setProperty(PYTHON_EXECUTABLE, pythonExecutable);
}
try {
InetAddress ip = InetAddress.getLocalHost();
hostName = ip.getHostName();
} catch (UnknownHostException e) {
hostName = "Unknown";
}
if (Boolean.parseBoolean(prop.getProperty(TS_ASYNC_LOGGING))) {
enableAsyncLogging();
}
if (Boolean.parseBoolean(getEnableEnvVarsConfig())) {
// Environment variables have higher precedence over the config file variables
setSystemVars();
}
setModelConfig();
}