QConf 管理端接口(C ) - Qihoo360/QConf GitHub Wiki
安装QConf管理端后,在lib目录下可以找到库文件libqconf_zk.a 及 libqconf_zk.so
int zk_init(const std::string &host);
Description
Initial ZooKeeper environment
Parameters
host - address of ZooKeeper cluster.
Return Value
QCONF_OK if success, other if failed
Example
QConfZK qconfZk;
if(QCONF_OK == qconfZk.zk_init(host))
{
...
}
void zk_close();
Description
Destroy ZooKeeper environment
Parameters
Return Value
Example
qconfZk.zk_close();
int zk_node_set(const std::string &node, const std::string &value);
Description
Set node value, add if not exist
Parameters
node - path of ZNode need to be add or modify
value - new value of the node
Return Value
QCONF_OK if success, other if failed
Example
if (QCONF_OK != qconfZk.zk_node_set(path, new_value))
{
// Failed
}
int zk_node_delete(const std::string &node);
Description
Delete node
Parameters
node - ZNode need to be delete.
Return Value
QCONF_OK if success, other if failed
Example
switch (qconfZk.zk_node_delete(path))
{
case QCONF_OK:
// Success
break;
case QCONF_ERR_ZOO_NOTEMPTY:
// children exist
break;
default:
// failed
}
int zk_node_get(const std::string &node, std::string &buf);
Description
get node value
Parameters
node - ZNode path.
buf - output parameter, value of the node
Return Value
QCONF_OK if success, other if failed
Example
switch(ret = qconfZk.zk_node_get(path, buf))
{
case QCONF_OK:
// Success
break;
case QCONF_ERR_ZOO_NOT_EXIST:
// Node not exist
break;
default:
//Failed
}
int zk_list(const std::string &node, std::set<std::string> &children);
Description
List all children nodes
Parameters
node - ZNode path.
children - output parameter, all children of current node
Return Value
QCONF_OK if success, other if failed
Example
set<string> list;
set<string>::iterator it;
int ret = 0;
switch (ret = qconfZk.zk_list(path, list))
{
case QCONF_OK:
for (it = list.begin(); it != list.end(); ++it)
{
//Success
}
break;
case QCONF_ERR_ZOO_NOT_EXIST:
// Node not exist
break;
default:
// Failed
}
int zk_list_with_values(const std::string &node, std::map<std::string, std::string> &children);
Description
List all children nodes with their value
Parameters
node - ZNode path.
children - output parameter, children node together with their value
Return Value
QCONF_OK if success, other if failed
int zk_list(const std::string &node, std::set<std::string> &children);
Description
List all children nodes
Parameters
node - ZNode path.
children - output parameter, all children of current node
Return Value
QCONF_OK if success, other if failed
Example
set<string> list;
set<string>::iterator it;
int ret = 0;
switch (ret = qconfZk.zk_list(path, list))
{
case QCONF_OK:
for (it = list.begin(); it != list.end(); ++it)
{
//Success
}
break;
case QCONF_ERR_ZOO_NOT_EXIST:
// Node not exist
break;
default:
// Failed
}
int zk_services_set(const std::string &node, const std::map<std::string, char> &servs);
Description
set a group of services together with their status
Parameters
node - ZNode path.
servs - a group of services ip:port together with their status,the status can be choose from STATUS_UP(0), STATUS_DOWN(1), STATUS_OFFLINE(2)
Return Value
QCONF_OK if success, other if any error happened.
Example
std::map<std::string, char> servs;
servs.insert(std::map<std::string, char>::value_type("1.1.1.1:80",
STATUS_UP));
servs.insert(std::map<std::string, char>::value_type("1.1.1.2:80",
STATUS_DOWN));
if (QCONF_OK != qconfZk.zk_services_set(path, servs)
{
//Failed
}
int zk_service_add(const std::string &node, const std::string &serv, const char &status);
Description
add a service ip:port
Parameters
node - service node path.
serv - new service ip:port
status - status of the service,the status can be choose from STATUS_UP(0), STATUS_DOWN(1), STATUS_OFFLINE(2)
Return Value
QCONF_OK if success, other if any error happened.
Example
if (QCONF_OK != qconfZk.zk_service_add(path, "1.1.1.1:80", STATUS_UP)
{
//Failed
}
int zk_service_up(const std::string &node, const std::string &serv);
Description
set status of the service to be STATUS_UP
Parameters
node - service node path.
serv - the service
Return Value
QCONF_OK if success, other if any error happened.
Example
if (QCONF_OK != qconfZk.zk_service_up(path, "1.1.1.1:80")
{
//Failed
}
int zk_service_offline(const std::string &node, const std::string &serv);
Description
set status of the service to be STATUS_OFFLINE
Parameters
node - service node path.
serv - the service
Return Value
QCONF_OK if success, other if any error happened.
Example
if (QCONF_OK != qconfZk.zk_service_offline(path, "1.1.1.1:80")
{
//Failed
}
int zk_service_delete(const std::string &node, const std::string &serv);
Description
delete a service
Parameters
node - service node path.
serv - the service to be delete
Return Value
QCONF_OK if success, other if any error happened.
Example
if (QCONF_OK != qconfZk.zk_service_delete(path, "1.1.1.1:80")
{
//Failed
}
int zk_service_clear(const std::string &node);
Description
delete all services under given service node
Parameters
node - service node path.
Return Value
QCONF_OK if success, other if any error happened.
Example
if (QCONF_OK != qconfZk.zk_service_clear(path)
{
//Failed
}
int zk_services_get_with_status(const std::string &node, std::map<std::string, char> &servs);
Description
List all services with their status
Parameters
node - ZNode path.
servs - output parameter, services together with their status
Return Value
QCONF_OK if success, other if failed
int zk_services_get(const std::string &node, std::set<std::string> &servs);
Description
get all services under the given service node
Parameters
node - ZNode path.
servs - output parameter, all services of current service node
Return Value
QCONF_OK if success, other if failed
Example
set<string> servs;
set<string>::iterator it;
int ret = 0;
switch (ret = qconfZk.zk_services_get(path, servs))
{
case QCONF_OK:
for (it = servs.begin(); it != servs.end(); ++it)
{
//Success
}
break;
case QCONF_ERR_ZOO_NOT_EXIST:
// Node not exist
break;
default:
// Failed
}
int zk_gray_begin(const std::map<std::string, std::string> &nodes, const std::vector<std::string> &machines, std::string &gray_id);
Description
begin gray process
Parameters
nodes - key-value pairs of path need to be in gray process.
machines - list of machines use the new config value in current gray process
gray_id - output parameter,the unique id of current gray process
Return Value
QCONF_OK if success, other if failed
int zk_gray_rollback(const std::string &gray_id);
Description
rollback gray process
Parameters
gray_id - the unique id of current gray process
Return Value
QCONF_OK if success, other if failed
int zk_gray_commit(const std::string &gray_id);
Description
commit gray process
Parameters
gray_id - the unique id of current gray process
Return Value
QCONF_OK if success, other if failed