Skip to content

Commit

Permalink
Automated Code Change
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 660285776
  • Loading branch information
tensorflower-gardener committed Aug 7, 2024
1 parent fd11379 commit 37a7a85
Show file tree
Hide file tree
Showing 30 changed files with 557 additions and 529 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ class AuthProvider {
/// \brief Returns the short-term authentication bearer token.
///
/// Safe for concurrent use by multiple threads.
virtual Status GetToken(string* t) = 0;
virtual absl::Status GetToken(string* t) = 0;

static Status GetToken(AuthProvider* provider, string* token) {
static absl::Status GetToken(AuthProvider* provider, string* token) {
if (!provider) {
return errors::Internal("Auth provider is required.");
}
Expand All @@ -44,9 +44,9 @@ class AuthProvider {
/// No-op auth provider, which will only work for public objects.
class EmptyAuthProvider : public AuthProvider {
public:
Status GetToken(string* token) override {
absl::Status GetToken(string* token) override {
*token = "";
return OkStatus();
return absl::OkStatus();
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ ComputeEngineMetadataClient::ComputeEngineMetadataClient(
: http_request_factory_(std::move(http_request_factory)),
retry_config_(config) {}

Status ComputeEngineMetadataClient::GetMetadata(
absl::Status ComputeEngineMetadataClient::GetMetadata(
const string& path, std::vector<char>* response_buffer) {
const auto get_metadata_from_gce = [path, response_buffer, this]() {
string metadata_url;
Expand All @@ -56,7 +56,7 @@ Status ComputeEngineMetadataClient::GetMetadata(
request->AddHeader("Metadata-Flavor", "Google");
request->SetResultBuffer(response_buffer);
TF_RETURN_IF_ERROR(request->Send());
return OkStatus();
return absl::OkStatus();
};

return RetryingUtils::CallWithRetries(get_metadata_from_gce, retry_config_);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ class ComputeEngineMetadataClient {
/// To get the zone of an instance:
/// compute_engine_metadata_client.GetMetadata(
/// "instance/zone", response_buffer);
virtual Status GetMetadata(const string& path,
std::vector<char>* response_buffer);
virtual absl::Status GetMetadata(const string& path,
std::vector<char>* response_buffer);

private:
std::shared_ptr<HttpRequest::Factory> http_request_factory_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ ComputeEngineZoneProvider::ComputeEngineZoneProvider(
std::shared_ptr<ComputeEngineMetadataClient> google_metadata_client)
: google_metadata_client_(std::move(google_metadata_client)) {}

Status ComputeEngineZoneProvider::GetZone(string* zone) {
absl::Status ComputeEngineZoneProvider::GetZone(string* zone) {
if (!cached_zone.empty()) {
*zone = cached_zone;
return OkStatus();
return absl::OkStatus();
}
std::vector<char> response_buffer;
TF_RETURN_IF_ERROR(google_metadata_client_->GetMetadata(kGceMetadataZonePath,
&response_buffer));
StringPiece location(&response_buffer[0], response_buffer.size());
absl::string_view location(&response_buffer[0], response_buffer.size());

std::vector<string> elems = str_util::Split(location, "/");
if (elems.size() == 4) {
Expand All @@ -47,7 +47,7 @@ Status ComputeEngineZoneProvider::GetZone(string* zone) {
<< string(location);
}

return OkStatus();
return absl::OkStatus();
}
ComputeEngineZoneProvider::~ComputeEngineZoneProvider() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class ComputeEngineZoneProvider : public ZoneProvider {
std::shared_ptr<ComputeEngineMetadataClient> google_metadata_client);
virtual ~ComputeEngineZoneProvider();

Status GetZone(string* zone) override;
absl::Status GetZone(string* zone) override;

private:
std::shared_ptr<ComputeEngineMetadataClient> google_metadata_client_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,8 @@ void CurlHttpRequest::SetDeleteRequest() {
libcurl_->curl_easy_setopt(curl_, CURLOPT_CUSTOMREQUEST, "DELETE"));
}

Status CurlHttpRequest::SetPutFromFile(const string& body_filepath,
size_t offset) {
absl::Status CurlHttpRequest::SetPutFromFile(const string& body_filepath,
size_t offset) {
CheckNotSent();
CheckMethodNotSet();
is_method_set_ = true;
Expand All @@ -257,7 +257,7 @@ Status CurlHttpRequest::SetPutFromFile(const string& body_filepath,
reinterpret_cast<void*>(put_body_)));
// Using the default CURLOPT_READFUNCTION, which is doing an fread() on the
// FILE * userdata set with CURLOPT_READDATA.
return OkStatus();
return absl::OkStatus();
}

void CurlHttpRequest::SetPutEmptyBody() {
Expand Down Expand Up @@ -286,7 +286,7 @@ void CurlHttpRequest::SetPostFromBuffer(const char* buffer, size_t size) {
reinterpret_cast<void*>(this)));
CHECK_CURL_OK(libcurl_->curl_easy_setopt(curl_, CURLOPT_READFUNCTION,
&CurlHttpRequest::ReadCallback));
post_body_buffer_ = StringPiece(buffer, size);
post_body_buffer_ = absl::string_view(buffer, size);
}

void CurlHttpRequest::SetPostEmptyBody() {
Expand Down Expand Up @@ -397,8 +397,8 @@ size_t CurlHttpRequest::HeaderCallback(const void* ptr, size_t size,
size_t nmemb, void* this_object) {
CHECK(ptr);
auto that = reinterpret_cast<CurlHttpRequest*>(this_object);
StringPiece header(reinterpret_cast<const char*>(ptr), size * nmemb);
StringPiece name, value;
absl::string_view header(reinterpret_cast<const char*>(ptr), size * nmemb);
absl::string_view name, value;
// The supplied header has the form "<name>: <value>", parse it.
if (strings::Scanner(header)
.ScanEscapedUntil(':')
Expand All @@ -412,7 +412,7 @@ size_t CurlHttpRequest::HeaderCallback(const void* ptr, size_t size,
return size * nmemb;
}

Status CurlHttpRequest::Send() {
absl::Status CurlHttpRequest::Send() {
CheckNotSent();
CHECK(is_uri_set_) << "URI has not been set.";

Expand Down Expand Up @@ -457,7 +457,7 @@ Status CurlHttpRequest::Send() {
auto get_error_message = [this]() -> string {
string error_message = strings::StrCat(
"Error executing an HTTP request: HTTP response code ", response_code_);
StringPiece body = GetResponse();
absl::string_view body = GetResponse();
if (!body.empty()) {
return strings::StrCat(
error_message, " with body '",
Expand All @@ -466,15 +466,15 @@ Status CurlHttpRequest::Send() {
return error_message;
};

Status result;
absl::Status result;
switch (response_code_) {
// The group of response codes indicating that the request achieved
// the expected goal.
case 200: // OK
case 201: // Created
case 204: // No Content
case 206: // Partial Content
result = OkStatus();
result = absl::OkStatus();
break;

case 416: // Requested Range Not Satisfiable
Expand All @@ -485,7 +485,7 @@ Status CurlHttpRequest::Send() {
if (IsDirectResponse()) {
direct_response_.bytes_transferred_ = 0;
}
result = OkStatus();
result = absl::OkStatus();
break;

// INVALID_ARGUMENT indicates a problem with how the request is constructed.
Expand Down Expand Up @@ -556,13 +556,14 @@ void CurlHttpRequest::CheckNotSent() const {
CHECK(!is_sent_) << "The request has already been sent.";
}

StringPiece CurlHttpRequest::GetResponse() const {
StringPiece response;
absl::string_view CurlHttpRequest::GetResponse() const {
absl::string_view response;
if (IsDirectResponse()) {
response = StringPiece(direct_response_.buffer_,
direct_response_.bytes_transferred_);
response = absl::string_view(direct_response_.buffer_,
direct_response_.bytes_transferred_);
} else {
response = StringPiece(response_buffer_->data(), response_buffer_->size());
response =
absl::string_view(response_buffer_->data(), response_buffer_->size());
}
return response;
}
Expand Down Expand Up @@ -627,10 +628,10 @@ int CurlHttpRequest::ProgressCallback(void* this_object, curl_off_t dltotal,
return 0;
}

Status CurlHttpRequest::CURLcodeToStatus(CURLcode code,
const char* error_buffer) {
absl::Status CurlHttpRequest::CURLcodeToStatus(CURLcode code,
const char* error_buffer) {
if (code == CURLE_OK) {
return OkStatus();
return absl::OkStatus();
}
string error_message = strings::StrCat(
"Error executing an HTTP request: libcurl code ", code, " meaning '",
Expand All @@ -648,7 +649,7 @@ Status CurlHttpRequest::CURLcodeToStatus(CURLcode code,
// a response body (e.g. GCS sends one with an error message) but we
// pretend as though they don't, so actually ignore this error.
if (get_response_result == CURLE_OK && response_code == 416) {
return OkStatus();
return absl::OkStatus();
}
return errors::FailedPrecondition(
strings::StrCat(error_message, overflow_message));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ class CurlHttpRequest : public HttpRequest {
///
/// The request body will be taken from the specified file starting from
/// the given offset.
Status SetPutFromFile(const string& body_filepath, size_t offset) override;
absl::Status SetPutFromFile(const string& body_filepath,
size_t offset) override;

/// Makes the request a PUT request with an empty body.
void SetPutEmptyBody() override;
Expand Down Expand Up @@ -140,7 +141,7 @@ class CurlHttpRequest : public HttpRequest {
///
/// If the result buffer was defined, the response will be written there.
/// The object is not designed to be re-used after Send() is executed.
Status Send() override;
absl::Status Send() override;

// Url encodes str and returns a new string.
string EscapeString(const string& str) override;
Expand All @@ -167,18 +168,18 @@ class CurlHttpRequest : public HttpRequest {
curl_off_t ulnow);
void CheckMethodNotSet() const;
void CheckNotSent() const;
StringPiece GetResponse() const;
absl::string_view GetResponse() const;

/// Helper to convert the given CURLcode and error buffer, representing the
/// result of performing a transfer, into a Status with an error message.
Status CURLcodeToStatus(CURLcode code, const char* error_buffer);
absl::Status CURLcodeToStatus(CURLcode code, const char* error_buffer);

LibCurl* libcurl_;
Env* env_;

FILE* put_body_ = nullptr;

StringPiece post_body_buffer_;
absl::string_view post_body_buffer_;
size_t post_body_read_ = 0;

std::vector<char>* response_buffer_ = nullptr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ class FakeLibCurl : public LibCurl {
posted_content_ = "";
do {
bytes_read = read_callback_(buffer, 1, sizeof(buffer), read_data_);
posted_content_ =
strings::StrCat(posted_content_, StringPiece(buffer, bytes_read));
posted_content_ = strings::StrCat(
posted_content_, absl::string_view(buffer, bytes_read));
} while (bytes_read > 0);
}
if (write_data_ || write_callback_) {
Expand Down Expand Up @@ -366,7 +366,7 @@ TEST(CurlHttpRequestTest, GetRequest_Direct_ResponseTooLarge) {

http_request.SetUri("http://www.testuri.com");
http_request.SetResultBufferDirect(scratch.data(), scratch.size());
const Status& status = http_request.Send();
const absl::Status& status = http_request.Send();
EXPECT_EQ(error::FAILED_PRECONDITION, status.code());
EXPECT_EQ(
"Error executing an HTTP request: libcurl code 23 meaning "
Expand Down Expand Up @@ -770,7 +770,7 @@ class TestStats : public HttpRequest::RequestStats {

void RecordResponse(const HttpRequest* request, const string& uri,
HttpRequest::RequestMethod method,
const Status& result) override {
const absl::Status& result) override {
has_recorded_response_ = true;
record_response_request_ = request;
record_response_uri_ = uri;
Expand All @@ -787,7 +787,7 @@ class TestStats : public HttpRequest::RequestStats {
string record_response_uri_ = "http://www.testuri.com";
HttpRequest::RequestMethod record_response_method_ =
HttpRequest::RequestMethod::kGet;
Status record_response_result_;
absl::Status record_response_result_;

bool has_recorded_request_ = false;
bool has_recorded_response_ = false;
Expand Down Expand Up @@ -864,7 +864,7 @@ TEST(CurlHttpRequestTest, StatsGetNotFound) {
http_request.AddAuthBearerHeader("fake-bearer");
http_request.SetRange(100, 199);
http_request.SetResultBuffer(&scratch);
Status s = http_request.Send();
absl::Status s = http_request.Send();

// Check interaction with stats.
ASSERT_TRUE(stats.has_recorded_request_);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ class ExpiringLRUCache {
return LookupLocked(key, value);
}

typedef std::function<Status(const string&, T*)> ComputeFunc;
typedef std::function<absl::Status(const string&, T*)> ComputeFunc;

/// Look up the entry with key `key` and copy it to `value` if found. If not
/// found, call `compute_func`. If `compute_func` returns successfully, store
/// a copy of the output parameter in the cache, and another copy in `value`.
Status LookupOrCompute(const string& key, T* value,
const ComputeFunc& compute_func) {
absl::Status LookupOrCompute(const string& key, T* value,
const ComputeFunc& compute_func) {
if (max_age_ == 0) {
return compute_func(key, value);
}
Expand All @@ -88,9 +88,9 @@ class ExpiringLRUCache {
// key if this proves to be a significant performance bottleneck.
mutex_lock lock(mu_);
if (LookupLocked(key, value)) {
return OkStatus();
return absl::OkStatus();
}
Status s = compute_func(key, value);
absl::Status s = compute_func(key, value);
if (s.ok()) {
InsertLocked(key, *value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ TEST(ExpiringLRUCacheTest, LookupOrCompute) {
[&num_compute_calls](const string& key, int* value) {
*value = num_compute_calls;
num_compute_calls++;
return OkStatus();
return absl::OkStatus();
};
ExpiringLRUCache<int> cache1(0, 4);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ class FileBlockCache {
/// cache is constructed. The returned Status should be OK as long as the
/// read from the remote filesystem succeeded (similar to the semantics of the
/// read(2) system call).
typedef std::function<Status(const string& filename, size_t offset,
size_t buffer_size, char* buffer,
size_t* bytes_transferred)>
typedef std::function<absl::Status(const string& filename, size_t offset,
size_t buffer_size, char* buffer,
size_t* bytes_transferred)>
BlockFetcher;

virtual ~FileBlockCache() {}
Expand All @@ -91,8 +91,8 @@ class FileBlockCache {
/// placed in `out`.
/// 4) OK otherwise (i.e. the read succeeded, and at least one byte was placed
/// in `out`).
virtual Status Read(const string& filename, size_t offset, size_t n,
char* buffer, size_t* bytes_transferred) = 0;
virtual absl::Status Read(const string& filename, size_t offset, size_t n,
char* buffer, size_t* bytes_transferred) = 0;

// Validate the given file signature with the existing file signature in the
// cache. Returns true if the signature doesn't change or the file did not
Expand Down
Loading

0 comments on commit 37a7a85

Please sign in to comment.