class TransactionMain:
    def __init__(self):
        self.configuration = TransactionConfiguration()
        self.configuration.loadEnvironment()

        self.transactionLirePika = PikaDAO(self.configuration)
        self.callbackImpl = CallbackNouvelleTransaction()

    def connecter(self):
        self.connexionMq = self.transactionLirePika.connecter()
        self.transactionLirePika.demarrer_lecture_nouvelles_transactions(
            self.callbackImpl.callbackAvecAck)

    def deconnecter(self):
        self.transactionLirePika.deconnecter()

    # Methode principale de traitement
    def run(self):
        print("Demarrage du traitement des transactions MQ -> MongoDB")
        print("MQ Host: %s, MQ Queue: %s" %
              (self.configuration.mq_host,
               self.configuration.queue_nouvelles_transactions))

        self.connecter()

        print("Fin execution transactions MQ -> MongoDB")
class NotificationActionExempleTest:

    def __init__(self):
        self.configuration = TransactionConfiguration()
        self.configuration.loadEnvironment()

        self.message_dao = PikaDAO(self.configuration)
        self.message_dao.connecter()

        self.generateur_transaction = GenerateurTransaction(self.configuration, self.message_dao)

    def deconnecter(self):
        self.message_dao.deconnecter()

    def test1(self):

        # temps_lecture_ajuste = temps_lecture + datetime.timedelta(hours=4)
        domaine = TachesConstantes.TRANSACTION_ACTION_TACHE

        transaction_message = dict({
            TachesConstantes.LIBELLE_ID_NOTIFICATION: '5c152457e094095d8c8d314e',
            TachesConstantes.LIBELLE_ACTION: TachesConstantes.ACTION_VUE,
            TachesConstantes.LIBELLE_DATE_ATTENTE_ACTION: 180
        })

        self.generateur_transaction.soumettre_transaction(transaction_message, domaine)

        print("Sent notification domaine %s: %s" % (domaine, transaction_message))
    def __init__(self):
        self._client = None
        self._logger = logging.getLogger('TesterCertificatsMongoDB')
        self._configuration = dict()
        self.configuration = TransactionConfiguration()

        self.mongo_dao = None
    def __init__(self):
        self.configuration = TransactionConfiguration()
        self.configuration.loadEnvironment()

        self.message_dao = PikaDAO(self.configuration)
        self.message_dao.connecter()

        self.generateur_transaction = GenerateurTransaction(self.configuration, self.message_dao)
コード例 #5
0
    def __init__(self):
        self.configuration = TransactionConfiguration()
        self.configuration.loadEnvironment()
        print("Connection MongDB")
        self.document_dao = MongoDAO(self.configuration)
        self.document_dao.connecter()
        print("Connecter Pika")
        self.message_dao = PikaDAO(self.configuration)
        self.message_dao.connecter()

        self._traitement = TraitementBacklogLecturesSenseursPassifs(
            self.message_dao, self.document_dao)
コード例 #6
0
    def __init__(self):
        configuration = TransactionConfiguration()
        configuration.loadEnvironment()
        document_dao = MongoDAO(configuration)
        document_dao.connecter()

        document_ids = ['5bef321b82cc2cb5ab0e33c2', '5bef323482cc2cb5ab0e995d']

        super().__init__(configuration,
                         document_dao,
                         document_ids=document_ids,
                         intervalle_secs=5)
    def __init__(self):
        self.configuration = TransactionConfiguration()
        self.configuration.loadEnvironment()
        print("Connecter Pika")
        self.messageDao = PikaDAO(self.configuration)
        self.messageDao.connecter()
        print("Connection MongDB")
        self.documentDao = MongoDAO(self.configuration)
        self.documentDao.connecter()

        self.producteur = ProducteurDocumentSenseurPassif(
            self.messageDao, self.documentDao)
コード例 #8
0
    def connecter(self):
        gestionnaire_docker = self.__service_monitor.gestionnaire_docker
        config_connexion_docker = gestionnaire_docker.charger_config_recente('millegrille.connexion')['config']
        config_connexion = json.loads(b64decode(config_connexion_docker.attrs['Spec']['Data']))
        # clecert_monitor = self.__service_monitor.clc

        gestionnaire_certificats = self.__service_monitor.gestionnaire_certificats
        certificats = gestionnaire_certificats.certificats
        path_secrets = gestionnaire_certificats.secret_path
        ca_certs_file = certificats['pki.millegrille.cert']
        monitor_cert_file = certificats['pki.%s.cert' % ConstantesGenerateurCertificat.ROLE_MONITOR_DEPENDANT]
        monitor_key_file = path.join(path_secrets, ConstantesServiceMonitor.DOCKER_CONFIG_MONITOR_DEPENDANT_KEY + '.pem')

        node_name = config_connexion['principal_mq_url']

        additionnals = [{
            'MG_MQ_HOST': node_name,
            'MG_MQ_PORT': 5673,
            'MG_MQ_CA_CERTS': ca_certs_file,
            'MG_MQ_CERTFILE': monitor_cert_file,
            'MG_MQ_KEYFILE': monitor_key_file,
            'MG_MQ_SSL': 'on',
            'MG_MQ_AUTH_CERT': 'on',
        }]

        configuration = TransactionConfiguration()
        self.__contexte = ContexteRessourcesMilleGrilles(configuration=configuration, additionals=additionnals)

        # Connecter a MQ du noeud principal
        self.__contexte.initialiser(init_message=True, connecter=True)

        self.__traitement_messages_principal = TraitementMessagesConnexionPrincipale(self.__service_monitor, self.__contexte)
        self.__contexte.message_dao.register_channel_listener(self.__traitement_messages_principal)
class AggregationSenseursDocumentTest:
    def __init__(self):
        self.configuration = TransactionConfiguration()
        self.configuration.loadEnvironment()
        print("Connecter Pika")
        self.messageDao = PikaDAO(self.configuration)
        self.messageDao.connecter()
        print("Connection MongDB")
        self.documentDao = MongoDAO(self.configuration)
        self.documentDao.connecter()

        self.producteur = ProducteurDocumentSenseurPassif(
            self.messageDao, self.documentDao)

    def run(self):

        id_documents = self.producteur.trouver_id_documents_senseurs()
        print("Documents: %s" % str(id_documents))
コード例 #10
0
class TesterCertificatsMongoDB:
    def __init__(self):
        self._client = None
        self._logger = logging.getLogger('TesterCertificatsMongoDB')
        self._configuration = dict()
        self.configuration = TransactionConfiguration()

        self.mongo_dao = None

    def connecter(self):
        self._client = MongoClient(**self._configuration)

        self._logger.debug("Verify if connection established")
        self._client.admin.command('ismaster')

    def connecter_mongodao(self):
        self.mongo_dao = MongoDAO(self.configuration)
        self._client = self.mongo_dao.connecter()

    def preparer_configuration_interne(self):
        self._configuration['host'] = 'think003.pivoine.mdugre.info'
        self._configuration['port'] = 27017
        self._configuration['username'] = '******'
        self._configuration['password'] = '******'
        self._configuration['ssl'] = True
        self._configuration['ssl_cert_reqs'] = ssl.CERT_REQUIRED
        self._configuration[
            'ssl_certfile'] = '/usr/local/etc/millegrilles/certs/keys/millegrilles.pem.key_cert'
        self._configuration[
            'ssl_ca_certs'] = '/usr/local/etc/millegrilles/certs/millegrilles.authority.pem'

    def preparer_configuration_objet(self):
        self.configuration.loadEnvironment()
        self._configuration = self.configuration.format_mongo_config()
        self._logger.info("Configuration Mongo: %s" % str(self._configuration))

    def lire_document(self):
        coll_allo = self.mongo_dao.get_collection('coll_allo')
        # doc = {'key': 'value', 'message': 'Super!'}
        # coll_allo.insert_one(doc)

        doc = coll_allo.find_one(filter={'key': 'value'})
        self._logger.info('Document trouve: %s' % str(doc))
コード例 #11
0
class SenseursPassifsRequetesTest:
    def __init__(self):
        self.configuration = TransactionConfiguration()
        self.configuration.loadEnvironment()
        print("Connection MongDB")
        self.document_dao = MongoDAO(self.configuration)
        self.document_dao.connecter()
        print("Connecter Pika")
        self.message_dao = PikaDAO(self.configuration)
        self.message_dao.connecter()

        self._traitement = TraitementBacklogLecturesSenseursPassifs(
            self.message_dao, self.document_dao)

    def run_requete_plusrecentetransactionlecture_parsenseur(self):
        return self._traitement.run_requete_plusrecentetransactionlecture_parsenseur(
        )

    def run_requete_genererdeclencheur_parsenseur(self, liste_senseurs):
        self._traitement.run_requete_genererdeclencheur_parsenseur(
            liste_senseurs)
コード例 #12
0
class NotificationExempleTest:
    def __init__(self):
        self.configuration = TransactionConfiguration()
        self.configuration.loadEnvironment()

        self.message_dao = PikaDAO(self.configuration)
        self.message_dao.connecter()

    def deconnecter(self):
        self.message_dao.deconnecter()

    def test1(self):

        # temps_lecture_ajuste = temps_lecture + datetime.timedelta(hours=4)
        notification = dict({
            '_mg-libelle':
            'regle_simple',
            'evenements':
            Constantes.EVENEMENT_NOTIFICATION,
            'source': {
                '_collection': 'mgdomaines_appareils_SenseursPassifs',
                '_id': "5bef31be82cc2cb5ab0d57fe"
            },
            'regles': [{
                "pasbonne_10": {
                    "element": "temperature"
                }
            }],
            "date":
            int(datetime.datetime.utcnow().timestamp()),
            'valeurs': {
                "element": "temperature",
                "valeur": 24.6
            }
        })

        self.message_dao.transmettre_notification(
            notification, TachesConstantes.AVERTISSEMENT)

        print("Sent notification: %s" % notification)
def message_test():

    message_test = {
        Constantes.TRANSACTION_MESSAGE_LIBELLE_ID_MONGO:
        "5bee12bce09409b7881c0da4"
    }

    processus = "mgdomaines_appareils_SenseursPassifs:ProcessusTransactionSenseursPassifsLecture"
    demarreur.demarrer_processus(processus, message_test)

    return message_test


# --- MAIN ---

configuration = TransactionConfiguration()
configuration.loadEnvironment()
print("Connecter Pika")
messageDao = PikaDAO(configuration)
messageDao.connecter()
print("Connection MongDB")
documentDao = MongoDAO(configuration)
documentDao.connecter()

print("Envoyer message")
demarreur = MGPProcessusDemarreur(messageDao, documentDao)

# TEST

enveloppe = message_test()
from millegrilles.dao.DocumentDAO import MongoDAO
from millegrilles.dao.Configuration import TransactionConfiguration
from millegrilles.dao.MessageDAO import PikaDAO

configuration = TransactionConfiguration()

messageDao = PikaDAO(configuration)
mongoDao = MongoDAO(configuration)

mongoDao.connecter()

transaction_helper = mongoDao.transaction_helper()

print("Connecte a Mongo")

message_dummy = {"contenu": "valeur"}
enveloppe = message_dummy

mongo_id = transaction_helper.sauvegarder_nouvelle_transaction(
    mongoDao._collection_transactions, enveloppe)
print("Document Mongo id=%s a ete cree" % mongo_id)

mongoDao.deconnecter()

print("Deconnecte de Mongo")
class TestCertificatsRabbitMQ:
    def __init__(self):
        self.configuration = TransactionConfiguration()
        self.connectionmq = None
        self.channel = None

        self.message_dao = None

    def configurer(self):
        self.configuration.loadEnvironment()
        self.message_dao = PikaDAO(self.configuration)

    def preparer_connexion(self):
        connection_parameters = {
            'host': self.configuration.mq_host,
            'port': self.configuration.mq_port,
            'virtual_host': self.configuration.idmg,
            'heartbeat': 300
        }

        credentials = {
            'username': self.configuration.mq_user,
            'password': self.configuration.mq_password,
            'erase_on_connect': True
        }
        connection_parameters['credentials'] = PlainCredentials(**credentials)

        if self.configuration.mq_ssl == 'on':
            # verify_mode = ssl.CERT_NONE
            # server_hostname = None
            ssl_options = {
                'ssl_version': ssl.PROTOCOL_TLSv1_2,
                'keyfile':
                '/usr/local/etc/millegrilles/certs/keys/think003.pivoine.mdugre.info.pem',
                'certfile':
                '/usr/local/etc/millegrilles/certs/think003.pivoine.mdugre.info.cert.pem',
                'ca_certs':
                '/usr/local/etc/millegrilles/certs/millegrilles.authority.pem',
                'cert_reqs': ssl.CERT_REQUIRED
            }

            connection_parameters['ssl'] = True
            connection_parameters['ssl_options'] = ssl_options

        return connection_parameters

    def connecter_test(self):
        connection_parameters = pika.ConnectionParameters(
            **self.preparer_connexion())
        self.connectionmq = pika.BlockingConnection(connection_parameters)

    def connecter_dao(self):
        self.connectionmq = self.message_dao.connecter()

    def verifier_connexion(self):
        self.channel = self.connectionmq.channel()
        self.channel.basic_qos(prefetch_count=1)

    def transmettre_message(self):
        pass

    def fermer(self):
        self.connectionmq.close()
    def __init__(self):
        self.configuration = TransactionConfiguration()
        self.configuration.loadEnvironment()

        self.transactionLirePika = PikaDAO(self.configuration)
        self.callbackImpl = CallbackNouvelleTransaction()
    def __init__(self):
        self.configuration = TransactionConfiguration()
        self.connectionmq = None
        self.channel = None

        self.message_dao = None
コード例 #18
0
from millegrilles.dao.Configuration import TransactionConfiguration


class TestNoms:
    def test_nom_module(self):
        print(instance.__class__.__module__.replace(".", "_"))


instance = TransactionConfiguration()

test = TestNoms()
test.test_nom_module()