Skip to content
Merged
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
49 changes: 47 additions & 2 deletions src/Common/AzurePSCmdlet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
using Newtonsoft.Json;
using System.IO;
using System.Management.Automation.Host;
using System.Text;
using System.Threading;

namespace Microsoft.WindowsAzure.Commands.Utilities.Common
Expand All @@ -39,6 +40,8 @@ public abstract class AzurePSCmdlet : PSCmdlet, IDisposable

private DebugStreamTraceListener _adalListener;
protected static AzurePSDataCollectionProfile _dataCollectionProfile = null;
protected static string _errorRecordFolderPath = null;
protected const string _fileTimeStampSuffixFormat = "yyyy-MM-dd-THH-mm-ss-fff";

protected AzurePSQoSEvent QosEvent;

Expand Down Expand Up @@ -254,7 +257,7 @@ protected bool IsVerbose()

protected new void WriteError(ErrorRecord errorRecord)
{
FlushDebugMessages();
FlushDebugMessages(IsDataCollectionAllowed());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to pass IsDataCollectionAllowed() just use it in FlushDebugMessages

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But we only want to log when there is an exception. Do you mean you want to log everything if data collection is allowed?

if (QosEvent != null && errorRecord != null)
{
QosEvent.Exception = errorRecord.Exception;
Expand Down Expand Up @@ -362,8 +365,13 @@ protected void SafeWriteOutputPSObject(string typeName, params object[] args)
WriteObject(customObject);
}

private void FlushDebugMessages()
private void FlushDebugMessages(bool record = false)
{
if (record)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (IsDataCollectionAllowed())
{
    RecordDebugMessages();
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same above

{
RecordDebugMessages();
}

string message;
while (_debugMessages.TryDequeue(out message))
{
Expand All @@ -373,6 +381,43 @@ private void FlushDebugMessages()

protected abstract void InitializeQosEvent();

private void RecordDebugMessages()
{
// Create 'ErrorRecords' folder under profile directory, if not exists
if (string.IsNullOrEmpty(_errorRecordFolderPath) || !Directory.Exists(_errorRecordFolderPath))
{
_errorRecordFolderPath = Path.Combine(AzureSession.ProfileDirectory, "ErrorRecords");
Directory.CreateDirectory(_errorRecordFolderPath);
}

CommandInfo cmd = this.MyInvocation.MyCommand;

string filePrefix = cmd.Name;
string timeSampSuffix = DateTime.Now.ToString(_fileTimeStampSuffixFormat);
string fileName = filePrefix + "_" + timeSampSuffix + ".log";
string filePath = Path.Combine(_errorRecordFolderPath, fileName);

StringBuilder sb = new StringBuilder();
sb.Append("Module : ").AppendLine(cmd.ModuleName);
sb.Append("Cmdlet : ").AppendLine(cmd.Name);

sb.AppendLine("Parameters");
foreach (var item in this.MyInvocation.BoundParameters)
{
sb.Append(" -").Append(item.Key).Append(" : ");
sb.AppendLine(item.Value == null ? "null" : item.Value.ToString());
}

sb.AppendLine();

foreach (var content in _debugMessages)
{
sb.AppendLine(content);
}

AzureSession.DataStore.WriteFile(filePath, sb.ToString());
}

/// <summary>
/// Invoke this method when the cmdlet is completed or terminated.
/// </summary>
Expand Down
6 changes: 6 additions & 0 deletions src/Common/Commands.ScenarioTest/Commands.ScenarioTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,12 @@
<None Include="Resources\CredentialTests\Common.ps1">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Resources\ServiceManagement\Files\LongRoleName.Cloud.cscfg">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Resources\ServiceManagement\Files\LongRoleName.Cloud.cspkg">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Resources\ServiceManagement\Files\OneWebOneWorker.cscfg">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
**********************************************************************************************

This file was generated by a tool from the project file: ServiceConfiguration.Cloud.cscfg

Changes to this file may cause incorrect behavior and will be lost if the file is regenerated.

**********************************************************************************************
-->
<ServiceConfiguration serviceName="AzureCloudService2" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration" osFamily="4" osVersion="*" schemaVersion="2015-04.2.6">
<Role name="WebRole1">
<Instances count="1" />
<ConfigurationSettings>
<Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" value="UseDevelopmentStorage=true" />
</ConfigurationSettings>
</Role>
<Role name="Microsoft.Contoso.Department.ProjectCodeName.Worker">
<Instances count="1" />
<ConfigurationSettings>
<Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" value="UseDevelopmentStorage=true" />
</ConfigurationSettings>
</Role>
</ServiceConfiguration>
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -556,18 +556,20 @@ function Run-ServiceDeploymentExtensionCmdletTests
$testMode = Get-ComputeTestMode;
if ($testMode.ToLower() -ne 'playback')
{
$cspkg = '.\Resources\ServiceManagement\Files\OneWebOneWorker.cspkg';
$cspkg = '.\Resources\ServiceManagement\Files\LongRoleName.Cloud.cspkg';
}
else
{
$cspkg = "https://${storageName}.blob.azure.windows.net/blob/OneWebOneWorker.cspkg";
$cspkg = "https://${storageName}.blob.azure.windows.net/blob/LongRoleName.Cloud.cspkg";
}
$cscfg = '.\Resources\ServiceManagement\Files\OneWebOneWorker.cscfg';

$rdpCfg1 = New-AzureServiceRemoteDesktopExtensionConfig -Credential $credential -Role WebRole1
$rdpCfg2 = New-AzureServiceRemoteDesktopExtensionConfig -Credential $credential -Role WorkerRole1;
$adCfg1 = New-AzureServiceADDomainExtensionConfig -Role WebRole1 -WorkgroupName 'test1';
$adCfg2 = New-AzureServiceADDomainExtensionConfig -Role WorkerRole1 -WorkgroupName 'test2';
$cscfg = '.\Resources\ServiceManagement\Files\LongRoleName.Cloud.cscfg';

$webRoleShortName = "WebRole1";
$workerRoleLongName = "Microsoft.Contoso.Department.ProjectCodeName.Worker";
$rdpCfg1 = New-AzureServiceRemoteDesktopExtensionConfig -Credential $credential -Role $webRoleShortName
$rdpCfg2 = New-AzureServiceRemoteDesktopExtensionConfig -Credential $credential -Role $workerRoleLongName;
$adCfg1 = New-AzureServiceADDomainExtensionConfig -Role $webRoleShortName -WorkgroupName 'test1';
$adCfg2 = New-AzureServiceADDomainExtensionConfig -Role $workerRoleLongName -WorkgroupName 'test2';

$st = New-AzureDeployment -ServiceName $svcName -Package $cspkg -Configuration $cscfg -Label $svcName -Slot Production -ExtensionConfiguration $rdpCfg1,$adCfg1;
$exts = Get-AzureServiceExtension -ServiceName $svcName -Slot Production;
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using System;
using System.Text;

namespace Microsoft.WindowsAzure.Commands.ServiceManagement.Extensions
{
public class ExtensionRole
{
protected const string DefaultExtensionIdPrefixStr = "Default";
protected const string ExtensionIdTemplate = "{0}-{1}-{2}-Ext-{3}";
protected const string ExtensionIdSuffixTemplate = "-{0}-{1}-Ext-{2}";
protected const int MaxExtensionIdLength = 60;

public string RoleName { get; private set; }
public string PrefixName { get; private set; }
Expand Down Expand Up @@ -57,7 +61,18 @@ public override string ToString()

public string GetExtensionId(string extensionName, string slot, int index)
{
return string.Format(ExtensionIdTemplate, PrefixName, extensionName, slot, index);
var normalizedExtName = extensionName.Replace(".", string.Empty);

var suffix = new StringBuilder();
suffix.AppendFormat(ExtensionIdSuffixTemplate, normalizedExtName, slot, index);

int prefixSubStrLen = Math.Min(Math.Max(MaxExtensionIdLength - suffix.Length, 0), PrefixName.Length);

var result = new StringBuilder();
result.Append(PrefixName, 0, prefixSubStrLen);
result.Append(suffix);

return result.ToString();
}
}
}
4 changes: 2 additions & 2 deletions src/ServiceManagement/Compute/Sync/Upload/BlobSynchronizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ public bool Synchronize()
if (loopResult.Exceptions.Any())
{
Program.SyncOutput.ErrorUploadFailedWithExceptions(loopResult.Exceptions);
//TODO: throw an AggregateException
return false;

throw new AggregateException(loopResult.Exceptions);
}
}
else
Expand Down