コード例 #1
0
ファイル: ccs_agent.c プロジェクト: Chairo/experiments
static int
create_tables(zhandle_t *zkhandle, char p[][64], int count)
{
    int ret = 0;
    char path[128];
    char buf[128] = {0};

    ret = zoo_create(zkhandle,
                        "/ccs",
                        "hello",
                        5,
                        &ZOO_OPEN_ACL_UNSAFE,  /* a completely open ACL */
                        0,
                        buf, 
                        sizeof(buf)-1);
    if (ret == ZNODEEXISTS) {
        ret = 0;
        fprintf(stderr, "/ccs node exists\n");
    } else if (ret != 0) {
        fprintf(stderr, "zoo_create error [%d]\n", ret);
        return ret;
    } else {
        fprintf(stderr, "create [%s] ok\n", "/ccs");
    } 

    for (int i = 0; i < count; i++) {
        memset(path, 0, sizeof(path));
        sprintf(path, "/ccs/%s", p[i]);
        ret = zoo_create(zkhandle,
                            path,
                            "hello", 
                            5,
                            &ZOO_OPEN_ACL_UNSAFE,  /* a completely open ACL */
                            0,
                            buf, 
                            sizeof(buf)-1);
        if (ret == ZNODEEXISTS) {
            ret = 0;
            fprintf(stderr, "%s node exists\n", path);
        } else if (ret != 0) {
            fprintf(stderr, "zoo_create error [%d]\n", ret);
            return ret;
        } else {
            fprintf(stderr, "create [%s] ok\n", path);
        } 
    }

    return ret;
}
コード例 #2
0
ファイル: main.c プロジェクト: crnt/myservices
static bool create_node_if_not_exists(service_location_t *service, int flags, const char *value, int value_len, const char *fmt, ...)
{
	struct Stat stat;
	int status, retry_count;
	char node_key[512];
	va_list args;
	
	if (service->connected_state == false) {
		return false;
	}

	va_start(args, fmt);
	vsnprintf(node_key, 512, fmt, args);
	va_end(args);
	
	retry_count = 3;
	do {
		status = zoo_exists(service->zk, node_key, 1, &stat);
		retry_count++;
	} while (status == ZCONNECTIONLOSS && retry_count--);
		
	if (status == ZNONODE) {
		LOG_INFO(service->log_fd, "Creating node=[%s] value=[%s]", node_key, value);
		
		retry_count = 3;
		do {
			status = zoo_create(service->zk, node_key, value, value_len, &ZOO_OPEN_ACL_UNSAFE, flags, 0, 0);
			retry_count++;
		} while (status == ZCONNECTIONLOSS && retry_count--);
	}

	return (status == ZOK) ? true : false;
}
コード例 #3
0
ファイル: replica.c プロジェクト: jingleyang/RDMA_Paxos
int start_zookeeper(view* cur_view, int *zfd, pthread_mutex_t *lock)
{
	int rc;
	char zoo_host_port[32];
	sprintf(zoo_host_port, "localhost:%d", zoo_port);
	zh = zookeeper_init(zoo_host_port, zookeeper_init_watcher, 15000, 0, 0, 0);

    while(is_connected != 1);
    int interest, fd;
    struct timeval tv;
    zookeeper_interest(zh, &fd, &interest, &tv);
    *zfd = fd;

    char path_buffer[512];
    rc = zoo_create(zh, "/election/guid-n_", NULL, -1, &ZOO_OPEN_ACL_UNSAFE, ZOO_SEQUENCE|ZOO_EPHEMERAL, path_buffer, 512);
    if (rc)
    {
        fprintf(stderr, "Error %d for zoo_create\n", rc);
    }
    char znode_path[512];
    get_znode_path(path_buffer, znode_path);

    check_leader(cur_view, path_buffer);
    struct watcherContext *watcherPara = (struct watcherContext *)malloc(sizeof(struct watcherContext));
    strcpy(watcherPara->znode_path, znode_path);
    watcherPara->lock = lock;
    watcherPara->cur_view = cur_view;

    rc = zoo_wget_children(zh, "/election", zoo_wget_children_watcher, (void*)watcherPara, NULL);
    if (rc)
    {
        fprintf(stderr, "Error %d for zoo_wget_children\n", rc);
    }
    return 0;
}
コード例 #4
0
ファイル: ccs_agent.c プロジェクト: Chairo/experiments
static 
int join_the_election(zhandle_t *zkhandle, char node[], struct watch_func_para_t *para) 
{
    char buf[512] = {0};
    int ret;

    ret = zoo_create(zkhandle,
                        "/election/ccs-member", 
                        "hello", 
                        5,
                        &ZOO_OPEN_ACL_UNSAFE,  /* a completely open ACL */
                        ZOO_SEQUENCE|ZOO_EPHEMERAL,
                        buf, 
                        sizeof(buf)-1);
    if (ret) {
        fprintf(stderr, "zoo_create error [%d]\n", ret);
        return ret;
    }

    get_node_name(buf, node);

    struct Stat stat;
    memset(&stat, 0, sizeof(stat));
    struct String_vector strings;
    memset(para, 0, sizeof(*para));
    para->zkhandle = zkhandle;
    strcpy(para->node, node);
    ret = zoo_wget_children2(zkhandle, "/election", ccs_children_watcher, para, &strings, &stat);
    if (ret) {
        fprintf(stderr, "zoo_wget_children2 error [%d]\n", ret);
        return ret;
    }

    return ret;
}
コード例 #5
0
int main(int argc, const char *argv[])  
{  
    int timeout = 30000;  
  
    zoo_set_debug_level(ZOO_LOG_LEVEL_WARN); //设置日志级别,避免出现一些其他信息  

    get_option(argc,argv);

    zhandle_t* zkhandle = zookeeper_init(g_host,NULL, timeout, 0, (char *)"Load Balancing Test", 0);  

    if (zkhandle ==NULL){ 
        fprintf(stderr, "Error when connecting to zookeeper servers...\n");  
        exit(EXIT_FAILURE);  
    }  
    
    char consumer_path[512] = "/Consumer";
    char topic_path[512] = {0};
    char group_path[512] = {0};
    char client_path[512] = {0};
    
    sprintf(topic_path,"%s/%s",consumer_path,g_topic);
    sprintf(group_path,"%s/group-%d",topic_path,g_groupid);
    sprintf(client_path,"%s/client-",group_path);
    

    create(zkhandle,consumer_path,0,"");
    create(zkhandle,topic_path,0,"");
    create(zkhandle,group_path,0,"00000000");
    
    int bufferlen = sizeof(g_my_path);

    int ret = zoo_create(zkhandle,client_path,NULL,0,
                          &ZOO_OPEN_ACL_UNSAFE,ZOO_SEQUENCE|ZOO_EPHEMERAL,
                          g_my_path,bufferlen);
  
    if (ret != ZOK){  
        printf("节点创建失败:%s \n",client_path);  
        exit(EXIT_FAILURE);  
    }else {  
        printf("创建的节点名称为:%s\n",g_my_path);  
    }

    char self_name[512] = {0};
    
    strcpy(self_name,rindex(g_my_path,'/')+1);

    
    choose_mater(zkhandle,group_path,self_name);

    do_work(zkhandle);

    getchar();

    zookeeper_close(zkhandle); 

    return 0;
}  
コード例 #6
0
int create_dir(zhandle_t* handle, const std::string& name,
               const std::string& stat_message) {
  int stat = zoo_create(handle, name.c_str(), NULL, -1, 
                       &ZOO_OPEN_ACL_UNSAFE, 0, NULL, 0);
  // we are ok with ZNODEEXISTS
  // if (stat == ZOK || stat == ZNODEEXISTS) return stat;
  if (stat != ZOK) print_stat(stat, stat_message + " create_dir", name);
  return stat;
}
コード例 #7
0
int create_ephemeral_node(zhandle_t* handle, 
                 const std::string& path, 
                 const std::string& value,
                 const std::string& stat_message) {
  int stat = zoo_create(handle, path.c_str(), value.c_str(), value.length(), 
                        &ZOO_OPEN_ACL_UNSAFE, ZOO_EPHEMERAL, NULL, 0);
  // if (stat == ZOK) return stat;
  if (stat != ZOK) print_stat(stat, stat_message + " create_ephemeral_node", path);
  return stat;
}
コード例 #8
0
ファイル: main.c プロジェクト: thiagodecasantiago/mo806
int main(int argc, char *argv[])
{
    char server_address[256];
    char ephemeral_path[256];
    int rc;

    /* verificação básica dos argumentos */
    if (argc != 2) {
        fprintf(stderr, "Uso: ./program <endereço do servidor>\n");
        exit(EXIT_FAILURE);
    }

    /* Primeiro argumento é o endereço do servidor */
    strcpy(server_address, argv[1]);

    /* Inicializa a conexão com o servidor */
    if ((zh = zookeeper_init(server_address, watcher, 10000, &myid, NULL, 0)) == NULL) {
        fprintf(stderr, "Não foi possível conectar-se ao servidor %s\n", server_address);
        exit(EXIT_FAILURE);
    } else {
        fprintf(stdout, "Conectado à %s\n", server_address);
    }
    fprintf(stdout, "Myid: %d\n", myid.client_id);
    sprintf(ephemeral_path, "/fase1/cliente-%d", myid.client_id);

    /* Cria um nó comum */
    zoo_create(zh, "/fase1", NULL, 0, &ZOO_OPEN_ACL_UNSAFE, 0,
               NULL, 0);
    /* Cria um nó efêmero */
    rc = zoo_create(zh, ephemeral_path, NULL, 0, &ZOO_OPEN_ACL_UNSAFE, ZOO_EPHEMERAL,
                    NULL, 0);
    /* seta um watch em um arquivo criado por um processo diferente */
    zoo_exists(zh, "/fase1/cliente-1", 1, &stat);

    while(1) {
        /* espera até que o watcher dispare */
    }

    /* não deve chegar aqui nunca */
    zookeeper_close(zh);
    return EXIT_SUCCESS;
}
コード例 #9
0
/**
 * create node in zookeeper server
 * \param node indicate key
 * param flag =ZOO_EPHEMERAL
*/ 
bool ZKOP::zkCreateNodePath(const std::string& node, int flag) 
{/*{{{*/
	int rc = 0;
/*
	if ((rc = zoo_exists(zkhandle, node.data(), 0, NULL)) == ZOK) {
		return true;
	}

	if (rc != ZNONODE) {
		//LOG(ERROR) << "create new node failed, node = [" << node << "], error = [" << zerror(rc) << "]";
		return false;
	}

	if (zoo_exists(zkhandle, node.data(), 0, NULL) == ZNONODE) {
		if ((rc = zoo_create(zkhandle, node.data(),
						NULL, -1, &ZOO_OPEN_ACL_UNSAFE,
						flag, NULL, 0)) != ZOK) {
			LOG(ERROR) << "create new node failed, node = [" << node << "], error = [" << zerror(rc) << "]";
			return false;
		}
	}

	LOG(INFO) << "create new node successful, node = [" << node << "], flag = [" << flag << "]";

	return true;
*/
	rc = zkNodeExists(node, flag);
	if( ZOK == rc ) {
		return true;
	}
	if(ZNONODE != rc){
		return false;
	}


	if(ZNONODE == rc){
		if ((rc = zoo_create(zkhandle, node.data(),
						NULL, -1, &ZOO_OPEN_ACL_UNSAFE,
						flag, NULL, 0)) != ZOK) {
			LOG(ERROR) << "create new node failed, node = [" << node << "], error = [" << zerror(rc) << "]";
			return false;
		}
	}else{
		std::stringstream ss;
		std::string str;
		ss << rc;
		ss >> str;
		LOG(ERROR) << "create new node failed, node = [" << node << "], error = [" << zerror(rc) << "]" << "\trc=" << str;
		return false;
	}

	return true;
}/*}}}*/
コード例 #10
0
ファイル: c_test.c プロジェクト: erich0929/programming
int main(int argc, char *argv[])  {
        char zkServers[100] = "127.0.0.1:2181";

        zoo_set_debug_level(ZOO_LOG_LEVEL_WARN);
        zoo_deterministic_conn_order(1); 
        zh = zookeeper_init(zkServers, watcher, 60000, &zkClientId, 0, 0);

        if (!zh) {
                printf("ZK Init error(%s)\n", zkServers);
                return 0;
        }

        while (true) {
                sleep(1);
                if (completeZkInit == 1) {
                        break;
                }
        }

        char resultPath[1024] = {0,};
        int resultLength;

        zoo_create(zh, "/test", "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, resultPath, 1024);

        //watchctx_t ctxWC;
        Stat zooStat;
        int result = zoo_exists(zh, "/test", 1, &zooStat);
        if (result == ZOK) {
                printf("node exists\n");
        }
        String_vector children;
        zoo_get_children(zh, "/test", 1, &children);
        zoo_create(zh, "/test/sub01", "", 0, &ZOO_OPEN_ACL_UNSAFE, ZOO_EPHEMERAL, resultPath, 1024);
        zoo_create(zh, "/test/sub02", "", 0, &ZOO_OPEN_ACL_UNSAFE, ZOO_EPHEMERAL, resultPath, 1024);

        zoo_delete(zh, "/test", -1);
        while(1) {
                sleep(20);
        }
}
コード例 #11
0
ファイル: zk.cpp プロジェクト: nakj/jubatus
// "/some/path" => "/some/path0000012"
void zk::create_seq(const std::string& path, std::string& seqfile) {
    scoped_lock lk(m_);
    char path_buffer[path.size()+16];
    int rc = zoo_create(zh_, path.c_str(), NULL, 0, &ZOO_OPEN_ACL_UNSAFE,
                        ZOO_EPHEMERAL|ZOO_SEQUENCE, path_buffer, path.size()+16);
    seqfile = "";
    if(rc != ZOK) {
        LOG(ERROR) << path << " failed in creation - " << zerror(rc);

    } else {
        seqfile = path_buffer;
    }
};
コード例 #12
0
static VALUE method_create(VALUE self, VALUE path, VALUE value, VALUE flags) {
  struct zk_rb_data* zk;
  char realpath[10240];

  Check_Type(path, T_STRING);
  Check_Type(value, T_STRING);
  Check_Type(flags, T_FIXNUM);
  Data_Get_Struct(rb_iv_get(self, "@data"), struct zk_rb_data, zk);

  check_errors(zoo_create(zk->zh, RSTRING(path)->ptr, RSTRING(value)->ptr, RSTRING(value)->len,
			  &ZOO_OPEN_ACL_UNSAFE, FIX2INT(flags), realpath, 10240));

  return rb_str_new2(realpath);
}
コード例 #13
0
ファイル: main.cpp プロジェクト: openvoipco/stuff
int main(int argc, char **argv) {
  char buffer[512];
  char p[2048];
  char *cert=0;
  char appId[64];

  strcpy(appId, "example.foo_test");
  cert = foo_get_cert_once(appId);
  if(cert!=0) {
    fprintf(stderr, "Certificate for appid [%s] is [%s]\n",appId,cert);
    strncpy(p,cert, sizeof(p)-1);
    free(cert);
  } else {
    fprintf(stderr, "Certificate for appid [%s] not found\n",appId);
    strcpy(p, "dummy");
  }

  zoo_set_debug_level(ZOO_LOG_LEVEL_DEBUG);

  zh = zookeeper_init("localhost:2181", watcher, 10000, 0, 0, 0);
  if (!zh) {
	fprintf(stderr, "Error1: %s\n", strerror(errno));
    return errno;
  }
  if (zoo_add_auth(zh, "foo", p, strlen(p), 0, 0) != ZOK) {
    fprintf(stderr, "Error2: %s\n", strerror(errno));
    return 2;
  }

  struct ACL CREATE_ONLY_ACL[] = {{ZOO_PERM_CREATE, ZOO_AUTH_IDS}};
  struct ACL_vector CREATE_ONLY = {1, CREATE_ONLY_ACL};
  int rc = zoo_create(zh, "/xyz", "value", 5, &CREATE_ONLY, ZOO_EPHEMERAL, (char*)&buffer, sizeof(buffer) - 1);
  if (!rc) {
    fprintf(stderr, "Error3: %s\n", strerror(errno));
    return errno;
  }

  /** this operation will fail with a ZNOAUTH error */
  int buflen= sizeof(buffer);
  struct Stat stat;
  rc = zoo_get(zh, "/xyz", 0, buffer, &buflen, &stat);
  if (rc) {
    fprintf(stderr, "Error4: %d for %s\n", rc, __LINE__);
  } else {
	fprintf(stdout, "Got %s\n", (char*)&buffer);
  }

  zookeeper_close(zh);
  return 0;
}
コード例 #14
0
ファイル: zoodis.c プロジェクト: Zunonia/zoodis
enum zoo_res zu_create_ephemeral(struct zoodis *z)
{
    int res;
    int bufsize = 512;
    char buffer[bufsize]; // no reason, added due to some of example, need to be done.
    int buffer_len = bufsize;
    memset(buffer, 0x00, bufsize);

    res = zoo_get(z->zh, z->zoo_nodepath->data, 0, buffer, &buffer_len, 0);

    if(res == ZOK)
    {
        if(buffer_len == z->zoo_nodedata->len && strncmp(z->zoo_nodedata->data, buffer, z->zoo_nodedata->len) == 0)
        {
            return ZOO_RES_OK;
        }else
        {
            zu_remove_ephemeral(z);
        }
    }else if(res != ZOK && res != ZNONODE)
    {
        ZU_RETURN_PRINT(res);
        if(res == ZINVALIDSTATE)
        {
            zookeeper_close(z->zh);
            zoodis.zoo_stat = ZOO_STAT_NOT_CONNECTED;
            z->zid = NULL;
            log_warn("Zookeeper: error, trying to re-connect.");
            zu_connect(z);
        }
        // exit_proc(-1);
    }

    res = zoo_create(z->zh, z->zoo_nodepath->data, z->zoo_nodedata->data, strlen(z->zoo_nodedata->data), &ZOO_READ_ACL_UNSAFE, ZOO_EPHEMERAL, buffer, sizeof(buffer)-1);
    if(res != ZOK)
    {
        ZU_RETURN_PRINT(res);
        if(res == ZINVALIDSTATE)
        {
            zookeeper_close(z->zh);
            zoodis.zoo_stat = ZOO_STAT_NOT_CONNECTED;
            z->zid = NULL;
            log_warn("Zookeeper: error, trying to re-connect.");
            zu_connect(z);
        }
    }

    return ZOO_RES_OK;
}
コード例 #15
0
ファイル: zookeeper_c.c プロジェクト: greglu/zookeeper_client
static VALUE method_create(VALUE self, VALUE path, VALUE value, VALUE flags) {
  char realpath[10240];

  Check_Type(path, T_STRING);
  Check_Type(value, T_STRING);
  Check_Type(flags, T_FIXNUM);

  FETCH_DATA_PTR(self, zk);

  check_errors(zoo_create(zk->zh, RSTRING(path)->ptr, 
                          RSTRING(value)->ptr, RSTRING(value)->len,
			  &ZOO_OPEN_ACL_UNSAFE, FIX2INT(flags), 
                          realpath, sizeof(realpath)));

  return rb_str_new2(realpath);
}
コード例 #16
0
  std::string ZooKeeperNodeManager::CreateSequentialNode( const std::string& path, const std::string& data, ZooKeeperNodeType nodeType )
  {
    int flags = ZOO_SEQUENCE;
    flags |= (nodeType == ZooKeeperNodeType::EPHEMERAL ? ZOO_EPHEMERAL : 0);

    char sequencedPath[MAX_PATH_BUFFER];

    // create a sequential (persistent or ephemeral) node synchronously
    int result = zoo_create( m_zooKeeperSessionManager->GetHandle(), path.c_str(), data.c_str(), data.size(), &ZOO_OPEN_ACL_UNSAFE, flags, sequencedPath, sizeof( sequencedPath ) );
    if( result == ZOK )
    {
      return std::string( sequencedPath, strlen( sequencedPath ) );
    }

    throw ZooKeeperException( result );
  }
コード例 #17
0
ファイル: zk.cpp プロジェクト: Tukamotosan/jubatus
// "/some/path" => "/some/path0000012"
bool zk::create_seq(const string& path, string& seqfile) {
  scoped_lock lk(m_);
  string path_buffer(path.size() + 16, '\0');
  int rc = zoo_create(zh_, path.c_str(), NULL, 0, &ZOO_OPEN_ACL_UNSAFE,
                      ZOO_EPHEMERAL | ZOO_SEQUENCE, &path_buffer[0],
                      path.size() + 16);
  seqfile = "";
  if (rc != ZOK) {
    LOG(ERROR) << "failed to create: " << path << " - " << zerror(rc);
    return false;
  } else {
    seqfile = path_buffer;
    DLOG(INFO) << __func__ << " " << seqfile;
    return true;
  }
}
コード例 #18
0
  bool ZooKeeperNodeManager::CreateNode( const std::string& path, const std::string& data, ZooKeeperNodeType nodeType )
  {
    int flags = (nodeType == ZooKeeperNodeType::EPHEMERAL) ? ZOO_EPHEMERAL : 0;

    // create a persistent or ephemeral node synchronously
    int result = zoo_create( m_zooKeeperSessionManager->GetHandle(), path.c_str(), data.c_str(), data.size(), &ZOO_OPEN_ACL_UNSAFE, flags, NULL, 0 );
    if( result == ZOK )
    {
      return true;
    }
    else if( result == ZNODEEXISTS )
    {
      return false;
    }

    throw ZooKeeperException( result );
  }
コード例 #19
0
std::pair<int,int> create_ephemeral_sequence_node(zhandle_t* handle, 
                                                  const std::string& path, 
                                                  const std::string& value,
                                                  const std::string& stat_message) {
  // make sure we always have enough room for the version number
  assert(path.length() + 10 < 1024);
  char retpathbuffer[1024];
  int stat = zoo_create(handle, path.c_str(), value.c_str(), value.length(), 
                        &ZOO_OPEN_ACL_UNSAFE, ZOO_EPHEMERAL | ZOO_SEQUENCE, 
                        retpathbuffer, 1024);
  // if (stat == ZOK) return stat;
  if (stat != ZOK) print_stat(stat, stat_message + " create_ephemeral_sequence_node", path);
  int retlen = strlen(retpathbuffer);
  assert(retlen > 10);
  int version = atoi(retpathbuffer + (retlen - 10));
  return std::pair<int, int>(stat, version);
}
コード例 #20
0
/**
 * create node and set value in zookeeper server
 * \param node indicate key
 * \param data indicate value
 * \param flag =ZOO_EPHEMERAL
*/ 
bool ZKOP::zkCreateDataNode(const std::string& node, const std::string& data, int flag) 
{/*{{{*/
	int rc = 0;
	bool __ret = true;
	if ((rc = zoo_create(zkhandle,
					node.data(), data.data(),
					data.size(),
					&ZOO_OPEN_ACL_UNSAFE,
					flag, NULL, 0)) != ZOK) {
		LOG(ERROR) << "create data node failed, node = [" << node << "], data = [" << data << "], error = [" << zerror(rc) << "]";
		__ret = false;
	}else{
		LOG(INFO) << "create data node succ, node = [" << node << "], data = [" << data << "]";
		__ret = true;
	}

	return __ret;
}/*}}}*/
コード例 #21
0
ファイル: zk_c_t.cpp プロジェクト: gityf/utils
//同步方式创建节点
void create(zhandle_t *zkhandle,char *str)
{
    char path_buffer[64];
    int bufferlen=sizeof(path_buffer);
    printf("同步方式创建节点-----------------------\n");
    int flag = zoo_create(zkhandle,str,"hahah",5,
                          &ZOO_OPEN_ACL_UNSAFE,0,
                          path_buffer,bufferlen);

    if (flag!=ZOK)
    {
        printf("节点创建失败 \n");
        exit(EXIT_FAILURE);
    }
    else
    {
        printf("创建的节点名称为:%s\n",path_buffer);
    }
}
コード例 #22
0
ファイル: Register.cpp プロジェクト: gameworld/RPC
int Register::registe(const serviceinfo & info)
{
		std::string name="/Register_"+info.servicename;
		char buf[1024];
		int bufflen=sizeof(buf);
		struct Stat stat;
		//首先查询节点是否存在
		int ret=zoo_exists(zh,name.c_str(),1,&stat);



		LOG(INFO)<<ret;
		switch(ret)
		{
		case ZOK:{
			LOG(INFO)<<"OK\n";
		} break;
		case ZNONODE:{
			LOG(INFO)<<"ZNONODE\n";
		}break;

		default:
			LOG(INFO)<<"other\n";

		}
		LOG(INFO)<<stat.ctime;

		LOG(INFO)<<bufflen;

		/*
		 * 创建节点
		 */
		char path_buffer[64];

		ret=zoo_create(zh,name.c_str(),"app",3,&ZOO_OPEN_ACL_UNSAFE, ZOO_EPHEMERAL,path_buffer,sizeof(path_buffer)-1);


		LOG(INFO)<<ret;


		return 0;
}
コード例 #23
0
ファイル: zookeeper_c.c プロジェクト: mgrosso/zookeeper
static VALUE method_create(VALUE self, VALUE reqid, VALUE path, VALUE data, VALUE async, VALUE acls, VALUE flags) {
  VALUE watch = Qfalse;
  const char *data_ptr ;
  size_t      data_len ;
  struct ACL_vector *aclptr = NULL;
  char realpath[16384];
  int rc;
  VALUE output ;
  STANDARD_PREAMBLE(self, zk, reqid, path, async, watch, data_ctx, watch_ctx, call_type);

  if (data != Qnil) Check_Type(data, T_STRING);
  Check_Type(flags, T_FIXNUM);
  data_ptr = (data == Qnil) ? NULL : RSTRING_PTR(data);
  data_len = (data == Qnil) ? -1   : RSTRING_LEN(data);

  if (acls != Qnil) { aclptr = zkrb_ruby_to_aclvector(acls); }

  switch (call_type) {
    case SYNC:
      rc = zoo_create(zk->zh, RSTRING_PTR(path), data_ptr, data_len, aclptr, FIX2INT(flags), realpath, sizeof(realpath));
      break;
    case ASYNC:
      rc = zoo_acreate(zk->zh, RSTRING_PTR(path), data_ptr, data_len, aclptr, FIX2INT(flags), zkrb_string_callback, data_ctx);
      break;
    default:
      /* TODO(wickman) raise proper argument error */
      return Qnil;
      break;
  }

  if (aclptr) {
    deallocate_ACL_vector(aclptr);
    free(aclptr);
  }

  output = rb_ary_new();
  rb_ary_push(output, INT2FIX(rc));
  if (IS_SYNC(call_type) && rc == ZOK) {
    return rb_ary_push(output, rb_str_new2(realpath));
  }
  return output;
}
コード例 #24
0
ファイル: DevCtlServiceReg.cpp プロジェクト: europelee/pigeon
int DevCtlServiceReg::createNode(zhandle_t *zkhandle, const char * path, int flags) {

    char path_buffer[512];  
    int bufferlen=sizeof(path_buffer); 
    int ret = zoo_exists(zkhandle, path,0,NULL);
    if(ret != ZOK){
        ret = zoo_create(zkhandle,path, NULL,0,&ZOO_OPEN_ACL_UNSAFE, flags, path_buffer,bufferlen);
        LOG(TRACE)<<"path_buffer:"<<path_buffer;
        mNodeRealPath = path_buffer;
        if(ret != ZOK){
            LOG(ERROR)<<"Error when create path :"<<path<<" retcode:"<<ret;
            return -1;  
        }

        return 0;
    }
    else {
        return 0;
    }
}
コード例 #25
0
ファイル: zk.cpp プロジェクト: nakj/jubatus
void zk::create(const std::string& path, const std::string& payload, bool ephemeral) {
    scoped_lock lk(m_);
    int rc = zoo_create(zh_, path.c_str(), payload.c_str(), payload.length(),
                        &ZOO_OPEN_ACL_UNSAFE,
                        ((ephemeral)?ZOO_EPHEMERAL:0), // | ZOO_SEQUENCE
                        NULL, 0);
    if(ephemeral) {
        if(rc != ZOK) {
            LOG(ERROR) << path << " failed in creation:" << zerror(rc);
            throw JUBATUS_EXCEPTION(jubatus::exception::runtime_error("failed to create zk empheral node")
                                    << jubatus::exception::error_message(std::string("zerror: ") + zerror(rc))
                                    << jubatus::exception::error_api_func("zoo_create")
                                    << jubatus::exception::error_file_name(path));
        }
    } else {
        if(rc != ZOK && rc != ZNODEEXISTS) {
            LOG(ERROR) << path << " failed in creation " << rc << " " << zerror(rc);
        }
    }
};
コード例 #26
0
ファイル: platanos.c プロジェクト: xekoukou/DocGraph
void
platanos_register (zhandle_t * zh, char *octopus, char *comp_name,
                   char *res_name, char *bind_point, oconfig_t * config)
{
    char path[1000];
    char bind_location[1000];
    int port = oconfig_incr_port (config);
    sprintf (bind_location, "tcp://%s:%d", bind_point, port);
    sprintf (path, "/%s/computers/%s/worker_nodes/%s/bind_point", octopus,
             comp_name, res_name);
    int result = zoo_create (zh, path, bind_location,
                             strlen (bind_location) + 1, &ZOO_OPEN_ACL_UNSAFE,
                             0, NULL, 0);


    assert (ZOK == result);



}
コード例 #27
0
ファイル: ZkClient.cpp プロジェクト: project-zerus/brood
void
ZkClient::createEphemeral(
    const folly::fbstring& path,
    const folly::fbstring& data) {
    zhandle_t* zhandle = zHandle_.get();
    CHECK(nullptr != zhandle) << "zhandle is NULL";
    int code = zoo_create(
                   zhandle,
                   path.c_str(),
                   data.data(),
                   data.length(),
                   &ZOO_READ_ACL_UNSAFE,
                   ZOO_EPHEMERAL,
                   nullptr,
                   0
               );
    CHECK(ZOK == code)
            << "zoo_acreate() failed with error: "
            << zooErrorCodeToString(code);
}
コード例 #28
0
/* {{{ Zookeeper::create( .. )
   */
static PHP_METHOD(Zookeeper, create)
{
	char *path, *value = NULL;
	int path_len, value_len;
	zval *acl_info = NULL;
	long flags = 0;
	char *realpath;
	int realpath_max = 0;
	struct ACL_vector aclv = { 0, };
	int status = ZOK;
	ZK_METHOD_INIT_VARS;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss!a!|l", &path, &path_len,
							  &value, &value_len, &acl_info, &flags) == FAILURE) {
		return;
	}

	ZK_METHOD_FETCH_OBJECT;

	realpath_max = path_len + 1;
	if (flags & ZOO_SEQUENCE) {
		// allocate extra space for sequence numbers
		realpath_max += 11;
	}
	realpath = emalloc(realpath_max);

	if (value == NULL) {
		value_len = -1;
	}

	php_parse_acl_list(acl_info, &aclv);
	status = zoo_create(i_obj->zk, path, value, value_len, (acl_info ? &aclv : 0), flags,
						realpath, realpath_max);
	if (status != ZOK) {
		efree(realpath);
		php_error_docref(NULL TSRMLS_CC, E_WARNING, "error: %s", zerror(status));
		return;
	}

	RETURN_STRING(realpath, 0);
}
コード例 #29
0
ファイル: zk.cpp プロジェクト: Tukamotosan/jubatus
bool zk::create(const string& path, const string& payload, bool ephemeral) {
  scoped_lock lk(m_);
  int rc = zoo_create(zh_, path.c_str(), payload.c_str(), payload.length(),
                      &ZOO_OPEN_ACL_UNSAFE,
                      ((ephemeral) ? ZOO_EPHEMERAL : 0),  // | ZOO_SEQUENCE
                      NULL, 0);
  if (ephemeral) {
    if (rc != ZOK) {
      LOG(ERROR) << "failed to create: " << path << " - " << zerror(rc);
      return false;
    }
  } else {
    if (rc != ZOK && rc != ZNODEEXISTS) {
      LOG(ERROR) << "failed to create: " << path << " - " << zerror(rc);
      return false;
    }
  }

  DLOG(INFO) << __func__ << " " << path;
  return true;
}
コード例 #30
0
void create(zhandle_t* zkHandler, const std::string strPath, const std::string& strNodeName)
{
	std::cout << "[Create node in sync mode...]\n";

	char path_buffer[64];
	int bufferlen = sizeof(path_buffer);
	int flag = zoo_create(zkHandler, 
			strPath.c_str(), strNodeName.c_str(), strNodeName.size(),
			&ZOO_OPEN_ACL_UNSAFE, 0,
			path_buffer, bufferlen
			);
	if (flag != ZOK)
	{
		fprintf(stderr, "Node '%s' create failed.\n", strNodeName.c_str());
		exit(EXIT_FAILURE);
	}
	else
	{
		printf("Node '%s' created OK!\n", path_buffer);
	}

}