You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by "yx9o (via GitHub)" <gi...@apache.org> on 2026/08/08 12:15:57 UTC

[PR] [Studio] feat: add resource change plan preview [rocketmq-dashboard]

yx9o opened a new pull request, #1269:
URL: https://github.com/apache/rocketmq-dashboard/pull/1269

   ## What is the purpose of the change
   
   Add a read-only Resource Plan page that previews Topic and Consumer Group bundle changes before operators apply them manually.
   
   ## Brief changelog
   
   - Added a Resource Plan page under instance management.
   - Added JSON bundle parsing and diff planning for Topic and Consumer Group resources.
   - Classifies planned changes as create, update, skip, conflict, or invalid without modifying cluster resources.
   - Added focused tests for resource plan parsing, preview logic, page rendering, and instance-scoped routing.
   
   ## Verifying this change
   
   - `npm test -- --run --api.host 127.0.0.1 src/services/resourcePlanService.test.ts src/pages/instance/__tests__/ResourcePlanPage.test.tsx src/hooks/useInstanceFilter.test.tsx`
   - `npm test -- --run --api.host 127.0.0.1`
   - `npm run build`
   - `npm run lint`
   - `npx prettier --check src/services/resourcePlanService.ts src/services/resourcePlanService.test.ts src/pages/instance/resourcePlan.tsx src/pages/instance/__tests__/ResourcePlanPage.test.tsx src/hooks/useInstanceFilter.ts src/hooks/useInstanceFilter.test.tsx src/App.tsx src/layouts/MainLayout.tsx src/i18n/translations.ts`
   - `git diff --check`


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Studio] feat: add resource change plan preview [rocketmq-dashboard]

Posted by "lizhimins (via GitHub)" <gi...@apache.org>.
lizhimins merged PR #1269:
URL: https://github.com/apache/rocketmq-dashboard/pull/1269


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Studio] feat: add resource change plan preview [rocketmq-dashboard]

Posted by "RockteMQ-AI (via GitHub)" <gi...@apache.org>.
RockteMQ-AI commented on code in PR #1269:
URL: https://github.com/apache/rocketmq-dashboard/pull/1269#discussion_r3740681610


##########
web/src/pages/instance/resourcePlan.tsx:
##########
@@ -0,0 +1,265 @@
+/*
+ * 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.
+ */
+
+import { useMemo, useState } from 'react';
+import {
+  Alert,
+  App,
+  Button,
+  Card,
+  Col,
+  Input,
+  Row,
+  Select,
+  Space,
+  Statistic,
+  Table,
+  Tag,
+  Typography,
+} from 'antd';
+import type { ColumnsType } from 'antd/es/table';
+import { PlayCircleOutlined } from '@ant-design/icons';
+import PageHeader from '../../components/PageHeader';
+import { useInstanceFilter } from '../../hooks/useInstanceFilter';
+import type { ResourcePlanEntry } from '../../services/resourcePlanService';
+import {
+  RESOURCE_PLAN_SAMPLE,
+  parseResourceBundle,
+  previewResourcePlan,
+} from '../../services/resourcePlanService';
+
+const { Text, Paragraph } = Typography;
+const { TextArea } = Input;
+
+const ACTION_COLOR: Record<string, string> = {
+  CREATE: 'green',
+  UPDATE: 'blue',
+  SKIP: 'default',
+  CONFLICT: 'orange',
+  INVALID: 'red',
+};
+
+const RESOURCE_LABEL: Record<string, string> = {
+  TOPIC: 'Topic',
+  CONSUMER_GROUP: 'Consumer Group',
+};
+
+const ResourcePlanPage = () => {
+  const { message } = App.useApp();
+  const { selectedInstanceId, selectedInstance, selectInstance, instanceOptions } =
+    useInstanceFilter();
+  const [bundleText, setBundleText] = useState(RESOURCE_PLAN_SAMPLE);
+  const [previewLoading, setPreviewLoading] = useState(false);
+  const [plan, setPlan] = useState<Awaited<ReturnType<typeof previewResourcePlan>> | null>(null);
+
+  const columns = useMemo<ColumnsType<ResourcePlanEntry>>(
+    () => [
+      {
+        title: '资源类型',
+        dataIndex: 'resourceType',
+        width: 150,
+        render: (value: ResourcePlanEntry['resourceType']) => RESOURCE_LABEL[value] ?? value,
+      },
+      {
+        title: '名称',
+        dataIndex: 'name',
+        width: 220,
+        render: (value: string) => value || <Text type="secondary">未命名</Text>,
+      },
+      {
+        title: '行号',
+        dataIndex: 'rowIndex',
+        width: 80,
+      },
+      {
+        title: '动作',
+        dataIndex: 'action',
+        width: 110,
+        render: (action: ResourcePlanEntry['action']) => (
+          <Tag color={ACTION_COLOR[action]}>{action}</Tag>
+        ),
+      },

Review Comment:
   **[Warning]** Page title, subtitle, button labels, placeholder text, and toast messages are hardcoded in Chinese instead of using the i18n `t()` function. This breaks the English locale and is inconsistent with other pages that already use `translations.ts`.



##########
web/src/services/resourcePlanService.ts:
##########
@@ -0,0 +1,395 @@
+/*
+ * 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.
+ */
+
+import { listConsumerGroups } from './consumerService';
+import { listTopics } from './topicService';
+import type { ConsumerGroup, Topic } from '../api/metadata';
+
+export type ResourcePlanResourceType = 'TOPIC' | 'CONSUMER_GROUP';
+export type ResourcePlanAction = 'CREATE' | 'UPDATE' | 'SKIP' | 'CONFLICT' | 'INVALID';
+
+export interface ResourcePlanTopicSpec {
+  name: string;
+  namespace?: string;
+  clusterId?: string;
+  type?: string;
+  writeQueues?: number;
+  readQueues?: number;
+  perm?: string;
+  remark?: string;
+}
+
+export interface ResourcePlanConsumerGroupSpec {
+  name: string;
+  namespace?: string;
+  clusterId?: string;
+  subscriptionMode?: string;
+  consumeType?: string;
+  subscribedTopics?: string[];
+  subscriptionDataType?: string;
+  deliveryOrderType?: string;
+  retryMaxTimes?: number;
+  delaySeconds?: number;
+}
+
+export interface ResourcePlanRequest {
+  instanceId: string;
+  topics?: ResourcePlanTopicSpec[];
+  consumerGroups?: ResourcePlanConsumerGroupSpec[];
+}
+
+export interface ResourcePlanChange {
+  field: string;
+  currentValue?: string | null;
+  desiredValue?: string | null;
+}
+
+export interface ResourcePlanEntry {
+  resourceType: ResourcePlanResourceType;
+  name: string;
+  rowIndex: number;
+  action: ResourcePlanAction;
+  applicable: boolean;
+  reason: string;
+  changes: ResourcePlanChange[];
+}
+
+export interface ResourcePlanSummary {
+  total: number;
+  creates: number;
+  updates: number;
+  skips: number;
+  conflicts: number;
+  invalids: number;
+  applicable: number;
+}
+
+export interface ResourcePlan {
+  instanceId: string;
+  summary: ResourcePlanSummary;
+  entries: ResourcePlanEntry[];
+}
+
+export interface ResourceBundle {
+  topics?: ResourcePlanTopicSpec[];
+  consumerGroups?: ResourcePlanConsumerGroupSpec[];
+}
+
+export const RESOURCE_PLAN_SAMPLE = JSON.stringify(
+  {
+    topics: [
+      {
+        name: 'order-status-change',
+        namespace: 'trade',
+        type: 'NORMAL',
+        writeQueues: 8,
+        readQueues: 8,
+        perm: 'RW',
+        remark: 'Order status events',
+      },
+      {
+        name: 'payment-callback',
+        namespace: 'trade',
+        type: 'FIFO',
+        writeQueues: 4,
+        readQueues: 4,
+        perm: 'RW',
+        remark: 'Payment callbacks with FIFO order',
+      },
+    ],
+    consumerGroups: [
+      {
+        name: 'cg-order-status-sync',
+        namespace: 'trade',
+        subscriptionMode: 'Push',
+        consumeType: 'CLUSTERING',
+        subscribedTopics: ['order-status-change'],
+        subscriptionDataType: 'NORMAL',
+        retryMaxTimes: 16,
+        delaySeconds: 0,
+      },
+    ],
+  },
+  null,
+  2,
+);
+
+export function parseResourceBundle(text: string): ResourceBundle {
+  let parsed: unknown;
+  try {
+    parsed = JSON.parse(text);
+  } catch {
+    throw new Error('Resource bundle must be valid JSON');
+  }
+  if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
+    throw new Error('Resource bundle must be a JSON object');
+  }
+  const bundle = parsed as ResourceBundle;
+  if (bundle.topics !== undefined && !Array.isArray(bundle.topics)) {
+    throw new Error('topics must be an array');
+  }
+  if (bundle.consumerGroups !== undefined && !Array.isArray(bundle.consumerGroups)) {
+    throw new Error('consumerGroups must be an array');
+  }
+  return {
+    topics: bundle.topics ?? [],
+    consumerGroups: bundle.consumerGroups ?? [],
+  };
+}
+
+export async function previewResourcePlan(request: ResourcePlanRequest): Promise<ResourcePlan> {
+  if (!request.instanceId?.trim()) throw new Error('instanceId is required');
+  const desiredTopics = request.topics ?? [];
+  const desiredGroups = request.consumerGroups ?? [];
+  const total = desiredTopics.length + desiredGroups.length;
+  if (total === 0) throw new Error('At least one topic or consumer group is required');
+  if (total > 200) throw new Error('Resource plan supports at most 200 resources');
+
+  const [topics, groups] = await Promise.all([
+    listTopics({ instanceId: request.instanceId }),
+    listConsumerGroups({ instanceId: request.instanceId }),

Review Comment:
   **[Warning]** `parseResourceBundle` casts parsed JSON as `ResourceBundle` without validating element shapes. A malformed `subscribedTopics` array (e.g. a string or array containing null) will cause `sortedTopics` to throw at runtime, producing a generic failure message instead of a clear validation error.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org