Skip to content

. #88

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

Merged
merged 19 commits into from
Sep 15, 2015
Merged

. #88

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());
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)
{
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 @@ -111,6 +111,9 @@
<Compile Include="Entities\Locks\LockLevel.cs" />
<Compile Include="Entities\Locks\LockProperties.cs" />
<Compile Include="Entities\Operations\AzureAsyncOperationResource.cs" />
<Compile Include="Entities\Policy\PolicyDefinition.cs" />
<Compile Include="Entities\Policy\PolicyDefinitionProperties.cs" />
<Compile Include="Entities\Policy\PolicyRule.cs" />
<Compile Include="Entities\Providers\ResourceProviderDefinition.cs" />
<Compile Include="Entities\Providers\ResourceTypeDefinition.cs" />
<Compile Include="Entities\ResourceGroup\ResourceBatchMoveParameters.cs" />
Expand All @@ -136,6 +139,11 @@
<Compile Include="Implementation\InvokeAzureResourceActionCmdlet.cs" />
<Compile Include="Implementation\MoveAzureResourceCmdlet.cs" />
<Compile Include="Implementation\NewAzureResourceLockCmdlet.cs" />
<Compile Include="Implementation\Policy\GetAzurePolicyDefinition.cs" />
<Compile Include="Implementation\Policy\NewAzurePolicyDefinition.cs" />
<Compile Include="Implementation\Policy\PolicyDefinitionCmdletBase.cs" />
<Compile Include="Implementation\Policy\RemoveAzurePolicyDefinition.cs" />
<Compile Include="Implementation\Policy\SetAzurePolicyDefinition.cs" />
<Compile Include="Implementation\RemoveAzureResourceCmdlet.cs" />
<Compile Include="Implementation\RemoveAzureResourceLockCmdlet.cs" />
<Compile Include="Implementation\ResourceLockManagementCmdletBase.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ public static class Constants
/// </summary>
public static readonly string MicrosoftResourceNamesapce = "Microsoft.Resources";

/// <summary>
/// The <c>Microsoft.Authorization</c> namespace.
/// </summary>
public static readonly string MicrosoftAuthorizationNamespace = "Microsoft.Authorization";

/// <summary>
/// The string literal <c>ResourceGroups</c>
/// </summary>
Expand Down Expand Up @@ -64,6 +69,11 @@ public static class Constants
/// </summary>
public static readonly string MicrosoftResourcesDeploymentOperationsType = Constants.MicrosoftResourceNamesapce + "/deployments/operations";

/// <summary>
/// The policy definition resource type.
/// </summary>
public static readonly string MicrosoftAuthorizationPolicyDefinitionType = Constants.MicrosoftAuthorizationNamespace + "/policydefinitions";

/// <summary>
/// The type name of the generic resource.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// ----------------------------------------------------------------------------------
//
// 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.
// ----------------------------------------------------------------------------------

namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Entities.Policy
{
using Newtonsoft.Json;

/// <summary>
/// The policy definition object.
/// </summary>
public class PolicyDefinition
{
/// <summary>
/// The policy definition properties.
/// </summary>
[JsonProperty(Required = Required.Default)]
public PolicyDefinitionProperties Properties { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// ----------------------------------------------------------------------------------
//
// 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.
// ----------------------------------------------------------------------------------

namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Entities.Policy
{
using Newtonsoft.Json;

/// <summary>
/// The policy definition properties.
/// </summary>
public class PolicyDefinitionProperties
{
/// <summary>
/// The description.
/// </summary>
[JsonProperty(Required = Required.Default)]
public string Description { get; set; }

/// <summary>
/// The display name.
/// </summary>
[JsonProperty(Required = Required.Default)]
public string DisplayName { get; set; }

/// <summary>
/// The policy rule.
/// </summary>
[JsonProperty(Required = Required.Always)]
public PolicyRule PolicyRule { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// ----------------------------------------------------------------------------------
//
// 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.
// ----------------------------------------------------------------------------------

namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Entities.Policy
{
using Newtonsoft.Json;

/// <summary>
/// The policy rule object.
/// </summary>
public class PolicyRule
{
/// <summary>
/// The policy rule
/// </summary>
[JsonProperty(Required = Required.Always)]
public string Rule { get; set; }
}
}
Loading