Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Commit

Permalink
Execute san mapping queue and report summary
Browse files Browse the repository at this point in the history
San mapping queue execution would fail the entire list
if one object did not pass validation. This change allows
the execution to act on all items on the queue and report
successes and failures.

Change-Id: I50a44e8c70c82af1f20c36d7fe50d6aaca4d46d3
  • Loading branch information
isaacm committed Jun 17, 2016
1 parent afa41d8 commit 0d43b45
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 62 deletions.
139 changes: 84 additions & 55 deletions poppy/manager/default/background_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,33 +44,49 @@ def __init__(self, manager):
def post_job(self, job_type, kwargs):
queue_data = []

run_list = []
ignore_list = []
if job_type == "akamai_check_and_update_cert_status":
# this task will consume the san mapping queue
if 'akamai' in self._driver.providers:
akamai_driver = self._driver.providers['akamai'].obj
queue_data += akamai_driver.san_mapping_queue.traverse_queue(
consume=True
)
for cert_dict in queue_data:
cert_dict = json.loads(cert_dict)
LOG.info('Starting to check status on domain: %s,'
'for project_id: %s'
'flavor_id: %s, cert_type: %s' %
(
cert_dict.get("domain_name"),
cert_dict.get("project_id"),
cert_dict.get("flavor_id"),
cert_dict.get("cert_type")
))
t_kwargs = {
"cert_obj_json": json.dumps(cert_dict),
"project_id": kwargs.get("project_id")
}
self.distributed_task_controller.submit_task(
check_cert_status_and_update_flow.
check_cert_status_and_update_flow,
**t_kwargs
)

run_list += queue_data
for cert_dict in queue_data:
try:
cert_dict = json.loads(cert_dict)
LOG.info(
'Starting to check status on domain: {0},'
'for project_id: {1}'
'flavor_id: {2}, cert_type: {3}'.format(
cert_dict.get("domain_name"),
cert_dict.get("project_id"),
cert_dict.get("flavor_id"),
cert_dict.get("cert_type")
)
)
t_kwargs = {
"cert_obj_json": json.dumps(cert_dict),
"project_id": kwargs.get("project_id")
}
self.distributed_task_controller.submit_task(
check_cert_status_and_update_flow.
check_cert_status_and_update_flow,
**t_kwargs
)
except Exception as e:
akamai_driver.san_mapping_queue.enqueue_san_mapping(
json.dumps(cert_dict)
)
run_list.remove(cert_dict)
cert_dict['error_message'] = str(e.message)
ignore_list.append(cert_dict)
LOG.exception(e)

return run_list, ignore_list
elif job_type == "akamai_update_papi_property_for_mod_san":
# this task will leave the san mapping queue intact
if 'akamai' in self._driver.providers:
Expand All @@ -79,46 +95,53 @@ def post_job(self, job_type, kwargs):

cname_host_info_list = []

run_list += queue_data
for cert_dict in queue_data:
cert_dict = json.loads(cert_dict)
try:
cert_dict = json.loads(cert_dict)

domain_name = cert_dict["domain_name"]
san_cert = (
cert_dict["cert_details"]
["Akamai"]["extra_info"]["san cert"]
)
LOG.info(
"{0}: {1} to {2}, on property: {3}".format(
kwargs.get("action", 'add'),
domain_name,
san_cert,
kwargs.get(
"property_spec",
'akamai_https_san_config_numbers'
)
domain_name = cert_dict["domain_name"]
san_cert = (
cert_dict["cert_details"]
["Akamai"]["extra_info"]["san cert"]
)
)

# Note(tonytan4ever): Put this check here so erroneous
# san cert params will not pass. Support occasionally put in
# the ending "edgekey.net"
# (e.g: securexxx.san1.abc.com.edgekey.net), this check will
# effectively error that out
if san_cert not in self.akamai_san_cert_cname_list:
raise ValueError(
"Not A valid san cert cname: {0}, "
"valid san cert cnames are: {1}".format(
LOG.info(
"{0}: {1} to {2}, on property: {3}".format(
kwargs.get("action", 'add'),
domain_name,
san_cert,
self.akamai_san_cert_cname_list
kwargs.get(
"property_spec",
'akamai_https_san_config_numbers'
)
)
)
cname_host_info_list.append({
"cnameFrom": domain_name,
"cnameTo": '.'.join(
[san_cert, self.akamai_san_cert_suffix]
),
"cnameType": "EDGE_HOSTNAME"
})

# Note(tonytan4ever): Put this check here so erroneous san
# cert params will not pass. Support occasionally put in
# the ending "edgekey.net"
# (e.g: securexxx.san1.abc.com.edgekey.net), this check
# will effectively error that out
if san_cert not in self.akamai_san_cert_cname_list:
raise ValueError(
"Not A valid san cert cname: {0}, "
"valid san cert cnames are: {1}".format(
san_cert,
self.akamai_san_cert_cname_list
)
)
cname_host_info_list.append({
"cnameFrom": domain_name,
"cnameTo": '.'.join(
[san_cert, self.akamai_san_cert_suffix]
),
"cnameType": "EDGE_HOSTNAME"
})
except Exception as e:
run_list.remove(cert_dict)
cert_dict['error_message'] = str(e.message)
ignore_list.append(cert_dict)
LOG.exception(e)

update_info_list = json.dumps([
(
Expand All @@ -140,8 +163,14 @@ def post_job(self, job_type, kwargs):
self.distributed_task_controller.submit_task(
update_property_flow.update_property_flow,
**t_kwargs)

return run_list, ignore_list
else:
raise NotImplementedError('job type: %s has not been implemented')
raise NotImplementedError(
'job type: {0} has not been implemented'.format(
job_type
)
)

def get_san_mapping_list(self):
res = []
Expand Down
19 changes: 12 additions & 7 deletions poppy/transport/pecan/controllers/v1/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,22 @@ def post(self):
request_json = json.loads(pecan.request.body.decode('utf-8'))
job_type = request_json.pop('job_type')

sent = []
ignored = []

try:
self._driver.manager.background_job_controller.post_job(
job_type,
request_json
)
except ValueError as e:
pecan.abort(400, str(e))
sent, ignored = self._driver.manager.background_job_controller.\
post_job(job_type, request_json)
except NotImplementedError as e:
pecan.abort(400, str(e))

return pecan.Response(None, 202)
return pecan.Response(
json_body={
"sent": sent,
"ignored": ignored
},
status=202,
)


class AkamaiSanMappingListController(base.Controller, hooks.HookController):
Expand Down

0 comments on commit 0d43b45

Please sign in to comment.