Skip to content

[do not merge] Try output op ID in LRO #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@
</Reference>
<Reference Include="System.Net.Http.WebRequest" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
Expand All @@ -149,6 +150,7 @@
<Compile Include="Common\ComputeAutoMapperProfile.cs" />
<Compile Include="Common\ComputeClientBaseCmdlet.cs" />
<Compile Include="Common\ComputeClient.cs" />
<Compile Include="Common\ComputeTracingInterceptor.cs" />
<Compile Include="ExtensionImages\GetAzureVMExtensionImageTypeCommand.cs" />
<Compile Include="ExtensionImages\GetAzureVMExtensionImageCommand.cs" />
<Compile Include="ExtensionImages\GetAzureVMExtensionImageDetailCommand.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,26 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using Microsoft.Azure.Commands.Compute.Common;
using Microsoft.WindowsAzure.Commands.Utilities.Common;
using System.Collections.Concurrent;

namespace Microsoft.Azure.Commands.Compute
{
public abstract class ComputeClientBaseCmdlet : AzurePSCmdlet
{
protected const string VirtualMachineExtensionType = "Microsoft.Compute/virtualMachines/extensions";

private readonly ConcurrentQueue<string> _computeMessages = new ConcurrentQueue<string>();

private ComputeClient computeClient;
private ComputeTracingInterceptor _computeTracingInterceptor;

protected string cmdletName = null;

public ComputeClientBaseCmdlet()
{
}

public ComputeClient ComputeClient
{
Expand All @@ -40,10 +51,24 @@ public ComputeClient ComputeClient

set { computeClient = value; }
}

protected override void BeginProcessing()
{
_computeTracingInterceptor = _computeTracingInterceptor ?? new ComputeTracingInterceptor(this, _computeMessages);
ComputeTracingInterceptor.AddToContext(_computeTracingInterceptor);
base.BeginProcessing();
}

public override void ExecuteCmdlet()
{
base.ExecuteCmdlet();
ComputeAutoMapperProfile.Initialize();
}

protected override void EndProcessing()
{
ComputeTracingInterceptor.RemoveFromContext(_computeTracingInterceptor);
base.EndProcessing();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using Hyak.Common;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;
using System.Net;
using System.Net.Http;
using System.Text;

namespace Microsoft.Azure.Commands.Compute.Common
{
public class ComputeTracingInterceptor : ICloudTracingInterceptor
{
private PSCmdlet _cmdlet;
private ConcurrentQueue<string> _messageQueue;

public ComputeTracingInterceptor(PSCmdlet cmdlet, ConcurrentQueue<string> queue)
{
_cmdlet = cmdlet;
_messageQueue = queue;
}

private void Write(HttpResponseMessage response)
{
const string xmlRequestHeaderStr = "x-ms-request-id";

StringBuilder sb = new StringBuilder();
sb.AppendFormat("Running Compute Cmdlet: '{0}'", _cmdlet.MyInvocation.MyCommand.Name).AppendLine();
sb.AppendFormat("Parameter Set Name: '{0}'", _cmdlet.ParameterSetName).AppendLine();
sb.AppendFormat("Method: '{0}'", response.RequestMessage.Method).AppendLine();
sb.AppendFormat("Request Uri: '{0}'", response.RequestMessage.RequestUri).AppendLine();
sb.AppendFormat("Status Code: '{0}'", response.StatusCode).AppendLine();
sb.AppendFormat("Asynchronous Operation Id: '{0}'", response.Headers.GetValues(xmlRequestHeaderStr).FirstOrDefault()).AppendLine();

string message = sb.ToString();
_messageQueue.Enqueue(message);
//_cmdlet.WriteVerbose(message);
}

private void Write(string message, params object[] arguments)
{
// Ignore
}

public void Information(string message)
{
// Ignore
}

public void Configuration(string source, string name, string value)
{
// Ignore
}

public void Enter(string invocationId, object instance, string method, IDictionary<string, object> parameters)
{
// Ignore
}

public void SendRequest(string invocationId, HttpRequestMessage request)
{
// Ignore
}

public void ReceiveResponse(string invocationId, HttpResponseMessage response)
{
if (response.StatusCode == HttpStatusCode.Accepted || response.StatusCode == HttpStatusCode.Created)
{
Write(response);
}
}

public void Error(string invocationId, Exception ex)
{
// Ignore
}

public void Exit(string invocationId, object result)
{
// Ignore
}

public static void AddToContext(ComputeTracingInterceptor interceptor)
{
RemoveFromContext(interceptor);
TracingAdapter.AddTracingInterceptor(interceptor);
}

public static void RemoveFromContext(ComputeTracingInterceptor interceptor)
{
try
{
TracingAdapter.RemoveTracingInterceptor(interceptor);
}
catch
{
// Ignore
}
}
}
}