Skip to content

Commit 4a74558

Browse files
authored
Merge pull request #123 from rd4398/rohand-issue#295
Parallelize API requests for esi-leap
2 parents c806e94 + 790cc76 commit 4a74558

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

esi_leap/api/controllers/v1/lease.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
# License for the specific language governing permissions and limitations
1111
# under the License.
1212

13+
import concurrent.futures
1314
import datetime
1415
import http.client as http_client
1516
from oslo_utils import uuidutils
@@ -115,9 +116,17 @@ def get_all(self, project_id=None, start_time=None, end_time=None,
115116
leases = lease_obj.Lease.get_all(filters, request)
116117

117118
lease_collection.leases = []
119+
118120
if len(leases) > 0:
119-
project_list = keystone.get_project_list()
120-
node_list = ironic.get_node_list()
121+
project_list = None
122+
node_list = None
123+
124+
with concurrent.futures.ThreadPoolExecutor() as executor:
125+
f1 = executor.submit(ironic.get_node_list)
126+
f2 = executor.submit(keystone.get_project_list)
127+
node_list = f1.result()
128+
project_list = f2.result()
129+
121130
leases_with_added_info = [
122131
Lease(**utils.lease_get_dict_with_added_info(l, project_list,
123132
node_list))

esi_leap/api/controllers/v1/node.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
# License for the specific language governing permissions and limitations
1111
# under the License.
1212

13+
import concurrent.futures
1314
from datetime import datetime
1415
import pecan
1516
from pecan import rest
@@ -63,11 +64,18 @@ class NodesController(rest.RestController):
6364
@wsme_pecan.wsexpose(NodeCollection)
6465
def get_all(self):
6566
context = pecan.request.context
66-
nodes = ironic.get_node_list(context)
67+
68+
nodes = None
69+
project_list = None
70+
71+
with concurrent.futures.ThreadPoolExecutor() as executor:
72+
f1 = executor.submit(ironic.get_node_list, context)
73+
f2 = executor.submit(keystone.get_project_list)
74+
nodes = f1.result()
75+
project_list = f2.result()
6776

6877
node_collection = NodeCollection()
6978

70-
project_list = keystone.get_project_list()
7179
now = datetime.now()
7280

7381
offers = offer_obj.Offer.get_all({'status': [statuses.AVAILABLE]},

esi_leap/api/controllers/v1/offer.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
# License for the specific language governing permissions and limitations
1111
# under the License.
1212

13+
import concurrent.futures
1314
import datetime
1415
import http.client as http_client
1516
from oslo_utils import uuidutils
@@ -167,9 +168,16 @@ def get_all(self, project_id=None, resource_type=None,
167168
offers = offer_obj.Offer.get_all(filters, request)
168169

169170
offer_collection.offers = []
171+
170172
if len(offers) > 0:
171-
project_list = keystone.get_project_list()
172-
node_list = ironic.get_node_list()
173+
project_list = None
174+
node_list = None
175+
with concurrent.futures.ThreadPoolExecutor() as executor:
176+
f1 = executor.submit(ironic.get_node_list)
177+
f2 = executor.submit(keystone.get_project_list)
178+
node_list = f1.result()
179+
project_list = f2.result()
180+
173181
offers_with_added_info = [
174182
Offer(**utils.offer_get_dict_with_added_info(o, project_list,
175183
node_list))

0 commit comments

Comments
 (0)