-
Notifications
You must be signed in to change notification settings - Fork 667
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(azure-batch): Ignore pool already exists error #5721
Open
adamrtalbot
wants to merge
1
commit into
nextflow-io:master
Choose a base branch
from
adamrtalbot:azure-batch-ignore-409-pool-already-exists
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+132
−63
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,12 @@ import nextflow.util.Duration | |
import nextflow.util.MemoryUnit | ||
import spock.lang.Specification | ||
import spock.lang.Unroll | ||
import com.azure.core.exception.HttpResponseException | ||
import com.azure.core.http.HttpResponse | ||
import reactor.core.publisher.Flux | ||
import java.nio.ByteBuffer | ||
import java.nio.charset.StandardCharsets | ||
import com.azure.core.exception.ResourceExistsException | ||
/** | ||
* | ||
* @author Paolo Di Tommaso <[email protected]> | ||
|
@@ -739,4 +745,59 @@ class AzBatchServiceTest extends Specification { | |
[managedIdentity: [clientId: 'client-123']] | 'client-123' | ||
} | ||
|
||
def 'should handle pool exists error' () { | ||
given: | ||
def CONFIG = [batch:[location: 'northeurope']] | ||
def exec = Mock(AzBatchExecutor) {getConfig() >> new AzConfig(CONFIG) } | ||
def batchImage = GroovyMock(com.azure.compute.batch.models.BatchSupportedImage) | ||
def vmConfig = GroovyMock(com.azure.compute.batch.models.VirtualMachineConfiguration) | ||
def client = GroovyMock(com.azure.compute.batch.BatchClient) | ||
AzBatchService svc = Spy(new AzBatchService(exec)) { | ||
getImage(_) >> batchImage | ||
poolVmConfig(_) >> vmConfig | ||
getClient() >> client | ||
} | ||
and: | ||
def spec = new AzVmPoolSpec( | ||
poolId: 'pool-1', | ||
vmType: Mock(AzVmType) { | ||
getName() >> 'Standard_D1_v2' | ||
getNumberOfCores() >> 1 | ||
}, | ||
opts: new AzPoolOpts([:])) | ||
and: | ||
def errorBody = """{ | ||
"odata.metadata":"https://mybatch.eastus.batch.azure.com/\$metadata#Microsoft.Azure.Batch.Protocol.Entities.Container.errors/@Element", | ||
"code":"PoolExists", | ||
"message":{ | ||
"lang":"en-US", | ||
"value":"The specified pool already exists.\\nRequestId:d9475bc1-f9e5-492b-9114-6a05a8a57abc\\nTime:2025-01-23T14:15:51.6526349Z" | ||
} | ||
}""" | ||
def bodyBytes = errorBody.getBytes(StandardCharsets.UTF_8) | ||
def response = GroovyMock(HttpResponse) { | ||
getStatusCode() >> 409 | ||
getBodyAsString() >> errorBody | ||
getBody() >> Flux.just(ByteBuffer.wrap(bodyBytes)) | ||
} | ||
|
||
when: | ||
svc.createPool(spec) | ||
then: | ||
1 * client.createPool(_) >> { throw new com.azure.core.exception.ResourceExistsException("Pool exists", response) } | ||
noExceptionThrown() | ||
} | ||
|
||
def 'should retry on specific error codes' () { | ||
given: | ||
def CONFIG = [batch:[location: 'northeurope']] | ||
def exec = Mock(AzBatchExecutor) {getConfig() >> new AzConfig(CONFIG) } | ||
AzBatchService svc = Spy(new AzBatchService(exec)) | ||
|
||
when: | ||
def cond = svc.@RETRY_CODES | ||
then: | ||
cond.containsAll([408, 409, 429, 500, 502, 503, 504]) | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally speaking, when a long function needs to be wrapped in a try-catch like this, we like to put the try-catch in a separate wrapper function: