Questions? Feedback? powered by Olark live chat software
Ignorar Navegação

Simpler Azure Management Libraries for Java

Publicado em 7 julho, 2016

Principal Program Manager, Azure Developer Experience

One Java statement to authenticate. One statement to create a virtual machine. One statement to modify an existing virtual network. No more guessing about what is required vs. optional vs. non-modifiable.

We are announcing the first developer preview release of the new, simplified Azure management libraries for Java. Our goal is to improve the developer experience by providing a higher-level, object-oriented API, optimized for readability and writability.

Azure authentication

One statement to authenticate and choose a subscription. The Azure class is the simplest entry point for creating and interacting with Azure resources.

Azure azure = Azure.authenticate(credFile).withDefaultSubscription();

Create a virtual machine

You can create a virtual machine instance by using the define() … create() method chain.

//=============================================================
// Create a Linux VM

System.out.println("Creating a Linux VM");

VirtualMachine linuxVM = azure.virtualMachines().define("myLinuxVM")
     .withRegion(Region.US_EAST)
     .withNewResourceGroup("myResourceGroup")
     .withNewPrimaryNetwork("10.0.0.0/28")
     .withPrimaryPrivateIpAddressDynamic()
     .withNewPrimaryPublicIpAddress("mylinuxvmdns")
     .withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_16_04_LTS)
     .withRootUserName("tirekicker")
     .withSsh(sshKey)
     .withSize(VirtualMachineSizeTypes.STANDARD_D3_V2)
     .create();

System.out.println("Created a Linux VM: " + linuxVM.id());

Update a virtual machine

You can update a virtual machine instance by using the update() … apply() method chain.

linuxVM.update()
     .defineNewDataDisk(dataDiskName)
     .withSizeInGB(20)
     .withCaching(CachingTypes.READ_WRITE)
     .attach()
     .apply();

Management libraries unleash the power of statement completion in Eclipse or IntelliJ

Fluent-inspired method chains in combination with statement completion deliver a wizard-like developer experience by presenting required and optional methods in the right sequence. For example, once you choose a Linux virtual machine image, statement completion will prompt for a root user name and nothing else.

Then, statement completion will prompt for an SSH key and nothing else. This will continue until you reach the minimum required to call create().

As another example, if you were to choose a Windows virtual machine image, statement completion would prompt for admin user name and then password.

Samples

You can find plenty of sample code that illustrates key management scenarios in Azure Compute, Storage, Network, and Resource Manager:

Give it a try

This is a developer preview that supports major parts of Azure Compute, Storage, Networking, and Resource Manager. You can run the samples above, go straight to the GitHub repo or browse Javadoc.

The next preview version of the Azure Management Libraries for Java is a work in-progress. We will be adding support for more Azure services and tweaking the API over the next few months.

Please give it a try and let us know what you think by answering a four-question survey, or sharing your thoughts on GitHub, Twitter, e-mail (Java at Microsoft dot com), or via the comments below. It would be particularly great to learn what you think about:

  • Usability and effectiveness of the new management libraries for Java.
  • What Azure services you would like to see supported soon.
  • What additional scenarios should be illustrated as sample code.
  • What your target platforms for apps that use management libraries for Java are (Windows, Linux, Mac, Android, etc.). 

We would also like to hear about the last time you used asynchronous calls for management and what async frameworks you took advantage of? Or, how you investigated failures and your thoughts on how we can help through the API to make you more productive?

You can find plenty of additional info about Java on Azure at http://azure.com/java.