简体   繁体   中英

Azure Batch client, how to test for validity?

I'm working on integrating with the Azure Batch API and construct a client object based on credentials I pass through. What I want to know is how can I test to see whether the connection is valid and the credentials are correct? I can't see anything on the API to do this. You can just create the BatchClient object and then call operations on it to list jobs, pools etc, all of which fail with a complex error if your initial credentials were wrong. I want to be able to test for incorrect credentials before I attempt any other operations. Does anyone know how to do this?

var client = BatchClient.Open(new BatchSharedKeyCredentials(
                                string.Format("https://{0}.{1}.batch.azure.com",
                                        _primaryBatchAccountName,
                                        _primaryRegion),
                                _primaryBatchAccountName,
                                _primaryBatchAccountKey));

This is the code to create the client object. But it doesn't throw any error even if you pass it completely wrong values. You only get the error when you try and do anything with it.

The BatchClient doesn't keep a persistent connection "open." It just issues REST requests to the target endpoint whenever required (ie when you use a method).

To the best of my knowledge, there is no way to determine if you have the "right" credentials values or endpoint data until you try to use the BatchClient to actually communicate with the server. This is because it's not really possible for the client to know what endpoints are valid, nor is it possible for it to know what a "valid" credential looks like, or if the credential you specified is correct (the server must verify that).

The best recommendation I can come up with is to just try to issue a simple API call (like a ListJobs or something) and ensure that it completes successfully. That should validate that your BatchClient is working.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM