mirror of
https://github.com/OpenNebula/one.git
synced 2024-12-22 13:33:52 +03:00
F #4809: API methods leader_only attribute. List, Info and Raft methods
are not leader only.
This commit is contained in:
parent
c1317ed697
commit
59cf651dd6
@ -177,6 +177,8 @@ protected:
|
||||
|
||||
bool log_method_call; //Write method call and result to the log
|
||||
|
||||
bool leader_only; //Method can be only execute by leaders or solo servers
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/* Class Constructors */
|
||||
/* ---------------------------------------------------------------------- */
|
||||
@ -189,6 +191,8 @@ protected:
|
||||
hidden_params.clear();
|
||||
|
||||
log_method_call = true;
|
||||
|
||||
leader_only = true;
|
||||
};
|
||||
|
||||
virtual ~Request(){};
|
||||
|
@ -34,6 +34,8 @@ protected:
|
||||
:Request(method_name, "A:si", help)
|
||||
{
|
||||
auth_op = AuthRequest::USE;
|
||||
|
||||
leader_only = false;
|
||||
};
|
||||
|
||||
~RequestManagerInfo(){};
|
||||
|
@ -63,7 +63,9 @@ protected:
|
||||
const string& help,
|
||||
const string& signature)
|
||||
:Request(method_name,signature,help)
|
||||
{};
|
||||
{
|
||||
leader_only = false;
|
||||
};
|
||||
|
||||
~RequestManagerPoolInfoFilter(){};
|
||||
|
||||
|
@ -92,6 +92,7 @@ public:
|
||||
"A:siiiiiiis")
|
||||
{
|
||||
log_method_call = false;
|
||||
leader_only = false;
|
||||
};
|
||||
|
||||
~ZoneReplicateLog(){};
|
||||
@ -106,9 +107,11 @@ public:
|
||||
class ZoneVoteRequest : public RequestManagerZone
|
||||
{
|
||||
public:
|
||||
ZoneVoteRequest():
|
||||
RequestManagerZone("one.zone.voterequest",
|
||||
"Request vote from a candidate", "A:siiii"){};
|
||||
ZoneVoteRequest(): RequestManagerZone("one.zone.voterequest",
|
||||
"Request vote from a candidate", "A:siiii")
|
||||
{
|
||||
leader_only = false;
|
||||
};
|
||||
|
||||
~ZoneVoteRequest(){};
|
||||
|
||||
@ -122,9 +125,11 @@ public:
|
||||
class ZoneRaftStatus : public RequestManagerZone
|
||||
{
|
||||
public:
|
||||
ZoneRaftStatus():
|
||||
RequestManagerZone("one.zone.raftstatus", "Returns Raft status",
|
||||
"A:s"){};
|
||||
ZoneRaftStatus(): RequestManagerZone("one.zone.raftstatus",
|
||||
"Returns Raft status", "A:s")
|
||||
{
|
||||
leader_only = false;
|
||||
};
|
||||
|
||||
~ZoneRaftStatus(){};
|
||||
|
||||
|
@ -273,29 +273,39 @@ void Request::execute(
|
||||
att.req_id = (reinterpret_cast<uintptr_t>(this) * rand()) % 10000;
|
||||
|
||||
Nebula& nd = Nebula::instance();
|
||||
UserPool* upool = nd.get_upool();
|
||||
|
||||
bool authenticated = upool->authenticate(att.session,
|
||||
att.password,
|
||||
att.uid,
|
||||
att.gid,
|
||||
att.uname,
|
||||
att.gname,
|
||||
att.group_ids,
|
||||
att.umask);
|
||||
UserPool* upool = nd.get_upool();
|
||||
RaftManager * raftm = nd.get_raftm();
|
||||
|
||||
if ( log_method_call )
|
||||
{
|
||||
log_method_invoked(att, _paramList, format_str, method_name,
|
||||
hidden_params);
|
||||
}
|
||||
|
||||
if ( authenticated == false )
|
||||
if ( raftm->is_follower() && leader_only)
|
||||
{
|
||||
failure_response(AUTHENTICATION, att);
|
||||
att.resp_msg = "Cannot process request, server is a follower";
|
||||
failure_response(INTERNAL, att);
|
||||
}
|
||||
else
|
||||
else if ( raftm->is_candidate() && leader_only)
|
||||
{
|
||||
request_execute(_paramList, att);
|
||||
att.resp_msg = "Cannot process request, oned cluster in election mode";
|
||||
failure_response(INTERNAL, att);
|
||||
}
|
||||
else //leader or solo or !leader_only
|
||||
{
|
||||
bool authenticated = upool->authenticate(att.session, att.password,
|
||||
att.uid, att.gid, att.uname, att.gname, att.group_ids, att.umask);
|
||||
|
||||
if ( authenticated == false )
|
||||
{
|
||||
failure_response(AUTHENTICATION, att);
|
||||
}
|
||||
else
|
||||
{
|
||||
request_execute(_paramList, att);
|
||||
}
|
||||
}
|
||||
|
||||
if ( log_method_call )
|
||||
|
Loading…
Reference in New Issue
Block a user