Optimize IMS service to send request to region(s)
Instead of broadcasting service request to all regions, IMS service will now send request to only affected regions. Un-affected regions will not receive request to perform a no-op. Change-Id: I4008739676ce8ccd71f72bca57fb33dd05f001bc
This commit is contained in:
parent
8f13fc47ed
commit
a97d54e8ef
@ -26,7 +26,7 @@ class RegionController(rest.RestController):
|
||||
status_code=405)
|
||||
|
||||
@wsexpose(RegionWrapper, str, body=RegionWrapper, rest_content_types='json', status_code=201)
|
||||
def post(self, image_id, region_wrapper): # add regions to image
|
||||
def post(self, image_id, region_wrapper):
|
||||
image_logic, utils = di.resolver.unpack(RegionController)
|
||||
auth.authorize(request, "region:create")
|
||||
|
||||
@ -58,12 +58,10 @@ class RegionController(rest.RestController):
|
||||
message=str(exception))
|
||||
|
||||
@wsexpose(RegionWrapper, str, body=RegionWrapper, rest_content_types='json', status_code=200)
|
||||
def put(self, image_id, region_wrapper): # add regions to image
|
||||
def put(self, image_id, region_wrapper):
|
||||
image_logic, utils = di.resolver.unpack(RegionController)
|
||||
auth.authorize(request, "region:update")
|
||||
try:
|
||||
if not region_wrapper.regions:
|
||||
raise ErrorStatus("Bad request, invalid json provided")
|
||||
LOG.info("RegionController - replace regions: " + str(region_wrapper))
|
||||
|
||||
result = image_logic.replace_regions(image_id, region_wrapper, request.transaction_id)
|
||||
|
@ -59,14 +59,19 @@ def create_image(image_wrapper, image_uuid, transaction_id):
|
||||
|
||||
|
||||
@di.dependsOn('rds_proxy')
|
||||
def send_to_rds_if_needed(sql_image, existing_region_names, http_action,
|
||||
transaction_id):
|
||||
def send_to_rds_if_needed(sql_image,
|
||||
existing_region_names,
|
||||
http_action,
|
||||
transaction_id,
|
||||
optimized=False):
|
||||
rds_proxy = di.resolver.unpack(send_to_rds_if_needed)
|
||||
if (sql_image.regions and len(sql_image.regions) > 0) or len(
|
||||
existing_region_names) > 0:
|
||||
image_dict = sql_image.get_proxy_dict()
|
||||
update_region_actions(image_dict, existing_region_names, http_action)
|
||||
if image_dict['regions'] or len(existing_region_names) > 0:
|
||||
update_region_actions(
|
||||
image_dict, existing_region_names, http_action, optimized)
|
||||
|
||||
if image_dict['regions']:
|
||||
LOG.debug("Image is valid, sending to RDS Proxy ")
|
||||
rds_proxy.send_image(image_dict, transaction_id, http_action)
|
||||
else:
|
||||
@ -202,11 +207,12 @@ def add_regions(image_uuid, regions, transaction_id):
|
||||
region_type=region.type)
|
||||
sql_image.add_region(db_region)
|
||||
|
||||
datamanager.flush() # i want to get any exception created by
|
||||
# Flush to get any exception, if any, created by
|
||||
# previous actions against the database
|
||||
datamanager.flush()
|
||||
|
||||
send_to_rds_if_needed(sql_image, existing_region_names, "put",
|
||||
transaction_id)
|
||||
transaction_id, optimized=True)
|
||||
|
||||
datamanager.commit()
|
||||
|
||||
@ -246,11 +252,13 @@ def replace_regions(image_uuid, regions, transaction_id):
|
||||
db_region = ImageRegion(region_name=region.name,
|
||||
region_type=region.type)
|
||||
sql_image.add_region(db_region)
|
||||
datamanager.flush() # i want to get any exception created by
|
||||
|
||||
# Flush to get any exception, if any, created by
|
||||
# previous actions against the database
|
||||
datamanager.flush()
|
||||
|
||||
send_to_rds_if_needed(sql_image, existing_region_names, "put",
|
||||
transaction_id)
|
||||
transaction_id, optimized=True)
|
||||
|
||||
datamanager.commit()
|
||||
|
||||
@ -288,18 +296,19 @@ def delete_region(image_uuid, region_name, transaction_id, force_delete):
|
||||
existing_region_names = sql_image.get_existing_region_names()
|
||||
sql_image.remove_region(region_name)
|
||||
|
||||
# Get any exception created by previous actions against the database
|
||||
# Flush to get any exception, if any, created by
|
||||
# previous actions against the database
|
||||
datamanager.flush()
|
||||
|
||||
send_to_rds_if_needed(sql_image, existing_region_names, "put",
|
||||
transaction_id)
|
||||
transaction_id, optimized=True)
|
||||
if force_delete:
|
||||
datamanager.commit()
|
||||
else:
|
||||
datamanager.rollback()
|
||||
|
||||
except ErrorStatus as exp:
|
||||
LOG.log_exception("ImageLogic - Failed to update image", exp)
|
||||
LOG.log_exception("ImageLogic - Failed to delete region", exp)
|
||||
datamanager.rollback()
|
||||
raise
|
||||
|
||||
@ -532,17 +541,22 @@ def get_image_list_by_params(visibility, region, Customer):
|
||||
raise
|
||||
|
||||
|
||||
def update_region_actions(image_dict, existing_region_names, action="put"):
|
||||
def update_region_actions(image_dict, existing_region_names, action,
|
||||
optimized):
|
||||
if action == "delete":
|
||||
set_regions_action(image_dict, "delete")
|
||||
elif action == "post":
|
||||
set_regions_action(image_dict, "create")
|
||||
else: # put
|
||||
requested_regions = []
|
||||
for region in image_dict["regions"]:
|
||||
if region["name"] in existing_region_names:
|
||||
region["action"] = "modify"
|
||||
if not optimized:
|
||||
requested_regions.append(region)
|
||||
else:
|
||||
region["action"] = "create"
|
||||
requested_regions.append(region)
|
||||
|
||||
# add deleted regions
|
||||
for exist_region_name in existing_region_names:
|
||||
@ -550,8 +564,10 @@ def update_region_actions(image_dict, existing_region_names, action="put"):
|
||||
image_dict["regions"]):
|
||||
continue
|
||||
else:
|
||||
image_dict["regions"].append(
|
||||
{"name": exist_region_name, "action": "delete"})
|
||||
requested_regions.append({"name": exist_region_name,
|
||||
"action": "delete"})
|
||||
|
||||
image_dict["regions"] = requested_regions
|
||||
|
||||
|
||||
def region_name_exist_in_regions(region_name, regions):
|
||||
|
Loading…
x
Reference in New Issue
Block a user