1 В избранное 0 Ответвления 0

OSCHINA-MIRROR/didiopensource-KnowStreaming

Присоединиться к Gitlife
Откройте для себя и примите участие в публичных проектах с открытым исходным кодом с участием более 10 миллионов разработчиков. Приватные репозитории также полностью бесплатны :)
Присоединиться бесплатно
Это зеркальный репозиторий, синхронизируется ежедневно с исходного репозитория.
Клонировать/Скачать
admin.ts 21 КБ
Копировать Редактировать Исходные данные Просмотреть построчно История
zengqiao Отправлено 4 лет назад 447a575
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782
import { observable, action } from 'mobx';
import { INewBulidEnums, ILabelValue, IClusterReal, IOptionType, IClusterMetrics, IClusterTopics, IKafkaFiles, IMetaData, IConfigure, IBrokerData, IOffset, IController, IBrokersBasicInfo, IBrokersStatus, IBrokersTopics, IBrokersPartitions, IBrokersAnalysis, IAnalysisTopicVO, IBrokersMetadata, IBrokersRegions, IThrottles, ILogicalCluster, INewRegions, INewLogical, ITaskManage, IPartitionsLocation, ITaskType, ITasksEnums, ITasksMetaData, ITaskStatusDetails, IKafkaRoles, IEnumsMap, IStaffSummary, IBill, IBillDetail } from 'types/base-type';
import {
deleteCluster,
getBasicInfo,
getClusterRealTime,
getClusterMetrice,
getClusterTopics,
getTopicsBasicInfo,
getTasksKafkaFiles,
getMetaData,
getConfigure,
addNewConfigure,
editConfigure,
deleteConfigure,
getDataCenter,
getClusterBroker,
getClusterConsumer,
getControllerHistory,
getConsumerDetails,
getBrokersBasicInfo,
getPeakFlowStatus,
getBrokersStatus,
getBrokersMetrics,
getBrokersTopics,
getBrokersPartitions,
getBrokersAnalysis,
getBrokersMetricsHistory,
getBrokersMetadata,
getBrokersRegions,
addNewRegions,
editRegions,
getLogicalClusters,
queryLogicalClusters,
createLogicalClusters,
editLogicalClusters,
deteleLogicalClusters,
getClustersThrottles,
getTaskManagement,
getPartitionsLocation,
getClusterTasksEnums,
getTasksMetadata,
getSubtasksStatus,
getClusterTaskLog,
newlyBuildEcmTasks,
getConfigsTaskStatus,
getConfigsKafkaRoles,
deteleClusterBrokers,
getStaffSummary,
getBillStaffSummary,
getBillStaffDetail,
} from 'lib/api';
import { getControlMetricOption, getClusterMetricOption } from 'lib/line-charts-config';
import { copyValueMap } from 'constants/status-map';
import { getPieChartOption } from 'lib/bar-pie-config';
import { getBillBarOption } from 'lib/bar-pie-config';
import { transBToMB } from 'lib/utils';
import moment from 'moment';
import { timestore } from './time';
class Admin {
@observable
public loading: boolean = false;
@observable
public realClusterLoading: boolean = true;
@observable
public realBrokerLoading: boolean = false;
@observable
public basicInfo: IMetaData = null;
@observable
public clusterRealData: IClusterReal = null;
@observable
public clusterMetrics: IClusterMetrics[] = [];
@observable
public clusterTopics: IClusterTopics[] = [];
@observable
public topicsBasic: IClusterTopics = null;
@observable
public packageList = [] as IKafkaFiles[];
@observable
public serverPropertiesList = [] as IKafkaFiles[];
@observable
public metaList: IMetaData[] = [];
@observable
public configureList: IConfigure[] = [];
@observable
public dataCenterList: string[] = [];
@observable
public clusterBroker: IBrokerData[] = [];
@observable
public consumerData: IOffset[] = [];
@observable
public brokersBasicInfo: IBrokersBasicInfo;
@observable
public peakFlowStatusList: IEnumsMap[];
@observable
public peakValueMap = [] as string[];
@observable
public bytesInStatus: number[];
@observable
public replicaStatus: number[];
@observable
public peakValueList = [] as ILabelValue[];
@observable
public copyValueList = [] as ILabelValue[];
@observable
public brokersStatus: IBrokersStatus;
@observable
public brokersMetrics: IClusterReal;
@observable
public brokersMetricsHistory: IClusterMetrics[];
@observable
public brokersTopics: IBrokersTopics[];
@observable
public controllerHistory: IController[] = [];
@observable
public brokersPartitions: IBrokersPartitions[] = [];
@observable
public brokersAnalysis: IBrokersAnalysis;
@observable
public brokersAnalysisTopic: IAnalysisTopicVO[] = [];
@observable
public brokersMetadata: IBrokersMetadata[] = [];
@observable
public brokersRegions: IBrokersRegions[] = [];
@observable
public logicalClusters: ILogicalCluster[] = [];
@observable
public queryLogical: ILogicalCluster;
@observable
public regionIdList: number[] = [];
@observable
public clustersThrottles: IThrottles[] = [];
@observable
public partitionsLocation: IPartitionsLocation[] = [];
@observable
public taskManagement: ITaskManage[] = [];
@observable
public taskType: ITaskType;
@observable
public tasksEnums: ITasksEnums[];
@observable
public configsTaskStatus: IEnumsMap[];
@observable
public staffSummary: IStaffSummary[];
@observable
public billStaff: IBill[];
@observable
public billDetailStaffData: IBillDetail[] = [];
@observable
public tasksMetaData: ITasksMetaData;
@observable
public taskStatusDetails: ITaskStatusDetails;
@observable
public clusterTaskLog: string;
@observable
public kafkaRoles: IKafkaRoles[];
@observable
public controlType: IOptionType = 'byteIn/byteOut' ;
@observable
public type: IOptionType = 'byteIn/byteOut' ;
@observable
public currentClusterId = null as number;
@action.bound
public setLoading(value: boolean) {
this.loading = value;
}
@action.bound
public getRealClusterLoading(value: boolean) {
this.realClusterLoading = value;
}
@action.bound
public setRealBrokerLoading(value: boolean) {
this.realBrokerLoading = value;
}
@action.bound
public setRegionIdList(value: number[]) {
this.regionIdList = value;
}
@action.bound
public setBasicInfo(data: IMetaData) {
this.basicInfo = data;
}
@action.bound
public setClusterRealTime(data: IClusterReal) {
this.clusterRealData = data;
this.getRealClusterLoading(false);
}
@action.bound
public changeType(controlType: IOptionType) {
this.controlType = controlType;
return getControlMetricOption(controlType, this.clusterMetrics);
}
@action.bound
public setClusterMetrice(data: IClusterMetrics[]) {
this.clusterMetrics = data;
return this.changeType(this.controlType);
}
@action.bound
public setClusterTopics(data: IClusterTopics[]) {
this.clusterTopics = data ? data.map((item, index) => {
item.key = index;
return item;
}) : [];
this.setLoading(false);
}
@action.bound
public setTopicsBasicInfo(data: IClusterTopics) {
return this.topicsBasic = data;
}
@action.bound
public setTasksKafkaFiles(data: IKafkaFiles[]) {
this.packageList = (data.filter(ele => ele.fileType === 0)).map((item => {
return {
...item,
label: item.fileName,
value: item.fileName + ',' + item.fileMd5,
};
}));
this.serverPropertiesList = (data.filter(ele => ele.fileType === 1)).map((item => {
return {
...item,
label: item.fileName,
value: item.fileName + ',' + item.fileMd5,
};
}));
}
@action.bound
public setMetaList(data: IMetaData[]) {
this.setLoading(false);
this.metaList = data ? data.map((item, index) => {
item.key = index;
return item;
}) : [];
}
@action.bound
public setConfigure(data: IConfigure[]) {
this.configureList = data ? data.map((item, index) => {
item.key = index;
return item;
}) : [];
}
@action.bound
public setDataCenter(data: string[]) {
this.dataCenterList = data || [];
}
@action.bound
public setClusterBroker(data: IBrokerData[]) {
this.clusterBroker = data ? data.map((item, index) => {
item.key = index;
return item;
}) : [];
}
@action.bound
public setClusterConsumer(data: IOffset[]) {
this.consumerData = data ? data.map((item, index) => {
item.key = index;
return item;
}) : [];
}
@action.bound
public setControllerHistory(data: IController[]) {
this.controllerHistory = data ? data.map((item, index) => {
item.key = index;
return item;
}) : [];
}
@action.bound
public setBrokersBasicInfo(data: IBrokersBasicInfo) {
this.brokersBasicInfo = data;
}
@action.bound
public setPeakFlowStatus(data: IEnumsMap[]) {
this.peakFlowStatusList = data;
data.forEach((ele: IEnumsMap) => {
this.peakValueMap.push(ele.message);
});
}
@action.bound
public setBrokersStatus(data: IBrokersStatus) {
this.brokersStatus = data;
this.bytesInStatus = data.brokerBytesInStatusList.slice(1);
const peakValueMap = this.peakValueMap.slice(1);
this.replicaStatus = data.brokerReplicaStatusList.slice(1);
this.bytesInStatus.forEach((item, index) => {
this.peakValueList.push({ name: peakValueMap[index], value: item});
});
this.replicaStatus.forEach((item, index) => {
this.copyValueList.push({name: copyValueMap[index], value: item});
});
}
@action.bound
public setBrokersMetrics(data: IClusterReal) {
this.brokersMetrics = data;
this.setRealBrokerLoading(false);
}
@action.bound
public changeBrokerType(type: IOptionType) {
this.type = type;
return getClusterMetricOption(type, this.brokersMetricsHistory);
}
@action.bound
public setBrokersMetricsHistory(data: IClusterMetrics[]) {
this.brokersMetricsHistory = data;
return this.changeBrokerType(this.type);
}
@action.bound
public setBrokersHistoryList(data: IClusterMetrics[]) {
this.brokersMetricsHistory = data;
}
@action.bound
public setBrokersTopics(data: IBrokersTopics[]) {
this.brokersTopics = data ? data.map((item, index) => {
item.key = index;
return item;
}) : [];
}
@action.bound
public setBrokersPartitions(data: IBrokersPartitions[]) {
this.brokersPartitions = data ? data.map((item, index) => {
item.key = index;
return item;
}) : [];
}
@action.bound
public setBrokersAnalysis(data: IBrokersAnalysis) {
data.bytesIn = transBToMB(data.bytesIn) as number;
data.bytesOut = transBToMB(data.bytesOut) as number;
this.brokersAnalysis = data;
this.brokersAnalysisTopic = data.topicAnalysisVOList ?
data.topicAnalysisVOList.map((item: IAnalysisTopicVO, index: number) => {
item.key = index;
return item;
}) : [];
}
@action.bound
public setBrokersMetadata(data: IBrokersMetadata[]) {
this.brokersMetadata = data ? data.map((item, index) => {
item.key = index;
return {
...item,
text: `${item.host} (BrokerID:${item.brokerId})`,
label: item.host,
value: item.brokerId,
};
}) : [];
}
@action.bound
public setBrokersRegions(data: IBrokersRegions[]) {
const regions = data ? data.map((item, index) => {
item.key = index;
const capacity = transBToMB(item.capacity) as number;
const estimateUsed = transBToMB(item.estimateUsed) as number;
const surplus = capacity - estimateUsed;
const text = `${item.name}(总容量${capacity} MB, 已使用${estimateUsed.toFixed(2)} MB, 剩余${surplus.toFixed(2)} MB)`;
const isCapacityFull = item.status === 1 ? `<容量已满>${text}` : text;
return {
...item,
label: isCapacityFull,
value: item.id,
surplus,
};
}) : [];
regions.sort((a, b) => a.surplus < b.surplus ? 1 : -1);
const filterRegions = [] as any;
if (this.regionIdList && this.regionIdList.length) {
regions.forEach(ele => {
this.regionIdList.forEach(t => {
if (ele.id === t) {
filterRegions.push(ele);
}
});
});
}
this.brokersRegions = filterRegions.length ? filterRegions : regions;
return this.brokersRegions;
}
@action.bound
public setLogicalClusters(data: ILogicalCluster[]) {
this.logicalClusters = data ? data.map((item, index) => {
item.key = index;
return item;
}) : [];
}
@action.bound
public setQueryLogical(data: ILogicalCluster) {
this.queryLogical = data;
}
@action.bound
public setClustersThrottles(data: IThrottles[]) {
this.clustersThrottles = data ? data.map((item, index) => {
item.key = index;
return item;
}) : [];
}
@action.bound
public setPartitionsLocation(data: IPartitionsLocation[]) {
this.partitionsLocation = data ? data.map((item, index) => {
item.key = index;
return item;
}) : [];
}
@action.bound
public setTaskManagement(data: ITaskManage[]) {
this.taskManagement = data ? data.map((item, index) => {
item.key = index;
return item;
}) : [];
}
@action.bound
public setClusterTasksEnums(data: ITaskType) {
this.tasksEnums = data.taskType.map(ele => {
return {
...ele,
label: ele.message,
value: ele.name,
};
});
}
@action.bound
public setTasksMetadata(data: ITasksMetaData) {
this.tasksMetaData = data;
}
@action.bound
public setSubtasksStatus(data: ITaskStatusDetails) {
this.taskStatusDetails = data;
}
@action.bound
public setClusterTaskLog(data: string) {
this.clusterTaskLog = data;
}
@action.bound
public setConfigsKafkaRoles(data: IKafkaRoles[]) {
this.kafkaRoles = data;
}
@action.bound
public setConfigsTaskStatus(data: IEnumsMap[]) {
this.configsTaskStatus = data;
}
@action.bound
public setStaffSummary(data: IStaffSummary[]) {
this.staffSummary = data ? data.map((item, index) => {
item.key = index;
return item;
}) : [];
}
@action.bound
public setBillStaffSummary(data: IBill[] = []) {
this.loading = false;
if (data) {
this.billStaff = data.map((item, index) => ({
...item,
cost: +item.cost.toFixed(2),
key: index,
}));
}
return getBillBarOption(this.billStaff);
}
@action.bound
public setBillStaffDetail(data: any) {
this.loading = false;
const billList = data.billList || [] as IBill[];
this.billDetailStaffData = billList.map((item: IBill, index: number) => ({
...item,
cost: +item.cost.toFixed(2),
key: index,
}));
}
public deleteCluster(clusterId: number) {
return deleteCluster(clusterId).then(() => this.getMetaData(true));
}
public getPeakFlowChartData(value: ILabelValue[], map: string []) {
return getPieChartOption(value, map);
}
public getSideStatusChartData(value: ILabelValue[]) {
return getPieChartOption(value, copyValueMap);
}
public getBasicInfo(clusterId: number) {
return getBasicInfo(clusterId).then(this.setBasicInfo);
}
public getClusterRealTime(clusterId: number) {
this.getRealClusterLoading(true);
return getClusterRealTime(clusterId).then(this.setClusterRealTime);
}
public getClusterMetrice(clusterId: number) {
return getClusterMetrice(clusterId,
timestore.startTime.format('x'),
timestore.endTime.format('x')).then(this.setClusterMetrice);
}
public getClusterTopics(clusterId: number) {
this.setLoading(true);
return getClusterTopics(clusterId).then(this.setClusterTopics);
}
public getTopicsBasicInfo(clusterId: number, topicName: string) {
return getTopicsBasicInfo(clusterId, topicName).then(data => {
return this.setTopicsBasicInfo(data);
});
}
public getTasksKafkaFiles(clusterId?: any) {
return getTasksKafkaFiles(clusterId || '').then(this.setTasksKafkaFiles);
}
public getMetaData(needDetail: boolean) {
this.setLoading(true);
getMetaData(needDetail).then(this.setMetaList);
}
public getConfigure() {
getConfigure().then(this.setConfigure);
}
public addNewConfigure(params: IConfigure) {
return addNewConfigure(params).then(() => this.getConfigure());
}
public editConfigure(params: IConfigure) {
return editConfigure(params).then(() => this.getConfigure());
}
public deleteConfigure(configKey: string) {
deleteConfigure(configKey).then(() => this.getConfigure());
}
public getDataCenter() {
getDataCenter().then(this.setDataCenter);
}
public getClusterBroker(clusterId: number) {
return getClusterBroker(clusterId).then(this.setClusterBroker);
}
public getClusterConsumer(clusterId: number) {
return getClusterConsumer(clusterId).then(this.setClusterConsumer);
}
public getControllerHistory(clusterId: number) {
return getControllerHistory(clusterId).then(this.setControllerHistory);
}
public getBrokersBasicInfo(clusterId: number, brokerId: number) {
return getBrokersBasicInfo(clusterId, brokerId).then(this.setBrokersBasicInfo);
}
public getPeakFlowStatus() {
return getPeakFlowStatus().then(this.setPeakFlowStatus);
}
public getBrokersStatus(clusterId: number) {
return getBrokersStatus(clusterId).then(this.setBrokersStatus);
}
public getBrokersMetrics(clusterId: number, brokerId: number) {
this.setRealBrokerLoading(true);
return getBrokersMetrics(clusterId, brokerId).then(this.setBrokersMetrics);
}
public getBrokersMetricsHistory(clusterId: number, brokerId: number) {
return getBrokersMetricsHistory(clusterId, brokerId,
timestore.startTime.format('x'), timestore.endTime.format('x')).then(this.setBrokersMetricsHistory);
}
// tslint:disable-next-line:max-line-length
public getBrokersHistoryList(clusterId: number, brokerId: number, startTime: string, endTime: string) {
return getBrokersMetricsHistory(clusterId, brokerId, startTime, endTime).then(
(data: IClusterMetrics[]) => this.setBrokersHistoryList(data));
}
public getBrokersTopics(clusterId: number, brokerId: number) {
return getBrokersTopics(clusterId, brokerId).then(this.setBrokersTopics);
}
public getBrokersPartitions(clusterId: number, brokerId: number) {
this.setRealBrokerLoading(true);
return getBrokersPartitions(clusterId, brokerId).then(this.setBrokersPartitions).finally(() => this.setRealBrokerLoading(false));
}
public getBrokersAnalysis(clusterId: number, brokerId: number) {
return getBrokersAnalysis(clusterId, brokerId).then(this.setBrokersAnalysis);
}
public getBrokersMetadata(clusterId: number) {
return getBrokersMetadata(clusterId).then(this.setBrokersMetadata);
}
public getBrokersRegions(clusterId: number) {
return getBrokersRegions(clusterId).then(this.setBrokersRegions);
}
public addNewRegions(clusterId: number, params: INewRegions) {
return addNewRegions(params).then(() => this.getBrokersRegions(clusterId));
}
public editRegions(clusterId: number, params: INewRegions) {
return editRegions(params).then(() => this.getBrokersRegions(clusterId));
}
public getLogicalClusters(clusterId: number) {
return getLogicalClusters(clusterId).then(this.setLogicalClusters);
}
public queryLogicalClusters(clusterId: number) {
return queryLogicalClusters(clusterId).then(this.setQueryLogical);
}
public createLogicalClusters(clusterId: number, params: INewLogical) {
return createLogicalClusters(params).then(() => this.getLogicalClusters(clusterId));
}
public editLogicalClusters(clusterId: number, params: INewLogical) {
return editLogicalClusters(params).then(() => this.getLogicalClusters(clusterId));
}
public deteleLogicalClusters(clusterId: number, id: number) {
return deteleLogicalClusters(id).then(() => this.getLogicalClusters(clusterId));
}
public getClustersThrottles(clusterId: number) {
return getClustersThrottles(clusterId).then(this.setClustersThrottles);
}
public getPartitionsLocation(clusterId: number, brokerId: number) {
return getPartitionsLocation(clusterId, brokerId).then(this.setPartitionsLocation);
}
public getTaskManagement() {
return getTaskManagement().then(this.setTaskManagement);
}
public getClusterTasksEnums() {
return getClusterTasksEnums().then(this.setClusterTasksEnums);
}
public getTasksMetadata(taskId: number) {
return getTasksMetadata(taskId).then(this.setTasksMetadata);
}
public getSubtasksStatus(taskId: number) {
return getSubtasksStatus(taskId).then(this.setSubtasksStatus);
}
public getClusterTaskLog(taskId: number, hostname: string) {
return getClusterTaskLog(taskId, hostname).then(this.setClusterTaskLog);
}
public getConfigsKafkaRoles() {
return getConfigsKafkaRoles().then(this.setConfigsKafkaRoles);
}
public addMigrationTask(params: INewBulidEnums) {
return newlyBuildEcmTasks(params).then(() => this.getTaskManagement());
}
public getConfigsTaskStatus() {
return getConfigsTaskStatus().then(this.setConfigsTaskStatus);
}
public deteleClusterBrokers(clusterId: number, brokerId: number) {
return deteleClusterBrokers(clusterId, brokerId).then(() => this.getClusterBroker(clusterId));
}
public getStaffSummary(timestamp: number) {
return getStaffSummary(timestamp).then(this.setStaffSummary);
}
public getBillStaffList(username: string, startTime: number, endTime: number) {
this.setLoading(true);
return getBillStaffSummary(username, startTime, endTime).then(this.setBillStaffSummary);
}
public getBillDetailStaffList(username: string, timestamp: number) {
this.setLoading(true);
return getBillStaffDetail(username, timestamp).then(this.setBillStaffDetail);
}
}
export const admin = new Admin();

Комментарий ( 0 )

Вы можете оставить комментарий после Вход в систему

1
https://gitlife.ru/oschina-mirror/didiopensource-KnowStreaming.git
git@gitlife.ru:oschina-mirror/didiopensource-KnowStreaming.git
oschina-mirror
didiopensource-KnowStreaming
didiopensource-KnowStreaming
v2.1.0