Ejemplo n.º 1
0
 def applyChanges(self, data):
     content = self.getContent()
     changes = applyChanges(self, content, data)
     # ``changes`` is a dictionary; if empty, there were no changes
     if changes:
         #import pdb;pdb.set_trace()
         # Construct change-descriptions for the object-modified event
         descriptions = []
         for interface, attrs in changes.items():
             if interface == IAdmUtilEvent:
                 print "##### Event 2 #######"
             elif IEventIfSuperclass.isEqualOrExtendedBy(interface):
                 print "##### Superclass 2 #######"
             names = attrs.keys()
             for attr in attrs:
                 if attr.find("eventInpObjs_"
                              ) == 0:  # attribute name starts with ...
                     functionName = attr[len('eventInpObjs_'):]
                     print "attr: %s (I:%s)" % (attr, interface)
                     print "   old: ", attrs[attr]['oldval']
                     print "   new: ", attrs[attr]['newval']
                     newSet = attrs[attr]['newval']
                     oldSet = attrs[attr]['oldval']
                     if type(newSet) == type(set()) and \
                        type(oldSet) == type(set()):
                         newEntries = newSet.difference(oldSet)
                         oldEntries = oldSet.difference(newSet)
                         for oldOid in oldEntries:
                             my_catalog = zapi.getUtility(ICatalog)
                             for resObj in my_catalog.searchResults(
                                     oid_index=oldOid):
                                 if IAdmUtilEvent.providedBy(resObj):
                                     resObj.removeOidFromOutObjects(
                                         content.objectID + "." +
                                         functionName)
                                     resObj.removeInvalidOidFromInpOutObjects(
                                     )
                                     resObj._p_changed = True
                         for newOid in newEntries:
                             my_catalog = zapi.getUtility(ICatalog)
                             for resObj in my_catalog.searchResults(
                                     oid_index=newOid):
                                 if IAdmUtilEvent.providedBy(resObj):
                                     resObj.addOidToOutObjects(
                                         content.objectID + "." +
                                         functionName)
                                     resObj.removeInvalidOidFromInpOutObjects(
                                     )
                                     resObj._p_changed = True
             descriptions.append(Attributes(interface, *names))
         # Send out a detailed object-modified event
         zope.event.notify(ObjectModifiedEvent(content, *descriptions))
     return changes
Ejemplo n.º 2
0
 def processInpEQueues(self):
     my_catalog = zapi.getUtility(ICatalog)
     for senderOid in self.inpEQueues:
         inpQueue = self.inpEQueues[senderOid]
         while len(inpQueue) > 0:
             inpEvent = inpQueue.pull()
             processed = False
             for eventObj in self.values():
                 if IAdmUtilEvent.providedBy(eventObj):
                     if (senderOid in eventObj.inpObjects) and \
                        (eventObj.objectID == inpEvent.oidEventObject):
                         for receiverOid in eventObj.outObjects:
                             for receiverObj in my_catalog.searchResults(\
                                 oid_index=receiverOid):
                                 processed = True
                                 receiverObj.injectInpEQueue(inpEvent)
             if not processed:
                 for oid in self.outEQueues:
                     for receiverObj in my_catalog.searchResults(\
                         oid_index=oid):
                         if (inpEvent.oidEventObject in \
                             receiverObj.getAllInpEventObjs()):
                             processed = True
                             receiverObj.injectInpEQueue(inpEvent)
             if not processed:
                 inpEvent.stopit(self)
Ejemplo n.º 3
0
 def __init__(self, **data):
     """
     constructor of the object
     """
     Supernode.__init__(self, **data)
     for (name, value) in data.items():
         if name in IAdmUtilEvent.names():
             setattr(self, name, value)
     self.ikRevision = __version__
Ejemplo n.º 4
0
 def isUsedIn(self):
     """
     this object is used at least in one host (returns object list)
     """
     retList = []
     iid = zapi.getUtility(IIntIds, '')
     for (oid, oobj) in iid.items():
         if IHost.providedBy(oobj.object):
             if self.objectID in oobj.object.hostGroups:
                 retList.append(oobj.object)
     utilXbar = getUtility(IAdmUtilEventCrossbar)
     for (oid, obj) in utilXbar.items():
         if IAdmUtilEvent.providedBy(obj):
             if self.objectID == obj.hostGroup:
                 retList.append(obj)
     return retList
Ejemplo n.º 5
0
def AllEventInstances(dummy_context):
    """Which events are there
    """
    try:
        eventXbar = zapi.getUtility(IAdmUtilEventCrossbar, '')
    except ComponentLookupError:
        return SimpleVocabulary([])
    terms = []
    for (oid, oobj) in eventXbar.items():
        if IAdmUtilEvent.providedBy(oobj):
            if oobj.ikComment is None:
                terms.append(\
                    SimpleTerm(oobj.objectID,
                               str(oobj.objectID),
                               oobj.getDcTitle()))
            else:
                terms.append(\
                    SimpleTerm(oobj.objectID,
                               str(oobj.objectID),
                               oobj.getDcTitle() + u' - ' + oobj.ikComment))
    return SimpleVocabulary(terms)
Ejemplo n.º 6
0
    def fillDotFile(self, dotFile, mode=None):
        """generate the dot file
        """
        my_catalog = zapi.getUtility(ICatalog)
        objIdSet = set()
        objSet = set()
        eventSet = set()
        for (oid, oobj) in self.items():
            objIdSet.add(oid)
        for objId in self.inpEQueues:
            objIdSet.add(objId)
        for objId in self.outEQueues:
            objIdSet.add(objId)
        for objId in objIdSet:
            for result in my_catalog.searchResults(oid_index=objId):
                if IAdmUtilEvent.providedBy(result):
                    eventSet.add(result)
                elif IEventLogic.providedBy(result):
                    objSet.add(result)
                elif IEventLogic.providedBy(result):
                    objSet.add(result)
                elif IComponent.providedBy(result):
                    if result.isConnectedToEvent():
                        objSet.add(result)
                else:
                    pass
        print >> dotFile, '// GraphViz DOT-File'
        print >> dotFile, 'digraph "%s" {' % (zapi.getRoot(self).__name__)
        if mode and mode.lower() == "fview":
            print >> dotFile, '\tgraph [bgcolor="#E5FFF9", dpi="100.0"];'
        else:
            print >> dotFile, '\tgraph [bgcolor="#E5FFF9", size="6.2,5.2",' +\
            ' splines="true", ratio = "auto", dpi="100.0"];'
        print >> dotFile, '\tnode [fontname = "Helvetica",fontsize = 10];'
        print >> dotFile, '\tedge [style = "setlinewidth(2)", color = black];'
        print >> dotFile, '\trankdir = LR;'
        print >> dotFile, '\t// objects ----------------------------------'
        for obj in objSet:
            objGraphvizDot = IGenGraphvizDot(obj)
            objGraphvizDot.traverse4DotGenerator(dotFile,
                                                 level=1,
                                                 comments=True,
                                                 signalsOutput=True,
                                                 recursive=False)
        #print "-" * 80
        #uidutil = zapi.getUtility(IIntIds)
        #print >> dotFile, '\t// locations ----------------------------------'
        #for (oid, oobj) in uidutil.items():
        #if ILocation.providedBy(oobj.object):
        #print "Location: ", oobj.object.ikName
        #print >> dotFile, \
        #'\tsubgraph "cluster_location" { color=blue; label="location"};'
        ##elif IRoom.providedBy(oobj.object):
        ##print "Room: ", oobj.object.ikName
        ##elif ILocation.providedBy(oobj.object):
        ##print "Location: ", oobj.object.ikName
        #print "-" * 80

        print >> dotFile, '\t// events ----------------------------------'
        for event in eventSet:
            eventGraphvizDot = IGenGraphvizDot(event)
            eventGraphvizDot.traverse4DotGenerator(dotFile,
                                                   level=1,
                                                   comments=True)
        for obj in objSet:
            allInpNamesDict = obj.getAllInpEventNames()
            allOutNamesDict = obj.getAllOutEventNames()
            for inpName in allInpNamesDict.keys():
                for iObj in allInpNamesDict[inpName]:
                    print >> dotFile, '\t "%s"-> "%s":"%s"' % (
                        iObj, obj.objectID, inpName)
            for outName in allOutNamesDict.keys():
                for iObj in allOutNamesDict[outName]:
                    print >> dotFile, '\t "%s":"%s"-> "%s"' % (obj.objectID,
                                                               outName, iObj)
        print >> dotFile, '}'
        dotFile.flush()