1
0

hdfs_http_client.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. #ifndef _HDFS_HTTP_CLIENT_H_
  19. #define _HDFS_HTTP_CLIENT_H_
  20. #include "hdfs.h" /* for tSize */
  21. #include <pthread.h> /* for pthread_t */
  22. #include <unistd.h> /* for size_t */
  23. enum hdfsStreamType
  24. {
  25. UNINITIALIZED = 0,
  26. INPUT = 1,
  27. OUTPUT = 2,
  28. };
  29. /**
  30. * webhdfsBuffer - used for hold the data for read/write from/to http connection
  31. */
  32. typedef struct {
  33. const char *wbuffer; // The user's buffer for uploading
  34. size_t remaining; // Length of content
  35. size_t offset; // offset for reading
  36. int openFlag; // Check whether the hdfsOpenFile has been called before
  37. int closeFlag; // Whether to close the http connection for writing
  38. pthread_mutex_t writeMutex; // Synchronization between the curl and hdfsWrite threads
  39. pthread_cond_t newwrite_or_close; // Transferring thread waits for this condition
  40. // when there is no more content for transferring in the buffer
  41. pthread_cond_t transfer_finish; // Condition used to indicate finishing transferring (one buffer)
  42. } webhdfsBuffer;
  43. struct webhdfsFileHandle {
  44. char *absPath;
  45. int bufferSize;
  46. short replication;
  47. tSize blockSize;
  48. char *datanode;
  49. webhdfsBuffer *uploadBuffer;
  50. pthread_t connThread;
  51. };
  52. enum HttpHeader {
  53. GET,
  54. PUT,
  55. POST,
  56. DELETE
  57. };
  58. enum Redirect {
  59. YES,
  60. NO
  61. };
  62. typedef struct {
  63. char *content;
  64. size_t remaining;
  65. size_t offset;
  66. } ResponseBufferInternal;
  67. typedef ResponseBufferInternal *ResponseBuffer;
  68. /**
  69. * The response got through webhdfs
  70. */
  71. typedef struct {
  72. ResponseBuffer body;
  73. ResponseBuffer header;
  74. }* Response;
  75. ResponseBuffer initResponseBuffer();
  76. void freeResponseBuffer(ResponseBuffer buffer);
  77. void freeResponse(Response resp);
  78. Response launchMKDIR(char *url);
  79. Response launchRENAME(char *url);
  80. Response launchCHMOD(char *url);
  81. Response launchGFS(char *url);
  82. Response launchLS(char *url);
  83. Response launchDELETE(char *url);
  84. Response launchCHOWN(char *url);
  85. Response launchOPEN(char *url, Response resp);
  86. Response launchUTIMES(char *url);
  87. Response launchNnWRITE(char *url);
  88. Response launchDnWRITE(const char *url, webhdfsBuffer *buffer);
  89. Response launchNnAPPEND(char *url);
  90. Response launchSETREPLICATION(char *url);
  91. Response launchDnAPPEND(const char *url, webhdfsBuffer *buffer);
  92. #endif //_HDFS_HTTP_CLIENT_H_