Ejemplo n.º 1
0
    def __reattachListenerToSystems(self):
        for user in self.db.getAllUsers():
            for system in user.managedSystems:
                QueueUtil.addSystemQueueHost(self.queueIP,
                                             self.queueCredentials, system)
                QueueUtil.addUserAccessToSystem(self.queueIP,
                                                self.queueCredentials, user,
                                                system)

                self.queue.listenToMessages(
                    self.queueIP,
                    system.name,
                    binding_keys=[system.name + ".lifecycle.alive"],
                    username=user.username,
                    password=user.password,
                    exchange=system.name,
                    queueName="alive",
                    callback=self.handleReceivedAliveMessage)
                self.queue.listenToMessages(
                    self.queueIP,
                    system.name,
                    binding_keys=[system.name + ".lifecycle.dead"],
                    username=user.username,
                    password=user.password,
                    exchange=system.name,
                    queueName="dead",
                    callback=self.handleReceivedDeadMessage)

                self.queue.listenToMessages(
                    self.queueIP,
                    system.name,
                    binding_keys=[system.name + ".events"],
                    username=user.username,
                    password=user.password,
                    exchange=system.name,
                    queueName="events",
                    callback=self.handleReceivedEventMessage)

                #ensure we start with fresh Result queues, so delete all previous result queues
                for unit in self.db.getSystemUnits(system):
                    self.queue.removeQueue(self.queueIP,
                                           system.name,
                                           queueName=unit.uuid + "-Results",
                                           username=user.username,
                                           password=user.password)

                for unit in self.db.getSystemUnits(system):
                    self.queue.listenToMessages(
                        self.queueIP,
                        system.name,
                        binding_keys=[
                            system.name + "." + unit.uuid + ".results"
                        ],
                        username=user.username,
                        password=user.password,
                        exchange=unit.name,
                        queueName=unit.uuid + "-Results",
                        callback=self.testManagementEngine.
                        handleReceivedTestResults,
                    )
Ejemplo n.º 2
0
    def addSystem(self, user, system):

        user_dao = UserDAO.toDAO(user)
        system_dao = SystemDAO(name=system.name,
                               description=pickle.dumps(system))
        if not self.db.existsUser(user):
            return "Credentials for " + user.username + " not correct, or user does not exist"
        self.db.add(system_dao)

        user_dao = self.db.getUser(
            user_dao
        )  #retrieve the suer form the database to add to it the new managed service

        # managedSystemRelationship = UserSystemsDAO(user_id=user_dao.id,system_id=system_dao.id)
        # self.db.add(managedSystemRelationship)

        user_dao.managedSystems.append(system_dao)
        self.db.update(user_dao)

        QueueUtil.addSystemQueueHost(self.queueIP, self.queueCredentials,
                                     system)
        QueueUtil.addUserAccessToSystem(self.queueIP, self.queueCredentials,
                                        user, system)

        self.queue.listenToMessages(
            self.queueIP,
            system.name,
            binding_keys=[system.name + ".lifecycle.alive"],
            username=user.username,
            password=user.password,
            exchange=system.name,
            queueName="alive",
            callback=self.handleReceivedAliveMessage)
        self.queue.listenToMessages(
            self.queueIP,
            system.name,
            binding_keys=[system.name + ".lifecycle.dead"],
            username=user.username,
            password=user.password,
            exchange=system.name,
            queueName="dead",
            callback=self.handleReceivedDeadMessage)
        self.queue.listenToMessages(self.queueIP,
                                    system.name,
                                    binding_keys=[system.name + ".events"],
                                    username=user.username,
                                    password=user.password,
                                    exchange=system.name,
                                    queueName="events",
                                    callback=self.handleReceivedEventMessage)

        return system_dao