Beispiel #1
0
def findMessages(mc,custid,count):
    print 'findMessages() find ',count
    amsm = mc.getActiveMailboxStoreManager()
    ids = HashSet()
    msgs = HashSet()
    retries = 30
    while msgs.size() < count and retries > 0:
        for p in mc.getPartitionManager().listPartitions():
            if p.isReadOnly():
                continue
            print 'searching for messages to be stored in',p
            tm = amsm.findMessages([SearchConstraint(IActiveMailboxStoreManager.PROP_CUST_ID, SearchConstraintOperator.CONSTRAINT_EQUALS,int(custid))],p)
            if tm.size() > 0:
                msgs.addAll(filter(lambda x : not ids.contains(x.getMessageId()),tm))
                ids.addAll(map(lambda x : x.getMessageId(), tm))

        if msgs.size() < count:
            time.sleep(10)
        retries = retries - 1

        print 'findMessages found',msgs.size(),'ids',ids.size()

    if msgs.isEmpty():
        print 'Failed to find any messages in DB'
        raise Exception('Failed to find any messages in DB')

    if msgs.size() < count:
        print 'Warning, did not find all messages expected'

    return msgs
Beispiel #2
0
def findMessages(mc,custid,count, includeCategorizedRecipients=False):
    print 'findMessages() should find ',count
    amsm = mc.getActiveMailboxStoreManager()
    msgs = HashSet()
    retries = 15

    while msgs.size() < count and retries > 0:
        for p in mc.getPartitionManager().listPartitions():
            if p.isReadOnly():
                continue
            print 'searching for messages to be stored in',p
            tm = amsm.findMessages([SearchConstraint(IActiveMailboxStoreManager.PROP_CUST_ID, SearchConstraintOperator.CONSTRAINT_EQUALS,int(custid))],p,includeCategorizedRecipients)
            if tm.size() > 0:
                 msgs.addAll(tm)

        if msgs.size() < count:
            time.sleep(10)
        retries = retries - 1

        print 'findMessages() found',msgs.size()

    if msgs.isEmpty():
        print 'Failed to find any messages in DB'
        raise Exception('Failed to find any messages in DB')

    if msgs.size() < count:
        print 'Warning, did not find all messages expected'

    return msgs
Beispiel #3
0
def runJob(cmdArray, hosts, sleepTime=60, maxWaits=60, interimResult=None):
    finished = HashSet()
    failures = HashSet()
    pb = ProcessBuilder(cmdArray)
    done = False
    # first wait is short in case job finishes quickly
    waitTime = 10
    while not done:
        p = pb.start()
        dataOut = DataOutputStream(p.getOutputStream())
        try:
            for host in hosts:
                dataOut.writeBytes(host + "\n")
        finally:
            dataOut.close()
        p.waitFor()
        (curFinished, curFailures) = processJobResults(p.getInputStream(), interimResult)
        finished.addAll(curFinished)
        failures.addAll(curFailures)
        done = finished.size() == len(hosts)

        if not done:
            maxWaits = maxWaits - 1
            done == maxWaits == 0

        if not done:
            time.sleep(waitTime)
            waitTime = sleepTime
    return failures
Beispiel #4
0
def get_conf_mbean(conn, mbean_class, sessionId):
    conf_name = ObjectName("com.bea:Name=" + mbean_class.NAME + sessionId +
                           ",Type=" + mbean_class.TYPE)
    mbeans = HashSet()
    mbeans.addAll(conn.queryNames(conf_name, None))
    return MBeanServerInvocationHandler.newProxyInstance(
        conn,
        mbeans.iterator().next(), mbean_class, false)
Beispiel #5
0
 def sliceSpaces( spaces):
     checked = HashSet()
     slices = []
     for i, space in enumerate(spaces):
         if not checked.contains(space):
             current = MeshMaker.createNewVerticalSlice(spaces, i)
             checked.addAll(current.tiles)
             slices.append(current)
     return slices
    def getUniqueSrcIps(self, protocol=6):
        uniqueIps = HashSet()
        srcAddrSqlBuilder = SelectSqlBuilder('Agg_V5', 'srcAddr as ip', distinct=1)
        srcAddrSqlBuilder.where('prot=%d' % protocol)
        srcIps = self._sqlClient.execute(srcAddrSqlBuilder)
        if srcIps:
            uniqueIps.addAll(Arrays.asList([ipEntry.ip for ipEntry in srcIps]))

        return uniqueIps.toArray()
 def getVarsInLiveConjuncts(cls, rule, constantSentenceForms):
     """ generated source for method getVarsInLiveConjuncts """
     result = HashSet()
     for literal in rule.getBody():
         if isinstance(literal, (GdlRelation, )):
             if not SentenceModelUtils.inSentenceFormGroup(literal, constantSentenceForms):
                 result.addAll(GdlUtils.getVariables(literal))
         elif isinstance(literal, (GdlNot, )):
             if not SentenceModelUtils.inSentenceFormGroup(inner, constantSentenceForms):
                 result.addAll(GdlUtils.getVariables(literal))
     return result
    def getUniqueSrcIps(self, protocol=6):
        uniqueIps = HashSet()
        srcAddrSqlBuilder = SelectSqlBuilder('Agg_V5',
                                             'srcAddr as ip',
                                             distinct=1)
        srcAddrSqlBuilder.where('prot=%d' % protocol)
        srcIps = self._sqlClient.execute(srcAddrSqlBuilder)
        if srcIps:
            uniqueIps.addAll(Arrays.asList([ipEntry.ip for ipEntry in srcIps]))

        return uniqueIps.toArray()
Beispiel #9
0
 def applyCondensation(cls, condensationSet, rule, sentenceNameSource):
     """ generated source for method applyCondensation """
     varsInCondensationSet = HashSet()
     for literal in condensationSet:
         varsInCondensationSet.addAll(GdlUtils.getVariables(literal))
     varsToKeep = HashSet()
     for literal in condensationSet:
         varsToKeep.addAll(GdlUtils.getVariables(literal))
     varsToKeep2 = HashSet()
     varsToKeep2.addAll(GdlUtils.getVariables(rule.getHead()))
     for literal in rule.getBody():
         if not condensationSet.contains(literal):
             varsToKeep2.addAll(GdlUtils.getVariables(literal))
     varsToKeep.retainAll(varsToKeep2)
     orderedVars = ArrayList(varsToKeep)
     condenserName = sentenceNameSource.getNameWithPrefix(rule.getHead().__name__)
     condenserHead = GdlSentence()
     if orderedVars.isEmpty():
         condenserHead = GdlPool.getProposition(condenserName)
     else:
         condenserHead = GdlPool.getRelation(condenserName, orderedVars)
     condenserBody = ArrayList(condensationSet)
     condenserRule = GdlPool.getRule(condenserHead, condenserBody)
     remainingLiterals = ArrayList()
     for literal in rule.getBody():
         if not condensationSet.contains(literal):
             remainingLiterals.add(literal)
     remainingLiterals.add(condenserHead)
     modifiedRule = GdlPool.getRule(rule.getHead(), remainingLiterals)
     newRules = ArrayList(2)
     newRules.add(condenserRule)
     newRules.add(modifiedRule)
     return newRules
Beispiel #10
0
 def findAllInstancesOf_1(self, var, gdl, loc):
     """ generated source for method findAllInstancesOf_1 """
     if not self.domains.containsKey(loc):
         self.domains.put(loc, self.Domain(loc))
     rval = HashSet()
     if isinstance(gdl, (GdlRelation, )):
         while i < relation.arity():
             parent.name = relation.__name__
             parent.idx = i
             rval.addAll(self.findAllInstancesOf(var, relation.get(i), parent))
             i += 1
     elif isinstance(gdl, (GdlDistinct, )):
         #           GdlDistinct distinct = (GdlDistinct)gdl;
         # Negative context, ignore it for now
     elif isinstance(gdl, (GdlNot, )):
         #           GdlNot not = (GdlNot)gdl;
         # Negative context, ignore it for now
     elif isinstance(gdl, (GdlOr, )):
         # TODO: check that this is right, I think it may not be
         while i < or_.arity():
             pass
             i += 1
     elif isinstance(gdl, (GdlProposition, )):
         #           GdlProposition prop = (GdlProposition)gdl;
         # I think these can safely be ignored, they have no body
     elif isinstance(gdl, (GdlConstant, )):
         #           GdlConstant constant = (GdlConstant)gdl;
         # Just a constant
     elif isinstance(gdl, (GdlFunction, )):
         while i < func.arity():
             parent.name = func.__name__
             parent.idx = i
             rval.addAll(self.findAllInstancesOf(var, func.get(i), parent))
             i += 1
     elif isinstance(gdl, (GdlVariable, )):
         # This is the interesting one
         if variable == var:
             # Found what we're looking for (base case of recursion)
             if loc == None:
                 raise RuntimeException("Parent missing for a variable.")
             rval.add(self.domains.get(loc))
     elif isinstance(gdl, (GdlRule, )):
         raise RuntimeException("Shouldn't nest rules.")
     return rval
Beispiel #11
0
 def findSatisfyingInstantiations_0(self, conditions, idx, instantiation):
     """ generated source for method findSatisfyingInstantiations_0 """
     rval = HashSet()
     if idx == len(conditions):
         rval.add(instantiation)
         return rval
     cond = conditions.get(idx)
     dom = cond.dom
     assignments = None
     i = 0
     while i < len(cond.template):
         if isinstance(t, (GdlVariable, )):
             if instantiation.containsKey(v):
                 c = instantiation.get(v)
         elif isinstance(t, (GdlConstant, )):
             c = t
         if c != None:
             if assignments == None:
                 assignments = self.Assignments()
                 if len(dom.indices) > i:
                     if index.containsKey(c):
                         assignments.addAll(index.get(c))
             else:
                 if len(dom.indices) > i:
                     if index.containsKey(c):
                         assignments.retainAll(index.get(c))
                 else:
                     assignments.clear()
         i += 1
     if assignments == None:
         assignments = dom.assignments
     for a in assignments:
         while i < len(a):
             if isinstance(t, (GdlVariable, )):
                 if not instantiation.containsKey(var):
                     newInstantiation.put(var, a.get(i))
             i += 1
         rval.addAll(self.findSatisfyingInstantiations(conditions, idx + 1, newInstantiation))
     return rval
Beispiel #12
0
def search(metaclasses, regexp, options):
  print "Searching ..."
  rawResults = HashSet()
  session = Modelio.getInstance().getModelingSession()
  
  #--- (1) Add all instances of selected metaclasses 
  for metaclass in metaclasses:
    print "  searching for instance of metaclass ",metaclass.getSimpleName()," ... ",
    metaclassInstances = session.findByClass(metaclass)
    print unicode(len(metaclassInstances)),"elements found"
    rawResults.addAll(metaclassInstances)
  # remove predefined types
  predefTypes = Modelio.getInstance().getModelingSession().getModel().getUmlTypes().getBOOLEAN().getOwner()
  rawResults.remove(predefTypes)
  rawResults.remove(predefTypes.getOwner())
  print "  ==>",unicode(len(rawResults)),"elements found (primitive types excluded)"
  
  #--- (2) Check for name matching
  filteredResults = []
  try:
    if options[0] == 1:
      p = Pattern.compile(regexp)
      for result in rawResults:
        name = result.getName()
        if (p.matcher(name).matches()):
          filteredResults.append(result)
    else:
      for result in rawResults:
        if result.getName().find(regexp) != -1:
          filteredResults.append(result)
  except PatternSyntaxException:
    messageBox("The entered regular expression: '"+regexp+"' has a syntax error.")
  except IllegalArgumentException:
    messageBox("Illegal Argument Exception.")
  print "  "+unicode(len(filteredResults))+" elements selected after name filtering"
  
  #--- (3) sort results by name
  filteredResults.sort(key=lambda x:x.getName())
  return filteredResults
Beispiel #13
0
    def translateAttributes(self, context, configurationAttributes):
        print "Idp extension. Method: translateAttributes"

        # Return False to use default method
        #return False

        request = context.getRequest()
        userProfile = context.getUserProfile()
        principalAttributes = self.defaultNameTranslator.produceIdpAttributePrincipal(
            userProfile.getAttributes())
        print "Idp extension. Converted user profile: '%s' to attribute principal: '%s'" % (
            userProfile, principalAttributes)

        if not principalAttributes.isEmpty():
            print "Idp extension. Found attributes from oxAuth. Processing..."

            # Start: Custom part
            # Add givenName attribute
            givenNameAttribute = IdPAttribute("oxEnrollmentCode")
            givenNameAttribute.setValues(
                ArrayList(Arrays.asList(StringAttributeValue("Dummy"))))
            principalAttributes.add(IdPAttributePrincipal(givenNameAttribute))
            print "Idp extension. Updated attribute principal: '%s'" % principalAttributes
            # End: Custom part

            principals = HashSet()
            principals.addAll(principalAttributes)
            principals.add(UsernamePrincipal(userProfile.getId()))

            request.setAttribute(
                ExternalAuthentication.SUBJECT_KEY,
                Subject(False, Collections.singleton(principals),
                        Collections.emptySet(), Collections.emptySet()))

            print "Created an IdP subject instance with principals containing attributes for: '%s'" % userProfile.getId(
            )

            if False:
                idpAttributes = ArrayList()
                for principalAttribute in principalAttributes:
                    idpAttributes.add(principalAttribute.getAttribute())

                request.setAttribute(ExternalAuthentication.ATTRIBUTES_KEY,
                                     idpAttributes)

                authenticationKey = context.getAuthenticationKey()
                profileRequestContext = ExternalAuthentication.getProfileRequestContext(
                    authenticationKey, request)
                authContext = profileRequestContext.getSubcontext(
                    AuthenticationContext)
                extContext = authContext.getSubcontext(
                    ExternalAuthenticationContext)

                extContext.setSubject(
                    Subject(False, Collections.singleton(principals),
                            Collections.emptySet(), Collections.emptySet()))

                extContext.getSubcontext(
                    AttributeContext,
                    True).setUnfilteredIdPAttributes(idpAttributes)
                extContext.getSubcontext(AttributeContext).setIdPAttributes(
                    idpAttributes)
        else:
            print "No attributes released from oxAuth. Creating an IdP principal for: '%s'" % userProfile.getId(
            )
            request.setAttribute(ExternalAuthentication.PRINCIPAL_NAME_KEY,
                                 userProfile.getId())

        #Return True to specify that default method is not needed
        return False
Beispiel #14
0
 def findAllInstancesOf(self, var, RHS):
     """ generated source for method findAllInstancesOf """
     rval = HashSet()
     for literal in RHS:
         rval.addAll(self.findAllInstancesOf(var, literal))
     return rval
Beispiel #15
0
class GameFlow(object):
    """ generated source for class GameFlow """
    INIT = GdlPool.getConstant("init")
    TRUE = GdlPool.getConstant("true")
    NEXT = GdlPool.getConstant("next")
    turnAfterLast = int()

    # We end with a loop
    sentencesTrueByTurn = ArrayList()

    # The non-constant ones
    formsControlledByFlow = Set()
    constantForms = Set()
    constantChecker = ConstantChecker()

    def __init__(self, description):
        """ generated source for method __init__ """
        description = GdlCleaner.run(description)
        description = DeORer.run(description)
        description = VariableConstrainer.replaceFunctionValuedVariables(description)
        # First we use a sentence model to get the relevant sentence forms
        model = SentenceDomainModelFactory.createWithCartesianDomains(description)
        self.formsControlledByFlow = HashSet()
        self.formsControlledByFlow.addAll(model.getIndependentSentenceForms())
        self.formsControlledByFlow.removeAll(model.getConstantSentenceForms())
        self.constantForms = model.getConstantSentenceForms()
        self.constantChecker = ConstantCheckerFactory.createWithForwardChaining(model)
        # Figure out which of these sentences are true at each stage
        solveTurns(model)

    def solveTurns(self, model):
        """ generated source for method solveTurns """
        # Before we can do anything else, we need a topological ordering on our forms
        ordering = getTopologicalOrdering(model.getIndependentSentenceForms(), model.getDependencyGraph())
        ordering.retainAll(self.formsControlledByFlow)
        # Let's add function info to the consideration...
        functionInfoMap = HashMap()
        for form in constantForms:
            functionInfoMap.put(form, FunctionInfoImpl.create(form, self.constantChecker))
        # First we set the "true" values, then we get the forms controlled by the flow...
        # Use "init" values
        trueFlowSentences = HashSet()
        for form in constantForms:
            if form.__name__ == self.INIT:
                for initSentence in constantChecker.getTrueSentences(form):
                    trueFlowSentences.add(trueSentence)
        # Go through ordering, adding to trueFlowSentences
        addSentenceForms(ordering, trueFlowSentences, model, functionInfoMap)
        self.sentencesTrueByTurn.add(trueFlowSentences)
        while True:
            # Now we use the "next" values from the previous turn
            trueFlowSentences = HashSet()
            for sentence in sentencesPreviouslyTrue:
                if sentence.__name__ == self.NEXT:
                    trueFlowSentences.add(trueSentence)
            addSentenceForms(ordering, trueFlowSentences, model, functionInfoMap)
            # Test if this turn's flow is the same as an earlier one
            while i < len(self.sentencesTrueByTurn):
                if prevSet == trueFlowSentences:
                    # Complete the loop
                    self.turnAfterLast = i
                    break
                i += 1
            self.sentencesTrueByTurn.add(trueFlowSentences)

    @SuppressWarnings("unchecked")
    def addSentenceForms(self, ordering, trueFlowSentences, model, functionInfoMap):
        """ generated source for method addSentenceForms """
        for curForm in ordering:
            # Check against trueFlowSentences, add to trueFlowSentences
            # or check against constantForms if necessary
            # Use basic Assignments class, of course
            for alwaysTrueSentences in model.getSentencesListedAsTrue(curForm):
                trueFlowSentences.add(alwaysTrueSentences)
            for rule in model.getRules(curForm):
                while asnItr.hasNext():
                    if trueFlowSentences.contains(transformedHead):
                        asnItr.changeOneInNext(varsInHead, assignment)
                    # Go through the conjuncts
                    for literal in rule.getBody():
                        if isinstance(literal, (GdlSentence, )):
                            if curForm.matches(literal):
                                raise RuntimeException("Haven't implemented recursion in the game flow")
                            if self.constantForms.contains(conjForm):
                                if not self.constantChecker.isTrueConstant(transformed):
                                    isGoodAssignment = False
                                    asnItr.changeOneInNext(GdlUtils.getVariables(literal), assignment)
                            else:
                                if not trueFlowSentences.contains(transformed):
                                    # False sentence
                                    isGoodAssignment = False
                                    asnItr.changeOneInNext(GdlUtils.getVariables(literal), assignment)
                        elif isinstance(literal, (GdlNot, )):
                            if self.constantForms.contains(conjForm):
                                if self.constantChecker.isTrueConstant(transformed):
                                    isGoodAssignment = False
                                    asnItr.changeOneInNext(GdlUtils.getVariables(literal), assignment)
                            else:
                                if trueFlowSentences.contains(transformed):
                                    # False sentence
                                    isGoodAssignment = False
                                    asnItr.changeOneInNext(GdlUtils.getVariables(literal), assignment)
                        # Nothing else needs attention, really
                    # We've gone through all the conjuncts and are at the
                    # end of the rule
                    if isGoodAssignment:
                        trueFlowSentences.add(transformedHead)
                        if varsInHead.isEmpty():
                            break
                        else:
                            asnItr.changeOneInNext(varsInHead, assignment)
            # We've gone through all the rules

    def getNumTurns(self):
        """ generated source for method getNumTurns """
        return len(self.sentencesTrueByTurn)

    @classmethod
    def getTopologicalOrdering(cls, forms, dependencyGraph):
        """ generated source for method getTopologicalOrdering """
        # We want each form as a key of the dependency graph to
        # follow all the forms in the dependency graph, except maybe itself
        queue = LinkedList(forms)
        ordering = ArrayList(len(forms))
        alreadyOrdered = HashSet()
        while not queue.isEmpty():
            # Don't add if there are dependencies
            for dependency in dependencyGraph.get(curForm):
                if not dependency == curForm and not alreadyOrdered.contains(dependency):
                    readyToAdd = False
                    break
            # Add it
            if readyToAdd:
                ordering.add(curForm)
                alreadyOrdered.add(curForm)
            else:
                queue.add(curForm)
            # TODO: Add check for an infinite loop here
            # Or replace with code that does stratification of loops
        return ordering

    def getTurnsConjunctsArePossible(self, body):
        """ generated source for method getTurnsConjunctsArePossible """
        # We want to identify the conjuncts that are used by the
        # game flow.
        relevantLiterals = ArrayList()
        for literal in body:
            if isinstance(literal, (GdlSentence, )):
                if SentenceModelUtils.inSentenceFormGroup(sentence, self.formsControlledByFlow):
                    relevantLiterals.add(literal)
            elif isinstance(literal, (GdlNot, )):
                if SentenceModelUtils.inSentenceFormGroup(innerSentence, self.formsControlledByFlow):
                    relevantLiterals.add(literal)
        # If none are related to the game flow, then that's it. It can
        # happen on any turn.
        # if(relevantLiterals.isEmpty())
        # return getCompleteTurnSet();
        turnsPossible = HashSet(getCompleteTurnSet())
        # For each of the relevant literals, we need to see if there are assignments
        # such that
        for literal in relevantLiterals:
            if isinstance(literal, (GdlSentence, )):
                while t < self.getNumTurns():
                    if self.sentencesTrueByTurn.get(t).contains(literal):
                        turns.add(t)
                    else:
                        for s in sentencesTrueByTurn.get(t):
                            # Could be true if there's an assignment
                            if None != GdlUtils.getAssignmentMakingLeftIntoRight(literal, s):
                                turns.add(t)
                                break
                    t += 1
            elif isinstance(literal, (GdlNot, )):
                while t < self.getNumTurns():
                    if not self.sentencesTrueByTurn.get(t).contains(internal):
                        turns.add(t)
                    else:
                        for s in sentencesTrueByTurn.get(t):
                            if None != GdlUtils.getAssignmentMakingLeftIntoRight(internal, s):
                                turns.add(t)
                                break
                    t += 1
            # Accumulate turns
            # Note that all relevant conjuncts must be true, so this
            # is an intersection of when the individual conjuncts
            # could be true.
            turnsPossible.retainAll(turns)
        return turnsPossible

    completeTurnSet = None

    def getCompleteTurnSet(self):
        """ generated source for method getCompleteTurnSet """
        if self.completeTurnSet == None:
            self.completeTurnSet = HashSet()
            while i < self.getNumTurns():
                self.completeTurnSet.add(i)
                i += 1
            self.completeTurnSet = Collections.unmodifiableSet(self.completeTurnSet)
        return self.completeTurnSet

    def getSentenceForms(self):
        """ generated source for method getSentenceForms """
        return self.formsControlledByFlow

    def getSentencesTrueOnTurn(self, i):
        """ generated source for method getSentencesTrueOnTurn """
        return self.sentencesTrueByTurn.get(i)

    def getTurnAfterLast(self):
        """ generated source for method getTurnAfterLast """
        return self.turnAfterLast