Ejemplo n.º 1
0
    def handleReceivedEventMessage(self, channel, method, properties, body):
        message = pickle.loads(body)
        channel.basic_ack(delivery_tag=method.delivery_tag)

        #process message depending on type
        if message.type == MessageType.Event:
            eventEncounterInfo = message.content
            if eventEncounterInfo:
                system = Unit(name=eventEncounterInfo.sourceUnit.system,
                              type=UnitType.Composite)
                user = User(username=eventEncounterInfo.sourceUnit.username,
                            password=eventEncounterInfo.sourceUnit.password)
                unit = Unit(name=eventEncounterInfo.sourceUnit.id,
                            uuid=eventEncounterInfo.sourceUnit.uuid,
                            type=eventEncounterInfo.sourceUnit.type)
                eventEncounter = EventEncounter(
                    event_id=eventEncounterInfo.event_id,
                    timestamp=eventEncounterInfo.timestamp,
                    sourceUnit=unit)
                self.testManagementEngine.executeTestForEvent(
                    user=user, system=system, eventEncounter=eventEncounter)
            else:
                logging.warn("No content received for message " +
                             str(message.type))
        else:
            logging.warn("Received message type " + str(message.type) +
                         " instead of MessageType.Event=" +
                         str(MessageType.Event))
Ejemplo n.º 2
0
 def testEventModel(self):
     u1 = Unit("UnitA", "UnitA", type=UnitType.SoftwareContainer)
     u2 = Unit("UnitA", "UnitB", type=UnitType.SoftwareContainer)
     e = Event("E2")
     e.addTarget(u1, u2)
     print(e)
     assert e.__str__(
     ) == "{'id='E2, on='[{'id='UnitA, name='UnitA, type=SoftwareContainer, uuid=None}, {'id='UnitB, name='UnitA, type=SoftwareContainer, uuid=None}]}"
Ejemplo n.º 3
0
    def handleReceivedAliveMessage(self, channel, method, properties, body):
        message = pickle.loads(body)
        channel.basic_ack(delivery_tag=method.delivery_tag)

        #process message depending on type
        if message.type == MessageType.UnitInstanceInformation:
            unitInstanceInfo = message.content
            if unitInstanceInfo:
                user = User(username=unitInstanceInfo.username,
                            password=unitInstanceInfo.password)
                system = Unit(name=unitInstanceInfo.system,
                              type=UnitType.Composite)
                system = self.db.getSystem(system)
                unit = Unit(name=unitInstanceInfo.id,
                            uuid=unitInstanceInfo.uuid,
                            type=unitInstanceInfo.type)
                self.addSystemUnit(user=user, system=system, unit=unit)

                #persist event encounter
                eventEncounter = EventEncounter(
                    type=EventType.Added,
                    timestamp=datetime.datetime.now(),
                    system=system,
                    details=str(unitInstanceInfo.uuid))
                self.db.addEventEncounter(eventEncounter)

                self.testManagementEngine.executeTestForEvent(
                    user=user, system=system, eventEncounter=eventEncounter)

                #notify user that something was added
                subject = "[Run-Time Verification Platform] [ System: " + unitInstanceInfo.system + "] [ Unit " + str(
                    unitInstanceInfo.uuid) + "] ADDED"
                content = "Added signal received for Unit with"
                content = content + "\n ID: " + str(unitInstanceInfo.id)
                content = content + "\n Type: " + str(unitInstanceInfo.type)
                content = content + "\n UUID: " + str(unitInstanceInfo.uuid)
                user = self.db.getUser(user)
                MailUtil.sendMail(user.mailAddress, user.mailUsername,
                                  user.mailPassword, user.smtpServerName,
                                  user.smtpServerPort, subject, content)
            else:
                logging.warn("No content received for message " +
                             str(message.type))
        else:
            logging.warn("Received message type " + str(message.type) +
                         " instead of MessageType.UnitInstanceInformation=" +
                         str(MessageType.UnitInstanceInformation))
Ejemplo n.º 4
0
 def getLatestCompleteSystemStructure(self, user, system):
     systemDescription = self.db.getSystem(system)
     staticSystemDescription = pickle.loads(systemDescription.description)
     completeStructure = Unit(name=system.name, type=UnitType.Composite)
     systemUnits = self.db.getSystemUnits(systemDescription)
     for unit in systemUnits:
         self.systemStructureManagementEngine.addUnitInstance(
             staticSystemDescription, completeStructure, unit.toUnit())
     return completeStructure
Ejemplo n.º 5
0
    def convertJSONToSystem(jsonText):
        systemUnits = {}  #units structured by

        json_acceptable_string = jsonText.replace("'", "\"").replace(
            "\t", "").replace("\r", "").replace("\n", "")
        dict = json.loads(json_acceptable_string)

        system = Unit(name=dict['name'])
        JSONConverter.__convertJSONToSystem(system, dict, systemUnits)
        return system
Ejemplo n.º 6
0
    def __convertJSONToSystem(parent, parent_info, systemUnits):

        if 'containedUnits' in parent_info:
            for unitInfo in parent_info['containedUnits']:
                if not UnitType.isValid(unitInfo['type']):
                    raise ValueError("Invalid unit type " + unitInfo['type'])
                unit = Unit(name=unitInfo['name'], type=unitInfo['type'])
                if 'hostedOn' in unitInfo:
                    hostedOnName = unitInfo['hostedOn']
                    if hostedOnName in systemUnits.keys():
                        systemUnits[hostedOnName].hosts(unit)
                        unit.hostedOn = systemUnits[hostedOnName]
                    else:
                        raise ValueError(hostedOnName + " not found in declared system units so far")

                systemUnits[unit.name] = unit
                parent.consistsOf(unit) #adding only parent complex units in the system directly. rest are sub units of the complex units
                JSONConverter.__convertJSONToSystem(unit,unitInfo, systemUnits)
        return parent
Ejemplo n.º 7
0
    def __convertJSONToSystem(parent, parent_info, systemUnits):

        if 'containedUnits' in parent_info:
            for unitInfo in parent_info['containedUnits']:
                if not UnitType.isValid(unitInfo['type']):
                    raise ValueError("Invalid unit type " + unitInfo['type'])
                unit = Unit(name=unitInfo['name'], type=unitInfo['type'])
                if 'hostedOn' in unitInfo:
                    hostedOnName = unitInfo['hostedOn']
                    if hostedOnName in systemUnits.keys():
                        systemUnits[hostedOnName].hosts(unit)
                        unit.hostedOn = systemUnits[hostedOnName]
                    else:
                        raise ValueError(
                            hostedOnName +
                            " not found in declared system units so far")

                systemUnits[unit.name] = unit
                parent.consistsOf(
                    unit
                )  #adding only parent complex units in the system directly. rest are sub units of the complex units
                JSONConverter.__convertJSONToSystem(unit, unitInfo,
                                                    systemUnits)
        return parent
Ejemplo n.º 8
0
     def testCreateDeleteUnit(self):


        # self.assertTrue(vmLB.containedUnits)
        # self.assertFalse(len(haproxy.containedUnits) > 0)

        commands.getoutput("rm /tmp/A.sql")
        databasePath ="/tmp/A.sql"
        db = DatabaseManagement(dbPath= databasePath)

        vmLB = Unit(name="VM.LoadBalancer", type=UnitType.VirtualMachine)
        haproxy = Unit(name="HAProxy", type=UnitType.Process)
        proxyConfigService = Unit(name="ConfigService", type=UnitType.Process)

        vmLB.hosts(proxyConfigService, haproxy)

        mqtt = Unit(name="LoadBalancer", type=UnitType.Composite, containedUnits=[vmLB, haproxy, proxyConfigService])

        vmEP = Unit(name="VM.EventProcessing", type=UnitType.VirtualMachine)
        dassWS = Unit(name="EventProcessingService", type=UnitType.Process)

        vmEP.hosts(dassWS)
        eventProcessing = Unit(name="EventProcessing", type=UnitType.Composite, containedUnits=[vmEP, dassWS])

        eventProcessing.connectsTo(haproxy)

        service = Unit(name="System", type=UnitType.Composite, containedUnits=[mqtt, eventProcessing])

        system_dao = SystemDAO(name=service.name, description = pickle.dumps(service))

        db.add(system_dao)

        system_dao = SystemDAO(name=service.name, description = pickle.dumps(service))

        system = db.getSystem(system_dao)

        db.add(UnitDAO.toDAO(vmLB,system.id))

        unit = db.getUnit(UnitDAO.toDAO(vmLB,system.id),system)

        print unit.name
    def testAdditiion(self):
        vmLB = Unit(id="VM.LoadBalancer", type=UnitType.VirtualMachine)
        haproxy = Unit(id="HAProxy", type=UnitType.Process)
        proxyConfigService = Unit(id="ConfigService", type=UnitType.Process)
        vmLB.consistsOf(proxyConfigService)

        print yaml.dump(vmLB.containedUnits, default_flow_style=False)
        print yaml.dump(haproxy.containedUnits, default_flow_style=False)

        self.assertTrue(vmLB.containedUnits)
        self.assertFalse(len(haproxy.containedUnits) > 0)
Ejemplo n.º 10
0
    def getLastTestSessionStatus(self, user, system):
        systemDAO = self.getLatestCompleteSystemStructure(user, system)
        units = []
        units.append(systemDAO)

        testsSession = self.db.getLastTestSessionForSystem(
            self.db.getSystem(system))

        if not testsSession:  #if no test session for system
            return systemDAO

        testExecutions = testsSession.calledTests

        while len(units) > 0:
            currentUnit = units.pop(0)
            currentUnit.testsStatus = {}
            for child in currentUnit.containedUnits:
                units.append(child)

            for testExecution in testExecutions:
                if currentUnit.id == testExecution.target_unit_id:
                    if not testExecution.finalized:
                        testExecutorInfo = Unit(
                            uuid=testExecution.executor_unit_uuid,
                            id=testExecution.executor_unit_type_id,
                            name=testExecution.executor_unit_name)
                        testResult = TestResultDAO(
                            test_id=testExecution.test_id,
                            execution_id=testExecution.id,
                            executorUnit=testExecutorInfo,
                            targetUnit=self.db.getTargetUnitForTestExecution(
                                testExecution),
                            successful=False,
                            details="Executing")
                    else:
                        testResult = self.db.getTestResultForExecution(
                            testExecution)
                    test = testResult.test
                    currentUnit.testsStatus[
                        test.name] = testResult.toTestResult()

        systemDAO.testSession = {}
        systemDAO.testSession['timestamp'] = testsSession.timestamp
        systemDAO.testSession['reason'] = testsSession.reason
        return systemDAO
Ejemplo n.º 11
0
    def test_add_remove(self):
        vmLB = Unit(id="VM.LoadBalancer", type=UnitType.VirtualMachine)
        haproxy = Unit(id="HAProxy", type=UnitType.Process)
        proxyConfigService = Unit(id="ConfigService", type=UnitType.Process)

        vmLB.hosts(proxyConfigService, haproxy)

        mqtt = Unit(id="LoadBalancer",
                    type=UnitType.Composite,
                    containedUnits=[vmLB, haproxy, proxyConfigService])

        vmEP = Unit(id="VM.EventProcessing", type=UnitType.VirtualMachine)
        dassWS = Unit(id="EventProcessingService", type=UnitType.Process)

        vmEP.hosts(dassWS)
        eventProcessing = Unit(id="EventProcessing",
                               type=UnitType.Composite,
                               containedUnits=[vmEP, dassWS])

        eventProcessing.connectsTo(haproxy)

        service = Unit(id="System",
                       type=UnitType.Composite,
                       containedUnits=[mqtt, eventProcessing])

        runt_time_service = Unit(
            id="System", type=UnitType.Composite,
            containedUnits=[])  #pickle.loads(pickle.dumps(service))

        print yaml.dump(service, default_flow_style=False) == yaml.dump(
            runt_time_service, default_flow_style=False)

        newEventProcessingVM = Unit(id="EventProcessingService",
                                    type=UnitType.Process,
                                    uuid="10.9.9.1-12345")

        engine = SystemStructureManagementEngine()

        pathToNewlyAdded = engine.getPathToUnitByType(service,
                                                      newEventProcessingVM,
                                                      path=[])
        lastFromPath = pathToNewlyAdded.pop().id
        print "|" + lastFromPath + "|"
        print "|" + newEventProcessingVM.id + "|"
        self.assertTrue(lastFromPath == newEventProcessingVM.id)

        engine.addUnitInstance(service, runt_time_service,
                               newEventProcessingVM)
        pathToNewlyAdded = engine.getPathToUnitByType(runt_time_service,
                                                      newEventProcessingVM,
                                                      path=[])
        lastFromPath = pathToNewlyAdded.pop().uuid
        print "|" + lastFromPath + "|"
        print "|" + newEventProcessingVM.uuid + "|"
        self.assertTrue(lastFromPath == newEventProcessingVM.uuid)

        engine.removeUnitInstance(runt_time_service, newEventProcessingVM)
        pathToRemoved = engine.getPathToUnitByType(runt_time_service,
                                                   newEventProcessingVM,
                                                   path=[])
        print "|" + str(pathToRemoved) + "|"
        self.assertFalse(pathToRemoved)

        newEventProcessingVM = Unit(id="EventProcessingService",
                                    type=UnitType.Process,
                                    uuid="10.9.9.1-1111")
        engine.addUnitInstance(service, runt_time_service,
                               newEventProcessingVM)
        pathToNewlyAdded = engine.getPathToUnitByType(runt_time_service,
                                                      newEventProcessingVM,
                                                      path=[])
        lastFromPath = pathToNewlyAdded.pop().uuid
        print "|" + lastFromPath + "|"
        print "|" + newEventProcessingVM.uuid + "|"
        self.assertTrue(lastFromPath == newEventProcessingVM.uuid)
Ejemplo n.º 12
0
    def test_dispatching_tests(self):
        vmLB = Unit(id="VM.LoadBalancer", type=UnitType.VirtualMachine)
        haproxy = Unit(id="HAProxy", type=UnitType.Process)
        proxyConfigService = Unit(id="ConfigService", type=UnitType.Process)

        vmLB.hosts(proxyConfigService, haproxy)

        mqtt = Unit(id="LoadBalancer",
                    type=UnitType.Composite,
                    containedUnits=[vmLB, haproxy, proxyConfigService])

        vmEP = Unit(id="VM.EventProcessing", type=UnitType.VirtualMachine)
        dassWS = Unit(id="EventProcessingService", type=UnitType.Process)

        vmEP.hosts(dassWS)
        eventProcessing = Unit(id="EventProcessing",
                               type=UnitType.Composite,
                               containedUnits=[vmEP, dassWS])

        eventProcessing.connectsTo(haproxy)

        service = Unit(id="service1",
                       type=UnitType.Composite,
                       containedUnits=[mqtt, eventProcessing])

        runt_time_service = Unit(
            id="service1", type=UnitType.Composite,
            containedUnits=[])  #pickle.loads(pickle.dumps(service))

        print yaml.dump(service, default_flow_style=False) == yaml.dump(
            runt_time_service, default_flow_style=False)

        newEventProcessingVM = Unit(id="EventProcessingService",
                                    type=UnitType.Process,
                                    uuid="10.9.9.1-12345")

        engine = SystemStructureManagementEngine()
        engine.addUnitInstance(service, runt_time_service,
                               newEventProcessingVM)
        pathToNewlyAdded = engine.getPathToUnitByType(runt_time_service,
                                                      newEventProcessingVM,
                                                      path=[])
        lastFromPath = pathToNewlyAdded.pop().uuid
        print "|" + lastFromPath + "|"
        print "|" + newEventProcessingVM.uuid + "|"
        self.assertTrue(lastFromPath == newEventProcessingVM.uuid)

        testDispatcher = TestDispatchEngine(
            configPath=
            '/home/daniel-tuwien/Documents/DSG_SVN/papers/MonitoringAndAnalyticsPlatform/python_framework/unittsts/testConfig/tests.simple.specification',
            queueIP='128.130.172.216')
        credentials = pika.PlainCredentials('service1', 'service1')
        testDispatcher.dispatchTests(runt_time_service, credentials)
Ejemplo n.º 13
0
    def test_dispatching_tests(self):

        commands.getoutput("rm ./test_db.sql")

        FORMAT = "[%(filename)s:%(lineno)s - %(funcName)20s() ] %(message)s"
        logging.basicConfig(format=FORMAT)
        logging.basicConfig(level=logging.DEBUG)

        controller = Controller(queueCredentials=pika.PlainCredentials(
            'mela', 'mela'),
                                queueIP='128.130.172.230',
                                dbPath="./test_db.sql")

        user = User(username="******", password="******")
        controller.addUser(user)

        vmLB = Unit(name="VM.LoadBalancer", type=UnitType.VirtualMachine)
        haproxy = Unit(name="HAProxy", type=UnitType.Process)
        proxyConfigService = Unit(name="ConfigService", type=UnitType.Process)
        vmLB.hosts(proxyConfigService, haproxy)

        mqtt = Unit(name="LoadBalancer",
                    type=UnitType.Composite,
                    containedUnits=[vmLB, haproxy, proxyConfigService])

        # controller.addSystem(user, mqtt)
        # retrieved = controller.db.getUnit(mqtt).toUnit()

        vmEP = Unit(name="VM.EventProcessing", type=UnitType.VirtualMachine)
        dassWS = Unit(name="EventProcessingService", type=UnitType.Process)

        vmEP.hosts(dassWS)
        eventProcessing = Unit(name="EventProcessing",
                               type=UnitType.Composite,
                               containedUnits=[vmEP, dassWS])

        eventProcessing.connectsTo(haproxy)

        system = Unit(name="MYSYSTEEEEM",
                      type=UnitType.Composite,
                      containedUnits=[eventProcessing, mqtt])

        system = controller.addSystem(user, system)

        extracted_run_time = controller.db.getSystem(Unit(name=system.name))

        newEventProcessingservice = Unit(name="EventProcessingService",
                                         type=UnitType.Process,
                                         uuid="10.9.9.1-12345")
        controller.addSystemUnit(user, system, newEventProcessingservice)

        extracted_run_time = controller.db.getUnit(
            Unit(name=newEventProcessingservice.name,
                 type=newEventProcessingservice.type,
                 uuid=newEventProcessingservice.uuid), system)

        newEventProcessingVM = Unit(name="VM.EventProcessing",
                                    type=UnitType.VirtualMachine,
                                    uuid="10.9.9.1")
        controller.addSystemUnit(user, system, newEventProcessingVM)

        newEventProcessingVM1 = Unit(name="VM.EventProcessing",
                                     type=UnitType.VirtualMachine,
                                     uuid="10.9.9.2")
        controller.addSystemUnit(user, system, newEventProcessingVM1)

        # print(yaml.dump(system, default_flow_style=False))

        # controller.dispatchTests(user, system)
        # #
        # #
        #
        # #TODO; to implement this
        # status = controller.getLastTestsStatus(user,system)
        #
        # representation =   json.dumps(JSONConverter.systemToJSON(status), separators=(',',':'))
        # print representation

        #TODO: add timestamps on messages and somehow record maybe when what was created

        # time.sleep(10)

        controller.removeSystemUnit(user, system, newEventProcessingservice)

        # time.sleep(10)

        controller.removeSystemUnit(user, system, newEventProcessingVM)

        # time.sleep(10)

        controller.removeSystem(user, system)

        controller.removeUser(user)
Ejemplo n.º 14
0
    def testCreateDeleteUnit(self):

        # self.assertTrue(vmLB.containedUnits)
        # self.assertFalse(len(haproxy.containedUnits) > 0)

        commands.getoutput("rm /tmp/A.sql")
        databasePath = "/tmp/A.sql"
        db = DatabaseManagement(dbPath=databasePath)

        vmLB = Unit(name="VM.LoadBalancer", type=UnitType.VirtualMachine)
        haproxy = Unit(name="HAProxy", type=UnitType.Process)
        proxyConfigService = Unit(name="ConfigService", type=UnitType.Process)

        vmLB.hosts(proxyConfigService, haproxy)

        mqtt = Unit(name="LoadBalancer",
                    type=UnitType.Composite,
                    containedUnits=[vmLB, haproxy, proxyConfigService])

        vmEP = Unit(name="VM.EventProcessing", type=UnitType.VirtualMachine)
        dassWS = Unit(name="EventProcessingService", type=UnitType.Process)

        vmEP.hosts(dassWS)
        eventProcessing = Unit(name="EventProcessing",
                               type=UnitType.Composite,
                               containedUnits=[vmEP, dassWS])

        eventProcessing.connectsTo(haproxy)

        service = Unit(name="System",
                       type=UnitType.Composite,
                       containedUnits=[mqtt, eventProcessing])

        system_dao = SystemDAO(name=service.name,
                               description=pickle.dumps(service))

        db.add(system_dao)

        system_dao = SystemDAO(name=service.name,
                               description=pickle.dumps(service))

        system = db.getSystem(system_dao)

        db.add(UnitDAO.toDAO(vmLB, system.id))

        unit = db.getUnit(UnitDAO.toDAO(vmLB, system.id), system)

        print unit.name
     def test_dispatching_tests(self):


        commands.getoutput("rm ./test_db.sql")

        FORMAT = "[%(filename)s:%(lineno)s - %(funcName)20s() ] %(message)s"
        logging.basicConfig(format=FORMAT)
        logging.basicConfig(level=logging.DEBUG)

        controller = Controller(queueCredentials= pika.PlainCredentials('mela', 'mela'),
                                queueIP='128.130.172.230', dbPath="./test_db.sql")

        user = User(username="******", password="******")
        controller.addUser(user)

        vmLB = Unit(name="VM.LoadBalancer", type=UnitType.VirtualMachine)
        haproxy = Unit(name="HAProxy", type=UnitType.Process)
        proxyConfigService = Unit(name="ConfigService", type=UnitType.Process)
        vmLB.hosts(proxyConfigService, haproxy)

        mqtt = Unit(name="LoadBalancer", type=UnitType.Composite, containedUnits=[vmLB, haproxy, proxyConfigService])

        # controller.addSystem(user, mqtt)
        # retrieved = controller.db.getUnit(mqtt).toUnit()


        vmEP = Unit(name="VM.EventProcessing", type=UnitType.VirtualMachine)
        dassWS = Unit(name="EventProcessingService", type=UnitType.Process)

        vmEP.hosts(dassWS)
        eventProcessing = Unit(name="EventProcessing", type=UnitType.Composite, containedUnits=[vmEP, dassWS])


        eventProcessing.connectsTo(haproxy)


        system =  Unit(name="MYSYSTEEEEM", type=UnitType.Composite, containedUnits=[eventProcessing, mqtt])


        system = controller.addSystem(user,system )

        extracted_run_time = controller.db.getSystem(Unit(name=system.name))



        newEventProcessingservice= Unit(name="EventProcessingService", type=UnitType.Process, uuid="10.9.9.1-12345" )
        controller.addSystemUnit(user, system, newEventProcessingservice)

        extracted_run_time = controller.db.getUnit(Unit(name=newEventProcessingservice.name, type=newEventProcessingservice.type, uuid=newEventProcessingservice.uuid ), system)


        newEventProcessingVM = Unit(name="VM.EventProcessing", type=UnitType.VirtualMachine, uuid="10.9.9.1" )
        controller.addSystemUnit(user, system, newEventProcessingVM)

        newEventProcessingVM1 = Unit(name="VM.EventProcessing", type=UnitType.VirtualMachine, uuid="10.9.9.2" )
        controller.addSystemUnit(user, system, newEventProcessingVM1)

        # print(yaml.dump(system, default_flow_style=False))

        # controller.dispatchTests(user, system)
        # #
        # #
        #
        # #TODO; to implement this
        # status = controller.getLastTestsStatus(user,system)
        #
        # representation =   json.dumps(JSONConverter.systemToJSON(status), separators=(',',':'))
        # print representation


       #TODO: add timestamps on messages and somehow record maybe when what was created





        # time.sleep(10)

        controller.removeSystemUnit(user, system, newEventProcessingservice)

        # time.sleep(10)

        controller.removeSystemUnit(user, system, newEventProcessingVM)


        # time.sleep(10)

        controller.removeSystem(user, system)

        controller.removeUser(user)