Exemple #1
0
    def remoteSynchronize(self, raiseExceptionOnSyncFail=False):
        """ Calls the webcast synchronization URL
            Will perform an intermediate commit before calling the URL
            or the remote server will query a non-updated state of the indico DB.
            
            raiseExceptionOnSyncFail: if True (default), we will raise a MaKaCError if calling the webcast
            synchronization URL had a problem
        """
        url = str(self.getWebcastSynchronizationURL()).strip()
        if url:

            try:
                Logger.get('webcast').info("Doing an intermediate commit...")
                DBMgr.getInstance().commit()
                Logger.get('webcast').info("Commit done.")
                Logger.get('webcast').info(
                    "Calling the webcast synchronization URL: " + url)
                answer = urlOpenWithTimeout(url, 10).read(100000).strip()
                Logger.get('webcast').info("Got answer: " + answer)
                return answer

            except HTTPError, e:
                code = e.code
                shortMessage = BaseHTTPRequestHandler.responses[code][0]
                longMessage = BaseHTTPRequestHandler.responses[code][1]

                Logger.get('webcast').error(
                    """Calling the webcast synchronization URL: [%s] triggered HTTPError: %s (code = %s, shortMessage = '%s', longMessage = '%s'"""
                    % (str(url), str(e), code, shortMessage, longMessage))

                if raiseExceptionOnSyncFail:
                    if str(code) == '404':
                        raise MaKaCError(
                            'Could not find the server at ' + str(url) +
                            "(HTTP error 404)", 'webcast')
                    elif str(code) == '500':
                        raise MaKaCError(
                            "The server at" + str(url) +
                            " has an internal problem (HTTP error 500)",
                            'webcast')
                    else:
                        raise MaKaCError(
                            "Problem contacting the webcast synchronization server. Reason: HTTPError: %s (code = %s, shortMessage = '%s', longMessage = '%s', url = '%s'"
                            "" % (str(e), code, shortMessage, longMessage,
                                  str(url)), 'webcast')

            except URLError, e:
                Logger.get('webcast').error(
                    """Calling the webcast synchronization URL: [%s] triggered exception: %s"""
                    % (str(url), str(e)))
                if raiseExceptionOnSyncFail:
                    if str(e.reason).strip() == 'timed out':
                        raise MaKaCError(
                            "The webcast synchronization URL is not responding",
                            'webcast')
                    raise MaKaCError(
                        """URLError when contacting the webcast synchronization URL: [%s]. Reason=[%s]"""
                        % (str(url), str(e.reason)), 'webcast')
Exemple #2
0
 def remoteSynchronize(self, raiseExceptionOnSyncFail = False):
     """ Calls the webcast synchronization URL
         Will perform an intermediate commit before calling the URL
         or the remote server will query a non-updated state of the indico DB.
         
         raiseExceptionOnSyncFail: if True (default), we will raise a MaKaCError if calling the webcast
         synchronization URL had a problem
     """
     url = str(self.getWebcastSynchronizationURL()).strip()
     if url:
         
         try:
             Logger.get('webcast').info("Doing an intermediate commit...")
             DBMgr.getInstance().commit()
             Logger.get('webcast').info("Commit done.")
             Logger.get('webcast').info("Calling the webcast synchronization URL: " + url)
             answer = urlOpenWithTimeout(url , 10).read(100000).strip()
             Logger.get('webcast').info("Got answer: " + answer)
             return answer
             
         except HTTPError, e:
             code = e.code
             shortMessage = BaseHTTPRequestHandler.responses[code][0]
             longMessage = BaseHTTPRequestHandler.responses[code][1]
             
             Logger.get('webcast').error("""Calling the webcast synchronization URL: [%s] triggered HTTPError: %s (code = %s, shortMessage = '%s', longMessage = '%s'""" % (str(url), str(e), code, shortMessage, longMessage))
             
             if raiseExceptionOnSyncFail:
                 if str(code) == '404':
                     raise MaKaCError('Could not find the server at ' + str(url) + "(HTTP error 404)", 'webcast')
                 elif str(code) == '500':
                     raise MaKaCError("The server at" + str(url) + " has an internal problem (HTTP error 500)", 'webcast')
                 else:
                     raise MaKaCError("Problem contacting the webcast synchronization server. Reason: HTTPError: %s (code = %s, shortMessage = '%s', longMessage = '%s', url = '%s'""" % (str(e), code, shortMessage, longMessage, str(url)), 'webcast')
             
         except URLError, e:
             Logger.get('webcast').error("""Calling the webcast synchronization URL: [%s] triggered exception: %s""" % (str(url), str(e)))
             if raiseExceptionOnSyncFail:
                 if str(e.reason).strip() == 'timed out':
                     raise MaKaCError("The webcast synchronization URL is not responding", 'webcast')
                 raise MaKaCError("""URLError when contacting the webcast synchronization URL: [%s]. Reason=[%s]"""%(str(url), str(e.reason)), 'webcast')
Exemple #3
0
def getEVOAnswer(action, arguments = {}, eventId = '', bookingId = ''):
    
    url = getRequestURL(action, arguments)
        
    Logger.get('EVO').info("""Evt:%s, booking:%s, sending request to EVO: [%s]""" % (eventId, bookingId, str(url)))
    
    try:
        answer = urlOpenWithTimeout(str(url) , secondsToWait).read(readLimit).strip() #we remove any whitespaces, etc. We won't read more than 100k characters
        Logger.get('EVO').info("""Evt:%s, booking:%s, got answer (unprocessed): [%s]""" % (eventId, bookingId, str(answer)))
        
    except HTTPError, e:
        code = e.code
        shortMessage = BaseHTTPRequestHandler.responses[code][0]
        longMessage = BaseHTTPRequestHandler.responses[code][1]
        
        Logger.get('EVO').error("""Evt:%s, booking:%s, request: [%s] triggered HTTPError: %s (code = %s, shortMessage = '%s', longMessage = '%s'""" % (eventId, bookingId, str(url), str(e), code, shortMessage, longMessage))
        
        if str(code) == '404':
            raise EVOException('Indico could not find the EVO Server at ' + getEVOOptionValueByName("httpServerLocation") + "(HTTP error 404)")
        elif str(code) == '500':
            raise EVOException("The EVO server has an internal problem (HTTP error 500)", e)
        else:
            raise EVOException("""Problem when Indico tried to contact the EVO Server.\nReason: HTTPError: %s (code = %s, shortMessage = '%s', longMessage = '%s', url = '%s'""" % (str(e), code, shortMessage, longMessage, str(url)), e)