Skip to content

Commit eff5e99

Browse files
committed
Merge pull request Azure#484 from huangpf/dev
HPF PR: vmss <- huangpf:dev
2 parents f58f441 + 56c649a commit eff5e99

File tree

41 files changed

+16126
-6084
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+16126
-6084
lines changed

src/ResourceManager/Compute/Commands.Compute.Test/Commands.Compute.Test.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
<Private>True</Private>
6969
</Reference>
7070
<Reference Include="Microsoft.Azure.Management.Network, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
71-
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Network.3.2.0-preview\lib\net45\Microsoft.Azure.Management.Network.dll</HintPath>
71+
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Network.3.3.0-preview\lib\net45\Microsoft.Azure.Management.Network.dll</HintPath>
7272
<Private>True</Private>
7373
</Reference>
7474
<Reference Include="Microsoft.Azure.Management.Storage, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">

src/ResourceManager/Compute/Commands.Compute.Test/ConfigFiles/DiagnosticsExtensionConfig.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,14 @@
8686
"scheduledTransferLogLevelFilter": "Error",
8787
"scheduledTransferPeriod": "PT1M"
8888
},
89+
"Metrics": {
90+
"resourceId": "dummy",
91+
"MetricAggregation": [
92+
{
93+
"scheduledTransferPeriod": "PT1M"
94+
}
95+
]
96+
},
8997
"overallQuotaInMB": 4096
9098
}
9199
}

src/ResourceManager/Compute/Commands.Compute.Test/ConfigFiles/DiagnosticsExtensionConfig.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
<CrashDumpConfiguration processName="w3wp.exe" />
2727
</CrashDumps>
2828
<Logs scheduledTransferPeriod="PT3M" />
29+
<Metrics resourceId="dummy">
30+
<MetricAggregation scheduledTransferPeriod="PT1M"/>
31+
</Metrics>
2932
</DiagnosticMonitorConfiguration>
3033
</WadCfg>
3134
<StorageAccount>definedinconfigstorage</StorageAccount>

src/ResourceManager/Compute/Commands.Compute.Test/SessionRecords/Microsoft.Azure.Commands.Compute.Test.ScenarioTests.DiagnosticsExtensionTests/TestDiagnosticsExtensionBasic.json

Lines changed: 2535 additions & 1648 deletions
Large diffs are not rendered by default.

src/ResourceManager/Compute/Commands.Compute.Test/SessionRecords/Microsoft.Azure.Commands.Compute.Test.ScenarioTests.DiagnosticsExtensionTests/TestDiagnosticsExtensionSepcifyStorageAccountName.json

Lines changed: 2093 additions & 1439 deletions
Large diffs are not rendered by default.

src/ResourceManager/Compute/Commands.Compute.Test/SessionRecords/Microsoft.Azure.Commands.Compute.Test.ScenarioTests.DiagnosticsExtensionTests/TestDiagnosticsExtensionSupportJsonConfig.json

Lines changed: 1410 additions & 1278 deletions
Large diffs are not rendered by default.

src/ResourceManager/Compute/Commands.Compute.Test/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<package id="Microsoft.Azure.Graph.RBAC" version="1.9.0-preview" targetFramework="net45" />
88
<package id="Microsoft.Azure.Management.Authorization" version="1.0.0" targetFramework="net45" />
99
<package id="Microsoft.Azure.Management.Compute" version="11.3.0-prerelease" targetFramework="net45" />
10-
<package id="Microsoft.Azure.Management.Network" version="3.2.0-preview" targetFramework="net45" />
10+
<package id="Microsoft.Azure.Management.Network" version="3.3.0-preview" targetFramework="net45" />
1111
<package id="Microsoft.Azure.Management.Storage" version="3.0.0" targetFramework="net45" />
1212
<package id="Microsoft.Azure.Test.Framework" version="1.0.5896.19355-prerelease" targetFramework="net45" />
1313
<package id="Microsoft.Azure.Test.HttpRecorder" version="1.6.0-preview" targetFramework="net45" />

src/ResourceManager/Compute/Commands.Compute/Commands.Compute.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
<Private>True</Private>
8282
</Reference>
8383
<Reference Include="Microsoft.Azure.Management.Network, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
84-
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Network.3.2.0-preview\lib\net45\Microsoft.Azure.Management.Network.dll</HintPath>
84+
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Network.3.3.0-preview\lib\net45\Microsoft.Azure.Management.Network.dll</HintPath>
8585
<Private>True</Private>
8686
</Reference>
8787
<Reference Include="Microsoft.Azure.Management.Storage">

src/ResourceManager/Compute/Commands.Compute/Common/DiagnosticsHelper.cs

Lines changed: 94 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
using System.Collections;
1717
using System.IO;
1818
using System.Linq;
19+
using System.Management.Automation;
1920
using System.Text;
2021
using System.Xml;
2122
using System.Xml.Linq;
@@ -46,12 +47,15 @@ public static class DiagnosticsHelper
4647
private static string StorageAccountEndPointTag = "storageAccountEndPoint";
4748

4849
public static string DiagnosticsConfigurationElemStr = "DiagnosticsConfiguration";
50+
public static string DiagnosticMonitorConfigurationElemStr = "DiagnosticMonitorConfiguration";
4951
public static string PublicConfigElemStr = "PublicConfig";
5052
public static string PrivateConfigElemStr = "PrivateConfig";
5153
public static string StorageAccountElemStr = "StorageAccount";
5254
public static string PrivConfNameAttr = "name";
5355
public static string PrivConfKeyAttr = "key";
5456
public static string PrivConfEndpointAttr = "endpoint";
57+
public static string MetricsElemStr = "Metrics";
58+
public static string MetricsResourceIdAttr = "resourceId";
5559

5660
public enum ConfigFileType
5761
{
@@ -70,71 +74,58 @@ public static ConfigFileType GetConfigFileType(string configurationPath)
7074
doc.Load(configurationPath);
7175
return ConfigFileType.Xml;
7276
}
73-
catch
77+
catch (XmlException)
7478
{ }
7579

7680
try
7781
{
7882
JsonConvert.DeserializeObject(File.ReadAllText(configurationPath));
7983
return ConfigFileType.Json;
8084
}
81-
catch
85+
catch (JsonReaderException)
8286
{ }
8387
}
8488

8589
return ConfigFileType.Unknown;
8690
}
8791

8892
public static Hashtable GetPublicDiagnosticsConfigurationFromFile(string configurationPath,
89-
string storageAccountName)
93+
string storageAccountName, string resourceId, Cmdlet cmdlet)
9094
{
9195
switch (GetConfigFileType(configurationPath))
9296
{
9397
case ConfigFileType.Xml:
94-
return GetPublicConfigFromXmlFile(configurationPath, storageAccountName);
98+
return GetPublicConfigFromXmlFile(configurationPath, storageAccountName, resourceId, cmdlet);
9599
case ConfigFileType.Json:
96-
return GetPublicConfigFromJsonFile(configurationPath, storageAccountName);
100+
return GetPublicConfigFromJsonFile(configurationPath, storageAccountName, resourceId, cmdlet);
97101
default:
98102
throw new ArgumentException(Properties.Resources.DiagnosticsExtensionInvalidConfigFileFormat);
99103
}
100104
}
101105

102-
private static Hashtable GetPublicConfigFromXmlFile(string configurationPath, string storageAccountName)
106+
private static Hashtable GetPublicConfigFromXmlFile(string configurationPath, string storageAccountName, string resourceId, Cmdlet cmdlet)
103107
{
104-
var config = File.ReadAllText(configurationPath);
105-
106-
// find the <WadCfg> element and extract it
107-
int wadCfgBeginIndex = config.IndexOf("<WadCfg>");
108-
if (wadCfgBeginIndex == -1)
108+
var doc = XDocument.Load(configurationPath);
109+
var wadCfgElement = doc.Descendants().FirstOrDefault(d => d.Name.LocalName == WadCfg);
110+
var wadCfgBlobElement = doc.Descendants().FirstOrDefault(d => d.Name.LocalName == WadCfgBlob);
111+
if (wadCfgElement == null && wadCfgBlobElement == null)
109112
{
110-
throw new ArgumentException(Properties.Resources.DiagnosticsExtensionXmlConfigNoWadCfgStartTag);
113+
throw new ArgumentException(Properties.Resources.DiagnosticsExtensionIaaSConfigElementNotDefinedInXml);
111114
}
112115

113-
int wadCfgEndIndex = config.IndexOf("</WadCfg>");
114-
if (wadCfgEndIndex == -1)
116+
if (wadCfgElement != null)
115117
{
116-
throw new ArgumentException(Properties.Resources.DiagnosticsExtensionXmlConfigNoWadCfgEndTag);
118+
AutoFillMetricsConfig(wadCfgElement, resourceId, cmdlet);
117119
}
118120

119-
if (wadCfgEndIndex <= wadCfgBeginIndex)
120-
{
121-
throw new ArgumentException(Properties.Resources.DiagnosticsExtensionXmlConfigWadCfgTagNotMatch);
122-
}
123-
124-
string encodedConfiguration = Convert.ToBase64String(
125-
Encoding.UTF8.GetBytes(
126-
config.Substring(
127-
wadCfgBeginIndex, wadCfgEndIndex + "</WadCfg>".Length - wadCfgBeginIndex).ToCharArray()));
121+
string originalConfiguration = wadCfgElement != null ? wadCfgElement.ToString() : wadCfgBlobElement.ToString();
122+
string encodedConfiguration = Convert.ToBase64String(Encoding.UTF8.GetBytes(wadCfgElement.ToString().ToCharArray()));
128123

129124
// Now extract the local resource directory element
130-
XmlDocument doc = new XmlDocument();
131-
XmlNamespaceManager ns = new XmlNamespaceManager(doc.NameTable);
132-
ns.AddNamespace("ns", XmlNamespace);
133-
doc.LoadXml(config);
134-
var node = doc.SelectSingleNode("//ns:LocalResourceDirectory", ns);
135-
string localDirectory = (node != null && node.Attributes != null) ? node.Attributes[Path].Value : null;
136-
string localDirectoryExpand = (node != null && node.Attributes != null)
137-
? node.Attributes["expandEnvironment"].Value
125+
var node = doc.Descendants().FirstOrDefault(e => e.Name.LocalName == "LocalResourceDirectory");
126+
string localDirectory = (node != null && node.Attribute(Path) != null) ? node.Attribute(Path).Value : null;
127+
string localDirectoryExpand = (node != null && node.Attribute("expandEnvironment") != null)
128+
? node.Attribute("expandEnvironment").Value
138129
: null;
139130
if (localDirectoryExpand == "0")
140131
{
@@ -159,7 +150,39 @@ private static Hashtable GetPublicConfigFromXmlFile(string configurationPath, st
159150
return hashTable;
160151
}
161152

162-
private static Hashtable GetPublicConfigFromJsonFile(string configurationPath, string storageAccountName)
153+
private static void AutoFillMetricsConfig(XElement wadCfgElement, string resourceId, Cmdlet cmdlet)
154+
{
155+
if (string.IsNullOrEmpty(resourceId))
156+
{
157+
return;
158+
}
159+
160+
var configurationElem = wadCfgElement.Elements().FirstOrDefault(d => d.Name.LocalName == DiagnosticMonitorConfigurationElemStr);
161+
if (configurationElem == null)
162+
{
163+
throw new ArgumentException(Properties.Resources.DiagnosticsExtensionDiagnosticMonitorConfigurationElementNotDefined);
164+
}
165+
166+
var metricsElement = configurationElem.Elements().FirstOrDefault(d => d.Name.LocalName == MetricsElemStr);
167+
if (metricsElement == null)
168+
{
169+
XNamespace ns = XmlNamespace;
170+
metricsElement = new XElement(ns + MetricsElemStr,
171+
new XAttribute(MetricsResourceIdAttr, resourceId));
172+
configurationElem.Add(metricsElement);
173+
}
174+
else
175+
{
176+
var resourceIdAttr = metricsElement.Attribute(MetricsResourceIdAttr);
177+
if (resourceIdAttr != null && !resourceIdAttr.Value.Equals(resourceId))
178+
{
179+
cmdlet.WriteWarning(Properties.Resources.DiagnosticsExtensionMetricsResourceIdNotMatch);
180+
}
181+
metricsElement.SetAttributeValue(MetricsResourceIdAttr, resourceId);
182+
}
183+
}
184+
185+
private static Hashtable GetPublicConfigFromJsonFile(string configurationPath, string storageAccountName, string resourceId, Cmdlet cmdlet)
163186
{
164187
var publicConfig = GetPublicConfigJObjectFromJsonFile(configurationPath);
165188
var properties = publicConfig.Properties().Select(p => p.Name);
@@ -170,9 +193,11 @@ private static Hashtable GetPublicConfigFromJsonFile(string configurationPath, s
170193
var hashTable = new Hashtable();
171194
hashTable.Add(StorageAccount, storageAccountName);
172195

173-
if (wadCfgProperty != null)
196+
if (wadCfgProperty != null && publicConfig[wadCfgProperty] is JObject)
174197
{
175-
hashTable.Add(wadCfgProperty, publicConfig[wadCfgProperty]);
198+
var wadCfgObject = (JObject)publicConfig[wadCfgProperty];
199+
AutoFillMetricsConfig(wadCfgObject, resourceId, cmdlet);
200+
hashTable.Add(wadCfgProperty, wadCfgObject);
176201
}
177202
else if (wadCfgBlobProperty != null)
178203
{
@@ -184,12 +209,43 @@ private static Hashtable GetPublicConfigFromJsonFile(string configurationPath, s
184209
}
185210
else
186211
{
187-
throw new ArgumentException(Properties.Resources.DiagnosticsExtensionIaaSConfigElementNotDefined);
212+
throw new ArgumentException(Properties.Resources.DiagnosticsExtensionIaaSConfigElementNotDefinedInJson);
188213
}
189214

190215
return hashTable;
191216
}
192217

218+
private static void AutoFillMetricsConfig(JObject wadCfgObject, string resourceId, Cmdlet cmdlet)
219+
{
220+
if (string.IsNullOrEmpty(resourceId))
221+
{
222+
return;
223+
}
224+
225+
var configObject = wadCfgObject[DiagnosticMonitorConfigurationElemStr] as JObject;
226+
if (configObject == null)
227+
{
228+
throw new ArgumentException(Properties.Resources.DiagnosticsExtensionDiagnosticMonitorConfigurationElementNotDefined);
229+
}
230+
231+
var metricsObject = configObject[MetricsElemStr] as JObject;
232+
if (metricsObject == null)
233+
{
234+
configObject.Add(new JProperty(MetricsElemStr,
235+
new JObject(
236+
new JProperty(MetricsResourceIdAttr, resourceId))));
237+
}
238+
else
239+
{
240+
var resourceIdValue = metricsObject[MetricsResourceIdAttr] as JValue;
241+
if (resourceIdValue != null && !resourceIdValue.Value.Equals(resourceId))
242+
{
243+
cmdlet.WriteWarning(Properties.Resources.DiagnosticsExtensionMetricsResourceIdNotMatch);
244+
}
245+
metricsObject[MetricsResourceIdAttr] = resourceId;
246+
}
247+
}
248+
193249
public static Hashtable GetPrivateDiagnosticsConfiguration(string storageAccountName,
194250
string storageKey, string endpoint)
195251
{
@@ -201,7 +257,7 @@ public static Hashtable GetPrivateDiagnosticsConfiguration(string storageAccount
201257
return privateConfig;
202258
}
203259

204-
public static XElement GetPublicConfigXElementFromXmlFile(string configurationPath)
260+
private static XElement GetPublicConfigXElementFromXmlFile(string configurationPath)
205261
{
206262
XElement publicConfig = null;
207263

@@ -224,7 +280,7 @@ public static XElement GetPublicConfigXElementFromXmlFile(string configurationPa
224280
return publicConfig;
225281
}
226282

227-
public static JObject GetPublicConfigJObjectFromJsonFile(string configurationPath)
283+
private static JObject GetPublicConfigJObjectFromJsonFile(string configurationPath)
228284
{
229285
var config = JsonConvert.DeserializeObject<JObject>(File.ReadAllText(configurationPath));
230286
var properties = config.Properties().Select(p => p.Name);

src/ResourceManager/Compute/Commands.Compute/Extension/AEM/AEMExtensionConstants.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ public static class AEMExtensionConstants
2424
public static Dictionary<string, string> AEMExtensionDefaultName = new Dictionary<string, string>() { { OSTypeWindows, "AzureCATExtensionHandler" }, { OSTypeLinux, "AzureEnhancedMonitorForLinux" } };
2525
public static Dictionary<string, string> AEMExtensionPublisher = new Dictionary<string, string>() { { OSTypeWindows, "Microsoft.AzureCAT.AzureEnhancedMonitoring" }, { OSTypeLinux, "Microsoft.OSTCExtensions" } };
2626
public static Dictionary<string, string> AEMExtensionType = new Dictionary<string, string>() { { OSTypeWindows, "AzureCATExtensionHandler" }, { OSTypeLinux, "AzureEnhancedMonitorForLinux" } };
27-
public static Dictionary<string, string> AEMExtensionVersion = new Dictionary<string, string>() { { OSTypeWindows, "2.2" }, { OSTypeLinux, "3.0" } };
27+
public static Dictionary<string, Version> AEMExtensionVersion = new Dictionary<string, Version>() { { OSTypeWindows, new Version(2, 2) }, { OSTypeLinux, new Version(3,0) } };
2828

2929
public static Dictionary<string, string> WADExtensionDefaultName = new Dictionary<string, string>() { { OSTypeWindows, "IaaSDiagnostics" }, { OSTypeLinux, "LinuxDiagnostic" } };
3030
public static Dictionary<string, string> WADExtensionPublisher = new Dictionary<string, string>() { { OSTypeWindows, "Microsoft.Azure.Diagnostics" }, { OSTypeLinux, "Microsoft.OSTCExtensions" } };
3131
public static Dictionary<string, string> WADExtensionType = new Dictionary<string, string>() { { OSTypeWindows, "IaaSDiagnostics" }, { OSTypeLinux, "LinuxDiagnostic" } };
32-
public static Dictionary<string, string> WADExtensionVersion = new Dictionary<string, string>() { { OSTypeWindows, "1.5" }, { OSTypeLinux, "2.2" } };
32+
public static Dictionary<string, Version> WADExtensionVersion = new Dictionary<string, Version>() { { OSTypeWindows, new Version(1,5) }, { OSTypeLinux, new Version(2,2) } };
3333

3434
public const string OSTypeWindows = "Windows";
3535
public const string OSTypeLinux = "Linux";

src/ResourceManager/Compute/Commands.Compute/Extension/AEM/AEMHelper.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,44 @@ internal VirtualMachineExtension GetExtension(VirtualMachine vm, string type, st
426426
return null;
427427
}
428428

429+
internal Version GetExtensionVersion(VirtualMachine vm, VirtualMachineInstanceView vmStatus, string osType, string type, string publisher)
430+
{
431+
Version version = new Version();
432+
if (AEMExtensionConstants.AEMExtensionPublisher[osType].Equals(publisher, StringComparison.InvariantCultureIgnoreCase)
433+
&& AEMExtensionConstants.AEMExtensionType[osType].Equals(type, StringComparison.InvariantCultureIgnoreCase))
434+
{
435+
version = AEMExtensionConstants.AEMExtensionVersion[osType];
436+
}
437+
else if (AEMExtensionConstants.WADExtensionPublisher[osType].Equals(publisher, StringComparison.InvariantCultureIgnoreCase)
438+
&& AEMExtensionConstants.WADExtensionType[osType].Equals(type, StringComparison.InvariantCultureIgnoreCase))
439+
{
440+
version = AEMExtensionConstants.WADExtensionVersion[osType];
441+
}
442+
443+
if (vm.Resources != null && vmStatus.Extensions != null)
444+
{
445+
var extension = vm.Resources.FirstOrDefault(ext =>
446+
ext.VirtualMachineExtensionType.Equals(type)
447+
&& ext.Publisher.Equals(publisher));
448+
449+
if (extension != null)
450+
{
451+
var extensionStatus = vmStatus.Extensions.FirstOrDefault(ext => ext.Name.Equals(extension.Name));
452+
453+
if (extensionStatus != null)
454+
{
455+
string strExtVersion = extensionStatus.TypeHandlerVersion;
456+
Version extVersion;
457+
if (Version.TryParse(strExtVersion, out extVersion))
458+
{
459+
version = extVersion;
460+
}
461+
}
462+
}
463+
}
464+
return version;
465+
}
466+
429467
internal VirtualMachineExtensionInstanceView GetExtension(VirtualMachine vm, VirtualMachineInstanceView vmStatus, string type, string publisher)
430468
{
431469
var ext = this.GetExtension(vm, type, publisher);

src/ResourceManager/Compute/Commands.Compute/Extension/AEM/GetAzureRmVMAEMExtension.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,6 @@ public override void ExecuteCmdlet()
127127
});
128128
}
129129

130-
private void WriteVerbose(string message, params object[] args)
131-
{
132-
base.WriteVerbose(String.Format(message, args));
133-
}
134-
135130
private void WriteError(string message, params object[] args)
136131
{
137132
base.WriteError(new ErrorRecord(new Exception(String.Format(message, args)), "Error", ErrorCategory.NotSpecified, null));

0 commit comments

Comments
 (0)