Skip to content

Commit

Permalink
CCS-4538: Provide an endpoint in Git2Pantheon that would handle cache…
Browse files Browse the repository at this point in the history
… clearing for both Drupal and Akamai. Changes for Drupal API changes
  • Loading branch information
aprajshekhar committed Sep 2, 2021
1 parent f8ccc4c commit 753ff9e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 43 deletions.
44 changes: 27 additions & 17 deletions git2pantheon/api-docs/cache_clear_api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,6 @@ parameters:
required: true
schema:
$ref: '#/definitions/CacheClearData'

reponses:
200:
description: 'The status of upload corresponding to the key'
schema:
$ref: '#/definitions/UploaderKey'
400:
description: 'Invalid content error'
schema:
$ref: '#/definitions/Error'
500:
description: 'Internal server error'
schema:
$ref: '#/definitions/Error'


definitions:
CacheClearData:
type: object
Expand All @@ -50,4 +34,30 @@ definitions:
details:
type: string
description: 'Error details'

CacheClearResult:
type: object
properties:
akamai_result:
type: object
description: 'Result of Akamai cache clear'
drupal_result_assemblies:
type: object
description: 'Result of Drupal cache clear for assemblies'
drupal_result_modules:
type: object
description: 'Result of Drupal cache clear for modules'
produces:
- application/json
reponses:
200:
description: 'The status of cache clear operation'
schema:
$ref: '#/definitions/CacheClearResult'
400:
description: 'Invalid content error'
schema:
$ref: '#/definitions/Error'
500:
description: 'Internal server error'
schema:
$ref: '#/definitions/Error'
20 changes: 4 additions & 16 deletions git2pantheon/api/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,27 +292,15 @@ def clear_cache():

def bulk_cache_clear_drupal(cache_clear_result, cache_req_data):
if ASSEMBLIES in cache_req_data:
cache_clear_result["drupal_result_assemblies"] = drupal_client.purge_cache_assembly("assemblies")
cache_clear_result["drupal_result_assemblies"] = drupal_client.purge_cache_assembly_bulk("assemblies")

if MODULES in cache_req_data:
cache_clear_result["drupal_result_modules"] = drupal_client.purge_cache_assembly("modules")
cache_clear_result["drupal_result_modules"] = drupal_client.purge_cache_module_bulk("modules")


def clear_drupal_cache(data, cache_clear_result, bulk_clear=False):
def clear_drupal_cache(data, cache_clear_result):
cache_req_data = CacheObjectHelper.get_drupal_req_data(data)
if bulk_clear:
bulk_cache_clear_drupal(cache_clear_result, cache_req_data)
return
individual_cache_clear_drupal(cache_clear_result, cache_req_data)


def individual_cache_clear_drupal(cache_clear_result, cache_req_data):
if ASSEMBLIES in cache_req_data:
for guid in cache_req_data[ASSEMBLIES]:
cache_clear_result["drupal_result_assemblies"][str(guid)] = drupal_client.purge_cache_assembly(guid)
if MODULES in cache_req_data:
for guid in cache_req_data[MODULES]:
cache_clear_result["drupal_result_modules"][str(guid)] = (drupal_client.purge_cache_module(guid))
bulk_cache_clear_drupal(cache_clear_result, cache_req_data)


def clear_akamai_cache(data, cache_clear_result):
Expand Down
10 changes: 0 additions & 10 deletions git2pantheon/clients/drupal/drupal_rest_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,6 @@ class DrupalClient(RestClient):
def __init__(self, *args, **kwargs):
super(DrupalClient, self).__init__(*args, **kwargs)

@GET('/api/cache_clear/topic/{guid}')
@header('accept', 'application/json')
def purge_cache_module(self, guid):
"""Purge the drupal cache for module"""

@GET('/api/cache_clear/guide/{guid}')
@header('accept', 'application/json')
def purge_cache_assembly(self, guid):
"""Purge the drupal cache for module"""

@POST('/api/cache_clear/topic')
@header('content-type', 'application/json')
@header('accept', 'application/json')
Expand Down

0 comments on commit 753ff9e

Please sign in to comment.