Exemplo n.º 1
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)
Exemplo n.º 2
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)
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))
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))
Exemplo n.º 6
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)
Exemplo n.º 7
0
    def initialiser(self,
                    init_message=True,
                    init_document=True,
                    connecter=True):
        """
        Initialise/reinitialise le contexte et connecte les DAOs.

        :param init_message: Si True, initialise et connecte PikaDAO
        :param init_document: Si True, initialise et connecte MongoDAO
        :param connecter: Si true, la connexion aux DAOs est ouverte immediatement
        """

        # Connecter=False pour permettre de connecter MongoDB en premier
        super().initialiser(init_message, connecter=False)

        if init_document:
            self._document_dao = MongoDAO(self._configuration)

            if connecter:
                self._document_dao.connecter()

        if connecter:
            # Connecter RabbitMQ
            self._message_dao.connecter()
    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()

# FIN TEST

print("Sent: %s" % enveloppe)

messageDao.deconnecter()
documentDao.deconnecter()
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")
Exemplo n.º 10
0
        NIVEAU_AGGREGATION_JOUR,
        date_reference=datetime.datetime(2018, 9, 24))

    generateur2.set_chemin_destination(
        ['appareils', 'senseur', 'rapport', 'quotidien'])
    generateur2.set_source(
        chemin=['appareils', 'senseur', 'lecture', 'historique'],
        groupe=['noeud', 'senseur'])

    generateur2.generer()


# --- MAIN ---
configuration = TransactionConfiguration()
configuration.loadEnvironment()
document_dao = MongoDAO(configuration)
document_dao.connecter()
helper = document_dao.information_generee_helper()


def main():
    try:
        #selection, document_resultat = test_executer_recherche1()
        #test_sauvegarder_rapport(selection, document_resultat)

        #test_executer_groupement()
        #test_generateur_documents2()
        #test_executer_groupement_calcul()
        test_generateur_aggregation1()

    finally:
Exemplo n.º 11
0
class ContexteRessourcesDocumentsMilleGrilles(ContexteRessourcesMilleGrilles):
    """ Classe helper qui permet d'initialiser et de passer les ressources (configuration, DAOs) """
    def __init__(self,
                 configuration=None,
                 message_dao=None,
                 document_dao=None,
                 additionals: list = None):
        """
        Init classe. Fournir les ressources deja initialisee ou utiliser methode initialiser().

        :param configuration: Optionnel, configuration MilleGrilles deja initialisee.
        :param message_dao: Optionnel, message_dao deja initialise.
        :param document_dao: Optionnel, document_dao deja initialise.
        :param additionals: Fichiers de config additionels a combiner
        """
        super().__init__(configuration, message_dao, additionals)
        self._document_dao: MongoDAO = cast(MongoDAO, document_dao)

    def initialiser(self,
                    init_message=True,
                    init_document=True,
                    connecter=True):
        """
        Initialise/reinitialise le contexte et connecte les DAOs.

        :param init_message: Si True, initialise et connecte PikaDAO
        :param init_document: Si True, initialise et connecte MongoDAO
        :param connecter: Si true, la connexion aux DAOs est ouverte immediatement
        """

        # Connecter=False pour permettre de connecter MongoDB en premier
        super().initialiser(init_message, connecter=False)

        if init_document:
            self._document_dao = MongoDAO(self._configuration)

            if connecter:
                self._document_dao.connecter()

        if connecter:
            # Connecter RabbitMQ
            self._message_dao.connecter()

    def fermer(self):
        super().fermer()
        try:
            self._document_dao.deconnecter()
        except:
            pass

    @property
    def document_dao(self) -> MongoDAO:
        """
        Retourne un document_dao.

        :return: Document dao.
        :raises: ValueError si document_dao n'a pas ete defini.
        """

        # if self._document_dao is None:
        #     raise ValueError("DocumentDAO n'est pas initialise")
        return self._document_dao

    @document_dao.setter
    def document_dao(self, document_dao):
        self._document_dao = document_dao
 def connecter_mongodao(self):
     self.mongo_dao = MongoDAO(self.configuration)
     self._client = self.mongo_dao.connecter()
Exemplo n.º 13
0
from millegrilles.dao.DocumentDAO import MongoDAO
from millegrilles.dao.Configuration import TransactionConfiguration

configuration = TransactionConfiguration()
configuration.loadEnvironment()

document_dao = MongoDAO(configuration)
document_dao.connecter()

document = document_dao.charger_transaction_par_id('5b9bb87ab1284a00018bbfae')

print('Document trouve: %s' % document)

document_dao.deconnecter()
from millegrilles.dao.DocumentDAO import MongoDAO
from millegrilles.dao.Configuration import TransactionConfiguration

configuration = TransactionConfiguration()
configuration.loadEnvironment()

document_dao = MongoDAO(configuration)
document_dao.connecter()
helper = document_dao.processus_helper()

# Creer document processus

id_process_doc = helper.sauvegarder_initialisation_processus(
    'MGPProcessus.testsauvegarde.sauvegarde', {"param": "valeur"})

print("Nouveau document cree pour le processus: %s" % id_process_doc)

# Creer etape #1

print("Document a l'etape initiale: %s" %
      document_dao.charger_processus_par_id(id_process_doc))

etape_1 = {
    "nom-etape": "Etape 1",
    "parametres": {
        "param": "valeur 2",
        "nombre": 23
    }
}

helper.sauvegarder_etape_processus(id_process_doc, etape_1)