Commit fb769c42 authored by qhoangxuan's avatar qhoangxuan

Fix proxy bugs after merging

parent 5fc3e24a
......@@ -59,7 +59,7 @@ class APIEndpoint:
ret = [e for e in execs if e.user_id == uid or role == 'admin']
return ret
def execution_start(self, uid, role_, exec_name, application_description):
def execution_start(self, uid, role, exec_name, application_description):
"""Start an execution."""
try:
zoe_lib.applications.app_validate(application_description)
......
......@@ -21,7 +21,7 @@ import logging
import zoe_api.proxy.base
import zoe_api.api_endpoint
from zoe_lib.swarm_client import SwarmClient
from zoe_master.backends.old_swarm.api_client import SwarmClient
from zoe_lib.config import get_conf
log = logging.getLogger(__name__)
......@@ -41,17 +41,28 @@ class ApacheProxy(zoe_api.proxy.base.BaseProxy):
def proxify(self, uid, role, id):
try:
length_service = 0
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...')
length_service = len(self.api_endpoint.execution_by_id(uid, role, id).services)
time.sleep(1)
exe = self.api_endpoint.execution_by_id(uid, role, id)
l = len(exe.services)
while l != 0:
exe = self.api_endpoint.execution_by_id(uid, role, id)
l = len(exe.services)
for srv in exe.services:
if srv.backend_id == None:
time.sleep(1)
else:
l = l - 1
for srv in exe.services:
swarm = SwarmClient(get_conf())
s_info = swarm.inspect_container(srv.docker_id)
s_info = swarm.inspect_container(srv.backend_id)
ip, p = None, None
portList = s_info['ports']
......
......@@ -21,7 +21,6 @@ import logging
import zoe_api.proxy.base
import zoe_api.api_endpoint
from zoe_lib.swarm_client import SwarmClient
from zoe_lib.config import get_conf
log = logging.getLogger(__name__)
......
......@@ -55,6 +55,9 @@ class ExposedPort:
self.number = data['port_number']
self.expose = data['expose'] if 'expose' in data else False
def isExpose(self):
return self.expose
class Service:
"""A Zoe Service."""
......@@ -121,7 +124,8 @@ class Service:
'backend_id': self.backend_id,
'ip_address': self.ip_address,
'backend_status': self.backend_status,
'essential': self.essential
'essential': self.essential,
'proxy_address': self.proxy_address
}
def __eq__(self, other):
......@@ -173,6 +177,15 @@ class Service:
execution = self.sql_manager.execution_list(only_one=True, id=self.execution_id)
return execution.user_id
@property
def proxy_address(self):
for p in self.ports:
if p.isExpose():
proxyAdd = get_conf().proxy_path + "/" + self.user_id + "/" + str(self.execution_id) + "/" + self.name
else:
proxyAdd = None
return proxyAdd
def is_dead(self):
"""Returns True if this service is not running."""
return self.backend_status == self.BACKEND_DESTROY_STATUS or self.backend_status == self.BACKEND_OOM_STATUS or self.backend_status == self.BACKEND_DIE_STATUS
......@@ -17,11 +17,11 @@
from typing import Dict
from zoe_lib.state import Service
from zoe_lib.state import Service, Execution
from zoe_master.backends.proxy import gen_proxypath, JUPYTER_NOTEBOOK, MONGO_EXPRESS
from zoe_master.exceptions import ZoeStartExecutionFatalException
def gen_environment(service: Service, env_subst_dict: Dict):
def gen_environment(execution: Execution, service: Service, env_subst_dict: Dict):
""" Generate a dictionary containing the current cluster status (before the new container is spawned)
This information is used to substitute template strings in the environment variables."""
......@@ -34,4 +34,10 @@ def gen_environment(service: Service, env_subst_dict: Dict):
service.set_error(error_msg)
raise ZoeStartExecutionFatalException("Service {} has wrong environment expression")
env_list.append((env_name, env_value))
#if 'jupyter' in service.image_name:
env_list.append((JUPYTER_NOTEBOOK, gen_proxypath(execution, service)))
#elif 'mongo-express' in service.image_name:
env_list.append((MONGO_EXPRESS, gen_proxypath(execution, service)))
return env_list
......@@ -84,7 +84,7 @@ class OldSwarmBackend(zoe_master.backends.base.BaseBackend):
# copts.restart = not service.is_monitor # Monitor containers should not restart
copts.restart = False
env_vars = zoe_master.backends.common.gen_environment(service, env_subst_dict)
env_vars = zoe_master.backends.common.gen_environment(execution, service, env_subst_dict)
for name, value in env_vars:
copts.add_env_variable(name, value)
......
# Copyright (c) 2017, Daniele Venzano
#
# 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.
"""The high-level interface that Zoe uses to talk to the configured container backend."""
from typing import Dict
from zoe_lib.state import Service, Execution
from zoe_master.exceptions import ZoeStartExecutionFatalException
JUPYTER_NOTEBOOK='BASE_URL'
MONGO_EXPRESS='ME_CONFIG_SITE_BASEURL'
def gen_proxypath(execution: Execution, service: Service):
proxy_path_value = '/zoe/' + execution.user_id + '/' + str(execution.id) + '/' + service.name
return proxy_path_value
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