Example #1
0
    def test_basic_query(self):
        qstr = 'find me again ' + str(random.random())
        # call quilt_submit "find me again" (check return code)
        quilt_test_core.call_quilt_script('quilt_submit.py',
            [qstr, '-y'], checkCall=False)
        # sleep a small amount
        quilt_test_core.sleep_small()
        # Use QuiltConfig, Call GetSourceManagers, for each one
        # use pyro, create proxy for the smd
        # call GetLastQuery()
        # assure it is equal to "find me again [uniqueval]"
        cfg = quilt_core.QuiltConfig()
        with quilt_core.GetQueryMasterProxy(cfg) as qm:
            smgrs = qm.GetClients("SourceManager")

            for smgr in smgrs:
                clientRec = qm.GetClientRec("SourceManager", smgr)
                with query_master.get_client_proxy(clientRec) as smgrClient:
                    lastQuery = smgrClient.GetLastQuery()
                    # after more functionality was added sources won't be called
                    # unless referenced in the query.  we should no longer
                    # see the unique query string down on the source
                    # we wouldn't anyway because it isn't the ID.  The 
                    # last query stuff was just a hack to get testing in
                    # 0.1.c1, and is added to issue list to remove
                    # TODO see ISSUE004
                    self.assertTrue(lastQuery != qstr)

            # check qmd to be sure that all quilt_submit's have unregistered
            # do this by accessing Config, finding qmd name,
            qs = qm.GetClients("QuiltSubmit")
            # make sure list is empty
            self.assertTrue(len(qs) == 0)
Example #2
0
    def OnRegisterEnd(self):
        """
        Retrieve the querySpec from the query master and issue the
        srcQueries to the source
        """
        qid = None
        try:
            # use query id passed in arguments
            if self._args.query_id is not None:
                qid = self._args.query_id[0]
            else:
                raise Exception("Query ID is required")

            # Access the QuiltQuery's registrar's host and port from the config
            config = quilt_core.QuiltConfig()
            rport = config.GetValue("registrar", "port", None, int)
            if rport is not None:
                rport = int(rport)
            rhost = config.GetValue("registrar", "host", None)
            self._registrarPort = rport
            self._registrarHost = rhost

            #   set the state to ACTIVE by calling BeginQuery
            # store pattern and query as a data member
            with self.GetQueryMasterProxy() as qm:
                self._patternSpec, self._querySpec = qm.BeginQuery(qid)

                # get the query spec from query master
                queryState = quilt_data.query_spec_get(self._querySpec,
                                                       state=True)
                if queryState != quilt_data.STATE_ACTIVE:
                    raise Exception("Query: " + qid + ", must be in " +
                                    quilt_data.STATE_ACTIVE +
                                    " state. It is currently in " +
                                    queryState + " state.")

                # iterate the sourceQuerySpec's in srcQueries list
                srcQuerySpecs = quilt_data.query_spec_tryget(
                    self._querySpec, sourceQuerySpecs=True)

                # there are no source query specs specified
                if srcQuerySpecs is None:
                    # so just don't do anything
                    self._processEvents = False
                    return

                self._srcQuerySpecs = srcQuerySpecs
                for srcQuerySpec in srcQuerySpecs.values():
                    # mark the sourceQuery ACTIVE
                    quilt_data.src_query_spec_set(srcQuerySpec,
                                                  state=quilt_data.STATE_ACTIVE)

                    # get proxy to the source manager
                    source = quilt_data.src_query_spec_get(
                        srcQuerySpec, source=True)
                    smgrRec = qm.GetClientRec("smd", source)
                    # TODO make more efficient by recycling proxies to same source
                    # in the case when making multi source queries to same source
                    with query_master.get_client_proxy(smgrRec) as smgr:
                        # query the source by sending it the source query specs as
                        #   asynchronous call
                        Pyro4.async(smgr).Query(
                            qid, srcQuerySpec, self.localname, rhost, rport)
                        # Note: no locking needed 
                        #   asynchronous call, and returning messages not
                        #   processed until this function exits

            self._processEvents = True


        except Exception, error:
            try:
                with self.GetQueryMasterProxy() as qm:
                    qm.OnQueryError(qid, error)
            except Exception, error2:
                logging.error(
                    "Unable to send query startup error to query master")
                logging.exception(error2)