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))
def getExecutorForubuntu1214Python2(system_id,unit_type, unit_id, unit_uuid): auth = request.authorization user = User(username=auth.username, password= auth.password) system = SystemDAO(name=system_id) if not controller.db.hasAccess(user, system): message = "User not authorized" return Response(message, mimetype='text/x-python', status=403) path = ".//resources/artifacts/ubuntu-12-14/python2/remote-executor/testsExecutor.py" with open (path, "r") as myfile: USERNAME=user.username PASSWORD =user.password SERVICE_NAME=system_id UNIT_ID=unit_id data=myfile.read() data = data.replace("HEALTH_CENTRAL_QUEUE_IP='localhost'", "HEALTH_CENTRAL_QUEUE_IP='" + str(queueIP)+"'") data = data.replace("USERNAME=''", "USERNAME='******'") data = data.replace("PASSWORD=''", "PASSWORD='******'") data = data.replace("SYSTEM_NAME=''", "SYSTEM_NAME='" + str(SERVICE_NAME)+"'") data = data.replace("UNIT_UUID=''", "UNIT_UUID='" + str(unit_uuid)+"'") data = data.replace("UNIT_ID=''", "UNIT_ID='" + str(UNIT_ID)+"'") data = data.replace("UNIT_TYPE=''", "UNIT_TYPE='" + str(unit_type)+"'") return Response(data, mimetype='text/x-python')
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))
def getInstallerForubuntu1214Python2Local(system_id, unit_ID, unit_type): auth = request.authorization user = User(username=auth.username, password= auth.password) system = SystemDAO(name=system_id) if not controller.db.hasAccess(user, system): message = "User not authorized" return Response(message, mimetype='text/x-python', status=403) path = ".//resources/artifacts/ubuntu-12-14/python2/local-executor/install.sh" with open (path, "r") as myfile: data=myfile.read() data = data.replace("HEALTH_CENTRAL_IP='localhost'", "HEALTH_CENTRAL_IP='" + str(centralPublicIP)+"'") data = data.replace("HEALTH_CENTRAL_PORT=*", "HEALTH_CENTRAL_PORT='" + str(centralPort)+"'") data = data.replace("USERNAME=''", "USERNAME='******'") data = data.replace("PASSWORD=''", "PASSWORD='******'") data = data.replace("UNIT_ID=''", "UNIT_ID='" + str(unit_ID)+"'") data = data.replace("UNIT_TYPE=''", "UNIT_TYPE='" + str(unit_type)+"'") data = data.replace("SYSTEM_NAME=''", "SYSTEM_NAME='" + str(system_id)+"'") return Response(data, mimetype='text/x-python')
app = Flask(__name__) pid = str(os.getpid()) pidfile = "/tmp/health-management.pid" #create pid file if not os.path.isfile(pidfile): file(pidfile, 'w').write(pid) app.secret_key = 'H3althM@nagementS!i2stem' #expire session app.permanent_session_lifetime = timedelta(hours=3) queueIP = 'localhost' queueCredentials = User(username='******', password='******') centralIP = 'localhost' centralPublicIP = None centralPort = 5001 dbBackupInterval = 60 profilingEnabled = False databasePath = "./runtime/system_db.sql" loggingPath = "./runtime/log.log" # testsSimpleConfigPath = "./config/tests.simple.specification" # testsComplexConfigPath = "./config/tests.complex.specification" #loading system configuration config = ConfigParser.RawConfigParser()
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)