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

Commit

Permalink
Mark san mapping items to mark progress
Browse files Browse the repository at this point in the history
Since we have two types of jobs for san mapping queue
mark completion of the first job in order to filter
items for the second job type. The order of execution
for job types matters.

Change-Id: Ifc9e5a24c9359befc5580007940d3aa7b9437426
  • Loading branch information
isaacm committed Aug 17, 2016
1 parent 9cf9088 commit 6fa8a59
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 11 deletions.
33 changes: 25 additions & 8 deletions poppy/manager/default/background_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ def post_job(self, job_type, kwargs):
run_list = []
ignore_list = []
if job_type == "akamai_check_and_update_cert_status":
# this task will consume the san mapping queue
# this task consumes the san mapping queue
# items marked as having an updated property are processed
# for the this job type, all other items are returned to the
# queue until they are ready for processing
if 'akamai' in self._driver.providers:
akamai_driver = self._driver.providers['akamai'].obj
queue_data += akamai_driver.san_mapping_queue.traverse_queue(
Expand All @@ -72,12 +75,24 @@ def post_job(self, job_type, kwargs):
"cert_obj_json": json.dumps(cert_dict),
"project_id": cert_dict.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.append(cert_dict)
if cert_dict.get('property_activated', False) is True:
self.distributed_task_controller.submit_task(
check_cert_status_and_update_flow.
check_cert_status_and_update_flow,
**t_kwargs
)
run_list.append(cert_dict)
else:
akamai_driver.san_mapping_queue.\
enqueue_san_mapping(json.dumps(cert_dict))
ignore_list.append(cert_dict)
LOG.info(
"Queue item for {0} was sent back to the "
"queue because it wasn't marked as "
"activated.".format(
cert_dict.get("domain_name")
)
)
except Exception as exc:
try:
akamai_driver.san_mapping_queue.\
Expand All @@ -93,7 +108,9 @@ def post_job(self, job_type, kwargs):

return run_list, ignore_list
elif job_type == "akamai_update_papi_property_for_mod_san":
# this task will leave the san mapping queue intact
# this task leaves the san mapping queue intact,
# once items are successfully processed they are marked
# ready for the next job type execution
if 'akamai' in self._driver.providers:
akamai_driver = self._driver.providers['akamai'].obj
queue_data += akamai_driver.san_mapping_queue.traverse_queue()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ def update_property_flow():
flow = linear_flow.Flow('Update Akamai Property').add(
update_property_tasks.PropertyGetLatestVersionTask(),
update_property_tasks.PropertyUpdateTask(),
update_property_tasks.PropertyActivateTask()
update_property_tasks.PropertyActivateTask(),
update_property_tasks.MarkQueueItemsWithActivatedProperty()
)
return flow

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,3 +309,29 @@ def execute(self, property_spec, new_version_number, update_detail,

def revert(self, property_spec, new_version_number, **kwargs):
LOG.info('retrying task: %s ...' % self.name)


class MarkQueueItemsWithActivatedProperty(task.Task):

def __init__(self):
super(MarkQueueItemsWithActivatedProperty, self).__init__()
service_controller, self.providers = \
memoized_controllers.task_controllers('poppy', 'providers')
self.akamai_driver = self.providers['akamai'].obj

def execute(self, update_info_list):
update_info_list = json.loads(update_info_list)

queue_data = self.akamai_driver.san_mapping_queue.traverse_queue()
new_queue_data = []
for cert in queue_data:
cert_dict = json.loads(cert)

for action, update_cname_host_mapping_info in update_info_list:
for host_info in update_cname_host_mapping_info:
if host_info['cnameFrom'] == cert_dict['domain_name']:
cert_dict['property_activated'] = True

new_queue_data.append(json.dumps(cert_dict))

self.akamai_driver.san_mapping_queue.put_queue_data(new_queue_data)
6 changes: 4 additions & 2 deletions tests/unit/manager/default/test_background_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@ def test_post_job_positive(self, job_type):
"akamai_spsId": 1
}
}
}
},
'property_activated': True
})
]

Expand Down Expand Up @@ -337,7 +338,8 @@ def test_post_job_submit_task_exception_enqueue_retry(self, job_type):
"akamai_spsId": 1
}
}
}
},
'property_activated': True
})
]

Expand Down
2 changes: 2 additions & 0 deletions tests/unit/provider/akamai/background_jobs/akamai_mocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ def get_providers():
akamai_mock_provider_obj.akamai_papi_api_base_url = (
'https://mybaseurl.net/papi/v0/{middle_part}/'
'?contractId=ctr_None&groupId=grp_None')
akamai_mock_provider_obj.san_mapping_queue.\
traverse_queue.return_value = []
akamai_mock_provider.obj = akamai_mock_provider_obj
providers = {
'akamai': akamai_mock_provider,
Expand Down

0 comments on commit 6fa8a59

Please sign in to comment.