Skip to content

Commit ff61e3f

Browse files
author
Hovsep
committed
Merge pull request Azure#1770 from yantang-msft/WadCfgBlob
Support WadCfgBlob in the config file
2 parents 1b09f28 + 94d11f1 commit ff61e3f

File tree

7 files changed

+59
-25
lines changed

7 files changed

+59
-25
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public static class DiagnosticsHelper
3636
private static string XmlNamespace = "http://schemas.microsoft.com/ServiceHosting/2010/10/DiagnosticsConfiguration";
3737
private static string EncodedXmlCfg = "xmlCfg";
3838
private static string WadCfg = "WadCfg";
39+
private static string WadCfgBlob = "WadCfgBlob";
3940
private static string StorageAccount = "storageAccount";
4041
private static string Path = "path";
4142
private static string ExpandResourceDirectory = "expandResourceDirectory";
@@ -163,6 +164,7 @@ private static Hashtable GetPublicConfigFromJsonFile(string configurationPath, s
163164
var publicConfig = GetPublicConfigJObjectFromJsonFile(configurationPath);
164165
var properties = publicConfig.Properties().Select(p => p.Name);
165166
var wadCfgProperty = properties.FirstOrDefault(p => p.Equals(WadCfg, StringComparison.OrdinalIgnoreCase));
167+
var wadCfgBlobProperty = properties.FirstOrDefault(p => p.Equals(WadCfgBlob, StringComparison.OrdinalIgnoreCase));
166168
var xmlCfgProperty = properties.FirstOrDefault(p => p.Equals(EncodedXmlCfg, StringComparison.OrdinalIgnoreCase));
167169

168170
var hashTable = new Hashtable();
@@ -172,13 +174,17 @@ private static Hashtable GetPublicConfigFromJsonFile(string configurationPath, s
172174
{
173175
hashTable.Add(wadCfgProperty, publicConfig[wadCfgProperty]);
174176
}
177+
else if (wadCfgBlobProperty != null)
178+
{
179+
hashTable.Add(wadCfgBlobProperty, publicConfig[wadCfgBlobProperty]);
180+
}
175181
else if (xmlCfgProperty != null)
176182
{
177183
hashTable.Add(xmlCfgProperty, publicConfig[xmlCfgProperty]);
178184
}
179185
else
180186
{
181-
throw new ArgumentException(Properties.Resources.DiagnosticsExtensionConfigNoWadCfgOrXmlCfg);
187+
throw new ArgumentException(Properties.Resources.DiagnosticsExtensionIaaSConfigElementNotDefined);
182188
}
183189

184190
return hashTable;

src/ResourceManager/Compute/Commands.Compute/Properties/Resources.Designer.cs

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ResourceManager/Compute/Commands.Compute/Properties/Resources.resx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -482,8 +482,8 @@ The file needs to be a PowerShell script (.ps1 or .psm1) or a ZIP archive (.zip)
482482
<data name="DiagnosticsExtensionNullStorageAccountEndpoint" xml:space="preserve">
483483
<value>Storage account endpoint is not defined or can not be retrieved automatically..</value>
484484
</data>
485-
<data name="DiagnosticsExtensionConfigNoWadCfgOrXmlCfg" xml:space="preserve">
486-
<value>WadCfg or xmlCfg is not defined in configuration file.</value>
485+
<data name="DiagnosticsExtensionIaaSConfigElementNotDefined" xml:space="preserve">
486+
<value>No WadCfg, WadCfgBlob or xmlCfg element defined in the configuration file.</value>
487487
</data>
488488
<data name="DiagnosticsExtensionInvalidConfigFileFormat" xml:space="preserve">
489489
<value>Invalid diagnostics configuration file. It should be in Invalid diagnostics configuration file. It should be in either xml or json format.either xml or json format.</value>

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public static class DiagnosticsHelper
3535
private static string XmlNamespace = "http://schemas.microsoft.com/ServiceHosting/2010/10/DiagnosticsConfiguration";
3636
private static string EncodedXmlCfg = "xmlCfg";
3737
private static string WadCfg = "WadCfg";
38+
private static string WadCfgBlob = "WadCfgBlob";
3839
private static string StorageAccount = "storageAccount";
3940
private static string Path = "path";
4041
private static string ExpandResourceDirectory = "expandResourceDirectory";
@@ -162,6 +163,7 @@ private static Hashtable GetPublicConfigFromJsonFile(string configurationPath, s
162163
var publicConfig = GetPublicConfigJObjectFromJsonFile(configurationPath);
163164
var properties = publicConfig.Properties().Select(p => p.Name);
164165
var wadCfgProperty = properties.FirstOrDefault(p => p.Equals(WadCfg, StringComparison.OrdinalIgnoreCase));
166+
var wadCfgBlobProperty = properties.FirstOrDefault(p => p.Equals(WadCfgBlob, StringComparison.OrdinalIgnoreCase));
165167
var xmlCfgProperty = properties.FirstOrDefault(p => p.Equals(EncodedXmlCfg, StringComparison.OrdinalIgnoreCase));
166168

167169
var hashTable = new Hashtable();
@@ -171,13 +173,17 @@ private static Hashtable GetPublicConfigFromJsonFile(string configurationPath, s
171173
{
172174
hashTable.Add(wadCfgProperty, publicConfig[wadCfgProperty]);
173175
}
176+
else if (wadCfgBlobProperty != null)
177+
{
178+
hashTable.Add(wadCfgBlobProperty, publicConfig[wadCfgBlobProperty]);
179+
}
174180
else if (xmlCfgProperty != null)
175181
{
176182
hashTable.Add(xmlCfgProperty, publicConfig[xmlCfgProperty]);
177183
}
178184
else
179185
{
180-
throw new ArgumentException(Properties.Resources.DiagnosticsExtensionConfigNoWadCfgOrXmlCfg);
186+
throw new ArgumentException(Properties.Resources.DiagnosticsExtensionIaaSConfigElementNotDefined);
181187
}
182188

183189
return hashTable;

src/ServiceManagement/Compute/Commands.ServiceManagement/Extensions/Diagnostics/BaseAzureServiceDiagnosticsExtension.cs

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -123,33 +123,43 @@ protected override void ValidateConfiguration()
123123
publicConfigElem.SetAttributeValue("xmlns", XmlNamespace);
124124
PublicConfiguration = publicConfigElem.ToString();
125125

126-
// The element <StorageAccount> is not meant to be set by the user in the public config.
127-
// Make sure it matches the storage account in the private config.
128126
XmlDocument doc = new XmlDocument();
129127
XmlNamespaceManager ns = new XmlNamespaceManager(doc.NameTable);
130128
ns.AddNamespace("ns", XmlNamespace);
131129
doc.Load(DiagnosticsConfigurationPath);
132-
var node = doc.SelectSingleNode("//ns:StorageAccount", ns);
133-
if(node != null)
130+
131+
// Make sure the configuration element exist
132+
var configElement = doc.SelectSingleNode("//ns:WadCfg", ns) ?? doc.SelectSingleNode("//ns:WadCfgBlob", ns);
133+
if (configElement == null)
134+
{
135+
throw new ArgumentException(Resources.DiagnosticsExtensionPaaSConfigElementNotDefined);
136+
}
137+
138+
// The element <StorageAccount> is not meant to be set by the user in the public config.
139+
// Make sure it matches the storage account in the private config.
140+
var storageAccountElement = doc.SelectSingleNode("//ns:StorageAccount", ns);
141+
if(storageAccountElement != null)
134142
{
135143
// The StorageAccount is empty, we must set it
136-
if (string.IsNullOrEmpty(node.InnerText))
144+
if (string.IsNullOrEmpty(storageAccountElement.InnerText))
137145
{
138-
var insertIndex = PublicConfiguration.IndexOf("</StorageAccount>");
139-
PublicConfiguration = PublicConfiguration.Insert(insertIndex, StorageAccountName);
146+
storageAccountElement.InnerText = StorageAccountName;
147+
PublicConfiguration = doc.OuterXml;
140148
}
141-
else if (!string.IsNullOrEmpty(node.InnerText) && string.Compare(node.InnerText, StorageAccountName, true) != 0)
149+
else if (!string.IsNullOrEmpty(storageAccountElement.InnerText) && string.Compare(storageAccountElement.InnerText, StorageAccountName, true) != 0)
142150
{
143151
throw new ArgumentException(Resources.DiagnosticsExtensionNoMatchStorageAccount);
144152
}
145153
}
146154
else
147155
{
148-
// the StorageAccount is not there. we must set it
149-
string storageAccountElem = "\n<StorageAccount>" + StorageAccountName + "</StorageAccount>\n";
150-
// insert it after </WadCfg>
151-
int wadCfgEndIndex = PublicConfiguration.IndexOf("</WadCfg>");
152-
PublicConfiguration = PublicConfiguration.Insert(wadCfgEndIndex + "</WadCfg>".Length, storageAccountElem);
156+
// The StorageAccount is not there. we must set it
157+
storageAccountElement = doc.CreateElement("StorageAccount", XmlNamespace);
158+
storageAccountElement.InnerText = StorageAccountName;
159+
160+
// Insert it after <WadCfg> or <WadCfgBlob>
161+
configElement.ParentNode.AppendChild(storageAccountElement);
162+
PublicConfiguration = doc.OuterXml;
153163
}
154164

155165
// Make sure the storage account name in PrivateConfig matches.

src/ServiceManagement/Compute/Commands.ServiceManagement/Properties/Resources.Designer.cs

Lines changed: 12 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ServiceManagement/Compute/Commands.ServiceManagement/Properties/Resources.resx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -783,10 +783,13 @@
783783
<data name="DiagnosticsExtensionXmlConfigWadCfgTagNotMatch" xml:space="preserve">
784784
<value>WadCfg start element in the config is not matching the end element.</value>
785785
</data>
786-
<data name="DiagnosticsExtensionConfigNoWadCfgOrXmlCfg" xml:space="preserve">
787-
<value>WadCfg or xmlCfg is not defined in configuration file.</value>
786+
<data name="DiagnosticsExtensionIaaSConfigElementNotDefined" xml:space="preserve">
787+
<value>No WadCfg, WadCfgBlob or xmlCfg element defined in the configuration file.</value>
788788
</data>
789789
<data name="DiagnosticsExtensionInvalidConfigFileFormat" xml:space="preserve">
790790
<value>Invalid diagnostics configuration file. It should be in either xml or json format.</value>
791791
</data>
792+
<data name="DiagnosticsExtensionPaaSConfigElementNotDefined" xml:space="preserve">
793+
<value>No WadCfg or WadCfgBlob element defined in the configuration file.</value>
794+
</data>
792795
</root>

0 commit comments

Comments
 (0)