Skip to content

HPF PR: dev <- Azure:dev #498

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 4 commits into from
Mar 24, 2016
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Management.Automation;
Expand All @@ -34,7 +35,6 @@ namespace Microsoft.Azure.Commands.Compute.Common
{
public static class DiagnosticsHelper
{
private static string XmlNamespace = "http://schemas.microsoft.com/ServiceHosting/2010/10/DiagnosticsConfiguration";
private static string EncodedXmlCfg = "xmlCfg";
private static string WadCfg = "WadCfg";
private static string WadCfgBlob = "WadCfgBlob";
Expand All @@ -46,6 +46,7 @@ public static class DiagnosticsHelper
private static string StorageAccountKeyTag = "storageAccountKey";
private static string StorageAccountEndPointTag = "storageAccountEndPoint";

public static string XmlNamespace = "http://schemas.microsoft.com/ServiceHosting/2010/10/DiagnosticsConfiguration";
public static string DiagnosticsConfigurationElemStr = "DiagnosticsConfiguration";
public static string DiagnosticMonitorConfigurationElemStr = "DiagnosticMonitorConfiguration";
public static string PublicConfigElemStr = "PublicConfig";
Expand All @@ -56,6 +57,10 @@ public static class DiagnosticsHelper
public static string PrivConfEndpointAttr = "endpoint";
public static string MetricsElemStr = "Metrics";
public static string MetricsResourceIdAttr = "resourceId";
public static string EventHubElemStr = "EventHub";
public static string EventHubUrlAttr = "Url";
public static string EventHubSharedAccessKeyNameAttr = "SharedAccessKeyName";
public static string EventHubSharedAccessKeyAttr = "SharedAccessKey";

public enum ConfigFileType
{
Expand Down Expand Up @@ -246,17 +251,36 @@ private static void AutoFillMetricsConfig(JObject wadCfgObject, string resourceI
}
}

public static Hashtable GetPrivateDiagnosticsConfiguration(string storageAccountName,
string storageKey, string endpoint)
public static Hashtable GetPrivateDiagnosticsConfiguration(string configurationPath,
string storageAccountName, string storageKey, string endpoint)
{
var privateConfig = new Hashtable();
privateConfig.Add(StorageAccountNameTag, storageAccountName);
privateConfig.Add(StorageAccountKeyTag, storageKey);
privateConfig.Add(StorageAccountEndPointTag, endpoint);

AddEventHubPrivateConfig(privateConfig, configurationPath);

return privateConfig;
}

private static void AddEventHubPrivateConfig(Hashtable privateConfig, string configurationPath)
{
var eventHubUrl = GetConfigValueFromPrivateConfig(configurationPath, EventHubElemStr, EventHubUrlAttr);
var eventHubSharedAccessKeyName = GetConfigValueFromPrivateConfig(configurationPath, EventHubElemStr, EventHubSharedAccessKeyNameAttr);
var eventHubSharedAccessKey = GetConfigValueFromPrivateConfig(configurationPath, EventHubElemStr, EventHubSharedAccessKeyAttr);

if (!string.IsNullOrEmpty(eventHubUrl) || !string.IsNullOrEmpty(eventHubSharedAccessKeyName) || !string.IsNullOrEmpty(eventHubSharedAccessKey))
{
var eventHubConfig = new Hashtable();
eventHubConfig.Add(EventHubUrlAttr, eventHubUrl);
eventHubConfig.Add(EventHubSharedAccessKeyNameAttr, eventHubSharedAccessKeyName);
eventHubConfig.Add(EventHubSharedAccessKeyAttr, eventHubSharedAccessKey);

privateConfig.Add(EventHubElemStr, eventHubConfig);
}
}

private static XElement GetPublicConfigXElementFromXmlFile(string configurationPath)
{
XElement publicConfig = null;
Expand Down Expand Up @@ -292,9 +316,34 @@ private static JObject GetPublicConfigJObjectFromJsonFile(string configurationPa
return publicConfig;
}

public static string GetStorageAccountInfoFromPrivateConfig(string configurationPath, string attributeName)
/// <summary>
/// Get the private config value for a specific attribute.
/// The private config looks like this:
/// XML:
/// <PrivateConfig xmlns="namespace">
/// <StorageAccount name = "name" key="key" endpoint="endpoint" />
/// <EventHub Url = "url" SharedAccessKeyName="sasKeyName" SharedAccessKey="sasKey"/>
/// </PrivateConfig>
///
/// JSON:
/// "PrivateConfig":{
/// "storageAccountName":"name",
/// "storageAccountKey":"key",
/// "storageAccountEndPoint":"endpoint",
/// "EventHub":{
/// "Url":"url",
/// "SharedAccessKeyName":"sasKeyName",
/// "SharedAccessKey":"sasKey"
/// }
/// }
/// </summary>
/// <param name="configurationPath">The path to the configuration file</param>
/// <param name="elementName">The element name of the private config. e.g., StorageAccount, EventHub</param>
/// <param name="attributeName">The attribute name of the element</param>
/// <returns></returns>
public static string GetConfigValueFromPrivateConfig(string configurationPath, string elementName, string attributeName)
{
string value = null;
string value = string.Empty;
var configFileType = GetConfigFileType(configurationPath);

if (configFileType == ConfigFileType.Xml)
Expand All @@ -304,25 +353,54 @@ public static string GetStorageAccountInfoFromPrivateConfig(string configuration
if (xmlConfig.Name.LocalName == DiagnosticsConfigurationElemStr)
{
var privateConfigElem = xmlConfig.Elements().FirstOrDefault(ele => ele.Name.LocalName == PrivateConfigElemStr);
var storageAccountElem = privateConfigElem == null ? null : privateConfigElem.Elements().FirstOrDefault(ele => ele.Name.LocalName == StorageAccountElemStr);
var attribute = storageAccountElem == null ? null : storageAccountElem.Attributes().FirstOrDefault(a => string.Equals(a.Name.LocalName, attributeName));
var configElem = privateConfigElem == null ? null : privateConfigElem.Elements().FirstOrDefault(ele => ele.Name.LocalName == elementName);
var attribute = configElem == null ? null : configElem.Attributes().FirstOrDefault(a => string.Equals(a.Name.LocalName, attributeName));
value = attribute == null ? null : attribute.Value;
}
}
else if (configFileType == ConfigFileType.Json)
{
// Find the PrivateConfig
var jsonConfig = JsonConvert.DeserializeObject<JObject>(File.ReadAllText(configurationPath));
var properties = jsonConfig.Properties().Select(p => p.Name);
var privateConfigProperty = properties.FirstOrDefault(p => p.Equals(PrivateConfigElemStr));

var privateConfigProperty = properties.FirstOrDefault(p => p.Equals(PrivateConfigElemStr, StringComparison.OrdinalIgnoreCase));
if (privateConfigProperty != null)
if (privateConfigProperty == null)
{
return value;
}
var privateConfig = jsonConfig[privateConfigProperty] as JObject;

// Find the target config object corresponding to elementName
JObject targetConfig = null;
if (elementName == StorageAccountElemStr)
{
// Special handling as private storage config is flattened
targetConfig = privateConfig;
var attributeNameMapping = new Dictionary<string, string>()
{
{ PrivConfNameAttr, "storageAccountName" },
{ PrivConfKeyAttr, "storageAccountKey" },
{ PrivConfEndpointAttr, "storageAccountEndPoint" }
};
attributeName = attributeNameMapping.FirstOrDefault(m => m.Key == attributeName).Value;
}
else
{
var privateConfig = jsonConfig[privateConfigProperty] as JObject;
properties = privateConfig.Properties().Select(p => p.Name);
var configProperty = properties.FirstOrDefault(p => p.Equals(elementName));
targetConfig = configProperty == null ? null : privateConfig[configProperty] as JObject;
}

var attributeProperty = properties.FirstOrDefault(p => p.Equals(attributeName, StringComparison.OrdinalIgnoreCase));
value = attributeProperty == null ? null : privateConfig[attributeProperty].Value<string>();
if (targetConfig == null || attributeName == null)
{
return value;
}

// Find the config value corresponding to attributeName
properties = targetConfig.Properties().Select(p => p.Name);
var attributeProperty = properties.FirstOrDefault(p => p.Equals(attributeName));
value = attributeProperty == null ? null : targetConfig[attributeProperty].Value<string>();
}

return value;
Expand Down Expand Up @@ -381,7 +459,7 @@ public static string InitializeStorageAccountKey(IStorageManagementClient storag
else
{
// Use the one defined in PrivateConfig
storageAccountKey = GetStorageAccountInfoFromPrivateConfig(configurationPath, PrivConfKeyAttr);
storageAccountKey = GetConfigValueFromPrivateConfig(configurationPath, StorageAccountElemStr, PrivConfKeyAttr);
}

return storageAccountKey;
Expand Down Expand Up @@ -414,7 +492,7 @@ public static string InitializeStorageAccountEndpoint(string storageAccountName,
storageAccountEndpoint = GetEndpointFromStorageContext(context);
}
else if (!string.IsNullOrEmpty(
storageAccountEndpoint = GetStorageAccountInfoFromPrivateConfig(configurationPath, PrivConfEndpointAttr)))
storageAccountEndpoint = GetConfigValueFromPrivateConfig(configurationPath, StorageAccountElemStr, PrivConfEndpointAttr)))
{
// We can get the value from PrivateConfig
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,8 @@ private Hashtable PrivateConfiguration
{
if (this.privateConfiguration == null)
{
this.privateConfiguration = DiagnosticsHelper.GetPrivateDiagnosticsConfiguration(this.StorageAccountName,
this.StorageAccountKey,
this.StorageAccountEndpoint);
this.privateConfiguration = DiagnosticsHelper.GetPrivateDiagnosticsConfiguration(this.DiagnosticsConfigurationPath,
this.StorageAccountName, this.StorageAccountKey, this.StorageAccountEndpoint);
}

return this.privateConfiguration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@
<DesignTime>True</DesignTime>
<DependentUpon>Resource.resx</DependentUpon>
</Compile>
<Compile Include="UnitTests\Cmdlets\IaaS\Extensions\Diagnostics\DiagnosticsHelperTest.cs" />
<Compile Include="UnitTests\Cmdlets\IaaS\Extensions\DSC\DscExtensionConfigurationParsingHelperTests.cs" />
<Compile Include="UnitTests\Cmdlets\IaaS\Extensions\DSC\DscExtensionSettingsSerializerTests.cs" />
<Compile Include="UnitTests\Cmdlets\IaaS\Extensions\DSC\GetAzureVMDscExtensionStatusUnitTest.cs" />
Expand Down Expand Up @@ -577,6 +578,12 @@
<None Include="Resources\wrongPara_VHD.csv">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Resources\Diagnostics\diagnostics.wadcfgx">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Resources\Diagnostics\config.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<Content Include="FunctionalTests\ExtensionTests\MicrosoftAntimalware\AntimalwareConfig.xml" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@ namespace Microsoft.WindowsAzure.Commands.ServiceManagement.Test
public class Category
{
public const string Scenario = "AzureRTScenario";
public const string BVT = "BVT";
public const string Functional = "Functional";
public const string Preview = "Preview";
public const string Sequential = "Sequential";
public const string Network = "Network";
public const string Upload = "AzureRTUpload";
public const string CleanUp = "AzureRTCleanUp";

// Acceptance type
public const string AcceptanceType = "AcceptanceType";
public const string BVT = "BVT";
public const string CheckIn = "CheckIn";
}

public class LoadBalancerDistribution
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
{
"PublicConfig": {
"WadCfg": {
"DiagnosticMonitorConfiguration": {
"DiagnosticInfrastructureLogs": {
"scheduledTransferLogLevelFilter": "Error"
},
"Directories": {
"IISLogs": {
"containerName": "wad-iis-logfiles"
},
"FailedRequestLogs": {
"containerName": "wad-failedrequestlogs"
},
"scheduledTransferPeriod": "PT1M"
},
"PerformanceCounters": {
"PerformanceCounterConfiguration": [
{
"annotation": [

],
"counterSpecifier": "\\Memory\\Available MBytes",
"sampleRate": "PT15S",
"sinks": "HotPath"
},
{
"annotation": [

],
"counterSpecifier": "\\Web Service(_Total)\\ISAPI Extension Requests/sec",
"sampleRate": "PT3M"
},
{
"annotation": [

],
"counterSpecifier": "\\Web Service(_Total)\\Bytes Total/Sec",
"sampleRate": "PT3M"
},
{
"annotation": [

],
"counterSpecifier": "\\ASP.NET Applications(__Total__)\\Requests/Sec",
"sampleRate": "PT3M"
},
{
"annotation": [

],
"counterSpecifier": "\\ASP.NET Applications(__Total__)\\Errors Total/Sec",
"sampleRate": "PT3M"
},
{
"annotation": [

],
"counterSpecifier": "\\ASP.NET\\Requests Queued",
"sampleRate": "PT3M"
},
{
"annotation": [

],
"counterSpecifier": "\\ASP.NET\\Requests Rejected",
"sampleRate": "PT3M"
},
{
"annotation": [

],
"counterSpecifier": "\\Processor(_Total)\\% Processor Time",
"sampleRate": "PT3M"
}
],
"scheduledTransferPeriod": "PT1M"
},
"WindowsEventLog": {
"sinks": "HotPath",
"DataSource": [
{
"name": "Application!*[System[(Level=1 or Level=2 or Level=3)]]"
},
{
"name": "Windows Azure!*[System[(Level=1 or Level=2 or Level=3 or Level=4)]]"
}
],
"scheduledTransferPeriod": "PT1M"
},
"CrashDumps": {
"CrashDumpConfiguration": [
{
"processName": "WaIISHost.exe"
},
{
"processName": "WaWorkerHost.exe"
},
{
"processName": "w3wp.exe"
}
]
},
"Logs": {
"scheduledTransferLogLevelFilter": "Error",
"scheduledTransferPeriod": "PT1M"
},
"overallQuotaInMB": 4096
},
"SinksConfig": {
"Sink": [
{
"name": "HotPath",
"EventHub": {
"Url": "Url",
"SharedAccessKeyName": "sasKeyName"
}
}
]
}
},
"StorageAccount": "yanmingv2vm9503"
},
"PrivateConfig": {
"storageAccountName": "storageAccountName",
"storageAccountKey": "storageAccountKey",
"storageAccountEndPoint": "https://core.windows.net/",
"EventHub": {
"Url": "Url",
"SharedAccessKeyName": "sasKeyName",
"SharedAccessKey": "sasKey"
}
}
}
Loading