Skip to content

Commit

Permalink
[Feature][RestAPI] Add overview api (#6883)
Browse files Browse the repository at this point in the history
  • Loading branch information
liugddx authored Jun 3, 2024
1 parent 26e433e commit 2cc82bd
Show file tree
Hide file tree
Showing 18 changed files with 505 additions and 5 deletions.
20 changes: 20 additions & 0 deletions docs/en/seatunnel-engine/rest-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,26 @@ network:

## API reference

### Returns an overview over the Zeta engine cluster.

#### Parameters

#### Responses

```json
{
"projectVersion":"2.3.5-SNAPSHOT",
"gitCommitAbbrev":"DeadD0d0",
"totalSlot":"0",
"unassignedSlot":"0",
"runningJobs":"0",
"finishedJobs":"0",
"failedJobs":"0",
"cancelledJobs":"0",
"works":"1"
}
```

### Returns an overview over all jobs and their current state.

<details>
Expand Down
20 changes: 20 additions & 0 deletions docs/zh/seatunnel-engine/rest-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,26 @@ network:

## API参考

### 返回Zeta集群的概览

#### 参数

#### 响应

```json
{
"projectVersion":"2.3.5-SNAPSHOT",
"gitCommitAbbrev":"DeadD0d0",
"totalSlot":"0",
"unassignedSlot":"0",
"runningJobs":"0",
"finishedJobs":"0",
"failedJobs":"0",
"cancelledJobs":"0",
"works":"1"
}
```

### 返回所有作业及其当前状态的概览。

<details>
Expand Down
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
<config.version>1.3.3</config.version>
<maven-shade-plugin.version>3.3.0</maven-shade-plugin.version>
<maven-helper-plugin.version>3.2.0</maven-helper-plugin.version>
<maven-git-commit-id-plugin.version>4.0.4</maven-git-commit-id-plugin.version>
<flatten-maven-plugin.version>1.3.0</flatten-maven-plugin.version>
<maven-license-maven-plugin>1.20</maven-license-maven-plugin>
<log4j-core.version>2.17.1</log4j-core.version>
Expand Down Expand Up @@ -704,6 +705,12 @@
<version>${maven-helper-plugin.version}</version>
</plugin>

<plugin>
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId>
<version>${maven-git-commit-id-plugin.version}</version>
</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>license-maven-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,26 @@ public void testGetJobInfoByJobId() {
});
}

@Test
public void testOverview() {
Arrays.asList(node2, node1)
.forEach(
instance -> {
given().get(
HOST
+ instance.getCluster()
.getLocalMember()
.getAddress()
.getPort()
+ RestConstant.OVERVIEW)
.then()
.statusCode(200)
.body("projectVersion", notNullValue())
.body("totalSlot", equalTo("40"))
.body("workers", equalTo("2"));
});
}

@Test
public void testGetRunningThreads() {
Arrays.asList(node2, node1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ seatunnel:
queue-type: blockingqueue
print-execution-info-interval: 10
slot-service:
dynamic-slot: true
dynamic-slot: false
slot-num: 20
checkpoint:
interval: 300000
timeout: 100000
Expand Down
48 changes: 48 additions & 0 deletions seatunnel-engine/seatunnel-engine-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,52 @@
<version>${project.version}</version>
</dependency>
</dependencies>

<build>
<resources>
<resource>
<filtering>false</filtering>
<directory>src/main/resources</directory>
</resource>
<resource>
<filtering>true</filtering>
<directory>src/main/resources-filtered</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>parse-version</id>
<goals>
<goal>parse-version</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId>
<configuration>
<skipPoms>false</skipPoms>
<failOnNoGitDirectory>false</failOnNoGitDirectory>
<failOnUnableToExtractRepoInfo>false</failOnUnableToExtractRepoInfo>
<gitDescribe>
<skip>true</skip>
</gitDescribe>
</configuration>
<executions>
<execution>
<id>get-the-git-information</id>
<goals>
<goal>revision</goal>
</goals>
<phase>validate</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,6 @@ public class Constant {
public static final Long IMAP_RUNNING_JOB_METRICS_KEY = 1L;

public static final String IMAP_CONNECTOR_JAR_REF_COUNTERS = "engine_connectorJarRefCounters";

public static final String PROP_FILE = "zeta.version.properties";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* 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.engine.common.env;

import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.io.InputStream;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Properties;

import static org.apache.seatunnel.engine.common.Constant.PROP_FILE;

@Slf4j
public class EnvironmentUtil {

private static String getProperty(Properties properties, String key, String defaultValue) {
String value = properties.getProperty(key);
if (value == null || value.charAt(0) == '$') {
return defaultValue;
}
return value;
}

public static Version getVersion() {

Version version = new Version();
ClassLoader classLoader = EnvironmentUtil.class.getClassLoader();

try (InputStream propFile = classLoader.getResourceAsStream(PROP_FILE)) {

if (propFile != null) {
Properties properties = new Properties();

properties.load(propFile);

version.setProjectVersion(
getProperty(properties, "project.version", version.getProjectVersion()));
version.setGitCommitId(
getProperty(properties, "git.commit.id", version.getGitCommitId()));
version.setGitCommitAbbrev(
getProperty(
properties, "git.commit.id.abbrev", version.getGitCommitAbbrev()));

DateTimeFormatter gitDateTimeFormatter =
DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssZ");

DateTimeFormatter systemDefault =
DateTimeFormatter.ISO_OFFSET_DATE_TIME.withZone(ZoneId.systemDefault());

version.setBuildTime(
systemDefault.format(
gitDateTimeFormatter.parse(
getProperty(
properties,
"git.build.time",
version.getBuildTime()))));
version.setCommitTime(
systemDefault.format(
gitDateTimeFormatter.parse(
getProperty(
properties,
"git.commit.time",
version.getCommitTime()))));
}

} catch (IOException ioException) {
log.info("Unable to read version property file: {}", ioException.getMessage());
}

return version;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* 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.engine.common.env;

import lombok.Data;

@Data
public class Version {
private String projectVersion = "<unknown>";
private String gitCommitId = "DecafC0ffeeD0d0F00d";
private String buildTime = "1970-01-01T00:00:00+0000";
private String commitTime = "1970-01-01T00:00:00+0000";
private String gitCommitAbbrev = "DeadD0d0";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#
# 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.
#

project.version=${project.version}
git.commit.id=${git.commit.id}
git.commit.id.abbrev=${git.commit.id.abbrev}
git.commit.time=${git.commit.time}
git.build.time=${git.build.time}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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.engine.common.config;

import org.apache.seatunnel.engine.common.env.EnvironmentUtil;
import org.apache.seatunnel.engine.common.env.Version;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertNotNull;

public class EnvironmentUtilTest {

@Test
public void testGetVersion() {

Version version = EnvironmentUtil.getVersion();

assertNotNull(version.getProjectVersion());
assertNotNull(version.getGitCommitId());
assertNotNull(version.getGitCommitAbbrev());
assertNotNull(version.getBuildTime());
assertNotNull(version.getCommitTime());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,16 @@ public List<SlotProfile> getUnassignedSlots() {
.flatMap(workerProfile -> Arrays.stream(workerProfile.getUnassignedSlots()))
.collect(Collectors.toList());
}

@Override
public List<SlotProfile> getAssignedSlots() {
return registerWorker.values().stream()
.flatMap(workerProfile -> Arrays.stream(workerProfile.getAssignedSlots()))
.collect(Collectors.toList());
}

@Override
public int workerCount() {
return registerWorker.size();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,8 @@ CompletableFuture<List<SlotProfile>> applyResources(
void close();

List<SlotProfile> getUnassignedSlots();

List<SlotProfile> getAssignedSlots();

int workerCount();
}
Loading

0 comments on commit 2cc82bd

Please sign in to comment.