Commit 3ed89b1f authored by Michael Davis's avatar Michael Davis
Browse files

[cta_frontend] Implements cta drive rm on server side

parent 56e2ff83
......@@ -129,6 +129,9 @@ void RequestMessage::process(const cta::xrd::Request &request, cta::xrd::Respons
case cmd_pair(AdminCmd::CMD_DRIVE, AdminCmd::SUBCMD_LS):
processDrive_Ls(request.admincmd(), response);
break;
case cmd_pair(AdminCmd::CMD_DRIVE, AdminCmd::SUBCMD_RM):
processDrive_Rm(request.admincmd(), response);
break;
case cmd_pair(AdminCmd::CMD_GROUPMOUNTRULE, AdminCmd::SUBCMD_ADD):
processGroupMountRule_Add(request.admincmd(), response);
break;
......@@ -842,6 +845,48 @@ void RequestMessage::processDrive_Ls(const cta::admin::AdminCmd &admincmd, cta::
void RequestMessage::processDrive_Rm(const cta::admin::AdminCmd &admincmd, cta::xrd::Response &response)
{
using namespace cta::admin;
std::stringstream cmdlineOutput;
auto regex = getRequired(OptionString::DRIVE);
cta::utils::Regex driveNameRegex(regex.c_str());
auto driveStates = m_scheduler.getDriveStates(m_cliIdentity, m_lc);
bool drivesFound = false;
for(auto driveState: driveStates)
{
const auto regexResult = driveNameRegex.exec(driveState.driveName);
if(!regexResult.empty())
{
if(driveState.driveStatus == cta::common::dataStructures::DriveStatus::Down ||
driveState.driveStatus == cta::common::dataStructures::DriveStatus::Shutdown ||
driveState.driveStatus == cta::common::dataStructures::DriveStatus::Unknown ||
has_flag(OptionBoolean::FORCE))
{
m_scheduler.removeDrive(m_cliIdentity, driveState.driveName, m_lc);
cmdlineOutput << "Drive " << driveState.driveName << " removed"
<< (has_flag(OptionBoolean::FORCE) ? " (forced)." : ".") << std::endl;
} else {
cmdlineOutput << "Drive " << driveState.driveName << " in state "
<< cta::common::dataStructures::toString(driveState.driveStatus)
<< " and force is not set (skipped)." << std::endl;
}
drivesFound = true;
}
}
if(!drivesFound) {
cmdlineOutput << "Drives not found by regex: " << regex << std::endl;
}
response.set_message_txt(cmdlineOutput.str());
response.set_type(cta::xrd::Response::RSP_SUCCESS);
}
void RequestMessage::processGroupMountRule_Add(const cta::admin::AdminCmd &admincmd, cta::xrd::Response &response)
{
using namespace cta::admin;
......
......@@ -86,6 +86,7 @@ private:
admincmd_t processDrive_Up;
admincmd_t processDrive_Down;
admincmd_t processDrive_Ls;
admincmd_t processDrive_Rm;
admincmd_t processGroupMountRule_Add;
admincmd_t processGroupMountRule_Ch;
admincmd_t processGroupMountRule_Rm;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment