Пример #1
0
static void
test_rmessage(struct pbc_env *env, struct pbc_slice *slice) {
	struct pbc_rmessage * m = pbc_rmessage_new(env, "tutorial.Person", slice);
	printf("name = %s\n", pbc_rmessage_string(m , "name" , 0 , NULL));
	printf("id = %d\n", pbc_rmessage_integer(m , "id" , 0 , NULL));
	printf("email = %s\n", pbc_rmessage_string(m , "email" , 0 , NULL));

	int phone_n = pbc_rmessage_size(m, "phone");
	int i;

	for (i=0;i<phone_n;i++) {
		struct pbc_rmessage * p = pbc_rmessage_message(m , "phone", i);
		printf("\tnumber[%d] = %s\n",i,pbc_rmessage_string(p , "number", i ,NULL));
		printf("\ttype[%d] = %s\n",i,pbc_rmessage_string(p, "type", i, NULL));
	}

	int n = pbc_rmessage_size(m , "test");

	for (i=0;i<n;i++) {
		printf("test[%d] = %d\n",i, pbc_rmessage_integer(m , "test" , i , NULL));
	}

	printf("tutorial.Ext.test = %d\n", pbc_rmessage_integer(m,"tutorial.Ext.test",0,NULL));
	pbc_rmessage_delete(m);
}
Пример #2
0
static void
test_rmessage(struct pbc_env *env, struct pbc_slice *slice) {
	struct pbc_rmessage * m = pbc_rmessage_new(env, "tutorial.Person", slice);
	if (m==NULL) {
		printf("Error : %s",pbc_error(env));
		return;
	}
	printf("name = %s\n", pbc_rmessage_string(m , "name" , 0 , NULL));
	printf("id = %d\n", pbc_rmessage_integer(m , "id" , 0 , NULL));
	printf("email = %s\n", pbc_rmessage_string(m , "email" , 0 , NULL));

	int phone_n = pbc_rmessage_size(m, "phone");
	int i;
	const char * field_name;
	pbc_type(env, "tutorial.Person", "phone", &field_name);
	printf("phone type [%s]\n",field_name);

	for (i=0;i<phone_n;i++) {
		struct pbc_rmessage * p = pbc_rmessage_message(m , "phone", i);
		printf("\tnumber[%d] = %s\n",i,pbc_rmessage_string(p , "number", i ,NULL));
		printf("\ttype[%d] = %s\n",i,pbc_rmessage_string(p, "type", i, NULL));
	}

	int n = pbc_rmessage_size(m , "test");

	for (i=0;i<n;i++) {
		printf("test[%d] = %d\n",i, pbc_rmessage_integer(m , "test" , i , NULL));
	}

	printf("tutorial.Ext.test = %d\n", pbc_rmessage_integer(m,"tutorial.Ext.test",0,NULL));
	pbc_rmessage_delete(m);
}
/**
 * launch a single container
 */
static int query_container_state_internal(hadoop_rpc_proxy_t* proxy, 
    int container_id,
    container_state_t* state,
    int* retval,
    char** diag_msg) {

    char* request = NULL;
    int request_len;
    int rc;

    rc = generate_query_container_state_request(&request, &request_len, proxy, container_id);
    if (0 != rc) {
        opal_output(0, "generate query_container_state_request failed.\n");
        return -1;
    }

    // send request
    rc = send_rpc_request(proxy, request, request_len);
    if (0 != rc) {
        opal_output(0, "send query_container_state_request failed.\n");
        free(request);
        return -1;
    }

    // now we will not use it anymore
    free(request);
    struct pbc_slice slice;

    // read response
    response_type_t response_type;
    response_type = recv_rpc_response(proxy, (char**)(&(slice.buffer)), &(slice.len));
    if (RESPONSE_SUCCEED == response_type) {
        // read response
        struct pbc_rmessage* rmsg = pbc_rmessage_new(env, "GetContainerStatusResponseProto", &slice);
        if (!rmsg) {
            opal_output(0, "deserialize GetContainerStatusResponseProto from buffer failed.\n");
            free(slice.buffer);
            return -1;
        }

        // get container status
        struct pbc_rmessage* status_msg = pbc_rmessage_message(rmsg, "status", 0);
        if (!status_msg) {
            opal_output(0, "get ContainerStatusProto from response failed.\n");
            return -1;
        }

        // read state
        *state = pbc_rmessage_integer(status_msg, "state", 0, NULL);
        *retval = pbc_rmessage_integer(status_msg, "exit_status", 0, NULL);

        pbc_rmessage_delete(rmsg);
        free(slice.buffer);
        return 0;
    } else {
        process_bad_rpc_response(proxy, response_type);
        return -1;
    }
}
Пример #4
0
static void
test_rmessage(struct pbc_env *env, struct pbc_slice *slice) {
	struct pbc_rmessage * m = pbc_rmessage_new(env, "real", slice);
	printf("f = %f\n", pbc_rmessage_real(m , "f" , 0 ));
	printf("d = %f\n", pbc_rmessage_real(m , "d" , 0 ));
	printf("e = %ld\n", pbc_rmessage_integer(m , "e" , 0,NULL ));
	pbc_rmessage_delete(m);
}
Пример #5
0
static void
test(struct pbc_env *env) {
	// int i;
	// for(i=0; i<COUNT; i++)
	// {
	// 		struct pbc_wmessage* w_msg = pbc_wmessage_new(env, "at");
	// 		struct pbc_rmessage* r_msg = NULL;
	// 		struct pbc_slice sl;
	// 		char buffer[1024];
	// 		sl.buffer = buffer, sl.len = 1024;
	// 		pbc_wmessage_integer(w_msg, "aa", 123, 0);
	// 		pbc_wmessage_integer(w_msg, "bb", 456, 0);
	// 		pbc_wmessage_string(w_msg, "cc", "test string!", 0);
	// 		pbc_wmessage_buffer(w_msg, &sl);

	// 		r_msg = pbc_rmessage_new(env, "at", &sl);

	// 		//===============
	// 		printf("aa = %d\n", pbc_rmessage_integer(r_msg, "aa", 0, NULL));
	// 		printf("bb = %d\n", pbc_rmessage_integer(r_msg, "bb", 0, NULL));
	// 		printf("cc = %s\n", pbc_rmessage_string(r_msg, "cc", 0, NULL));
	// 		//===============

	// 		pbc_rmessage_delete(r_msg);
	// 		pbc_wmessage_delete(w_msg);
	// }

	struct pbc_wmessage *w_msg = pbc_wmessage_new(env, "at");
	pbc_wmessage_integer(w_msg, "aa", 123, 0);
	pbc_wmessage_integer(w_msg, "bb", 456, 0); 
	pbc_wmessage_string(w_msg, "cc", "test string!", 0);

	struct pbc_slice slice;
	char buffer[1024];
	slice.len = 1024;
	slice.buffer = buffer;
	pbc_wmessage_buffer(w_msg, &slice);
	// pbc_wmessage_delete(w_msg);  //!!!!!!!! should not delete here

	struct pbc_rmessage *r_msg = pbc_rmessage_new(env, "at", &slice);
	printf("aa = %d\n", pbc_rmessage_integer(r_msg, "aa", 0, NULL));
	printf("bb = %d\n", pbc_rmessage_integer(r_msg, "bb", 0, NULL));
	printf("cc = %s\n", pbc_rmessage_string(r_msg, "cc", 0, NULL));

	pbc_rmessage_delete(r_msg);
	pbc_wmessage_delete(w_msg);
}
Пример #6
0
static void
dump(const char *proto, const char * message, struct pbc_slice *data) {
	struct pbc_env * env = pbc_new();
	struct pbc_slice pb;
	read_file(proto, &pb);
	int r = pbc_register(env, &pb);
	if (r!=0) {
		fprintf(stderr, "Can't register %s\n", proto);
		exit(1);
	}
	struct pbc_rmessage * m = pbc_rmessage_new(env , message , data);
	if (m == NULL) {
		fprintf(stderr, "Decode message %s fail\n",message);
		exit(1);
	}
	dump_message(m,0);
}
static int launch_container_internal(hadoop_rpc_proxy_t* proxy,
    containers_launch_context_t* launch_context, int container_id) {

    char* request = NULL;
    int request_len;
    int rc;

    rc = generate_launch_container_request(&request, &request_len, proxy, container_id, launch_context);
    if (0 != rc) {
        opal_output(0, "generate launch_container_request failed.\n");
        return -1;
    }

    // send request
    rc = send_rpc_request(proxy, request, request_len);
    if (0 != rc) {
        opal_output(0, "send launch_container_request failed.\n");
        free(request);
        return -1;
    }

    // now we will not use it anymore
    free(request);
    struct pbc_slice slice;

    // read response
    response_type_t response_type;
    response_type = recv_rpc_response(proxy, (char**)(&(slice.buffer)), &(slice.len));
    if (RESPONSE_SUCCEED == response_type) {
        // read response
        struct pbc_rmessage* rmsg = pbc_rmessage_new(env, "StartContainerResponseProto", &slice);
        if (!rmsg) {
            opal_output(0, "deserialize StartContainerResponseProto from buffer failed.\n");
            free(slice.buffer);
            return -1;
        }
        pbc_rmessage_delete(rmsg);
        free(slice.buffer);
        return 0;
    } else {
        process_bad_rpc_response(proxy, response_type);
        return -1;
    }
}
Пример #8
0
static int
_rmessage_new(lua_State *L) {
	struct pbc_env * env = (struct pbc_env *)checkuserdata(L,1);
	const char * type_name = luaL_checkstring(L,2);
	struct pbc_slice slice;
	if (lua_isstring(L,3)) {
		size_t sz = 0;
		slice.buffer = (void *)lua_tolstring(L,3,&sz);
		slice.len = (int)sz;
	} else {
		slice.buffer = lua_touserdata(L,3);
		slice.len = luaL_checkinteger(L,4);
	}
	struct pbc_rmessage * m = pbc_rmessage_new(env, type_name, &slice);
	if (m==NULL)
		return 0;
	lua_pushlightuserdata(L,m);
	return 1;
}
Пример #9
0
int
pbc_register(struct pbc_env * p, struct pbc_slice *slice) {
	//dump((uint8_t *)slice->buffer, slice->len);
	struct pbc_rmessage * message = pbc_rmessage_new(p, "google.protobuf.FileDescriptorSet", slice);
	if (message == NULL) {
		p->lasterror = "register open google.protobuf.FileDescriptorSet fail";
		return 1;
	}
	int n = pbc_rmessage_size(message, "file");

	struct pbc_rmessage ** files = (struct pbc_rmessage **)_pbcM_malloc(n*(sizeof(struct pbc_rmessage *)));
	int i;
    int r = n;
	if (n == 0) {
		p->lasterror = "register empty";
		goto _error;
	}
	for (i=0;i<n;i++) {
		files[i] = pbc_rmessage_message(message, "file", i);
		if (files[i] == NULL) {
			p->lasterror = "register open fail";
			goto _error;
		}
	}

	
	do {
		int rr = _register_no_dependency(p,files , n);
		if (rr == r) {
			p->lasterror = "register dependency error";
			goto _error;
		}
		r = rr;
	} while (r>0);

	pbc_rmessage_delete(message);
    free(files);
	return 0;
_error:
	pbc_rmessage_delete(message);
    free(files);
	return 1;
}
Пример #10
0
static void
test(struct pbc_env *env) {
	int i;
	for(i=0; i<COUNT; i++)
	{
			struct pbc_wmessage* w_msg = pbc_wmessage_new(env, "at");
			struct pbc_rmessage* r_msg = NULL;
			struct pbc_slice sl;
			char buffer[1024];
			sl.buffer = buffer, sl.len = 1024;
			pbc_wmessage_integer(w_msg, "aa", 123, 0);
			pbc_wmessage_integer(w_msg, "bb", 456, 0);
			pbc_wmessage_string(w_msg, "cc", "test string!", -1);
			pbc_wmessage_buffer(w_msg, &sl);
					
			r_msg = pbc_rmessage_new(env, "at", &sl);
			pbc_rmessage_delete(r_msg);
			pbc_wmessage_delete(w_msg);
	} 
}
Пример #11
0
static void
test_rmessage(struct pbc_env *env, struct pbc_slice *slice) {
	struct pbc_rmessage * m = pbc_rmessage_new(env, "test", slice);
	if (m==NULL) {
		printf("Error : %s",pbc_error(env));
		return;
	}

	int phone_n = pbc_rmessage_size(m, "el");
	int i;


	for (i=0;i<phone_n;i++) {
		struct pbc_rmessage * p = pbc_rmessage_message(m , "el", i);
		printf("\tint16_min[%d] = %d\n",i,pbc_rmessage_integer(p , "int16_min", i ,NULL));
		printf("\tdouble_max[%d] = %f\n",i,pbc_rmessage_real(p, "double_max", i));
		printf("\tstring[%d] = %s\n",i,pbc_rmessage_string(p, "str", i, NULL));
	}

	pbc_rmessage_delete(m);
}
Пример #12
0
int
pbc_register(struct pbc_env * p, struct pbc_slice *slice) {
	struct pbc_rmessage * message = pbc_rmessage_new(p, "google.protobuf.FileDescriptorSet", slice);
	if (message == NULL) {
		p->lasterror = "register open google.protobuf.FileDescriptorSet fail";
		return 1;
	}
	int n = pbc_rmessage_size(message, "file");
	struct pbc_rmessage * files[n];
	int i;
	if (n == 0) {
		p->lasterror = "register empty";
		goto _error;
	}
	for (i=0;i<n;i++) {
		files[i] = pbc_rmessage_message(message, "file", i);
		if (files[i] == NULL) {
			p->lasterror = "register open fail";
			goto _error;
		}
	}

	int r = n;
	do {
		int rr = _register_no_dependency(p,files , n);
		if (rr == r) {
			p->lasterror = "register dependency error";
			goto _error;
		}
		r = rr;
	} while (r>0);

	pbc_rmessage_delete(message);
	return 0;
_error:
	pbc_rmessage_delete(message);
	return 1;
}