def SetParameter(self, name, value): """Sets (parameter:value) pair into request. Args: name: name of parameter. value: value of parameter (integer, string, list). """ if name in self.parameters: raise exceptions.StreamPublisherServletException( "Internal Error - parameter %s is already set." % name) self.parameters[name] = value
def HandleDeleteVsRequest(self, request, response): """Handles delete virtual server request. Args: request: request object. response: response object. Raises: psycopg2.Error/Warning, PublishServeException. """ vs_name = request.GetParameter(constants.VS_NAME) if not vs_name: raise exceptions.StreamPublisherServletException( "HandleDeleteVsRequest: Missing Virtual server name.") self._publish_helper.HandleDeleteVsRequest(vs_name, response)
def DoRequest(self, request, response): """Handles request by delegating it to search publish manager.""" assert isinstance(request, http_io.Request) assert isinstance(response, http_io.Response) # Check for init failure and return an error status and appropriate message. if not self._search_publish_manager: http_io.ResponseWriter.AddJsonFailureBody( response, "Server-side Internal Error: Failure to init SearchPublisher") return try: cmd = request.GetParameter(constants.CMD) if not cmd: raise exceptions.StreamPublisherServletException( "Internal Error - Missing Request Command.") if cmd == constants.CMD_QUERY: self._search_publish_manager.HandleQueryRequest( request, response) elif cmd == constants.CMD_PING: self._search_publish_manager.HandlePingRequest( request, response) elif cmd == constants.CMD_ADD_SEARCH_DEF: self._search_publish_manager.HandleAddSearchDefRequest( request, response) elif cmd == constants.CMD_DELETE_SEARCH_DEF: self._search_publish_manager.HandleDeleteSearchDefRequest( request, response) else: raise exceptions.SearchPublishServeException( "Internal Error - Invalid Request Command: %s." % cmd) except exceptions.SearchPublishServeException as e: logger.error(e) http_io.ResponseWriter.AddJsonFailureBody(response, str(e)) except (psycopg2.Warning, psycopg2.Error) as e: logger.error(e) http_io.ResponseWriter.AddJsonFailureBody(response, str(e)) except Exception as e: logger.error(e) http_io.ResponseWriter.AddJsonFailureBody( response, "Server-side Internal Error: {0}".format(e))
def DoGet(self, request, response): """Handles request by delegating it to search push manager.""" # Check for init failure and return an error status and appropriate message. if not self._search_push_manager: if response: http_io.ResponseWriter.AddBodyElement( response, constants.HDR_STATUS_MESSAGE, "Server-side Internal Error: Failure to init SearchPusher") http_io.ResponseWriter.AddBodyElement( response, constants.HDR_STATUS_CODE, constants.STATUS_FAILURE) return try: cmd = request.GetParameter(constants.CMD) if not cmd: raise exceptions.StreamPublisherServletException( "Internal Error - Missing Request Command.") # Handle query requests. if cmd == constants.CMD_QUERY: self._search_push_manager.HandleQueryRequest(request, response) # Handle gesearch DB ping request. elif cmd == constants.CMD_PING: self._search_push_manager.HandlePingRequest(request, response) # Handle registering DB request. elif cmd == constants.CMD_ADD_DB: self._search_push_manager.HandleAddDbRequest(request, response) # Handle delete DB request. elif cmd == constants.CMD_DELETE_DB: self._search_push_manager.HandleDeleteDbRequest( request, response) # Handle sync DB request (pushing search data and creating poi tables). elif cmd == constants.CMD_SYNC_DB: self._search_push_manager.HandleSyncRequest(request, response) # Deprecated. elif cmd == constants.CMD_PUBLISH_DB: # Note: Search data publishing is deprecated after 5.0.1. Return # success to keep compatibility between Fusion 5.0.1 and Server 5.0.2 # and later versions. http_io.ResponseWriter.AddBodyElement( response, constants.HDR_STATUS_CODE, constants.STATUS_SUCCESS) # Handle garbage collecting request - deleting not used files from # publish assetroot and cleaning up postgres tables. elif cmd == constants.CMD_GARBAGE_COLLECT: self._search_push_manager.HandleGarbageCollectRequest( request, response) # Handle file transferring request. elif cmd == constants.CMD_LOCAL_TRANSFER: self._search_push_manager.HandleLocalTransferRequest( request, response) else: raise exceptions.SearchPushServeException( "Internal Error - Invalid Request Command: %s." % cmd) return except exceptions.SearchPushServeException as e: logger.error(e) http_io.ResponseWriter.AddBodyElement(response, constants.HDR_STATUS_MESSAGE, e) except (psycopg2.Warning, psycopg2.Error) as e: logger.error(e) http_io.ResponseWriter.AddBodyElement(response, constants.HDR_STATUS_MESSAGE, e) except Exception as e: logger.error(e) http_io.ResponseWriter.AddBodyElement( response, constants.HDR_STATUS_MESSAGE, "Server-side Internal Error") # Set failure status whether we reach this point. http_io.ResponseWriter.AddBodyElement(response, constants.HDR_STATUS_CODE, constants.STATUS_FAILURE)