2013-01-02 20:31:14 +00:00
|
|
|
// This file is part of BOINC.
|
|
|
|
// http://boinc.berkeley.edu
|
|
|
|
// Copyright (C) 2012 University of California
|
|
|
|
//
|
|
|
|
// BOINC is free software; you can redistribute it and/or modify it
|
|
|
|
// under the terms of the GNU Lesser General Public License
|
|
|
|
// as published by the Free Software Foundation,
|
|
|
|
// either version 3 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// BOINC is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
// See the GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2013-03-06 04:30:12 +00:00
|
|
|
// C++ interfaces to web RPCs related to remote job submission,
|
|
|
|
// namely those described here:
|
2023-05-25 19:59:56 +00:00
|
|
|
// https://github.com/BOINC/boinc/wiki/RemoteInputFiles
|
|
|
|
// https://github.com/BOINC/boinc/wiki/RemoteOutputFiles
|
|
|
|
// https://github.com/BOINC/boinc/wiki/RemoteJobs
|
2013-03-06 04:30:12 +00:00
|
|
|
|
2013-01-02 20:31:14 +00:00
|
|
|
#include <curl/curl.h>
|
|
|
|
#include <stdio.h>
|
2013-01-17 03:42:48 +00:00
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
2013-01-25 08:35:00 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "parse.h"
|
2013-10-22 22:27:34 +00:00
|
|
|
#include "str_util.h"
|
2013-08-27 03:52:25 +00:00
|
|
|
#include "url.h"
|
2013-01-02 20:31:14 +00:00
|
|
|
|
2013-02-21 00:20:00 +00:00
|
|
|
#include "remote_submit.h"
|
2013-01-17 03:42:48 +00:00
|
|
|
|
|
|
|
using std::vector;
|
|
|
|
using std::string;
|
|
|
|
|
2016-07-31 18:43:40 +00:00
|
|
|
//#define SHOW_REQUEST
|
2013-05-29 06:14:17 +00:00
|
|
|
//#define SHOW_REPLY
|
|
|
|
|
2016-07-27 08:07:07 +00:00
|
|
|
// replies can have one or more <error> elements.
|
|
|
|
// These can be either PHP Notices or Warnings (which are not fatal),
|
|
|
|
// or fatal errors.
|
|
|
|
// Fatal errors have nonzero error_num.
|
|
|
|
//
|
2021-08-16 13:55:54 +00:00
|
|
|
struct RS_ERROR {
|
2016-07-27 08:07:07 +00:00
|
|
|
int error_num;
|
|
|
|
char error_msg[256];
|
|
|
|
char type[256];
|
|
|
|
char file[256];
|
|
|
|
char line[256];
|
|
|
|
|
|
|
|
void parse(XML_PARSER& xp) {
|
|
|
|
error_num = 0;
|
|
|
|
strcpy(error_msg, "");
|
|
|
|
strcpy(type, "");
|
|
|
|
strcpy(file, "");
|
|
|
|
strcpy(line, "");
|
|
|
|
while (!xp.get_tag()) {
|
|
|
|
if (xp.match_tag("/error")) break;
|
|
|
|
if (xp.parse_str("error_msg", error_msg, sizeof(error_msg))) continue;
|
|
|
|
if (xp.parse_int("error_num", error_num)) continue;
|
|
|
|
if (xp.parse_str("type", type, sizeof(type))) continue;
|
|
|
|
if (xp.parse_str("file", file, sizeof(file))) continue;
|
|
|
|
if (xp.parse_str("line", line, sizeof(line))) continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-01-31 22:06:17 +00:00
|
|
|
// do an HTTP GET request.
|
|
|
|
//
|
|
|
|
static int do_http_get(
|
|
|
|
const char* url,
|
|
|
|
const char* dst_path
|
|
|
|
) {
|
|
|
|
FILE* reply = fopen(dst_path, "w");
|
|
|
|
if (!reply) return -1;
|
|
|
|
CURL *curl = curl_easy_init();
|
|
|
|
if (!curl) {
|
2013-05-04 05:40:46 +00:00
|
|
|
fclose(reply);
|
2013-01-31 22:06:17 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
curl_easy_setopt(curl, CURLOPT_URL, url);
|
2013-02-21 00:20:00 +00:00
|
|
|
curl_easy_setopt(curl, CURLOPT_USERAGENT, "BOINC remote job submission");
|
2013-01-31 22:06:17 +00:00
|
|
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, reply);
|
|
|
|
|
|
|
|
CURLcode res = curl_easy_perform(curl);
|
|
|
|
if (res != CURLE_OK) {
|
|
|
|
fprintf(stderr, "CURL error: %s\n", curl_easy_strerror(res));
|
|
|
|
}
|
|
|
|
|
|
|
|
curl_easy_cleanup(curl);
|
2013-05-04 05:40:46 +00:00
|
|
|
fclose(reply);
|
2013-01-31 22:06:17 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-01-17 03:42:48 +00:00
|
|
|
// send an HTTP POST request,
|
|
|
|
// with an optional set of multi-part file attachments
|
|
|
|
//
|
2013-01-25 08:35:00 +00:00
|
|
|
static int do_http_post(
|
2013-01-17 03:42:48 +00:00
|
|
|
const char* url,
|
|
|
|
const char* request,
|
|
|
|
FILE* reply,
|
|
|
|
vector<string> send_files
|
|
|
|
) {
|
2013-01-02 20:31:14 +00:00
|
|
|
CURL *curl;
|
|
|
|
CURLcode res;
|
2013-01-17 03:42:48 +00:00
|
|
|
char buf[256];
|
2023-05-05 18:05:20 +00:00
|
|
|
|
2013-01-02 20:31:14 +00:00
|
|
|
curl = curl_easy_init();
|
|
|
|
if (!curl) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-07-31 18:43:40 +00:00
|
|
|
#ifdef SHOW_REQUEST
|
|
|
|
printf("HTTP request:\n%s\n", request);
|
|
|
|
#endif
|
|
|
|
|
2013-01-17 03:42:48 +00:00
|
|
|
struct curl_httppost *formpost=NULL;
|
|
|
|
struct curl_httppost *lastptr=NULL;
|
|
|
|
struct curl_slist *headerlist=NULL;
|
|
|
|
|
2013-01-02 20:31:14 +00:00
|
|
|
curl_formadd(&formpost, &lastptr,
|
2013-01-17 03:42:48 +00:00
|
|
|
CURLFORM_COPYNAME, "request",
|
|
|
|
CURLFORM_COPYCONTENTS, request,
|
2013-01-02 20:31:14 +00:00
|
|
|
CURLFORM_END
|
|
|
|
);
|
2013-01-17 03:42:48 +00:00
|
|
|
for (unsigned int i=0; i<send_files.size(); i++) {
|
2022-08-03 09:21:59 +00:00
|
|
|
snprintf(buf, sizeof(buf), "file_%d", i);
|
2013-01-17 03:42:48 +00:00
|
|
|
string s = send_files[i];
|
|
|
|
curl_formadd(&formpost, &lastptr,
|
|
|
|
CURLFORM_COPYNAME, buf,
|
|
|
|
CURLFORM_FILE, s.c_str(),
|
|
|
|
CURLFORM_END
|
|
|
|
);
|
|
|
|
}
|
2023-05-05 18:05:20 +00:00
|
|
|
|
2013-01-02 20:31:14 +00:00
|
|
|
headerlist = curl_slist_append(headerlist, "Expect:");
|
|
|
|
curl_easy_setopt(curl, CURLOPT_URL, url);
|
|
|
|
curl_easy_setopt(curl, CURLOPT_USERAGENT, "BOINC Condor adapter");
|
|
|
|
curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
|
2013-01-17 03:42:48 +00:00
|
|
|
curl_easy_setopt(curl, CURLOPT_READDATA, request);
|
|
|
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, reply);
|
2013-01-02 20:31:14 +00:00
|
|
|
|
|
|
|
res = curl_easy_perform(curl);
|
|
|
|
if (res != CURLE_OK) {
|
|
|
|
fprintf(stderr, "CURL error: %s\n", curl_easy_strerror(res));
|
|
|
|
}
|
|
|
|
|
|
|
|
curl_easy_cleanup(curl);
|
|
|
|
curl_formfree(formpost);
|
|
|
|
curl_slist_free_all(headerlist);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-01-25 08:35:00 +00:00
|
|
|
int query_files(
|
|
|
|
const char* project_url,
|
|
|
|
const char* authenticator,
|
2016-07-22 23:10:23 +00:00
|
|
|
vector<string> &boinc_names,
|
2013-02-07 06:06:52 +00:00
|
|
|
int batch_id,
|
2013-03-06 23:00:15 +00:00
|
|
|
vector<int> &absent_files,
|
|
|
|
string& error_msg
|
2013-01-25 08:35:00 +00:00
|
|
|
) {
|
|
|
|
string req_msg;
|
|
|
|
char buf[256];
|
|
|
|
req_msg = "<query_files>\n";
|
2022-08-03 09:21:59 +00:00
|
|
|
snprintf(buf, sizeof(buf), "<authenticator>%s</authenticator>\n", authenticator);
|
2013-01-25 08:35:00 +00:00
|
|
|
req_msg += string(buf);
|
|
|
|
if (batch_id) {
|
2022-08-03 09:21:59 +00:00
|
|
|
snprintf(buf, sizeof(buf), "<batch_id>%d</batch_id>\n", batch_id);
|
2013-01-25 08:35:00 +00:00
|
|
|
req_msg += string(buf);
|
|
|
|
}
|
2016-07-22 23:10:23 +00:00
|
|
|
for (unsigned int i=0; i<boinc_names.size(); i++) {
|
2022-08-03 09:21:59 +00:00
|
|
|
snprintf(buf, sizeof(buf), " <phys_name>%s</phys_name>\n", boinc_names[i].c_str());
|
2013-01-25 08:35:00 +00:00
|
|
|
req_msg += string(buf);
|
|
|
|
}
|
|
|
|
req_msg += "</query_files>\n";
|
|
|
|
FILE* reply = tmpfile();
|
|
|
|
char url[256];
|
2022-08-03 09:21:59 +00:00
|
|
|
snprintf(url, sizeof(url), "%sjob_file.php", project_url);
|
2013-10-09 00:36:45 +00:00
|
|
|
vector<string> xx;
|
|
|
|
int retval = do_http_post(url, req_msg.c_str(), reply, xx);
|
2013-01-25 08:35:00 +00:00
|
|
|
if (retval) {
|
|
|
|
fclose(reply);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
fseek(reply, 0, SEEK_SET);
|
|
|
|
int x;
|
2016-07-27 08:07:07 +00:00
|
|
|
retval = 0;
|
|
|
|
MIOFILE mf;
|
|
|
|
mf.init_file(reply);
|
|
|
|
XML_PARSER xp(&mf);
|
|
|
|
while (!xp.get_tag()) {
|
2013-05-29 06:14:17 +00:00
|
|
|
#ifdef SHOW_REPLY
|
2016-07-27 08:07:07 +00:00
|
|
|
printf("query_files reply: %s\n", xp.parsed_tag);
|
2013-05-29 06:14:17 +00:00
|
|
|
#endif
|
2016-07-27 08:07:07 +00:00
|
|
|
if (xp.match_tag("absent_files")) {
|
|
|
|
while (!xp.get_tag()) {
|
|
|
|
if (xp.match_tag("/absent_files")) break;
|
|
|
|
if (xp.parse_int("file", x)) {
|
|
|
|
absent_files.push_back(x);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (xp.match_tag("error")) {
|
2021-08-16 13:55:54 +00:00
|
|
|
RS_ERROR error;
|
2016-07-27 08:07:07 +00:00
|
|
|
error.parse(xp);
|
|
|
|
if (error.error_num) {
|
|
|
|
retval = error.error_num;
|
|
|
|
error_msg = error.error_msg;
|
|
|
|
}
|
2013-01-25 08:35:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose(reply);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
int upload_files (
|
|
|
|
const char* project_url,
|
|
|
|
const char* authenticator,
|
2013-02-07 06:06:52 +00:00
|
|
|
vector<string> &paths,
|
2016-07-22 23:10:23 +00:00
|
|
|
vector<string> &boinc_names,
|
2013-03-06 23:00:15 +00:00
|
|
|
int batch_id,
|
|
|
|
string &error_msg
|
2013-01-25 08:35:00 +00:00
|
|
|
) {
|
|
|
|
char buf[1024];
|
|
|
|
string req_msg = "<upload_files>\n";
|
2022-08-03 09:21:59 +00:00
|
|
|
snprintf(buf, sizeof(buf), "<authenticator>%s</authenticator>\n", authenticator);
|
2013-01-25 19:30:50 +00:00
|
|
|
req_msg += string(buf);
|
|
|
|
if (batch_id) {
|
2022-08-03 09:21:59 +00:00
|
|
|
snprintf(buf, sizeof(buf), "<batch_id>%d</batch_id>\n", batch_id);
|
2013-01-25 19:30:50 +00:00
|
|
|
req_msg += string(buf);
|
|
|
|
}
|
2016-07-22 23:10:23 +00:00
|
|
|
for (unsigned int i=0; i<boinc_names.size(); i++) {
|
2022-08-03 09:21:59 +00:00
|
|
|
snprintf(buf, sizeof(buf), "<phys_name>%s</phys_name>\n", boinc_names[i].c_str());
|
2013-01-25 08:35:00 +00:00
|
|
|
req_msg += string(buf);
|
|
|
|
}
|
2013-01-25 19:30:50 +00:00
|
|
|
req_msg += "</upload_files>\n";
|
2013-01-25 08:35:00 +00:00
|
|
|
FILE* reply = tmpfile();
|
|
|
|
char url[256];
|
2022-08-03 09:21:59 +00:00
|
|
|
snprintf(url, sizeof(url), "%sjob_file.php", project_url);
|
2013-01-25 08:35:00 +00:00
|
|
|
int retval = do_http_post(url, req_msg.c_str(), reply, paths);
|
|
|
|
if (retval) {
|
|
|
|
fclose(reply);
|
|
|
|
return retval;
|
|
|
|
}
|
2013-01-25 19:30:50 +00:00
|
|
|
fseek(reply, 0, SEEK_SET);
|
2013-03-06 23:00:15 +00:00
|
|
|
retval = -1;
|
2016-07-27 08:07:07 +00:00
|
|
|
bool success;
|
|
|
|
MIOFILE mf;
|
|
|
|
mf.init_file(reply);
|
|
|
|
XML_PARSER xp(&mf);
|
|
|
|
while (!xp.get_tag()) {
|
2013-05-29 06:14:17 +00:00
|
|
|
#ifdef SHOW_REPLY
|
2016-07-27 08:07:07 +00:00
|
|
|
printf("upload_files reply: %s\n", xp.parsed_tag);
|
2013-05-29 06:14:17 +00:00
|
|
|
#endif
|
2016-07-27 08:07:07 +00:00
|
|
|
if (xp.parse_bool("success", success)) {
|
2013-03-06 23:00:15 +00:00
|
|
|
retval = 0;
|
|
|
|
continue;
|
2013-01-25 08:35:00 +00:00
|
|
|
}
|
2016-07-27 08:07:07 +00:00
|
|
|
if (xp.match_tag("error")) {
|
2021-08-16 13:55:54 +00:00
|
|
|
RS_ERROR error;
|
2016-07-27 08:07:07 +00:00
|
|
|
error.parse(xp);
|
|
|
|
if (error.error_num) {
|
|
|
|
retval = error.error_num;
|
|
|
|
error_msg = error.error_msg;
|
|
|
|
}
|
|
|
|
}
|
2013-01-25 08:35:00 +00:00
|
|
|
}
|
|
|
|
fclose(reply);
|
2013-03-06 23:00:15 +00:00
|
|
|
return retval;
|
2013-01-25 08:35:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int create_batch(
|
|
|
|
const char* project_url,
|
|
|
|
const char* authenticator,
|
2013-01-26 06:43:57 +00:00
|
|
|
const char* batch_name,
|
|
|
|
const char* app_name,
|
2013-09-17 20:35:55 +00:00
|
|
|
double expire_time,
|
2013-03-06 23:00:15 +00:00
|
|
|
int& batch_id,
|
|
|
|
string& error_msg
|
2013-01-25 08:35:00 +00:00
|
|
|
) {
|
|
|
|
char request[1024];
|
|
|
|
char url[1024];
|
2022-08-03 09:21:59 +00:00
|
|
|
snprintf(request, sizeof(request),
|
2013-01-25 08:35:00 +00:00
|
|
|
"<create_batch>\n"
|
|
|
|
" <authenticator>%s</authenticator>\n"
|
2018-04-12 14:46:54 +00:00
|
|
|
" <batch_name>%s</batch_name>\n"
|
|
|
|
" <app_name>%s</app_name>\n"
|
|
|
|
" <expire_time>%f</expire_time>\n"
|
2013-01-25 08:35:00 +00:00
|
|
|
"</create_batch>\n",
|
|
|
|
authenticator,
|
2013-01-26 06:43:57 +00:00
|
|
|
batch_name,
|
2013-09-17 20:35:55 +00:00
|
|
|
app_name,
|
|
|
|
expire_time
|
2013-01-17 03:42:48 +00:00
|
|
|
);
|
2022-08-03 09:21:59 +00:00
|
|
|
snprintf(url, sizeof(url), "%ssubmit_rpc_handler.php", project_url);
|
2013-01-25 08:35:00 +00:00
|
|
|
FILE* reply = tmpfile();
|
|
|
|
vector<string> x;
|
|
|
|
int retval = do_http_post(url, request, reply, x);
|
|
|
|
if (retval) {
|
|
|
|
fclose(reply);
|
|
|
|
return retval;
|
|
|
|
}
|
2013-01-26 06:43:57 +00:00
|
|
|
batch_id = 0;
|
2013-01-25 08:35:00 +00:00
|
|
|
fseek(reply, 0, SEEK_SET);
|
2016-07-27 08:07:07 +00:00
|
|
|
MIOFILE mf;
|
|
|
|
mf.init_file(reply);
|
|
|
|
XML_PARSER xp(&mf);
|
|
|
|
retval = 0;
|
|
|
|
while (!xp.get_tag()) {
|
2013-05-29 06:14:17 +00:00
|
|
|
#ifdef SHOW_REPLY
|
2016-07-27 08:07:07 +00:00
|
|
|
printf("create_batch reply: %s\n", xp.parsed_tag);
|
2013-05-29 06:14:17 +00:00
|
|
|
#endif
|
2016-07-27 08:07:07 +00:00
|
|
|
if (xp.parse_int("batch_id", batch_id)) continue;
|
|
|
|
if (xp.match_tag("error")) {
|
2021-08-16 13:55:54 +00:00
|
|
|
RS_ERROR error;
|
2016-07-27 08:07:07 +00:00
|
|
|
error.parse(xp);
|
|
|
|
if (error.error_num) {
|
|
|
|
retval = error.error_num;
|
|
|
|
error_msg = error.error_msg;
|
|
|
|
}
|
|
|
|
}
|
2013-01-25 08:35:00 +00:00
|
|
|
}
|
|
|
|
fclose(reply);
|
2016-07-27 08:07:07 +00:00
|
|
|
return retval;
|
2013-01-25 08:35:00 +00:00
|
|
|
}
|
|
|
|
|
2013-10-22 06:40:30 +00:00
|
|
|
int estimate_batch(
|
|
|
|
const char* project_url,
|
|
|
|
const char* authenticator,
|
|
|
|
char app_name[256],
|
|
|
|
vector<JOB> jobs,
|
|
|
|
double& est_makespan,
|
|
|
|
string& error_msg
|
|
|
|
) {
|
|
|
|
char buf[1024], url[1024];
|
2022-08-03 09:21:59 +00:00
|
|
|
snprintf(buf, sizeof(buf),
|
2013-10-22 06:40:30 +00:00
|
|
|
"<estimate_batch>\n"
|
|
|
|
"<authenticator>%s</authenticator>\n"
|
|
|
|
"<batch>\n"
|
|
|
|
" <app_name>%s</app_name>\n",
|
|
|
|
authenticator,
|
|
|
|
app_name
|
|
|
|
);
|
|
|
|
string request = buf;
|
|
|
|
for (unsigned int i=0; i<jobs.size(); i++) {
|
|
|
|
JOB job = jobs[i];
|
|
|
|
request += "<job>\n";
|
|
|
|
if (!job.cmdline_args.empty()) {
|
|
|
|
request += "<command_line>" + job.cmdline_args + "</command_line>\n";
|
|
|
|
}
|
|
|
|
request += "</job>\n";
|
|
|
|
}
|
|
|
|
request += "</batch>\n</estimate_batch>\n";
|
2022-08-03 09:21:59 +00:00
|
|
|
snprintf(url, sizeof(url), "%ssubmit_rpc_handler.php", project_url);
|
2013-10-22 06:40:30 +00:00
|
|
|
FILE* reply = tmpfile();
|
|
|
|
vector<string> x;
|
|
|
|
int retval = do_http_post(url, request.c_str(), reply, x);
|
|
|
|
if (retval) {
|
|
|
|
fclose(reply);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
fseek(reply, 0, SEEK_SET);
|
|
|
|
retval = -1;
|
2016-07-27 08:07:07 +00:00
|
|
|
MIOFILE mf;
|
|
|
|
mf.init_file(reply);
|
|
|
|
XML_PARSER xp(&mf);
|
|
|
|
while (!xp.get_tag()) {
|
2013-10-22 06:40:30 +00:00
|
|
|
#ifdef SHOW_REPLY
|
2016-07-27 08:07:07 +00:00
|
|
|
printf("estimate_batch reply: %s\n", xp.parsed_tag);
|
2013-10-22 06:40:30 +00:00
|
|
|
#endif
|
2016-07-27 08:07:07 +00:00
|
|
|
if (xp.parse_double("seconds", est_makespan)) {
|
2013-10-22 06:40:30 +00:00
|
|
|
retval = 0;
|
|
|
|
continue;
|
|
|
|
}
|
2016-07-27 08:07:07 +00:00
|
|
|
if (xp.match_tag("error")) {
|
2021-08-16 13:55:54 +00:00
|
|
|
RS_ERROR error;
|
2016-07-27 08:07:07 +00:00
|
|
|
error.parse(xp);
|
|
|
|
if (error.error_num) {
|
|
|
|
retval = error.error_num;
|
|
|
|
error_msg = error.error_msg;
|
|
|
|
}
|
|
|
|
}
|
2013-10-22 06:40:30 +00:00
|
|
|
}
|
|
|
|
fclose(reply);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2013-01-25 08:35:00 +00:00
|
|
|
int submit_jobs(
|
|
|
|
const char* project_url,
|
|
|
|
const char* authenticator,
|
2013-10-09 00:36:45 +00:00
|
|
|
char app_name[256],
|
|
|
|
int batch_id,
|
|
|
|
vector<JOB> jobs,
|
2017-08-18 06:55:15 +00:00
|
|
|
string& error_msg,
|
|
|
|
int app_version_num
|
2018-03-19 06:25:26 +00:00
|
|
|
) {
|
|
|
|
JOB_PARAMS jp;
|
|
|
|
return submit_jobs_params(
|
|
|
|
project_url,
|
|
|
|
authenticator,
|
|
|
|
app_name,
|
|
|
|
batch_id,
|
|
|
|
jobs,
|
|
|
|
error_msg,
|
|
|
|
jp,
|
|
|
|
app_version_num
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
int submit_jobs_params(
|
|
|
|
const char* project_url,
|
|
|
|
const char* authenticator,
|
|
|
|
char app_name[256],
|
|
|
|
int batch_id,
|
|
|
|
vector<JOB> jobs,
|
|
|
|
string& error_msg,
|
|
|
|
JOB_PARAMS &job_params,
|
|
|
|
int app_version_num
|
2013-01-25 08:35:00 +00:00
|
|
|
) {
|
|
|
|
char buf[1024], url[1024];
|
2022-08-03 09:21:59 +00:00
|
|
|
snprintf(buf, sizeof(buf),
|
2013-01-30 05:17:47 +00:00
|
|
|
"<submit_batch>\n"
|
2013-01-25 08:35:00 +00:00
|
|
|
"<authenticator>%s</authenticator>\n"
|
2013-01-30 05:17:47 +00:00
|
|
|
"<batch>\n"
|
|
|
|
" <batch_id>%d</batch_id>\n"
|
2017-08-18 06:55:15 +00:00
|
|
|
" <app_name>%s</app_name>\n"
|
2018-03-19 06:25:26 +00:00
|
|
|
" <app_version_num>%d</app_version_num>\n"
|
|
|
|
" <job_params>\n"
|
|
|
|
" <rsc_disk_bound>%f</rsc_disk_bound>\n"
|
|
|
|
" <rsc_fpops_est>%f</rsc_fpops_est>\n"
|
|
|
|
" <rsc_fpops_bound>%f</rsc_fpops_bound>\n"
|
|
|
|
" <rsc_memory_bound>%f</rsc_memory_bound>\n"
|
|
|
|
" <delay_bound>%f</delay_bound>\n"
|
|
|
|
" </job_params>\n",
|
2013-01-25 08:35:00 +00:00
|
|
|
authenticator,
|
2013-10-09 00:36:45 +00:00
|
|
|
batch_id,
|
2017-08-18 06:55:15 +00:00
|
|
|
app_name,
|
2018-03-19 06:25:26 +00:00
|
|
|
app_version_num,
|
|
|
|
job_params.rsc_disk_bound,
|
|
|
|
job_params.rsc_fpops_est,
|
|
|
|
job_params.rsc_fpops_bound,
|
|
|
|
job_params.rsc_memory_bound,
|
|
|
|
job_params.delay_bound
|
2013-01-25 08:35:00 +00:00
|
|
|
);
|
|
|
|
string request = buf;
|
2013-10-09 00:36:45 +00:00
|
|
|
for (unsigned int i=0; i<jobs.size(); i++) {
|
|
|
|
JOB job = jobs[i];
|
2013-01-25 08:35:00 +00:00
|
|
|
request += "<job>\n";
|
2022-08-03 09:21:59 +00:00
|
|
|
snprintf(buf, sizeof(buf), " <name>%s</name>\n", job.job_name);
|
2013-05-29 06:14:17 +00:00
|
|
|
request += buf;
|
2013-01-25 08:35:00 +00:00
|
|
|
if (!job.cmdline_args.empty()) {
|
|
|
|
request += "<command_line>" + job.cmdline_args + "</command_line>\n";
|
|
|
|
}
|
|
|
|
for (unsigned int j=0; j<job.infiles.size(); j++) {
|
2013-01-30 05:17:47 +00:00
|
|
|
INFILE infile = job.infiles[j];
|
2016-07-22 20:51:04 +00:00
|
|
|
switch (infile.mode) {
|
|
|
|
case FILE_MODE_LOCAL_STAGED:
|
2022-08-03 09:21:59 +00:00
|
|
|
snprintf(buf, sizeof(buf),
|
2016-07-22 20:51:04 +00:00
|
|
|
"<input_file>\n"
|
|
|
|
"<mode>local_staged</mode>\n"
|
|
|
|
"<source>%s</source>\n"
|
|
|
|
"</input_file>\n",
|
|
|
|
infile.physical_name
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
case FILE_MODE_REMOTE:
|
2022-08-03 09:21:59 +00:00
|
|
|
snprintf(buf, sizeof(buf),
|
2016-07-22 20:51:04 +00:00
|
|
|
"<input_file>\n"
|
|
|
|
"<mode>remote</mode>\n"
|
|
|
|
"<url>%s</url>\n"
|
|
|
|
"<nbytes>%f</nbytes>\n"
|
|
|
|
"<md5>%s</md5>\n"
|
|
|
|
"</input_file>\n",
|
|
|
|
infile.url,
|
|
|
|
infile.nbytes,
|
|
|
|
infile.md5
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
fprintf(stderr, "unsupported file mode %d\n", infile.mode);
|
|
|
|
exit(1);
|
|
|
|
}
|
2013-01-25 08:35:00 +00:00
|
|
|
request += buf;
|
|
|
|
}
|
|
|
|
request += "</job>\n";
|
|
|
|
}
|
2013-01-30 05:17:47 +00:00
|
|
|
request += "</batch>\n</submit_batch>\n";
|
2022-08-03 09:21:59 +00:00
|
|
|
snprintf(url, sizeof(url), "%ssubmit_rpc_handler.php", project_url);
|
2013-01-25 08:35:00 +00:00
|
|
|
FILE* reply = tmpfile();
|
|
|
|
vector<string> x;
|
|
|
|
int retval = do_http_post(url, request.c_str(), reply, x);
|
|
|
|
if (retval) {
|
|
|
|
fclose(reply);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
fseek(reply, 0, SEEK_SET);
|
2013-03-06 23:00:15 +00:00
|
|
|
retval = -1;
|
|
|
|
int temp;
|
2016-07-27 08:07:07 +00:00
|
|
|
MIOFILE mf;
|
|
|
|
mf.init_file(reply);
|
|
|
|
XML_PARSER xp(&mf);
|
|
|
|
while (!xp.get_tag()) {
|
2013-05-29 06:14:17 +00:00
|
|
|
#ifdef SHOW_REPLY
|
2016-07-27 08:07:07 +00:00
|
|
|
printf("submit_batch reply: %s\n", xp.parsed_tag);
|
2013-05-29 06:14:17 +00:00
|
|
|
#endif
|
2016-07-27 08:07:07 +00:00
|
|
|
if (xp.parse_int("batch_id", temp)) {
|
2013-03-06 23:00:15 +00:00
|
|
|
retval = 0;
|
|
|
|
continue;
|
2013-01-30 05:17:47 +00:00
|
|
|
}
|
2016-07-27 08:07:07 +00:00
|
|
|
if (xp.match_tag("error")) {
|
2021-08-16 13:55:54 +00:00
|
|
|
RS_ERROR error;
|
2016-07-27 08:07:07 +00:00
|
|
|
error.parse(xp);
|
|
|
|
if (error.error_num) {
|
|
|
|
retval = error.error_num;
|
|
|
|
error_msg = error.error_msg;
|
|
|
|
}
|
|
|
|
}
|
2013-01-25 08:35:00 +00:00
|
|
|
}
|
|
|
|
fclose(reply);
|
2013-01-30 05:17:47 +00:00
|
|
|
return retval;
|
2013-01-02 20:31:14 +00:00
|
|
|
}
|
2013-01-31 22:06:17 +00:00
|
|
|
|
2013-10-22 22:27:34 +00:00
|
|
|
int query_batch_set(
|
2013-01-31 22:06:17 +00:00
|
|
|
const char* project_url,
|
|
|
|
const char* authenticator,
|
2014-01-16 18:24:10 +00:00
|
|
|
double min_mod_time,
|
2013-03-13 18:22:27 +00:00
|
|
|
vector<string> &batch_names,
|
2013-10-22 22:27:34 +00:00
|
|
|
QUERY_BATCH_SET_REPLY& qb_reply,
|
2013-03-06 23:00:15 +00:00
|
|
|
string& error_msg
|
2013-01-31 22:06:17 +00:00
|
|
|
) {
|
|
|
|
string request;
|
|
|
|
char url[1024], buf[256];
|
2013-05-31 06:38:33 +00:00
|
|
|
int batch_size;
|
|
|
|
|
2013-02-19 20:16:21 +00:00
|
|
|
request = "<query_batch2>\n";
|
2022-08-03 09:21:59 +00:00
|
|
|
snprintf(buf, sizeof(buf), "<authenticator>%s</authenticator>\n", authenticator);
|
2013-01-31 22:06:17 +00:00
|
|
|
request += string(buf);
|
2022-08-03 09:21:59 +00:00
|
|
|
snprintf(buf, sizeof(buf), "<min_mod_time>%f</min_mod_time>\n", min_mod_time);
|
2014-01-16 18:24:10 +00:00
|
|
|
request += string(buf);
|
2013-03-13 18:22:27 +00:00
|
|
|
for (unsigned int i=0; i<batch_names.size(); i++) {
|
2022-08-03 09:21:59 +00:00
|
|
|
snprintf(buf, sizeof(buf), "<batch_name>%s</batch_name>\n", batch_names[i].c_str());
|
2013-03-13 18:22:27 +00:00
|
|
|
request += string(buf);
|
|
|
|
}
|
2013-02-19 20:16:21 +00:00
|
|
|
request += "</query_batch2>\n";
|
2022-08-03 09:21:59 +00:00
|
|
|
snprintf(url, sizeof(url), "%ssubmit_rpc_handler.php", project_url);
|
2013-01-31 22:06:17 +00:00
|
|
|
FILE* reply = tmpfile();
|
|
|
|
vector<string> x;
|
|
|
|
int retval = do_http_post(url, request.c_str(), reply, x);
|
|
|
|
if (retval) {
|
|
|
|
fclose(reply);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
fseek(reply, 0, SEEK_SET);
|
2013-03-06 23:00:15 +00:00
|
|
|
retval = -1;
|
2014-01-16 18:24:10 +00:00
|
|
|
qb_reply.server_time = 0;
|
2016-07-27 08:07:07 +00:00
|
|
|
MIOFILE mf;
|
|
|
|
mf.init_file(reply);
|
|
|
|
XML_PARSER xp(&mf);
|
|
|
|
while (!xp.get_tag()) {
|
2013-05-29 06:14:17 +00:00
|
|
|
#ifdef SHOW_REPLY
|
|
|
|
printf("query_batches reply: %s", buf);
|
|
|
|
#endif
|
2016-08-01 06:00:24 +00:00
|
|
|
if (xp.match_tag("query_batch2")) {
|
2013-03-06 23:00:15 +00:00
|
|
|
retval = 0;
|
|
|
|
continue;
|
2013-01-31 22:06:17 +00:00
|
|
|
}
|
2016-07-27 08:07:07 +00:00
|
|
|
if (xp.parse_double("server_time", qb_reply.server_time)) continue;
|
|
|
|
if (xp.parse_int("batch_size", batch_size)) {
|
2013-05-31 06:38:33 +00:00
|
|
|
qb_reply.batch_sizes.push_back(batch_size);
|
|
|
|
continue;
|
|
|
|
}
|
2016-07-27 08:07:07 +00:00
|
|
|
if (xp.match_tag("job")) {
|
2013-10-22 22:27:34 +00:00
|
|
|
JOB_STATUS js;
|
2016-07-27 08:07:07 +00:00
|
|
|
while (!xp.get_tag()) {
|
2013-05-29 06:14:17 +00:00
|
|
|
#ifdef SHOW_REPLY
|
|
|
|
printf("query_batches reply: %s", buf);
|
|
|
|
#endif
|
2016-07-27 08:07:07 +00:00
|
|
|
if (xp.match_tag("/job")) {
|
2013-10-22 22:27:34 +00:00
|
|
|
qb_reply.jobs.push_back(js);
|
2013-05-31 06:38:33 +00:00
|
|
|
break;
|
2013-01-31 22:06:17 +00:00
|
|
|
}
|
2016-07-27 08:07:07 +00:00
|
|
|
if (xp.parse_string("job_name", js.job_name)) continue;
|
|
|
|
if (xp.parse_string("status", js.status)) continue;
|
2013-10-22 22:27:34 +00:00
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2016-07-27 08:07:07 +00:00
|
|
|
if (xp.match_tag("error")) {
|
2021-08-16 13:55:54 +00:00
|
|
|
RS_ERROR error;
|
2016-07-27 08:07:07 +00:00
|
|
|
error.parse(xp);
|
|
|
|
if (error.error_num) {
|
|
|
|
retval = error.error_num;
|
|
|
|
error_msg = error.error_msg;
|
|
|
|
}
|
|
|
|
}
|
2013-10-22 22:27:34 +00:00
|
|
|
}
|
|
|
|
fclose(reply);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
int BATCH_STATUS::parse(XML_PARSER& xp) {
|
2019-11-05 08:16:02 +00:00
|
|
|
static const BATCH_STATUS x;
|
|
|
|
*this = x;
|
2013-10-22 22:27:34 +00:00
|
|
|
while (!xp.get_tag()) {
|
|
|
|
if (xp.match_tag("/batch")) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (xp.parse_int("id", id)) continue;
|
|
|
|
if (xp.parse_str("name", name, sizeof(name))) continue;
|
|
|
|
if (xp.parse_int("state", state)) continue;
|
|
|
|
if (xp.parse_int("njobs", njobs)) continue;
|
|
|
|
if (xp.parse_int("nerror_jobs", nerror_jobs)) continue;
|
|
|
|
if (xp.parse_double("fraction_done", fraction_done)) continue;
|
|
|
|
if (xp.parse_double("create_time", create_time)) continue;
|
|
|
|
if (xp.parse_double("expire_time", expire_time)) continue;
|
|
|
|
if (xp.parse_double("est_completion_time", est_completion_time)) continue;
|
|
|
|
if (xp.parse_double("completion_time", completion_time)) continue;
|
|
|
|
if (xp.parse_double("credit_estimate", credit_estimate)) continue;
|
|
|
|
if (xp.parse_double("credit_canonical", credit_canonical)) continue;
|
|
|
|
}
|
|
|
|
return ERR_XML_PARSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BATCH_STATUS::print() {
|
|
|
|
printf("Batch %d (%s)\n"
|
|
|
|
" state: %s\n"
|
|
|
|
" njobs: %d\n"
|
|
|
|
" nerror_jobs: %d\n"
|
|
|
|
" fraction_done: %f\n",
|
|
|
|
id, name,
|
|
|
|
batch_state_string(state),
|
|
|
|
njobs,
|
|
|
|
nerror_jobs,
|
|
|
|
fraction_done
|
|
|
|
);
|
|
|
|
printf(
|
|
|
|
" create_time: %s\n",
|
|
|
|
time_to_string(create_time)
|
|
|
|
);
|
|
|
|
printf(
|
|
|
|
" expire_time: %s\n",
|
|
|
|
time_to_string(expire_time)
|
|
|
|
);
|
|
|
|
printf(
|
|
|
|
" est_completion_time: %s\n",
|
|
|
|
time_to_string(est_completion_time)
|
|
|
|
);
|
|
|
|
printf(
|
|
|
|
" completion_time: %s\n",
|
|
|
|
time_to_string(completion_time)
|
|
|
|
);
|
|
|
|
printf(
|
|
|
|
" credit_estimate: %f\n"
|
|
|
|
" credit_canonical: %f\n",
|
|
|
|
credit_estimate,
|
|
|
|
credit_canonical
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
int query_batches(
|
|
|
|
const char* project_url,
|
|
|
|
const char* authenticator,
|
|
|
|
vector<BATCH_STATUS>& batches,
|
|
|
|
string &error_msg
|
|
|
|
) {
|
|
|
|
string request;
|
|
|
|
char url[1024], buf[256];
|
|
|
|
request = "<query_batches>\n";
|
2022-08-03 09:21:59 +00:00
|
|
|
snprintf(buf, sizeof(buf), "<authenticator>%s</authenticator>\n", authenticator);
|
2013-10-22 22:27:34 +00:00
|
|
|
request += string(buf);
|
|
|
|
request += "</query_batches>\n";
|
2022-08-03 09:21:59 +00:00
|
|
|
snprintf(url, sizeof(url), "%ssubmit_rpc_handler.php", project_url);
|
2013-10-22 22:27:34 +00:00
|
|
|
FILE* reply = tmpfile();
|
|
|
|
vector<string> x;
|
|
|
|
int retval = do_http_post(url, request.c_str(), reply, x);
|
|
|
|
if (retval) {
|
|
|
|
fclose(reply);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
fseek(reply, 0, SEEK_SET);
|
|
|
|
retval = -1;
|
|
|
|
error_msg = "failed to parse Web RPC reply";
|
|
|
|
MIOFILE mf;
|
|
|
|
XML_PARSER xp(&mf);
|
|
|
|
mf.init_file(reply);
|
|
|
|
while (!xp.get_tag()) {
|
2016-08-01 06:00:24 +00:00
|
|
|
if (xp.match_tag("/query_batches")) {
|
2013-10-22 22:27:34 +00:00
|
|
|
retval = 0;
|
|
|
|
error_msg = "";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (xp.match_tag("batch")) {
|
|
|
|
BATCH_STATUS bs;
|
|
|
|
if (!bs.parse(xp)) {
|
|
|
|
batches.push_back(bs);
|
2013-01-31 22:06:17 +00:00
|
|
|
}
|
2013-03-06 23:00:15 +00:00
|
|
|
continue;
|
2013-01-31 22:06:17 +00:00
|
|
|
}
|
2016-07-27 08:07:07 +00:00
|
|
|
if (xp.match_tag("error")) {
|
2021-08-16 13:55:54 +00:00
|
|
|
RS_ERROR error;
|
2016-07-27 08:07:07 +00:00
|
|
|
error.parse(xp);
|
|
|
|
if (error.error_num) {
|
|
|
|
retval = error.error_num;
|
|
|
|
error_msg = error.error_msg;
|
|
|
|
}
|
|
|
|
}
|
2013-10-22 22:27:34 +00:00
|
|
|
}
|
|
|
|
fclose(reply);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
int JOB_STATE::parse(XML_PARSER& xp) {
|
2019-11-05 08:16:02 +00:00
|
|
|
static const JOB_STATE x;
|
|
|
|
*this = x;
|
2013-10-22 22:27:34 +00:00
|
|
|
while (!xp.get_tag()) {
|
|
|
|
if (xp.match_tag("/job")) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (xp.parse_int("id", id)) continue;
|
|
|
|
if (xp.parse_str("name", name, sizeof(name))) continue;
|
|
|
|
if (xp.parse_int("canonical_instance_id", canonical_instance_id)) continue;
|
|
|
|
if (xp.parse_int("n_outfiles", n_outfiles)) continue;
|
|
|
|
}
|
|
|
|
return ERR_XML_PARSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void JOB_STATE::print() {
|
|
|
|
printf(
|
|
|
|
"job %d (%s)\n"
|
|
|
|
" canonical_instance_id %d\n"
|
|
|
|
" n_outfiles %d\n",
|
|
|
|
id, name,
|
|
|
|
canonical_instance_id,
|
|
|
|
n_outfiles
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
int query_batch(
|
|
|
|
const char* project_url,
|
|
|
|
const char* authenticator,
|
|
|
|
int batch_id,
|
|
|
|
const char* batch_name,
|
|
|
|
vector<JOB_STATE>& jobs,
|
|
|
|
string &error_msg
|
|
|
|
) {
|
|
|
|
string request;
|
|
|
|
char url[1024], buf[256];
|
|
|
|
request = "<query_batch>\n";
|
2022-08-03 09:21:59 +00:00
|
|
|
snprintf(buf, sizeof(buf), "<authenticator>%s</authenticator>\n", authenticator);
|
2013-10-22 22:27:34 +00:00
|
|
|
request += string(buf);
|
|
|
|
if (batch_id) {
|
2022-08-03 09:21:59 +00:00
|
|
|
snprintf(buf, sizeof(buf), "<batch_id>%d</batch_id>\n", batch_id);
|
2013-10-22 22:27:34 +00:00
|
|
|
} else {
|
2022-08-03 09:21:59 +00:00
|
|
|
snprintf(buf, sizeof(buf), "<batch_name>%s</batch_name>\n", batch_name);
|
2013-10-22 22:27:34 +00:00
|
|
|
}
|
|
|
|
request += string(buf);
|
|
|
|
request += "</query_batch>\n";
|
2022-08-03 09:21:59 +00:00
|
|
|
snprintf(url, sizeof(url), "%ssubmit_rpc_handler.php", project_url);
|
2013-10-22 22:27:34 +00:00
|
|
|
FILE* reply = tmpfile();
|
|
|
|
vector<string> x;
|
|
|
|
int retval = do_http_post(url, request.c_str(), reply, x);
|
|
|
|
if (retval) {
|
|
|
|
fclose(reply);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
fseek(reply, 0, SEEK_SET);
|
|
|
|
retval = -1;
|
|
|
|
error_msg = "";
|
|
|
|
MIOFILE mf;
|
|
|
|
XML_PARSER xp(&mf);
|
|
|
|
mf.init_file(reply);
|
|
|
|
while (!xp.get_tag()) {
|
|
|
|
if (xp.match_tag("/jobs")) {
|
|
|
|
retval = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (xp.match_tag("job")) {
|
|
|
|
JOB_STATE js;
|
|
|
|
if (!js.parse(xp)) {
|
|
|
|
jobs.push_back(js);
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-01-31 22:06:17 +00:00
|
|
|
}
|
|
|
|
fclose(reply);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2013-02-21 00:20:00 +00:00
|
|
|
int abort_jobs(
|
|
|
|
const char* project_url,
|
|
|
|
const char* authenticator,
|
2013-03-06 23:00:15 +00:00
|
|
|
vector<string> &job_names,
|
|
|
|
string &error_msg
|
2013-02-21 00:20:00 +00:00
|
|
|
) {
|
|
|
|
string request;
|
|
|
|
char url[1024], buf[256];
|
|
|
|
request = "<abort_jobs>\n";
|
2022-08-03 09:21:59 +00:00
|
|
|
snprintf(buf, sizeof(buf), "<authenticator>%s</authenticator>\n", authenticator);
|
2013-02-21 00:20:00 +00:00
|
|
|
request += string(buf);
|
|
|
|
for (unsigned int i=0; i<job_names.size(); i++) {
|
2022-08-03 09:21:59 +00:00
|
|
|
snprintf(buf, sizeof(buf), "<job_name>%s</job_name>\n", job_names[i].c_str());
|
2013-02-21 00:20:00 +00:00
|
|
|
request += string(buf);
|
|
|
|
}
|
|
|
|
request += "</abort_jobs>\n";
|
2022-08-03 09:21:59 +00:00
|
|
|
snprintf(url, sizeof(url), "%ssubmit_rpc_handler.php", project_url);
|
2013-02-21 00:20:00 +00:00
|
|
|
FILE* reply = tmpfile();
|
|
|
|
vector<string> x;
|
|
|
|
int retval = do_http_post(url, request.c_str(), reply, x);
|
|
|
|
if (retval) {
|
|
|
|
fclose(reply);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
fseek(reply, 0, SEEK_SET);
|
2013-03-06 23:00:15 +00:00
|
|
|
retval = -1;
|
2016-07-27 08:07:07 +00:00
|
|
|
bool success;
|
|
|
|
MIOFILE mf;
|
|
|
|
XML_PARSER xp(&mf);
|
|
|
|
mf.init_file(reply);
|
|
|
|
while (!xp.get_tag()) {
|
2013-05-29 06:14:17 +00:00
|
|
|
#ifdef SHOW_REPLY
|
2016-07-27 08:07:07 +00:00
|
|
|
printf("abort_jobs reply: %s\n", xp.parsed_tag);
|
2013-05-29 06:14:17 +00:00
|
|
|
#endif
|
2016-07-27 08:07:07 +00:00
|
|
|
if (xp.parse_bool("success", success)) {
|
2013-03-06 23:00:15 +00:00
|
|
|
retval = 0;
|
|
|
|
continue;
|
2013-02-21 00:20:00 +00:00
|
|
|
}
|
2016-07-27 08:07:07 +00:00
|
|
|
if (xp.match_tag("error")) {
|
2021-08-16 13:55:54 +00:00
|
|
|
RS_ERROR error;
|
2016-07-27 08:07:07 +00:00
|
|
|
error.parse(xp);
|
|
|
|
if (error.error_num) {
|
|
|
|
retval = error.error_num;
|
|
|
|
error_msg = error.error_msg;
|
|
|
|
}
|
|
|
|
}
|
2013-02-21 00:20:00 +00:00
|
|
|
}
|
|
|
|
fclose(reply);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2013-03-06 04:30:12 +00:00
|
|
|
int get_templates(
|
|
|
|
const char* project_url,
|
|
|
|
const char* authenticator,
|
|
|
|
const char* app_name,
|
2013-03-23 05:04:35 +00:00
|
|
|
const char* job_name,
|
2013-03-06 23:00:15 +00:00
|
|
|
TEMPLATE_DESC &td,
|
|
|
|
string &error_msg
|
2013-03-06 04:30:12 +00:00
|
|
|
) {
|
|
|
|
string request;
|
|
|
|
char url[1024], buf[256];
|
|
|
|
request = "<get_templates>\n";
|
2022-08-03 09:21:59 +00:00
|
|
|
snprintf(buf, sizeof(buf), "<authenticator>%s</authenticator>\n", authenticator);
|
2013-03-06 04:30:12 +00:00
|
|
|
request += string(buf);
|
2013-03-23 05:04:35 +00:00
|
|
|
if (app_name) {
|
2022-08-03 09:21:59 +00:00
|
|
|
snprintf(buf, sizeof(buf), "<app_name>%s</app_name>\n", app_name);
|
2013-03-23 05:04:35 +00:00
|
|
|
request += string(buf);
|
|
|
|
} else {
|
2022-08-03 09:21:59 +00:00
|
|
|
snprintf(buf, sizeof(buf), "<job_name>%s</job_name>\n", job_name);
|
2013-03-23 05:04:35 +00:00
|
|
|
request += string(buf);
|
|
|
|
}
|
2013-03-06 23:00:15 +00:00
|
|
|
request += "</get_templates>\n";
|
2022-08-03 09:21:59 +00:00
|
|
|
snprintf(url, sizeof(url), "%ssubmit_rpc_handler.php", project_url);
|
2013-03-06 04:30:12 +00:00
|
|
|
FILE* reply = tmpfile();
|
|
|
|
vector<string> x;
|
|
|
|
int retval = do_http_post(url, request.c_str(), reply, x);
|
|
|
|
if (retval) {
|
|
|
|
fclose(reply);
|
|
|
|
return retval;
|
|
|
|
}
|
2013-03-06 23:00:15 +00:00
|
|
|
retval = -1;
|
2013-03-06 04:30:12 +00:00
|
|
|
fseek(reply, 0, SEEK_SET);
|
2016-07-27 08:07:07 +00:00
|
|
|
MIOFILE mf;
|
|
|
|
XML_PARSER xp(&mf);
|
|
|
|
mf.init_file(reply);
|
|
|
|
while (!xp.get_tag()) {
|
2013-05-29 06:14:17 +00:00
|
|
|
#ifdef SHOW_REPLY
|
2016-07-27 08:07:07 +00:00
|
|
|
printf("get_templates reply: %s\n", xp.parsed_tag);
|
2013-05-29 06:14:17 +00:00
|
|
|
#endif
|
2016-07-27 08:07:07 +00:00
|
|
|
if (xp.match_tag("templates")) {
|
2013-03-06 23:00:15 +00:00
|
|
|
retval = td.parse(xp);
|
|
|
|
}
|
2016-07-27 08:07:07 +00:00
|
|
|
if (xp.match_tag("error")) {
|
2021-08-16 13:55:54 +00:00
|
|
|
RS_ERROR error;
|
2016-07-27 08:07:07 +00:00
|
|
|
error.parse(xp);
|
|
|
|
if (error.error_num) {
|
|
|
|
retval = error.error_num;
|
|
|
|
error_msg = error.error_msg;
|
|
|
|
}
|
|
|
|
}
|
2013-03-06 23:00:15 +00:00
|
|
|
}
|
2013-03-13 18:22:27 +00:00
|
|
|
fclose(reply);
|
2013-03-06 23:00:15 +00:00
|
|
|
return retval;
|
2013-03-06 04:30:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int TEMPLATE_DESC::parse(XML_PARSER& xp) {
|
|
|
|
string s;
|
|
|
|
while (!xp.get_tag()) {
|
|
|
|
if (xp.match_tag("input_template")) {
|
|
|
|
while (!xp.get_tag()) {
|
|
|
|
if (xp.match_tag("/input_template")) break;
|
|
|
|
if (xp.parse_string("open_name", s)) {
|
|
|
|
input_files.push_back(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (xp.match_tag("output_template")) {
|
|
|
|
while (!xp.get_tag()) {
|
|
|
|
if (xp.match_tag("/output_template")) break;
|
|
|
|
if (xp.parse_string("open_name", s)) {
|
|
|
|
output_files.push_back(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-03-08 07:21:18 +00:00
|
|
|
int COMPLETED_JOB_DESC::parse(XML_PARSER& xp) {
|
|
|
|
canonical_resultid = 0;
|
|
|
|
error_mask = 0;
|
|
|
|
error_resultid = 0;
|
|
|
|
exit_status = 0;
|
|
|
|
elapsed_time = 0;
|
|
|
|
cpu_time = 0;
|
|
|
|
while (!xp.get_tag()) {
|
|
|
|
if (xp.match_tag("/completed_job")) return 0;
|
|
|
|
if (xp.parse_int("canonical_resultid", canonical_resultid)) continue;
|
|
|
|
if (xp.parse_int("error_mask", error_mask)) continue;
|
|
|
|
if (xp.parse_int("error_resultid", error_resultid)) continue;
|
|
|
|
if (xp.parse_int("exit_status", exit_status)) continue;
|
|
|
|
if (xp.parse_double("elapsed_time", elapsed_time)) continue;
|
|
|
|
if (xp.parse_double("cpu_time", cpu_time)) continue;
|
|
|
|
if (xp.parse_string("stderr_out", stderr_out)) {
|
|
|
|
xml_unescape(stderr_out);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ERR_XML_PARSE;
|
|
|
|
}
|
|
|
|
|
2013-01-31 22:06:17 +00:00
|
|
|
int get_output_file(
|
|
|
|
const char* project_url,
|
|
|
|
const char* authenticator,
|
|
|
|
const char* job_name,
|
|
|
|
int file_num,
|
2013-03-06 23:00:15 +00:00
|
|
|
const char* dst_path,
|
|
|
|
string &error_msg
|
2013-01-31 22:06:17 +00:00
|
|
|
) {
|
2013-08-27 03:52:25 +00:00
|
|
|
char url[1024], job_name_esc[1024];
|
|
|
|
escape_url(job_name, job_name_esc, sizeof(job_name_esc));
|
2022-08-03 09:21:59 +00:00
|
|
|
snprintf(url, sizeof(url), "%sget_output.php?cmd=workunit_file&auth_str=%s&wu_name=%s&file_num=%d",
|
2013-08-27 03:52:25 +00:00
|
|
|
project_url, authenticator, job_name_esc, file_num
|
2013-01-31 22:06:17 +00:00
|
|
|
);
|
2013-05-27 18:45:10 +00:00
|
|
|
//printf("fetching %s to %s\n", url, dst_path);
|
2013-03-06 23:00:15 +00:00
|
|
|
int retval = do_http_get(url, dst_path);
|
|
|
|
error_msg = "";
|
|
|
|
if (retval) {
|
|
|
|
char buf[1024];
|
2022-08-03 09:21:59 +00:00
|
|
|
snprintf(buf, sizeof(buf), "couldn't fetch %s: %d", url, retval);
|
2013-03-06 23:00:15 +00:00
|
|
|
error_msg = string(buf);
|
|
|
|
}
|
|
|
|
return retval;
|
2013-01-31 22:06:17 +00:00
|
|
|
}
|
2013-03-08 07:21:18 +00:00
|
|
|
|
|
|
|
int query_completed_job(
|
|
|
|
const char* project_url,
|
|
|
|
const char* authenticator,
|
|
|
|
const char* job_name,
|
|
|
|
COMPLETED_JOB_DESC& jd,
|
|
|
|
string &error_msg
|
|
|
|
) {
|
|
|
|
string request;
|
|
|
|
char url[1024], buf[256];
|
|
|
|
request = "<query_completed_job>\n";
|
2022-08-03 09:21:59 +00:00
|
|
|
snprintf(buf, sizeof(buf), "<authenticator>%s</authenticator>\n", authenticator);
|
2013-03-08 07:21:18 +00:00
|
|
|
request += string(buf);
|
2022-08-03 09:21:59 +00:00
|
|
|
snprintf(buf, sizeof(buf), "<job_name>%s</job_name>\n", job_name);
|
2013-03-08 07:21:18 +00:00
|
|
|
request += string(buf);
|
|
|
|
request += "</query_completed_job>\n";
|
2022-08-03 09:21:59 +00:00
|
|
|
snprintf(url, sizeof(url), "%ssubmit_rpc_handler.php", project_url);
|
2013-03-08 07:21:18 +00:00
|
|
|
FILE* reply = tmpfile();
|
|
|
|
vector<string> x;
|
|
|
|
int retval = do_http_post(url, request.c_str(), reply, x);
|
|
|
|
if (retval) {
|
|
|
|
fclose(reply);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
retval = -1;
|
|
|
|
fseek(reply, 0, SEEK_SET);
|
2016-07-27 08:07:07 +00:00
|
|
|
MIOFILE mf;
|
|
|
|
XML_PARSER xp(&mf);
|
|
|
|
mf.init_file(reply);
|
|
|
|
while (!xp.get_tag()) {
|
2013-05-29 06:14:17 +00:00
|
|
|
#ifdef SHOW_REPLY
|
2016-07-27 08:07:07 +00:00
|
|
|
printf("query_completed_job reply: %s\n", xp.parsed_tag);
|
2013-05-29 06:14:17 +00:00
|
|
|
#endif
|
2016-07-27 08:07:07 +00:00
|
|
|
if (xp.match_tag("completed_job")) {
|
2013-03-08 07:21:18 +00:00
|
|
|
retval = jd.parse(xp);
|
|
|
|
}
|
2016-07-27 08:07:07 +00:00
|
|
|
if (xp.match_tag("error")) {
|
2021-08-16 13:55:54 +00:00
|
|
|
RS_ERROR error;
|
2016-07-27 08:07:07 +00:00
|
|
|
error.parse(xp);
|
|
|
|
if (error.error_num) {
|
|
|
|
retval = error.error_num;
|
|
|
|
error_msg = error.error_msg;
|
|
|
|
}
|
|
|
|
}
|
2013-03-08 07:21:18 +00:00
|
|
|
}
|
2013-03-13 18:22:27 +00:00
|
|
|
fclose(reply);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2013-05-30 16:44:58 +00:00
|
|
|
int retire_batch(
|
|
|
|
const char* project_url,
|
|
|
|
const char* authenticator,
|
|
|
|
const char* batch_name,
|
|
|
|
string &error_msg
|
|
|
|
) {
|
|
|
|
string request;
|
|
|
|
char url[1024], buf[256];
|
|
|
|
request = "<retire_batch>\n";
|
2022-08-03 09:21:59 +00:00
|
|
|
snprintf(buf, sizeof(buf), "<authenticator>%s</authenticator>\n", authenticator);
|
2013-05-30 16:44:58 +00:00
|
|
|
request += string(buf);
|
2022-08-03 09:21:59 +00:00
|
|
|
snprintf(buf, sizeof(buf), "<batch_name>%s</batch_name>\n", batch_name);
|
2013-05-30 16:44:58 +00:00
|
|
|
request += string(buf);
|
|
|
|
request += "</retire_batch>\n";
|
2022-08-03 09:21:59 +00:00
|
|
|
snprintf(url, sizeof(url), "%ssubmit_rpc_handler.php", project_url);
|
2013-05-30 16:44:58 +00:00
|
|
|
FILE* reply = tmpfile();
|
|
|
|
vector<string> x;
|
|
|
|
int retval = do_http_post(url, request.c_str(), reply, x);
|
|
|
|
if (retval) {
|
|
|
|
fclose(reply);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
retval = -1;
|
2016-07-27 08:07:07 +00:00
|
|
|
bool success;
|
2013-05-30 16:44:58 +00:00
|
|
|
fseek(reply, 0, SEEK_SET);
|
2016-07-27 08:07:07 +00:00
|
|
|
MIOFILE mf;
|
|
|
|
XML_PARSER xp(&mf);
|
|
|
|
mf.init_file(reply);
|
|
|
|
while (!xp.get_tag()) {
|
2013-05-30 16:44:58 +00:00
|
|
|
#ifdef SHOW_REPLY
|
2016-07-27 08:07:07 +00:00
|
|
|
printf("retire_batch reply: %s\n", xp.parsed_tag);
|
2013-09-17 20:35:55 +00:00
|
|
|
#endif
|
2016-07-27 08:07:07 +00:00
|
|
|
if (xp.parse_bool("success", success)) {
|
2013-09-17 20:35:55 +00:00
|
|
|
retval = 0;
|
|
|
|
continue;
|
|
|
|
}
|
2016-07-27 08:07:07 +00:00
|
|
|
if (xp.match_tag("error")) {
|
2021-08-16 13:55:54 +00:00
|
|
|
RS_ERROR error;
|
2016-07-27 08:07:07 +00:00
|
|
|
error.parse(xp);
|
|
|
|
if (error.error_num) {
|
|
|
|
retval = error.error_num;
|
|
|
|
error_msg = error.error_msg;
|
|
|
|
}
|
|
|
|
}
|
2013-09-17 20:35:55 +00:00
|
|
|
}
|
|
|
|
fclose(reply);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
int set_expire_time(
|
|
|
|
const char* project_url,
|
|
|
|
const char* authenticator,
|
|
|
|
const char* batch_name,
|
|
|
|
double expire_time,
|
|
|
|
string &error_msg
|
|
|
|
) {
|
|
|
|
string request;
|
|
|
|
char url[1024], buf[256];
|
|
|
|
request = "<set_expire_time>\n";
|
2022-08-03 09:21:59 +00:00
|
|
|
snprintf(buf, sizeof(buf), "<authenticator>%s</authenticator>\n", authenticator);
|
2013-09-17 20:35:55 +00:00
|
|
|
request += string(buf);
|
2022-08-03 09:21:59 +00:00
|
|
|
snprintf(buf, sizeof(buf), "<batch_name>%s</batch_name>\n", batch_name);
|
2013-09-17 20:35:55 +00:00
|
|
|
request += string(buf);
|
2022-08-03 09:21:59 +00:00
|
|
|
snprintf(buf, sizeof(buf), "<expire_time>%f</expire_time>\n", expire_time);
|
2013-09-18 06:14:57 +00:00
|
|
|
request += string(buf);
|
2013-09-17 20:35:55 +00:00
|
|
|
request += "</set_expire_time>\n";
|
2022-08-03 09:21:59 +00:00
|
|
|
snprintf(url, sizeof(url), "%ssubmit_rpc_handler.php", project_url);
|
2013-09-17 20:35:55 +00:00
|
|
|
FILE* reply = tmpfile();
|
|
|
|
vector<string> x;
|
|
|
|
int retval = do_http_post(url, request.c_str(), reply, x);
|
|
|
|
if (retval) {
|
|
|
|
fclose(reply);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
retval = -1;
|
2016-07-27 08:07:07 +00:00
|
|
|
bool success;
|
2013-09-17 20:35:55 +00:00
|
|
|
error_msg = "";
|
|
|
|
fseek(reply, 0, SEEK_SET);
|
2016-07-27 08:07:07 +00:00
|
|
|
MIOFILE mf;
|
|
|
|
XML_PARSER xp(&mf);
|
|
|
|
mf.init_file(reply);
|
|
|
|
while (!xp.get_tag()) {
|
2013-09-17 20:35:55 +00:00
|
|
|
#ifdef SHOW_REPLY
|
2016-07-27 08:07:07 +00:00
|
|
|
printf("set_expire_time reply: %s\n", xp.parsed_tag);
|
2013-05-30 16:44:58 +00:00
|
|
|
#endif
|
2016-07-27 08:07:07 +00:00
|
|
|
if (xp.parse_bool("success", success)) {
|
2013-05-30 16:44:58 +00:00
|
|
|
retval = 0;
|
|
|
|
continue;
|
|
|
|
}
|
2016-07-27 08:07:07 +00:00
|
|
|
if (xp.match_tag("error")) {
|
2021-08-16 13:55:54 +00:00
|
|
|
RS_ERROR error;
|
2016-07-27 08:07:07 +00:00
|
|
|
error.parse(xp);
|
|
|
|
if (error.error_num) {
|
|
|
|
retval = error.error_num;
|
|
|
|
error_msg = error.error_msg;
|
|
|
|
}
|
|
|
|
}
|
2013-05-30 16:44:58 +00:00
|
|
|
}
|
|
|
|
fclose(reply);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2013-03-13 18:22:27 +00:00
|
|
|
int ping_server(
|
|
|
|
const char* project_url,
|
|
|
|
string &error_msg
|
|
|
|
) {
|
|
|
|
string request;
|
2016-08-01 06:00:24 +00:00
|
|
|
char url[1024];
|
2013-03-13 18:22:27 +00:00
|
|
|
request = "<ping> </ping>\n"; // the space is needed
|
2022-08-03 09:21:59 +00:00
|
|
|
snprintf(url, sizeof(url), "%ssubmit_rpc_handler.php", project_url);
|
2013-03-13 18:22:27 +00:00
|
|
|
FILE* reply = tmpfile();
|
|
|
|
vector<string> x;
|
|
|
|
int retval = do_http_post(url, request.c_str(), reply, x);
|
|
|
|
if (retval) {
|
|
|
|
fclose(reply);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
retval = -1;
|
2016-07-27 08:07:07 +00:00
|
|
|
bool success;
|
2013-03-13 18:22:27 +00:00
|
|
|
error_msg = "";
|
|
|
|
fseek(reply, 0, SEEK_SET);
|
2016-07-27 08:07:07 +00:00
|
|
|
MIOFILE mf;
|
|
|
|
XML_PARSER xp(&mf);
|
|
|
|
mf.init_file(reply);
|
|
|
|
while (!xp.get_tag()) {
|
2013-05-29 06:14:17 +00:00
|
|
|
#ifdef SHOW_REPLY
|
2016-07-27 08:07:07 +00:00
|
|
|
printf("ping_server() reply: %s\n", xp.parsed_tag);
|
2013-05-29 06:14:17 +00:00
|
|
|
#endif
|
2016-07-27 08:07:07 +00:00
|
|
|
if (xp.parse_bool("success", success)) {
|
2013-03-13 18:22:27 +00:00
|
|
|
retval = 0;
|
|
|
|
continue;
|
|
|
|
}
|
2016-07-27 08:07:07 +00:00
|
|
|
if (xp.match_tag("error")) {
|
2021-08-16 13:55:54 +00:00
|
|
|
RS_ERROR error;
|
2016-07-27 08:07:07 +00:00
|
|
|
error.parse(xp);
|
|
|
|
if (error.error_num) {
|
|
|
|
retval = error.error_num;
|
|
|
|
error_msg = error.error_msg;
|
|
|
|
}
|
|
|
|
}
|
2013-03-13 18:22:27 +00:00
|
|
|
}
|
|
|
|
fclose(reply);
|
2013-03-08 07:21:18 +00:00
|
|
|
return retval;
|
|
|
|
}
|