Esempio n. 1
0
    def test_set_last_updated_on_update(self):
        cluster_handler_mock = mock.Mock()
        cluster_handler_mock.execute_query.return_value = [{'[applied]': True}]
        table_repo = CassandraTableInfoRepository(cluster_handler_mock)
        context = mock.Mock(tenant='fake_tenant')

        table_schema = mock.Mock()
        table_schema.to_json.return_value = ''

        table_info = TableInfo('fake_table', table_schema,
                               TableMeta.TABLE_STATUS_CREATING)
        table_info.last_updated = datetime.now() - timedelta(0, 1000)
        table_repo.update(context, table_info)

        seconds = (datetime.now() - table_info.last_updated).total_seconds()
        self.assertLess(seconds, 30)
    def test_set_last_updated_on_update(self):
        cluster_handler_mock = mock.Mock()
        cluster_handler_mock.execute_query.return_value = [{'[applied]': True}]
        table_repo = CassandraTableInfoRepository(cluster_handler_mock)
        context = mock.Mock(tenant='fake_tenant')

        table_schema = mock.Mock()
        table_schema.to_json.return_value = ''

        table_info = TableInfo(
            'fake_table', table_schema, TableMeta.TABLE_STATUS_CREATING)
        table_info.last_updated = datetime.now() - timedelta(0, 1000)
        table_repo.update(context, table_info)

        seconds = (datetime.now() - table_info.last_updated).total_seconds()
        self.assertLess(seconds, 30)
Esempio n. 3
0
    def create_table(self, context, table_name, table_schema):
        self._notifier.info(
            context,
            notifier.EVENT_TYPE_TABLE_CREATE_START,
            table_schema)

        table_id = self._get_table_id(table_name)
        table_info = TableInfo(table_name, table_id, table_schema,
                               TableMeta.TABLE_STATUS_CREATING)

        try:
            self._table_info_repo.save(context, table_info)
        except TableAlreadyExistsException as e:
            self._notifier.error(
                context,
                notifier.EVENT_TYPE_TABLE_CREATE_ERROR,
                dict(
                    table_name=table_name,
                    message=e.message
                ))
            raise

        self._do_create_table(context, table_info)

        return TableMeta(table_info.id, table_info.schema, table_info.status,
                         table_info.creation_date_time)
    def test_update_status_on_describe_for_deleting_table_negative(
            self, mock_repo_get, mock_repo_update):

        context = mock.Mock(tenant='fake_tenant')
        table_name = 'fake_table'
        storage_manager = SimpleStorageManager(None, TableInfoRepository())

        table_info = TableInfo(table_name, None, None,
                               TableMeta.TABLE_STATUS_DELETING)
        table_info.last_update_date_time = datetime.now()

        mock_repo_get.return_value = table_info

        table_meta = storage_manager.describe_table(context, table_name)

        self.assertEqual(table_meta.status, TableMeta.TABLE_STATUS_DELETING)
    def test_update_status_on_describe_for_deleting_table_negative(
            self, mock_repo_get, mock_repo_update):

        context = mock.Mock(tenant='fake_tenant')
        table_name = 'fake_table'
        storage_manager = SimpleStorageManager(None, TableInfoRepository())

        table_info = TableInfo(
            table_name, None, TableMeta.TABLE_STATUS_DELETING)
        table_info.last_update_date_time = datetime.now()

        mock_repo_get.return_value = table_info

        table_meta = storage_manager.describe_table(context, table_name)

        self.assertEqual(
            table_meta.status, TableMeta.TABLE_STATUS_DELETING)
    def test_update_status_on_describe_for_creating_table(
            self, mock_repo_get, mock_repo_update, mock_notify):

        context = mock.Mock(tenant='fake_tenant')
        table_name = 'fake_table'
        storage_manager = SimpleStorageManager(None, TableInfoRepository())

        table_info = TableInfo(
            table_name, None, TableMeta.TABLE_STATUS_CREATING)
        table_info.last_updated = datetime.now() - timedelta(0, 1000)

        mock_repo_get.return_value = table_info

        table_meta = storage_manager.describe_table(context, table_name)

        self.assertEqual(
            table_meta.status, TableMeta.TABLE_STATUS_CREATE_FAILED)
Esempio n. 7
0
    def test_update_status_on_describe_for_creating_table(
            self, mock_repo_get, mock_repo_update, mock_notify):

        context = mock.Mock(tenant='fake_tenant')
        table_name = 'fake_table'
        storage_manager = SimpleStorageManager(None, TableInfoRepository())

        table_info = TableInfo(table_name, None,
                               TableMeta.TABLE_STATUS_CREATING)
        table_info.last_updated = datetime.now() - timedelta(0, 1000)

        mock_repo_get.return_value = table_info

        table_meta = storage_manager.describe_table(context, table_name)

        self.assertEqual(table_meta.status,
                         TableMeta.TABLE_STATUS_CREATE_FAILED)
Esempio n. 8
0
    def create_table(self, context, table_name, table_schema):
        notifier.notify(context, notifier.EVENT_TYPE_TABLE_CREATE_START,
                        table_schema)

        table_info = TableInfo(table_name, table_schema,
                               TableMeta.TABLE_STATUS_CREATING)
        try:
            self._table_info_repo.save(context, table_info)
        except TableAlreadyExistsException as e:
            notifier.notify(context,
                            notifier.EVENT_TYPE_TABLE_CREATE_ERROR,
                            e.message,
                            priority=notifier.PRIORITY_ERROR)
            raise

        self._do_create_table(context, table_info)

        return TableMeta(table_info.schema, table_info.status)
Esempio n. 9
0
    def get(self, context, table_name, fields_to_refresh=tuple()):
        table_info = self._get_table_info_from_cache(context, table_name)
        if table_info is None:
            with self.__table_cache_lock:
                table_info = self._get_table_info_from_cache(
                    context, table_name)
                if table_info is None:
                    table_info = TableInfo(table_name, None, None, None)
                    self.__refresh(context, table_info)
                    self._save_table_info_to_cache(context, table_info)
                    return table_info

        if table_info.status == models.TableMeta.TABLE_STATUS_CREATING:
            fields_to_refresh = set(fields_to_refresh)
            fields_to_refresh.update(
                self.__creating_to_active_field_list_to_update)
        if fields_to_refresh:
            self.__refresh(context, table_info, fields_to_refresh)

        return table_info