Skip to content

Commit

Permalink
Remove default behaviour of selecting the first cold location on expi…
Browse files Browse the repository at this point in the history
…ration of cold objects

We don’t need this logic anymore as sorbet always sets the location name
and this might introduce unwanted behaviours when having multiple locations

Issue: BB-417
  • Loading branch information
Kerkesni committed Oct 20, 2023
1 parent 726be8e commit 2201733
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
14 changes: 9 additions & 5 deletions extensions/lifecycle/tasks/LifecycleUpdateExpirationTask.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const { errors } = require('arsenal');
const ObjectMD = require('arsenal').models.ObjectMD;
const BackbeatTask = require('../../../lib/tasks/BackbeatTask');
const ActionQueueEntry = require('../../../lib/models/ActionQueueEntry');
const locations = require('../../../conf/locationConfig.json') || {};

class LifecycleUpdateExpirationTask extends BackbeatTask {
/**
Expand Down Expand Up @@ -146,10 +145,15 @@ class LifecycleUpdateExpirationTask extends BackbeatTask {
async.waterfall([
next => this._getMetadata(entry, log, next),
(objMD, next) => {
const coldLocation = entry.getAttribute('target.location') ||
// If location not specified, use the first (and only) location
// This is a temporary fix, until Sorbet is fixed to provide the information
Object.keys(locations).find(name => locations[name].isCold);
const coldLocation = entry.getAttribute('target.location');
if (!coldLocation) {
// this should never happen as sorbet always sets the location attribute
log.error('missing target location', {
entry: entry.getLogInfo(),
method: 'LifecycleUpdateExpirationTask.processActionEntry',
});
return next(errors.MissingParameter.customizeDescription('missing target location'));
}

const archive = objMD.getArchive();

Expand Down
24 changes: 24 additions & 0 deletions tests/unit/lifecycle/LifecycleUpdateExpirationTask.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,28 @@ describe('LifecycleUpdateExpirationTask', () => {
done();
});
});

it.only('should throw an error when location is not specified', done => {
const mdObj = new ObjectMD();
backbeatMetadataProxyClient.setMdObj(mdObj);
const invalidActionEntry = ActionQueueEntry.create('deleteObject')
.setAttribute('target', {
owner: 'eab6642741045d0ae7cb3333962ad56f847ce0d9bb73de98eb4959428fc28108',
bucket: 'somebucket',
key: 'somekey',
accountId: '871467171849',
})
.setAttribute('details', {
lastModified: '2023-06-02T12:50:57.016Z',
})
.addContext('details', {
origin: 'lifecycle',
ruleType: 'expiration',
reqId: '8b902aef7346801d99fc',
});
task.processActionEntry(invalidActionEntry, err => {
assert(err.is.MissingParameter);
done();
});
});
});

0 comments on commit 2201733

Please sign in to comment.