|
19 | 19 |
|
20 | 20 | import abc
|
21 | 21 |
|
| 22 | +from oslo_log import log as logging |
| 23 | + |
22 | 24 | from nova import loadables
|
23 | 25 |
|
24 | 26 |
|
| 27 | +LOG = logging.getLogger(__name__) |
| 28 | + |
| 29 | + |
25 | 30 | def normalize(weight_list, minval=None, maxval=None):
|
26 | 31 | """Normalize the values in a list between 0 and 1.0.
|
27 | 32 |
|
@@ -127,13 +132,40 @@ def get_weighed_objects(self, weighers, obj_list, weighing_properties):
|
127 | 132 | for weigher in weighers:
|
128 | 133 | weights = weigher.weigh_objects(weighed_objs, weighing_properties)
|
129 | 134 |
|
| 135 | + LOG.debug( |
| 136 | + "%s: raw weights %s", |
| 137 | + weigher.__class__.__name__, |
| 138 | + {(obj.obj.host, obj.obj.nodename): weight |
| 139 | + for obj, weight in zip(weighed_objs, weights)} |
| 140 | + ) |
| 141 | + |
130 | 142 | # Normalize the weights
|
131 |
| - weights = normalize(weights, |
132 |
| - minval=weigher.minval, |
133 |
| - maxval=weigher.maxval) |
| 143 | + weights = list( |
| 144 | + normalize( |
| 145 | + weights, minval=weigher.minval, maxval=weigher.maxval)) |
| 146 | + |
| 147 | + LOG.debug( |
| 148 | + "%s: normalized weights %s", |
| 149 | + weigher.__class__.__name__, |
| 150 | + {(obj.obj.host, obj.obj.nodename): weight |
| 151 | + for obj, weight in zip(weighed_objs, weights)} |
| 152 | + ) |
| 153 | + |
| 154 | + log_data = {} |
134 | 155 |
|
135 | 156 | for i, weight in enumerate(weights):
|
136 | 157 | obj = weighed_objs[i]
|
137 |
| - obj.weight += weigher.weight_multiplier(obj.obj) * weight |
| 158 | + multiplier = weigher.weight_multiplier(obj.obj) |
| 159 | + weigher_score = multiplier * weight |
| 160 | + obj.weight += weigher_score |
| 161 | + |
| 162 | + log_data[(obj.obj.host, obj.obj.nodename)] = ( |
| 163 | + f"{multiplier} * {weight}") |
| 164 | + |
| 165 | + LOG.debug( |
| 166 | + "%s: score (multiplier * weight) %s", |
| 167 | + weigher.__class__.__name__, |
| 168 | + {name: log for name, log in log_data.items()} |
| 169 | + ) |
138 | 170 |
|
139 | 171 | return sorted(weighed_objs, key=lambda x: x.weight, reverse=True)
|
0 commit comments