Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes version number reporting for TorchServe #360

Merged
merged 13 commits into from
May 21, 2020
Merged
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
include ts/frontend/model-server.jar
include PyPiDescription.rst
include ts/configs/*
include ts/version.txt
dhaniram-kshirsagar marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.ArrayList;
import java.util.List;
import org.pytorch.serve.archive.Manifest;
import org.pytorch.serve.util.ConfigManager;
import org.pytorch.serve.util.ConnectorType;
import org.pytorch.serve.util.JsonUtils;
import org.pytorch.serve.wlm.Model;
Expand All @@ -18,7 +19,8 @@ public static String listApis(ConnectorType type) {
info.setTitle("TorchServe APIs");
info.setDescription(
"TorchServe is a flexible and easy to use tool for serving deep learning models");
info.setVersion("1.0.0");
ConfigManager config = ConfigManager.getInstance();
info.setVersion(config.getProperty("version", null));
openApi.setInfo(info);

if (ConnectorType.BOTH.equals(type) || ConnectorType.INFERENCE_CONNECTOR.equals(type)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public final class ConfigManager {
private static final String IO_RATIO = "io_ratio";
private static final String METRIC_TIME_INTERVAL = "metric_time_interval";
private static final String ENABLE_ENVVARS_CONFIG = "enable_envvars_config";
private static final String VERSION = "version";

// Variables which are local
public static final String MODEL_METRICS_LOGGER = "MODEL_METRICS";
Expand All @@ -97,13 +98,17 @@ public final class ConfigManager {
private boolean snapshotDisabled;

private static ConfigManager instance;

private String hostName;

private ConfigManager(Arguments args) {
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) {
Expand Down Expand Up @@ -186,6 +191,10 @@ private ConfigManager(Arguments args) {
}
}

public static String readFile(String path) throws IOException {
return Files.readString(Paths.get(path));
}

private void resolveEnvVarVals(Properties prop) {
Set<String> keys = prop.stringPropertyNames();
for (String key : keys) {
Expand Down Expand Up @@ -232,7 +241,7 @@ public String getHostName() {
return hostName;
}

public static void init(Arguments args) {
public static void init(Arguments args) throws IOException {
instance = new ConfigManager(args);
}

Expand Down Expand Up @@ -474,7 +483,9 @@ public void validateConfigurations() throws InvalidPropertiesFormatException {

public String dumpConfigurations() {
Runtime runtime = Runtime.getRuntime();
return "\nTS Home: "
return "\nTorchserve version: "
+ prop.getProperty(VERSION)
+ "\nTS Home: "
+ getModelServerHome()
+ "\nCurrent directory: "
+ getCanonicalPath(".")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,15 @@ public void beforeSuite()

server = new ModelServer(configManager);
server.start();

String version = configManager.getProperty("version", null);
try (InputStream is = new FileInputStream("src/test/resources/inference_open_api.json")) {
listInferenceApisResult = IOUtils.toString(is, StandardCharsets.UTF_8.name());
listInferenceApisResult =
String.format(IOUtils.toString(is, StandardCharsets.UTF_8.name()), version);
}

try (InputStream is = new FileInputStream("src/test/resources/management_open_api.json")) {
listManagementApisResult = IOUtils.toString(is, StandardCharsets.UTF_8.name());
listManagementApisResult =
String.format(IOUtils.toString(is, StandardCharsets.UTF_8.name()), version);
}

try (InputStream is = new FileInputStream("src/test/resources/describe_api.json")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ private void updateSnapshot(Properties prop) {
prop.put("tsConfigFile", "dummyconfig");
prop.put("NUM_WORKERS", 4);
prop.put("number_of_gpu", 4);
prop.put("version", "0.1.1");
}

private String getLastSnapshot() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ public void test()

@Test
public void testNoEnvVars()
throws IllegalAccessException, NoSuchFieldException, ClassNotFoundException {
throws IllegalAccessException, NoSuchFieldException, ClassNotFoundException,
IOException {
System.setProperty("tsConfigFile", "src/test/resources/config_test_env.properties");
modifyEnv("TS_DEFAULT_RESPONSE_TIMEOUT", "130");
ConfigManager.Arguments args = new ConfigManager.Arguments();
Expand Down
2 changes: 1 addition & 1 deletion frontend/server/src/test/resources/inference_open_api.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"info": {
"title": "TorchServe APIs",
"description": "TorchServe is a flexible and easy to use tool for serving deep learning models",
"version": "1.0.0"
"version": "%s"
},
"paths": {
"/": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"info": {
"title": "TorchServe APIs",
"description": "TorchServe is a flexible and easy to use tool for serving deep learning models",
"version": "1.0.0"
"version": "%s"
},
"paths": {
"/": {
Expand Down
1 change: 1 addition & 0 deletions model-archiver/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
include PyPiDescription.rst
include model_archiver/version.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def test_model_export_tool_version():
Test the model archive version
:return:
"""
with (open(os.path.join('model_archiver', 'version.py'))) as f:
exec(f.read(), globals())
with open(os.path.join('model_archiver', 'version.txt')) as f:
__version__ = f.readline().strip()

assert __version__ == str(model_archiver.__version__), "Versions do not match"
5 changes: 4 additions & 1 deletion model-archiver/model_archiver/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
"""
This is the current version of Model Archiver Tool
"""
import os
from pathlib import Path

__version__ = '0.1.0'
version_path = os.path.join(Path(__file__).resolve().parent, 'version.txt')
__version__ = open(version_path, 'r').read().strip()
1 change: 1 addition & 0 deletions model-archiver/model_archiver/version.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.1.1
2 changes: 2 additions & 0 deletions torchserve_sanity.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ cleanup()

install_pytest_suite_deps

run_backend_pytest

run_backend_python_linting

run_model_archiver_UT_suite
Expand Down
4 changes: 2 additions & 2 deletions ts/tests/unit_tests/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


def test_ts_version():
with open(os.path.join("ts", "version.py")) as f:
exec(f.read(), globals())
with open(os.path.join("ts", "version.txt")) as f:
__version__ = f.readline().strip()

assert __version__ == str(ts.__version__), "Versions don't match"
6 changes: 4 additions & 2 deletions ts/version.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

"""
This is the current version of TorchServe
"""
import os
from pathlib import Path

__version__ = '0.0.1'
version_path = os.path.join(Path(__file__).resolve().parent, 'version.txt')
__version__ = open(version_path, 'r').read().strip()
1 change: 1 addition & 0 deletions ts/version.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.1.1