Skip to content

Commit

Permalink
feat(pci-block-storage): add deploy zone
Browse files Browse the repository at this point in the history
ref: TAPC-2112

Signed-off-by: Simon Chaumet <[email protected]>
  • Loading branch information
SimonChaumet committed Jan 17, 2025
1 parent a022a6f commit 348b94f
Show file tree
Hide file tree
Showing 31 changed files with 719 additions and 503 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,15 @@
"pci_projects_project_storages_blocks_add_save_form": "Création du volume en cours",
"pci_projects_project_storages_blocks_add_error_query": "Une erreur est survenue lors de la récupération des régions : {{ message }}",
"pci_projects_project_storages_blocks_add_success_message": "Le volume {{volume}} a été ajouté",
"pci_projects_project_storages_blocks_add_error_post": "Une erreur est survenue lors de l'ajout du volume {{ volume }} : {{ message }}"
"pci_projects_project_storages_blocks_add_error_post": "Une erreur est survenue lors de l'ajout du volume {{ volume }} : {{ message }}",
"pci_projects_project_storages_blocks_add_deployment_mode_title": "Sélectionnez un mode de déploiement",
"pci_projects_project_storages_blocks_add_deployment_mode_description": "Sélectionnez une configuration optimale pour assurer la disponibilité, la résilience et la latence appropriées pour vos données selon vos cas d’usage. <Link>En savoir plus</Link>",
"pci_projects_project_storages_blocks_add_deployment_mode_title_region": "Région 1-AZ",
"pci_projects_project_storages_blocks_add_deployment_mode_description_region": "Déploiement résilient et économique sur 1 zone de disponibilité.",
"pci_projects_project_storages_blocks_add_deployment_mode_title_region-3-az": "Région 3-AZ",
"pci_projects_project_storages_blocks_add_deployment_mode_description_region-3-az": "Déploiement haute résilience/haute disponibilité pour vos applications critiques sur 3 zones de disponibilité.",
"pci_projects_project_storages_blocks_add_deployment_mode_title_localzone": "Local Zone",
"pci_projects_project_storages_blocks_add_deployment_mode_description_localzone": "Déploiement de vos applications au plus près de vos utilisatrices et utilisateurs pour une faible latence et la résidence des données.",
"pci_projects_project_storages_blocks_add_deployment_mode_price_from": "A partir de {{price}} HT/Go/heure",
"pci_projects_project_storages_blocks_add_beta_free": "Gratuit"
}

This file was deleted.

100 changes: 73 additions & 27 deletions packages/manager/apps/pci-block-storage/src/api/data/catalog.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,74 @@
export type TPricing = {
capacities: string[];
mode: string;
phase: number;
commitment: number;
description: string;
price: {
currencyCode: string;
text: string;
value: number;
};
tax: number;
interval: number;
intervalUnit: string;
quantity: {
max?: number;
min?: number;
};
repeat: {
max?: number;
min?: number;
};
strategy: string;
mustBeCompleted: boolean;
type: string;
promotions: unknown[];
engagementConfiguration?: unknown;
import { TAddon } from '@ovh-ux/manager-pci-common';
import { v6 } from '@ovh-ux/manager-core-api';
import { TRegion } from '@/api/data/regions';

export type TCatalogGroup = {
name: string;
tags: string[];
};

export type TVolumePricing = Pick<TAddon['pricings'][number], 'price'> & {
regions: TRegion['name'][];
showAvailabilityZones: boolean;
interval: 'day' | 'hour' | 'month' | 'none';
specs: TAddon['blobs']['technical'];
};

export type TVolumeCatalogFilter = {
[key in 'deployment' | 'region']: TCatalogGroup[];
};

export type TVolumeCatalogElementFilter = {
[Property in keyof TVolumeCatalogFilter]?: TVolumeCatalogFilter[Property][number]['name'][];
};

export type TVolumeAddon = {
name: string;
tags: string[];
filters: TVolumeCatalogElementFilter;
pricings: TVolumePricing[];
};

export type TVolumeCatalog = {
filters: TVolumeCatalogFilter;
regions: TRegion[];
models: TVolumeAddon[];
};

export const getVolumeCatalog = async (
projectId: string,
): Promise<TVolumeCatalog> =>
(await v6.get<TVolumeCatalog>(`/cloud/project/${projectId}/catalog/volume`))
.data;

export function getLeastPrice(pricings: TVolumePricing[]) {
return pricings.reduce<number | null>(
(leastPrice, p) =>
leastPrice === null ? p.price : Math.min(p.price, leastPrice),
null,
);
}

export function getGroupLeastPrice(
group: TCatalogGroup,
regions: TRegion[],
models: TVolumeAddon[],
): number | null {
const groupRegions = regions
.filter((r) => r.type === group.name)
.map((r) => r.name);

const hasGroupRegions = (p: TVolumePricing) =>
p.regions.some(groupRegions.includes);

return models
.map((m) => getLeastPrice(m.pricings.filter(hasGroupRegions)))
.filter((p) => p !== null)
.reduce<number | null>(
(leastPrice, modelLeastPrice) =>
leastPrice === null
? modelLeastPrice
: Math.min(modelLeastPrice, leastPrice),
null,
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface Instance {
planCode: string;
operationIds: string[];
currentMonthOutgoingTraffic: number;
availabilityZone?: string;
}

export interface MonthlyBilling {
Expand Down
29 changes: 11 additions & 18 deletions packages/manager/apps/pci-block-storage/src/api/data/regions.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
import { fetchIcebergV6 } from '@ovh-ux/manager-core-api';
import { TVolumeCatalogElementFilter } from '@/api/data/catalog';

export type TRegion = {
name: string;
type: string;
status: string;
continentCode: string;
services: {
name: string;
status: string;
endpoint: string;
}[];
datacenterLocation: string;
type: 'region-3-az' | 'region' | 'localzone';
availabilityZones: string[];
isInMaintenance: boolean;
isActivated: boolean;
country: string;
filters: TVolumeCatalogElementFilter;
datacenter: string;
};

export const getProjectRegions = async (
projectId: string,
): Promise<TRegion[]> => {
const { data } = await fetchIcebergV6<TRegion>({
route: `/cloud/project/${projectId}/region`,
});
return data;
};
export function isRegionWith3AZ(region: Pick<TRegion, 'type'>) {
return region.type === 'region-3-az';
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export type TVolume = {
planCode: string;
type: string;
regionName: string;
availabilityZone?: string;
};

export type VolumeOptions = {
Expand Down Expand Up @@ -185,7 +186,7 @@ export interface AddVolumeProps {
regionName: string;
volumeCapacity: number;
volumeType: string;
availabilityZone?: string;
availabilityZone: string | null;
}

export const addVolume = async ({
Expand All @@ -194,13 +195,15 @@ export const addVolume = async ({
regionName,
volumeCapacity,
volumeType,
availabilityZone,
}: AddVolumeProps): Promise<void> => {
const { data } = await v6.post<void>(
`/cloud/project/${projectId}/region/${regionName}/volume`,
{
name,
size: volumeCapacity,
type: volumeType,
availabilityZone,
},
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
import { useQuery } from '@tanstack/react-query';
import { useMe } from '@ovh-ux/manager-react-components';
import { getCatalog } from '@ovh-ux/manager-pci-common';
import { getVolumeCatalog } from '@/api/data/catalog';

export const getCatalogQuery = (ovhSubsidiary: string) => ({
queryKey: ['catalog'],
queryFn: () => getCatalog(ovhSubsidiary),
});

/**
* @deprecated use {@link useVolumeCatalog} instead
*/
export const useCatalog = () => {
const { me } = useMe();
return useQuery({
...getCatalogQuery(me?.ovhSubsidiary),
enabled: !!me,
});
};

export const useVolumeCatalog = (projectId: string) =>
useQuery({
queryKey: ['projects', projectId, 'catalog', 'volume'],
queryFn: () => getVolumeCatalog(projectId),
});

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { useVolumeCatalog } from '@/api/hooks/useCatalog';

export const useHas3AZRegion = (projectId: string) => {
const { data: volumeCatalog, isPending } = useVolumeCatalog(projectId);

return {
has3AZ:
volumeCatalog?.models.some((m) =>
m.filters.deployment.includes('region-3-az'),
) || false,
isPending,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ export const getInstanceQueryKey = (projectId: string, instanceId: string) => [
export const useInstance = (projectId: string, instanceId: string) =>
useQuery({
queryKey: getInstanceQueryKey(projectId, instanceId),
queryFn: (): Promise<Required<Instance>> =>
getInstance(projectId, instanceId),
queryFn: (): Promise<Instance> => getInstance(projectId, instanceId),
enabled: !!instanceId,
});

Expand All @@ -25,7 +24,7 @@ export const getInstancesQueryKey = (projectId: string, region: string) => [
export const useInstances = (projectId: string, region: string) =>
useQuery({
queryKey: getInstancesQueryKey(projectId, region),
queryFn: (): Promise<Required<Instance>[]> =>
getInstancesByRegion(projectId, region) as Promise<Required<Instance>[]>,
queryFn: (): Promise<Instance[]> =>
getInstancesByRegion(projectId, region) as Promise<Instance[]>,
enabled: !!region,
});

This file was deleted.

Loading

0 comments on commit 348b94f

Please sign in to comment.