Skip to content

Commit

Permalink
feat(KPFv2Client): add httpServer and oauthToken parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
jiridanek committed Oct 21, 2024
1 parent 462ff04 commit d8ce9dd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 23 deletions.
46 changes: 23 additions & 23 deletions src/main/java/io/odh/test/platform/KFPv2Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,26 @@ public class KFPv2Client {
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
.enable(JsonParser.Feature.INCLUDE_SOURCE_IN_LOCATION)
.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE);
private final HttpClient httpClient = HttpClient.newBuilder()
.version(HttpClient.Version.HTTP_2)
.followRedirects(HttpClient.Redirect.NORMAL)
.build();

private final HttpClient httpClient;
private final String baseUrl;
private final String oauthToken;

public KFPv2Client(String baseUrl) {
public KFPv2Client(HttpClient httpClient, String baseUrl, String oauthToken) {
this.httpClient = httpClient;
this.baseUrl = baseUrl;
this.oauthToken = oauthToken;
}

@SneakyThrows
public Pipeline importPipeline(String name, String description, String filePath) {
MultipartFormDataBodyPublisher requestBody = new MultipartFormDataBodyPublisher()
.addFile("uploadfile", Path.of(filePath), "application/yaml");

HttpRequest createPipelineRequest = HttpRequest.newBuilder()
HttpRequest createPipelineRequest = buildRequest()
.uri(new URI(baseUrl + "/apis/v2beta1/pipelines/upload?name=%s&description=%s".formatted(name, description)))
.header("Content-Type", requestBody.contentType())
.POST(requestBody)
.timeout(Duration.of(DEFAULT_TIMEOUT_DURATION, DEFAULT_TIMEOUT_UNIT.toChronoUnit()))
.build();
HttpResponse<String> responseCreate = httpClient.send(createPipelineRequest, HttpResponse.BodyHandlers.ofString());

Expand All @@ -69,10 +68,9 @@ public Pipeline importPipeline(String name, String description, String filePath)

@SneakyThrows
public @Nonnull List<Pipeline> listPipelines() {
HttpRequest request = HttpRequest.newBuilder()
HttpRequest request = buildRequest()
.uri(URI.create(baseUrl + "/apis/v2beta1/pipelines"))
.GET()
.timeout(Duration.of(DEFAULT_TIMEOUT_DURATION, DEFAULT_TIMEOUT_UNIT.toChronoUnit()))
.build();

HttpResponse<String> reply = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
Expand All @@ -86,10 +84,9 @@ public Pipeline importPipeline(String name, String description, String filePath)

@SneakyThrows
public @Nonnull List<PipelineVersion> listPipelineVersions(String pipelineId) {
HttpRequest request = HttpRequest.newBuilder()
HttpRequest request = buildRequest()
.uri(URI.create(baseUrl + "/apis/v2beta1/pipelines/" + pipelineId + "/versions"))
.GET()
.timeout(Duration.of(DEFAULT_TIMEOUT_DURATION, DEFAULT_TIMEOUT_UNIT.toChronoUnit()))
.build();

HttpResponse<String> reply = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
Expand All @@ -113,10 +110,9 @@ public PipelineRun runPipeline(String pipelineTestRunBasename, String pipelineId
pipelineRun.runtimeConfig = new RuntimeConfig();
pipelineRun.runtimeConfig.parameters = parameters;
}
HttpRequest request = HttpRequest.newBuilder()
HttpRequest request = buildRequest()
.uri(URI.create(baseUrl + "/apis/v2beta1/runs"))
.POST(HttpRequest.BodyPublishers.ofString(objectMapper.writeValueAsString(pipelineRun)))
.timeout(Duration.of(DEFAULT_TIMEOUT_DURATION, DEFAULT_TIMEOUT_UNIT.toChronoUnit()))
.build();
HttpResponse<String> reply = httpClient.send(request, HttpResponse.BodyHandlers.ofString());

Expand All @@ -126,10 +122,9 @@ public PipelineRun runPipeline(String pipelineTestRunBasename, String pipelineId

@SneakyThrows
public List<PipelineRun> getPipelineRunStatus() {
HttpRequest request = HttpRequest.newBuilder()
HttpRequest request = buildRequest()
.uri(URI.create(baseUrl + "/apis/v2beta1/runs"))
.GET()
.timeout(Duration.of(DEFAULT_TIMEOUT_DURATION, DEFAULT_TIMEOUT_UNIT.toChronoUnit()))
.build();
HttpResponse<String> reply = httpClient.send(request, HttpResponse.BodyHandlers.ofString());

Expand All @@ -139,10 +134,9 @@ public List<PipelineRun> getPipelineRunStatus() {

@SneakyThrows
public PipelineRun waitForPipelineRun(String pipelineRunId) {
HttpRequest request = HttpRequest.newBuilder()
HttpRequest request = buildRequest()
.uri(URI.create(baseUrl + "/apis/v2beta1/runs/" + pipelineRunId))
.GET()
.timeout(Duration.of(DEFAULT_TIMEOUT_DURATION, DEFAULT_TIMEOUT_UNIT.toChronoUnit()))
.build();

AtomicReference<PipelineRun> run = new AtomicReference<>();
Expand Down Expand Up @@ -177,32 +171,29 @@ public PipelineRun waitForPipelineRun(String pipelineRunId) {

@SneakyThrows
public void deletePipelineRun(String runId) {
HttpRequest request = HttpRequest.newBuilder()
HttpRequest request = buildRequest()
.uri(URI.create(baseUrl + "/apis/v2beta1/runs/" + runId))
.DELETE()
.timeout(Duration.of(DEFAULT_TIMEOUT_DURATION, DEFAULT_TIMEOUT_UNIT.toChronoUnit()))
.build();
HttpResponse<String> reply = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
Assertions.assertEquals(200, reply.statusCode(), reply.body());
}

@SneakyThrows
public void deletePipeline(String pipelineId) {
HttpRequest request = HttpRequest.newBuilder()
HttpRequest request = buildRequest()
.uri(URI.create(baseUrl + "/apis/v2beta1/pipelines/" + pipelineId))
.DELETE()
.timeout(Duration.of(DEFAULT_TIMEOUT_DURATION, DEFAULT_TIMEOUT_UNIT.toChronoUnit()))
.build();
HttpResponse<String> reply = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
Assertions.assertEquals(200, reply.statusCode(), reply.body());
}

@SneakyThrows
public void deletePipelineVersion(String pipelineId, String pipelineVersionId) {
HttpRequest request = HttpRequest.newBuilder()
HttpRequest request = buildRequest()
.uri(URI.create(baseUrl + "/apis/v2beta1/pipelines/" + pipelineId + "/versions/" + pipelineVersionId))
.DELETE()
.timeout(Duration.of(DEFAULT_TIMEOUT_DURATION, DEFAULT_TIMEOUT_UNIT.toChronoUnit()))
.build();
HttpResponse<String> reply = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
Assertions.assertEquals(200, reply.statusCode(), reply.body());
Expand Down Expand Up @@ -270,4 +261,13 @@ public static class RuntimeConfig {
public Object parameters;
public String pipelineRoot;
}

private HttpRequest.Builder buildRequest() {
HttpRequest.Builder requestBuilder = HttpRequest.newBuilder()
.timeout(Duration.of(DEFAULT_TIMEOUT_DURATION, DEFAULT_TIMEOUT_UNIT.toChronoUnit()));
if (oauthToken != null) {
requestBuilder.header("Authorization", "Bearer " + oauthToken);
}
return requestBuilder;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ void deployDataScienceCluster() {
/// ODS-2206 - Verify user can create and run a data science pipeline in DS Project
/// ODS-2226 - Verify user can delete components of data science pipeline from DS Pipelines page
/// https://issues.redhat.com/browse/RHODS-5133
@SuppressWarnings({"checkstyle:MethodLength"})
@TestDoc(
description = @Desc("Check that user can create, run and deleted DataSciencePipeline from a DataScience project"),
contact = @Contact(name = "Jiri Danek", email = "[email protected]"),
Expand Down

0 comments on commit d8ce9dd

Please sign in to comment.