Skip to content

Commit

Permalink
supported lifecycle rules in bb lifecycle config instead of const
Browse files Browse the repository at this point in the history
Issue : BB-514
  • Loading branch information
benzekrimaha committed Oct 29, 2024
1 parent 53ffd8e commit 3eacc99
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 13 deletions.
7 changes: 6 additions & 1 deletion extensions/lifecycle/LifecycleConfigValidator.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ const {
inheritedAuthJoi,
mongoJoi,
probeServerJoi,
retryParamsJoi,
retryParamsJoi
} = require('../../lib/config/configItems.joi');

const { supportedLifecycleRules } = require('../../lib/constants');

const joiSchema = joi.object({
zookeeperPath: joi.string().required(),
bucketTasksTopic: joi.string().required(),
Expand Down Expand Up @@ -73,6 +75,9 @@ const joiSchema = joi.object({
coldStorageRestoreAdjustTopicPrefix: joi.string().default('cold-restore-adjust-req-'),
coldStorageGCTopicPrefix: joi.string().default('cold-gc-req-'),
coldStorageStatusTopicPrefix: joi.string().default('cold-status-'),
supportedLifecycleRules: joi.array().items(
joi.string().valid(...supportedLifecycleRules)
).default(supportedLifecycleRules),
});

function configValidator(backbeatConfig, extConfig) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const ClientManager = require('../../../lib/clients/ClientManager');
const { authTypeAssumeRole } = require('../../../lib/constants');
const LocationStatusStream = require('../../utils/LocationStatusStream');
const {
getFormattedSupportedLifecycleRules,
formatSupportedLifecycleRules,
isExpirationRule
} = require('../util/rules');
const {
Expand Down Expand Up @@ -88,7 +88,7 @@ class LifecycleBucketProcessor {
this._producer = null;
this._kafkaBacklogMetrics = null;

this._supportedRules = getFormattedSupportedLifecycleRules();
this._supportedRules = formatSupportedLifecycleRules(lcConfig);

this._producerReady = false;
this._consumerReady = false;
Expand Down Expand Up @@ -186,6 +186,7 @@ class LifecycleBucketProcessor {
lcOptions: this._lcOptions,
circuitBreakers: this._circuitBreakers,
log: this._log,
supportedRules: this._lcConfig.supportedLifecycleRules,
};
}

Expand Down
5 changes: 2 additions & 3 deletions extensions/lifecycle/tasks/LifecycleTask.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
const async = require('async');
const { errors, versioning } = require('arsenal');
const { ObjectMD } = require('arsenal').models;
const { supportedLifecycleRules } = require('arsenal').constants;
const {
LifecycleDateTime,
LifecycleUtils,
Expand Down Expand Up @@ -96,10 +95,10 @@ class LifecycleTask extends BackbeatTask {
});

this._lifecycleUtils = new LifecycleUtils(
supportedLifecycleRules,
this.supportedRules,
this._lifecycleDateTime
);
this._supportedRules = supportedLifecycleRules;
this._supportedRules = this.supportedRules;
this._totalRetries = 0;
}

Expand Down
10 changes: 5 additions & 5 deletions extensions/lifecycle/util/rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const { RulesReducer } = require('./RulesReducer');
const { lifecycleListing: { NON_CURRENT_TYPE, CURRENT_TYPE, ORPHAN_DM_TYPE } } = require('../../../lib/constants');

const { s3middleware } = require('arsenal');
const { supportedLifecycleRules } = require('arsenal').constants;
const { scaleMsPerDay } = s3middleware.objectUtils;

// Default max AWS limit is 1000 for both list objects and list object versions
Expand Down Expand Up @@ -197,11 +196,12 @@ function rulesToParams(versioningStatus, currentDate, bucketLCRules, bucketData,
/**
* Formats the array of supported lifecycle rules in Arsenal so that
* they correspond to how they are written in the lifecycle configuration.
* @param {string[]} supportedLifecycleRules list of supported lifecycle rules
* @param {Object} lcConfig - Lifecycle configuration object
* @param {string[]} lcConfig.supportedLifecycleRules - List of supported lifecycle rules
* @returns {string[]} formatted supported lifecycle rules
*/
function getFormattedSupportedLifecycleRules() {
return supportedLifecycleRules.map(rule => {
function formatSupportedLifecycleRules(lcConfig) {
return lcConfig.supportedLifecycleRules.map(rule => {
if (rule === 'noncurrentVersionTransition') {
return 'NoncurrentVersionTransitions';
}
Expand All @@ -222,6 +222,6 @@ function isExpirationRule(ruleName) {

module.exports = {
rulesToParams,
getFormattedSupportedLifecycleRules,
formatSupportedLifecycleRules,
isExpirationRule,
};
3 changes: 2 additions & 1 deletion lib/config/configItems.joi.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ const qpKafkaJoi = kafkaJoi.append({
replication: extensionKafkaJoi,
});


module.exports = {
hostPortJoi,
transportJoi,
Expand All @@ -172,5 +173,5 @@ module.exports = {
probeServerPerSite,
stsConfigJoi,
mongoJoi,
qpKafkaJoi,
qpKafkaJoi
};
9 changes: 8 additions & 1 deletion lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,14 @@ const constants = {
},
],
},
}
},
supportedLifecycleRules: [
'expiration',
'noncurrentVersionExpiration',
'abortIncompleteMultipartUpload',
'transitions',
'noncurrentVersionTransition'
]
};

module.exports = constants;
7 changes: 7 additions & 0 deletions tests/functional/lifecycle/configObjects.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ const lcConfig = {
enabled: true,
},
},
supportedLifecycleRules: [
'expiration',
'noncurrentVersionExpiration',
'abortIncompleteMultipartUpload',
'transitions',
'noncurrentVersionTransition'
]
};

const repConfig = {
Expand Down

0 comments on commit 3eacc99

Please sign in to comment.