-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix the problem in automation that stream is still used after being c…
…losed (#33907)
- Loading branch information
Showing
5 changed files
with
163 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
sdk/automation/Azure.ResourceManager.Automation/src/Customized/AutomationRunbookResource.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
#nullable disable | ||
|
||
using System; | ||
using System.IO; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Azure.Core; | ||
|
||
namespace Azure.ResourceManager.Automation | ||
{ | ||
/// <summary> | ||
/// A Class representing an AutomationRunbook along with the instance operations that can be performed on it. | ||
/// If you have a <see cref="ResourceIdentifier" /> you can construct an <see cref="AutomationRunbookResource" /> | ||
/// from an instance of <see cref="ArmClient" /> using the GetAutomationRunbookResource method. | ||
/// Otherwise you can get one from its parent resource <see cref="AutomationAccountResource" /> using the GetAutomationRunbook method. | ||
/// </summary> | ||
public partial class AutomationRunbookResource | ||
{ | ||
/// <summary> | ||
/// Replaces the runbook draft content. | ||
/// <list type="bullet"> | ||
/// <item> | ||
/// <term>Request Path</term> | ||
/// <description>/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/runbooks/{runbookName}/draft/content</description> | ||
/// </item> | ||
/// <item> | ||
/// <term>Operation Id</term> | ||
/// <description>RunbookDraft_ReplaceContent</description> | ||
/// </item> | ||
/// </list> | ||
/// </summary> | ||
/// <param name="waitUntil"> <see cref="WaitUntil.Completed"/> if the method should wait to return until the long-running operation has completed on the service; <see cref="WaitUntil.Started"/> if it should return after starting the operation. For more information on long-running operations, please see <see href="https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/core/Azure.Core/samples/LongRunningOperations.md"> Azure.Core Long-Running Operation samples</see>. </param> | ||
/// <param name="runbookContent"> The runbook draft content. </param> | ||
/// <param name="cancellationToken"> The cancellation token to use. </param> | ||
/// <exception cref="ArgumentNullException"> <paramref name="runbookContent"/> is null. </exception> | ||
public virtual async Task<ArmOperation> ReplaceContentRunbookDraftAsync(WaitUntil waitUntil, Stream runbookContent, CancellationToken cancellationToken = default) | ||
{ | ||
Argument.AssertNotNull(runbookContent, nameof(runbookContent)); | ||
|
||
using var scope = _runbookDraftClientDiagnostics.CreateScope("AutomationRunbookResource.ReplaceContentRunbookDraft"); | ||
scope.Start(); | ||
try | ||
{ | ||
var response = await _runbookDraftRestClient.ReplaceContentAsync(Id.SubscriptionId, Id.ResourceGroupName, Id.Parent.Name, Id.Name, runbookContent, cancellationToken).ConfigureAwait(false); | ||
var operation = new AutomationArmOperation(_runbookDraftClientDiagnostics, Pipeline, _runbookDraftRestClient.CreateReplaceContentRequest(Id.SubscriptionId, Id.ResourceGroupName, Id.Parent.Name, Id.Name, runbookContent, true).Request, response, OperationFinalStateVia.Location); | ||
if (waitUntil == WaitUntil.Completed) | ||
await operation.WaitForCompletionResponseAsync(cancellationToken).ConfigureAwait(false); | ||
return operation; | ||
} | ||
catch (Exception e) | ||
{ | ||
scope.Failed(e); | ||
throw; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Replaces the runbook draft content. | ||
/// <list type="bullet"> | ||
/// <item> | ||
/// <term>Request Path</term> | ||
/// <description>/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/runbooks/{runbookName}/draft/content</description> | ||
/// </item> | ||
/// <item> | ||
/// <term>Operation Id</term> | ||
/// <description>RunbookDraft_ReplaceContent</description> | ||
/// </item> | ||
/// </list> | ||
/// </summary> | ||
/// <param name="waitUntil"> <see cref="WaitUntil.Completed"/> if the method should wait to return until the long-running operation has completed on the service; <see cref="WaitUntil.Started"/> if it should return after starting the operation. For more information on long-running operations, please see <see href="https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/core/Azure.Core/samples/LongRunningOperations.md"> Azure.Core Long-Running Operation samples</see>. </param> | ||
/// <param name="runbookContent"> The runbook draft content. </param> | ||
/// <param name="cancellationToken"> The cancellation token to use. </param> | ||
/// <exception cref="ArgumentNullException"> <paramref name="runbookContent"/> is null. </exception> | ||
public virtual ArmOperation ReplaceContentRunbookDraft(WaitUntil waitUntil, Stream runbookContent, CancellationToken cancellationToken = default) | ||
{ | ||
Argument.AssertNotNull(runbookContent, nameof(runbookContent)); | ||
|
||
using var scope = _runbookDraftClientDiagnostics.CreateScope("AutomationRunbookResource.ReplaceContentRunbookDraft"); | ||
scope.Start(); | ||
try | ||
{ | ||
var response = _runbookDraftRestClient.ReplaceContent(Id.SubscriptionId, Id.ResourceGroupName, Id.Parent.Name, Id.Name, runbookContent, cancellationToken); | ||
var operation = new AutomationArmOperation(_runbookDraftClientDiagnostics, Pipeline, _runbookDraftRestClient.CreateReplaceContentRequest(Id.SubscriptionId, Id.ResourceGroupName, Id.Parent.Name, Id.Name, runbookContent, true).Request, response, OperationFinalStateVia.Location); | ||
if (waitUntil == WaitUntil.Completed) | ||
operation.WaitForCompletionResponse(cancellationToken); | ||
return operation; | ||
} | ||
catch (Exception e) | ||
{ | ||
scope.Failed(e); | ||
throw; | ||
} | ||
} | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...re.ResourceManager.Automation/src/Customized/RestOperations/RunbookDraftRestOperations.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
#nullable disable | ||
|
||
using System.IO; | ||
using Azure.Core; | ||
|
||
namespace Azure.ResourceManager.Automation | ||
{ | ||
[CodeGenSuppress("CreateReplaceContentRequest", typeof(string), typeof(string), typeof(string), typeof(string), typeof(Stream))] | ||
internal partial class RunbookDraftRestOperations | ||
{ | ||
internal HttpMessage CreateReplaceContentRequest(string subscriptionId, string resourceGroupName, string automationAccountName, string runbookName, Stream runbookContent, bool isContentSkipped = false) | ||
{ | ||
var message = _pipeline.CreateMessage(); | ||
var request = message.Request; | ||
request.Method = RequestMethod.Put; | ||
var uri = new RawRequestUriBuilder(); | ||
uri.Reset(_endpoint); | ||
uri.AppendPath("/subscriptions/", false); | ||
uri.AppendPath(subscriptionId, true); | ||
uri.AppendPath("/resourceGroups/", false); | ||
uri.AppendPath(resourceGroupName, true); | ||
uri.AppendPath("/providers/Microsoft.Automation/automationAccounts/", false); | ||
uri.AppendPath(automationAccountName, true); | ||
uri.AppendPath("/runbooks/", false); | ||
uri.AppendPath(runbookName, true); | ||
uri.AppendPath("/draft/content", false); | ||
uri.AppendQuery("api-version", _apiVersion, true); | ||
request.Uri = uri; | ||
request.Headers.Add("Accept", "application/json"); | ||
request.Headers.Add("Content-Type", "text/powershell"); | ||
if (!isContentSkipped) | ||
{ | ||
request.Content = RequestContent.Create(runbookContent); | ||
} | ||
_userAgent.Apply(message); | ||
return message; | ||
} | ||
} | ||
} |
76 changes: 0 additions & 76 deletions
76
sdk/automation/Azure.ResourceManager.Automation/src/Generated/AutomationRunbookResource.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
25 changes: 0 additions & 25 deletions
25
...ure.ResourceManager.Automation/src/Generated/RestOperations/RunbookDraftRestOperations.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.