Exemple #1
0
    def OnRegisterEnd(self):
        """After registration is complete submit the query to the 
        query master"""
        # create a partial query spec dictionary
        #   set pattern name from args
        #   set notification address in spec
        #   set state as UNINITIALIZED
        querySpec = quilt_data.query_spec_create(
            name='new ' + self._args.pattern,
            state=quilt_data.STATE_UNINITIALIZED,
            patternName=self._args.pattern,
            notificationEmail=self._args.notifcation_email)

        #   set variables/values from args
        if self._args.variable is not None and len(self._args.variable) > 0:
            variables = quilt_data.var_specs_create()
            for v in self._args.variable:
                vname = v[0]
                vval = v[1]
                quilt_data.var_specs_add(variables,
                    quilt_data.var_spec_create(name=vname, value=vval))
            quilt_data.query_spec_set(querySpec, variables=variables)

        logging.info('Submiting query: ' + pprint.pformat(querySpec))

        # call remote method asyncronysly, this will return right away
        Pyro4.async(self._qm).Query(self._remotename, querySpec)

        # Validate query will be remote called from query master

        # return True to allow event loop to start running, which
        # should soon recieve a validation callback from query master

        import time

        ns = Pyro4.locateNS()
        uri = ns.lookup(self._remotename)

        for i in range(10):
            print "loop being"
            time.sleep(1)
            with Pyro4.Proxy(uri) as p:
                print "Sending", i
                Pyro4.async(p).TestMsg(i)
                print "sent", i
            print "loop end"

        return True
Exemple #2
0
    def OnRegisterEnd(self):
        """After registration is complete submit the query to the 
        query master"""
        # create a partial query spec dictionary
        #   set pattern name from args
        #   set notification address in spec
        #   set state as UNINITIALIZED
        querySpec = quilt_data.query_spec_create(
            name='new ' + self._args.pattern,
            state=quilt_data.STATE_UNINITIALIZED,
            patternName=self._args.pattern,
            notificationEmail=self._args.notification_email)

        #   set variables/values from args
        if self._args.variable is not None and len(self._args.variable) > 0:
            variables = quilt_data.var_specs_create()
            for v in self._args.variable:
                vname = v[0]
                vval = v[1]
                quilt_data.var_specs_add(variables,
                    quilt_data.var_spec_create(name=vname, value=vval))
            quilt_data.query_spec_set(querySpec, variables=variables)

        logging.info('Submitting query: ' + pprint.pformat(querySpec))

        # call remote method asynchronously, this will return right away
        with self.GetQueryMasterProxy() as qm:
            Pyro4.async(qm).Query(self._remotename, querySpec)

        logging.info('Query Submitted')

        # Validate query will be remote called from query master

        # return True to allow event loop to start running, which
        # should soon receive a validation callback from query master
        return True
Exemple #3
0
def create_src_query_spec(
        srcPatSpec, srcPatInstance, varSpecs, patVarSpecs, qid, source,
        patternName,
        varDict):
    """Helper function for filling out a srcQuerySpec with variable values"""

    srcPatVars = quilt_data.src_pat_spec_get(
        srcPatSpec, variables=True)
    if srcPatVars is None:
        return

    srcVarToVarDict = varDict[source][patternName][srcPatInstance]

    logging.debug("srcVarToVarDict: " + str(srcVarToVarDict))
    logging.debug("varDict is " + str(varDict))

    srcQueryVarSpecs = None
    # iterate the variables in the "new" 
    #   sourceQuerySpec
    for srcVarName, srcPatVarSpec in srcPatVars.items():

        # find that source variable in the pattern's 
        #   mappings
        # get the name of the query variable that maps to it
        varValue = None
        if srcVarName in srcVarToVarDict:
            varName = srcVarToVarDict[srcVarName]

            # get the value of the query variable from the
            #   querySpec, if it was given in the query spec
            varSpec = quilt_data.var_specs_tryget(varSpecs, varName)
            if varSpec is not None:
                varValue = quilt_data.var_spec_tryget(varSpec, value=True)

            if (varValue is None and patVarSpecs is not None
            and varName in patVarSpecs):
                # user did not supply value for the variable in the
                # query, but there is a default set in pattern definition
                patVarSpec = quilt_data.var_specs_tryget(
                    patVarSpecs, varName)
                # use the default in the pattern
                varValue = quilt_data.var_spec_tryget(
                    patVarSpec, default=True)

        if varValue is None:
            # pattern definer did not supply a default, check
            # to see if there is a default in the source pattern
            varValue = quilt_data.var_spec_tryget(
                srcPatVarSpec, default=True)

            if varValue is None:
                # could not determine a value for this variable
                # must throw error
                raise Exception("""No value set or default found
                    for the variable: """ + srcVarName)

        # create a source query variable value with the determined value
        srcQueryVarSpec = quilt_data.var_spec_create(
            name=srcVarName, value=varValue)
        # append it to a list of src query variables
        srcQueryVarSpecs = quilt_data.var_specs_add(
            srcQueryVarSpecs, srcQueryVarSpec)

    # Combine strings to get a name for this source query
    srcQueryName = '_'.join([qid, source, patternName])
    if srcPatInstance is not None:
        srcQueryName += "_" + str(srcPatInstance)

    # create and return a src query spec
    # TODO see Issue I001, this name may not be unique
    # logging.info("srcPatSpec looks like: " + str(srcPatSpec))
    srcPatName = quilt_data.src_pat_spec_get(srcPatSpec, name=True)

    # get whether src pattern is ordered 
    ordered = quilt_data.src_pat_spec_get(srcPatSpec, ordered=True)

    logging.debug("Creating " + srcQueryName + " from " + srcPatName)
    return quilt_data.src_query_spec_create(
        name=srcQueryName,
        srcPatternName=srcPatName,
        srcPatternInstance=srcPatInstance,
        source=source,
        ordered=ordered,
        variables=srcQueryVarSpecs)
Exemple #4
0
    def OnRegisterEnd(self):
        """Create a patternSpec dict from arguments (name, 
        VARIABLES, and VARIABLE to SOURCE_VARIABLE mappings), register
        this pattern with the query master"""

        # create the spec with it's requested name
        requestedName = self._args.name
        if requestedName is None:
            requestedName = "pattern"
        else:
            requestedName = self._args.name[0]

        patternSpec = quilt_data.pat_spec_create(name=requestedName)

        # create the specs for the variables
        variables = None
        if self._args.variable is not None:
            for v in self._args.variable:
                # create the variables section if it does not exist

                # first position of the cmd line argument is name of variable
                varName = v[0]
                varSpec = quilt_data.var_spec_create(name=varName)

                # if description was specified on cmd line, load it in the spec
                if len(v) > 1:
                    varDesc = v[1]
                    quilt_data.var_spec_set(varSpec, description=varDesc)

                # if default was specified on cmd line, load it in spec
                if len(v) > 2:
                    varDef = v[2]
                    quilt_data.var_spec_set(varSpec, default=varDef)
                variables = quilt_data.var_specs_add(variables, varSpec)

        quilt_data.pat_spec_set(patternSpec, variables=variables)

        mappings = None
        # create the specs for the variable mappings
        if self._args.mapping is not None:
            for m in self._args.mapping:
                varName = m[0]
                src = m[1]
                srcPat = m[2]
                srcVar = m[3]
                srcPatInstance = None
                if len(m) > 4:
                    srcPatInstance = m[4]



                # query variables are allowed to map to multiple
                # source variables.  Initialize a blank list if it isn't present
                # then append the new mapping information

                srcVarMappingSpec = quilt_data.src_var_mapping_spec_create(
                    name=varName,
                    sourceName=src,
                    sourcePattern=srcPat,
                    sourceVariable=srcVar,
                    sourcePatternInstance=srcPatInstance)

                mappings = quilt_data.src_var_mapping_specs_add(
                    mappings, srcVarMappingSpec)

        if mappings is not None:
            quilt_data.pat_spec_set(patternSpec, mappings=mappings)


        # if the pattern code is specified, set it in the pattern as
        #   a string
        if self._args.code is not None:
            # perform first pass parse on the pattern to ensure syntax
            # call get_pattern_vars from parser, but ignore the result
            #   this will check the syntax

            codestr = str(self._args.code)
            # store the code in the pattern
            quilt_data.pat_spec_set(patternSpec, code=codestr)

            # syntax parsing may be dependent on variables in the pattern, so
            #   generate the code str after replacing any pattern variables
            codestr = quilt_data.generate_query_code(patternSpec, None)
            quilt_parse.get_pattern_src_refs(codestr)


        # define patternSpec in the query master as a synchronous call
        # return will be the pattern name
        with self.GetQueryMasterProxy() as qm:
            patName = qm.DefinePattern(patternSpec)

        # print out pattern Name
        print 'Pattern', patName, ' defined'

        # return false (prevent event loop from beginning)

        return False