Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions src/js/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,87 @@ const useDeleteCertificateFromZenkoConfigurationMutation = (
return usePatchZenkoConfigurationMutation(patch, options);
};

// Veeam repository automation types
export type VeeamRepositoryRequest = {
repositoryName: string;
servicePoint: string;
accessKey: string;
secretKey: string;
bucketName: string;
region?: string;
immutable?: boolean;
immutablePeriodDays?: number;
storageConsumptionLimitKind: string;
storageConsumptionLimitCount: number;
};

export type VeeamRepositoryResponse = {
status: 'success' | 'error';
repositoryID?: string;
repositoryName?: string;
message?: string;
};

const useCreateVeeamRepositoryMutation = () => {
const { useAuth } = useShellHooks();
const { getToken } = useAuth();

return useMutation<VeeamRepositoryResponse, ApiError, VeeamRepositoryRequest>(
{
mutationFn: async (repositoryConfig) => {
const response = await fetch('/api/veeam-automation/create-s3-repo', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${await getToken()}`,
},
body: JSON.stringify({
repositoryName: repositoryConfig.repositoryName,
servicePoint: repositoryConfig.servicePoint,
accessKey: repositoryConfig.accessKey,
secretKey: repositoryConfig.secretKey,
bucketName: repositoryConfig.bucketName,
region: repositoryConfig.region,
...(repositoryConfig.immutable !== undefined && {
immutable: repositoryConfig.immutable,
}),
...(repositoryConfig.immutablePeriodDays !== undefined && {
immutablePeriodDays: repositoryConfig.immutablePeriodDays,
}),
storageConsumptionLimitKind:
repositoryConfig.storageConsumptionLimitKind,
storageConsumptionLimitCount:
repositoryConfig.storageConsumptionLimitCount,
}),
});

if (!response.ok) {
const errorData = await response.json().catch(() => ({
message: 'Failed to create Veeam repository',
}));
const error: ApiError = {
name: 'ApiError',
message:
errorData.message ||
`HTTP ${response.status}: ${response.statusText}`,
status: (response.status as ApiError['status']) || 500,
};
throw error;
}

const data = await response.json();

return {
status: data.status,
repositoryID: data.repositoryId,
repositoryName: data.repositoryName,
message: data.message,
};
},
},
);
};

export {
useAddCertificateToZenkoConfigurationMutation,
useAttachPolicyToUserMutation,
Expand All @@ -564,6 +645,7 @@ export {
useCreateOrAddBucketToPolicyMutation,
useCreatePolicyMutation,
useCreateUserAccessKeyMutation,
useCreateVeeamRepositoryMutation,
useDeleteCertificateFromZenkoConfigurationMutation,
useEnableSOSAPIMutation,
usePatchZenkoConfigurationMutation,
Expand Down
18 changes: 16 additions & 2 deletions src/js/useChainedMutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,26 @@ export const useChainedMutations = <T extends any[]>({
>(mutations);
const go = (results: unknown[] = []) => {
const index = results.length;

if (!mutations[index]) {
return;
}

const mutation = mutations[index];
if (!mutation.key) {
return;
}

const compute = computeVariablesForNext[
mutations[index].key
mutation.key
] as ComputeVariablesForNextBuilder<unknown[], unknown>;

if (!compute) {
return;
}

const mutateAndTriggerNext = () => {
mutations[index].mutate(compute(results), {
mutation.mutate(compute(results), {
onSuccess: (data: unknown) => {
if (index < mutations.length - 1) {
go([...results, data]);
Expand Down
38 changes: 32 additions & 6 deletions src/react/ISV/components/BucketField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
CapacityFormSection,
} from './ISVCapacityFormSection';
import { unitChoices } from '../constants';
import { useIsVeeamVBROnly } from '../hooks/useIsVeeamVBROnly';

const MIN_BUCKETS = 1;
const MAX_BUCKETS = 20;
Expand Down Expand Up @@ -90,6 +91,7 @@ interface BucketField {
interface FormValues {
buckets: BucketField[];
bucketNumber?: number;
autoCreateRepository?: boolean;
}

const defaultBucketNameTooltip = (
Expand All @@ -112,19 +114,37 @@ const BucketNameFormGroup: React.FC<{
bucketNamePlaceholder: string;
bucketNumber: number;
bucketNameTooltip: React.ReactElement;
platform?: string;
}> = ({
index,
errors,
bucketNamePlaceholder,
bucketNumber,
bucketNameTooltip,
platform,
}) => {
const { register } = useFormContext<FormValues>();
const { register, watch } = useFormContext<FormValues>();
const isVeeamVBROnly = useIsVeeamVBROnly();

// Check if we're in Veeam context with auto-creation enabled
const autoCreateRepository = watch('autoCreateRepository');
const isVeeamAutoCreation =
isVeeamVBROnly && platform === 'veeam-vbr' && autoCreateRepository;

// Determine the appropriate label
const getLabel = () => {
if (isVeeamAutoCreation) {
return bucketNumber > 1
? `Veeam Repository #${index + 1} Name`
: 'Veeam Repository Name';
}
return bucketNumber > 1 ? `Bucket #${index + 1} name` : 'Bucket name';
};

return (
<FormGroup
id={`bucketName-${index}`}
label={bucketNumber > 1 ? `Bucket #${index + 1} name` : 'Bucket name'}
label={getLabel()}
required
labelHelpTooltip={bucketNameTooltip}
error={(errors?.buckets?.[index]?.name?.message as string) ?? ''}
Expand Down Expand Up @@ -204,10 +224,13 @@ const BucketField: React.FC<BucketFieldProps> = ({
}
}, [fields.length]);

const bucketNamePlaceholder = useMemo(
() => `${platform}-bucket-name`,
[platform],
);
const bucketNamePlaceholder = useMemo(() => {
const isVeeamVBROnly = platform === 'veeam-vbr';
if (isVeeamVBROnly) {
return `veeam-repository-name`;
}
return `${platform}-bucket-name`;
}, [platform]);

const xCoreLibrary = useXCoreLibrary();
const { useClusterCapacity } =
Expand Down Expand Up @@ -244,6 +267,7 @@ const BucketField: React.FC<BucketFieldProps> = ({
bucketNamePlaceholder={bucketNamePlaceholder}
bucketNumber={fields.length}
bucketNameTooltip={bucketNameTooltip}
platform={platform}
/>
{renderCapacitySection(0)}
</FormSection>
Expand All @@ -258,6 +282,7 @@ const BucketField: React.FC<BucketFieldProps> = ({
bucketNamePlaceholder={bucketNamePlaceholder}
bucketNumber={fields.length}
bucketNameTooltip={bucketNameTooltip}
platform={platform}
/>
<div
style={{
Expand All @@ -277,6 +302,7 @@ const BucketField: React.FC<BucketFieldProps> = ({
bucketNamePlaceholder,
bucketNameTooltip,
renderCapacitySection,
platform,
]);

return (
Expand Down
78 changes: 75 additions & 3 deletions src/react/ISV/components/ISVApplyActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
usePutObjectMutation,
} from '../../../js/mutations';
import { useMultiMutation, Mutation } from '../hooks/useMultiMutation';
import { useVeeamAutoRepositoryFeature } from '../hooks/useVeeamAutoRepositoryFeature';

export const ListItem = styled.li`
padding: 0.5rem;
Expand Down Expand Up @@ -61,13 +62,21 @@ const BucketMutation = ({
const BucketVeeamMutation = ({
bucket,
onMutationReady,
autoCreateRepository,
isAutoRepoFeatureEnabled,
}: {
bucket: Bucket;
onMutationReady: (key: string, mutation: Mutation) => void;
autoCreateRepository?: boolean;
isAutoRepoFeatureEnabled?: boolean;
}) => {
const putVeeamFolderMutation = usePutObjectMutation();
const putVeeamSystemXmlMutation = usePutObjectMutation();
const putVeeamCapacityXmlMutation = usePutObjectMutation();
const putVeeamBackupFolderMutation = usePutObjectMutation();
const putVeeamBackupClientsFolderMutation = usePutObjectMutation();
const putVeeamBackupConfigFolderMutation = usePutObjectMutation();
const putVeeamArchiveFolderMutation = usePutObjectMutation();

useMemo(() => {
onMutationReady(`putVeeamFolder-${bucket.name}`, putVeeamFolderMutation);
Expand All @@ -79,10 +88,36 @@ const BucketVeeamMutation = ({
`putVeeamCapacityXml-${bucket.name}`,
putVeeamCapacityXmlMutation,
);

// Add folder creation mutations when auto-repository creation is enabled
if (isAutoRepoFeatureEnabled && autoCreateRepository) {
onMutationReady(
`putVeeamBackupFolder-${bucket.name}`,
putVeeamBackupFolderMutation,
);
onMutationReady(
`putVeeamBackupClientsFolder-${bucket.name}`,
putVeeamBackupClientsFolderMutation,
);
onMutationReady(
`putVeeamBackupConfigFolder-${bucket.name}`,
putVeeamBackupConfigFolderMutation,
);
onMutationReady(
`putVeeamArchiveFolder-${bucket.name}`,
putVeeamArchiveFolderMutation,
);
}
}, [
putVeeamFolderMutation.status,
putVeeamSystemXmlMutation.status,
putVeeamCapacityXmlMutation.status,
putVeeamBackupFolderMutation.status,
putVeeamBackupClientsFolderMutation.status,
putVeeamBackupConfigFolderMutation.status,
putVeeamArchiveFolderMutation.status,
autoCreateRepository,
isAutoRepoFeatureEnabled,
]);

return <></>;
Expand All @@ -107,8 +142,12 @@ const Main = ({
application,
platform,
accessKeys,
autoCreateRepository,
} = props;
const { data, accessKey, secretKey } = useMutationActions(props, mutations);
const { data, accessKey, secretKey, repositoryData } = useMutationActions(
props,
mutations,
);

const isCancellable = useMemo(
() => data.some((row) => row.status === 'error'),
Expand All @@ -129,6 +168,8 @@ const Main = ({
secretKey,
application,
accessKeys,
repositoryData,
autoCreateRepository,
});
}, [
accountName,
Expand All @@ -138,6 +179,8 @@ const Main = ({
secretKey,
application,
accessKeys,
repositoryData,
autoCreateRepository,
]);

const handleExit = useCallback(() => {
Expand Down Expand Up @@ -233,13 +276,40 @@ const Main = ({
);
};

const MUTATIONS_PER_BUCKET = {
DEFAULT: 2,
VEEAM_BASE: 5,
VEEAM_WITH_AUTO_REPO: 9,
} as const;

function calculateMutationCount(
bucketCount: number,
isVeeamVBR: boolean,
autoCreateRepository: boolean,
isAutoRepoFeatureEnabled: boolean,
): number {
if (!isVeeamVBR || !isAutoRepoFeatureEnabled) {
return bucketCount * MUTATIONS_PER_BUCKET.DEFAULT;
}

return autoCreateRepository
? bucketCount * MUTATIONS_PER_BUCKET.VEEAM_WITH_AUTO_REPO
: bucketCount * MUTATIONS_PER_BUCKET.VEEAM_BASE;
}

export default memo(function ISVApplyActions(props: ISVApplyActionsProps) {
const { buckets, platform } = props;
const { buckets, platform, autoCreateRepository } = props;
const isVeeamVBR = platform.id === 'veeam-vbr';
const isAutoRepoFeatureEnabled = useVeeamAutoRepositoryFeature();
const { mutations, handleMutationReady, isAllMutationsReady } =
useMultiMutation(
buckets,
isVeeamVBR ? buckets.length * 5 : buckets.length * 2,
calculateMutationCount(
buckets.length,
isVeeamVBR,
autoCreateRepository,
isAutoRepoFeatureEnabled,
),
);

return (
Expand All @@ -254,6 +324,8 @@ export default memo(function ISVApplyActions(props: ISVApplyActionsProps) {
<BucketVeeamMutation
bucket={bucket}
onMutationReady={handleMutationReady}
autoCreateRepository={autoCreateRepository}
isAutoRepoFeatureEnabled={isAutoRepoFeatureEnabled}
/>
)}
</Fragment>
Expand Down
Loading
Loading