Beispiel #1
0
int
main()
{
	struct pbc_slice slice;
	read_file("addressbook.pb", &slice);
	if (slice.buffer == NULL)
		return 1;
	struct pbc_env * env = pbc_new();
	pbc_register(env, &slice);

	free(slice.buffer);

	struct pbc_wmessage *msg = test_wmessage(env);

	pbc_wmessage_buffer(msg, &slice);

	dump(slice.buffer, slice.len);

	test_rmessage(env, &slice);

	pbc_wmessage_delete(msg);
	pbc_delete(env);

	return 0;
}
Beispiel #2
0
void testOldWrite()
{
	struct pbc_slice slice;
	read_file("addressbooknew.pb", &slice); //ClientSvrMsg
	//read_file("ClientSvrMsg.pb", &slice); //ClientSvrMsg
	if (slice.buffer == NULL)
		return 1;
	struct pbc_env * env = pbc_new();
	int r = pbc_register(env, &slice);
	if (r) {
		printf("Error : %s", pbc_error(env));
		return 1;
	}

	free(slice.buffer);

	struct pbc_wmessage *msg = test_wmessage(env);
	//struct pbc_wmessage *msg = test_ClientSevermessage(env);
	pbc_wmessage_buffer(msg, &slice);
	dump(slice.buffer, slice.len);
	FILE* f = fopen("test.bin", "wb");
	fwrite(slice.buffer, slice.len, 1, f);
	fclose(f);
	f = NULL;
}
Beispiel #3
0
static int
_wmessage_buffer_string(lua_State *L) {
	struct pbc_slice slice;
	struct pbc_wmessage * m = (struct pbc_wmessage *)checkuserdata(L,1);
	pbc_wmessage_buffer(m , &slice);
	lua_pushlstring(L, (const char *)slice.buffer, slice.len);
	return 1;
}
/*
 * generate query container state request
 */
static int generate_query_container_state_request(
    char** buffer,
    int* size,
    hadoop_rpc_proxy_t* proxy,
    int container_id) {

    int rc;
    struct pbc_wmessage* req = pbc_wmessage_new(env, "GetContainerStatusRequestProto");
    if (!req) {
        opal_output(0, "get GetContainerStatusRequestProto message failed.\n");
        return -1;
    }

    // set container_id
    struct pbc_wmessage* id_proto = pbc_wmessage_message(req, "container_id");
    if (!id_proto) {
        opal_output(0, "get ContainerIdProto from ContainerLaunchContextProto failed.\n");
        pbc_wmessage_delete(req);
        return -1;
    }
    rc = pbc_wmessage_integer(id_proto, "id", container_id, NULL);
    if (0 != rc) {
        opal_output(0, "pack container-id failed.\n");
        pbc_wmessage_delete(req);
        return -1;
    }
    rc = set_app_attempt_id(id_proto, "app_attempt_id", proxy);
    if (0 != rc) {
        opal_output(0, "pack app_attempt_id failed.\n");
        pbc_wmessage_delete(req);
        return -1;
    }
    rc = set_app_id(id_proto, "app_id", proxy);
    if (0 != rc) {
        opal_output(0, "pack app_id failed.\n");
        pbc_wmessage_delete(req);
        return -1;
    }

    struct pbc_slice slice;
    pbc_wmessage_buffer(req, &slice);

    /* try to create HadoopRpcRequestProto */
    rc = generate_hadoop_request((const char*)(slice.buffer),
        slice.len,
        CONTAINER_MANAGER_PROTOCOL_NAME,
        GET_CONTAINER_STATUS_METHOD_NAME,
        buffer,
        size);
    if (0 != rc) {
        opal_output(0, "create HadoopRpcRequestProto failed.\n");
        pbc_wmessage_delete(req);
        return -1;
    }

    pbc_wmessage_delete(req);
    return 0;
}
Beispiel #5
0
static int
_wmessage_buffer(lua_State *L) {
	struct pbc_slice slice;
	struct pbc_wmessage * m = (struct pbc_wmessage *)checkuserdata(L,1);
	pbc_wmessage_buffer(m , &slice);
	lua_pushlightuserdata(L, slice.buffer);
	lua_pushinteger(L, slice.len);
	return 2;
}
Beispiel #6
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);
}
Beispiel #7
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);
	} 
}
Beispiel #8
0
int
main()
{
	struct pbc_slice slice;
	read_file("performance.pb", &slice);
	if (slice.buffer == NULL)
		return 1;
	struct pbc_env * env = pbc_new();
	int r = pbc_register(env, &slice);
	if (r) {
		printf("Error : %s", pbc_error(env));
		return 1;
	}

	free(slice.buffer);

	clock_t start = clock();
	int i;
	for ( i = 0;i < 1000000;i ++ )
	{
		struct pbc_wmessage *msg = test_wmessage(env);

		pbc_wmessage_buffer(msg, &slice);

		//dump(slice.buffer, slice.len);

		//test_rmessage(env, &slice);

		//if ( i == 100000 - 1) test_rmessage(env, &slice);
		pbc_wmessage_delete(msg);
	}

	clock_t t = clock() - start;
	printf( "time cost %f\n", ((float)t)/CLOCKS_PER_SEC );

	pbc_delete(env);

	return 0;
}
/**
 * generate launch container PB request
     message ContainerLaunchContextProto {
      optional ContainerIdProto container_id = 1;
      optional string user = 2;
      optional ResourceProto resource = 3;
      repeated StringLocalResourceMapProto localResources = 4;
      optional bytes container_tokens = 5;
      repeated StringBytesMapProto service_data = 6;
      repeated StringStringMapProto environment = 7;
      repeated string command = 8;
      repeated ApplicationACLMapProto application_ACLs = 9;
    }

    message StartContainerRequestProto {
      optional ContainerLaunchContextProto container_launch_context = 1;
    }
 */
static int generate_launch_container_request(
        char** buffer,
        int* size,
        hadoop_rpc_proxy_t* proxy,
        int container_id,
        containers_launch_context_t* launch_context) {
    int rc;
    struct pbc_wmessage* req = pbc_wmessage_new(env, "StartContainerRequestProto");
    if (!req) {
        opal_output(0, "get StartContainerRequestProto message failed.\n");
        return -1;
    }

    struct pbc_wmessage* ctx = pbc_wmessage_message(req, "container_launch_context");
    if (!ctx) {
        opal_output(0, "get container_launch_context from StartContainerRequestProto failed.\n");
        pbc_wmessage_delete(req);
        return -1;
    }

    // set container_id
    struct pbc_wmessage* id_proto = pbc_wmessage_message(ctx, "container_id");
    if (!id_proto) {
        opal_output(0, "get ContainerIdProto from ContainerLaunchContextProto failed.\n");
        pbc_wmessage_delete(req);
        return -1;
    }
    rc = pbc_wmessage_integer(id_proto, "id", container_id, NULL);
    if (0 != rc) {
        opal_output(0, "pack container-id failed.\n");
        pbc_wmessage_delete(req);
        return -1;
    }
    rc = set_app_attempt_id(id_proto, "app_attempt_id", proxy);
    if (0 != rc) {
        opal_output(0, "pack app_attempt_id failed.\n");
        pbc_wmessage_delete(req);
        return -1;
    }
    rc = set_app_id(id_proto, "app_id", proxy);
    if (0 != rc) {
        opal_output(0, "pack app_id failed.\n");
        pbc_wmessage_delete(req);
        return -1;
    }

    // pack user
    rc = pbc_wmessage_string(ctx, "user", getlogin(), 0);
    if (rc != 0) {
        opal_output(0, "pack user name failed.\n");
        return -1;
    }

    // pack resource
    struct pbc_wmessage* res_msg = pbc_wmessage_message(ctx, "resource");
    if (!res_msg) {
        opal_output(0, "get resource_proto from context failed.\n");
        return -1;
    }
    rc = pbc_wmessage_integer(res_msg, "memory", launch_context->resource.memory_per_slot, NULL);
    if (rc != 0) {
        pbc_wmessage_delete(req);
        opal_output(0, "pack memory to resource failed.\n");
        return -1;
    }
    // TODO, in 2.0.3, need pack cpu

    // pack localResources
    rc = set_local_resources(ctx, "localResources");
    if (rc != 0) {
        pbc_wmessage_delete(req);
        opal_output(0, "pack local resources failed.\n");
        return -1;
    }

    // pack env
    int offset = 0;
    if (launch_context->env) {
        while (launch_context->env[offset]) {
            struct pbc_wmessage* env_msg = pbc_wmessage_message(ctx, "environment");
            if (!env_msg) {
                pbc_wmessage_delete(req);
                opal_output(0, "get env message from context failed.\n");
                return -1;
            }

            char* key = get_env_key(launch_context->env[offset]);
            char* val = get_env_val(launch_context->env[offset]);
            if ((!key) || (!val)) {
                if (key) {
                    free(key);
                }
                if (val) {
                    free(val);
                }
                pbc_wmessage_delete(req);
                opal_output(0, "get env key or value failed, env=%s.\n", launch_context->env[offset]);
                return -1;
            }

            // pack key
            rc = pbc_wmessage_string(env_msg, "key", key, 0);
            free(key);
            if (rc != 0) {
                free(val);
                pbc_wmessage_delete(req);
                opal_output(0, "set key to environment failed.\n");
                return -1;
            }
            // pack val
            rc = pbc_wmessage_string(env_msg, "value", val, 0);
            if (rc != 0) {
                free(val);
                pbc_wmessage_delete(req);
                opal_output(0, "set value to environment failed.\n");
                return -1;
            }
            free(val);
            offset++;
        }
    }

    // pack $PATH, $LD_LIBRARY_PATH, $DYLD_LIBRARY_PATH, $CLASSPATH to env
    if (0 != (rc = pack_env_to_launch_ctx("PATH", ctx))) {
        pbc_wmessage_delete(req);
        return -1;
    }
    if (0 != (rc = pack_env_to_launch_ctx("LD_LIBRARY_PATH", ctx))) {
        pbc_wmessage_delete(req);
        return -1;
    }
    if (0 != (rc = pack_env_to_launch_ctx("DYLD_LIBRARY_PATH", ctx))) {
        pbc_wmessage_delete(req);
        return -1;
    }
    if (0 != (rc = pack_env_to_launch_ctx("CLASSPATH", ctx))) {
        pbc_wmessage_delete(req);
        return -1;
    }

    // pack command
    char* command = concat_argv_to_cmd(launch_context->argv);
    if (!command) {
        pbc_wmessage_delete(req);
        opal_output(0, "concat argv to command to command failed. argv[0]:%s.\n", launch_context->argv[0]);
        return -1;
    }
    rc = pbc_wmessage_string(ctx, "command", command, 0);
    free(command);
    if (rc != 0) {
        opal_output(0, "pack command to context failed.\n");
        pbc_wmessage_delete(req);
        return -1;
    }

    struct pbc_slice slice;
    pbc_wmessage_buffer(req, &slice);

    /* try to create HadoopRpcRequestProto */
    rc = generate_hadoop_request((const char*)(slice.buffer),
        slice.len,
        CONTAINER_MANAGER_PROTOCOL_NAME,
        START_CONTAINER_METHOD_NAME,
        buffer,
        size);
    if (0 != rc) {
        opal_output(0, "create HadoopRpcRequestProto failed.\n");
        pbc_wmessage_delete(req);
        return -1;
    }

    pbc_wmessage_delete(req);
    return 0;
}