1

I am using the Java sdk to try and automate some azure tasks like start a server and shutdown a server. I was using version 0.9.0 of the java sdk from the maven

           <dependency>
                <groupId>com.microsoft.azure</groupId>
                <artifactId>azure-svc-mgmt</artifactId>
                <version>0.9.0</version>
            </dependency>   

            <dependency>
                <groupId>com.microsoft.azure</groupId>
                <artifactId>azure-svc-mgmt-compute</artifactId>
                <version>0.9.0</version>
            </dependency>

This code compiled and ran successfully in eclipse

 package com.services.servers.operations.azure;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

import com.microsoft.windowsazure.Configuration;
import com.microsoft.windowsazure.core.utils.KeyStoreType;
import com.microsoft.windowsazure.exception.ServiceException;
import com.microsoft.windowsazure.management.compute.ComputeManagementClient;
import com.microsoft.windowsazure.management.compute.ComputeManagementService;
import com.microsoft.windowsazure.management.compute.VirtualMachineOperations;
import com.microsoft.windowsazure.management.configuration.ManagementConfiguration;

public class AzureTest {

    String uri = "https://management.core.windows.net/";
    String subscriptionId = "dasdas9-86da-4343-a1f4-24c20864e166";
    String keyStoreLocation = "C:\\Users\\test\\Desktop\\azure\\testKeystore.jks";
    String keyStorePassword = "password";

    public boolean startVirtualMachine(String serviceName, String deploymentName, String virtualMachineName){

        boolean isSuccess = true;

        try {            

            VirtualMachineOperations virtualMachineOperations = null;

            Configuration config = ManagementConfiguration.configure(
                        new URI(uri), 
                          subscriptionId,
                          keyStoreLocation, 
                          keyStorePassword, 
                          KeyStoreType.jks 
                      );

            ComputeManagementClient computeManagementClient = ComputeManagementService.create(config);

            virtualMachineOperations = computeManagementClient.getVirtualMachinesOperations();

            virtualMachineOperations.beginStarting(serviceName, deploymentName, virtualMachineName);

        } catch (IOException e) {
            System.out.println("An IOException has occured. Exception: " +e);
            isSuccess = false;
        }  catch (ServiceException e) {
            System.out.println("A ServiceException has occured. Exception: " + e);
            isSuccess = false;
        } catch (URISyntaxException e) {
            System.out.println("A URISyntaxException has occured. Exception: " + e);
            isSuccess = false;
        }         


        return isSuccess;
    }

}

When I upgrade to the latest version of the sdk - 0.9.1 - the following classes dont exist any longer

import com.microsoft.windowsazure.Configuration;
import com.microsoft.windowsazure.core.utils.KeyStoreType;
import com.microsoft.windowsazure.exception.ServiceException;
import com.microsoft.windowsazure.management.configuration.ManagementConfiguration;

I couldnt find anything online to state where these classes have gone to - whether they have been deprecated or more to another lib

If anyone has any idea what classes I should instead or what libs they may have moved to- that would be great Or if anyone can suggest any improvements to the above code for starting a server that would be much appreciated

Thanks Damien

Damien
  • 4,081
  • 12
  • 75
  • 126

2 Answers2

1

I tried to reproduce the issue, I got the error Failed to read artifact descriptor for com.microsoft.azure:azure-svc-mgmt...jar:0.9.0.

It seems that the issue is caused by the maven repository for downloading the dependencies of the version 0.9.1 of Microsoft Azure SDK for Management.

I suggest you can use the version 0.9.0 for the present.

If you have to use the version 0.9.1, you can add the complete maven list for the libraries and their dependencies manually in the pom.xml file, or you can download & add all library files into the project classpath manually.

Peter Pan
  • 23,476
  • 4
  • 25
  • 43
  • Hi Peter. thanks for getting back to me. Yes I stuck with version 0.9.0 for now. I waas looking at the api docs (http://azure.github.io/azure-sdk-for-java/) and it did not say anywhere if classes were deprecated so I was wondering the same about the maven repo. Also - do you know is there a page to show the latest api docs? e.g. a http://azure.github.io/azure-sdk-for-java/latest type url? – Damien Jan 11 '16 at 08:44
  • 1
    @Damo The page `azure.github.io/azure-sdk-for-java` as a static web page generated by jekyll and hosted on Github that only show the latest api docs if the related project release a new version and generate the new javadocs. There is not a path `latest` for the page. – Peter Pan Jan 11 '16 at 09:43
  • ok fair enough.I have concerns here when looking at duplicate classes like this http://azure.github.io/azure-sdk-for-java/com/microsoft/azure/management/compute/VirtualMachineOperationsImpl.html and http://azure.github.io/azure-sdk-for-java/com/microsoft/windowsazure/management/compute/VirtualMachineOperationsImpl.html. Should we be using classes in the package structure com.microsoft.azure. or com.microsoft.windowsazure.? com.microsoft.azure. seems more current to me – Damien Jan 12 '16 at 11:19
  • 1
    @Damo The classes in the package `azure` are different from the classes in the package `windowsazure`. They respectively corresponding to different services `Resource Management` & `Service Management` that need different authenticating request. You can refer to https://msdn.microsoft.com/en-us/library/azure/dn790557.aspx and https://msdn.microsoft.com/en-us/library/azure/ee460782.aspx to know the difference for authenticating. – Peter Pan Jan 13 '16 at 11:52
1

go to http://go.microsoft.com/fwlink/?linkid=690320&clcid=0x409, download the file 'PackageForAzureLibrariesForJava.zip' and put these jar files to your project build path or add dependency in pom file if you are using maven. I have tested this in my local. It works.

Alex Chen-WX
  • 521
  • 2
  • 5