diff --git a/Clients/CloudserverClient.js b/Clients/CloudserverClient.js index 501aa3da..54d76af9 100644 --- a/Clients/CloudserverClient.js +++ b/Clients/CloudserverClient.js @@ -2,6 +2,9 @@ const { CloudserverClient, GetMetadataCommand, PutMetadataCommand, + GetLocationsStatusCommand, + ListFailedCommand, + RetryFailedObjectsCommand, } = require('@scality/cloudserverclient'); const { http: httpArsn } = require('httpagent'); const https = require('https'); @@ -63,6 +66,27 @@ class Client { .then(data => callback(null, data)) .catch(err => callback(err)); } + + getLocationsStatus(callback) { + const command = new GetLocationsStatusCommand({}); + this.client.send(command) + .then(data => callback(null, data)) + .catch(err => callback(err)); + } + + listFailed(params, callback) { + const command = new ListFailedCommand(params); + this.client.send(command) + .then(data => callback(null, data)) + .catch(err => callback(err)); + } + + retryFailedObjects(params, callback) { + const command = new RetryFailedObjectsCommand(); + this.client.send(command) + .then(data => callback(null, data)) + .catch(err => callback(err)); + } } module.exports = Client; diff --git a/StalledRetry/StalledRequestHandler.js b/StalledRetry/StalledRequestHandler.js index f4d812de..4d9dad78 100644 --- a/StalledRetry/StalledRequestHandler.js +++ b/StalledRetry/StalledRequestHandler.js @@ -35,7 +35,7 @@ class StalledRequestHandler { } return this.client.retryFailedObjects({ - Body: JSON.stringify(batch.map(entry => entry.toObject())), + Body: Buffer.from(JSON.stringify(batch.map(entry => entry.toObject()))), }, err => { if (err) { return done(err); diff --git a/autoRetryFailedCRR.js b/autoRetryFailedCRR.js index 1a42d359..f22d91ec 100644 --- a/autoRetryFailedCRR.js +++ b/autoRetryFailedCRR.js @@ -1,6 +1,6 @@ const { waterfall, mapValuesLimit } = require('async'); const { Logger } = require('werelogs'); -const ZenkoClient = require('zenkoclient'); +const CloudserverClient = require('./Clients/CloudserverClient'); const log = new Logger('s3utils::autoRetryFailedCRR'); const { ACCESS_KEY } = process.env; @@ -16,29 +16,24 @@ if (!SECRET_KEY) { throw new Error('SECRET_KEY not defined'); } -const zenkoClient = new ZenkoClient({ - apiVersion: '2018-07-08-json', - accessKeyId: ACCESS_KEY, - secretAccessKey: SECRET_KEY, - endpoint: ENDPOINT, - s3ForcePathStyle: true, - signatureVersion: 'v4', - maxRetries: 0, - sslEnabled: false, - httpOptions: { timeout: 0 }, -}); +const cloudserverclient = new CloudserverClient( + ENDPOINT, + ACCESS_KEY, + SECRET_KEY, +); waterfall([ - next => zenkoClient.getLocationsStatus(next), - (locations, next) => { + next => cloudserverclient.getLocationsStatus(next), + (res, next) => { + const locations = res.status || {}; mapValuesLimit(locations, 3, (status, location, done) => { - zenkoClient.listFailed({ Sitename: location }, (err, res) => { + cloudserverclient.listFailed({ Sitename: location }, (err, res) => { if (err) { return done(err); } - if (res.Versions.length > 0) { - return zenkoClient.retryFailedObjects({ - Body: JSON.stringify(res.Versions), + if (res.Versions && res.Versions.length > 0) { + return cloudserverclient.retryFailedObjects({ + Body: Buffer.from(JSON.stringify(res.Versions)), }, done); } return done(); diff --git a/cleanupNoncurrentVersions.js b/cleanupNoncurrentVersions.js index 1884d492..50ce573d 100644 --- a/cleanupNoncurrentVersions.js +++ b/cleanupNoncurrentVersions.js @@ -9,7 +9,6 @@ const { doWhilst, eachSeries, filterLimit } = require('async'); const { Logger } = require('werelogs'); -const BackbeatClient = require('./BackbeatClient'); const CloudserverClient = require('./Clients/CloudserverClient'); const parseOlderThan = require('./utils/parseOlderThan'); diff --git a/package.json b/package.json index 7623f063..a5097fa4 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "dependencies": { "@aws-sdk/client-s3": "^3.873.0", "@aws-sdk/node-http-handler": "^3.374.0", - "@scality/cloudserverclient": "git+https://github.com/scality/cloudserverclient#v1.0.0", + "@scality/cloudserverclient": "^1.0.2", "@senx/warp10": "^2.0.3", "@smithy/util-retry": "^4.0.7", "JSONStream": "^1.3.5", @@ -46,8 +46,7 @@ "uuid": "^11.0.3", "vaultclient": "scality/vaultclient#8.5.1", "werelogs": "scality/werelogs#8.2.1", - "xml2js": "^0.6.2", - "zenkoclient": "scality/zenkoclient#1.2.1" + "xml2js": "^0.6.2" }, "resolutions": { "ioctl": "2.0.2", diff --git a/stalled.js b/stalled.js index 2a06a1af..dea1ce50 100644 --- a/stalled.js +++ b/stalled.js @@ -1,6 +1,6 @@ const assert = require('assert'); const { Logger } = require('werelogs'); -const ZenkoClient = require('zenkoclient'); +const CloudserverClient = require('./Clients/CloudserverClient'); const { MongoClientInterfaceStalled, @@ -59,20 +59,14 @@ function wrapperFactory(bucketName, cmpDate, cursor, log) { } function handlerFactory(log) { - const zenkoClient = new ZenkoClient({ - apiVersion: '2018-07-08-json', - accessKeyId: ACCESS_KEY, - secretAccessKey: SECRET_KEY, - endpoint: ENDPOINT, - s3ForcePathStyle: true, - signatureVersion: 'v4', - maxRetries: 0, - sslEnabled: false, - httpOptions: { timeout: 0 }, - }); + const cloudserverClient = new CloudserverClient( + ENDPOINT, + ACCESS_KEY, + SECRET_KEY, + ); return new StalledRequestHandler( - zenkoClient, + cloudserverClient, { dryRun: DRY_RUN, batchSize: BATCH_SIZE, diff --git a/yarn.lock b/yarn.lock index 6252b47b..fd43df66 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1905,9 +1905,10 @@ resolved "https://registry.yarnpkg.com/@rtsao/scc/-/scc-1.1.0.tgz#927dd2fae9bc3361403ac2c7a00c32ddce9ad7e8" integrity sha512-zt6OdqaDoOnJ1ZYsCYGt9YmWzDXl4vQdKTyJev62gFhRGKdx7mcT54V9KIjg+d2wi9EXsPvAPKe7i7WjfVWB8g== -"@scality/cloudserverclient@git+https://github.com/scality/cloudserverclient#v1.0.0": - version "1.0.0" - resolved "git+https://github.com/scality/cloudserverclient#5be9d7bb697ac7010ed1a0f862748c0b4840aa71" +"@scality/cloudserverclient@^1.0.2": + version "1.0.2" + resolved "https://registry.yarnpkg.com/@scality/cloudserverclient/-/cloudserverclient-1.0.2.tgz#8d30aafc7dde7ad09d4dcac7323eb2161ce98ffe" + integrity sha512-7Q4b9LQxUGB6DqNxZPDT6rxUAhWgJlXVAOy9ZHY7Vu4m2UOfvbaaxBXo7C4T3d2lxwdgOEWbdc+4GZoykqRI9Q== dependencies: "@aws-sdk/client-s3" "^3.896.0" JSONStream "^1.3.5" @@ -3537,7 +3538,7 @@ available-typed-arrays@^1.0.7: dependencies: possible-typed-array-names "^1.0.0" -aws-sdk@^2.1005.0, aws-sdk@^2.1691.0: +aws-sdk@^2.1691.0: version "2.1692.0" resolved "https://registry.yarnpkg.com/aws-sdk/-/aws-sdk-2.1692.0.tgz#9dac5f7bfcc5ab45825cc8591b12753aa7d2902c" integrity sha512-x511uiJ/57FIsbgUe5csJ13k3uzu25uWQE+XqfBis/sB0SFoiElJWXRkgEAUh0U6n40eT3ay5Ue4oPkRMu1LYw== @@ -8433,9 +8434,3 @@ yocto-queue@^0.1.0: version "0.1.0" resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-0.1.0.tgz#0294eb3dee05028d31ee1a5fa2c556a6aaf10a1b" integrity sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q== - -zenkoclient@scality/zenkoclient#1.2.1: - version "1.2.1" - resolved "https://codeload.github.com/scality/zenkoclient/tar.gz/da298747e292eb2d0058d9e070e8fe93dd897bdc" - dependencies: - aws-sdk "^2.1005.0"