1

Java SDK を使用して、サーバーの起動やサーバーのシャットダウンなどの Azure タスクを自動化しようとしています。MavenのJava SDKのバージョン0.9.0を使用していました

           <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>

このコードは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;
    }

}

SDK の最新バージョン 0.9.1 にアップグレードすると、次のクラスが存在しなくなります

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;

これらのクラスがどこに行ったのかをオンラインで見つけることができませんでした-それらが非推奨になっているか、別のライブラリに追加されているかどうか

誰かが私が代わりにどのクラスにすべきか、またはどのライブラリに移動した可能性があるかを知っているなら、それは素晴らしいことです。

ありがとうダミアン

4

2 に答える 2

1

http://go.microsoft.com/fwlink/?linkid=690320&clcid=0x409にアクセスし、'PackageForAzureLibrariesForJava.zip' ファイルをダウンロードして、これらの jar ファイルをプロジェクトのビルド パスに配置するか、maven を使用している場合は pom ファイルに依存関係を追加します。 . 私は自分のローカルでこれをテストしました。できます。

于 2016-01-13T06:09:33.837 に答える