Commit cb966704 authored by qhoangxuan's avatar qhoangxuan

add proxy comment, remove unused variables

parent 6ea32cc2
...@@ -77,9 +77,9 @@ class APIEndpoint: ...@@ -77,9 +77,9 @@ class APIEndpoint:
raise zoe_api.exceptions.ZoeException('The Zoe master is unavailable, execution will be submitted automatically when the master is back up ({}).'.format(message)) raise zoe_api.exceptions.ZoeException('The Zoe master is unavailable, execution will be submitted automatically when the master is back up ({}).'.format(message))
if get_conf().proxy_type == 'apache': if get_conf().proxy_type == 'apache':
proxy = zoe_api.proxy.apache.ApacheProxy(self, application_description) proxy = zoe_api.proxy.apache.ApacheProxy(self)
else: else:
proxy = zoe_api.proxy.nginx.NginxProxy(self, application_description) proxy = zoe_api.proxy.nginx.NginxProxy(self)
threading.Thread(target=proxy.proxify,args=(uid, role, new_id)).start() threading.Thread(target=proxy.proxify,args=(uid, role, new_id)).start()
return new_id return new_id
...@@ -96,9 +96,9 @@ class APIEndpoint: ...@@ -96,9 +96,9 @@ class APIEndpoint:
if e.is_active: if e.is_active:
if get_conf().proxy_type == 'apache': if get_conf().proxy_type == 'apache':
proxy = zoe_api.proxy.apache.ApacheProxy(self, None) proxy = zoe_api.proxy.apache.ApacheProxy(self)
else: else:
proxy = zoe_api.proxy.nginx.NginxProxy(self, None) proxy = zoe_api.proxy.nginx.NginxProxy(self)
proxy.unproxify(uid, role, exec_id) proxy.unproxify(uid, role, exec_id)
return self.master.execution_terminate(exec_id) return self.master.execution_terminate(exec_id)
else: else:
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
"""Base authenticator class.""" """Proxifying using Apache2 Container."""
import docker import docker
import time import time
...@@ -28,20 +28,15 @@ log = logging.getLogger(__name__) ...@@ -28,20 +28,15 @@ log = logging.getLogger(__name__)
class ApacheProxy(zoe_api.proxy.base.BaseProxy): class ApacheProxy(zoe_api.proxy.base.BaseProxy):
"""Apache proxy class.""" """Apache proxy class."""
def __init__(self, apiEndpoint, appDescription): def __init__(self, apiEndpoint):
self.appDesc = appDescription
self.api_endpoint = apiEndpoint self.api_endpoint = apiEndpoint
if self.appDesc is not None: """Proxify function."""
services = self.appDesc['services']
self.total_ctn = 0
for srv in services:
self.total_ctn += srv['total_count']
def proxify(self, uid, role, id): def proxify(self, uid, role, id):
try: try:
length_service = 0 length_service = 0
#Wait until all the services get created and started to be able to get the backend_id
while self.api_endpoint.execution_by_id(uid, role, id).status != 'running': while self.api_endpoint.execution_by_id(uid, role, id).status != 'running':
log.info('Waiting for all services get started...') log.info('Waiting for all services get started...')
length_service = len(self.api_endpoint.execution_by_id(uid, role, id).services) length_service = len(self.api_endpoint.execution_by_id(uid, role, id).services)
...@@ -58,7 +53,8 @@ class ApacheProxy(zoe_api.proxy.base.BaseProxy): ...@@ -58,7 +53,8 @@ class ApacheProxy(zoe_api.proxy.base.BaseProxy):
time.sleep(1) time.sleep(1)
else: else:
l = l - 1 l = l - 1
#Start proxifying by adding entry to use proxypass and proxypassreverse in apache2 config file
for srv in exe.services: for srv in exe.services:
swarm = SwarmClient(get_conf()) swarm = SwarmClient(get_conf())
...@@ -81,6 +77,8 @@ class ApacheProxy(zoe_api.proxy.base.BaseProxy): ...@@ -81,6 +77,8 @@ class ApacheProxy(zoe_api.proxy.base.BaseProxy):
except Exception as ex: except Exception as ex:
log.error(ex) log.error(ex)
#The apache2 server is running inside a container
#Adding new entries with the proxy path and the ip:port of the application to the apache2 config file
def dispatch_to_docker(self, base_path, original_path): def dispatch_to_docker(self, base_path, original_path):
proxy = ['ProxyPass ' + base_path + '/api/kernels/ ws://' + original_path + '/api/kernels/', proxy = ['ProxyPass ' + base_path + '/api/kernels/ ws://' + original_path + '/api/kernels/',
'ProxyPassReverse ' + base_path + '/api/kernels/ ws://' + original_path + '/api/kernels/', 'ProxyPassReverse ' + base_path + '/api/kernels/ ws://' + original_path + '/api/kernels/',
...@@ -106,6 +104,7 @@ class ApacheProxy(zoe_api.proxy.base.BaseProxy): ...@@ -106,6 +104,7 @@ class ApacheProxy(zoe_api.proxy.base.BaseProxy):
reloadID = docker_client.exec_create(get_conf().proxy_container, reloadCommand) reloadID = docker_client.exec_create(get_conf().proxy_container, reloadCommand)
docker_client.exec_start(reloadID) docker_client.exec_start(reloadID)
#Simply remove the added entries at the apache2 config file when terminating applcations
def unproxify(self, uid, role, id): def unproxify(self, uid, role, id):
log.info('Unproxifying for user %s - execution %s', uid, str(id)) log.info('Unproxifying for user %s - execution %s', uid, str(id))
pattern = '/zoe\/' + uid + '\/' + str(id) + '/d' pattern = '/zoe\/' + uid + '\/' + str(id) + '/d'
......
...@@ -13,11 +13,11 @@ ...@@ -13,11 +13,11 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
"""Base authenticator class.""" """Base Proxy class."""
class BaseProxy: class BaseProxy:
"""Base authenticator class.""" """Base proxy class."""
def proxify(self, uid, role, id): def proxify(self, uid, role, id):
"""The methods that needs to be overridden by implementations.""" """The methods that needs to be overridden by implementations."""
......
...@@ -27,7 +27,7 @@ log = logging.getLogger(__name__) ...@@ -27,7 +27,7 @@ log = logging.getLogger(__name__)
class NginxProxy(zoe_api.proxy.base.BaseProxy): class NginxProxy(zoe_api.proxy.base.BaseProxy):
"""Nginx proxy class.""" """Nginx proxy class."""
def __init__(self, apiEndpoint, appDescription): def __init__(self, apiEndpoint):
return {} return {}
def proxify(self, uid, role, id): def proxify(self, uid, role, id):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment