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

OSCHINA-MIRROR/didiopensource-KnowStreaming

Присоединиться к Gitlife
Откройте для себя и примите участие в публичных проектах с открытым исходным кодом с участием более 10 миллионов разработчиков. Приватные репозитории также полностью бесплатны :)
Присоединиться бесплатно
Это зеркальный репозиторий, синхронизируется ежедневно с исходного репозитория.
Клонировать/Скачать
topic.tsx 24 КБ
Копировать Редактировать Исходные данные Просмотреть построчно История
孙超 Отправлено 4 лет назад 47b8fe5
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777
import { wrapper } from 'store';
import { notification } from 'component/antd';
import { IQuotaModelItem, ITopic, ILimitsItem, IQuotaQuery } from 'types/base-type';
import { topic, IAppsIdInfo } from 'store/topic';
import { users } from 'store/users';
import { app } from 'store/app';
import { cluster } from 'store/cluster';
import { AppSelect } from 'container/app-select';
import { PeakFlowInput } from '../topic/peak-flow';
import { urlPrefix } from 'constants/left-menu';
import { transMBToB, transBToMB } from 'lib/utils';
import { region } from 'store';
import * as React from 'react';
import '../app/index.less';
import { modal } from 'store/modal';
import { TopicAppSelect } from '../topic/topic-app-select';
import Url from 'lib/url-parser';
import { expandRemarks, quotaRemarks } from 'constants/strategy';
export const applyTopic = () => {
const xFormModal = {
formMap: [
{
key: 'clusterId',
label: '所属集群:',
type: 'select',
options: cluster.clusterData,
rules: [{ required: true, message: '请选择' }],
attrs: {
placeholder: '请选择',
},
}, {
key: 'topicName',
label: 'Topic名称:',
attrs: {
addonBefore: region.currentRegion === 'us' || region.currentRegion === 'ru' ? `${region.currentRegion}01_` : '',
},
rules: [
{
required: true,
pattern: /^[-\w]{3,128}$/,
message: '只能包含字母、数字、下划线(_)和短划线(-),长度限制在3-128字符之间',
},
],
},
{
key: 'appId',
label: '所属应用:',
type: 'custom',
defaultValue: '',
rules: [{ required: true, message: '请选择' }],
customFormItem: <AppSelect selectData={app.data} />,
}, {
key: 'peakBytesIn',
label: '峰值流量',
type: 'custom',
rules: [{
required: true,
pattern: /^[1-9]\d*$/,
validator: (rule: any, value: any, callback: any) => {
const regexp = /^[1-9]\d*$/;
if (value.length <= 0) {
callback('流量上限不能为空');
return false;
} else if (!regexp.test(value)) {
callback('流量上限只能填写大于0的正整数');
return false;
}
return true;
},
}],
customFormItem: <PeakFlowInput />,
},
{
key: 'description',
label: '申请原因',
type: 'text_area',
rules: [{ required: true, pattern: /^.{4,}.$/s, message: '请输入至少5个字符' }],
attrs: {
placeholder: `概要描述Topic的数据源, Topic数据的生产者/消费者, Topic的申请原因及备注信息等。(最多100个字)
例如:
数据源:xxx
生产消费方:xxx
申请原因及备注:xxx`,
rows: 7,
},
},
],
formData: {},
visible: true,
title: <div><span>申请Topic</span><a className='applicationDocument' href="https://github.com/didi/Logi-KafkaManager/blob/master/docs/user_guide/resource_apply.md" target='_blank'>资源申请文档</a></div>,
okText: '确认',
// customRenderElement: <span className="tips">集群资源充足时,预计1分钟自动审批通过</span>,
isWaitting: true,
onSubmit: (value: any) => {
value.topicName = region.currentRegion === 'us' || region.currentRegion === 'ru' ?
`${region.currentRegion}01_` + value.topicName : value.topicName;
value.peakBytesIn = transMBToB(value.peakBytesIn);
const params = JSON.parse(JSON.stringify(value));
delete (params.description);
const quotaParams = {
type: 0,
applicant: users.currentUser.username,
description: value.description,
extensions: JSON.stringify(params),
};
return topic.applyTopic(quotaParams).then(data => {
window.location.href = `${urlPrefix}/user/order-detail/?orderId=${data.id}&region=${region.currentRegion}`;
})
},
onSubmitFaild: (err: any, ref: any, formData: any, formMap: any) => {
if (err.message === 'topic already existed') {
const topic = ref.getFieldValue('topicName');
ref.setFields({
topicName: {
value: topic,
errors: [new Error('该topic名称已存在')],
}
})
}
}
};
wrapper.open(xFormModal);
};
export const deferTopic = (item: ITopic) => {
const xFormModal = {
formMap: [
{
key: 'topicName',
label: 'Topic名称',
value: '',
rules: [{ required: false, disabled: true }],
attrs: {
disabled: true,
},
},
{
key: 'retainDays',
label: '延期时间',
type: 'select',
value: '',
options: [{
label: '一周',
value: '7',
}, {
label: '一月',
value: '30',
}, {
label: '三月',
value: '90',
}],
rules: [{ required: false }],
attrs: { placeholder: '请选择延期时间' },
},
],
formData: {
topicName: item.topicName,
retainDays: '',
},
visible: true,
title: '申请延期',
okText: '确认',
onSubmit: (value: any) => {
value.clusterId = item.clusterId;
topic.deferTopic(value).then(data => {
notification.success({ message: '申请延期成功' });
});
},
};
wrapper.open(xFormModal);
};
export const applyOnlineModal = (item: ITopic) => {
modal.showOfflineTopicModal(item);
};
export const showApplyQuatoModal = (item: ITopic | IAppsIdInfo, record: IQuotaQuery) => {
const isProduce = item.access === 0 || item.access === 1;
const isConsume = item.access === 0 || item.access === 2;
const xFormModal = {
formMap: [
// {
// key: 'clusterName',
// label: '逻辑集群名称',
// rules: [{ required: true, message: '' }],
// attrs: { disabled: true },
// invisible: !item.hasOwnProperty('clusterName'),
// },
{
key: 'topicName',
label: 'Topic名称',
rules: [{ required: true, message: '' }],
attrs: { disabled: true },
}, {
key: 'appId',
label: '所属应用:',
defaultValue: '',
rules: [{ required: true, message: '请输入' }],
attrs: { disabled: true },
}, {
key: 'produceQuota',
label: '申请发送数据速率',
attrs: {
disabled: isProduce,
placeholder: '请输入',
suffix: 'MB/s',
},
rules: [{
required: !isProduce,
message: '请输入',
}],
}, {
key: 'consumeQuota',
label: '申请消费数据速率',
attrs: {
disabled: isConsume,
placeholder: '请输入',
suffix: 'MB/s',
},
rules: [{
required: !isConsume,
message: '请输入',
}],
}, {
key: 'description',
label: '申请原因',
type: 'text_area',
rules: [{ required: true, pattern: /^.{4,}.$/, message: quotaRemarks }],
attrs: {
placeholder: quotaRemarks,
},
}],
formData: {
clusterName: item.clusterName,
topicName: record.topicName || item.topicName,
appId: record.appId || item.appId,
produceQuota: transBToMB(record.produceQuota),
consumeQuota: transBToMB(record.consumeQuota),
},
okText: '确认',
visible: true,
title: '申请配额',
onSubmit: (value: any) => {
const quota = {} as IQuotaModelItem;
Object.assign(quota, {
clusterId: record.clusterId || item.clusterId,
topicName: record.topicName || item.topicName,
appId: record.appId || item.appId,
consumeQuota: transMBToB(value.consumeQuota),
produceQuota: transMBToB(value.produceQuota),
});
if (item.isPhysicalClusterId) {
Object.assign(quota, {
isPhysicalClusterId: true,
});
}
const quotaParams = {
type: 2,
applicant: users.currentUser.username,
description: value.description,
extensions: JSON.stringify(quota),
};
topic.applyQuota(quotaParams).then((data) => {
notification.success({ message: '申请配额成功' });
window.location.href = `${urlPrefix}/user/order-detail/?orderId=${data.id}&region=${region.currentRegion}`;
});
},
};
wrapper.open(xFormModal);
};
let permission: number = null;
const updateFormModal = (appId: string) => {
const formMap = wrapper.xFormWrapper.formMap;
const formData = wrapper.xFormWrapper.formData;
const quota = app.appQuota.filter(ele => ele.appId === appId);
permission = quota[0].access;
const isProduce = quota[0].access === 0 || quota[0].access === 1;
const isConsume = quota[0].access === 0 || quota[0].access === 2;
formData.produceQuota = transBToMB(quota[0].produceQuota);
formData.consumeQuota = transBToMB(quota[0].consumerQuota);
formMap[3].attrs = { disabled: isProduce, suffix: 'MB/s' };
formMap[3].rules = [{ required: !isProduce, message: '请输入' }];
formMap[4].attrs = { disabled: isConsume, suffix: 'MB/s' };
formMap[4].rules = [{ required: !isConsume, message: '请输入' }];
// tslint:disable-next-line:no-unused-expression
wrapper.ref && wrapper.ref.updateFormMap$(formMap, formData);
};
export const showTopicApplyQuatoModal = (item: ITopic) => {
const xFormModal = {
formMap: [
// {
// key: 'clusterName',
// label: '逻辑集群名称',
// rules: [{ required: true, message: '' }],
// attrs: { disabled: true },
// defaultValue: item.clusterName,
// // invisible: !item.hasOwnProperty('clusterName'),
// },
{
key: 'topicName',
label: 'Topic名称',
rules: [{ required: true, message: '' }],
attrs: { disabled: true },
}, {
key: 'appId',
label: '所属应用:',
defaultValue: '',
rules: [{
required: true,
validator: (rule: any, value: string, callback: any) => {
if (!value) {
callback('请选择应用');
return false;
}
if (permission === 0) {
callback('该应用无当前topic权限!请选择其他应用,或申请权限。');
return false;
}
return true;
},
}],
type: 'select',
options: app.appQuota,
attrs: {
onChange(value: string) {
updateFormModal(value);
},
},
}, { // 0 无权限 1可读 2可写 3 可读写 4可读写可管理
key: 'produceQuota',
label: '申请发送数据速率',
attrs: {
disabled: false,
placeholder: '请输入',
suffix: 'MB/s',
},
rules: [{
required: true,
message: '请输入',
}],
}, {
key: 'consumeQuota',
label: '申请消费数据速率',
attrs: {
disabled: false,
placeholder: '请输入',
suffix: 'MB/s',
},
rules: [{
required: true,
message: '请输入',
}],
}, {
key: 'description',
label: '申请原因',
type: 'text_area',
rules: [{ required: true, pattern: /^.{5,}$/, message: quotaRemarks }],
attrs: {
placeholder: quotaRemarks,
},
}],
formData: {
clusterName: item.clusterName,
topicName: item.topicName,
},
okText: '确认',
visible: true,
title: '申请配额',
onSubmit: (value: any) => {
const quota = {} as IQuotaModelItem;
Object.assign(quota, {
clusterId: item.clusterId,
topicName: item.topicName,
appId: value.appId,
consumeQuota: transMBToB(value.consumeQuota),
produceQuota: transMBToB(value.produceQuota),
});
const quotaParams = {
type: 2,
applicant: users.currentUser.username,
description: value.description,
extensions: JSON.stringify(quota),
};
topic.applyQuota(quotaParams).then((data) => {
notification.success({ message: '申请配额成功' });
window.location.href = `${urlPrefix}/user/order-detail/?orderId=${data.id}&region=${region.currentRegion}`;
});
},
};
wrapper.open(xFormModal);
};
export const updateAllTopicFormModal = () => {
const formMap = wrapper.xFormWrapper.formMap;
if (topic.authorities) {
const { consume, send, checkStatus } = judgeAccessStatus(topic.authorities.access);
formMap[2].defaultValue = checkStatus;
formMap[2].options = [{
label: `消费权限${consume ? '(已拥有)' : ''}`,
value: '1',
disabled: consume,
}, {
label: `发送权限${send ? '(已拥有)' : ''}`,
value: '2',
disabled: send,
}];
formMap[2].rules = [{
required: true,
validator: (rule: any, value: any, callback: any) => getPowerValidator(rule, value, callback, checkStatus, 'allTopic'),
}];
}
// tslint:disable-next-line:no-unused-expression
wrapper.ref && wrapper.ref.updateFormMap$(formMap, wrapper.xFormWrapper.formData, true, ['access', 'description']);
};
const getPowerValidator = (rule: any, value: any, callback: any, checkStatus: any, isAll?: any) => {
if (
(!checkStatus.length && !value.length) ||
(checkStatus.indexOf('1') !== -1 || checkStatus.indexOf('2') !== -1) && value.length === 1
) {
callback('请选择权限!');
return false;
}
if (isAll && checkStatus.length === 2) {
callback('您已拥有发送,消费权限!');
return false;
}
return true;
};
const getCheckStatus = (checkStatus: string[], accessValue: string) => {
let access = null as string;
if (!checkStatus.length) {
access = accessValue.length === 2 ? '3' : accessValue[0];
} else if (checkStatus.indexOf('1') !== -1 && checkStatus.length === 1) {
access = '2';
} else if (checkStatus.indexOf('2') !== -1 && checkStatus.length === 1) {
access = '1';
}
return access;
};
const judgeAccessStatus = (access: number) => {
const consume = access === 1 || access === 3 || access === 4;
const send = access === 2 || access === 3 || access === 4;
const checkStatus = access === 0 ? [] : (access === 1 || access === 2) ? [access + ''] : ['1', '2'];
return { consume, send, checkStatus };
};
export const showAllPermissionModal = (item: ITopic) => {
let appId: string = null;
if (!app.data || !app.data.length) {
return notification.info({
message: (
<>
<span>
您的账号暂无可用应用,请先
<a href={`${urlPrefix}/topic/app-list?application=1`}>申请应用</a>
</span>
</>),
});
}
const index = app.data.findIndex(row => row.appId === item.appId);
appId = index > -1 ? item.appId : app.data[0].appId;
topic.getAuthorities(appId, item.clusterId, item.topicName).then((data) => {
showAllPermission(appId, item, data.access);
});
};
const showAllPermission = (appId: string, item: ITopic, access: number) => {
const { consume, send, checkStatus } = judgeAccessStatus(access);
const xFormModal = {
formMap: [
{
key: 'topicName',
label: 'Topic名称',
defaultValue: item.topicName,
rules: [{ required: true, message: '请输入Topic名称' }],
attrs: {
placeholder: '请输入Topic名称',
disabled: true,
},
},
{
key: 'appId',
label: '绑定应用',
defaultValue: appId,
rules: [{ required: true, message: '请选择应用' }],
type: 'custom',
customFormItem: <TopicAppSelect selectData={app.data} parameter={item} />,
},
{
key: 'access',
label: '权限',
type: 'check_box',
defaultValue: checkStatus,
options: [{
label: `消费权限${consume ? '(已拥有)' : ''}`,
value: '1',
disabled: consume,
}, {
label: `发送权限${send ? '(已拥有)' : ''}`,
value: '2',
disabled: send,
}],
rules: [{
required: true,
validator: (rule: any, value: any, callback: any) => getPowerValidator(rule, value, callback, checkStatus, 'allTopic'),
}],
},
// {
// key: 'clusterName',
// label: '集群名称',
// defaultValue: item.clusterName,
// rules: [{ required: true, message: '请输入集群名称' }],
// attrs: {
// placeholder: '请输入集群名称',
// disabled: true,
// },
// },
// {
// key: 'clusterName',
// label: '集群名称',
// defaultValue: item.clusterName,
// rules: [{ required: true, message: '请输入集群名称' }],
// attrs: {
// placeholder: '请输入集群名称',
// disabled: true,
// },
// },
{
key: 'description',
label: '申请原因',
type: 'text_area',
rules: [{
required: true,
validator: (rule: any, value: string, callback: any) => {
const regexp = /^.{4,}.$/;
value = value.trim();
if (!regexp.test(value)) {
callback('请输入至少5个字符');
return false;
}
return true;
},
}],
attrs: {
placeholder: '请输入至少5个字符',
},
},
],
formData: {},
visible: true,
title: '申请权限',
okText: '确认',
onSubmit: (value: ILimitsItem) => {
const { checkStatus: originStatus } = judgeAccessStatus(topic.authorities.access);
const access = getCheckStatus(originStatus, value.access);
const params = {} as ILimitsItem;
Object.assign(params, { clusterId: item.clusterId, topicName: item.topicName, appId: value.appId, access });
const accessParams = {
type: 3,
applicant: users.currentUser.username,
description: value.description.trim(),
extensions: JSON.stringify(params),
};
topic.applyQuota(accessParams).then(data => {
notification.success({ message: '申请权限成功' });
window.location.href = `${urlPrefix}/user/order-detail/?orderId=${data.id}&region=${region.currentRegion}`;
}).catch((err) => {
notification.error({ message: '申请权限失败' });
});
},
};
wrapper.open(xFormModal);
};
export const showPermissionModal = (item: ITopic) => {
const { consume, send, checkStatus } = judgeAccessStatus(item.access);
const xFormModal = {
formMap: [
{
key: 'topicName',
label: 'Topic名称',
defaultValue: item.topicName,
rules: [{ required: true, message: '请输入Topic名称' }],
attrs: {
placeholder: '请输入Topic名称',
disabled: true,
},
},
// {
// key: 'clusterName',
// label: '集群名称',
// defaultValue: item.clusterName,
// rules: [{ required: true, message: '请输入集群名称' }],
// attrs: {
// placeholder: '请输入集群名称',
// disabled: true,
// },
// },
{
key: 'appName',
label: '绑定应用',
defaultValue: `${item.appName}${item.appId})`,
rules: [{ required: true, message: '请选择应用' }],
attrs: {
disabled: true,
},
},
{
key: 'access',
label: '权限',
type: 'check_box',
defaultValue: checkStatus,
options: [{
label: `消费权限${consume ? '(已拥有)' : ''}`,
value: '1',
disabled: consume,
}, {
label: `发送权限${send ? '(已拥有)' : ''}`,
value: '2',
disabled: send,
}],
rules: [{
required: true,
validator: (rule: any, value: any, callback: any) => getPowerValidator(rule, value, callback, checkStatus),
}],
},
{
key: 'description',
label: '申请原因',
type: 'text_area',
rules: [{
required: true,
validator: (rule: any, value: string, callback: any) => {
const regexp = /^.{4,}.$/;
value = value.trim();
if (!regexp.test(value)) {
callback('请输入至少5个字符');
return false;
}
return true;
},
}],
attrs: {
placeholder: '请输入至少5个字符',
},
},
],
formData: {},
visible: true,
title: '申请权限',
okText: '确认',
onSubmit: (value: ILimitsItem) => {
const access = getCheckStatus(checkStatus, value.access);
const params = {} as ILimitsItem;
Object.assign(params, { clusterId: item.clusterId, topicName: item.topicName, appId: item.appId, access });
const accessParams = {
type: 3,
applicant: users.currentUser.username,
description: value.description.trim(),
extensions: JSON.stringify(params),
};
topic.applyQuota(accessParams).then(data => {
notification.success({ message: '申请权限成功' });
window.location.href = `${urlPrefix}/user/order-detail/?orderId=${data.id}&region=${region.currentRegion}`;
});
},
};
wrapper.open(xFormModal);
};
export const showTopicEditModal = (item: ITopic) => {
const xFormModal = {
formMap: [
{
key: 'topicName',
label: 'Topic名称',
attrs: { disabled: true },
rules: [{ required: false }],
}, {
key: 'description',
label: '备注',
type: 'text_area',
rules: [{ required: false }, { pattern: /^.{4,}.$/, message: '请输入至少5个字符' }],
},
],
formData: {
topicName: item.topicName,
description: item.description,
},
visible: true,
title: '编辑',
onSubmit: (value: any) => {
const params = {} as IQuotaModelItem;
Object.assign(params,
{
clusterId: item.clusterId,
topicName: value.topicName,
description: value.description,
});
topic.updateTopic(params).then(() => {
notification.success({ message: '编辑成功' });
topic.getTopic();
topic.getExpired();
});
},
};
wrapper.open(xFormModal);
};
export const applyExpandModal = (item: ITopic) => {
const xFormModal = {
formMap: [
{
key: 'topicName',
label: 'Topic名称',
attrs: { disabled: true },
rules: [{ required: true }],
}, {
key: 'needIncrPartitionNum',
label: '申请增加分区数量',
type: 'input_number',
rules: [{
required: true,
message: '请输入0-1000正整数',
pattern: /^((?!0)\d{1,3}|1000)$/,
}],
attrs: { placeholder: '0-1000正整数' },
renderExtraElement: () => <div className="form-tip mr--10">分区标准为3MB/s一个,请按需申请</div>,
}, {
key: 'description',
label: '申请原因',
type: 'text_area',
rules: [{ required: true, pattern: /^.{5,}.$/, message: expandRemarks }],
attrs: { placeholder: expandRemarks },
},
],
formData: {
topicName: item.topicName,
description: item.description,
},
visible: true,
title: '申请分区',
customRenderElement: <div className="expand-text">若Topic已被限流,则申请分区无效,请直接“申请配额”!</div>,
onSubmit: (value: any) => {
const isPhysicalClusterId = Url().search.hasOwnProperty('isPhysicalClusterId') && Url().search.isPhysicalClusterId;
const offlineParams = {
type: 12,
applicant: users.currentUser.username,
description: value.description,
extensions: JSON.stringify({
clusterId: item.clusterId,
topicName: item.topicName,
isPhysicalClusterId,
needIncrPartitionNum: value.needIncrPartitionNum,
}),
};
app.applyExpand(offlineParams).then((data: any) => {
notification.success({ message: '申请分区成功' });
window.location.href = `${urlPrefix}/user/order-detail/?orderId=${data.id}&region=${region.currentRegion}`;
}).catch((err) => {
notification.error({ message: '申请权限失败' });
});
},
};
wrapper.open(xFormModal);
};

Комментарий ( 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.4.2