fengling-activity/scripts/gateway/Register-ActivityService.ps1
sam ab8d12527e refactor: major project restructuring and cleanup
Changes:

- Remove deprecated Fengling.Activity and YarpGateway.Admin projects

- Add points processing services with distributed lock support

- Update Vben frontend with gateway management pages

- Add gateway config controller and database listener

- Update routing to use header-mixed-nav layout

- Add comprehensive test suites for Member services

- Add YarpGateway integration tests

- Update package versions in Directory.Packages.props

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
2026-02-15 10:34:07 +08:00

136 lines
4.4 KiB
PowerShell
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Activity服务接入YARP网关配置脚本
# PowerShell: pwsh Register-ActivityService.ps1 -GatewayUrl "http://localhost:5000"
param(
[string]$GatewayUrl = "http://localhost:5000",
[string]$ServiceName = "activity",
[string]$ClusterId = "activity-service",
[string]$PathPattern = "/api/activity/{**path}",
[string]$InstanceAddress = "http://localhost:5001",
[string]$DestinationId = "activity-1",
[int]$Weight = 1,
[switch]$IsGlobal = $true,
[string]$TenantCode = ""
)
$ErrorActionPreference = "Stop"
function Register-ActivityService {
param(
[string]$GatewayUrl,
[string]$ServiceName,
[string]$ClusterId,
[string]$PathPattern,
[string]$InstanceAddress,
[string]$DestinationId,
[int]$Weight,
[bool]$IsGlobal,
[string]$TenantCode
)
Write-Host "========================================" -ForegroundColor Cyan
Write-Host "Activity Service Gateway Configuration" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
# Step 1: Add Service Instance (Cluster)
Write-Host "[Step 1] Adding service instance to cluster..." -ForegroundColor Yellow
$instanceBody = @{
destinationId = $DestinationId
address = $InstanceAddress
weight = $Weight
} | ConvertTo-Json
try {
$instanceResponse = Invoke-RestMethod -Uri "$GatewayUrl/api/gateway/clusters/$ClusterId/instances" `
-Method Post `
-ContentType "application/json" `
-Body $instanceBody
Write-Host " ✓ Instance added: $DestinationId -> $InstanceAddress" -ForegroundColor Green
}
catch {
if ($_.Exception.Response.StatusCode -eq "BadRequest") {
Write-Host " Instance already exists, skipping..." -ForegroundColor Gray
}
else {
throw $_
}
}
# Step 2: Add Route
Write-Host ""
Write-Host "[Step 2] Adding gateway route..." -ForegroundColor Yellow
if ($IsGlobal) {
$routeBody = @{
serviceName = $ServiceName
clusterId = $ClusterId
pathPattern = $PathPattern
} | ConvertTo-Json
$routeUrl = "$GatewayUrl/api/gateway/routes/global"
$routeDescription = "global route"
}
else {
$routeBody = @{
serviceName = $ServiceName
pathPattern = $PathPattern
} | ConvertTo-Json
$routeUrl = "$GatewayUrl/api/gateway/tenants/$TenantCode/routes"
$routeDescription = "tenant route for $TenantCode"
}
try {
$routeResponse = Invoke-RestMethod -Uri $routeUrl `
-Method Post `
-ContentType "application/json" `
-Body $routeBody
Write-Host " ✓ Route added: $PathPattern -> $ClusterId" -ForegroundColor Green
}
catch {
if ($_.Exception.Response.StatusCode -eq "BadRequest") {
Write-Host " Route already exists, skipping..." -ForegroundColor Gray
}
else {
throw $_
}
}
# Step 3: Reload Config
Write-Host ""
Write-Host "[Step 3] Reloading gateway configuration..." -ForegroundColor Yellow
$reloadResponse = Invoke-RestMethod -Uri "$GatewayUrl/api/gateway/reload" -Method Post
Write-Host " ✓ Configuration reloaded" -ForegroundColor Green
# Summary
Write-Host ""
Write-Host "========================================" -ForegroundColor Cyan
Write-Host "Configuration Complete!" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
Write-Host "Service: $ServiceName" -ForegroundColor White
Write-Host "Cluster: $ClusterId" -ForegroundColor White
Write-Host "Route: $routeDescription" -ForegroundColor White
Write-Host "Pattern: $PathPattern" -ForegroundColor White
Write-Host "Target: $InstanceAddress" -ForegroundColor White
Write-Host ""
Write-Host "Test the service at:" -ForegroundColor Yellow
Write-Host " $GatewayUrl$($PathPattern.Replace('{**path}', 'campaigns'))" -ForegroundColor Cyan
Write-Host ""
}
# Execute
Register-ActivityService -GatewayUrl $GatewayUrl `
-ServiceName $ServiceName `
-ClusterId $ClusterId `
-PathPattern $PathPattern `
-InstanceAddress $InstanceAddress `
-DestinationId $DestinationId `
-Weight $Weight `
-IsGlobal $IsGlobal.IsPresent `
-TenantCode $TenantCode