1
votes

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

2

2 Answers

1
votes

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.

1
votes

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.