From 6bc70ff4de665403402bdba44fbca0833af63505 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20G=C3=B3mez=20Garc=C3=ADa?= Date: Sat, 24 Oct 2015 10:32:51 +0200 Subject: [PATCH] Several minor fixes & aditions --- server/src/uds/REST/methods/services_pools.py | 3 +++ server/src/uds/REST/methods/user_services.py | 4 +++- server/src/uds/REST/model.py | 7 +++--- server/src/uds/__init__.py | 15 +++++++++++- server/src/uds/core/jobs/DelayedTaskRunner.py | 6 ++--- .../uds/core/managers/UserServiceManager.py | 13 +++++----- server/src/uds/core/util/Storage.py | 14 ++++++----- server/src/uds/core/util/UniqueIDGenerator.py | 4 ++-- .../uds/core/workers/UserServiceCleaner.py | 5 +++- .../uds/static/adm/js/gui-d-services.coffee | 1 + .../static/adm/js/gui-d-servicespools.coffee | 24 +++++++++++-------- .../src/uds/static/adm/js/gui-element.coffee | 12 +++++++++- server/src/uds/static/adm/js/gui.coffee | 8 +++---- .../uds/admin/tmpl/configuration.html | 6 ----- 14 files changed, 78 insertions(+), 44 deletions(-) diff --git a/server/src/uds/REST/methods/services_pools.py b/server/src/uds/REST/methods/services_pools.py index 6129bd45..4a259361 100644 --- a/server/src/uds/REST/methods/services_pools.py +++ b/server/src/uds/REST/methods/services_pools.py @@ -212,6 +212,9 @@ class ServicesPools(ModelHandler): except Exception: raise RequestError(ugettext('This service requires an OS Manager')) + # If max < initial or cache_1 or cache_l2 + fields['max_srvs'] = max((int(fields['initial_srvs']), int(fields['cache_l1_srvs']), int(fields['max_srvs']))) + imgId = fields['image_id'] fields['image_id'] = None logger.debug('Image id: {}'.format(imgId)) diff --git a/server/src/uds/REST/methods/user_services.py b/server/src/uds/REST/methods/user_services.py index 9e7e37ae..9c3bea3b 100644 --- a/server/src/uds/REST/methods/user_services.py +++ b/server/src/uds/REST/methods/user_services.py @@ -143,10 +143,12 @@ class AssignedService(DetailHandler): self.invalidItemException() logger.debug('Deleting assigned service') - if service.state == State.USABLE: + if service.state in (State.USABLE, State.REMOVING): service.remove() elif service.state == State.PREPARING: service.cancel() + elif service.state == State.REMOVABLE: + self.invalidItemException(_('Item already being removed')) else: self.invalidItemException(_('Item is not removable')) diff --git a/server/src/uds/REST/model.py b/server/src/uds/REST/model.py index 202108b7..1a479b2a 100644 --- a/server/src/uds/REST/model.py +++ b/server/src/uds/REST/model.py @@ -52,7 +52,7 @@ import logging logger = logging.getLogger(__name__) -__updated__ = '2015-04-28' +__updated__ = '2015-10-23' # a few constants @@ -238,8 +238,9 @@ class BaseModelHandler(Handler): ''' Raises a NotFound exception, with location info ''' - message = _('Item not found') if message is None else None - raise NotFound('{} {}: {}'.format(message, self.__class__, self._args)) + message = _('Item not found') if message is None else message + raise NotFound(message) + # raise NotFound('{} {}: {}'.format(message, self.__class__, self._args)) def accessDenied(self, message=None): raise AccessDenied(message or _('Access denied')) diff --git a/server/src/uds/__init__.py b/server/src/uds/__init__.py index da3de9fc..c30206ee 100644 --- a/server/src/uds/__init__.py +++ b/server/src/uds/__init__.py @@ -46,6 +46,7 @@ import uds.xmlrpc # To make actor live from django.db.backends.signals import connection_created from django.dispatch import receiver import math +import ssl from django.apps import AppConfig @@ -55,7 +56,19 @@ import logging logger = logging.getLogger(__name__) -__updated__ = '2015-06-09' +__updated__ = '2015-10-20' + + +# Default ssl context is unverified, as MOST servers that we will connect will be with self signed certificates... +try: + _create_unverified_https_context = ssl._create_unverified_context +except AttributeError: + # Legacy Python that doesn't verify HTTPS certificates by default + pass +else: + # Handle target environment that doesn't support HTTPS verification + ssl._create_default_https_context = _create_unverified_https_context + class UDSAppConfig(AppConfig): diff --git a/server/src/uds/core/jobs/DelayedTaskRunner.py b/server/src/uds/core/jobs/DelayedTaskRunner.py index f3d5c322..78bdad16 100644 --- a/server/src/uds/core/jobs/DelayedTaskRunner.py +++ b/server/src/uds/core/jobs/DelayedTaskRunner.py @@ -44,7 +44,7 @@ import threading import time import logging -__updated__ = '2015-10-16' +__updated__ = '2015-10-24' logger = logging.getLogger(__name__) @@ -60,8 +60,8 @@ class DelayedTaskThread(threading.Thread): def run(self): try: self._taskInstance.execute() - except Exception, e: - logger.debug("Exception in thread {0}: {1}".format(e.__class__, e)) + except Exception as e: + logger.exception("Exception in thread {0}: {1}".format(e.__class__, e)) class DelayedTaskRunner(object): diff --git a/server/src/uds/core/managers/UserServiceManager.py b/server/src/uds/core/managers/UserServiceManager.py index 63027428..8f919c7f 100644 --- a/server/src/uds/core/managers/UserServiceManager.py +++ b/server/src/uds/core/managers/UserServiceManager.py @@ -51,7 +51,7 @@ import requests import json import logging -__updated__ = '2015-10-15' +__updated__ = '2015-10-24' logger = logging.getLogger(__name__) @@ -69,7 +69,7 @@ class UserServiceOpChecker(DelayedTask): ''' This method ensures that there will be only one delayedtask related to the userService indicated ''' - DelayedTaskRunner.runner().remove(USERSERVICE_TAG + str(userService.id)) + DelayedTaskRunner.runner().remove(USERSERVICE_TAG + userService.uuid) UserServiceOpChecker.checkAndUpdateState(userService, userServiceInstance, state) @staticmethod @@ -139,9 +139,9 @@ class UserServiceOpChecker(DelayedTask): @param pi: Instance of Publication manager for the object ''' # Do not add task if already exists one that updates this service - if DelayedTaskRunner.runner().checkExists(USERSERVICE_TAG + str(userService.id)): + if DelayedTaskRunner.runner().checkExists(USERSERVICE_TAG + userService.uuid): return - DelayedTaskRunner.runner().insert(UserServiceOpChecker(userService), ci.suggestedTime, USERSERVICE_TAG + str(userService.id)) + DelayedTaskRunner.runner().insert(UserServiceOpChecker(userService), ci.suggestedTime, USERSERVICE_TAG + userService.uuid) def run(self): logger.debug('Checking user service finished {0}'.format(self._svrId)) @@ -325,8 +325,9 @@ class UserServiceManager(object): Removes a uService element @return: the uService removed (marked for removal) ''' - uService = UserService.objects.get(id=uService.id) - logger.debug('Removing uService {0}'.format(uService)) + uService.refresh_from_db() + # uService = UserService.objects.get(id=uService.id) + logger.debug('Removing uService {}'.format(uService)) if uService.isUsable() is False and State.isRemovable(uService.state) is False: raise OperationException(_('Can\'t remove a non active element')) diff --git a/server/src/uds/core/util/Storage.py b/server/src/uds/core/util/Storage.py index 5fa50d23..3b3d3a1e 100644 --- a/server/src/uds/core/util/Storage.py +++ b/server/src/uds/core/util/Storage.py @@ -63,7 +63,7 @@ class Storage(object): dbStorage.objects.create(owner=self._owner, key=key, data=data, attr1=attr1) # @UndefinedVariable except Exception: dbStorage.objects.filter(key=key).update(owner=self._owner, data=data, attr1=attr1) # @UndefinedVariable - logger.debug('Key saved') + # logger.debug('Key saved') def put(self, skey, data): return self.saveData(skey, data) @@ -127,24 +127,26 @@ class Storage(object): dbStorage.objects.unlock() # @UndefinedVariable def locateByAttr1(self, attr1): - res = [] if isinstance(attr1, (list, tuple)): query = dbStorage.objects.filter(owner=self._owner, attr1_in=attr1) # @UndefinedVariable else: query = dbStorage.objects.filter(owner=self._owner, attr1=attr1) # @UndefinedVariable for v in query: - res.append(v.data.decode(Storage.CODEC)) - return res + yield v.data.decode(Storage.CODEC) - def filterPickle(self, attr1=None): + def filter(self, attr1): if attr1 is None: query = dbStorage.objects.filter(owner=self._owner) # @UndefinedVariable else: query = dbStorage.objects.filter(owner=self._owner, attr1=attr1) # @UndefinedVariable for v in query: # @UndefinedVariable - yield (v.key, pickle.loads(v.data.decode(Storage.CODEC)), v.attr1) + yield (v.key, v.data.decode(Storage.CODEC), v.attr1) + + def filterPickle(self, attr1=None): + for v in self.filter(attr1): + yield (v[0], pickle.loads(v[1]), v[2]) @staticmethod def delete(owner=None): diff --git a/server/src/uds/core/util/UniqueIDGenerator.py b/server/src/uds/core/util/UniqueIDGenerator.py index fdafa272..29493472 100644 --- a/server/src/uds/core/util/UniqueIDGenerator.py +++ b/server/src/uds/core/util/UniqueIDGenerator.py @@ -60,7 +60,7 @@ class UniqueIDGenerator(object): ''' # First look for a name in the range defined stamp = getSqlDatetime(True) - logger.debug(UniqueId) + # logger.debug(UniqueId) try: UniqueId.objects.lock() # @UndefinedVariable flt = self.__filter(rangeStart, rangeEnd) @@ -74,7 +74,7 @@ class UniqueIDGenerator(object): seq = last.seq + 1 except Exception: # If there is no assigned at database seq = rangeStart - logger.debug('Found seq {0}'.format(seq)) + # logger.debug('Found seq {0}'.format(seq)) if seq > rangeEnd: return -1 # No ids free in range UniqueId.objects.create(owner=self._owner, basename=self._baseName, seq=seq, assigned=True, stamp=stamp) # @UndefinedVariable diff --git a/server/src/uds/core/workers/UserServiceCleaner.py b/server/src/uds/core/workers/UserServiceCleaner.py index bfef2b6d..d6e78f57 100644 --- a/server/src/uds/core/workers/UserServiceCleaner.py +++ b/server/src/uds/core/workers/UserServiceCleaner.py @@ -78,4 +78,7 @@ class UserServiceRemover(Job): removables = UserService.objects.filter(state=State.REMOVABLE, state_date__lt=removeFrom, deployed_service__service__provider__maintenance_mode=False)[0:UserServiceRemover.removeAtOnce] for us in removables: - UserServiceManager.manager().remove(us) + try: + UserServiceManager.manager().remove(us) + except Exception: + logger.exception('Exception invoking remove user service {}'.format(us)) diff --git a/server/src/uds/static/adm/js/gui-d-services.coffee b/server/src/uds/static/adm/js/gui-d-services.coffee index 96e39b52..0f4d2f49 100644 --- a/server/src/uds/static/adm/js/gui-d-services.coffee +++ b/server/src/uds/static/adm/js/gui-d-services.coffee @@ -155,6 +155,7 @@ gui.providers.link = (event) -> permission: api.permissions.MANAGEMENT text: maintenanceText('fa-ambulance', gettext("Maintenance")) css: "disabled" + disabled: true click: (vals, value, btn, tbl, refreshFnc) -> if vals.length > 1 diff --git a/server/src/uds/static/adm/js/gui-d-servicespools.coffee b/server/src/uds/static/adm/js/gui-d-servicespools.coffee index 41233be6..82c64f50 100644 --- a/server/src/uds/static/adm/js/gui-d-servicespools.coffee +++ b/server/src/uds/static/adm/js/gui-d-servicespools.coffee @@ -199,7 +199,7 @@ gui.servicesPools.link = (event) -> doNotLoadData: true icon: 'cached' container: "cache-placeholder_tbl" - rowSelect: "single" + rowSelect: "multi" deferRender: true doNotLoadData: true buttons: [ @@ -442,6 +442,7 @@ gui.servicesPools.link = (event) -> { text: gettext("Cancel") css: "disabled" + disabled: true click: (val, value, btn, tbl, refreshFnc) -> gui.promptModal gettext("Publish"), gettext("Cancel publication"), onYes: -> @@ -453,11 +454,14 @@ gui.servicesPools.link = (event) -> return - select: (val, value, btn, tbl, refreshFnc) -> - unless val - $(btn).removeClass("btn3d-warning").addClass "disabled" + select: (vals, self, btn, tbl, refreshFnc) -> + unless vals.length == 1 + $(btn).addClass "disabled" + $(btn).prop('disabled', true) return + val = vals[0] + if val.state == 'K' $(btn).empty().append(gettext("Force Cancel")) else @@ -465,12 +469,12 @@ gui.servicesPools.link = (event) -> # Waiting for publication, Preparing or running gui.doLog "State: ", val.state - $(btn).removeClass("disabled").addClass "btn3d-warning" if [ - "P" - "W" - "L" - "K" - ].indexOf(val.state) != -1 + if ["P", "W", "L", "K"].indexOf(val.state) != -1 + $(btn).removeClass("disabled") + $(btn).prop('disabled', false) + else + $(btn).addClass("disabled") + $(btn).prop('disabled', true) return } diff --git a/server/src/uds/static/adm/js/gui-element.coffee b/server/src/uds/static/adm/js/gui-element.coffee index 94852eb6..7d4b2ab6 100644 --- a/server/src/uds/static/adm/js/gui-element.coffee +++ b/server/src/uds/static/adm/js/gui-element.coffee @@ -381,6 +381,7 @@ type: "text" content: value.text css: css + disabled: value.disabled? and value.disabled is true if value.click btn.fnClick = () -> @@ -473,8 +474,17 @@ for btn in btns $div = $('div.'+tbId) if btn.type == 'text' + gui.doLog "Button: ", btn + btnId = gui.genRamdonId('btn') - $div.append('') + btnHtml = '