1
0
Fork 0
mirror of https://github.com/openstf/stf synced 2025-10-05 10:39:25 +02:00

Too much overlap in storage plugin URLs for meaningful loadbalancing and config simplicity. Make poorxy emulate the real situation and change related URLs.

This commit is contained in:
Simo Kinnunen 2015-01-07 14:04:36 +09:00
parent 7c16c40dae
commit 8b9e5d58c9
8 changed files with 70 additions and 57 deletions

View file

@ -15,34 +15,35 @@ module.exports = syrup.serial()
plugin.store = function(type, stream, meta) {
var resolver = Promise.defer()
var req = request.post({
url: url.resolve(options.storageUrl, util.format('s/api/v1/%s', type))
var args = {
url: url.resolve(options.storageUrl, util.format('s/upload/%s', type))
}
var req = request.post(args, function(err, res, body) {
if (err) {
log.error('Upload to "%s" failed', args.url, err.stack)
resolver.reject(err)
}
, function(err, res, body) {
if (err) {
log.error('Upload failed', err.stack)
else if (res.statusCode !== 201) {
log.error('Upload to "%s" failed: HTTP %d', args.url, res.statusCode)
resolver.reject(new Error(util.format(
'Upload to "%s" failed: HTTP %d'
, args.url
, res.statusCode
)))
}
else {
try {
var result = JSON.parse(body)
log.info('Uploaded to "%s"', result.resources.file.href)
resolver.resolve(result.resources.file)
}
catch (err) {
log.error('Invalid JSON in response', err.stack, body)
resolver.reject(err)
}
else if (res.statusCode !== 201) {
log.error('Upload failed: HTTP %d', res.statusCode)
resolver.reject(new Error(util.format(
'Upload failed: HTTP %d'
, res.statusCode
)))
}
else {
try {
var result = JSON.parse(body)
log.info('Uploaded to %s', result.resources.file.href)
resolver.resolve(result.resources.file)
}
catch (err) {
log.error('Invalid JSON in response', err.stack, body)
resolver.reject(err)
}
}
}
)
})
req.form()
.append('file', stream, meta)