|
@@ -4,7 +4,7 @@ const request = require('request')
|
|
|
const ProjectGetter = require('../Project/ProjectGetter')
|
|
const ProjectGetter = require('../Project/ProjectGetter')
|
|
|
const ProjectEntityHandler = require('../Project/ProjectEntityHandler')
|
|
const ProjectEntityHandler = require('../Project/ProjectEntityHandler')
|
|
|
const logger = require('@overleaf/logger')
|
|
const logger = require('@overleaf/logger')
|
|
|
-const { URL } = require('url')
|
|
|
|
|
|
|
+const { URL, URLSearchParams } = require('url')
|
|
|
const OError = require('@overleaf/o-error')
|
|
const OError = require('@overleaf/o-error')
|
|
|
|
|
|
|
|
const ClsiCookieManager = require('./ClsiCookieManager')(
|
|
const ClsiCookieManager = require('./ClsiCookieManager')(
|
|
@@ -122,8 +122,9 @@ const ClsiManager = {
|
|
|
if (options == null) {
|
|
if (options == null) {
|
|
|
options = {}
|
|
options = {}
|
|
|
}
|
|
}
|
|
|
|
|
+ const { compileGroup } = options
|
|
|
const compilerUrl = this._getCompilerUrl(
|
|
const compilerUrl = this._getCompilerUrl(
|
|
|
- options.compileGroup,
|
|
|
|
|
|
|
+ compileGroup,
|
|
|
projectId,
|
|
projectId,
|
|
|
userId,
|
|
userId,
|
|
|
'compile/stop'
|
|
'compile/stop'
|
|
@@ -132,18 +133,15 @@ const ClsiManager = {
|
|
|
url: compilerUrl,
|
|
url: compilerUrl,
|
|
|
method: 'POST',
|
|
method: 'POST',
|
|
|
}
|
|
}
|
|
|
- ClsiManager._makeRequest(projectId, userId, opts, callback)
|
|
|
|
|
|
|
+ ClsiManager._makeRequest(projectId, userId, compileGroup, opts, callback)
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
deleteAuxFiles(projectId, userId, options, clsiserverid, callback) {
|
|
deleteAuxFiles(projectId, userId, options, clsiserverid, callback) {
|
|
|
if (options == null) {
|
|
if (options == null) {
|
|
|
options = {}
|
|
options = {}
|
|
|
}
|
|
}
|
|
|
- const compilerUrl = this._getCompilerUrl(
|
|
|
|
|
- options.compileGroup,
|
|
|
|
|
- projectId,
|
|
|
|
|
- userId
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ const { compileGroup } = options
|
|
|
|
|
+ const compilerUrl = this._getCompilerUrl(compileGroup, projectId, userId)
|
|
|
const opts = {
|
|
const opts = {
|
|
|
url: compilerUrl,
|
|
url: compilerUrl,
|
|
|
method: 'DELETE',
|
|
method: 'DELETE',
|
|
@@ -151,6 +149,7 @@ const ClsiManager = {
|
|
|
ClsiManager._makeRequestWithClsiServerId(
|
|
ClsiManager._makeRequestWithClsiServerId(
|
|
|
projectId,
|
|
projectId,
|
|
|
userId,
|
|
userId,
|
|
|
|
|
+ compileGroup,
|
|
|
opts,
|
|
opts,
|
|
|
clsiserverid,
|
|
clsiserverid,
|
|
|
clsiErr => {
|
|
clsiErr => {
|
|
@@ -274,13 +273,14 @@ const ClsiManager = {
|
|
|
_makeRequestWithClsiServerId(
|
|
_makeRequestWithClsiServerId(
|
|
|
projectId,
|
|
projectId,
|
|
|
userId,
|
|
userId,
|
|
|
|
|
+ compileGroup,
|
|
|
opts,
|
|
opts,
|
|
|
clsiserverid,
|
|
clsiserverid,
|
|
|
callback
|
|
callback
|
|
|
) {
|
|
) {
|
|
|
if (clsiserverid) {
|
|
if (clsiserverid) {
|
|
|
// ignore cookies and newBackend, go straight to the clsi node
|
|
// ignore cookies and newBackend, go straight to the clsi node
|
|
|
- opts.qs = Object.assign({ clsiserverid }, opts.qs)
|
|
|
|
|
|
|
+ opts.qs = Object.assign({ compileGroup, clsiserverid }, opts.qs)
|
|
|
request(opts, (err, response, body) => {
|
|
request(opts, (err, response, body) => {
|
|
|
if (err) {
|
|
if (err) {
|
|
|
return callback(
|
|
return callback(
|
|
@@ -290,11 +290,11 @@ const ClsiManager = {
|
|
|
callback(null, response, body)
|
|
callback(null, response, body)
|
|
|
})
|
|
})
|
|
|
} else {
|
|
} else {
|
|
|
- ClsiManager._makeRequest(projectId, userId, opts, callback)
|
|
|
|
|
|
|
+ ClsiManager._makeRequest(projectId, userId, compileGroup, opts, callback)
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
- _makeRequest(projectId, userId, opts, callback) {
|
|
|
|
|
|
|
+ _makeRequest(projectId, userId, compileGroup, opts, callback) {
|
|
|
async.series(
|
|
async.series(
|
|
|
{
|
|
{
|
|
|
currentBackend(cb) {
|
|
currentBackend(cb) {
|
|
@@ -302,6 +302,7 @@ const ClsiManager = {
|
|
|
ClsiCookieManager.getCookieJar(
|
|
ClsiCookieManager.getCookieJar(
|
|
|
projectId,
|
|
projectId,
|
|
|
userId,
|
|
userId,
|
|
|
|
|
+ compileGroup,
|
|
|
(err, jar, clsiServerId) => {
|
|
(err, jar, clsiServerId) => {
|
|
|
if (err != null) {
|
|
if (err != null) {
|
|
|
return callback(
|
|
return callback(
|
|
@@ -327,6 +328,7 @@ const ClsiManager = {
|
|
|
ClsiCookieManager.setServerId(
|
|
ClsiCookieManager.setServerId(
|
|
|
projectId,
|
|
projectId,
|
|
|
userId,
|
|
userId,
|
|
|
|
|
+ compileGroup,
|
|
|
response,
|
|
response,
|
|
|
clsiServerId,
|
|
clsiServerId,
|
|
|
(err, newClsiServerId) => {
|
|
(err, newClsiServerId) => {
|
|
@@ -361,6 +363,7 @@ const ClsiManager = {
|
|
|
ClsiManager._makeNewBackendRequest(
|
|
ClsiManager._makeNewBackendRequest(
|
|
|
projectId,
|
|
projectId,
|
|
|
userId,
|
|
userId,
|
|
|
|
|
+ compileGroup,
|
|
|
opts,
|
|
opts,
|
|
|
(err, response, body) => {
|
|
(err, response, body) => {
|
|
|
if (err != null) {
|
|
if (err != null) {
|
|
@@ -407,7 +410,7 @@ const ClsiManager = {
|
|
|
)
|
|
)
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
- _makeNewBackendRequest(projectId, userId, baseOpts, callback) {
|
|
|
|
|
|
|
+ _makeNewBackendRequest(projectId, userId, compileGroup, baseOpts, callback) {
|
|
|
if (Settings.apis.clsi_new == null || Settings.apis.clsi_new.url == null) {
|
|
if (Settings.apis.clsi_new == null || Settings.apis.clsi_new.url == null) {
|
|
|
return callback()
|
|
return callback()
|
|
|
}
|
|
}
|
|
@@ -421,6 +424,7 @@ const ClsiManager = {
|
|
|
NewBackendCloudClsiCookieManager.getCookieJar(
|
|
NewBackendCloudClsiCookieManager.getCookieJar(
|
|
|
projectId,
|
|
projectId,
|
|
|
userId,
|
|
userId,
|
|
|
|
|
+ compileGroup,
|
|
|
(err, jar, clsiServerId) => {
|
|
(err, jar, clsiServerId) => {
|
|
|
if (err != null) {
|
|
if (err != null) {
|
|
|
return callback(
|
|
return callback(
|
|
@@ -444,6 +448,7 @@ const ClsiManager = {
|
|
|
NewBackendCloudClsiCookieManager.setServerId(
|
|
NewBackendCloudClsiCookieManager.setServerId(
|
|
|
projectId,
|
|
projectId,
|
|
|
userId,
|
|
userId,
|
|
|
|
|
+ compileGroup,
|
|
|
response,
|
|
response,
|
|
|
clsiServerId,
|
|
clsiServerId,
|
|
|
err => {
|
|
err => {
|
|
@@ -463,15 +468,15 @@ const ClsiManager = {
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
_getCompilerUrl(compileGroup, projectId, userId, action) {
|
|
_getCompilerUrl(compileGroup, projectId, userId, action) {
|
|
|
- const host = Settings.apis.clsi.url
|
|
|
|
|
- let path = `/project/${projectId}`
|
|
|
|
|
|
|
+ const u = new URL(`/project/${projectId}`, Settings.apis.clsi.url)
|
|
|
if (userId != null) {
|
|
if (userId != null) {
|
|
|
- path += `/user/${userId}`
|
|
|
|
|
|
|
+ u.pathname += `/user/${userId}`
|
|
|
}
|
|
}
|
|
|
if (action != null) {
|
|
if (action != null) {
|
|
|
- path += `/${action}`
|
|
|
|
|
|
|
+ u.pathname += `/${action}`
|
|
|
}
|
|
}
|
|
|
- return `${host}${path}`
|
|
|
|
|
|
|
+ u.search = new URLSearchParams({ compileGroup }).toString()
|
|
|
|
|
+ return u.href
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
_postToClsi(projectId, userId, req, compileGroup, callback) {
|
|
_postToClsi(projectId, userId, req, compileGroup, callback) {
|
|
@@ -489,16 +494,21 @@ const ClsiManager = {
|
|
|
ClsiManager._makeRequest(
|
|
ClsiManager._makeRequest(
|
|
|
projectId,
|
|
projectId,
|
|
|
userId,
|
|
userId,
|
|
|
|
|
+ compileGroup,
|
|
|
opts,
|
|
opts,
|
|
|
(err, response, body, clsiServerId) => {
|
|
(err, response, body, clsiServerId) => {
|
|
|
if (err != null) {
|
|
if (err != null) {
|
|
|
return callback(
|
|
return callback(
|
|
|
- new OError('failed to make request to CLSI', {
|
|
|
|
|
- projectId,
|
|
|
|
|
- userId,
|
|
|
|
|
- compileOptions: req.compile.options,
|
|
|
|
|
- rootResourcePath: req.compile.rootResourcePath,
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ new OError(
|
|
|
|
|
+ 'failed to make request to CLSI',
|
|
|
|
|
+ {
|
|
|
|
|
+ projectId,
|
|
|
|
|
+ userId,
|
|
|
|
|
+ compileOptions: req.compile.options,
|
|
|
|
|
+ rootResourcePath: req.compile.rootResourcePath,
|
|
|
|
|
+ },
|
|
|
|
|
+ err
|
|
|
|
|
+ )
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
if (response.statusCode >= 200 && response.statusCode < 300) {
|
|
if (response.statusCode >= 200 && response.statusCode < 300) {
|
|
@@ -655,9 +665,18 @@ const ClsiManager = {
|
|
|
)
|
|
)
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
- getOutputFileStream(projectId, userId, buildId, outputFilePath, callback) {
|
|
|
|
|
|
|
+ getOutputFileStream(
|
|
|
|
|
+ projectId,
|
|
|
|
|
+ userId,
|
|
|
|
|
+ compileGroup,
|
|
|
|
|
+ clsiServerId,
|
|
|
|
|
+ buildId,
|
|
|
|
|
+ outputFilePath,
|
|
|
|
|
+ callback
|
|
|
|
|
+ ) {
|
|
|
const url = `${Settings.apis.clsi.url}/project/${projectId}/user/${userId}/build/${buildId}/output/${outputFilePath}`
|
|
const url = `${Settings.apis.clsi.url}/project/${projectId}/user/${userId}/build/${buildId}/output/${outputFilePath}`
|
|
|
- ClsiCookieManager.getCookieJar(projectId, userId, (err, jar) => {
|
|
|
|
|
|
|
+ // TODO(das7pad): remove one week after landing frontend changes.
|
|
|
|
|
+ ClsiCookieManager.getCookieJar(projectId, userId, '', (err, jar) => {
|
|
|
if (err != null) {
|
|
if (err != null) {
|
|
|
return callback(
|
|
return callback(
|
|
|
OError.tag(err, 'Failed to get cookie jar', {
|
|
OError.tag(err, 'Failed to get cookie jar', {
|
|
@@ -669,6 +688,10 @@ const ClsiManager = {
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
const options = { url, method: 'GET', timeout: 60 * 1000, jar }
|
|
const options = { url, method: 'GET', timeout: 60 * 1000, jar }
|
|
|
|
|
+ if (clsiServerId) {
|
|
|
|
|
+ options.qs = { compileGroup, clsiserverid: clsiServerId }
|
|
|
|
|
+ delete options.jar
|
|
|
|
|
+ }
|
|
|
const readStream = request(options)
|
|
const readStream = request(options)
|
|
|
callback(null, readStream)
|
|
callback(null, readStream)
|
|
|
})
|
|
})
|
|
@@ -863,6 +886,7 @@ const ClsiManager = {
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
wordCount(projectId, userId, file, options, clsiserverid, callback) {
|
|
wordCount(projectId, userId, file, options, clsiserverid, callback) {
|
|
|
|
|
+ const { compileGroup } = options
|
|
|
ClsiManager._buildRequest(projectId, options, (err, req) => {
|
|
ClsiManager._buildRequest(projectId, options, (err, req) => {
|
|
|
if (err != null) {
|
|
if (err != null) {
|
|
|
return callback(
|
|
return callback(
|
|
@@ -874,7 +898,7 @@ const ClsiManager = {
|
|
|
}
|
|
}
|
|
|
const filename = file || req.compile.rootResourcePath
|
|
const filename = file || req.compile.rootResourcePath
|
|
|
const wordCountUrl = ClsiManager._getCompilerUrl(
|
|
const wordCountUrl = ClsiManager._getCompilerUrl(
|
|
|
- options.compileGroup,
|
|
|
|
|
|
|
+ compileGroup,
|
|
|
projectId,
|
|
projectId,
|
|
|
userId,
|
|
userId,
|
|
|
'wordcount'
|
|
'wordcount'
|
|
@@ -891,6 +915,7 @@ const ClsiManager = {
|
|
|
ClsiManager._makeRequestWithClsiServerId(
|
|
ClsiManager._makeRequestWithClsiServerId(
|
|
|
projectId,
|
|
projectId,
|
|
|
userId,
|
|
userId,
|
|
|
|
|
+ compileGroup,
|
|
|
opts,
|
|
opts,
|
|
|
clsiserverid,
|
|
clsiserverid,
|
|
|
(err, response, body) => {
|
|
(err, response, body) => {
|