Merge "Add some optimization around registered node query"
This commit is contained in:
commit
f04e97b170
@ -393,7 +393,7 @@ class Resource(base.APIResourceWrapper):
|
|||||||
self._role = kwargs['role']
|
self._role = kwargs['role']
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_by_node(cls, request, node):
|
def get_by_node(cls, request, node, all_resources=None):
|
||||||
"""Return the specified Heat Resource given a Node
|
"""Return the specified Heat Resource given a Node
|
||||||
|
|
||||||
:param request: request object
|
:param request: request object
|
||||||
@ -409,13 +409,31 @@ class Resource(base.APIResourceWrapper):
|
|||||||
# TODO(tzumainn): this is terribly inefficient, but I don't see a
|
# TODO(tzumainn): this is terribly inefficient, but I don't see a
|
||||||
# better way. Maybe if Heat set some node metadata. . . ?
|
# better way. Maybe if Heat set some node metadata. . . ?
|
||||||
if node.instance_uuid:
|
if node.instance_uuid:
|
||||||
for stack in Stack.list(request):
|
if all_resources is None:
|
||||||
for resource in stack.resources(with_joins=False):
|
resource_list = cls.list_all_resources(request)
|
||||||
|
else:
|
||||||
|
resource_list = all_resources
|
||||||
|
for resource in resource_list:
|
||||||
if resource.physical_resource_id == node.instance_uuid:
|
if resource.physical_resource_id == node.instance_uuid:
|
||||||
return resource
|
return resource
|
||||||
msg = _('Could not find resource matching node "%s"') % node.uuid
|
msg = _('Could not find resource matching node "%s"') % node.uuid
|
||||||
raise exceptions.NotFound(msg)
|
raise exceptions.NotFound(msg)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def list_all_resources(cls, request):
|
||||||
|
"""Iterate through all the stacks and return all relevant resources
|
||||||
|
|
||||||
|
:param request: request object
|
||||||
|
:type request: django.http.HttpRequest
|
||||||
|
|
||||||
|
:return: list of resources
|
||||||
|
:rtype: list of tuskar_ui.api.heat.Resource
|
||||||
|
"""
|
||||||
|
all_resources = []
|
||||||
|
for stack in Stack.list(request):
|
||||||
|
all_resources.extend(stack.resources(with_joins=False))
|
||||||
|
return all_resources
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def role(self):
|
def role(self):
|
||||||
"""Return the OvercloudRole associated with this Resource
|
"""Return the OvercloudRole associated with this Resource
|
||||||
|
@ -84,11 +84,12 @@ class RegisteredTab(tabs.TableTab):
|
|||||||
if 'errors' in self.request.GET:
|
if 'errors' in self.request.GET:
|
||||||
return api.node.filter_nodes(nodes, healthy=False)
|
return api.node.filter_nodes(nodes, healthy=False)
|
||||||
|
|
||||||
|
if nodes:
|
||||||
|
all_resources = api.heat.Resource.list_all_resources(self.request)
|
||||||
for node in nodes:
|
for node in nodes:
|
||||||
# TODO(tzumainn): this could probably be done more efficiently
|
|
||||||
# by getting the resource for all nodes at once
|
|
||||||
try:
|
try:
|
||||||
resource = api.heat.Resource.get_by_node(self.request, node)
|
resource = api.heat.Resource.get_by_node(
|
||||||
|
self.request, node, all_resources=all_resources)
|
||||||
node.role_name = resource.role.name
|
node.role_name = resource.role.name
|
||||||
node.role_id = resource.role.id
|
node.role_id = resource.role.id
|
||||||
node.stack_id = resource.stack.id
|
node.stack_id = resource.stack.id
|
||||||
|
@ -95,9 +95,10 @@ class NodesTests(test.BaseAdminViewTests, helpers.APITestCase):
|
|||||||
'image_get.return_value': image,
|
'image_get.return_value': image,
|
||||||
}),
|
}),
|
||||||
patch('tuskar_ui.api.heat.Resource', **{
|
patch('tuskar_ui.api.heat.Resource', **{
|
||||||
'spec_set': ['get_by_node'], # Only allow these attributes
|
'spec_set': ['get_by_node', 'list_all_resources'],
|
||||||
'get_by_node.side_effect': (
|
'get_by_node.side_effect': (
|
||||||
self._raise_horizon_exception_not_found),
|
self._raise_horizon_exception_not_found),
|
||||||
|
'list_all_resources.return_value': [],
|
||||||
}),
|
}),
|
||||||
) as (_OvercloudRole, Node, _nova, _glance, _resource):
|
) as (_OvercloudRole, Node, _nova, _glance, _resource):
|
||||||
res = self.client.get(INDEX_URL + '?tab=nodes__registered')
|
res = self.client.get(INDEX_URL + '?tab=nodes__registered')
|
||||||
@ -315,9 +316,10 @@ class NodesTests(test.BaseAdminViewTests, helpers.APITestCase):
|
|||||||
'image_get.return_value': image,
|
'image_get.return_value': image,
|
||||||
}),
|
}),
|
||||||
patch('tuskar_ui.api.heat.Resource', **{
|
patch('tuskar_ui.api.heat.Resource', **{
|
||||||
'spec_set': ['get_by_node'], # Only allow these attributes
|
'spec_set': ['get_by_node', 'list_all_resources'],
|
||||||
'get_by_node.side_effect': (
|
'get_by_node.side_effect': (
|
||||||
self._raise_horizon_exception_not_found),
|
self._raise_horizon_exception_not_found),
|
||||||
|
'list_all_resources.return_value': [],
|
||||||
}),
|
}),
|
||||||
) as (mock_node_client, mock_node, mock_role, mock_nova, mock_glance,
|
) as (mock_node_client, mock_node, mock_role, mock_nova, mock_glance,
|
||||||
mock_resource):
|
mock_resource):
|
||||||
@ -362,9 +364,10 @@ class NodesTests(test.BaseAdminViewTests, helpers.APITestCase):
|
|||||||
'image_get.return_value': image,
|
'image_get.return_value': image,
|
||||||
}),
|
}),
|
||||||
patch('tuskar_ui.api.heat.Resource', **{
|
patch('tuskar_ui.api.heat.Resource', **{
|
||||||
'spec_set': ['get_by_node'], # Only allow these attributes
|
'spec_set': ['get_by_node', 'list_all_resources'],
|
||||||
'get_by_node.side_effect': (
|
'get_by_node.side_effect': (
|
||||||
self._raise_horizon_exception_not_found),
|
self._raise_horizon_exception_not_found),
|
||||||
|
'list_all_resources.return_value': [],
|
||||||
}),
|
}),
|
||||||
) as (mock_node_client, mock_node, mock_role, mock_nova, mock_glance,
|
) as (mock_node_client, mock_node, mock_role, mock_nova, mock_glance,
|
||||||
mock_resource):
|
mock_resource):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user