Hot questions for Using Azure in virtual machine

Top Java Programmings / Azure / virtual machine


Case 1. I installed mongo on my machine (Mac OS), and mongo is configured with bind-ip : A remote machine in LAN can connect to my mongodb using my IP. (Wrong observation : See UPDATE section)

Case 2. I installed mongo on Azure Ubuntu VM, mongo configured with bind-ip: No remote machine from the same VNet can connect to that mongo using private vnet IP.

MongoDB Network Setting (both case 1 and case 2):

# network interfaces
  port: 27017

Exception (Case 2):

2018-04-03 06:35:29.948 INFO 44518 --- [] org.mongodb.driver.cluster : Exception in monitor thread while connecting to server

com.mongodb.MongoSocketOpenException: Exception opening socket at ~[mongodb-driver-core-3.4.1.jar!/:na] at ~[mongodb-driver-core-3.4.1.jar!/:na] at com.mongodb.connection.DefaultServerMonitor$ ~[mongodb-driver-core-3.4.1.jar!/:na] at [na:1.8.0_151] Caused by: Connection refused (Connection refused) at Method) ~[na:1.8.0_151] at ~[na:1.8.0_151] at ~[na:1.8.0_151] at ~[na:1.8.0_151] at ~[na:1.8.0_151] at ~[na:1.8.0_151] at com.mongodb.connection.SocketStreamHelper.initialize( ~[mongodb-driver-core-3.4.1.jar!/:na] at ~[mongodb-driver-core-3.4.1.jar!/:na] ... 3 common frames omitted

Whats is different in Azure VM that it behaves differently from a Mac OS installation?

Note: Changing the bindIp to the IP ( or works.


Case 1: The remote access on my local machine's mongo was because of the distribution I picked which was configured to allow remote connections.


Based on my knowledge, only works inside machine. You could check this blog.

By default, MongoDB bind to local interface only, it will restrict the remote connections. If you don’t care about security, just comment out to accept any remote connections (NOT Recommend).

I suggest you could configure Mongodb like bind_ip =,


I'm trying to create a VM using Azure's Java ARM SDK (0.9.3) and I want to tag all of the related resources with a tag, so later on I can delete them by this tag (and I don't want to create a separate resource group for this VM and then delete it).

I have seen in the feedback forums here - that others are trying to do the same, but is there a way to tag all the related resources during creation time, rather that iterating all of them, because this will be the same as deleting them one by one.

In general - is there a better way for deleting all the resources without tags?



@s-rusev, It seems that the only way for deleting all the resources without tags is using Azure Resource Management REST API for template deployments to creating and deleting a VM. Please see the REST API reference Template Deployments to know how to manage deployments of multiple resources.


I am looking for a way to get the power state of a VM through the Azure ARM API (more specifically with the Java SDK), so far without any luck.

The code which retrieves the VM is the following:


public void getVirtualMachine() throws Exception {
    ComputeManagementClient client = ComputeManagementService.create(createConfiguration());
    VirtualMachineGetResponse response = client.getVirtualMachinesOperations().get("vdimtest5rg", "vdim-test-5");
    VirtualMachine virtualMachine = response.getVirtualMachine();

The REST call to which this results is:

GET /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{virtualMachineName}?api-version=2015-06-15

What is the recommended way to get the power state of a virtual machine in Azure through ARM?

I don't mind using a plain HTTP request, as long as I don't have to fall back to the ASM API and authenticate with a client certificate.


You need to be calling the 'InstanceView' of the virtual machine, which will give you the status of the associated disks and machine.


Which should give you something that contains a snippet like this -

  "statuses": [
      "code": "ProvisioningState/succeeded",
      "level": "Info",
      "displayStatus": "Provisioning succeeded",
      "time": "2016-01-26T20:00:46.4647319+00:00"
      "code": "PowerState/running",
      "level": "Info",
      "displayStatus": "VM running"


I am using the Azure Rest API. How can I check if a virtual machine is running or stopped? for first I thought to use the provisioning State, but it gives no useful info


Try the code below. PowerState is what you need to check.

       using (ComputeManagementClient computeClient = new ComputeManagementClient(credentials))
            HostedServiceListResponse services  = await computeClient.HostedServices.ListAsync();
            foreach(HostedServiceListResponse.HostedService service in services.HostedServices)
                DeploymentGetResponse deployment = await computeClient.Deployments.GetBySlotAsync(service.ServiceName, DeploymentSlot.Production);

                var powerState = deployment.RoleInstances[0].PowerState;



I have created a Java Web Application using Jetty (in Eclipse, using OSGI etc.). The application itself runs quite well (when being tested locally), so I wanted to run it on an Azure virtual machine in order to be accessible for external users (for testing reasons).

What I did so far:

  • created an Azure account
  • create a virtual machine with Windows Server running in it
  • downloaded all my eclipse files etc. to the virtual machine
  • started the application (in fact in eclipse, not the compiled jar) in the virtual machine; the application is published to port 8080
  • so, when i run a webbrowser in the VM and connect to localhost:8080, everything works well
  • but when I try to access the website from external (using my assigned domain of the VM,, it does not work
  • I also created endpoints in the azure management console for this VM (80, 8080, etc.)

Does anyone ever tried to run a java webapp on Azure or has a hint what could go wrong here?


By default, windows servers in Azure have the windows firewall enabled. This would block external connections to port 8080 by default. Try adding an appropriate exception to the windows firewall rules.


Tried to run the from Azure-Java-SDK

   VirtualMachine vm = ComputeHelper.createVM(
                        resourceManagementClient, computeManagementClient, networkResourceProviderClient, storageManagementClient,
                        context, "javaSampleVM", "Foo12", "BaR@123rgababaab")

                System.out.println(vm.getName() + " is created");

and got the following error.

Exception in thread "main" java.util.concurrent.ExecutionException: MissingSubscriptionRegistration: The subscription is not registered to use namespace 'Microsoft.Storage'.
    at java.util.concurrent.FutureTask.get(

As I'm new to Azure from AWS, couldn't understand where to begin. saw same kind of error releavnt to Azure PS. But not much helpful. Please suggest something. I'm using Azure Active Directory Auth. Thanks.


The issue is caused by authenticating with Azure AD. The doc "Authenticating Azure Resource Management request"( says "All of the tasks that you do on resources using the Azure Resource Manager must be authenticated with Azure Active Directory. ". So using the Azure Resource Management API of Class ComputeHelper must be authenticated with AAD.

You need to setup authentication on Azure AD by using the Management Portal firstly. For the steps of details, please refer to and

There is a sample project ( for calling Azure AD in Java that it can help you.


Tell me please, how can I get all options for instance on Azure using Java ?

For example, I mean all VM parameters: name, instance type, launch time and etc. So that I can use them in my code and get a detailed message in case of all kinds of errors associated with the VM on Azure. Thanks


You can use Azure virtual machine libraries to manage your virtual machines.

To use Azure management library, firstly, you need to get authenticated. For more details, you may refer to: Authentication in Azure Management Libraries for Java

Another way is to use Azure REST API. Here is the tutorial for your getting started:

You can use HttpClient or You can also directly try that API on the page:


I have a springboot application running on a Microsoft azure VM machine, which I want to be able to communicate with from the outside world.

When I type in the address to the application in a browser on the VM machine, which in this case is http://localhost:8080/spring, I get the expected reply back.

However, when I try to reach this application from any other device, even when using the public ip address for the virtualmachine, for some reason I cannot access it.

Do anyone of you know what I should do to solve this problem?


You will need to export the port that you want to access externally.

You can find a documentation on how to open ports here, through the Azure portal.

To summarize from their documentation:

  1. Create a Network Security Group (NSG)
  2. Select from the newly created NSG, create a new Inbound security rule
  3. Select HTTP, your port that you desire (in your case 8080), priority 100, give it a name.
  4. Your final step is to associate your NSG with a subnet or a specific network interface.


I am trying to Create Virtual Machine Deployment operation through azure rest API as of the documentation here.

But I fail to figure out parameters to create a VM with a OSImage(like Ubuntu 14.04). What should be the values for SourceImageName and MediaLink of OSVirtualHadrDisk?


You can easily get a list of available image names using Get-AzureVMImage from the Azure PowerShell Cmdlets.

Get-AzureVMImage | where { $_.ImageFamily -like "*ubuntu*14.04*" } | Sort-Object PublishedDate | Format-List ImageFamily, ImageName

ImageFamily : Ubuntu Server 14.04 LTS
ImageName   : b39f27a8b8c64d52b05eac6a62ebad85__Ubuntu-14_04_1-LTS-amd64-server-20140927-en-us-30GB

ImageFamily : Ubuntu Server 14.04 LTS
ImageName   : b39f27a8b8c64d52b05eac6a62ebad85__Ubuntu-14_04_1-LTS-amd64-server-20141125-en-us-30GB

ImageFamily : Ubuntu Server 14.04 LTS
ImageName   : b39f27a8b8c64d52b05eac6a62ebad85__Ubuntu-14_04_1-LTS-amd64-server-20150123-en-us-30GB

So, for example, your SourceImageName would be as follows for the image published 01-23-2015:


The MediaLink is the name and location of the VHD that is created for your virtual machine. It can be any name you want provided it resides in your Azure Storage Account. For example:


If you want to see an example, create a Virtual Machine in your subscription using the Azure Management Portal and then look at the Disks section of the DASHBOARD page for your Virtual Machine.