Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .dlc.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
{
"replacementPatterns": [
{
"pattern": "^@site/docs/",
"replacement": "{{BASEURL}}/docs/en/"
}
],
"ignorePatterns": [
{
"pattern": "^http://localhost"
Expand Down
190 changes: 190 additions & 0 deletions docs/en/engines/zeta/openapi-v2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
# 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.

openapi: 3.1.0
info:
title: SeaTunnel Zeta REST v2 (read-only subset)
version: 0.1.0
description: >-
This initial contract covers only GET /overview and GET /resource/workers.
Other REST v2 endpoints are not yet described. The YAML is maintained with
the Jetty servlet routes and response tests in this repository.
servers:
- url: http://localhost:8080
description: >-
Example only. Set the scheme, host, port, and configured context path for
your running Zeta REST service before using a generated client. Use HTTPS
when sending Basic authentication credentials beyond localhost.
security:
- basicAuth: []
- {}
paths:
/overview:
get:
operationId: getOverview
summary: Get cluster overview
description: >-
Optional query keys filter the worker and slot totals by worker tags.
Job counts are cluster-wide. Count fields are JSON strings in this
servlet's current response, even though their source fields are numeric.
parameters:
- name: tags
in: query
required: false
description: >-
Free-form worker tag keys and string values, serialized as
key=value pairs such as region=west&team=data. There is no literal
tags query key.
style: form
explode: true
schema:
type: object
additionalProperties:
type: string
responses:
'200':
description: Current cluster overview.
content:
application/json:
schema:
$ref: '#/components/schemas/Overview'
'401':
description: Basic authentication is enabled and credentials are missing or invalid.
'500':
description: The server could not complete the request; error bodies vary.
/resource/workers:
get:
operationId: getWorkerResources
summary: Get worker resource snapshot
description: >-
Returns the latest worker resource projection. During a master
transition, available is false and workers is empty; HTTP 200 still
indicates a successfully delivered snapshot.
responses:
'200':
description: Point-in-time worker resource snapshot.
content:
application/json:
schema:
$ref: '#/components/schemas/WorkerResourceSnapshot'
'401':
description: Basic authentication is enabled and credentials are missing or invalid.
'500':
description: The server could not complete the request; error bodies vary.
components:
securitySchemes:
basicAuth:
type: http
scheme: basic
description: Optional; configured on the Zeta Jetty service.
schemas:
Overview:
type: object
required:
- projectVersion
- gitCommitAbbrev
- totalSlot
- unassignedSlot
- runningJobs
- finishedJobs
- failedJobs
- pendingJobs
- cancelledJobs
- workers
properties:
projectVersion:
type: string
gitCommitAbbrev:
type: string
totalSlot:
$ref: '#/components/schemas/DecimalCountString'
unassignedSlot:
$ref: '#/components/schemas/DecimalCountString'
runningJobs:
$ref: '#/components/schemas/DecimalCountString'
finishedJobs:
$ref: '#/components/schemas/DecimalCountString'
failedJobs:
$ref: '#/components/schemas/DecimalCountString'
pendingJobs:
$ref: '#/components/schemas/DecimalCountString'
cancelledJobs:
$ref: '#/components/schemas/DecimalCountString'
workers:
$ref: '#/components/schemas/DecimalCountString'
DecimalCountString:
type: string
pattern: '^[0-9]+$'
description: A non-negative count serialized as a decimal JSON string.
WorkerResourceSnapshot:
type: object
required: [available, collectedAt, workers]
properties:
available:
type: boolean
description: False when the resource projection could not be collected.
collectedAt:
type: integer
format: int64
description: Snapshot collection time in Unix epoch milliseconds.
workers:
type: array
items:
$ref: '#/components/schemas/WorkerResourceDiagnostic'
WorkerResourceDiagnostic:
type: object
required: [address, tags, totalSlots, freeSlots, usedSlots, dynamicSlot, runningJobIds]
properties:
address:
type: string
tags:
type: object
additionalProperties:
type: string
totalSlots:
type: integer
format: int32
description: For dynamic slots, current assigned plus unassigned slots.
freeSlots:
type: integer
format: int32
usedSlots:
type: integer
format: int32
dynamicSlot:
type: boolean
totalCpuCores:
type: integer
format: int32
availableCpuCores:
type: integer
format: int32
totalHeapMemoryBytes:
type: integer
format: int64
availableHeapMemoryBytes:
type: integer
format: int64
cpuUsage:
type: number
format: double
memUsage:
type: number
format: double
runningJobIds:
type: array
items:
type: integer
format: int64
2 changes: 2 additions & 0 deletions docs/en/engines/zeta/rest-api-v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ Please refer [security](security.md)

## API reference

The [OpenAPI 3.1 contract for the read-only REST v2 subset](openapi-v2.yaml) currently covers `GET /overview` and `GET /resource/workers` only. Other endpoints below remain documented here but are not yet included in the machine-readable contract. The spec is maintained alongside the servlet route registrations and response tests. Configure the generated client's base URL for your listener, port, and optional context path. Basic authentication depends on your server configuration; use HTTPS when sending credentials beyond localhost.

### Get Connector Option Rules

<details>
Expand Down
2 changes: 2 additions & 0 deletions docs/zh/engines/zeta/rest-api-v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ seatunnel:

## API参考

[REST v2 只读接口的 OpenAPI 3.1 规范](@site/docs/engines/zeta/openapi-v2.yaml)目前仅覆盖 `GET /overview` 和 `GET /resource/workers`。下文的其他接口仍有文档,但尚未纳入机器可读规范。该规范与 Servlet 路由注册及响应测试一起维护。使用生成的客户端时,请按实际地址、端口及可选的上下文路径设置基础 URL。是否使用 Basic 认证取决于服务端配置;向非本机发送凭据时请使用 HTTPS。

### 获取 Connector 的 OptionRule

<details>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package org.apache.seatunnel.engine.server.rest;

import org.apache.seatunnel.shade.com.fasterxml.jackson.databind.JsonNode;
import org.apache.seatunnel.shade.com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.seatunnel.shade.org.apache.commons.lang3.StringUtils;

import org.apache.seatunnel.engine.common.config.SeaTunnelConfig;
Expand All @@ -30,6 +32,7 @@
import org.apache.seatunnel.engine.server.SeaTunnelServerStarter;
import org.apache.seatunnel.engine.server.TestUtils;

import org.awaitility.Awaitility;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
Expand All @@ -47,22 +50,28 @@
import java.util.Base64;
import java.util.Base64.Encoder;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

import static org.apache.seatunnel.engine.server.rest.RestConstant.REST_URL_LOGS;
import static org.apache.seatunnel.engine.server.rest.RestConstant.REST_URL_OVERVIEW;
import static org.apache.seatunnel.engine.server.rest.RestConstant.REST_URL_WORKER_RESOURCES;

/** Test for Rest API with Basic. */
class RestApiHttpBasicTest extends AbstractSeaTunnelServerTest {

private static final int HTTP_PORT = 18081;
private static final int HTTP_TIMEOUT_MILLIS = 10_000;
private static final Long JOB_1 = System.currentTimeMillis() + 1L;
private static final String USER = "admin";
private static final String PASS = "admin";
private static final String DOMAIN = "http://localhost:" + HTTP_PORT;

private static final String AUTHORIZATION_HEADER = "Authorization";
private static final String BASIC_PREFIX = "Basic ";
private static final ObjectMapper JSON = new ObjectMapper();

@Override
@BeforeAll
Expand Down Expand Up @@ -124,6 +133,97 @@ public void testRestApiOverview() throws Exception {
}
}

@Test
void testDocumentedReadOnlyEndpoints() throws IOException {
for (String path : new String[] {REST_URL_OVERVIEW, REST_URL_WORKER_RESOURCES}) {
HttpURLConnection unauthenticated = null;
try {
unauthenticated = (HttpURLConnection) new URL(DOMAIN + path).openConnection();
unauthenticated.setConnectTimeout(HTTP_TIMEOUT_MILLIS);
unauthenticated.setReadTimeout(HTTP_TIMEOUT_MILLIS);
Assertions.assertEquals(401, unauthenticated.getResponseCode(), path);
Assertions.assertTrue(
unauthenticated.getHeaderField("WWW-Authenticate").startsWith("Basic "),
path);
} finally {
if (unauthenticated != null) {
unauthenticated.disconnect();
}
}
}

JsonNode overview = getAuthenticatedJson(REST_URL_OVERVIEW);
Assertions.assertEquals(
Set.of(
"projectVersion",
"gitCommitAbbrev",
"totalSlot",
"unassignedSlot",
"runningJobs",
"finishedJobs",
"failedJobs",
"pendingJobs",
"cancelledJobs",
"workers"),
fields(overview));
overview.fields()
.forEachRemaining(
field ->
Assertions.assertTrue(
field.getValue().isTextual(), field.getKey()));

JsonNode filteredOverview = getAuthenticatedJson(REST_URL_OVERVIEW + "?region=unmatched");
Assertions.assertEquals("0", filteredOverview.path("workers").asText());

JsonNode snapshot =
Awaitility.await()
.atMost(30, TimeUnit.SECONDS)
.until(
() -> getAuthenticatedJson(REST_URL_WORKER_RESOURCES),
value ->
value.path("available").asBoolean()
&& !value.path("workers").isEmpty());
Assertions.assertEquals(Set.of("available", "collectedAt", "workers"), fields(snapshot));
Assertions.assertTrue(snapshot.path("available").isBoolean());
Assertions.assertTrue(snapshot.path("collectedAt").isIntegralNumber());
Assertions.assertTrue(snapshot.path("workers").isArray());
Assertions.assertFalse(snapshot.path("workers").isEmpty());
snapshot.path("workers")
.forEach(
worker -> {
Assertions.assertTrue(worker.path("address").isTextual());
Assertions.assertTrue(worker.path("tags").isObject());
Assertions.assertTrue(worker.path("totalSlots").isIntegralNumber());
Assertions.assertTrue(worker.path("freeSlots").isIntegralNumber());
Assertions.assertTrue(worker.path("usedSlots").isIntegralNumber());
Assertions.assertTrue(worker.path("dynamicSlot").isBoolean());
Assertions.assertTrue(worker.path("runningJobIds").isArray());
});
}

private JsonNode getAuthenticatedJson(String path) throws IOException {
HttpURLConnection connection = null;
try {
connection = (HttpURLConnection) new URL(DOMAIN + path).openConnection();
connection.setConnectTimeout(HTTP_TIMEOUT_MILLIS);
connection.setReadTimeout(HTTP_TIMEOUT_MILLIS);
setBasicAuth(connection);
Assertions.assertEquals(200, connection.getResponseCode(), path);
Assertions.assertTrue(connection.getContentType().startsWith("application/json"), path);
return JSON.readTree(connection.getInputStream());
} finally {
if (connection != null) {
connection.disconnect();
}
}
}

private static Set<String> fields(JsonNode node) {
Set<String> names = new HashSet<>();
node.fieldNames().forEachRemaining(names::add);
return names;
}

@Test
void testLogRestApiResponseFailure() throws IOException {
startJob();
Expand Down
Loading
Loading