1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-25 02:50:08 +03:00

F #5422: Improves on cache behavior (#2043)

This commit is contained in:
Sergio Betanzos 2022-05-13 11:56:45 +02:00 committed by GitHub
parent 171384d069
commit ecd2d1a9b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 32 additions and 51 deletions

View File

@ -14,13 +14,10 @@
* limitations under the License. *
* ------------------------------------------------------------------------- */
import { ReactElement } from 'react'
import { useHistory, useLocation } from 'react-router'
import { useHistory } from 'react-router'
import { useGeneralApi } from 'client/features/General'
import {
useUpdateHostMutation,
useAllocateHostMutation,
} from 'client/features/OneApi/host'
import { useAllocateHostMutation } from 'client/features/OneApi/host'
import {
DefaultFormStepper,
@ -36,23 +33,15 @@ import { PATH } from 'client/apps/sunstone/routesOne'
*/
function CreateHost() {
const history = useHistory()
const { state: { ID: id, NAME } = {} } = useLocation()
const { enqueueSuccess } = useGeneralApi()
const [update] = useUpdateHostMutation()
const [allocate] = useAllocateHostMutation()
const onSubmit = async (props) => {
try {
if (!id) {
const newHostId = await allocate(props).unwrap()
history.push(PATH.INFRASTRUCTURE.HOSTS.LIST)
enqueueSuccess(`Host created - #${newHostId}`)
} else {
await update({ id, ...props })
history.push(PATH.INFRASTRUCTURE.HOSTS.LIST)
enqueueSuccess(`Host updated - #${id} ${NAME}`)
}
const newHostId = await allocate(props).unwrap()
history.push(PATH.INFRASTRUCTURE.HOSTS.LIST)
enqueueSuccess(`Host created - #${newHostId}`)
} catch {}
}

View File

@ -13,14 +13,14 @@
* See the License for the specific language governing permissions and *
* limitations under the License. *
* ------------------------------------------------------------------------- */
import { useEffect, ReactElement } from 'react'
import { ReactElement } from 'react'
import { useHistory, useLocation } from 'react-router'
import { useGeneralApi } from 'client/features/General'
import {
useUpdateTemplateMutation,
useAllocateTemplateMutation,
useLazyGetTemplateQuery,
useGetTemplateQuery,
} from 'client/features/OneApi/vmTemplate'
import { useGetVMGroupsQuery } from 'client/features/OneApi/vmGroup'
import { useGetHostsQuery } from 'client/features/OneApi/host'
@ -48,14 +48,17 @@ function CreateVmTemplate() {
const [update] = useUpdateTemplateMutation()
const [allocate] = useAllocateTemplateMutation()
const { data } = useGetTemplateQuery(
{ id: templateId, extended: true },
{ skip: templateId === undefined }
)
useGetVMGroupsQuery(undefined, { refetchOnMountOrArgChange: false })
useGetHostsQuery(undefined, { refetchOnMountOrArgChange: false })
useGetImagesQuery(undefined, { refetchOnMountOrArgChange: false })
useGetUsersQuery(undefined, { refetchOnMountOrArgChange: false })
useGetDatastoresQuery(undefined, { refetchOnMountOrArgChange: false })
const [getTemplate, { data }] = useLazyGetTemplateQuery()
const onSubmit = async (xmlTemplate) => {
try {
if (!templateId) {
@ -63,17 +66,13 @@ function CreateVmTemplate() {
history.push(PATH.TEMPLATE.VMS.LIST)
enqueueSuccess(`VM Template created - #${newTemplateId}`)
} else {
await update({ id: templateId, template: xmlTemplate })
await update({ id: templateId, template: xmlTemplate }).unwrap()
history.push(PATH.TEMPLATE.VMS.LIST)
enqueueSuccess(`VM Template updated - #${templateId} ${NAME}`)
}
} catch {}
}
useEffect(() => {
templateId && getTemplate({ id: templateId, extended: true })
}, [])
return templateId && !data ? (
<SkeletonStepsForm />
) : (

View File

@ -43,20 +43,20 @@ function InstantiateVmTemplate() {
const { enqueueInfo } = useGeneralApi()
const [instantiate] = useInstantiateTemplateMutation()
useGetUsersQuery(undefined, { refetchOnMountOrArgChange: false })
useGetGroupsQuery(undefined, { refetchOnMountOrArgChange: false })
const { data, isError } = useGetTemplateQuery(
{ id: templateId, extended: true },
{ refetchOnMountOrArgChange: false }
{ skip: templateId === undefined, refetchOnMountOrArgChange: false }
)
useGetUsersQuery(undefined, { refetchOnMountOrArgChange: false })
useGetGroupsQuery(undefined, { refetchOnMountOrArgChange: false })
const onSubmit = async ([templateSelected, templates]) => {
try {
const { ID, NAME } = templateSelected
const templatesWithId = templates.map((t) => ({ id: ID, ...t }))
await Promise.all(templatesWithId.map(instantiate))
await Promise.all(templatesWithId.map((t) => instantiate(t).unwrap()))
history.push(PATH.INSTANCE.VMS.LIST)

View File

@ -64,7 +64,7 @@ const groupApi = oneApi.injectEndpoints({
return { params: { id }, command }
},
transformResponse: (data) => data?.GROUP ?? {},
invalidatesTags: (_, __, id) => [{ type: GROUP, id }],
invalidatesTags: (_, __, { id }) => [{ type: GROUP, id }],
}),
allocateGroup: builder.mutation({
/**

View File

@ -186,7 +186,7 @@ const imageApi = oneApi.injectEndpoints({
return { params, command }
},
invalidatesTags: (_, __, id) => [{ type: IMAGE, id }, IMAGE_POOL],
invalidatesTags: (_, __, { id }) => [{ type: IMAGE, id }, IMAGE_POOL],
}),
changeImageType: builder.mutation({
/**
@ -222,7 +222,7 @@ const imageApi = oneApi.injectEndpoints({
return { params, command }
},
invalidatesTags: (_, __, id) => [{ type: IMAGE, id }],
invalidatesTags: (_, __, { id }) => [{ type: IMAGE, id }],
}),
changeImagePermissions: builder.mutation({
/**
@ -380,7 +380,7 @@ const imageApi = oneApi.injectEndpoints({
return { params, command }
},
invalidatesTags: (_, __, id) => [{ type: IMAGE, id }, IMAGE_POOL],
invalidatesTags: (_, __, { id }) => [{ type: IMAGE, id }, IMAGE_POOL],
}),
}),
})

View File

@ -213,7 +213,7 @@ const marketplaceApi = oneApi.injectEndpoints({
return { params: { id, enable: true }, command }
},
invalidatesTags: (_, __, id) => [
invalidatesTags: (_, __, { id }) => [
{ type: MARKETPLACE, id },
MARKETPLACE_POOL,
],
@ -233,7 +233,7 @@ const marketplaceApi = oneApi.injectEndpoints({
return { params: { id, enable: false }, command }
},
invalidatesTags: (_, __, id) => [
invalidatesTags: (_, __, { id }) => [
{ type: MARKETPLACE, id },
MARKETPLACE_POOL,
],

View File

@ -65,7 +65,7 @@ const userApi = oneApi.injectEndpoints({
return { params: { id }, command }
},
transformResponse: (data) => data?.USER ?? {},
providesTags: (_, __, id) => [{ type: USER, id }],
providesTags: (_, __, { id }) => [{ type: USER, id }],
}),
allocateUser: builder.mutation({
/**

View File

@ -107,7 +107,7 @@ const vmApi = oneApi.injectEndpoints({
return { params, command }
},
transformResponse: (data) => data?.VM ?? {},
providesTags: (_, __, id) => [{ type: VM, id }],
providesTags: (_, __, { id }) => [{ type: VM, id }],
async onQueryStarted(id, { dispatch, queryFulfilled }) {
try {
const { data: resourceFromQuery } = await queryFulfilled
@ -267,7 +267,6 @@ const vmApi = oneApi.injectEndpoints({
return { params, command }
},
invalidatesTags: [VM_POOL],
}),
saveAsTemplate: builder.mutation({
/**
@ -338,7 +337,7 @@ const vmApi = oneApi.injectEndpoints({
return { params, command }
},
invalidatesTags: (_, __, { id }) => [{ type: VM, id }],
invalidatesTags: (_, __, { id }) => [{ type: VM, id }, VM_POOL],
}),
migrate: builder.mutation({
/**
@ -363,7 +362,7 @@ const vmApi = oneApi.injectEndpoints({
return { params, command }
},
invalidatesTags: (_, __, { id }) => [{ type: VM, id }],
invalidatesTags: (_, __, { id }) => [{ type: VM, id }, VM_POOL],
}),
saveAsDisk: builder.mutation({
/**
@ -931,7 +930,7 @@ const vmApi = oneApi.injectEndpoints({
return { params, command }
},
invalidatesTags: (_, __, id) => [{ type: VM, id }],
invalidatesTags: (_, __, { id }) => [{ type: VM, id }],
async onQueryStarted(params, { dispatch, queryFulfilled }) {
try {
const patchVm = dispatch(

View File

@ -33,7 +33,7 @@ import {
import { LockLevel, FilterFlag, Permission, VmTemplate } from 'client/constants'
const { TEMPLATE } = ONE_RESOURCES
const { TEMPLATE_POOL, VM_POOL, IMAGE_POOL } = ONE_RESOURCES_POOL
const { TEMPLATE_POOL } = ONE_RESOURCES_POOL
const vmTemplateApi = oneApi.injectEndpoints({
endpoints: (builder) => ({
@ -124,7 +124,6 @@ const vmTemplateApi = oneApi.injectEndpoints({
return { params, command }
},
invalidatesTags: [TEMPLATE_POOL],
}),
cloneTemplate: builder.mutation({
/**
@ -163,11 +162,7 @@ const vmTemplateApi = oneApi.injectEndpoints({
return { params, command }
},
invalidatesTags: (_, __, { id, image }) => [
TEMPLATE_POOL,
{ type: TEMPLATE, id },
...(image ? [IMAGE_POOL] : []),
],
invalidatesTags: [TEMPLATE_POOL],
}),
instantiateTemplate: builder.mutation({
/**
@ -188,7 +183,6 @@ const vmTemplateApi = oneApi.injectEndpoints({
return { params, command }
},
invalidatesTags: [VM_POOL],
}),
updateTemplate: builder.mutation({
/**
@ -432,7 +426,7 @@ const vmTemplateApi = oneApi.injectEndpoints({
return { params, command }
},
invalidatesTags: (_, __, id) => [{ type: TEMPLATE, id }],
invalidatesTags: (_, __, { id }) => [{ type: TEMPLATE, id }],
async onQueryStarted(params, { dispatch, queryFulfilled }) {
try {
const patchVmTemplate = dispatch(