Skip to content

Commit

Permalink
fixed review comment
Browse files Browse the repository at this point in the history
  • Loading branch information
Amit Roushan committed Mar 16, 2021
1 parent d0b65d9 commit d422a2a
Show file tree
Hide file tree
Showing 10 changed files with 201 additions and 750 deletions.
30 changes: 0 additions & 30 deletions delfin/api/schemas/perf_collection.py

This file was deleted.

19 changes: 9 additions & 10 deletions delfin/api/v1/storages.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

import copy
import six

from oslo_config import cfg
from oslo_log import log
Expand Down Expand Up @@ -106,15 +107,16 @@ def create(self, req, body):
# Trigger Performance monitoring
capabilities = self.driver_api.get_capabilities(
context=ctxt, storage_id=storage['id'])
# ignore if capabilities is empty
if capabilities:
_create_performance_monitoring_task(ctxt, storage['id'],
capabilities)
# validate capabilities
validation.validate_capabilities(capabilities)
# trigger performance monitoring
_create_performance_monitoring_task(ctxt, storage['id'],
capabilities)
except Exception as e:
# Unexpected error occurred, while performance monitoring.
msg = _('Failed to trigger performance monitoring for storage: '
msg = _('Failed to create performance monitoring task for storage:'
'%(storage)s. Error: %(err)s') % {'storage': storage['id'],
'err': e}
'err': six.text_type(e)}
LOG.error(msg)
return storage_view.build_storage(storage)

Expand Down Expand Up @@ -207,7 +209,6 @@ def _storage_exist(self, context, access_info):

return False


@wsgi.response(200)
def get_capabilities(self, req, id):
"""
Expand Down Expand Up @@ -261,9 +262,7 @@ def _create_performance_monitoring_task(context, storage_id, capabilities):
# check if resource_metric is empty
if 'resource_metrics' not in capabilities \
or not bool(capabilities.get('resource_metrics')):
msg = _('Skipping performance monitoring as resource metric is empty '
'for storage: %(storage)s.') % {'storage': storage_id}
LOG.warning(msg)
raise exception.EmptyResourceMetrics()

task = dict()
task.update(storage_id=storage_id)
Expand Down
37 changes: 1 addition & 36 deletions delfin/common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,12 @@
stepping stone.
"""
import json
import socket
from delfin import exception

from oslo_config import cfg
from oslo_log import log
from oslo_middleware import cors
from oslo_utils import netutils
from apscheduler.schedulers.background import BackgroundScheduler

LOG = log.getLogger(__name__)

Expand Down Expand Up @@ -130,36 +128,3 @@ def set_middleware_defaults():
'DELETE',
'PATCH']
)


def load_json_file(config_file):
try:
with open(config_file) as f:
data = json.load(f)
return data
except json.decoder.JSONDecodeError as e:
msg = ("{0} file is not correct. Please check the configuration file"
.format(config_file))
LOG.error(msg)
raise exception.InvalidInput(e.msg)
except FileNotFoundError as e:
LOG.error(e)
raise exception.ConfigNotFound(e)


class Scheduler:
__instance = None

@staticmethod
def getInstance():
""" Get instance of scheduler class """
if Scheduler.__instance is None:
Scheduler.__instance = BackgroundScheduler()
return Scheduler.__instance

def __init__(self):
if Scheduler.__instance is not None:
raise Exception("The instance of scheduler class is already"
"running.")
else:
Scheduler.__instance = self
7 changes: 2 additions & 5 deletions delfin/common/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
# Valid access type supported currently.
ACCESS_TYPE = ['rest', 'ssh', 'cli', 'smis']

RESOURCE_CLASS_TYPE = {'array_polling': 'ArrayPerformanceCollection'}
SCHEDULING_MIN_INTERVAL = 5


# Custom fields for Delfin objects
class StorageStatus(object):
Expand Down Expand Up @@ -308,6 +305,6 @@ class ResourceSync(object):
class Task(object):
DEFAULT_TASK_INTERVAL = 30
"""Default task interval"""
PERFORMANCE_TASK_METHOD = "delfin.task_manager.tasks." \
"performance_monitoring"
PERFORMANCE_TASK_METHOD = "delfin.task_manager.tasks.telemetry." \
"PerformanceCollectionTask"
"""Performance monitoring task name"""
Loading

0 comments on commit d422a2a

Please sign in to comment.