Jiří Moskovčák has uploaded a new change for review. Change subject: add errors to the xmlrpc response ......................................................................
add errors to the xmlrpc response Change-Id: I765acfcc65555c046749ed51a21023418d870a35 Bug-Url: https://bugzilla.redhat.com/1066576 Signed-off-by: Jiri Moskovcak <[email protected]> --- M src/ovirtscheduler/API.py M src/ovirtscheduler/oschedproxyd.py M src/ovirtscheduler/request_handler.py A src/ovirtscheduler/result.py 4 files changed, 89 insertions(+), 17 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-scheduler-proxy refs/changes/83/24683/1 diff --git a/src/ovirtscheduler/API.py b/src/ovirtscheduler/API.py index 63c0e61..f62b7ec 100644 --- a/src/ovirtscheduler/API.py +++ b/src/ovirtscheduler/API.py @@ -28,21 +28,23 @@ return self._plugin_executor.discover() def runFilters(self, filters, hosts, vm, properties_map): + # we use custom class as a return value, which won't be + # serialized properly, so we need to call to_dict on it, to get the right format return self._plugin_executor.run_filters( filters, hosts, vm, - properties_map) + properties_map).to_dict() def runCostFunctions(self, cost_functions, hosts, vm, properties_map): return self._plugin_executor.run_cost_functions( cost_functions, hosts, vm, - properties_map) + properties_map).to_dict() def runLoadBalancing(self, balance, hosts, properties_map): return self._plugin_executor.run_load_balancing( balance, hosts, - properties_map) + properties_map).to_dict() diff --git a/src/ovirtscheduler/oschedproxyd.py b/src/ovirtscheduler/oschedproxyd.py index 2517c15..85dbe83 100644 --- a/src/ovirtscheduler/oschedproxyd.py +++ b/src/ovirtscheduler/oschedproxyd.py @@ -58,8 +58,8 @@ plugins_path = os.path.join(os.getcwd(), "plugins") analyzer_path = os.path.dirname(__file__) - logging.info("Loading modules from %s" % plugins_path) - logging.info("Loading analyzer from %s" % analyzer_path) + logging.info("Loading modules from '%s'" % plugins_path) + logging.info("Loading analyzer from '%s'" % analyzer_path) self._handler = RequestHandler( plugins_path, diff --git a/src/ovirtscheduler/request_handler.py b/src/ovirtscheduler/request_handler.py index 8e6616a..7afd5ed 100644 --- a/src/ovirtscheduler/request_handler.py +++ b/src/ovirtscheduler/request_handler.py @@ -19,6 +19,7 @@ import utils import logging import uuid +from result import Result class RequestHandler(object): @@ -152,6 +153,7 @@ return resultSet def run_filters(self, filters, hostIDs, vmID, properties_map): + result = Result() request_id = str(uuid.uuid1()) log_adapter = \ utils.RequestAdapter(self._logger, @@ -166,7 +168,8 @@ # handle missing filters for f in missing_f: log_adapter.warning("Filter requested but was not found: %s" % f) - raise RuntimeError("plugin not found: " + f) + #raise RuntimeError("plugin not found: " + f) + result.pluginError(f, "plugin not found: '%s'" % f) # Prepare a generator "list" of runners filterRunners = [ @@ -189,12 +192,16 @@ log_adapter.warning("Waiting on filters timed out") log_adapter.debug("Aggregating results") - results = self.aggregate_filter_results(filterRunners, request_id) - if results is None: + filters_results = self.aggregate_filter_results(filterRunners, request_id) + if filters_results is None: log_adapter.info('All filters failed, return the full list') - results = hostIDs - log_adapter.info('returning: %s' % str(results)) - return results + result.error("all filters failed") + filters_results = hostIDs + + result.add(filters_results) + log_adapter.info('returning: %s' % str(filters_results)) + + return result #accumalate the results def aggregate_score_results(self, scoreRunners, request_id): @@ -228,6 +235,7 @@ hostIDs, vmID, properties_map): + result = Result() request_id = str(uuid.uuid1()) log_adapter = \ utils.RequestAdapter(self._logger, @@ -244,6 +252,7 @@ # Report the unknown functions for name, weight in missing_cost_f: log_adapter.warning("requested but was not found: %s" % name) + result.pluginError(name, "plugin not found: '%s'" % name) # Prepare a generator "list" with runners and weights scoreRunners = [ @@ -263,13 +272,16 @@ log_adapter.debug("Waiting for scoring to finish") if utils.waitOnGroup([runner for runner, _weight in scoreRunners]): log_adapter.warning("Waiting on score functions timed out") + result.error("Waiting on score functions timed out") log_adapter.debug("Aggregating results") results = self.aggregate_score_results(scoreRunners, request_id) + result.add(results) log_adapter.info('returning: %s' % str(results)) - return results + return result def run_load_balancing(self, balance, hostIDs, properties_map): + result = Result() request_id = str(uuid.uuid1()) log_adapter = \ utils.RequestAdapter(self._logger, @@ -280,9 +292,9 @@ if balance not in self._balancers: log_adapter.warning( - "Load balance requested but was not found: %s", - balance) - return + "Load balance requested but was not found: %s" % balance) + result.pluginError(balance, "Load balance requested but was not found: %s" % balance) + return result runner = PythonMethodRunner(self._pluginDir, self._class_to_module_map[balance], @@ -299,6 +311,8 @@ log_adapter.info('returning: %s' % str(runner.getResults())) if runner.getResults() is None: - return ['', []] + result.add(['', []]) else: - return runner.getResults() + result.add(runner.getResults()) + + return result diff --git a/src/ovirtscheduler/result.py b/src/ovirtscheduler/result.py new file mode 100644 index 0000000..28eeaef --- /dev/null +++ b/src/ovirtscheduler/result.py @@ -0,0 +1,56 @@ +# +# Copyright 2013 Red Hat, Inc. +# +# 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. +# + +RESULT_OK = 0 +RESULT_ERROR = 1 +PLUGIN_ERRORS = "plugin_errors" +ERRORS = "errors" + + +class Result(object): + def __init__(self): + self._result = {} + self._result["result_code"] = RESULT_OK # no error so far.. + self._result["result"] = [] + + def add(self, obj_list): + self._result["result"].extend(obj_list) + + def pluginError(self, pluginName, errorMsg): + self._result["result_code"] = RESULT_ERROR + pluginErrors = self._result.get(PLUGIN_ERRORS, {}) + pluginErrors = pluginErrors.get(pluginName, []) + pluginErrors.append(errorMsg) + self._result[PLUGIN_ERRORS] = pluginErrors + + def error(self, errorMsg): + self._result["result_code"] = RESULT_ERROR + errors = self._result.get(ERRORS, []) + errors.append(errorMsg) + self._result[ERRORS] = errors + + def to_dict(self): + return self._result + + +class FilterResult(Result): + def __init__(self): + super(FilterResult, self).__init__() + + +class WeightResult(Result): + def __init__(self): + super(WeightResult, self).__init__() -- To view, visit http://gerrit.ovirt.org/24683 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I765acfcc65555c046749ed51a21023418d870a35 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-scheduler-proxy Gerrit-Branch: master Gerrit-Owner: Jiří Moskovčák <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
