* feat(mq): implement Apache Pulsar message queue admin - Add complete MQ admin adapter layer with version detection * Pulsar adapter with multi-version API support * OAuth2 token caching and authentication * JWT token signing for Pulsar clients * Transport layer (SSH/Proxy) integration - Implement comprehensive admin operations * Tenant, namespace, topic management * Subscription and consumer/producer monitoring * Rate limits, backlog quotas, retention policies * Permissions and role-based access control * Raw admin API for advanced operations - Add desktop UI components * MQ admin console with tabbed interface * Tenant, namespace, topic panels * Subscription management and cursor operations * Monitoring panel with stats visualization * Policy configuration UI - Add web routes for MQ admin operations - Add secret store support for MQ auth credentials - Add comprehensive test coverage * fix: del local test files * fix(mq): mark message queue as unsupported mcpMode in driver manifest MQ admin connections do not use the MCP query bridge - they use a separate REST admin API. Mark mcpMode as 'unsupported' to align with the test expectations and reflect the actual architecture. Fixes CI test: driver-manifest.test.ts * fix(mq): fix TypeScript errors in MQ components - Fix typo in SubscriptionsPanel.vue: messagformatError(e)Id -> message.messageId - Use formatError() helper in RawApiPanel.vue instead of accessing e?.message - Fix undefined 'tab' reference in ConnectionTree.vue: use config.db_type instead Fixes frontend CI TypeScript check errors. * fix(mcp): add 'mq' to MCP server connection type description The MCP server's connection type description must include all database types from the driver manifest. Add 'mq' to the list to fix the test: 'add connection database type description includes every manifest database type' Fixes: packages/mcp-server/tests/driver-manifest.test.ts * fix(mq): add missing ConnectionConfig fields for Rust compilation - Add gbase_server and keepalive_interval_secs fields to all ConnectionConfig test constructors in mq/config.rs, mq/service.rs, and storage.rs - Import uses_bare_mysql_pool in connection.rs tests module Fixes compilation errors from upstream ConnectionConfig changes. * chore(ui): simplify Pulsar icon to logo-only version Remove text from Pulsar icon (127x30 -> 35x30), keeping only the wave logo symbol for a cleaner, more consistent appearance with other database icons. * fix(mq): return removed pools from drain_connection_pools --------- Co-authored-by: t8y2 <1156263951@qq.com>
138 lines
5.6 KiB
TypeScript
138 lines
5.6 KiB
TypeScript
import type { BacklogQuota, DispatchRate, PublishRate, RetentionPolicy, SubscribeRate } from "@/types/mq";
|
|
|
|
export interface MqPolicyForms {
|
|
publishForm: PublishRate;
|
|
dispatchForm: DispatchRate;
|
|
subscribeForm: SubscribeRate;
|
|
backlogForm: BacklogQuota;
|
|
retentionForm: RetentionPolicy;
|
|
}
|
|
|
|
export function defaultMqPolicyForms(): MqPolicyForms {
|
|
return {
|
|
publishForm: {
|
|
publishThrottlingRateInMsg: 0,
|
|
publishThrottlingRateInByte: 0,
|
|
},
|
|
dispatchForm: {
|
|
dispatchThrottlingRateInMsg: 0,
|
|
dispatchThrottlingRateInByte: 0,
|
|
ratePeriodInSecond: 1,
|
|
},
|
|
subscribeForm: {
|
|
subscribeThrottlingRatePerConsumer: 0,
|
|
ratePeriodInSecond: 1,
|
|
},
|
|
backlogForm: {
|
|
limitSize: -1,
|
|
limitTime: -1,
|
|
policy: "producer_request_hold",
|
|
quotaType: "destination_storage",
|
|
},
|
|
retentionForm: {
|
|
retentionTimeInMinutes: -1,
|
|
retentionSizeInMb: -1,
|
|
},
|
|
};
|
|
}
|
|
|
|
export function policyFormsFromEffectivePolicies(raw: unknown, fallback: MqPolicyForms): MqPolicyForms {
|
|
const root = objectRecord(raw);
|
|
const topicPolicies = objectRecord(root.topicPolicies);
|
|
const namespacePolicies = objectRecord(root.namespacePolicies);
|
|
const namespaceSource = Object.keys(namespacePolicies).length ? namespacePolicies : root;
|
|
|
|
const publish = firstRecord(topicPolicies.publishRate, root.publishRate, namespaceSource.publishRate, namespaceSource.publishMaxMessageRate);
|
|
const dispatch = firstRecord(topicPolicies.dispatchRate, root.dispatchRate, namespaceSource.dispatchRate);
|
|
const subscribe = firstRecord(topicPolicies.subscribeRate, root.subscribeRate, namespaceSource.subscribeRate);
|
|
const backlog = normalizeBacklogQuota(firstDefined(topicPolicies.backlogQuota, root.backlogQuota, namespaceSource.backlogQuota, namespaceSource.backlogQuotaMap, namespaceSource.backlog_quota_map));
|
|
const retention = firstRecord(topicPolicies.retention, root.retention, namespaceSource.retention, namespaceSource.retentionPolicies, namespaceSource.retention_policies);
|
|
|
|
return {
|
|
publishForm: publish
|
|
? {
|
|
publishThrottlingRateInMsg: numberField(publish.publishThrottlingRateInMsg) ?? fallback.publishForm.publishThrottlingRateInMsg,
|
|
publishThrottlingRateInByte: numberField(publish.publishThrottlingRateInByte) ?? fallback.publishForm.publishThrottlingRateInByte,
|
|
}
|
|
: { ...fallback.publishForm },
|
|
dispatchForm: dispatch
|
|
? {
|
|
dispatchThrottlingRateInMsg: numberField(dispatch.dispatchThrottlingRateInMsg) ?? fallback.dispatchForm.dispatchThrottlingRateInMsg,
|
|
dispatchThrottlingRateInByte: numberField(dispatch.dispatchThrottlingRateInByte) ?? fallback.dispatchForm.dispatchThrottlingRateInByte,
|
|
ratePeriodInSecond: numberField(dispatch.ratePeriodInSecond) ?? fallback.dispatchForm.ratePeriodInSecond,
|
|
}
|
|
: { ...fallback.dispatchForm },
|
|
subscribeForm: subscribe
|
|
? {
|
|
subscribeThrottlingRatePerConsumer: numberField(subscribe.subscribeThrottlingRatePerConsumer) ?? fallback.subscribeForm.subscribeThrottlingRatePerConsumer,
|
|
ratePeriodInSecond: numberField(subscribe.ratePeriodInSecond) ?? fallback.subscribeForm.ratePeriodInSecond,
|
|
}
|
|
: { ...fallback.subscribeForm },
|
|
backlogForm: backlog
|
|
? {
|
|
limitSize: numberField(backlog.limitSize) ?? numberField(backlog.limit) ?? fallback.backlogForm.limitSize,
|
|
limitTime: numberField(backlog.limitTime) ?? fallback.backlogForm.limitTime,
|
|
policy: stringField(backlog.policy) || fallback.backlogForm.policy,
|
|
quotaType: stringField(backlog.quotaType) || fallback.backlogForm.quotaType,
|
|
}
|
|
: { ...fallback.backlogForm },
|
|
retentionForm: retention
|
|
? {
|
|
retentionTimeInMinutes: numberField(retention.retentionTimeInMinutes) ?? fallback.retentionForm.retentionTimeInMinutes,
|
|
retentionSizeInMb: numberField(retention.retentionSizeInMb) ?? numberField(retention.retentionSizeInMB) ?? fallback.retentionForm.retentionSizeInMb,
|
|
}
|
|
: { ...fallback.retentionForm },
|
|
};
|
|
}
|
|
|
|
function normalizeBacklogQuota(value: unknown): Record<string, unknown> | undefined {
|
|
const quota = objectRecord(value);
|
|
if (!Object.keys(quota).length) return undefined;
|
|
if (hasQuotaFields(quota)) return quota;
|
|
|
|
const entries = Object.entries(quota);
|
|
for (const [quotaType, body] of entries) {
|
|
const normalized = objectRecord(body);
|
|
if (hasQuotaFields(normalized)) {
|
|
return {
|
|
...normalized,
|
|
quotaType: normalized.quotaType ?? quotaType,
|
|
};
|
|
}
|
|
}
|
|
return undefined;
|
|
}
|
|
|
|
function hasQuotaFields(value: Record<string, unknown>): boolean {
|
|
return "limit" in value || "limitSize" in value || "limitTime" in value || "policy" in value;
|
|
}
|
|
|
|
function firstRecord(...values: unknown[]): Record<string, unknown> | undefined {
|
|
for (const value of values) {
|
|
const record = objectRecord(value);
|
|
if (Object.keys(record).length) return record;
|
|
}
|
|
return undefined;
|
|
}
|
|
|
|
function firstDefined(...values: unknown[]) {
|
|
return values.find((value) => value !== undefined && value !== null);
|
|
}
|
|
|
|
function objectRecord(value: unknown): Record<string, unknown> {
|
|
return value && typeof value === "object" && !Array.isArray(value) ? (value as Record<string, unknown>) : {};
|
|
}
|
|
|
|
function numberField(value: unknown): number | undefined {
|
|
if (typeof value === "number" && Number.isFinite(value)) return value;
|
|
if (typeof value === "string" && value.trim() !== "") {
|
|
const parsed = Number(value);
|
|
return Number.isFinite(parsed) ? parsed : undefined;
|
|
}
|
|
return undefined;
|
|
}
|
|
|
|
function stringField(value: unknown): string | undefined {
|
|
return typeof value === "string" ? value : undefined;
|
|
}
|