Skip to content

Commit 73c6e62

Browse files
authored
Merge pull request #601 from mspruc/main
custom ports for json api & python api
2 parents 5466166 + 553c212 commit 73c6e62

3 files changed

Lines changed: 27 additions & 5 deletions

File tree

python/src/pywy/core/core.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def execute(self):
109109
json_data["operators"] = []
110110

111111
nodes = []
112-
pipeline = list()
112+
pipeline = []
113113
self.graph.traversal(self.graph.starting_nodes, lambda x, parent: nodes.append(x))
114114
id_table = {(obj.current[0]): index + 1 for index, obj in enumerate(nodes)}
115115
serializer = JSONSerializer(id_table)
@@ -123,10 +123,14 @@ def execute(self):
123123
json_data["operators"].append(serializer.serialize_pipeline(pipeline))
124124

125125
json_data["operators"].append(serializer.serialize(operator))
126-
pipeline = list()
126+
pipeline = []
127127

128-
# This should either be configurable on the WayangContext or env
129-
url = 'http://localhost:8080/wayang-api-json/submit-plan/json'
128+
port = self.configuration.get_property("wayang.api.python.port")
129+
130+
if port is None:
131+
port = 8080
132+
133+
url = f'http://localhost:{port}/wayang-api-json/submit-plan/json'
130134
headers = {'Content-type': 'application/json'}
131135
json_body = json.dumps(json_data)
132136
print(json_body)

wayang-api/wayang-api-json/src/main/scala/Main.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,8 @@ object Main extends ZIOAppDefault {
7070
val app = Routes(drawRoute, jsonRoute).toHttpApp
7171

7272
// Run it like any simple app
73-
override val run = Server.serve(app).provide(Server.default)
73+
def run = for {
74+
args <- getArgs
75+
_ <- Server.serve(app).provide(Server.defaultWithPort((args.headOption getOrElse "8080" toInt)))
76+
} yield ()
7477
}

wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/api/Configuration.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
import java.util.Map;
7676
import java.util.Optional;
7777
import java.util.OptionalDouble;
78+
import java.util.OptionalInt;
7879
import java.util.OptionalLong;
7980
import java.util.Properties;
8081
import java.util.Random;
@@ -778,6 +779,20 @@ public long getLongProperty(String key) {
778779
return optionalLongProperty.getAsLong();
779780
}
780781

782+
783+
public OptionalInt getOptionalIntProperty(String key) {
784+
final Optional<String> intValue = this.properties.optionallyProvideFor(key);
785+
if (intValue.isPresent()) {
786+
return OptionalInt.of(Integer.valueOf(intValue.get()));
787+
} else {
788+
return OptionalInt.empty();
789+
}
790+
}
791+
792+
public int getIntProperty(String key) {
793+
return getOptionalIntProperty(key).orElseThrow(() -> new WayangException(String.format("No value for \"%s\".", key)));
794+
}
795+
781796
public long getLongProperty(String key, long fallback) {
782797
return this.getOptionalLongProperty(key).orElse(fallback);
783798
}

0 commit comments

Comments
 (0)