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)
|
status_code=405)
|
||||||
|
|
||||||
@wsexpose(RegionWrapper, str, body=RegionWrapper, rest_content_types='json', status_code=201)
|
@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)
|
image_logic, utils = di.resolver.unpack(RegionController)
|
||||||
auth.authorize(request, "region:create")
|
auth.authorize(request, "region:create")
|
||||||
|
|
||||||
@ -58,12 +58,10 @@ class RegionController(rest.RestController):
|
|||||||
message=str(exception))
|
message=str(exception))
|
||||||
|
|
||||||
@wsexpose(RegionWrapper, str, body=RegionWrapper, rest_content_types='json', status_code=200)
|
@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)
|
image_logic, utils = di.resolver.unpack(RegionController)
|
||||||
auth.authorize(request, "region:update")
|
auth.authorize(request, "region:update")
|
||||||
try:
|
try:
|
||||||
if not region_wrapper.regions:
|
|
||||||
raise ErrorStatus("Bad request, invalid json provided")
|
|
||||||
LOG.info("RegionController - replace regions: " + str(region_wrapper))
|
LOG.info("RegionController - replace regions: " + str(region_wrapper))
|
||||||
|
|
||||||
result = image_logic.replace_regions(image_id, region_wrapper, request.transaction_id)
|
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')
|
@di.dependsOn('rds_proxy')
|
||||||
def send_to_rds_if_needed(sql_image, existing_region_names, http_action,
|
def send_to_rds_if_needed(sql_image,
|
||||||
transaction_id):
|
existing_region_names,
|
||||||
|
http_action,
|
||||||
|
transaction_id,
|
||||||
|
optimized=False):
|
||||||
rds_proxy = di.resolver.unpack(send_to_rds_if_needed)
|
rds_proxy = di.resolver.unpack(send_to_rds_if_needed)
|
||||||
if (sql_image.regions and len(sql_image.regions) > 0) or len(
|
if (sql_image.regions and len(sql_image.regions) > 0) or len(
|
||||||
existing_region_names) > 0:
|
existing_region_names) > 0:
|
||||||
image_dict = sql_image.get_proxy_dict()
|
image_dict = sql_image.get_proxy_dict()
|
||||||
update_region_actions(image_dict, existing_region_names, http_action)
|
update_region_actions(
|
||||||
if image_dict['regions'] or len(existing_region_names) > 0:
|
image_dict, existing_region_names, http_action, optimized)
|
||||||
|
|
||||||
|
if image_dict['regions']:
|
||||||
LOG.debug("Image is valid, sending to RDS Proxy ")
|
LOG.debug("Image is valid, sending to RDS Proxy ")
|
||||||
rds_proxy.send_image(image_dict, transaction_id, http_action)
|
rds_proxy.send_image(image_dict, transaction_id, http_action)
|
||||||
else:
|
else:
|
||||||
@ -202,11 +207,12 @@ def add_regions(image_uuid, regions, transaction_id):
|
|||||||
region_type=region.type)
|
region_type=region.type)
|
||||||
sql_image.add_region(db_region)
|
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
|
# previous actions against the database
|
||||||
|
datamanager.flush()
|
||||||
|
|
||||||
send_to_rds_if_needed(sql_image, existing_region_names, "put",
|
send_to_rds_if_needed(sql_image, existing_region_names, "put",
|
||||||
transaction_id)
|
transaction_id, optimized=True)
|
||||||
|
|
||||||
datamanager.commit()
|
datamanager.commit()
|
||||||
|
|
||||||
@ -246,11 +252,13 @@ def replace_regions(image_uuid, regions, transaction_id):
|
|||||||
db_region = ImageRegion(region_name=region.name,
|
db_region = ImageRegion(region_name=region.name,
|
||||||
region_type=region.type)
|
region_type=region.type)
|
||||||
sql_image.add_region(db_region)
|
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
|
# previous actions against the database
|
||||||
|
datamanager.flush()
|
||||||
|
|
||||||
send_to_rds_if_needed(sql_image, existing_region_names, "put",
|
send_to_rds_if_needed(sql_image, existing_region_names, "put",
|
||||||
transaction_id)
|
transaction_id, optimized=True)
|
||||||
|
|
||||||
datamanager.commit()
|
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()
|
existing_region_names = sql_image.get_existing_region_names()
|
||||||
sql_image.remove_region(region_name)
|
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()
|
datamanager.flush()
|
||||||
|
|
||||||
send_to_rds_if_needed(sql_image, existing_region_names, "put",
|
send_to_rds_if_needed(sql_image, existing_region_names, "put",
|
||||||
transaction_id)
|
transaction_id, optimized=True)
|
||||||
if force_delete:
|
if force_delete:
|
||||||
datamanager.commit()
|
datamanager.commit()
|
||||||
else:
|
else:
|
||||||
datamanager.rollback()
|
datamanager.rollback()
|
||||||
|
|
||||||
except ErrorStatus as exp:
|
except ErrorStatus as exp:
|
||||||
LOG.log_exception("ImageLogic - Failed to update image", exp)
|
LOG.log_exception("ImageLogic - Failed to delete region", exp)
|
||||||
datamanager.rollback()
|
datamanager.rollback()
|
||||||
raise
|
raise
|
||||||
|
|
||||||
@ -532,17 +541,22 @@ def get_image_list_by_params(visibility, region, Customer):
|
|||||||
raise
|
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":
|
if action == "delete":
|
||||||
set_regions_action(image_dict, "delete")
|
set_regions_action(image_dict, "delete")
|
||||||
elif action == "post":
|
elif action == "post":
|
||||||
set_regions_action(image_dict, "create")
|
set_regions_action(image_dict, "create")
|
||||||
else: # put
|
else: # put
|
||||||
|
requested_regions = []
|
||||||
for region in image_dict["regions"]:
|
for region in image_dict["regions"]:
|
||||||
if region["name"] in existing_region_names:
|
if region["name"] in existing_region_names:
|
||||||
region["action"] = "modify"
|
region["action"] = "modify"
|
||||||
|
if not optimized:
|
||||||
|
requested_regions.append(region)
|
||||||
else:
|
else:
|
||||||
region["action"] = "create"
|
region["action"] = "create"
|
||||||
|
requested_regions.append(region)
|
||||||
|
|
||||||
# add deleted regions
|
# add deleted regions
|
||||||
for exist_region_name in existing_region_names:
|
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"]):
|
image_dict["regions"]):
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
image_dict["regions"].append(
|
requested_regions.append({"name": exist_region_name,
|
||||||
{"name": exist_region_name, "action": "delete"})
|
"action": "delete"})
|
||||||
|
|
||||||
|
image_dict["regions"] = requested_regions
|
||||||
|
|
||||||
|
|
||||||
def region_name_exist_in_regions(region_name, regions):
|
def region_name_exist_in_regions(region_name, regions):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user