Skip to content

Commit a0a0390

Browse files
committed
Merge pull request Azure#905 from huangpf/r098
AzureRT S54 PR #2 - Record Debug Messages & Fix Add-AzureVhd
2 parents 05acbb4 + d4d5923 commit a0a0390

File tree

8 files changed

+960
-956
lines changed

8 files changed

+960
-956
lines changed

src/Common/AzurePSCmdlet.cs

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
using Newtonsoft.Json;
2525
using System.IO;
2626
using System.Management.Automation.Host;
27+
using System.Text;
2728
using System.Threading;
2829

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

4041
private DebugStreamTraceListener _adalListener;
4142
protected static AzurePSDataCollectionProfile _dataCollectionProfile = null;
43+
protected static string _errorRecordFolderPath = null;
44+
protected const string _fileTimeStampSuffixFormat = "yyyy-MM-dd-THH-mm-ss-fff";
4245

4346
protected AzurePSQoSEvent QosEvent;
4447

@@ -254,7 +257,7 @@ protected bool IsVerbose()
254257

255258
protected new void WriteError(ErrorRecord errorRecord)
256259
{
257-
FlushDebugMessages();
260+
FlushDebugMessages(IsDataCollectionAllowed());
258261
if (QosEvent != null && errorRecord != null)
259262
{
260263
QosEvent.Exception = errorRecord.Exception;
@@ -362,8 +365,13 @@ protected void SafeWriteOutputPSObject(string typeName, params object[] args)
362365
WriteObject(customObject);
363366
}
364367

365-
private void FlushDebugMessages()
368+
private void FlushDebugMessages(bool record = false)
366369
{
370+
if (record)
371+
{
372+
RecordDebugMessages();
373+
}
374+
367375
string message;
368376
while (_debugMessages.TryDequeue(out message))
369377
{
@@ -373,6 +381,43 @@ private void FlushDebugMessages()
373381

374382
protected abstract void InitializeQosEvent();
375383

384+
private void RecordDebugMessages()
385+
{
386+
// Create 'ErrorRecords' folder under profile directory, if not exists
387+
if (string.IsNullOrEmpty(_errorRecordFolderPath) || !Directory.Exists(_errorRecordFolderPath))
388+
{
389+
_errorRecordFolderPath = Path.Combine(AzureSession.ProfileDirectory, "ErrorRecords");
390+
Directory.CreateDirectory(_errorRecordFolderPath);
391+
}
392+
393+
CommandInfo cmd = this.MyInvocation.MyCommand;
394+
395+
string filePrefix = cmd.Name;
396+
string timeSampSuffix = DateTime.Now.ToString(_fileTimeStampSuffixFormat);
397+
string fileName = filePrefix + "_" + timeSampSuffix + ".log";
398+
string filePath = Path.Combine(_errorRecordFolderPath, fileName);
399+
400+
StringBuilder sb = new StringBuilder();
401+
sb.Append("Module : ").AppendLine(cmd.ModuleName);
402+
sb.Append("Cmdlet : ").AppendLine(cmd.Name);
403+
404+
sb.AppendLine("Parameters");
405+
foreach (var item in this.MyInvocation.BoundParameters)
406+
{
407+
sb.Append(" -").Append(item.Key).Append(" : ");
408+
sb.AppendLine(item.Value == null ? "null" : item.Value.ToString());
409+
}
410+
411+
sb.AppendLine();
412+
413+
foreach (var content in _debugMessages)
414+
{
415+
sb.AppendLine(content);
416+
}
417+
418+
AzureSession.DataStore.WriteFile(filePath, sb.ToString());
419+
}
420+
376421
/// <summary>
377422
/// Invoke this method when the cmdlet is completed or terminated.
378423
/// </summary>

src/Common/Commands.ScenarioTest/Commands.ScenarioTest.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,12 @@
203203
<None Include="Resources\CredentialTests\Common.ps1">
204204
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
205205
</None>
206+
<None Include="Resources\ServiceManagement\Files\LongRoleName.Cloud.cscfg">
207+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
208+
</None>
209+
<None Include="Resources\ServiceManagement\Files\LongRoleName.Cloud.cspkg">
210+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
211+
</None>
206212
<None Include="Resources\ServiceManagement\Files\OneWebOneWorker.cscfg">
207213
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
208214
</None>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
**********************************************************************************************
4+
5+
This file was generated by a tool from the project file: ServiceConfiguration.Cloud.cscfg
6+
7+
Changes to this file may cause incorrect behavior and will be lost if the file is regenerated.
8+
9+
**********************************************************************************************
10+
-->
11+
<ServiceConfiguration serviceName="AzureCloudService2" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration" osFamily="4" osVersion="*" schemaVersion="2015-04.2.6">
12+
<Role name="WebRole1">
13+
<Instances count="1" />
14+
<ConfigurationSettings>
15+
<Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" value="UseDevelopmentStorage=true" />
16+
</ConfigurationSettings>
17+
</Role>
18+
<Role name="Microsoft.Contoso.Department.ProjectCodeName.Worker">
19+
<Instances count="1" />
20+
<ConfigurationSettings>
21+
<Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" value="UseDevelopmentStorage=true" />
22+
</ConfigurationSettings>
23+
</Role>
24+
</ServiceConfiguration>

src/Common/Commands.ScenarioTest/Resources/ServiceManagement/ServiceManagementTests.ps1

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -556,18 +556,20 @@ function Run-ServiceDeploymentExtensionCmdletTests
556556
$testMode = Get-ComputeTestMode;
557557
if ($testMode.ToLower() -ne 'playback')
558558
{
559-
$cspkg = '.\Resources\ServiceManagement\Files\OneWebOneWorker.cspkg';
559+
$cspkg = '.\Resources\ServiceManagement\Files\LongRoleName.Cloud.cspkg';
560560
}
561561
else
562562
{
563-
$cspkg = "https://${storageName}.blob.azure.windows.net/blob/OneWebOneWorker.cspkg";
563+
$cspkg = "https://${storageName}.blob.azure.windows.net/blob/LongRoleName.Cloud.cspkg";
564564
}
565-
$cscfg = '.\Resources\ServiceManagement\Files\OneWebOneWorker.cscfg';
566-
567-
$rdpCfg1 = New-AzureServiceRemoteDesktopExtensionConfig -Credential $credential -Role WebRole1
568-
$rdpCfg2 = New-AzureServiceRemoteDesktopExtensionConfig -Credential $credential -Role WorkerRole1;
569-
$adCfg1 = New-AzureServiceADDomainExtensionConfig -Role WebRole1 -WorkgroupName 'test1';
570-
$adCfg2 = New-AzureServiceADDomainExtensionConfig -Role WorkerRole1 -WorkgroupName 'test2';
565+
$cscfg = '.\Resources\ServiceManagement\Files\LongRoleName.Cloud.cscfg';
566+
567+
$webRoleShortName = "WebRole1";
568+
$workerRoleLongName = "Microsoft.Contoso.Department.ProjectCodeName.Worker";
569+
$rdpCfg1 = New-AzureServiceRemoteDesktopExtensionConfig -Credential $credential -Role $webRoleShortName
570+
$rdpCfg2 = New-AzureServiceRemoteDesktopExtensionConfig -Credential $credential -Role $workerRoleLongName;
571+
$adCfg1 = New-AzureServiceADDomainExtensionConfig -Role $webRoleShortName -WorkgroupName 'test1';
572+
$adCfg2 = New-AzureServiceADDomainExtensionConfig -Role $workerRoleLongName -WorkgroupName 'test2';
571573

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

src/Common/Commands.ScenarioTest/SessionRecords/Microsoft.WindowsAzure.Commands.ScenarioTest.ServiceManagementTests/RunServiceDeploymentExtensionCmdletTests.json

Lines changed: 854 additions & 942 deletions
Large diffs are not rendered by default.

src/ServiceManagement/Compute/Commands.ServiceManagement/Extensions/Common/ExtensionRole.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,16 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15+
using System;
16+
using System.Text;
17+
1518
namespace Microsoft.WindowsAzure.Commands.ServiceManagement.Extensions
1619
{
1720
public class ExtensionRole
1821
{
1922
protected const string DefaultExtensionIdPrefixStr = "Default";
20-
protected const string ExtensionIdTemplate = "{0}-{1}-{2}-Ext-{3}";
23+
protected const string ExtensionIdSuffixTemplate = "-{0}-{1}-Ext-{2}";
24+
protected const int MaxExtensionIdLength = 60;
2125

2226
public string RoleName { get; private set; }
2327
public string PrefixName { get; private set; }
@@ -57,7 +61,18 @@ public override string ToString()
5761

5862
public string GetExtensionId(string extensionName, string slot, int index)
5963
{
60-
return string.Format(ExtensionIdTemplate, PrefixName, extensionName, slot, index);
64+
var normalizedExtName = extensionName.Replace(".", string.Empty);
65+
66+
var suffix = new StringBuilder();
67+
suffix.AppendFormat(ExtensionIdSuffixTemplate, normalizedExtName, slot, index);
68+
69+
int prefixSubStrLen = Math.Min(Math.Max(MaxExtensionIdLength - suffix.Length, 0), PrefixName.Length);
70+
71+
var result = new StringBuilder();
72+
result.Append(PrefixName, 0, prefixSubStrLen);
73+
result.Append(suffix);
74+
75+
return result.ToString();
6176
}
6277
}
6378
}

src/ServiceManagement/Compute/Sync/Upload/BlobSynchronizer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ public bool Synchronize()
7070
if (loopResult.Exceptions.Any())
7171
{
7272
Program.SyncOutput.ErrorUploadFailedWithExceptions(loopResult.Exceptions);
73-
//TODO: throw an AggregateException
74-
return false;
73+
74+
throw new AggregateException(loopResult.Exceptions);
7575
}
7676
}
7777
else

0 commit comments

Comments
 (0)