From d8ce9ddc5093863b16adbd14a676071b98031d7c Mon Sep 17 00:00:00 2001 From: Jiri Danek Date: Sat, 19 Oct 2024 20:49:13 +0200 Subject: [PATCH] feat(KPFv2Client): add httpServer and oauthToken parameters --- .../io/odh/test/platform/KFPv2Client.java | 46 +++++++++---------- .../test/e2e/standard/PipelineV2ServerST.java | 1 + 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/src/main/java/io/odh/test/platform/KFPv2Client.java b/src/main/java/io/odh/test/platform/KFPv2Client.java index e5e07ced..b5257a09 100644 --- a/src/main/java/io/odh/test/platform/KFPv2Client.java +++ b/src/main/java/io/odh/test/platform/KFPv2Client.java @@ -38,15 +38,15 @@ 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 @@ -54,11 +54,10 @@ 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 responseCreate = httpClient.send(createPipelineRequest, HttpResponse.BodyHandlers.ofString()); @@ -69,10 +68,9 @@ public Pipeline importPipeline(String name, String description, String filePath) @SneakyThrows public @Nonnull List 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 reply = httpClient.send(request, HttpResponse.BodyHandlers.ofString()); @@ -86,10 +84,9 @@ public Pipeline importPipeline(String name, String description, String filePath) @SneakyThrows public @Nonnull List 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 reply = httpClient.send(request, HttpResponse.BodyHandlers.ofString()); @@ -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 reply = httpClient.send(request, HttpResponse.BodyHandlers.ofString()); @@ -126,10 +122,9 @@ public PipelineRun runPipeline(String pipelineTestRunBasename, String pipelineId @SneakyThrows public List 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 reply = httpClient.send(request, HttpResponse.BodyHandlers.ofString()); @@ -139,10 +134,9 @@ public List 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 run = new AtomicReference<>(); @@ -177,10 +171,9 @@ 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 reply = httpClient.send(request, HttpResponse.BodyHandlers.ofString()); Assertions.assertEquals(200, reply.statusCode(), reply.body()); @@ -188,10 +181,9 @@ public void deletePipelineRun(String runId) { @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 reply = httpClient.send(request, HttpResponse.BodyHandlers.ofString()); Assertions.assertEquals(200, reply.statusCode(), reply.body()); @@ -199,10 +191,9 @@ public void deletePipeline(String pipelineId) { @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 reply = httpClient.send(request, HttpResponse.BodyHandlers.ofString()); Assertions.assertEquals(200, reply.statusCode(), reply.body()); @@ -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; + } } diff --git a/src/test/java/io/odh/test/e2e/standard/PipelineV2ServerST.java b/src/test/java/io/odh/test/e2e/standard/PipelineV2ServerST.java index b64f01ab..cfb583aa 100644 --- a/src/test/java/io/odh/test/e2e/standard/PipelineV2ServerST.java +++ b/src/test/java/io/odh/test/e2e/standard/PipelineV2ServerST.java @@ -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 = "jdanek@redhat.com"),