Search code examples
azureazure-resource-managerazure-api-managementazure-java-sdkazure-resource-group

While deleting vm in Azure, last status that I get is 'Deleting' and that too in provisioningState field. How to get 'Deleted' status?


I am using Java api (azure-compute:version 0.9.0) to perform VM operation. I want to make sure cloud operation on VM is performed successfully. I am getting some issue in Delete operation.

  • While beginDeleting(async) VM, I get Future and status in DeleteOperationResponse is Error once I get the response after future is Done.
  • Later after submitting beginDeleting(async), I am getting VM from VMGetResponse and then checking provisioningState after every 1 sec. After several 'Deleting', I get 'Error' state.

My expectation is to get VM object even after termination of instance with status like Deleted(or terminated) as I get in Amazon. So that I can get assured my cloud operation is successful.


Solution

  • Any APIs call of Azure SDK for Java are really calling the related Azure REST APIs. So according to the references of REST API Delete a virtual machine & Get information about a virtual machine, you only could get the error status which comes from the response 404 status code, as below, because the resource has been deleted.

    1. Quote from the description of Response of Delete a virtual machine.

      If resource does not exist, 404 (NotFound) is returned.

    2. Quote from the description of Response of Get information about a virtual machine.

      otherwise 404 (Not Found) is returned.

    For your question in the comment, if you want to get the last n number of logs, the only way is using Azure Monitor REST API in Java. On Azure Offical website, you can refer to the documents below to know Azure Monitor service.

    1. Audit Logs in Azure Preview Portal
    2. Get started with Azure Monitor
    3. View events and activity logs