0

Web ロールと Worker ロールを持つ Windows Azure クラウド サービスを使用しています。クラウド サービスに対してさまざまな管理機能 (停止/開始、インスタンスの再起動、インスタンスの追加、インスタンスの削除) を実行できる Web サイトを構築しました。すべての機能は Web API 経由で実行されます。私の問題は、Web ロールのインスタンスを追加すると、worker ロールが再起動することです。Azure portal 経由でインスタンスを追加した場合、これは発生しないことに注意してください。コードは他のすべての面で正しく機能します。すべてのロールのリサイクルではなく、影響を受けるロールのみがリサイクルされるようにする方法はありますか?

私のコード:

    public void AddInstance()
    {
        XDocument configDoc = this.GetDeploymentConfiguration();
        var ns = configDoc.Root.GetDefaultNamespace();

        configDoc.Root
            .Elements( ns + "Role" )
            .FirstOrDefault( r => r.Attribute( "name" ).Value.ToLower() == this.RoleName.ToLower() )
            .Element( ns + "Instances" )
            .Attribute( "count" )
            .Value = ( int.Parse( configDoc.Root
                           .Elements( ns + "Role" )
                           .FirstOrDefault( r => r.Attribute( "name" ).Value.ToLower() == this.RoleName.ToLower() )
                           .Element( ns + "Instances" )
                           .Attribute( "count" )
                           .Value ) + 1 ).ToString();

        string encodedString = Convert.ToBase64String( Encoding.UTF8.GetBytes( configDoc.ToString() ) );
        this.SetDeploymentConfig( encodedString );
    }

    public XDocument GetDeploymentConfiguration()
    {
        string uri = string.Format( this.servicePropertiesOperationFormat, this.subscriptionID, this.serviceName, "production", "" );
        ServiceManagementOperation operation = new ServiceManagementOperation( this.thumbprint, this.versionID );

        var xdoc= operation.Invoke( uri );
        var myelm = xdoc.Element( wa + "Deployment" ).Element( wa + "Configuration" );

        var mystring=  Encoding.UTF8.GetString( Convert.FromBase64String( myelm.Value ) );

        return XDocument.Parse( mystring );
    }

    public string SetDeploymentConfig( string configurationFile )
    {
        string uri = string.Format( this.servicePropertiesOperationFormat, this.subscriptionID, this.serviceName, "production", "/?comp=config" );
        ServiceManagementOperation operation = new ServiceManagementOperation( this.thumbprint, this.versionID );
        string payloadString = string.Format(
            @"<?xml version=""1.0"" encoding=""utf-8""?>
            <ChangeConfiguration xmlns=""http://schemas.microsoft.com/windowsazure"">
                    <Configuration>{0}</Configuration>
            </ChangeConfiguration>", configurationFile );

        XDocument payload = XDocument.Parse( payloadString );
        return operation.Invoke( uri, payload );
    }
4

1 に答える 1