1
0
Fork 0
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:
Chaim Lev-Ari 2022-12-11 08:58:22 +02:00 committed by GitHub
parent 756ac034ec
commit 5cbf52377d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
73 changed files with 1374 additions and 421 deletions

View file

@ -0,0 +1,9 @@
export function buildUrl(action?: string) {
let url = '/system';
if (action) {
url += `/${action}`;
}
return url;
}

View file

@ -0,0 +1,3 @@
export const queryKeys = {
base: () => ['system'] as const,
};

View 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'),
});
}

View 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'),
});
}

View 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,
});
}

View 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());
}

View 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);
}
}