Skip to content

Commit

Permalink
hosts mask using simple find() function by default.
Browse files Browse the repository at this point in the history
Now find function is used to match hosts mask and hosts exclude mask.
This is the default behaviour for user, job and branch.
You can configure user, job and branch to use Regular Expressions.
If a new job does not have hosts_mask_type parameter, user host mask
type will be used.

References #604.
  • Loading branch information
timurhai committed Oct 14, 2024
1 parent dfc6bd9 commit 1a6c67e
Show file tree
Hide file tree
Showing 25 changed files with 378 additions and 197 deletions.
10 changes: 6 additions & 4 deletions afanasy/src/cmd/cmd_regexp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,19 @@ CmdRegExp::CmdRegExp()
setCmd("rx");
setArgsCount(2);
setInfo("Test a regular expression.");
setHelp("rx [string] [expression] [eci] Whether string matches specified regular expression\n"
"Optional mode [eci]: exclude, contain, case insensitive.\n"
setHelp("rx [string] [expression] [ecif] Whether string matches specified regular expression\n"
"Optional mode [ecif]: exclude, contain, case insensitive, simple find mode.\n"
"Examples:\n"
"afcmd rx ubuntu \"u.*\"\n"
"afcmd rx ubuntu \"UBU\" eci");
"afcmd rx ubuntu \"UBU\" ecif");
}

CmdRegExp::~CmdRegExp(){}

bool CmdRegExp::v_processArguments( int argc, char** argv, af::Msg & msg)
{
af::RegExp rx;
rx.setRegEx();
std::string str = argv[0];
std::string pattern = argv[1];
std::string str_error;
Expand All @@ -40,9 +41,10 @@ bool CmdRegExp::v_processArguments( int argc, char** argv, af::Msg & msg)
int pos = -1;
while( mode[++pos] != '\0')
{
if( mode[pos] == 'f') rx.setFind();
if( mode[pos] == 'e') rx.setExclude();
if( mode[pos] == 'c') rx.setContain();
if( mode[pos] == 'i') rx.setCaseInsensitive();
if( mode[pos] == 'i') rx.setCaseIns();
}
}
if( rx.setPattern( pattern, &str_error)) printf( rx.match( str) ? " MATCH\n" : " NOT MATCH\n");
Expand Down
43 changes: 35 additions & 8 deletions afanasy/src/libafanasy/afwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,14 @@ using namespace af;

Work::Work()
{
m_solving_flags = 0;
m_work_flags = 0;
m_max_tasks_per_second = -1;

m_max_running_tasks = af::Environment::getMaxRunningTasksNumber();
m_max_running_tasks_per_host = -1;

m_hosts_mask.setCaseInsensitive();
m_hosts_mask_exclude.setCaseInsensitive();
m_hosts_mask_exclude.setExclude();

m_need_os.setCaseInsensitive();
m_need_os.setContain();
m_need_properties.setCaseSensitive();
m_need_properties.setContain();
m_need_power = -1;
m_need_memory = -1;
m_need_hdd = -1;
Expand All @@ -58,7 +52,7 @@ Work::~Work()

void Work::readwrite(Msg *msg)
{
rw_int8_t(m_solving_flags, msg);
rw_int8_t(m_work_flags, msg);

rw_int32_t(m_max_tasks_per_second, msg);

Expand Down Expand Up @@ -146,6 +140,19 @@ void Work::jsonRead(const JSON &i_object, std::string *io_changes)
else
setSolveTasksNum();
}

std::string hosts_mask_type;
if (jr_string("hosts_mask_type", hosts_mask_type, i_object, io_changes))
{
if (hosts_mask_type == "find")
{
v_setHostsMaskFind();
}
else if (hosts_mask_type == "regex")
{
v_setHostsMaskRegEx();
}
}
}

void Work::jsonWrite(std::ostringstream &o_str, int i_type) const
Expand Down Expand Up @@ -174,10 +181,30 @@ void Work::jsonWrite(std::ostringstream &o_str, int i_type) const
o_str << ",\n\"solve_method\":\"" << (isSolvePriority() ? "solve_priority" : "solve_order") << "\"";
o_str << ",\n\"solve_need\":\"" << (isSolveCapacity() ? "solve_capacity" : "solve_tasksnum") << "\"";

if (isHostsMaskRegEx())
o_str << ",\n\"hosts_mask_type\":\"regex\"";
if (isHostsMaskFind())
o_str << ",\n\"hosts_mask_type\":\"find\"";

if (m_running_tasks_num > 0) o_str << ",\n\"running_tasks_num\":" << m_running_tasks_num;
if (m_running_capacity_total > 0) o_str << ",\n\"running_capacity_total\":" << m_running_capacity_total;
}

void Work::v_setHostsMaskFind()
{
m_work_flags = m_work_flags | FHostsMask_Find;
m_work_flags = m_work_flags & (~FHostsMask_RegEx);
m_hosts_mask.setFind();
m_hosts_mask_exclude.setFind();
}
void Work::v_setHostsMaskRegEx()
{
m_work_flags = m_work_flags & (~FHostsMask_Find);
m_work_flags = m_work_flags | FHostsMask_RegEx;
m_hosts_mask.setRegEx();
m_hosts_mask_exclude.setRegEx();
}

int Work::getPoolPriority(const std::string & i_pool, bool & o_canrunon) const
{
o_canrunon = true;
Expand Down
34 changes: 22 additions & 12 deletions afanasy/src/libafanasy/afwork.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,31 @@ class Work : public Node
virtual ~Work();


enum SolvingFlags
enum WorkFlags
{
SolvePriority = 1 << 0, ///< Solve by order or prioruty
SolveCapacity = 1 << 1 ///< Solve by running tasks number or total capacity
FSolvePriority = 1 << 0, ///< Solve by order or prioruty
FSolveCapacity = 1 << 1, ///< Solve by running tasks number or total capacity

FHostsMask_Find = 1 << 2,
FHostsMask_RegEx = 1 << 3
};

inline void setSolvePriority() { m_solving_flags |= SolvePriority; }
inline void setSolveOrder() { m_solving_flags &=~SolvePriority; }
inline void setSolveCapacity() { m_solving_flags |= SolveCapacity; }
inline void setSolveTasksNum() { m_solving_flags &=~SolveCapacity; }
virtual void v_setHostsMaskFind();
virtual void v_setHostsMaskRegEx();

inline bool isHostsMaskInherit() const {return (m_work_flags & (FHostsMask_Find | FHostsMask_RegEx)) == 0;}
inline bool isHostsMaskFind() const {return (m_work_flags & FHostsMask_Find);}
inline bool isHostsMaskRegEx() const {return (m_work_flags & FHostsMask_RegEx);}

inline void setSolvePriority() { m_work_flags |= FSolvePriority; }
inline void setSolveOrder() { m_work_flags &=~FSolvePriority; }
inline void setSolveCapacity() { m_work_flags |= FSolveCapacity; }
inline void setSolveTasksNum() { m_work_flags &=~FSolveCapacity; }

inline bool isSolvePriority() const {return m_solving_flags & SolvePriority;}
inline bool isSolveOrder() const {return (m_solving_flags & SolvePriority) == false;}
inline bool isSolveCapacity() const {return m_solving_flags & SolveCapacity;}
inline bool isSolveTasksNum() const {return (m_solving_flags & SolveCapacity) == false;}
inline bool isSolvePriority() const {return m_work_flags & FSolvePriority;}
inline bool isSolveOrder() const {return (m_work_flags & FSolvePriority) == false;}
inline bool isSolveCapacity() const {return m_work_flags & FSolveCapacity;}
inline bool isSolveTasksNum() const {return (m_work_flags & FSolveCapacity) == false;}


void generateInfoStream(std::ostringstream &o_str, bool full = false) const; /// Generate information.
Expand Down Expand Up @@ -115,7 +125,7 @@ class Work : public Node
void readwrite(Msg *msg); ///< Read or write node attributes in message

protected:
int8_t m_solving_flags;
int8_t m_work_flags;

int32_t m_max_tasks_per_second;

Expand Down
10 changes: 2 additions & 8 deletions afanasy/src/libafanasy/blockdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,16 +144,10 @@ void BlockData::construct()
m_running_tasks_counter = 0;
m_running_capacity_counter = 0;

m_depend_mask.setCaseSensitive();
m_tasks_depend_mask.setCaseSensitive();
m_depend_mask.setRegEx();
m_tasks_depend_mask.setRegEx();

m_hosts_mask.setCaseInsensitive();

m_hosts_mask_exclude.setCaseInsensitive();
m_hosts_mask_exclude.setExclude();

m_need_properties.setCaseSensitive();
m_need_properties.setContain();
}

/// Construct data from JSON:
Expand Down
3 changes: 3 additions & 0 deletions afanasy/src/libafanasy/blockdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ class BlockData : public Af
inline void setSequential(int64_t i_value) { m_sequential = i_value; } ///< Used in afcmd cmd_numeric
inline int64_t getSequential() const { return m_sequential; }

inline void setHostsMaskFind() {m_hosts_mask.setFind(); m_hosts_mask_exclude.setFind(); }
inline void setHostsMaskRegEx() {m_hosts_mask.setRegEx(); m_hosts_mask_exclude.setRegEx();}

inline void setParserCoeff(int value) { m_parser_coeff = value; }

/// Set block tasks command. Used in system job.
Expand Down
4 changes: 2 additions & 2 deletions afanasy/src/libafanasy/job.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,8 @@ void Job::initDefaultValues()
m_thumb_data = NULL;
m_blocks_data = NULL;

m_depend_mask.setCaseSensitive();
m_depend_mask_global.setCaseSensitive();
m_depend_mask.setRegEx();
m_depend_mask_global.setRegEx();
}

bool Job::isValid( std::string * o_err) const
Expand Down
3 changes: 2 additions & 1 deletion afanasy/src/libafanasy/pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ Pool::Pool(int i_id)

void Pool::initDefaultValues()
{
m_pattern.setCaseInsensitive();
m_pattern.setRegEx();
m_pattern.setCaseIns();

m_time_creation = 0;

Expand Down
Loading

0 comments on commit 1a6c67e

Please sign in to comment.