Skip to content

Commit

Permalink
Merge branch 'staging_0_1_1' of https://github.com/pytorch/serve into…
Browse files Browse the repository at this point in the history
… issue_204

# Conflicts:
#	frontend/server/src/main/java/org/pytorch/serve/util/ConfigManager.java
  • Loading branch information
shivamshriwas committed May 21, 2020
2 parents 29dfd93 + 7db018b commit 3456e29
Show file tree
Hide file tree
Showing 19 changed files with 104 additions and 22 deletions.
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
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 METRIC_TIME_INTERVAL = "metric_time_interval";
private static final String ENABLE_ENVVARS_CONFIG = "enable_envvars_config";
private static final String MODEL_SNAPSHOT = "model_snapshot";
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 @@ -105,7 +105,7 @@ public static Connector parse(String binding, boolean management) {
} else {
port = Integer.parseInt(listeningPort);
}
if (port >= Short.MAX_VALUE) {
if (port >= Short.MAX_VALUE * 2 + 1) {
throw new IllegalArgumentException("Invalid port number: " + binding);
}
return new Connector(port, false, host, String.valueOf(port), ssl, management);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.List;
import java.util.Properties;
import java.util.concurrent.CountDownLatch;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.pytorch.serve.http.DescribeModelResponse;
import org.pytorch.serve.http.ErrorResponse;
Expand Down Expand Up @@ -71,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 Expand Up @@ -1366,6 +1369,61 @@ public void testUnregisterModelFailure() throws InterruptedException {
TestUtils.unregisterModel(channel, "noopversioned", "1.2.1", false);
}

@Test(
alwaysRun = true,
dependsOnMethods = {"testUnregisterModelFailure"})
private void testTSValidPort()
throws InterruptedException, InvalidSnapshotException, GeneralSecurityException,
IOException {
// test case for verifying port range refer https://github.com/pytorch/serve/issues/291
server.stop();
FileUtils.deleteQuietly(new File(System.getProperty("LOG_LOCATION"), "config"));
configManager.setProperty("inference_address", "https://127.0.0.1:42523");
server = new ModelServer(configManager);
server.start();

Channel channel = null;
Channel managementChannel = null;
for (int i = 0; i < 5; ++i) {
channel = TestUtils.connect(false, configManager);
if (channel != null) {
break;
}
Thread.sleep(100);
}

for (int i = 0; i < 5; ++i) {
managementChannel = TestUtils.connect(true, configManager);
if (managementChannel != null) {
break;
}
Thread.sleep(100);
}

Assert.assertNotNull(channel, "Failed to connect to inference port.");
Assert.assertNotNull(managementChannel, "Failed to connect to management port.");

testPing();
}

@Test(
alwaysRun = true,
dependsOnMethods = {"testTSValidPort"})
private void testTSInvalidPort() {
// test case for verifying port range refer https://github.com/pytorch/serve/issues/291
// invalid port test
server.stop();
FileUtils.deleteQuietly(new File(System.getProperty("LOG_LOCATION"), "config"));
configManager.setProperty("inference_address", "https://127.0.0.1:65536");
server = new ModelServer(configManager);
try {
server.start();
} catch (Exception e) {
Assert.assertEquals(e.getClass(), IllegalArgumentException.class);
Assert.assertEquals(e.getMessage(), "Invalid port number: https://127.0.0.1:65536");
}
}

private void testLoadModel(String url, String modelName) throws InterruptedException {
Channel channel = TestUtils.getManagementChannel(configManager);
TestUtils.setResult(null);
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
1 change: 0 additions & 1 deletion frontend/server/src/test/resources/config.properties
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ certificate_file=src/test/resources/certs.pem
# max_response_size=6553500
max_request_size=10485760
# blacklist_env_vars=.*USERNAME.*|.*PASSWORD.*
# enable_env_vars_config=false
# decode_input_request=true
enable_envvars_config=true
# default_service_handler=/path/to/service.py:handle
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,5 @@ certificate_file=src/test/resources/certs.pem
# max_response_size=6553500
max_request_size=10485760
# blacklist_env_vars=.*USERNAME.*|.*PASSWORD.*
# enable_env_vars_config=false
# decode_input_request=true
# enable_envvars_config=false
# decode_input_request=true
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

0 comments on commit 3456e29

Please sign in to comment.