* -------------------------------------------------------------------------
* This file is part of the MindStudio project.
* Copyright (c) 2025 Huawei Technologies Co.,Ltd.
*
* MindStudio is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
*
* http://license.coscl.org.cn/MulanPSL2
*
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* -------------------------------------------------------------------------
*/
import { message as Message } from 'antd';
import { runInAction } from 'mobx';
import i18n from '@insight/lib/i18n';
import connector from '@/connection';
import { GLOBAL_HOST } from '@/centralServer/websocket/defs';
import { ClusterFile, File } from '@/entity/session';
import { store } from '@/store';
import { cancelBaseline, setBaseline } from '@/utils/Request';
import { sendClusterBaselineStatus } from '@/connection/sendNotification';
import { notNull } from '@insight/lib/utils';
import { getRankInfo } from '@/utils/Rank';
export interface CompareData extends File {
rankId: string;
dbPath?: string;
host?: string;
cardName?: string;
isCluster?: boolean;
}
export interface TimelineCard {
cardName: string;
cardPath: string;
host: string;
rankId: string;
dbPath?: string;
result: boolean;
}
const sendTabAddBaseline = function(dataSource: any, baseLine: TimelineCard[]): void {
connector.send({
event: 'baseline/add',
body: { dataSource, baseLine },
});
};
export const sendTabRemoveBaseline = function(dataSource: any, singleDataPath: string): void {
connector.send({
event: 'baseline/remove',
body: { dataSource, singleDataPath },
});
};
* 设置基线数据
* @param projectName 工程名
* @param fileType 文件类型
* @param filePath 路径
* @param baselineClusterPath 基线项目的集群路径
* @param selectedClusterPath 当前选中项目的集群路径
*/
export const setBaselineData = async ({ projectName, fileType, filePath, rankId, baselineClusterPath, currentClusterPath }: ClusterFile): Promise<void> => {
const session = store.sessionStore.activeSession;
await cancelBaselineData();
const result = await setBaseline({ projectName, fileType, filePath, rankId, baselineClusterPath, currentClusterPath });
const isProject = projectName !== '' && fileType === 'PROJECT';
const isClusterCompare = isProject || result.isCluster === true;
if (notNull(result.errorMessage) || notNull(result?.error?.code)) {
Message.warning(result.errorMessage as string ?? result.error?.code);
} else if (isClusterCompare) {
handleClusterCompare({ projectName, fileType, filePath, ...result } as CompareData);
} else {
const { rankId: resultRankId, dbPath, cardName, host } = result as CompareData;
const timelineCard: TimelineCard = {
rankId: resultRankId,
dbPath,
result: true,
cardName: cardName ?? '',
host: host ?? '',
cardPath: filePath,
};
const dataSourceForTimeline = { ...GLOBAL_HOST, projectName, dataPath: [filePath] };
sendTabAddBaseline(dataSourceForTimeline, [timelineCard]);
runInAction(() => {
session.compareSet.baseline = { projectName, fileType, filePath, rankId: resultRankId };
});
}
};
* 集群对比
*/
const handleClusterCompare = async(data: CompareData): Promise<void> => {
const session = store.sessionStore.activeSession;
const { activeDataSource } = session;
if (activeDataSource.projectName === '') {
Message.warning(i18n.t('Open a Project as Comparison Data', { ns: 'framework' }));
return;
}
if (!data.isCluster) {
Message.warning(i18n.t('No cluster data available in Baseline', { ns: 'framework' }));
return;
}
if (!session.isCluster) {
Message.warning(i18n.t('No cluster data available in Comparison', { ns: 'framework' }));
return;
}
runInAction(() => {
session.compareSet.baseline = { projectName: data.projectName, fileType: data.fileType, filePath: data.filePath, rankId: '' };
});
sendClusterBaselineStatus(true);
};
export const isInClusterCompare = (): boolean => {
const session = store.sessionStore.activeSession;
const { projectName, rankId } = session.compareSet.baseline;
return projectName !== '' && rankId === '';
};
* 取消基线数据
*/
export const cancelBaselineData = async (): Promise<void> => {
const session = store.sessionStore.activeSession;
const { projectName, filePath } = session.compareSet.baseline;
const dataSourceForTimeline = { ...GLOBAL_HOST, projectName, dataPath: [filePath] };
sendTabRemoveBaseline(dataSourceForTimeline, filePath);
sendClusterBaselineStatus(false);
await cancelBaseline({ projectName, filePath });
runInAction(() => {
session.compareSet = {
baseline: { projectName: '', fileType: 'UNKNOWN', filePath: '', rankId: '' },
comparison: { projectName: '', fileType: 'UNKNOWN', filePath: '', rankId: '' },
};
});
};
* 设置对比数据
* @param projectName 工程名
* @param fileType 文件类型
* @param filePath 路径
* @param rankId 卡ID clusterId+host+realRankId+deviceId
*/
export const setCompareData = ({ projectName, fileType, filePath, rankId }: File): void => {
const session = store.sessionStore.activeSession;
const { activeDataSource } = session;
if (projectName !== activeDataSource.projectName) {
Message.warning(i18n.t('Set Comparsion Data Out Of Range', { ns: 'framework' }));
return;
};
if (fileType === 'PROJECT' || fileType === 'CLUSTER') {
runInAction(() => {
session.compareSet.comparison = {
projectName,
fileType,
filePath,
rankId: '',
host: '',
cardName: '',
};
});
} else {
runInAction(() => {
const rank = getRankInfo({ projectName, filePath, rankId });
session.compareSet.comparison = {
projectName,
fileType,
filePath,
rankId: rank?.rankId ?? '',
host: rank?.host ?? '',
cardName: rank?.cardName ?? '',
};
});
}
};
* 取消对比数据
*/
export const cancelCompareData = (): void => {
const session = store.sessionStore.activeSession;
runInAction(() => {
session.compareSet.comparison = { projectName: '', fileType: 'UNKNOWN', filePath: '', rankId: '' };
});
sendClusterBaselineStatus(false);
};
* 更新对比数据
* @param oldProjectName 原工程名
* @param newProjectName 新工程名
*/
export const updateProjectNameHandler = (oldProjectName: string, newProjectName: string): void => {
const session = store.sessionStore.activeSession;
runInAction(() => {
const { compareSet } = session;
if (compareSet.baseline.projectName === oldProjectName) {
compareSet.baseline.projectName = newProjectName;
}
if (compareSet.comparison.projectName === oldProjectName) {
compareSet.comparison.projectName = newProjectName;
}
});
};