From 02e4c1893151b72aa95faa34e141a81ba02e8f82 Mon Sep 17 00:00:00 2001 From: drigato Date: Mon, 12 Jan 2015 14:50:42 -0500 Subject: [PATCH] SAAS-531: Finalize S3 folder hierarchy --- airtime_mvc/application/models/RabbitMq.php | 10 +++++++--- .../airtime_analyzer/cloud_storage_uploader.py | 12 +++++++++++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/airtime_mvc/application/models/RabbitMq.php b/airtime_mvc/application/models/RabbitMq.php index 4acc74584..ae3fe3fe3 100644 --- a/airtime_mvc/application/models/RabbitMq.php +++ b/airtime_mvc/application/models/RabbitMq.php @@ -113,10 +113,14 @@ class Application_Model_RabbitMq // Pro stations will share the same bucket. $data['station_domain'] = $stationDomain = Application_Model_Preference::GetStationName(); - // Each file uploaded to cloud storage is prefixed with the station's - // hosting id. + // We add a prefix to the resource name so files are not all placed + // under the root folder. We do this in case we need to restore a + // customer's file/s; File restoration is done via the S3 Browser + // client. The client will hang if there are too many files under the + // same folder. $clientCurrentAirtimeProduct = BillingController::getClientCurrentAirtimeProduct(); - $data['file_prefix'] = $clientCurrentAirtimeProduct["id"]; + $hostingId = $clientCurrentAirtimeProduct["id"]; + $data['file_prefix'] = substr($hostingId, -2)."/".$hostingId; $jsonData = json_encode($data); //self::sendMessage($exchange, 'topic', false, $jsonData, 'airtime-uploads'); diff --git a/python_apps/airtime_analyzer/airtime_analyzer/cloud_storage_uploader.py b/python_apps/airtime_analyzer/airtime_analyzer/cloud_storage_uploader.py index 65735785d..635764154 100644 --- a/python_apps/airtime_analyzer/airtime_analyzer/cloud_storage_uploader.py +++ b/python_apps/airtime_analyzer/airtime_analyzer/cloud_storage_uploader.py @@ -74,7 +74,17 @@ class CloudStorageUploader: # in the object name. URL encoding the object name doesn't solve the # problem. As a solution we will replace spaces with dashes. file_name = file_name.replace(" ", "-") - resource_id = "%s/%s_%s%s" % (metadata["file_prefix"], file_name, str(uuid.uuid4()), extension) + + unique_id = str(uuid.uuid4()) + + # We add another prefix to the resource name with the last two characters + # of the unique id so files are not all placed under the root folder. We + # do this in case we need to restore a customer's file/s; File restoration + # is done via the S3 Browser client. The client will hang if there are too + # many files under the same folder. + unique_id_prefix = unique_id[-2:] + + resource_id = "%s/%s/%s_%s%s" % (metadata['file_prefix'], unique_id_prefix, file_name, unique_id, extension) conn = S3Connection(self._api_key, self._api_key_secret, host=self._host) bucket = conn.get_bucket(self._bucket)