Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#13190 - Improve URL handling for Airflow REST Client #14403

Merged
merged 5 commits into from
Dec 19, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fmt
pmbrull committed Dec 15, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 466c4bc1c561859e47ee723707660bc38c0934ee
Original file line number Diff line number Diff line change
@@ -16,19 +16,15 @@
import com.fasterxml.jackson.core.type.TypeReference;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.security.KeyStoreException;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Stream;
import javax.net.ssl.SSLContext;
import javax.ws.rs.core.Response;
import lombok.extern.slf4j.Slf4j;
@@ -165,7 +161,7 @@ public PipelineServiceClientResponse runPipeline(
String pipelineName = ingestionPipeline.getName();
HttpResponse<String> response;
try {
String triggerUrl = buildURI("trigger").build().toString();
String triggerUrl = buildURI("trigger").build().toString();
JSONObject requestPayload = new JSONObject();
requestPayload.put(DAG_ID, pipelineName);
response = post(triggerUrl, requestPayload.toString());
@@ -241,8 +237,7 @@ public List<PipelineStatus> getQueuedPipelineStatusInternal(IngestionPipeline in
URIBuilder uri = buildURI("status");
uri.addParameter(DAG_ID, ingestionPipeline.getName());
uri.addParameter("only_queued", "true");
response =
getRequestAuthenticatedForJsonContent(uri.build().toString());
response = getRequestAuthenticatedForJsonContent(uri.build().toString());
if (response.statusCode() == 200) {
return JsonUtils.readObjects(response.body(), PipelineStatus.class);
}
@@ -402,8 +397,7 @@ public Map<String, String> getLastIngestionLogs(IngestionPipeline ingestionPipel
uri.addParameter(DAG_ID, ingestionPipeline.getName());
uri.addParameter("task_id", taskId);
try {
response =
getRequestAuthenticatedForJsonContent(uri.build().toString());
response = getRequestAuthenticatedForJsonContent(uri.build().toString());
if (response.statusCode() == 200) {
return JsonUtils.readValue(response.body(), new TypeReference<>() {});
}
@@ -420,16 +414,19 @@ private URIBuilder buildURI(String path) {
pathInternal.add(path);
return new URIBuilder(String.valueOf(serviceURL)).setPathSegments(pathInternal);
} catch (Exception e) {
throw PipelineServiceClientException.byMessage(String.format("Failed to built request URI for path [%s].", path), e.getMessage());
throw PipelineServiceClientException.byMessage(
String.format("Failed to built request URI for path [%s].", path), e.getMessage());
}
}

private HttpResponse<String> getRequestAuthenticatedForJsonContent(String url) throws IOException, InterruptedException {
private HttpResponse<String> getRequestAuthenticatedForJsonContent(String url)
throws IOException, InterruptedException {
HttpRequest request = authenticatedRequestBuilder(url).GET().build();
return client.send(request, HttpResponse.BodyHandlers.ofString());
}

private HttpResponse<String> deleteRequestAuthenticatedForJsonContent(String url) throws IOException, InterruptedException {
private HttpResponse<String> deleteRequestAuthenticatedForJsonContent(String url)
throws IOException, InterruptedException {
HttpRequest request = authenticatedRequestBuilder(url).DELETE().build();
return client.send(request, HttpResponse.BodyHandlers.ofString());
}