def __init__(self, source, destination): """ Constructor to initialize the ESTransfer object Args source (str): source elastic search url with port e.g. http://localhost:9200 destination (str): destination elastic search url with port e.g. http://localhost:9400 es_index_1 (str): index1 present in both source and destination elastic search es_index_2 (str): index2 present in both source and destination elastic search. """ self.source = source self.destination = destination self.engine = CHATBOT_NER_DATASTORE.get('engine') if self.engine is None: raise EngineNotImplementedException() self.es_index_1 = CHATBOT_NER_DATASTORE.get( self.engine).get('es_index_1') if self.es_index_1 is None: raise IndexForTransferException() self.es_index_2 = CHATBOT_NER_DATASTORE.get( self.engine).get('es_index_2') if self.es_index_2 is None: raise IndexForTransferException() self.es_alias = CHATBOT_NER_DATASTORE.get(self.engine).get('es_alias') if self.es_alias is None: raise AliasForTransferException()
def get_es_url(): """ This method is used to obtain the es_url Returns: es_url (str): returns es_url currently pointed at """ engine = CHATBOT_NER_DATASTORE.get('engine') es_url = (CHATBOT_NER_DATASTORE.get(engine).get('es_scheme', 'http') + '://' + CHATBOT_NER_DATASTORE.get(engine).get('host') + ":" + CHATBOT_NER_DATASTORE.get(engine).get('port')) return es_url
def transfer_entities_elastic_search(self, entity_list): """ This method is used to transfer the entities from one environment to the other for elastic search engine only. Args: entity_list (list): List of entities that have to be transfered """ if self._engine != ELASTICSEARCH: raise NonESEngineTransferException es_url = CHATBOT_NER_DATASTORE.get(self._engine).get('connection_url') if es_url is None: es_url = elastic_search.connect.get_es_url() if es_url is None: raise DataStoreSettingsImproperlyConfiguredException() destination = CHATBOT_NER_DATASTORE.get(self._engine).get('destination_url') es_object = elastic_search.transfer.ESTransfer(source=es_url, destination=destination) es_object.transfer_specific_entities(list_of_entities=entity_list)
def __init__(self): """ Initializes DataStore object with the config set in environment variables. Raises: DataStoreSettingsImproperlyConfiguredException if connection settings are invalid or missing """ self._engine = CHATBOT_NER_DATASTORE.get(ENGINE) if self._engine is None: raise DataStoreSettingsImproperlyConfiguredException() self._connection_settings = CHATBOT_NER_DATASTORE.get(self._engine) if self._connection_settings is None: raise DataStoreSettingsImproperlyConfiguredException() # This can be index name for elastic search, table name for SQL, self._store_name = None self._client_or_connection = None self._connect()
def _configure_store(self): """ Configure self variables and connection settings. """ self._connection_settings = CHATBOT_NER_DATASTORE.get( self._engine_name) if self._connection_settings is None: raise DataStoreSettingsImproperlyConfiguredException() self._check_doc_type_for_elasticsearch() self._index_name = self._connection_settings[ constants.ELASTICSEARCH_ALIAS] self._doc_type = self._connection_settings[ constants.ELASTICSEARCH_DOC_TYPE]
def test_elasticsearch_add_connection(self): kwargs = CHATBOT_NER_DATASTORE.get('elasticsearch') c = Elasticsearch(**kwargs) es = ElasticSearchDataStore() es.add_new_connection('new', c) conn = es.get_or_create_new_connection() new_conn = es.get_or_create_new_connection('new') self.assertIsInstance(new_conn, Elasticsearch) self.assertIsInstance(c, Elasticsearch) self.assertIsInstance(conn, Elasticsearch)
def test_elasticsearch_connect(self): kwargs = CHATBOT_NER_DATASTORE.get('elasticsearch') connection = ElasticSearchDataStore.connect(**kwargs) self.assertIsInstance(connection, Elasticsearch)