From a2dcea64de40386e039591ce4d7801d2dc8f0b25 Mon Sep 17 00:00:00 2001 From: Nick Petrovic <4001122+nickpetrovic@users.noreply.github.com> Date: Thu, 9 Jan 2025 16:10:47 -0500 Subject: [PATCH] replace selecting version for enabling multipart --- pkg/abstractions/volume/multipart.go | 5 ++--- pkg/common/config.default.yaml | 2 +- pkg/types/config.go | 5 +++-- sdk/src/beta9/cli/volume.py | 33 ++++++++++++++++++---------- 4 files changed, 28 insertions(+), 17 deletions(-) diff --git a/pkg/abstractions/volume/multipart.go b/pkg/abstractions/volume/multipart.go index de2105b58..a619e10a7 100644 --- a/pkg/abstractions/volume/multipart.go +++ b/pkg/abstractions/volume/multipart.go @@ -50,9 +50,8 @@ func joinCleanPath(parts ...string) string { func (s *GlobalVolumeService) GetFileServiceInfo(ctx context.Context, in *pb.GetFileServiceInfoRequest) (*pb.GetFileServiceInfoResponse, error) { return &pb.GetFileServiceInfoResponse{ - Ok: true, - Enabled: s.config.EndpointURL != "" && s.config.BucketName != "", - CommandVersion: s.config.CommandVersion, + Ok: true, + Enabled: s.config.Enabled && s.config.EndpointURL != "" && s.config.BucketName != "", }, nil } diff --git a/pkg/common/config.default.yaml b/pkg/common/config.default.yaml index 588f2793c..268d12b51 100644 --- a/pkg/common/config.default.yaml +++ b/pkg/common/config.default.yaml @@ -57,12 +57,12 @@ gateway: maxReplicas: 10 maxGpuCount: 2 fileService: + enabled: true endpointUrl: http://juicefs-s3-gateway.beta9.svc.cluster.local:9900 bucketName: beta9-fs accessKey: test secretKey: test-test-test region: - commandVersion: 1 imageService: localCacheEnabled: true registryStore: local diff --git a/pkg/types/config.go b/pkg/types/config.go index 2223fe77c..b5e7184ae 100644 --- a/pkg/types/config.go +++ b/pkg/types/config.go @@ -130,8 +130,9 @@ type FileServiceConfig struct { SecretKey string `key:"secretKey" json:"secret_key"` Region string `key:"region" json:"region"` - // Determines which version of the copy command to use in the CLI - CommandVersion uint32 `key:"commandVersion" json:"command_version"` + // Determines if the SDK should use this service + // Requires that EndpointURL and BucketName are set + Enabled bool `key:"enabled" json:"enabled"` } type ImageServiceConfig struct { diff --git a/sdk/src/beta9/cli/volume.py b/sdk/src/beta9/cli/volume.py index b3fec2096..e1277b9ba 100644 --- a/sdk/src/beta9/cli/volume.py +++ b/sdk/src/beta9/cli/volume.py @@ -1,6 +1,6 @@ import glob from pathlib import Path -from typing import Iterable, List, Union +from typing import Iterable, List, Optional, Union import click from rich.table import Column, Table, box @@ -151,9 +151,8 @@ def read_with_progress( @common.command( help="Upload or download contents to or from a volume.", epilog=""" - Version 1: + Version 1 (Streaming uploads to the Gateway): - !!! This is deprecated. Use v2 of this command. Uploads files or directories to a volume. Downloads are not supported. SOURCE and DESTINATION syntax: @@ -193,10 +192,15 @@ def read_with_progress( {cli_name} cp mydir/\\[a-c\\]/data[0-1].json' myvol/data {cli_name} cp mydir/\\?/data\\?.json myvol/sub/path - Version 2: + Version 2 (Multipart uploads/downloads via an external file service): Upload and download files or directories between a volume and your system. + This is available if the Gateway has a file service configured and enabled. + When enabled, this command will use the external file service to upload and + download files directly only using the Gateway for initiating, completing, or + cancelling the transfer. + SOURCE and DESTINATION syntax: SOURCE can be local or remote. @@ -249,10 +253,9 @@ def read_with_progress( required=True, ) @click.option( - "--version", - is_eager=True, - type=click.Choice(["1", "2"]), - help="The version of this command to run. [default is determined by the server]", + "--multipart/--no-multipart", + "use_multipart", + help="Use multipart upload/download. [default: True if the server supports it, else False]", default=None, required=False, ) @@ -261,12 +264,20 @@ def cp( service: ServiceClient, source: Union[Path, RemotePath], destination: Union[Path, RemotePath], - version: str, + use_multipart: Optional[bool], ): res = service.volume.get_file_service_info(GetFileServiceInfoRequest()) - if version == "1" or (version is None and res.command_version == 1) or not res.enabled: + if res.enabled and (use_multipart is None or use_multipart): + use_multipart = True + elif not res.enabled and use_multipart: + terminal.warn("Multipart upload/download is not currently supported by the server.") + use_multipart = False + + if not use_multipart: if "://" in str(source) or "://" in str(destination): - raise click.BadArgumentUsage("Remote path syntax ($scheme://) is not supported in v1.") + raise click.BadArgumentUsage( + "Remote path syntax ($scheme://) is not supported without multipart transfers enabled." + ) return cp_v1(service, source, destination) # type: ignore if isinstance(source, Path) and isinstance(destination, Path):