mirror of
https://github.com/portainer/portainer.git
synced 2025-08-05 13:55:21 +02:00
feat(system): path to upgrade standalone to BE [EE-4071] (#8095)
This commit is contained in:
parent
756ac034ec
commit
5cbf52377d
73 changed files with 1374 additions and 421 deletions
9
app/react/portainer/system/build-url.ts
Normal file
9
app/react/portainer/system/build-url.ts
Normal file
|
@ -0,0 +1,9 @@
|
|||
export function buildUrl(action?: string) {
|
||||
let url = '/system';
|
||||
|
||||
if (action) {
|
||||
url += `/${action}`;
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
3
app/react/portainer/system/query-keys.ts
Normal file
3
app/react/portainer/system/query-keys.ts
Normal file
|
@ -0,0 +1,3 @@
|
|||
export const queryKeys = {
|
||||
base: () => ['system'] as const,
|
||||
};
|
28
app/react/portainer/system/useNodesCount.ts
Normal file
28
app/react/portainer/system/useNodesCount.ts
Normal file
|
@ -0,0 +1,28 @@
|
|||
import { useQuery } from 'react-query';
|
||||
|
||||
import axios, { parseAxiosError } from '@/portainer/services/axios';
|
||||
import { withError } from '@/react-tools/react-query';
|
||||
|
||||
import { buildUrl } from './build-url';
|
||||
import { queryKeys } from './query-keys';
|
||||
|
||||
export const queryKey = [...queryKeys.base(), 'nodes'] as const;
|
||||
|
||||
export interface NodesCountResponse {
|
||||
nodes: number;
|
||||
}
|
||||
|
||||
async function getNodesCount() {
|
||||
try {
|
||||
const { data } = await axios.get<NodesCountResponse>(buildUrl('nodes'));
|
||||
return data.nodes;
|
||||
} catch (error) {
|
||||
throw parseAxiosError(error as Error);
|
||||
}
|
||||
}
|
||||
|
||||
export function useNodesCount() {
|
||||
return useQuery(queryKey, getNodesCount, {
|
||||
...withError('Unable to retrieve nodes count'),
|
||||
});
|
||||
}
|
38
app/react/portainer/system/useSystemInfo.ts
Normal file
38
app/react/portainer/system/useSystemInfo.ts
Normal file
|
@ -0,0 +1,38 @@
|
|||
import { useQuery } from 'react-query';
|
||||
|
||||
import axios, { parseAxiosError } from '@/portainer/services/axios';
|
||||
import { withError } from '@/react-tools/react-query';
|
||||
|
||||
import { buildUrl } from './build-url';
|
||||
import { queryKeys } from './query-keys';
|
||||
|
||||
export const queryKey = [...queryKeys.base(), 'info'] as const;
|
||||
|
||||
export type ContainerPlatform =
|
||||
| 'Docker Standalone'
|
||||
| 'Docker Swarm'
|
||||
| 'Kubernetes'
|
||||
| 'Podman'
|
||||
| 'Nomad';
|
||||
|
||||
export interface SystemInfoResponse {
|
||||
platform: ContainerPlatform;
|
||||
agents: number;
|
||||
edgeAgents: number;
|
||||
edgeDevices: number;
|
||||
}
|
||||
|
||||
async function getSystemInfo() {
|
||||
try {
|
||||
const { data } = await axios.get<SystemInfoResponse>(buildUrl('info'));
|
||||
return data;
|
||||
} catch (error) {
|
||||
throw parseAxiosError(error as Error);
|
||||
}
|
||||
}
|
||||
|
||||
export function useSystemInfo() {
|
||||
return useQuery(queryKey, getSystemInfo, {
|
||||
...withError('Unable to retrieve system info'),
|
||||
});
|
||||
}
|
46
app/react/portainer/system/useSystemStatus.ts
Normal file
46
app/react/portainer/system/useSystemStatus.ts
Normal file
|
@ -0,0 +1,46 @@
|
|||
import { useQuery } from 'react-query';
|
||||
import { RetryValue } from 'react-query/types/core/retryer';
|
||||
|
||||
import axios, { parseAxiosError } from '@/portainer/services/axios';
|
||||
|
||||
import { buildUrl } from './build-url';
|
||||
import { queryKeys } from './query-keys';
|
||||
|
||||
export const queryKey = [...queryKeys.base(), 'status'] as const;
|
||||
|
||||
export interface StatusResponse {
|
||||
Edition: string;
|
||||
Version: string;
|
||||
InstanceID: string;
|
||||
}
|
||||
|
||||
export async function getSystemStatus() {
|
||||
try {
|
||||
const { data } = await axios.get<StatusResponse>(buildUrl('status'));
|
||||
|
||||
data.Edition = 'Community Edition';
|
||||
|
||||
return data;
|
||||
} catch (error) {
|
||||
throw parseAxiosError(error as Error);
|
||||
}
|
||||
}
|
||||
|
||||
export function useSystemStatus<T = StatusResponse>({
|
||||
select,
|
||||
enabled,
|
||||
retry,
|
||||
onSuccess,
|
||||
}: {
|
||||
select?: (status: StatusResponse) => T;
|
||||
enabled?: boolean;
|
||||
retry?: RetryValue<unknown>;
|
||||
onSuccess?: (data: T) => void;
|
||||
} = {}) {
|
||||
return useQuery(queryKey, () => getSystemStatus(), {
|
||||
select,
|
||||
enabled,
|
||||
retry,
|
||||
onSuccess,
|
||||
});
|
||||
}
|
38
app/react/portainer/system/useSystemVersion.ts
Normal file
38
app/react/portainer/system/useSystemVersion.ts
Normal file
|
@ -0,0 +1,38 @@
|
|||
import { useQuery } from 'react-query';
|
||||
|
||||
import axios, { parseAxiosError } from '@/portainer/services/axios';
|
||||
|
||||
import { buildUrl } from './build-url';
|
||||
import { queryKeys } from './query-keys';
|
||||
|
||||
export const queryKey = [...queryKeys.base(), 'version'] as const;
|
||||
|
||||
export interface VersionResponse {
|
||||
// Whether portainer has an update available
|
||||
UpdateAvailable: boolean;
|
||||
// The latest version available
|
||||
LatestVersion: string;
|
||||
ServerVersion: string;
|
||||
DatabaseVersion: string;
|
||||
Build: {
|
||||
BuildNumber: string;
|
||||
ImageTag: string;
|
||||
NodejsVersion: string;
|
||||
YarnVersion: string;
|
||||
WebpackVersion: string;
|
||||
GoVersion: string;
|
||||
};
|
||||
}
|
||||
|
||||
export async function getSystemVersion() {
|
||||
try {
|
||||
const { data } = await axios.get<VersionResponse>(buildUrl('version'));
|
||||
return data;
|
||||
} catch (error) {
|
||||
throw parseAxiosError(error as Error);
|
||||
}
|
||||
}
|
||||
|
||||
export function useSystemVersion() {
|
||||
return useQuery(queryKey, () => getSystemVersion());
|
||||
}
|
20
app/react/portainer/system/useUpgradeEditionMutation.ts
Normal file
20
app/react/portainer/system/useUpgradeEditionMutation.ts
Normal file
|
@ -0,0 +1,20 @@
|
|||
import { useMutation } from 'react-query';
|
||||
|
||||
import axios, { parseAxiosError } from '@/portainer/services/axios';
|
||||
import { withError } from '@/react-tools/react-query';
|
||||
|
||||
import { buildUrl } from './build-url';
|
||||
|
||||
export function useUpgradeEditionMutation() {
|
||||
return useMutation(upgradeEdition, {
|
||||
...withError('Unable to upgrade edition'),
|
||||
});
|
||||
}
|
||||
|
||||
async function upgradeEdition({ license }: { license: string }) {
|
||||
try {
|
||||
await axios.post(buildUrl('upgrade'), { license });
|
||||
} catch (error) {
|
||||
throw parseAxiosError(error as Error);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue