Skip to content

Commit

Permalink
[Bug] [Seatunnel-web] GET /seatunnel/api/v1/job/executor/resource API…
Browse files Browse the repository at this point in the history
… is not using logged-in user. (#195)
  • Loading branch information
arshadmohammad authored Aug 25, 2024
1 parent 12459d1 commit ee45dca
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public Result<Long> jobExecutor(
@GetMapping("/resource")
@ApiOperation(value = "get the resource for job executor", httpMethod = "GET")
public Result<JobExecutorRes> 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -45,10 +46,10 @@ public Result<Long> jobExecutor(Long jobDefineId, JobExecParam jobExecParam) {
return JSONTestUtils.parseObject(response, new TypeReference<Result<Long>>() {});
}

public Result<Void> resource(Long jobDefineId) {
public Result<JobExecutorRes> resource(Long jobDefineId) {
String response =
sendRequest(urlWithParam("job/executor/resource?jobDefineId=" + jobDefineId));
return JSONTestUtils.parseObject(response, Result.class);
return JSONTestUtils.parseObject(response, new TypeReference<Result<JobExecutorRes>>() {});
}

public Result<Void> jobPause(Long jobInstanceId) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<JobExecutorRes> {

@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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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 {
Expand Down Expand Up @@ -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<JobExecutorRes> result = jobExecutorControllerWrapper.resource(jobVersionId);
assertTrue(result.isSuccess());
assertNotNull(result.getData());
}

@Test
public void executeJob_JobStatusUpdate_WhenSubmissionFailed() {
String jobName = "execJobStatus" + uniqueId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit ee45dca

Please sign in to comment.