Skip to content

Commit

Permalink
Merge pull request #5836 from liumt1993/feat/host-support-cross-biz-t…
Browse files Browse the repository at this point in the history
…ransfer

 feat: 支持将多个业务下的空闲机模块下的主机一次转移到另外一个业务下的空闲机set下的任一模块
  • Loading branch information
breezelxp authored Dec 21, 2021
2 parents ce9b77b + afa1988 commit f9f91cc
Show file tree
Hide file tree
Showing 8 changed files with 162 additions and 38 deletions.
8 changes: 5 additions & 3 deletions src/ui/src/components/modal/permission-main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,11 @@
const allRelationPath = []
relatedResourceTypes.forEach(({ instances = [] }) => {
instances.forEach((fullPaths) => {
// 数据格式[type, id, label]
// eslint-disable-next-line max-len
const topoPath = fullPaths.map(pathData => [pathData.type, pathData.id, IAM_VIEWS_NAME[pathData.type][languageIndex]])
const topoPath = fullPaths.map((pathData) => {
const { type, id } = pathData
const label = IAM_VIEWS_NAME[type][languageIndex]
return [type, id, label]
})
allRelationPath.push(topoPath)
})
})
Expand Down
5 changes: 3 additions & 2 deletions src/ui/src/components/modal/permission.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import { IAM_VIEWS } from '@/dictionary/iam-auth'
import permissionMixins from '@/mixins/permission'
import PermissionMain from './permission-main.vue'
import uniqBy from 'lodash/uniqBy'
export default {
name: 'permissionModal',
components: {
Expand Down Expand Up @@ -72,15 +73,15 @@
const { related_resource_types: relatedResourceTypes = [] } = action
const newInstances = []
relatedResourceTypes.forEach(({ instances = [] }) => {
const insts = instances.filter((fullPaths) => {
let insts = instances.filter((fullPaths) => {
const matched = fullPaths.find(item => batchInstTypes.includes(item.type))
if (matched) {
const authed = authResults.find(item => String(item.resource_id) === matched.id)
return !authed?.is_pass
}
return true
})
insts = uniqBy(insts, inst => inst[0].id)
newInstances.push(insts)
})
Expand Down
28 changes: 18 additions & 10 deletions src/ui/src/dictionary/iam-auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,16 +426,24 @@ export const IAM_ACTIONS = {
instances: [IAM_VIEWS.BIZ]
}],
transform: (cmdbAction, relationIds) => {
const [[[currentBizId], [targetBizId]]] = relationIds
const verifyMeta = basicTransform(cmdbAction)
verifyMeta.parent_layers = [{
resource_id: currentBizId,
resource_type: 'biz'
}, {
resource_id: targetBizId,
resource_type: 'biz'
}]
return verifyMeta
const verifyMetas = []

relationIds.forEach((relationId) => {
const [[currentBizId], [targetBizId]] = relationId
const verifyMeta = basicTransform(cmdbAction)

verifyMeta.parent_layers = [{
resource_id: currentBizId,
resource_type: 'biz'
}, {
resource_id: targetBizId,
resource_type: 'biz'
}]

verifyMetas.push(verifyMeta)
})

return verifyMetas
}
},

Expand Down
3 changes: 2 additions & 1 deletion src/ui/src/i18n/lang/cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -1469,5 +1469,6 @@
"重置成功": "重置成功",
"转移至": "转移至",
"追加至": "追加至",
"追加主机到业务模块": "追加主机到业务模块"
"追加主机到业务模块": "追加主机到业务模块",
"仅允许业务下空闲机跨业务转移": "仅允许业务下{idleModule}跨业务转移"
}
3 changes: 2 additions & 1 deletion src/ui/src/i18n/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1464,5 +1464,6 @@
"重置成功": "Successful restored",
"转移至": "Transfer to",
"追加至": "Append to",
"追加主机到业务模块": "Append to Business Modules"
"追加主机到业务模块": "Append to Business Modules",
"仅允许业务下空闲机跨业务转移": "Only {idleModule} under the business allowed to transfer across businesses"
}
7 changes: 7 additions & 0 deletions src/ui/src/store/modules/api/host-relation.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ const actions = {
*/
transferHostToMutipleBizModule({ commit, state, dispatch }, { params, config }) {
return $http.post('hosts/modules/biz/mutilple', params, config)
},

/**
* 跨业务转移空闲机到空闲机模块
*/
transferHostToOtherBizModule({ commit, state, dispatch }, { params, config }) {
return $http.post('hosts/resource/cross/biz', params, config)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
:key="item.bk_biz_id"
:id="item.bk_biz_id"
:name="`[${item.bk_biz_id}] ${item.bk_biz_name}`"
:auth="{ type: $OPERATION.HOST_TRANSFER_ACROSS_BIZ, relation: [[[bizId], [item.bk_biz_id]]] }">
:auth="{ type: $OPERATION.HOST_TRANSFER_ACROSS_BIZ, relation: item.relation }">
</cmdb-auth-option>
</bk-select>
<template v-if="targetBizId">
Expand All @@ -30,7 +30,7 @@
nameKey: 'bk_inst_name',
childrenKey: 'child'
}"
:height="278"
:height="450"
:node-height="36"
:show-checkbox="isShowCheckbox"
@node-click="handleNodeClick"
Expand Down Expand Up @@ -89,8 +89,11 @@
type: String,
default: ''
},
/**
* 选择的机器所在业务
*/
business: {
type: Object,
type: [Object, Array],
required: true
}
},
Expand All @@ -114,8 +117,11 @@
},
computed: {
...mapGetters('objectModelClassify', ['getModelById']),
bizId() {
return this.business.bk_biz_id
bizIds() {
if (this.business?.bk_biz_id) {
return [this.business.bk_biz_id]
}
return this.business
},
targetBiz() {
return this.businessList.find(biz => biz.bk_biz_id === this.targetBizId)
Expand All @@ -128,10 +134,20 @@
this.getFullAmountBusiness()
},
methods: {
generateRelation(businesses) {
businesses.forEach((item) => {
const relation = []
this.bizIds.forEach((bizId) => {
relation.push([[bizId], [item.bk_biz_id]])
})
item.relation = relation
})
},
async getFullAmountBusiness() {
try {
const data = await this.$http.get('biz/simplify?sort=bk_biz_id', { requestId: this.request.list })
const availableBusiness = (data.info || []).filter(business => business.bk_biz_id !== this.bizId)
this.generateRelation(availableBusiness)
this.businessList = Object.freeze(availableBusiness)
} catch (e) {
console.error(e)
Expand All @@ -146,7 +162,10 @@
}
},
sortBusinessByAuth(authData) {
const list = this.businessList.map((item, index) => ({ ...item, is_pass: authData[index]?.is_pass }))
if (!authData) {
return false
}
const list = this.businessList?.map((item, index) => ({ ...item, is_pass: authData[index]?.is_pass }))
list.sort((itemA, itemB) => itemB?.is_pass - itemA?.is_pass)
this.businessList = list
},
Expand Down Expand Up @@ -208,7 +227,8 @@
const removeChecked = []
checked.forEach((id) => {
const node = this.$refs.tree.getNodeById(id)
if (node.data.default === currentNode.data.default) {
// 用户自定义空闲模块的 default 是一样的,所以增加 bk_inst_id 是否一致的判断
if (node.data.default === currentNode.data.default && node.data.bk_inst_id === currentNode.data.bk_inst_id) {
currentChecked.push(id)
} else {
removeChecked.push(id)
Expand Down
112 changes: 98 additions & 14 deletions src/ui/src/views/resource/transfer/transfer-menu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,19 @@
{{$store.state.globalConfig.config.idlePool.idle}}
</a>
</li>
<li><a href="javascript:;" @click="transferToBizModule">{{$t('业务模块')}}</a></li>
<li>
<a href="javascript:;" @click="transferToBizModule">{{$t('业务模块')}}</a>
</li>
<li><a href="javascript:;" @click="transferToResourcePool">{{$t('主机池')}}</a></li>
<li>
<a
v-bk-tooltips.right="{
content: $t('仅允许业务下空闲机跨业务转移', { idleModule: $store.state.globalConfig.config.idlePool.idle }),
disabled: !transferToOtherDisabled
}"
:class="{ disabled: transferToOtherDisabled }"
href="javascript:;" @click="transferToOtherBizModule">{{$t('其他业务')}}</a>
</li>
</ul>
</bk-dropdown-menu>
<cmdb-dialog v-model="dialog.show" :width="dialog.width" :height="dialog.height">
Expand All @@ -35,12 +46,15 @@
import HostStore from './host-store'
import ModuleSelector from '../../business-topology/host/module-selector'
import MoveToResourceConfirm from '../../business-topology/host/move-to-resource-confirm'
import AcrossBusinessModuleSelector from '@/views/business-topology/host/across-business-module-selector.vue'
import { MENU_BUSINESS_TRANSFER_HOST } from '@/dictionary/menu-symbol'
import RouterQuery from '@/router/query'
import uniq from 'lodash.uniq'
export default {
components: {
[ModuleSelector.name]: ModuleSelector,
[MoveToResourceConfirm.name]: MoveToResourceConfirm
[MoveToResourceConfirm.name]: MoveToResourceConfirm,
[AcrossBusinessModuleSelector.name]: AcrossBusinessModuleSelector
},
data() {
return {
Expand All @@ -54,14 +68,18 @@
},
request: {
moveToIdleModule: Symbol('moveToIdleModule'),
moveToResource: Symbol('moveToResource')
moveToResource: Symbol('moveToResource'),
moveToOtherBizModule: Symbol('moveToOtherBizModule')
}
}
},
computed: {
disabled() {
return !HostStore.isSelected
}
},
transferToOtherDisabled() {
return !HostStore.isAllIdleModule || HostStore.hosts.some(host => host.biz[0].default === 1)
},
},
methods: {
handleMenuToggle(isShow) {
Expand Down Expand Up @@ -149,27 +167,40 @@
this.dialog.component = MoveToResourceConfirm.name
this.dialog.show = true
},
transferToOtherBizModule() {
if (this.transferToOtherDisabled) return false
const moduleBizs = uniq(HostStore.getSelected().map(host => host.biz[0].bk_biz_id))
const props = {
moduleType: 'business',
business: moduleBizs,
title: this.$t('转移主机到其他业务')
}
this.dialog.props = props
this.dialog.width = 830
this.dialog.height = 600
this.dialog.component = AcrossBusinessModuleSelector.name
this.dialog.show = true
},
handleDialogCancel() {
this.dialog.show = false
},
handleDialogConfirm() {
handleDialogConfirm(...args) {
const theArgs = args
this.dialog.show = false
if (this.dialog.component === ModuleSelector.name) {
if (this.dialog.props.moduleType === 'idle') {
if (HostStore.isAllIdleSet) {
// eslint-disable-next-line prefer-rest-params
this.transferDirectly(...arguments)
this.transferDirectly(...theArgs)
} else {
// eslint-disable-next-line prefer-rest-params
this.gotoTransferPage(...arguments)
this.gotoTransferPage(...theArgs)
}
} else {
// eslint-disable-next-line prefer-rest-params
this.gotoTransferPage(...arguments)
this.gotoTransferPage(...theArgs)
}
} else if (this.dialog.component === MoveToResourceConfirm.name) {
// eslint-disable-next-line prefer-rest-params
this.moveHostToResource(...arguments)
this.moveHostToResource(...theArgs)
} else if (this.dialog.component === AcrossBusinessModuleSelector.name) {
this.moveHostToOtherBiz(...theArgs)
}
},
async transferDirectly(modules) {
Expand Down Expand Up @@ -230,7 +261,45 @@
} catch (e) {
console.error(e)
}
}
},
moveHostToOtherBiz(selectedNode, targetBizId) {
const targetModuleId = selectedNode[0].data.bk_inst_id
const resourceHosts = []
HostStore.getSelected().forEach((selectedHost) => {
const hostBizId = selectedHost.biz[0].bk_biz_id
const hostId = selectedHost.host.bk_host_id
const existedResourceHost = resourceHosts.find(resourceHost => resourceHost.src_bk_biz_id === hostBizId)
if (existedResourceHost) {
existedResourceHost.src_bk_host_ids.push(hostId)
} else {
resourceHosts.push({
src_bk_biz_id: hostBizId,
src_bk_host_ids: [hostId]
})
}
})
this.$store.dispatch('hostRelation/transferHostToOtherBizModule', {
params: {
resource_hosts: resourceHosts,
dst_bk_biz_id: targetBizId,
dst_bk_module_id: targetModuleId
},
config: {
requestId: this.request.moveToOtherBizModule
}
})
.then(() => {
HostStore.clear()
this.$success('转移成功')
RouterQuery.set({
_t: Date.now(),
page: 1
})
})
},
}
}
</script>
Expand Down Expand Up @@ -261,4 +330,19 @@
cursor: pointer;
border-color: #979ba5;
}
.bk-dropdown-list {
font-size: 14px;
color: $textColor;
> li > a {
&.disabled {
color: $textDisabledColor;
cursor: not-allowed;
&:hover{
background: inherit;
}
}
}
}
</style>

0 comments on commit f9f91cc

Please sign in to comment.