/* * get list of data nodes' rest servers, * and choose one (based on modulo segment id). * if pxf_isilon is true, there are no PXF instances on the datanodes. * TODO: add locality */ PxfServer* get_pxf_server(GPHDUri* gphd_uri, const Relation rel) { ClientContext client_context; /* holds the communication info */ PxfInputData inputData = {0}; List *rest_servers = NIL; ListCell *rest_server_c = NULL; PxfServer *found_server = NULL; PxfServer *ret_server = (PxfServer*)palloc0(sizeof(PxfServer)); char *server_ip = NULL; int server_index = 0; Assert(gphd_uri); /* init context */ init_client_context(&client_context); client_context.http_headers = churl_headers_init(); /* set HTTP header that guarantees response in JSON format */ churl_headers_append(client_context.http_headers, REST_HEADER_JSON_RESPONSE, NULL); if (!client_context.http_headers) { return NULL; } /* * Enrich the curl HTTP header */ inputData.headers = client_context.http_headers; inputData.gphduri = gphd_uri; inputData.rel = rel; inputData.filterstr = NULL; /* We do not supply filter data to the HTTP header */ add_delegation_token(&inputData); build_http_header(&inputData); int port = atoi(gphd_uri->port); if (!pxf_isilon) { /* send request */ rest_servers = get_datanode_rest_servers(gphd_uri, &client_context); foreach(rest_server_c, rest_servers) { PxfServer *rest_server = (PxfServer*)lfirst(rest_server_c); /* In case there are several rest servers on the same host, we assume * there are multiple DN residing together. * The port is incremented by one, to match singlecluster convention */ if (pxf_service_singlecluster) { if (server_ip == NULL) { server_ip = rest_server->host; } else if (are_ips_equal(server_ip, rest_server->host)) { port++; } } rest_server->port = port; }
/* * Add key/value pairs to connection header. * These values are the context of the query and used * by the remote component. */ void add_querydata_to_http_header(gphadoop_context* context, PG_FUNCTION_ARGS) { PxfInputData inputData = {0}; inputData.headers = context->churl_headers; inputData.gphduri = context->gphd_uri; inputData.rel = EXTPROTOCOL_GET_RELATION(fcinfo); inputData.filterstr = serializePxfFilterQuals(EXTPROTOCOL_GET_SCANQUALS(fcinfo)); add_delegation_token(&inputData); build_http_header(&inputData); free_token_resources(&inputData); }
void test__build_http_header__remote_login_is_null(void **state) { expect_external_vars(); expect_churl_headers("X-GP-SEGMENT-ID", mock_extvar->GP_SEGMENT_ID); expect_churl_headers("X-GP-SEGMENT-COUNT", mock_extvar->GP_SEGMENT_COUNT); expect_churl_headers("X-GP-XID", mock_extvar->GP_XID); expect_churl_headers_alignment(); expect_churl_headers("X-GP-URL-HOST", gphd_uri->host); expect_churl_headers("X-GP-URL-PORT", gphd_uri->port); expect_churl_headers("X-GP-DATA-DIR", gphd_uri->data); expect_churl_headers("X-GP-URI", gphd_uri->uri); expect_churl_headers("X-GP-HAS-FILTER", "0"); build_http_header(input_data); }
void send_get_answer(int fd) { int size; char * buf = NULL; /*On recuper le fichier sous forme de chaine de cara*/ file_to_buffer("catalogue.txt", &buf, &size); /*On construit l'entete HTML aproprié*/ char * header = build_http_header("text/plain", size); /*Et on envoie les données*/ puts("Going to send"); send(fd, header, strlen(header), MSG_MORE); printf("send : %s\n", strerror(errno)); send(fd, buf, size, 0); printf("send : %s\n", strerror(errno)); /*On libere les ressources alloué*/ free(header); free(buf); }
/* * Add key/value pairs to connection header. * These values are the context of the query and used * by the remote component. */ void add_querydata_to_http_header(gphadoop_context* context, PG_FUNCTION_ARGS) { PxfInputData inputData = {0}; inputData.headers = context->churl_headers; inputData.gphduri = context->gphd_uri; inputData.rel = EXTPROTOCOL_GET_RELATION(fcinfo); inputData.quals = EXTPROTOCOL_GET_SCANQUALS(fcinfo); inputData.filterstr = serializePxfFilterQuals(EXTPROTOCOL_GET_SCANQUALS(fcinfo)); if (EXTPROTOCOL_GET_SELECTDESC(fcinfo)) { inputData.proj_info = EXTPROTOCOL_GET_PROJINFO(fcinfo); int agg_type = EXTPROTOCOL_GET_AGG_TYPE(fcinfo); if (agg_type) { inputData.agg_type = agg_type; } } add_delegation_token(&inputData); build_http_header(&inputData); free_token_resources(&inputData); }
void test__build_http_header__remote_credentials_are_not_null(void **state) { expect_external_vars(); expect_churl_headers("X-GP-SEGMENT-ID", mock_extvar->GP_SEGMENT_ID); expect_churl_headers("X-GP-SEGMENT-COUNT", mock_extvar->GP_SEGMENT_COUNT); expect_churl_headers("X-GP-XID", mock_extvar->GP_XID); expect_churl_headers_alignment(); expect_churl_headers("X-GP-URL-HOST", gphd_uri->host); expect_churl_headers("X-GP-URL-PORT", gphd_uri->port); expect_churl_headers("X-GP-DATA-DIR", gphd_uri->data); expect_churl_headers("X-GP-URI", gphd_uri->uri); expect_churl_headers("X-GP-HAS-FILTER", "0"); pxf_remote_service_login = "******"; expect_churl_headers("X-GP-REMOTE-USER", pxf_remote_service_login); pxf_remote_service_secret = "password"; expect_churl_headers("X-GP-REMOTE-PASS", pxf_remote_service_secret); build_http_header(input_data); }