Skip to content

Conversation

@gapra-msft
Copy link
Member

Description

Refactor of jobs resume code for AzCopy as a library.

  • Feature / Bug Fix: (Brief description of the feature or issue being addressed)

  • Related Links:

  • Issues

  • Team thread

  • Documents

  • [Email Subject]

Type of Change

  • Bug fix
  • New feature
  • Documentation update required
  • Code quality improvement
  • Other (describe):

How Has This Been Tested?

Existing integration tests as this is a refactor.
Thank you for your contribution to AzCopy!

Copilot AI review requested due to automatic review settings November 11, 2025 17:54
@gapra-msft gapra-msft changed the title Gapra/resume migration Migrated resume code Nov 11, 2025
Copilot finished reviewing on behalf of gapra-msft November 11, 2025 17:57
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the jobs resume functionality in AzCopy to support library usage, moving resume-related code from the CLI layer into the azcopy package. The refactoring enables programmatic job resumption while maintaining CLI compatibility.

Key Changes

  • Migrated resume job logic from cmd/jobsResume.go to azcopy/jobsResume.go, exposing ResumeJob() as a public API
  • Introduced JobLifecycleManager to handle job lifecycle events with adaptive progress reporting
  • Moved credential utility functions to azcopy/credentialUtil.go for shared use between CLI and library modes

Reviewed Changes

Copilot reviewed 21 out of 21 changed files in this pull request and generated 14 comments.

Show a summary per file
File Description
ste/mgr-JobPartMgr.go Removed obsolete include/exclude transfer list check
ste/mgr-JobMgr.go Removed include/exclude transfer methods and fields from job manager
jobsAdmin/init.go Simplified ResumeJobOrder by removing SAS stripping and include/exclude logic
common/rpc-models.go Removed obsolete SourceSAS, DestinationSAS, IncludeTransfer, and ExcludeTransfer fields from ResumeJobRequest
cmd/sync.go Updated constant reference from base10Mega to azcopy.Base10Mega
cmd/root.go Refactored Initialize function to handle library mode vs CLI mode initialization
cmd/jobsShow.go Updated API calls to pass JobID as first parameter instead of in options
cmd/jobsResume.go Completely refactored to use new azcopy.ResumeJob API with handler pattern
cmd/jobsRemove.go Updated API call signature to pass JobID as first parameter
cmd/credentialUtil.go Delegated credential logic to azcopy package functions
cmd/copyEnumeratorInit.go Fixed trailing whitespace and variable reference
cmd/copy.go Updated constant reference from base10Mega to azcopy.Base10Mega
cmd/constants.go Removed constants migrated to azcopy package
cmd/cancel.go Updated API call signature for GetJobSummary
azcopy/zt_credentialUtil_test.go Moved and updated credential tests to azcopy package
azcopy/jobsShow.go Updated API to take JobID as first parameter with cleaner option structs
azcopy/jobsResume.go New file implementing ResumeJob API with handler pattern for progress tracking
azcopy/jobsRemove.go Updated API signature to take JobID as first parameter
azcopy/jobLifecycleManager.go New file implementing job lifecycle management with adaptive progress reporting
azcopy/credentialUtil.go New file consolidating credential utility functions for library usage
azcopy/client.go Added LogLevel support and moved constants from cmd package

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +105 to +106
// TODO : rename interface method to OnError to match other method naming conventions
func (j *JobLifecycleManager) Error(err string) {
Copy link

Copilot AI Nov 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The TODO comment on line 105 mentions renaming the interface method to OnError to match naming conventions, but this hasn't been addressed. This should either be implemented or the TODO should be tracked elsewhere to ensure consistency across the API.

Suggested change
// TODO : rename interface method to OnError to match other method naming conventions
func (j *JobLifecycleManager) Error(err string) {
// Renamed to OnError to match other method naming conventions
func (j *JobLifecycleManager) OnError(err string) {

Copilot uses AI. Check for mistakes.
}
return false, nil
}

Copy link

Copilot AI Nov 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing documentation for the exported function GetCredentialTypeForLocation. Public API functions should have doc comments explaining their parameters, return values, and behavior.

Suggested change
// GetCredentialTypeForLocation determines the appropriate credential type to use for a given storage location and resource.
//
// Parameters:
// - ctx: The context for cancellation and deadlines.
// - location: The storage location (e.g., Azure, local, etc.).
// - resource: The resource string representing the target or source.
// - isSource: True if the resource is a source; false if it is a destination.
// - cpkOptions: Options for customer-provided keys.
// - uotm: User OAuth token manager for managing OAuth tokens.
//
// Returns:
// - credType: The determined credential type for accessing the resource.
// - isPublic: True if the resource is publicly accessible; false otherwise.
// - err: Any error encountered during determination.

Copilot uses AI. Check for mistakes.
Comment on lines +48 to +51
type ResumeJobHandler interface {
OnStart(ctx JobContext)
OnTransferProgress(progress ResumeJobProgress)
}
Copy link

Copilot AI Nov 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing documentation for the exported ResumeJobHandler interface. Public API interfaces should have doc comments describing their contract and when they will be called.

Copilot uses AI. Check for mistakes.
Comment on lines +34 to +45
type JobProgressTracker interface {
// Start - calls OnStart
Start()
// CheckProgress checks the progress of the job and returns the number of transfers completed so far and whether the job is done
CheckProgress() (uint32, bool)
// CompletedEnumeration checks whether the enumeration is complete
CompletedEnumeration() bool // Whether we should prompt before cancelling
// GetJobID returns the JobID of the job being tracked
GetJobID() common.JobID
// GetElapsedTime returns the elapsed time since the job started
GetElapsedTime() time.Duration
}
Copy link

Copilot AI Nov 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing documentation for the exported JobProgressTracker interface. Public API interfaces should have doc comments explaining the contract and typical usage patterns.

Copilot uses AI. Check for mistakes.

func warnIfSharedKeyAuthForDatalake() {
sharedKeyDeprecation.Do(func() {
common.GetLifecycleMgr().Warn(sharedKeyDeprecationMessage)
Copy link

Copilot AI Nov 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reference to common.GetLifecycleMgr() may return nil in library mode, but the code immediately calls .Warn() on line 52. While there's a nil check in the function body at line 128, the warnIfSharedKeyAuthForDatalake function doesn't guard against this nil case and could panic.

Suggested change
common.GetLifecycleMgr().Warn(sharedKeyDeprecationMessage)
lcm := common.GetLifecycleMgr()
if lcm != nil {
lcm.Warn(sharedKeyDeprecationMessage)
}

Copilot uses AI. Check for mistakes.
Comment on lines +220 to +221
common.GetLifecycleMgr().Info(message)
}
Copy link

Copilot AI Nov 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The call to common.GetLifecycleMgr().Info(message) on line 220 may panic if GetLifecycleMgr() returns nil, which can happen in library mode. A nil check is needed before calling the method.

Suggested change
common.GetLifecycleMgr().Info(message)
}
if mgr := common.GetLifecycleMgr(); mgr != nil {
mgr.Info(message)
}

Copilot uses AI. Check for mistakes.
return
}

if err = checkAuthSafeForTarget(credType, resource.Value, TrustedSuffixes, location); err != nil {
Copy link

Copilot AI Nov 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the check for TrustedSuffixes on line 330, the code references a global variable TrustedSuffixes that may not be set in the azcopy package context. The checkAuthSafeForTarget function receives extraSuffixesAAD as a parameter but on line 330 it references the global TrustedSuffixes variable. This should use a local reference or be passed as a parameter to ensure it has the correct value.

Suggested change
if err = checkAuthSafeForTarget(credType, resource.Value, TrustedSuffixes, location); err != nil {
if err = checkAuthSafeForTarget(credType, resource.Value, TrustedSuffixesAAD, location); err != nil {

Copilot uses AI. Check for mistakes.
Comment on lines +42 to +46
type ResumeJobProgress struct {
common.ListJobSummaryResponse
Throughput float64
ElapsedTime time.Duration
}
Copy link

Copilot AI Nov 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing documentation for the exported ResumeJobProgress struct. Public API types should have doc comments explaining their purpose, especially since this is part of the library API migration.

Copilot uses AI. Check for mistakes.
Comment on lines +53 to +56
type ResumeJobResult struct {
common.ListJobSummaryResponse
ElapsedTime time.Duration
}
Copy link

Copilot AI Nov 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing documentation for the exported ResumeJobResult struct. Public API types should have doc comments explaining what they represent.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants