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 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 */
|
/* Class Constructors */
|
||||||
/* ---------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------- */
|
||||||
@ -189,6 +191,8 @@ protected:
|
|||||||
hidden_params.clear();
|
hidden_params.clear();
|
||||||
|
|
||||||
log_method_call = true;
|
log_method_call = true;
|
||||||
|
|
||||||
|
leader_only = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
virtual ~Request(){};
|
virtual ~Request(){};
|
||||||
|
@ -34,6 +34,8 @@ protected:
|
|||||||
:Request(method_name, "A:si", help)
|
:Request(method_name, "A:si", help)
|
||||||
{
|
{
|
||||||
auth_op = AuthRequest::USE;
|
auth_op = AuthRequest::USE;
|
||||||
|
|
||||||
|
leader_only = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
~RequestManagerInfo(){};
|
~RequestManagerInfo(){};
|
||||||
|
@ -63,7 +63,9 @@ protected:
|
|||||||
const string& help,
|
const string& help,
|
||||||
const string& signature)
|
const string& signature)
|
||||||
:Request(method_name,signature,help)
|
:Request(method_name,signature,help)
|
||||||
{};
|
{
|
||||||
|
leader_only = false;
|
||||||
|
};
|
||||||
|
|
||||||
~RequestManagerPoolInfoFilter(){};
|
~RequestManagerPoolInfoFilter(){};
|
||||||
|
|
||||||
|
@ -92,6 +92,7 @@ public:
|
|||||||
"A:siiiiiiis")
|
"A:siiiiiiis")
|
||||||
{
|
{
|
||||||
log_method_call = false;
|
log_method_call = false;
|
||||||
|
leader_only = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
~ZoneReplicateLog(){};
|
~ZoneReplicateLog(){};
|
||||||
@ -106,9 +107,11 @@ public:
|
|||||||
class ZoneVoteRequest : public RequestManagerZone
|
class ZoneVoteRequest : public RequestManagerZone
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ZoneVoteRequest():
|
ZoneVoteRequest(): RequestManagerZone("one.zone.voterequest",
|
||||||
RequestManagerZone("one.zone.voterequest",
|
"Request vote from a candidate", "A:siiii")
|
||||||
"Request vote from a candidate", "A:siiii"){};
|
{
|
||||||
|
leader_only = false;
|
||||||
|
};
|
||||||
|
|
||||||
~ZoneVoteRequest(){};
|
~ZoneVoteRequest(){};
|
||||||
|
|
||||||
@ -122,9 +125,11 @@ public:
|
|||||||
class ZoneRaftStatus : public RequestManagerZone
|
class ZoneRaftStatus : public RequestManagerZone
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ZoneRaftStatus():
|
ZoneRaftStatus(): RequestManagerZone("one.zone.raftstatus",
|
||||||
RequestManagerZone("one.zone.raftstatus", "Returns Raft status",
|
"Returns Raft status", "A:s")
|
||||||
"A:s"){};
|
{
|
||||||
|
leader_only = false;
|
||||||
|
};
|
||||||
|
|
||||||
~ZoneRaftStatus(){};
|
~ZoneRaftStatus(){};
|
||||||
|
|
||||||
|
@ -273,29 +273,39 @@ void Request::execute(
|
|||||||
att.req_id = (reinterpret_cast<uintptr_t>(this) * rand()) % 10000;
|
att.req_id = (reinterpret_cast<uintptr_t>(this) * rand()) % 10000;
|
||||||
|
|
||||||
Nebula& nd = Nebula::instance();
|
Nebula& nd = Nebula::instance();
|
||||||
UserPool* upool = nd.get_upool();
|
|
||||||
|
|
||||||
bool authenticated = upool->authenticate(att.session,
|
UserPool* upool = nd.get_upool();
|
||||||
att.password,
|
RaftManager * raftm = nd.get_raftm();
|
||||||
att.uid,
|
|
||||||
att.gid,
|
|
||||||
att.uname,
|
|
||||||
att.gname,
|
|
||||||
att.group_ids,
|
|
||||||
att.umask);
|
|
||||||
if ( log_method_call )
|
if ( log_method_call )
|
||||||
{
|
{
|
||||||
log_method_invoked(att, _paramList, format_str, method_name,
|
log_method_invoked(att, _paramList, format_str, method_name,
|
||||||
hidden_params);
|
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 )
|
if ( log_method_call )
|
||||||
|
Loading…
Reference in New Issue
Block a user