Skip to content

Commit

Permalink
New REST API method
Browse files Browse the repository at this point in the history
  • Loading branch information
henricasanova committed Sep 14, 2024
1 parent df1de1f commit 92b8ab1
Show file tree
Hide file tree
Showing 6 changed files with 238 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ class BareMetalOneSleepActionTestWMS : public wrench::ExecutionController {
try {
auto bogus_action = job->getActionByName("bogus");
throw std::runtime_error("Should not be able to lookup by name an action that doesn't exist");
} catch (std::invlud_argument &ignore) {}
} catch (std::invalid_argument &ignore) {}

job_manager->submitJob(job, this->test->compute_service, {});
job->getStateAsString();// coverage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ class ActionExecutionServiceOneActionSuccessTestWMS : public wrench::ExecutionCo
// Add a sleep action to it
auto action = job->addSleepAction("my_sleep", 10.0);

// Coverage
auto fc = action->getFailureCause();

// Submit the action to the action executor
action_execution_service->submitAction(action);

Expand Down
146 changes: 146 additions & 0 deletions tools/wrench/wrench-daemon/doc/wrench-openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -2943,6 +2943,76 @@
}
}
},
"/simulation/{simid}/compoundJobs/{compound_job_name}/addActionDependency": {
"post": {
"tags": [
"WRENCH"
],
"summary": "Add a dependency between two actions in a compound job.",
"deprecated": false,
"operationId": "addActionDependency",
"parameters": [
{
"name": "simid",
"in": "path",
"description": "ID of the simulation",
"required": true,
"schema": {
"type": "string"
}
},
{
"name": "compound_job_name",
"in": "path",
"description": "Name of the compound job",
"required": true,
"schema": {
"type": "string"
}
}
],
"requestBody": {
"description": "Input to create an action dependency.",
"required": true,
"content": {
"application/json": {
"schema": {
"properties": {
"parent_action_name": {
"type": "string",
"description": "Name of the parent action."
},
"child_action_name": {
"type": "File",
"description": "Name of the child action."
}
}
}
}
}
},
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/GenericResponse"
}
}
}
},
"404": {
"description": "Job not found",
"content": {}
},
"405": {
"description": "Invalid input",
"content": {}
}
}
}
},
"/simulation/{simid}/compoundJobs/{compound_job_name}/actions/{action_name}/getStartDate": {
"get": {
"tags": [
Expand Down Expand Up @@ -3061,6 +3131,65 @@
}
}
},
"/simulation/{simid}/compoundJobs/{compound_job_name}/actions/{action_name}/getFailureCause": {
"get": {
"tags": [
"WRENCH"
],
"summary": "Get an action's failure cause as a string (or the empty string if no failure).",
"deprecated": false,
"operationId": "getActionFailureCause",
"parameters": [
{
"name": "simid",
"in": "path",
"description": "ID of the simulation",
"required": true,
"schema": {
"type": "string"
}
},
{
"name": "compound_job_name",
"in": "path",
"description": "Name of the compound job",
"required": true,
"schema": {
"type": "string"
}
},
{
"name": "action_name",
"in": "path",
"description": "Name of the action",
"required": true,
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ActionFailureCauseResponse"
}
}
}
},
"404": {
"description": "Job not found",
"content": {}
},
"405": {
"description": "Invalid input",
"content": {}
}
}
}
},
"/simulation/{simid}/cloud_compute_services/{service_name}/createVM": {
"post": {
"tags": [
Expand Down Expand Up @@ -4333,6 +4462,23 @@
"description": "human-readable error message (if failure)"
}
}
},
"ActionFailureCauseResponse": {
"type": "object",
"properties": {
"action_failure_cause": {
"type": "string",
"description": "The action's failure cause (or the empty string if no failure)."
},
"wrench_api_request_success": {
"type": "boolean",
"description": "true if success, false if failure"
},
"failure_cause": {
"type": "string",
"description": "human-readable error message (if failure)"
}
}
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion tools/wrench/wrench-daemon/include/SimulationController.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,11 @@ namespace wrench {
json addFileWriteAction(json data);
json addFileReadAction(json data);
json addSleepAction(json data);
json addActionDependency(json data);
json addParentJob(json data);
json getActionStartDate(json data);
json getActionEndDate(json data);
json getActionFailureCause(json data);

json createTask(json data);
json getTaskFlops(json data);
Expand Down Expand Up @@ -101,7 +103,6 @@ namespace wrench {
json stageInputFiles(json data);
json workflowIsDone(json data);


json supportsCompoundJobs(json data);
json supportsPilotJobs(json data);
json supportsStandardJobs(json data);
Expand Down
34 changes: 18 additions & 16 deletions tools/wrench/wrench-daemon/include/callback-map.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,21 @@ request_handlers["addFileCopyAction_45"] = [sc](json data) { return sc->addFileC
request_handlers["addFileDeleteAction_46"] = [sc](json data) { return sc->addFileDeleteAction(std::move(data)); };
request_handlers["addFileReadAction_47"] = [sc](json data) { return sc->addFileReadAction(std::move(data)); };
request_handlers["addFileWriteAction_48"] = [sc](json data) { return sc->addFileWriteAction(std::move(data)); };
request_handlers["getStartDate_49"] = [sc](json data) { return sc->getActionStartDate(std::move(data)); };
request_handlers["getEndDate_50"] = [sc](json data) { return sc->getActionEndDate(std::move(data)); };
request_handlers["createVM_51"] = [sc](json data) { return sc->createVM(std::move(data)); };
request_handlers["startVM_52"] = [sc](json data) { return sc->startVM(std::move(data)); };
request_handlers["shutdownVM_53"] = [sc](json data) { return sc->shutdownVM(std::move(data)); };
request_handlers["destroyVM_54"] = [sc](json data) { return sc->destroyVM(std::move(data)); };
request_handlers["isVMRunning_55"] = [sc](json data) { return sc->isVMRunning(std::move(data)); };
request_handlers["isVMDown_56"] = [sc](json data) { return sc->isVMDown(std::move(data)); };
request_handlers["suspendVM_57"] = [sc](json data) { return sc->suspendVM(std::move(data)); };
request_handlers["resumeVM_58"] = [sc](json data) { return sc->resumeVM(std::move(data)); };
request_handlers["isVMSuspended_59"] = [sc](json data) { return sc->isVMSuspended(std::move(data)); };
request_handlers["getVMPhysicalHostname_60"] = [sc](json data) { return sc->getVMPhysicalHostname(std::move(data)); };
request_handlers["getVMComputeService_61"] = [sc](json data) { return sc->getVMComputeService(std::move(data)); };
request_handlers["getExecutionHosts_62"] = [sc](json data) { return sc->getExecutionHosts(std::move(data)); };
request_handlers["createWorkflowFromJSON_63"] = [sc](json data) { return sc->createWorkflowFromJSON(std::move(data)); };
request_handlers["createWorkflow_64"] = [sc](json data) { return sc->createWorkflow(std::move(data)); };
request_handlers["addActionDependency_49"] = [sc](json data) { return sc->addActionDependency(std::move(data)); };
request_handlers["getStartDate_50"] = [sc](json data) { return sc->getActionStartDate(std::move(data)); };
request_handlers["getEndDate_51"] = [sc](json data) { return sc->getActionEndDate(std::move(data)); };
request_handlers["getFailureCause_52"] = [sc](json data) { return sc->getActionFailureCause(std::move(data)); };
request_handlers["createVM_53"] = [sc](json data) { return sc->createVM(std::move(data)); };
request_handlers["startVM_54"] = [sc](json data) { return sc->startVM(std::move(data)); };
request_handlers["shutdownVM_55"] = [sc](json data) { return sc->shutdownVM(std::move(data)); };
request_handlers["destroyVM_56"] = [sc](json data) { return sc->destroyVM(std::move(data)); };
request_handlers["isVMRunning_57"] = [sc](json data) { return sc->isVMRunning(std::move(data)); };
request_handlers["isVMDown_58"] = [sc](json data) { return sc->isVMDown(std::move(data)); };
request_handlers["suspendVM_59"] = [sc](json data) { return sc->suspendVM(std::move(data)); };
request_handlers["resumeVM_60"] = [sc](json data) { return sc->resumeVM(std::move(data)); };
request_handlers["isVMSuspended_61"] = [sc](json data) { return sc->isVMSuspended(std::move(data)); };
request_handlers["getVMPhysicalHostname_62"] = [sc](json data) { return sc->getVMPhysicalHostname(std::move(data)); };
request_handlers["getVMComputeService_63"] = [sc](json data) { return sc->getVMComputeService(std::move(data)); };
request_handlers["getExecutionHosts_64"] = [sc](json data) { return sc->getExecutionHosts(std::move(data)); };
request_handlers["createWorkflowFromJSON_65"] = [sc](json data) { return sc->createWorkflowFromJSON(std::move(data)); };
request_handlers["createWorkflow_66"] = [sc](json data) { return sc->createWorkflow(std::move(data)); };
68 changes: 68 additions & 0 deletions tools/wrench/wrench-daemon/src/SimulationController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1205,6 +1205,45 @@ namespace wrench {
return answer;
}

/**
* @brief REST API Handler
* @param data JSON input
* @return JSON output
*/
json SimulationController::addActionDependency(json data) {
std::string compougnd_job_name = data["compound_job_name"];
std::string parent_action_name = data["parent_action_name"];
std::string child_action_name = data["child_action_name"];
std::shared_ptr<CompoundJob> job;
json answer;

if (not this->compound_job_registry.lookup(compound_job_name, job)) {
throw std::runtime_error("Unknown compound job " + compound_job_name);
}

std::shared_ptr<Action> parent_action;
try {
parent_action = job->getActionByName(parent_action_name);
} catch (std::invalid_argument &e) {
throw std::runtime_error("Unknown action " + parent_action_name + " in job " + compound_job_name);
}

std::shared_ptr<Action> child_action;
try {
child_action = job->getActionByName(child_action_name);
} catch (std::invalid_argument &e) {
throw std::runtime_error("Unknown action " + child_action_name + " in job " + compound_job_name);
}

try {
job->addActionDependency(parent_action, child_action);
} catch (std::invalid_argument &e) {
throw std::runtime_error("Cannot add action dependency: " + std::string(e.what()));
}

return {};
}

/**
* @brief REST API Handler
* @param data JSON input
Expand Down Expand Up @@ -1278,6 +1317,35 @@ namespace wrench {
return answer;
}

/**
* @brief REST API Handler
* @param data JSON input
* @return JSON output
*/
json SimulationController::getActionFailureCause(json data) {
std::string compound_job_name = data["compound_job_name"];
std::string action_name = data["action_name"];

std::shared_ptr<CompoundJob> job;
if (not this->compound_job_registry.lookup(compound_job_name, job)) {
throw std::runtime_error("Unknown job " + compound_job_name);
}

std::shared_ptr<Action> action;
try {
action = job->getActionByName(action_name);
} catch (std::invalid_argument &e) {
throw std::runtime_error("Unknown action " + action_name + " in job " + compound_job_name);
}
json answer;
if (action->getFailureCause()) {
answer["action_failure_cause"] = action->getFailureCause()->toString();
} else {
answer["action_failure_cause"] = "";
}
return answer;
}

/**
* @brief REST API Handler
* @param data JSON input
Expand Down

0 comments on commit 92b8ab1

Please sign in to comment.