예제 #1
0
    def AppendQueryResults(self, queryId, results):
        """
        Append the specified eventList to the specified queryId
        """
        try:
            # acquire lock
            with self.lock:
                # Get query from Q
                querySpec = quilt_data.query_specs_get(self._queries, queryId)
                # Try to get any existing results then
                #   append the results into the query spec

                # set the results into the query spec
                existingEvents = quilt_data.query_spec_tryget(
                    querySpec, results=True)

                if existingEvents is None:
                    existingEvents = []

                # append the results into the query spec
                quilt_data.query_spec_set(querySpec,
                    results=(existingEvents + results))

        except Exception, error:
            try:
                # log exception here, because there is no detail in it once we 
                #   pass it across pyro
                logging.error("Unable append results for query: " +
                              str(queryId))
                logging.exception(error)
            finally:
                # throw the exception back over to the calling process
                raise error
예제 #2
0
    def GetQueryHistoryStats(self, queryId=None):
        """
        format a string with information about the specified query
        from the history, or provide stats for all if no queryId is 
        specified
        """
        try:
            results = None
            # acquire lock
            with self.lock:
            # if queryID specified
                if queryId is not None:
                    # throw error if query not found in history, 
                    # otherwise return the query's record
                    if queryId not in self._history:
                        raise Exception("query id: " + str(queryId) +
                                        " is not present in history")
                    results = pprint.pformat(quilt_data.query_specs_get(
                        self._history, queryId))
                else:
                    # return complete history summary
                    results = pprint.pformat(self._history.keys())

            return results

        except Exception, e:
            logging.exception(e)
            raise
예제 #3
0
    def BeginQuery(self, queryId):
        """
        string queryID          # the query we are interested in
        
        Called by quilt_query to Move a query into the an active state,
        and return a copy of the query
        """

        try:
            logging.info("Beginning query: " + str(queryId))
            patternSpec = None

            # lock self
            with self.lock:

                # get the query from the Q
                # if can't get it raise exception
                querySpec = quilt_data.query_specs_get(self._queries, queryId)

                queryState = quilt_data.query_spec_get(querySpec, state=True)
                # if query state is not expected INITIALIZED state
                if queryState != quilt_data.STATE_INITIALIZED:
                    # raise exception
                    raise Exception("Query: " + str(queryId) +
                                    " is not ready for processing")

                # move query to ACTIVE state
                quilt_data.query_spec_set(querySpec,
                    state=quilt_data.STATE_ACTIVE)

                # create a  copy of the query
                querySpec = querySpec.copy()

                # get a copy of the patternSpec
                patternSpec = quilt_data.pat_specs_get(self._patterns,
                    quilt_data.query_spec_get(querySpec, patternName=True))
                patternSpec = patternSpec.copy()

            # returning copy because we don't want to stay locked when asking
            #   pyro to marshall across process bounds.  Not that I know for
            #   a fact that that won't work, but it sounds like a bad idea
            # return the pattern and query spec 
            return patternSpec, querySpec

        except Exception, error:
            try:
                # log exception here, because there is no detail in it once we 
                #   pass it across pyro
                logging.error("Unable begin query: " + str(queryId))
                logging.exception(error)
            finally:
                # throw the exception back over to the calling process
                raise error