Skip to content

Commit

Permalink
Merge pull request #123 from rd4398/rohand-issue#295
Browse files Browse the repository at this point in the history
Parallelize API requests for esi-leap
  • Loading branch information
tzumainn committed Sep 13, 2022
2 parents c806e94 + 790cc76 commit 4a74558
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
13 changes: 11 additions & 2 deletions esi_leap/api/controllers/v1/lease.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
# License for the specific language governing permissions and limitations
# under the License.

import concurrent.futures
import datetime
import http.client as http_client
from oslo_utils import uuidutils
Expand Down Expand Up @@ -115,9 +116,17 @@ def get_all(self, project_id=None, start_time=None, end_time=None,
leases = lease_obj.Lease.get_all(filters, request)

lease_collection.leases = []

if len(leases) > 0:
project_list = keystone.get_project_list()
node_list = ironic.get_node_list()
project_list = None
node_list = None

with concurrent.futures.ThreadPoolExecutor() as executor:
f1 = executor.submit(ironic.get_node_list)
f2 = executor.submit(keystone.get_project_list)
node_list = f1.result()
project_list = f2.result()

leases_with_added_info = [
Lease(**utils.lease_get_dict_with_added_info(l, project_list,
node_list))
Expand Down
12 changes: 10 additions & 2 deletions esi_leap/api/controllers/v1/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
# License for the specific language governing permissions and limitations
# under the License.

import concurrent.futures
from datetime import datetime
import pecan
from pecan import rest
Expand Down Expand Up @@ -63,11 +64,18 @@ class NodesController(rest.RestController):
@wsme_pecan.wsexpose(NodeCollection)
def get_all(self):
context = pecan.request.context
nodes = ironic.get_node_list(context)

nodes = None
project_list = None

with concurrent.futures.ThreadPoolExecutor() as executor:
f1 = executor.submit(ironic.get_node_list, context)
f2 = executor.submit(keystone.get_project_list)
nodes = f1.result()
project_list = f2.result()

node_collection = NodeCollection()

project_list = keystone.get_project_list()
now = datetime.now()

offers = offer_obj.Offer.get_all({'status': [statuses.AVAILABLE]},
Expand Down
12 changes: 10 additions & 2 deletions esi_leap/api/controllers/v1/offer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
# License for the specific language governing permissions and limitations
# under the License.

import concurrent.futures
import datetime
import http.client as http_client
from oslo_utils import uuidutils
Expand Down Expand Up @@ -167,9 +168,16 @@ def get_all(self, project_id=None, resource_type=None,
offers = offer_obj.Offer.get_all(filters, request)

offer_collection.offers = []

if len(offers) > 0:
project_list = keystone.get_project_list()
node_list = ironic.get_node_list()
project_list = None
node_list = None
with concurrent.futures.ThreadPoolExecutor() as executor:
f1 = executor.submit(ironic.get_node_list)
f2 = executor.submit(keystone.get_project_list)
node_list = f1.result()
project_list = f2.result()

offers_with_added_info = [
Offer(**utils.offer_get_dict_with_added_info(o, project_list,
node_list))
Expand Down

0 comments on commit 4a74558

Please sign in to comment.