예제 #1
0
    def put(self):
        """
        """
        start_time = time.time()
        prevTimer = time.time()
        editedJobs = []

        nodes = self.getDispatchTree().nodes[1].children
        totalNodes = len(nodes)

        #
        # Getting new value, we check its presence in args, type (int) and range (>-1)
        #
        try:
            newMaxRn = int(
                self.get_argument('value')
            )  # Tornado raises a MissingArgumentError if not present
        except ValueError:
            raise Http400(
                'Bad request:  invalid value, maxRN must be an integer')

        if newMaxRn < -1:
            raise Http400(
                'Bad request: invalid value, maxRN cannot be lower than -1')

        #
        # Filtering nodes
        #
        nodes = self.filterNodes(self.request.arguments, nodes)

        #
        # Perform action
        #
        for currNode in nodes:
            try:
                currNode.maxRN = newMaxRn
                editedJobs.append(currNode.id)
            except:
                raise Http500('Error changing status of job: %d.', currNode.id)

        #
        # Prepare response and return
        #
        content = {
            'summary': {
                'editedCount': len(editedJobs),
                'filteredCount': len(nodes),
                'totalInDispatcher': totalNodes,
                'requestTime': time.time() - start_time,
                'requestDate': time.ctime()
            },
            'editedJobs': editedJobs
        }
        self.writeCallback(json.dumps(content))
예제 #2
0
 def __call__(self, request, *args, **kwargs):
     try:
         method = self.mappingDict[request.command]
     except KeyError:
         return Http405(allowed=self.mappingDict.keys())
     try:
         return method(request, *args, **kwargs)
     except Exception:
         logger.exception(
             'Unexpected exception caught while routing url "%s" for method "%s"'
             % (request.path, request.command))
         return Http500()
예제 #3
0
    def post(self):
        '''
        '''
        try:
            result = {'return_code': True}
            self.write(json.dumps(result))
            tornado.ioloop.IOLoop.instance().add_callback(
                self.framework.application.shutdown)
            tornado.ioloop.IOLoop.instance().add_callback(
                tornado.ioloop.IOLoop.instance().stop)

        except Exception, e:
            raise Http500("Error during server restart: %s" % e)
예제 #4
0
 def post(self):
     '''
     Reload the main config file (using singletonconfig) and reload
     every main loggers.
     '''
     try:
         singletonconfig.reload()
         logLevel = singletonconfig.get('CORE', 'LOG_LEVEL')
         logging.getLogger().setLevel(logLevel)
         logging.getLogger('main').setLevel(logLevel)
         logging.getLogger("worker").setLevel(logLevel)
     except Exception, e:
         raise Http500("Error during server reconfig: %r" % e)
예제 #5
0
    def put(self):
        """

        """
        start_time = time.time()
        prevTimer = time.time()
        editedJobs = []

        nodes = self.getDispatchTree().nodes[1].children
        totalNodes = len(nodes)

        args = self.request.arguments

        if 'update_status' in args:
            newStatus = int(args['update_status'][0])
        else:
            raise Http400('New status could not be found.')

        if newStatus not in NODE_STATUS:
            raise Http400("Invalid status given: %d" % newStatus)

        # # Optional argument to allow job to be restarted (if defined) or only resumed (if nothing defined)
        # if 'update_option' in args:
        #     if args['update_option'][0] == "restart" :
        #         restartNode = True

        nodes = self.filterNodes(args, nodes)

        for currNode in nodes:
            # logger.info("Changing status for job : %d -- %s" % ( currNode.id, currNode.name ) )
            try:
                if self.setStatusForNode(newStatus, currNode) is not None:
                    editedJobs.append(currNode.id)
            except:
                raise Http500('Error changing status.')

        content = {
            'summary': {
                'editedCount': len(editedJobs),
                'filteredCount': len(nodes),
                'totalInDispatcher': totalNodes,
                'requestTime': time.time() - start_time,
                'requestDate': time.ctime()
            },
            'editedJobs': editedJobs
        }

        # Create response and callback
        self.writeCallback(json.dumps(content))
예제 #6
0
    def delete(self, licenseName):
        data = self.getBodyAsJSON()
        try:
            rns = data['rns']
        except KeyError:
            raise Http404("Missing entry : 'rns'")
        else:
            rnsList = rns.split(",")
            for rnName in rnsList:
                if rnName in self.dispatcher.dispatchTree.renderNodes:
                    rn = self.dispatcher.dispatchTree.renderNodes[rnName]
                else:
                    raise Http500(
                        "Internal Server Error: Render node %s is not registered."
                        % (rnName))

                self.dispatcher.licenseManager.releaseLicenseForRenderNode(
                    licenseName, rn)
            self.writeCallback("OK")