Merge "Change MySqlDB to pymysql"

This commit is contained in:
Jenkins 2016-01-30 01:59:41 +00:00 committed by Gerrit Code Review
commit 36d6625065
6 changed files with 11 additions and 96 deletions

View File

@ -13,22 +13,14 @@
# License for the specific language governing permissions and limitations
# under the License.
class RepositoryException(Exception):
pass
class DoesNotExistException(RepositoryException):
pass
class AlreadyExistsException(RepositoryException):
pass
class InvalidUpdateException(RepositoryException):
pass
from monasca_common.repositories.exceptions import AlreadyExistsException
from monasca_common.repositories.exceptions import DoesNotExistException
from monasca_common.repositories.exceptions import InvalidUpdateException
from monasca_common.repositories.exceptions import RepositoryException
class MultipleMetricsException(RepositoryException):
pass
__all__ = (AlreadyExistsException, DoesNotExistException, InvalidUpdateException,
RepositoryException, MultipleMetricsException)

View File

@ -20,7 +20,7 @@ from oslo_utils import uuidutils
from monasca_api.common.repositories import alarm_definitions_repository as adr
from monasca_api.common.repositories import exceptions
from monasca_api.common.repositories.model import sub_alarm_definition
from monasca_api.common.repositories.mysql import mysql_repository
from monasca_common.repositories.mysql import mysql_repository
LOG = log.getLogger(__name__)

View File

@ -18,7 +18,7 @@ from time import time
from monasca_api.common.repositories import alarms_repository
from monasca_api.common.repositories import exceptions
from monasca_api.common.repositories.mysql import mysql_repository
from monasca_common.repositories.mysql import mysql_repository
LOG = log.getLogger(__name__)

View File

@ -1,77 +0,0 @@
# Copyright 2014 Hewlett-Packard
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import MySQLdb as mdb
from oslo_config import cfg
from oslo_log import log
from monasca_api.common.repositories import exceptions
LOG = log.getLogger(__name__)
class MySQLRepository(object):
def __init__(self):
try:
super(MySQLRepository, self).__init__()
self.conf = cfg.CONF
self.database_name = self.conf.mysql.database_name
self.database_server = self.conf.mysql.hostname
self.database_uid = self.conf.mysql.username
self.database_pwd = self.conf.mysql.password
except Exception as ex:
LOG.exception(ex)
raise exceptions.RepositoryException(ex)
def _get_cnxn_cursor_tuple(self):
cnxn = mdb.connect(self.database_server, self.database_uid,
self.database_pwd, self.database_name,
use_unicode=True, charset='utf8')
cursor = cnxn.cursor(mdb.cursors.DictCursor)
return cnxn, cursor
def _execute_query(self, query, parms):
cnxn, cursor = self._get_cnxn_cursor_tuple()
with cnxn:
cursor.execute(query, parms)
return cursor.fetchall()
def mysql_try_catch_block(fun):
def try_it(*args, **kwargs):
try:
return fun(*args, **kwargs)
except exceptions.DoesNotExistException:
raise
except exceptions.InvalidUpdateException:
raise
except exceptions.AlreadyExistsException:
raise
except Exception as ex:
LOG.exception(ex)
raise exceptions.RepositoryException(ex)
return try_it

View File

@ -18,8 +18,8 @@ from oslo_log import log
from oslo_utils import uuidutils
from monasca_api.common.repositories import exceptions
from monasca_api.common.repositories.mysql import mysql_repository
from monasca_api.common.repositories import notifications_repository as nr
from monasca_common.repositories.mysql import mysql_repository
LOG = log.getLogger(__name__)

View File

@ -16,10 +16,10 @@ six
ujson>=1.33
pyparsing
voluptuous
MySQL-python
influxdb
eventlet
kafka-python
simplejson
simport
validate_email>=1.3
monasca-common>=0.0.2