我试图通过API端点api/2.0/jobs/run-now
调用Databricks api来通过其ID运行笔记本或作业,但出现类似getaddrinfo ENOTFOUND https://adb-<workspace-id>.<random-number>.azuredatabricks.net/api/2.0/jobs/run-now
的错误。但是我提供了正确的网址(注意:按照Example Job API
下面是我的Node.JS代码:
router.get('/triggerJob', (req, res) => {
var job_payload = {
"job_id": <Job_ID>
}
var options = {
host: 'https://adb-<workspaceid>.<number>.azuredatabricks.net/api/2.0/jobs/run-now',
body: JSON.stringify(job_payload),
method: 'Post',
headers: { 'Authorization': 'token' }
}
var data = '';
console.log('till here')
var request = https.request(options, function (result) {
var body = "";
result.on('data', function (data) {
console.log('data came');
body += data;
});
result.on('end', function () {
console.log('ended too');
data = JSON.parse(body);
res.json(data);
});
});
request.on('error', function (e) {
console.log('Problem with request: ' + e.message);
});
request.end();
})
答案 0 :(得分:0)
当我获得问题的解决方案时,我想与所有人分享以备将来参考。
根据Microsoft文档:enter link description here
他们要求我们用https://adb-<workspaceid>.<number>.azuredatabricks.net/api/2.0/jobs/run-now
来访问URL,但我知道我们需要点击该URL:
https:// <{locationname}> .azuredatabricks.net,然后选择api / 2.0 / jobs / run-now。所以下面是相同的代码:
const request=require("request");
const rp=require("request-promise");
const triggerJob=((res,req)=>{
var job_payload = {
"job_id": <Job_ID>
}
var options = {
host: 'https://<locationname>.azuredatabricks.net/api/2.0/jobs/run-now',
body: JSON.stringify(job_payload),
method: 'Post',
headers: { 'Content-Type':'application/jsoon','Authorization': 'Bearer token' }
}
var response=await rp(url,options);
if(response!=null){
return res.json(response)
}
});
module.exports= triggerJob;
为了清晰起见,我将代码行最小化。