You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@heron.apache.org by GitBox <gi...@apache.org> on 2018/05/11 18:34:06 UTC
[GitHub] huijunwu closed pull request #2274: Topology package fetcher.
huijunwu closed pull request #2274: Topology package fetcher.
URL: https://github.com/apache/incubator-heron/pull/2274
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/heron/tools/cli/src/python/fetcher/__init__.py b/heron/tools/cli/src/python/fetcher/__init__.py
new file mode 100644
index 0000000000..7b2d7bdfda
--- /dev/null
+++ b/heron/tools/cli/src/python/fetcher/__init__.py
@@ -0,0 +1,3 @@
+''' __init__ '''
+from base_fetcher import BaseFetcher
+from local_fetcher import LocalFetcher
diff --git a/heron/tools/cli/src/python/fetcher/base_fetcher.py b/heron/tools/cli/src/python/fetcher/base_fetcher.py
new file mode 100644
index 0000000000..d3ef6ca5c8
--- /dev/null
+++ b/heron/tools/cli/src/python/fetcher/base_fetcher.py
@@ -0,0 +1,25 @@
+# Copyright 2017 Twitter. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+'''base_fetcher.py'''
+import abc
+
+class BaseFetcher(object):
+ """Result class"""
+ def __init__(self, protocol, location):
+ self.protocol = protocol
+ self.location = location
+
+ @abc.abstractmethod
+ def fetch(self):
+ pass
diff --git a/heron/tools/cli/src/python/fetcher/fetcher.py b/heron/tools/cli/src/python/fetcher/fetcher.py
new file mode 100644
index 0000000000..2fe7f11ae2
--- /dev/null
+++ b/heron/tools/cli/src/python/fetcher/fetcher.py
@@ -0,0 +1,38 @@
+# Copyright 2017 Twitter. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+'''dispatcher.py'''
+import heron.tools.cli.src.python.fetcher as fetcher
+
+all_fetchers = [fetcher.LocalFetcher]
+
+def extract(package):
+ ''' extract protocol and package location '''
+ sep = "://"
+ if sep not in package:
+ return "file", package
+ else:
+ chunks = package.split(sep)
+ if len(chunks) != 2 or '' in chunks:
+ raise Exception(
+ "Failed to get protocol of the package location: %s" % package)
+ else:
+ return chunks[0], chunks[1]
+
+# pylint: disable=dangerous-default-value
+def fetch(package, fetchers=all_fetchers):
+ protocol, loc = extract(package)
+ for f in fetchers:
+ if f.protocol == protocol:
+ return f.fetch(loc)
+ raise Exception("No available fetcher for protocol %s" % protocol)
diff --git a/heron/tools/cli/src/python/fetcher/local_fetcher.py b/heron/tools/cli/src/python/fetcher/local_fetcher.py
new file mode 100644
index 0000000000..9dfba40c45
--- /dev/null
+++ b/heron/tools/cli/src/python/fetcher/local_fetcher.py
@@ -0,0 +1,23 @@
+# Copyright 2017 Twitter. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+'''local_fetcher.py'''
+from heron.tools.cli.src.python.fetcher import BaseFetcher
+
+class LocalFetcher(BaseFetcher):
+ """Result class"""
+ def __init__(self, protocol, location):
+ super(LocalFetcher, self).__init__(protocol, location)
+
+ def fetch(self):
+ return self.location
diff --git a/heron/tools/cli/src/python/submit.py b/heron/tools/cli/src/python/submit.py
index b0ca0380c5..b61d843b71 100644
--- a/heron/tools/cli/src/python/submit.py
+++ b/heron/tools/cli/src/python/submit.py
@@ -23,6 +23,7 @@
from heron.tools.cli.src.python.result import SimpleResult, Status
import heron.tools.cli.src.python.args as cli_args
import heron.tools.cli.src.python.execute as execute
+import heron.tools.cli.src.python.fetcher.fetcher as fetcher
import heron.tools.cli.src.python.jars as jars
import heron.tools.cli.src.python.opts as opts
import heron.tools.cli.src.python.result as result
@@ -355,6 +356,11 @@ def run(command, parser, cl_args, unknown_args):
# get the topology file name
topology_file = cl_args['topology-file-name']
+ try:
+ topology_file = fetcher.fetch(topology_file)
+ except Exception:
+ pass # fixme
+
# check to see if the topology file exists
if not os.path.isfile(topology_file):
err_context = "Topology file '%s' does not exist" % topology_file
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services