Skip to content

Commit f38a22f

Browse files
authored
Merge pull request #602 from mspruc/main
fix wrongful configuration getter, core.py should now fetch set port …
2 parents 73c6e62 + 4e4d27f commit f38a22f

5 files changed

Lines changed: 40 additions & 23 deletions

File tree

python/src/pywy/configuration.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
#
3+
# Licensed to the Apache Software Foundation (ASF) under one or more
4+
# contributor license agreements. See the NOTICE file distributed with
5+
# this work for additional information regarding copyright ownership.
6+
# The ASF licenses this file to You under the Apache License, Version 2.0
7+
# (the "License"); you may not use this file except in compliance with
8+
# the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
19+
from typing import Dict
20+
21+
class Configuration:
22+
entries: Dict[str, str]
23+
24+
def __init__(self):
25+
self.entries = {}
26+
27+
def set_property(self, key: str, value: str):
28+
self.entries[key] = value
29+
30+
def get_property(self, key: str):
31+
return self.entries.get(key)

python/src/pywy/core/core.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import json
1919
import requests
2020

21+
from pywy.configuration import Configuration
2122
from pywy.core.platform import Platform
2223
from pywy.core.serializer import JSONSerializer
2324
from pywy.graph.graph import WayangGraph
@@ -68,7 +69,7 @@ class PywyPlan:
6869
"""
6970
graph: WayangGraph
7071

71-
def __init__(self, plugins: Set[Plugin], configuration: Dict[str, str], sinks: Iterable[SinkOperator]):
72+
def __init__(self, plugins: Set[Plugin], configuration: Configuration, sinks: Iterable[SinkOperator]):
7273
"""basic Constructor of PywyPlan
7374
7475
this constructor set the plugins and sinks element, and it prepares
@@ -100,7 +101,7 @@ def execute(self):
100101
context = {}
101102
context["origin"] = "python"
102103
context["platforms"] = {}
103-
context["configuration"] = self.configuration
104+
context["configuration"] = self.configuration.entries
104105

105106
if len(self.plugins) > 0:
106107
context["platforms"] = list(map(lambda pl: next(iter(pl.platforms)).name, self.plugins))
@@ -125,10 +126,7 @@ def execute(self):
125126
json_data["operators"].append(serializer.serialize(operator))
126127
pipeline = []
127128

128-
port = self.configuration.get_property("wayang.api.python.port")
129-
130-
if port is None:
131-
port = 8080
129+
port = self.configuration.get_property("wayang.api.python.port") or 8080
132130

133131
url = f'http://localhost:{port}/wayang-api-json/submit-plan/json'
134132
headers = {'Content-type': 'application/json'}

python/src/pywy/dataquanta.py

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# limitations under the License.
1616
#
1717

18-
from typing import Dict, Set, List, Optional, cast
18+
from typing import Set, List, Optional, cast
1919

2020
from pywy.core.core import Plugin, PywyPlan
2121
from pywy.operators.base import PO_T
@@ -24,18 +24,7 @@
2424
from pywy.basic.data.record import Record
2525
from pywy.basic.model.option import Option
2626
from pywy.basic.model.models import (Model, LogisticRegression, DecisionTreeRegression, LinearSVC)
27-
28-
29-
30-
class Configuration:
31-
entries: Dict[str, str]
32-
33-
def __init__(self):
34-
self.entries = {}
35-
36-
def set_property(self, key: str, value: str):
37-
self.entries[key] = value
38-
27+
from pywy.configuration import Configuration
3928

4029
class WayangContext:
4130
"""
@@ -242,7 +231,7 @@ def store_textfile(self: "DataQuanta[In]", path: str, input_type: GenericTco = N
242231
)
243232
)
244233
]
245-
PywyPlan(self.context.plugins, self.context.configuration.entries, last).execute()
234+
PywyPlan(self.context.plugins, self.context.configuration, last).execute()
246235

247236
def _connect(self, op: PO_T, port_op: int = 0) -> PywyOperator:
248237
self.operator.connect(0, op, port_op)

python/src/pywy/tests/word_count.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@
1616
#
1717

1818
import unittest
19-
from typing import Tuple, Callable, Iterable
19+
from typing import Iterable
2020
from pywy.dataquanta import WayangContext, Configuration
21-
from unittest.mock import Mock
2221
from pywy.platforms.java import JavaPlugin
2322
from pywy.platforms.spark import SparkPlugin
2423

python/src/pywy/types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#
1717

1818
import re
19-
from ast import literal_eval
19+
2020
from inspect import signature
2121
from typing import (
2222
Generic, TypeVar, Callable, Hashable, Iterable, Type, Union, Tuple, get_args, get_origin, List, Dict, Any

0 commit comments

Comments
 (0)