コード例 #1
0
ファイル: dao_test.py プロジェクト: marquesds/sync
    def setUp(self):
        self.es = ElasticSearchDAO()
        self.doc_type = 'movie'

        self.data = {
            "title": "Big Hero 6",
            "director": ["Don Hall", "Chris Williams"],
            "year": 2015,
            "genres": ["Comédia", "Animação"]
        }

        self.updated_data = {
            "title": "Big Hero 6",
            "director": ["Don Hall", "Chris Williams"],
            "year": 2014,
            "genres": ["Comédia", "Animação"]
        }
コード例 #2
0
ファイル: sync.py プロジェクト: PythonPunters/sync
class Synchronizer():
    """
    Sync data between cassandra end elasticsearch
    """

    def __init__(self):
        self.elasticsearch = ElasticSearchDAO()
        self.cassandra = CassandraDAO()

    def is_updated(self, provider, table):
        """
        Check if provider is updated
        :param provider: "Database" to be checked
        :return: If provider is updated (True) or outdated (False)
        """

        if provider.lower() == 'elasticsearch':
            return False
        elif provider.lower() == 'cassandra':
            return False
        else:
            logger.error("Provider doesnt exists.")
            raise ValueError('Invalid provider.')

    def cassandra_to_elasticsearch(self):
        """
        Write something cool here
        """
        for table in self.cassandra.get_all_tables():
            # if size of table content is not equal between cassandra end elasticsearch return False
            if len(self.cassandra.get_all_data(table=table)) != len(self.elasticsearch.get_all_data(doc_type=table)):
                return False

    def elasticsearch_to_cassandra(self):
        """
        Write something cool here
        """
        for doc_type in self.elasticsearch.get_doc_types():
            if len(self.elasticsearch.get_all_data(doc_type=doc_type)) != len(
                    self.cassandra.get_all_data(table=doc_type)):
                return False
コード例 #3
0
class Synchronizer():
    """
    Sync data between cassandra end elasticsearch
    """
    def __init__(self):
        self.elasticsearch = ElasticSearchDAO()
        self.cassandra = CassandraDAO()

    def is_updated(self, provider, table):
        """
        Check if provider is updated
        :param provider: "Database" to be checked
        :return: If provider is updated (True) or outdated (False)
        """

        if provider.lower() == 'elasticsearch':
            return False
        elif provider.lower() == 'cassandra':
            return False
        else:
            logger.error("Provider doesnt exists.")
            raise ValueError('Invalid provider.')

    def cassandra_to_elasticsearch(self):
        """
        Write something cool here
        """
        for table in self.cassandra.get_all_tables():
            # if size of table content is not equal between cassandra end elasticsearch return False
            if len(self.cassandra.get_all_data(table=table)) != len(
                    self.elasticsearch.get_all_data(doc_type=table)):
                return False

    def elasticsearch_to_cassandra(self):
        """
        Write something cool here
        """
        for doc_type in self.elasticsearch.get_doc_types():
            if len(self.elasticsearch.get_all_data(doc_type=doc_type)) != len(
                    self.cassandra.get_all_data(table=doc_type)):
                return False
コード例 #4
0
ファイル: dao_test.py プロジェクト: marquesds/sync
class TestElasticSearchDAO(unittest.TestCase):
    """
    ElasticSearchDAO Test Case
    """
    def setUp(self):
        self.es = ElasticSearchDAO()
        self.doc_type = 'movie'

        self.data = {
            "title": "Big Hero 6",
            "director": ["Don Hall", "Chris Williams"],
            "year": 2015,
            "genres": ["Comédia", "Animação"]
        }

        self.updated_data = {
            "title": "Big Hero 6",
            "director": ["Don Hall", "Chris Williams"],
            "year": 2014,
            "genres": ["Comédia", "Animação"]
        }

    def test_insert(self):
        self.assertEquals(
            self.es.insert(doc_type=self.doc_type, body=self.data),
            "Document inserted.")

    def test_insert_existing_values(self):
        self.assertEquals(
            self.es.insert(doc_type=self.doc_type, body=self.data),
            "Document not inserted.")

    def test_update(self):
        self.assertEquals(
            self.es.insert(doc_type=self.doc_type, body=self.updated_data),
            "Document updated.")

    def test_delete(self):
        self.assertEquals(
            self.es.delete(doc_type=self.doc_type, id=self.__get_last_id()),
            "Document deleted.")

    def doCleanups(self):
        print(self.__get_last_id())
        self.es.delete(doc_type=self.doc_type, id=self.__get_last_id())

    def __get_last_id(self):
        id_list = []
        for r in self.es.get_all_data():
            print(r)
            id_list.append(str(r['_id']))

        if id_list:
            return id_list[len(id_list) - 1]
コード例 #5
0
ファイル: dao_test.py プロジェクト: PythonPunters/sync
class TestElasticSearchDAO(unittest.TestCase):
    """
    ElasticSearchDAO Test Case
    """

    def setUp(self):
        self.es = ElasticSearchDAO()
        self.doc_type = 'movie'

        self.data = {
            "title": "Big Hero 6",
            "director": ["Don Hall", "Chris Williams"],
            "year": 2015,
            "genres": [
                "Comédia",
                "Animação"
            ]
        }

        self.updated_data = {
            "title": "Big Hero 6",
            "director": ["Don Hall", "Chris Williams"],
            "year": 2014,
            "genres": [
                "Comédia",
                "Animação"
            ]
        }

    def test_insert(self):
        self.assertEquals(self.es.insert(doc_type=self.doc_type, body=self.data), "Document inserted.")

    def test_insert_existing_values(self):
        self.assertEquals(self.es.insert(doc_type=self.doc_type, body=self.data), "Document not inserted.")

    def test_update(self):
        self.assertEquals(self.es.insert(doc_type=self.doc_type, body=self.updated_data), "Document updated.")

    def test_delete(self):
        self.assertEquals(self.es.delete(doc_type=self.doc_type, id=self.__get_last_id()), "Document deleted.")

    def doCleanups(self):
        print(self.__get_last_id())
        self.es.delete(doc_type=self.doc_type, id=self.__get_last_id())

    def __get_last_id(self):
        id_list = []
        for r in self.es.get_all_data():
            print(r)
            id_list.append(str(r['_id']))

        if id_list:
            return id_list[len(id_list) - 1]
コード例 #6
0
ファイル: dao_test.py プロジェクト: PythonPunters/sync
    def setUp(self):
        self.es = ElasticSearchDAO()
        self.doc_type = 'movie'

        self.data = {
            "title": "Big Hero 6",
            "director": ["Don Hall", "Chris Williams"],
            "year": 2015,
            "genres": [
                "Comédia",
                "Animação"
            ]
        }

        self.updated_data = {
            "title": "Big Hero 6",
            "director": ["Don Hall", "Chris Williams"],
            "year": 2014,
            "genres": [
                "Comédia",
                "Animação"
            ]
        }
コード例 #7
0
ファイル: sync.py プロジェクト: PythonPunters/sync
 def __init__(self):
     self.elasticsearch = ElasticSearchDAO()
     self.cassandra = CassandraDAO()
コード例 #8
0
 def __init__(self):
     self.elasticsearch = ElasticSearchDAO()
     self.cassandra = CassandraDAO()