feat: add java control plane container baseline

This commit is contained in:
wlx committed 2026-08-31 14:48:02 +08:00
1 parent 2897354dd8
commit 1615401185
18 files changed
+566

No files matched your search

+4
View File
@@ -0,0 +1,4 @@
.git
.idea
target
*.log
+16
View File
@@ -0,0 +1,16 @@
FROM maven:3.9-eclipse-temurin-21-alpine AS build
WORKDIR /workspace
COPY pom.xml .
RUN mvn -B -q dependency:go-offline
COPY src ./src
RUN mvn -B -q clean package -DskipTests
FROM eclipse-temurin:21-jre-alpine
WORKDIR /app
RUN apk add --no-cache wget
ENV JAVA_OPTS="-XX:MaxRAMPercentage=75 -XX:+ExitOnOutOfMemoryError"
COPY --from=build /workspace/target/moyi-control-plane.jar /app/moyi-control-plane.jar
EXPOSE 8787
ENTRYPOINT ["sh", "-c", "exec java $JAVA_OPTS -jar /app/moyi-control-plane.jar"]
+14
View File
@@ -0,0 +1,14 @@
# MOYI Java Control Plane
这是 MOYI Control Plane 的 Java 迁移基线,目标运行时为 Java 21,框架为 Spring Boot。当前提供健康检查、Flyway 数据库迁移和容器启动骨架,后续按接口契约逐步迁移现有 TypeScript 服务的认证、模型目录、API Key、路由和任务能力。
目标依赖边界:
- PostgreSQL:用户、工作区、供应商、模型目录、Key、计费和审计等持久化数据。
- Redis:会话、限流、并发计数、幂等键和异步任务队列。
- OSS:3D、图片、视频等任务结果和用户上传文件;只保存对象元数据,应用不保存大文件本体。
- Provider Adapter:服务端调用 DeepSeek、Kimi、GLM、Seedance、Tripo/VAST 和后续中转渠道。
Flyway 脚本位于 `src/main/resources/db/migration/`,与现有 TypeScript 服务使用同一套基础表命名,后续迁移数据时可以按表逐步切换。
本目录的镜像由 `infra/moyi/docker-compose.yml` 构建。当前 TypeScript Control Plane 仍是迁移期间的可用实现,不要在 Java 接口尚未完成前直接切换生产流量。
+72
View File
@@ -0,0 +1,72 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.4.5</version>
<relativePath />
</parent>
<groupId>com.moyi</groupId>
<artifactId>moyi-control-plane</artifactId>
<version>0.1.0</version>
<name>moyi-control-plane</name>
<description>MOYI Model Intelligence Hub Java Control Plane</description>
<properties>
<java.version>21</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-database-postgresql</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>moyi-control-plane</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
@@ -0,0 +1,17 @@
package com.moyi.controlplane;
import java.util.Map;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HealthController {
@GetMapping("/health")
public Map<String, Object> health() {
return Map.of(
"status", "ok",
"service", "moyi-control-plane-java",
"migration", "bootstrap"
);
}
}
@@ -0,0 +1,11 @@
package com.moyi.controlplane;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class MoyiControlPlaneApplication {
public static void main(String[] args) {
SpringApplication.run(MoyiControlPlaneApplication.class, args);
}
}
@@ -0,0 +1,42 @@
spring:
application:
name: moyi-control-plane
datasource:
url: ${SPRING_DATASOURCE_URL:jdbc:postgresql://localhost:5434/moyi_control}
username: ${SPRING_DATASOURCE_USERNAME:moyi}
password: ${SPRING_DATASOURCE_PASSWORD:}
hikari:
maximum-pool-size: ${DB_POOL_MAX_SIZE:15}
minimum-idle: ${DB_POOL_MIN_IDLE:2}
data:
redis:
url: ${SPRING_DATA_REDIS_URL:redis://localhost:6379}
flyway:
enabled: ${FLYWAY_ENABLED:true}
baseline-on-migrate: true
server:
address: ${CONTROL_PLANE_HOST:0.0.0.0}
port: ${CONTROL_PLANE_PORT:8787}
shutdown: graceful
management:
endpoints:
web:
exposure:
include: health,info,prometheus
endpoint:
health:
probes:
enabled: true
moyi:
auth:
session-ttl-hours: ${SESSION_TTL_HOURS:168}
password-pepper: ${AUTH_PASSWORD_PEPPER:}
storage:
oss-endpoint: ${OSS_ENDPOINT:}
oss-region: ${OSS_REGION:}
oss-bucket: ${OSS_BUCKET:}
oss-access-key-id: ${OSS_ACCESS_KEY_ID:}
oss-access-key-secret: ${OSS_ACCESS_KEY_SECRET:}
@@ -0,0 +1,61 @@
CREATE TABLE IF NOT EXISTS users (
id uuid PRIMARY KEY,
account varchar(320) NOT NULL UNIQUE,
account_kind varchar(16) NOT NULL CHECK (account_kind IN ('email', 'phone', 'username')),
password_hash text NOT NULL,
display_name varchar(80) NOT NULL,
role varchar(16) NOT NULL DEFAULT 'user' CHECK (role IN ('user', 'admin')),
status varchar(16) NOT NULL DEFAULT 'active' CHECK (status IN ('active', 'disabled')),
created_at timestamptz NOT NULL DEFAULT now(),
updated_at timestamptz NOT NULL DEFAULT now(),
last_login_at timestamptz
);
CREATE TABLE IF NOT EXISTS invitation_codes (
id uuid PRIMARY KEY,
code_hash char(64) NOT NULL UNIQUE,
code_prefix varchar(12) NOT NULL,
label varchar(100) NOT NULL,
max_uses integer NOT NULL DEFAULT 1 CHECK (max_uses > 0),
used_count integer NOT NULL DEFAULT 0 CHECK (used_count >= 0 AND used_count <= max_uses),
expires_at timestamptz,
disabled_at timestamptz,
created_by uuid NOT NULL REFERENCES users(id),
created_at timestamptz NOT NULL DEFAULT now()
);
CREATE TABLE IF NOT EXISTS invitation_redemptions (
invitation_id uuid NOT NULL REFERENCES invitation_codes(id),
user_id uuid NOT NULL REFERENCES users(id),
redeemed_at timestamptz NOT NULL DEFAULT now(),
PRIMARY KEY (invitation_id, user_id)
);
CREATE TABLE IF NOT EXISTS auth_sessions (
id uuid PRIMARY KEY,
token_hash char(64) NOT NULL UNIQUE,
user_id uuid NOT NULL REFERENCES users(id) ON DELETE CASCADE,
expires_at timestamptz NOT NULL,
revoked_at timestamptz,
created_at timestamptz NOT NULL DEFAULT now(),
last_seen_at timestamptz NOT NULL DEFAULT now(),
user_agent text,
ip_address inet
);
CREATE INDEX IF NOT EXISTS auth_sessions_user_id_idx ON auth_sessions(user_id);
CREATE INDEX IF NOT EXISTS auth_sessions_expires_at_idx ON auth_sessions(expires_at);
CREATE TABLE IF NOT EXISTS auth_audit_log (
id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
actor_user_id uuid REFERENCES users(id),
event_type varchar(64) NOT NULL,
target_type varchar(32),
target_id text,
ip_address inet,
user_agent text,
details jsonb NOT NULL DEFAULT '{}'::jsonb,
created_at timestamptz NOT NULL DEFAULT now()
);
CREATE INDEX IF NOT EXISTS auth_audit_log_created_at_idx ON auth_audit_log(created_at DESC);
@@ -0,0 +1,47 @@
CREATE TABLE IF NOT EXISTS model_providers (
id varchar(64) PRIMARY KEY,
code varchar(64) NOT NULL UNIQUE,
name varchar(120) NOT NULL,
protocol varchar(32) NOT NULL CHECK (protocol IN ('openai-compatible', 'http', 'sdk')),
base_url text,
description text,
status varchar(16) NOT NULL DEFAULT 'active' CHECK (status IN ('active', 'disabled')),
created_at timestamptz NOT NULL DEFAULT now(),
updated_at timestamptz NOT NULL DEFAULT now()
);
CREATE TABLE IF NOT EXISTS model_catalog (
id varchar(64) PRIMARY KEY,
provider_id varchar(64) NOT NULL REFERENCES model_providers(id),
public_name varchar(160) NOT NULL,
upstream_model varchar(160) NOT NULL,
model_type varchar(24) NOT NULL CHECK (model_type IN ('text', 'code', 'multimodal', 'image', 'audio', 'video', 'embedding', '3d')),
call_mode varchar(16) NOT NULL CHECK (call_mode IN ('sync', 'stream', 'async')),
description text NOT NULL DEFAULT '',
input_types jsonb NOT NULL DEFAULT '[]'::jsonb,
output_types jsonb NOT NULL DEFAULT '[]'::jsonb,
capabilities jsonb NOT NULL DEFAULT '{}'::jsonb,
status varchar(16) NOT NULL DEFAULT 'active' CHECK (status IN ('active', 'disabled')),
created_at timestamptz NOT NULL DEFAULT now(),
updated_at timestamptz NOT NULL DEFAULT now()
);
CREATE INDEX IF NOT EXISTS model_catalog_provider_id_idx ON model_catalog(provider_id);
CREATE INDEX IF NOT EXISTS model_catalog_status_idx ON model_catalog(status);
CREATE TABLE IF NOT EXISTS platform_api_keys (
id uuid PRIMARY KEY,
user_id uuid NOT NULL REFERENCES users(id) ON DELETE CASCADE,
name varchar(80) NOT NULL,
key_prefix varchar(24) NOT NULL,
key_hash char(64) NOT NULL UNIQUE,
scopes jsonb NOT NULL DEFAULT '["invoke"]'::jsonb,
model_ids jsonb NOT NULL DEFAULT '[]'::jsonb,
status varchar(16) NOT NULL DEFAULT 'active' CHECK (status IN ('active', 'disabled')),
created_at timestamptz NOT NULL DEFAULT now(),
last_used_at timestamptz,
revoked_at timestamptz
);
CREATE INDEX IF NOT EXISTS platform_api_keys_user_id_idx ON platform_api_keys(user_id);
CREATE INDEX IF NOT EXISTS platform_api_keys_status_idx ON platform_api_keys(status);
@@ -0,0 +1,13 @@
CREATE TABLE IF NOT EXISTS model_projects (
id varchar(64) PRIMARY KEY,
owner_user_id uuid NOT NULL REFERENCES users(id) ON DELETE CASCADE,
name varchar(80) NOT NULL,
description text NOT NULL DEFAULT '',
status varchar(16) NOT NULL DEFAULT 'active' CHECK (status IN ('active', 'disabled')),
created_at timestamptz NOT NULL DEFAULT now(),
updated_at timestamptz NOT NULL DEFAULT now()
);
ALTER TABLE platform_api_keys ADD COLUMN IF NOT EXISTS project_id varchar(64) REFERENCES model_projects(id) ON DELETE CASCADE;
CREATE INDEX IF NOT EXISTS model_projects_owner_user_id_idx ON model_projects(owner_user_id);
CREATE INDEX IF NOT EXISTS platform_api_keys_project_id_idx ON platform_api_keys(project_id);