Skip to content

Commit 2cc82bd

Browse files
authored
[Feature][RestAPI] Add overview api (#6883)
1 parent 26e433e commit 2cc82bd

File tree

18 files changed

+505
-5
lines changed

18 files changed

+505
-5
lines changed

Diff for: docs/en/seatunnel-engine/rest-api.md

+20
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,26 @@ network:
3535

3636
## API reference
3737

38+
### Returns an overview over the Zeta engine cluster.
39+
40+
#### Parameters
41+
42+
#### Responses
43+
44+
```json
45+
{
46+
"projectVersion":"2.3.5-SNAPSHOT",
47+
"gitCommitAbbrev":"DeadD0d0",
48+
"totalSlot":"0",
49+
"unassignedSlot":"0",
50+
"runningJobs":"0",
51+
"finishedJobs":"0",
52+
"failedJobs":"0",
53+
"cancelledJobs":"0",
54+
"works":"1"
55+
}
56+
```
57+
3858
### Returns an overview over all jobs and their current state.
3959

4060
<details>

Diff for: docs/zh/seatunnel-engine/rest-api.md

+20
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,26 @@ network:
3434

3535
## API参考
3636

37+
### 返回Zeta集群的概览
38+
39+
#### 参数
40+
41+
#### 响应
42+
43+
```json
44+
{
45+
"projectVersion":"2.3.5-SNAPSHOT",
46+
"gitCommitAbbrev":"DeadD0d0",
47+
"totalSlot":"0",
48+
"unassignedSlot":"0",
49+
"runningJobs":"0",
50+
"finishedJobs":"0",
51+
"failedJobs":"0",
52+
"cancelledJobs":"0",
53+
"works":"1"
54+
}
55+
```
56+
3757
### 返回所有作业及其当前状态的概览。
3858

3959
<details>

Diff for: pom.xml

+7
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@
121121
<config.version>1.3.3</config.version>
122122
<maven-shade-plugin.version>3.3.0</maven-shade-plugin.version>
123123
<maven-helper-plugin.version>3.2.0</maven-helper-plugin.version>
124+
<maven-git-commit-id-plugin.version>4.0.4</maven-git-commit-id-plugin.version>
124125
<flatten-maven-plugin.version>1.3.0</flatten-maven-plugin.version>
125126
<maven-license-maven-plugin>1.20</maven-license-maven-plugin>
126127
<log4j-core.version>2.17.1</log4j-core.version>
@@ -704,6 +705,12 @@
704705
<version>${maven-helper-plugin.version}</version>
705706
</plugin>
706707

708+
<plugin>
709+
<groupId>pl.project13.maven</groupId>
710+
<artifactId>git-commit-id-plugin</artifactId>
711+
<version>${maven-git-commit-id-plugin.version}</version>
712+
</plugin>
713+
707714
<plugin>
708715
<groupId>org.codehaus.mojo</groupId>
709716
<artifactId>license-maven-plugin</artifactId>

Diff for: seatunnel-e2e/seatunnel-engine-e2e/connector-seatunnel-e2e-base/src/test/java/org/apache/seatunnel/engine/e2e/RestApiIT.java

+20
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,26 @@ public void testGetJobInfoByJobId() {
218218
});
219219
}
220220

221+
@Test
222+
public void testOverview() {
223+
Arrays.asList(node2, node1)
224+
.forEach(
225+
instance -> {
226+
given().get(
227+
HOST
228+
+ instance.getCluster()
229+
.getLocalMember()
230+
.getAddress()
231+
.getPort()
232+
+ RestConstant.OVERVIEW)
233+
.then()
234+
.statusCode(200)
235+
.body("projectVersion", notNullValue())
236+
.body("totalSlot", equalTo("40"))
237+
.body("workers", equalTo("2"));
238+
});
239+
}
240+
221241
@Test
222242
public void testGetRunningThreads() {
223243
Arrays.asList(node2, node1)

Diff for: seatunnel-e2e/seatunnel-engine-e2e/connector-seatunnel-e2e-base/src/test/resources/seatunnel.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ seatunnel:
2222
queue-type: blockingqueue
2323
print-execution-info-interval: 10
2424
slot-service:
25-
dynamic-slot: true
25+
dynamic-slot: false
26+
slot-num: 20
2627
checkpoint:
2728
interval: 300000
2829
timeout: 100000

Diff for: seatunnel-engine/seatunnel-engine-common/pom.xml

+48
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,52 @@
4242
<version>${project.version}</version>
4343
</dependency>
4444
</dependencies>
45+
46+
<build>
47+
<resources>
48+
<resource>
49+
<filtering>false</filtering>
50+
<directory>src/main/resources</directory>
51+
</resource>
52+
<resource>
53+
<filtering>true</filtering>
54+
<directory>src/main/resources-filtered</directory>
55+
</resource>
56+
</resources>
57+
<plugins>
58+
<plugin>
59+
<groupId>org.codehaus.mojo</groupId>
60+
<artifactId>build-helper-maven-plugin</artifactId>
61+
<executions>
62+
<execution>
63+
<id>parse-version</id>
64+
<goals>
65+
<goal>parse-version</goal>
66+
</goals>
67+
</execution>
68+
</executions>
69+
</plugin>
70+
<plugin>
71+
<groupId>pl.project13.maven</groupId>
72+
<artifactId>git-commit-id-plugin</artifactId>
73+
<configuration>
74+
<skipPoms>false</skipPoms>
75+
<failOnNoGitDirectory>false</failOnNoGitDirectory>
76+
<failOnUnableToExtractRepoInfo>false</failOnUnableToExtractRepoInfo>
77+
<gitDescribe>
78+
<skip>true</skip>
79+
</gitDescribe>
80+
</configuration>
81+
<executions>
82+
<execution>
83+
<id>get-the-git-information</id>
84+
<goals>
85+
<goal>revision</goal>
86+
</goals>
87+
<phase>validate</phase>
88+
</execution>
89+
</executions>
90+
</plugin>
91+
</plugins>
92+
</build>
4593
</project>

Diff for: seatunnel-engine/seatunnel-engine-common/src/main/java/org/apache/seatunnel/engine/common/Constant.java

+2
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,6 @@ public class Constant {
6060
public static final Long IMAP_RUNNING_JOB_METRICS_KEY = 1L;
6161

6262
public static final String IMAP_CONNECTOR_JAR_REF_COUNTERS = "engine_connectorJarRefCounters";
63+
64+
public static final String PROP_FILE = "zeta.version.properties";
6365
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.seatunnel.engine.common.env;
19+
20+
import lombok.extern.slf4j.Slf4j;
21+
22+
import java.io.IOException;
23+
import java.io.InputStream;
24+
import java.time.ZoneId;
25+
import java.time.format.DateTimeFormatter;
26+
import java.util.Properties;
27+
28+
import static org.apache.seatunnel.engine.common.Constant.PROP_FILE;
29+
30+
@Slf4j
31+
public class EnvironmentUtil {
32+
33+
private static String getProperty(Properties properties, String key, String defaultValue) {
34+
String value = properties.getProperty(key);
35+
if (value == null || value.charAt(0) == '$') {
36+
return defaultValue;
37+
}
38+
return value;
39+
}
40+
41+
public static Version getVersion() {
42+
43+
Version version = new Version();
44+
ClassLoader classLoader = EnvironmentUtil.class.getClassLoader();
45+
46+
try (InputStream propFile = classLoader.getResourceAsStream(PROP_FILE)) {
47+
48+
if (propFile != null) {
49+
Properties properties = new Properties();
50+
51+
properties.load(propFile);
52+
53+
version.setProjectVersion(
54+
getProperty(properties, "project.version", version.getProjectVersion()));
55+
version.setGitCommitId(
56+
getProperty(properties, "git.commit.id", version.getGitCommitId()));
57+
version.setGitCommitAbbrev(
58+
getProperty(
59+
properties, "git.commit.id.abbrev", version.getGitCommitAbbrev()));
60+
61+
DateTimeFormatter gitDateTimeFormatter =
62+
DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssZ");
63+
64+
DateTimeFormatter systemDefault =
65+
DateTimeFormatter.ISO_OFFSET_DATE_TIME.withZone(ZoneId.systemDefault());
66+
67+
version.setBuildTime(
68+
systemDefault.format(
69+
gitDateTimeFormatter.parse(
70+
getProperty(
71+
properties,
72+
"git.build.time",
73+
version.getBuildTime()))));
74+
version.setCommitTime(
75+
systemDefault.format(
76+
gitDateTimeFormatter.parse(
77+
getProperty(
78+
properties,
79+
"git.commit.time",
80+
version.getCommitTime()))));
81+
}
82+
83+
} catch (IOException ioException) {
84+
log.info("Unable to read version property file: {}", ioException.getMessage());
85+
}
86+
87+
return version;
88+
}
89+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.seatunnel.engine.common.env;
19+
20+
import lombok.Data;
21+
22+
@Data
23+
public class Version {
24+
private String projectVersion = "<unknown>";
25+
private String gitCommitId = "DecafC0ffeeD0d0F00d";
26+
private String buildTime = "1970-01-01T00:00:00+0000";
27+
private String commitTime = "1970-01-01T00:00:00+0000";
28+
private String gitCommitAbbrev = "DeadD0d0";
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one or more
3+
# contributor license agreements. See the NOTICE file distributed with
4+
# this work for additional information regarding copyright ownership.
5+
# The ASF licenses this file to You under the Apache License, Version 2.0
6+
# (the "License"); you may not use this file except in compliance with
7+
# the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
project.version=${project.version}
19+
git.commit.id=${git.commit.id}
20+
git.commit.id.abbrev=${git.commit.id.abbrev}
21+
git.commit.time=${git.commit.time}
22+
git.build.time=${git.build.time}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.seatunnel.engine.common.config;
19+
20+
import org.apache.seatunnel.engine.common.env.EnvironmentUtil;
21+
import org.apache.seatunnel.engine.common.env.Version;
22+
23+
import org.junit.jupiter.api.Test;
24+
25+
import static org.junit.jupiter.api.Assertions.assertNotNull;
26+
27+
public class EnvironmentUtilTest {
28+
29+
@Test
30+
public void testGetVersion() {
31+
32+
Version version = EnvironmentUtil.getVersion();
33+
34+
assertNotNull(version.getProjectVersion());
35+
assertNotNull(version.getGitCommitId());
36+
assertNotNull(version.getGitCommitAbbrev());
37+
assertNotNull(version.getBuildTime());
38+
assertNotNull(version.getCommitTime());
39+
}
40+
}

Diff for: seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/resourcemanager/AbstractResourceManager.java

+12
Original file line numberDiff line numberDiff line change
@@ -223,4 +223,16 @@ public List<SlotProfile> getUnassignedSlots() {
223223
.flatMap(workerProfile -> Arrays.stream(workerProfile.getUnassignedSlots()))
224224
.collect(Collectors.toList());
225225
}
226+
227+
@Override
228+
public List<SlotProfile> getAssignedSlots() {
229+
return registerWorker.values().stream()
230+
.flatMap(workerProfile -> Arrays.stream(workerProfile.getAssignedSlots()))
231+
.collect(Collectors.toList());
232+
}
233+
234+
@Override
235+
public int workerCount() {
236+
return registerWorker.size();
237+
}
226238
}

Diff for: seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/resourcemanager/ResourceManager.java

+4
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,8 @@ CompletableFuture<List<SlotProfile>> applyResources(
6060
void close();
6161

6262
List<SlotProfile> getUnassignedSlots();
63+
64+
List<SlotProfile> getAssignedSlots();
65+
66+
int workerCount();
6367
}

0 commit comments

Comments
 (0)