Querying Details About an Instance
This section describes how to query an instance using AK/SK authentication.
Replace the AK/SK in the sample code with the actual AK/SK. Use the setInstanceName method of the RunQueryInstanceRequest class to specify the name of the instance you want to query. After the configuration is complete, run the code.
- The sample code for querying an instance is as follows:
import com.alibaba.fastjson.JSON; import com.huaweicloud.sdk.core.auth.ICredential; import com.huaweicloud.sdk.core.auth.BasicCredentials; import com.huaweicloud.sdk.core.exception.ConnectionException; import com.huaweicloud.sdk.core.exception.RequestTimeoutException; import com.huaweicloud.sdk.core.exception.ServiceResponseException; import com.huaweicloud.sdk.imagesearch.v1.*; import com.huaweicloud.sdk.imagesearch.v1.model.*; import com.huaweicloud.sdk.imagesearch.v1.region.ImageSearchRegion; /** * Display details about an instance. */ public class RunQueryInstanceSolution { public static void main(String[] args) { //Set the obtained AK and SK. String ak = "<YOUR AK>"; String sk = "<YOUR SK>"; ICredential auth = new BasicCredentials() .withAk(ak) .withSk(sk); ImageSearchClient client = ImageSearchClient.newBuilder() .withCredential(auth) //Set the region. In this example, CN North-Beijing4 is used. .withRegion(ImageSearchRegion.valueOf("cn-north-4")) .build(); RunQueryInstanceRequest request = new RunQueryInstanceRequest(); //Set the instance name. request.setInstanceName("instance-name"); try { RunQueryInstanceResponse response = client.runQueryInstance(request); System.out.println(JSON.toJSONString(response)); } catch (ConnectionException e) { e.printStackTrace(); } catch (RequestTimeoutException e) { e.printStackTrace(); } catch (ServiceResponseException e) { e.printStackTrace(); System.out.println(e.getHttpStatusCode()); System.out.println(e.getErrorCode()); System.out.println(e.getErrorMsg()); } } }
- Execute the sample code. If the instance querying result is displayed on the console, the code is successfully executed. For details, see Querying the Details About an Instance.
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". SLF4J: Defaulting to no-operation (NOP) logger implementation SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details. {"desc":"","domain":"general image search","expiredDate":-1,"httpStatusCode":200,"instanceName":"instance-name","level":30000000,"registerDate":1637230766199,"status":{"value":"NORMAL"},"tags":["animal","plant"]} Process finished with exit code 0
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot