From 39c2f200dd2d55918ed5f764ebee0efdce2516be Mon Sep 17 00:00:00 2001 From: Mohammad Arshad Date: Sat, 24 Aug 2024 23:17:53 +0530 Subject: [PATCH] [Bug] [Seatunnel-web] GET /seatunnel/api/v1/job/executor/resource API is not using logged-in user. --- .../app/controller/JobExecutorController.java | 2 +- .../JobExecutorControllerWrapper.java | 5 ++- .../domain/JobExecutorResDeserializer.java | 45 +++++++++++++++++++ .../app/test/JobExecutorControllerTest.java | 11 +++++ .../seatunnel/app/utils/JSONTestUtils.java | 3 ++ 5 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 seatunnel-web-it/src/test/java/org/apache/seatunnel/app/domain/JobExecutorResDeserializer.java diff --git a/seatunnel-server/seatunnel-app/src/main/java/org/apache/seatunnel/app/controller/JobExecutorController.java b/seatunnel-server/seatunnel-app/src/main/java/org/apache/seatunnel/app/controller/JobExecutorController.java index 77a7604f2..d330f3754 100644 --- a/seatunnel-server/seatunnel-app/src/main/java/org/apache/seatunnel/app/controller/JobExecutorController.java +++ b/seatunnel-server/seatunnel-app/src/main/java/org/apache/seatunnel/app/controller/JobExecutorController.java @@ -62,7 +62,7 @@ public Result jobExecutor( @GetMapping("/resource") @ApiOperation(value = "get the resource for job executor", httpMethod = "GET") public Result resource( - @ApiParam(value = "userId", required = true) @RequestParam Integer userId, + @ApiParam(value = "userId", required = true) @RequestAttribute("userId") Integer userId, @ApiParam(value = "Job define id", required = true) @RequestParam Long jobDefineId) throws IOException { try { diff --git a/seatunnel-web-it/src/test/java/org/apache/seatunnel/app/controller/JobExecutorControllerWrapper.java b/seatunnel-web-it/src/test/java/org/apache/seatunnel/app/controller/JobExecutorControllerWrapper.java index 881cf4ca6..c77325481 100644 --- a/seatunnel-web-it/src/test/java/org/apache/seatunnel/app/controller/JobExecutorControllerWrapper.java +++ b/seatunnel-web-it/src/test/java/org/apache/seatunnel/app/controller/JobExecutorControllerWrapper.java @@ -19,6 +19,7 @@ import org.apache.seatunnel.app.common.Result; import org.apache.seatunnel.app.common.SeatunnelWebTestingBase; import org.apache.seatunnel.app.domain.request.job.JobExecParam; +import org.apache.seatunnel.app.domain.response.executor.JobExecutorRes; import org.apache.seatunnel.app.utils.JSONTestUtils; import org.apache.seatunnel.app.utils.JSONUtils; @@ -45,10 +46,10 @@ public Result jobExecutor(Long jobDefineId, JobExecParam jobExecParam) { return JSONTestUtils.parseObject(response, new TypeReference>() {}); } - public Result resource(Long jobDefineId) { + public Result resource(Long jobDefineId) { String response = sendRequest(urlWithParam("job/executor/resource?jobDefineId=" + jobDefineId)); - return JSONTestUtils.parseObject(response, Result.class); + return JSONTestUtils.parseObject(response, new TypeReference>() {}); } public Result jobPause(Long jobInstanceId) { diff --git a/seatunnel-web-it/src/test/java/org/apache/seatunnel/app/domain/JobExecutorResDeserializer.java b/seatunnel-web-it/src/test/java/org/apache/seatunnel/app/domain/JobExecutorResDeserializer.java new file mode 100644 index 000000000..5aef4554e --- /dev/null +++ b/seatunnel-web-it/src/test/java/org/apache/seatunnel/app/domain/JobExecutorResDeserializer.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.seatunnel.app.domain; + +import org.apache.seatunnel.app.domain.response.executor.JobExecutorRes; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.JsonNode; + +import java.io.IOException; + +public class JobExecutorResDeserializer extends JsonDeserializer { + + @Override + public JobExecutorRes deserialize( + JsonParser jsonParser, DeserializationContext deserializationContext) + throws IOException, JsonProcessingException { + JsonNode node = jsonParser.getCodec().readTree(jsonParser); + Long jobInstanceId = node.get("jobInstanceId").asLong(); + String jobConfig = node.get("jobConfig").asText(); + String engine = node.get("engine").asText(); + String deployMode = node.get("deployMode").asText(); + String master = node.get("master").asText(); + String jobMode = node.get("jobMode").asText(); + + return new JobExecutorRes(jobInstanceId, jobConfig, engine, deployMode, master, jobMode); + } +} diff --git a/seatunnel-web-it/src/test/java/org/apache/seatunnel/app/test/JobExecutorControllerTest.java b/seatunnel-web-it/src/test/java/org/apache/seatunnel/app/test/JobExecutorControllerTest.java index 965ad200c..3af81eb0a 100644 --- a/seatunnel-web-it/src/test/java/org/apache/seatunnel/app/test/JobExecutorControllerTest.java +++ b/seatunnel-web-it/src/test/java/org/apache/seatunnel/app/test/JobExecutorControllerTest.java @@ -25,6 +25,7 @@ import org.apache.seatunnel.app.domain.request.job.JobCreateReq; import org.apache.seatunnel.app.domain.request.job.JobExecParam; import org.apache.seatunnel.app.domain.request.job.PluginConfig; +import org.apache.seatunnel.app.domain.response.executor.JobExecutorRes; import org.apache.seatunnel.app.domain.response.metrics.JobPipelineDetailMetricsRes; import org.apache.seatunnel.app.utils.JobUtils; @@ -41,6 +42,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; public class JobExecutorControllerTest { @@ -243,6 +245,15 @@ public void restoreJob_shouldReturnSuccess_whenValidRequest() { assertTrue(result.isSuccess()); } + @Test + public void getResource_shouldReturnSuccess_whenValidRequest() { + String jobName = "getResource" + uniqueId; + long jobVersionId = JobUtils.createJob(jobName); + Result result = jobExecutorControllerWrapper.resource(jobVersionId); + assertTrue(result.isSuccess()); + assertNotNull(result.getData()); + } + @Test public void executeJob_JobStatusUpdate_WhenSubmissionFailed() { String jobName = "execJobStatus" + uniqueId; diff --git a/seatunnel-web-it/src/test/java/org/apache/seatunnel/app/utils/JSONTestUtils.java b/seatunnel-web-it/src/test/java/org/apache/seatunnel/app/utils/JSONTestUtils.java index cfd29d029..dd9c146b4 100644 --- a/seatunnel-web-it/src/test/java/org/apache/seatunnel/app/utils/JSONTestUtils.java +++ b/seatunnel-web-it/src/test/java/org/apache/seatunnel/app/utils/JSONTestUtils.java @@ -19,8 +19,10 @@ import org.apache.seatunnel.app.common.Constants; import org.apache.seatunnel.app.domain.ConnectorInfoDeserializer; +import org.apache.seatunnel.app.domain.JobExecutorResDeserializer; import org.apache.seatunnel.app.domain.PluginIdentifierDeserializer; import org.apache.seatunnel.app.domain.response.connector.ConnectorInfo; +import org.apache.seatunnel.app.domain.response.executor.JobExecutorRes; import org.apache.seatunnel.plugin.discovery.PluginIdentifier; import org.apache.commons.lang3.StringUtils; @@ -75,6 +77,7 @@ public class JSONTestUtils { SimpleModule module = new SimpleModule(); module.addDeserializer(PluginIdentifier.class, new PluginIdentifierDeserializer()); module.addDeserializer(ConnectorInfo.class, new ConnectorInfoDeserializer()); + module.addDeserializer(JobExecutorRes.class, new JobExecutorResDeserializer()); objectMapper.registerModule(module); }