Skip to content

Support WadCfgBlob in the config file #1770

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 2 commits into from
Feb 4, 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 @@ -36,6 +36,7 @@ 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";
private static string StorageAccount = "storageAccount";
private static string Path = "path";
private static string ExpandResourceDirectory = "expandResourceDirectory";
Expand Down Expand Up @@ -163,6 +164,7 @@ private static Hashtable GetPublicConfigFromJsonFile(string configurationPath, s
var publicConfig = GetPublicConfigJObjectFromJsonFile(configurationPath);
var properties = publicConfig.Properties().Select(p => p.Name);
var wadCfgProperty = properties.FirstOrDefault(p => p.Equals(WadCfg, StringComparison.OrdinalIgnoreCase));
var wadCfgBlobProperty = properties.FirstOrDefault(p => p.Equals(WadCfgBlob, StringComparison.OrdinalIgnoreCase));
var xmlCfgProperty = properties.FirstOrDefault(p => p.Equals(EncodedXmlCfg, StringComparison.OrdinalIgnoreCase));

var hashTable = new Hashtable();
Expand All @@ -172,13 +174,17 @@ private static Hashtable GetPublicConfigFromJsonFile(string configurationPath, s
{
hashTable.Add(wadCfgProperty, publicConfig[wadCfgProperty]);
}
else if (wadCfgBlobProperty != null)
{
hashTable.Add(wadCfgBlobProperty, publicConfig[wadCfgBlobProperty]);
}
else if (xmlCfgProperty != null)
{
hashTable.Add(xmlCfgProperty, publicConfig[xmlCfgProperty]);
}
else
{
throw new ArgumentException(Properties.Resources.DiagnosticsExtensionConfigNoWadCfgOrXmlCfg);
throw new ArgumentException(Properties.Resources.DiagnosticsExtensionIaaSConfigElementNotDefined);
}

return hashTable;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -482,8 +482,8 @@ The file needs to be a PowerShell script (.ps1 or .psm1) or a ZIP archive (.zip)
<data name="DiagnosticsExtensionNullStorageAccountEndpoint" xml:space="preserve">
<value>Storage account endpoint is not defined or can not be retrieved automatically..</value>
</data>
<data name="DiagnosticsExtensionConfigNoWadCfgOrXmlCfg" xml:space="preserve">
<value>WadCfg or xmlCfg is not defined in configuration file.</value>
<data name="DiagnosticsExtensionIaaSConfigElementNotDefined" xml:space="preserve">
<value>No WadCfg, WadCfgBlob or xmlCfg element defined in the configuration file.</value>
</data>
<data name="DiagnosticsExtensionInvalidConfigFileFormat" xml:space="preserve">
<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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ 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";
private static string StorageAccount = "storageAccount";
private static string Path = "path";
private static string ExpandResourceDirectory = "expandResourceDirectory";
Expand Down Expand Up @@ -162,6 +163,7 @@ private static Hashtable GetPublicConfigFromJsonFile(string configurationPath, s
var publicConfig = GetPublicConfigJObjectFromJsonFile(configurationPath);
var properties = publicConfig.Properties().Select(p => p.Name);
var wadCfgProperty = properties.FirstOrDefault(p => p.Equals(WadCfg, StringComparison.OrdinalIgnoreCase));
var wadCfgBlobProperty = properties.FirstOrDefault(p => p.Equals(WadCfgBlob, StringComparison.OrdinalIgnoreCase));
var xmlCfgProperty = properties.FirstOrDefault(p => p.Equals(EncodedXmlCfg, StringComparison.OrdinalIgnoreCase));

var hashTable = new Hashtable();
Expand All @@ -171,13 +173,17 @@ private static Hashtable GetPublicConfigFromJsonFile(string configurationPath, s
{
hashTable.Add(wadCfgProperty, publicConfig[wadCfgProperty]);
}
else if (wadCfgBlobProperty != null)
{
hashTable.Add(wadCfgBlobProperty, publicConfig[wadCfgBlobProperty]);
}
else if (xmlCfgProperty != null)
{
hashTable.Add(xmlCfgProperty, publicConfig[xmlCfgProperty]);
}
else
{
throw new ArgumentException(Properties.Resources.DiagnosticsExtensionConfigNoWadCfgOrXmlCfg);
throw new ArgumentException(Properties.Resources.DiagnosticsExtensionIaaSConfigElementNotDefined);
}

return hashTable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,33 +123,43 @@ protected override void ValidateConfiguration()
publicConfigElem.SetAttributeValue("xmlns", XmlNamespace);
PublicConfiguration = publicConfigElem.ToString();

// The element <StorageAccount> is not meant to be set by the user in the public config.
// Make sure it matches the storage account in the private config.
XmlDocument doc = new XmlDocument();
XmlNamespaceManager ns = new XmlNamespaceManager(doc.NameTable);
ns.AddNamespace("ns", XmlNamespace);
doc.Load(DiagnosticsConfigurationPath);
var node = doc.SelectSingleNode("//ns:StorageAccount", ns);
if(node != null)

// Make sure the configuration element exist
var configElement = doc.SelectSingleNode("//ns:WadCfg", ns) ?? doc.SelectSingleNode("//ns:WadCfgBlob", ns);
if (configElement == null)
{
throw new ArgumentException(Resources.DiagnosticsExtensionPaaSConfigElementNotDefined);
}

// The element <StorageAccount> is not meant to be set by the user in the public config.
// Make sure it matches the storage account in the private config.
var storageAccountElement = doc.SelectSingleNode("//ns:StorageAccount", ns);
if(storageAccountElement != null)
{
// The StorageAccount is empty, we must set it
if (string.IsNullOrEmpty(node.InnerText))
if (string.IsNullOrEmpty(storageAccountElement.InnerText))
{
var insertIndex = PublicConfiguration.IndexOf("</StorageAccount>");
PublicConfiguration = PublicConfiguration.Insert(insertIndex, StorageAccountName);
storageAccountElement.InnerText = StorageAccountName;
PublicConfiguration = doc.OuterXml;
}
else if (!string.IsNullOrEmpty(node.InnerText) && string.Compare(node.InnerText, StorageAccountName, true) != 0)
else if (!string.IsNullOrEmpty(storageAccountElement.InnerText) && string.Compare(storageAccountElement.InnerText, StorageAccountName, true) != 0)
{
throw new ArgumentException(Resources.DiagnosticsExtensionNoMatchStorageAccount);
}
}
else
{
// the StorageAccount is not there. we must set it
string storageAccountElem = "\n<StorageAccount>" + StorageAccountName + "</StorageAccount>\n";
// insert it after </WadCfg>
int wadCfgEndIndex = PublicConfiguration.IndexOf("</WadCfg>");
PublicConfiguration = PublicConfiguration.Insert(wadCfgEndIndex + "</WadCfg>".Length, storageAccountElem);
// The StorageAccount is not there. we must set it
storageAccountElement = doc.CreateElement("StorageAccount", XmlNamespace);
storageAccountElement.InnerText = StorageAccountName;

// Insert it after <WadCfg> or <WadCfgBlob>
configElement.ParentNode.AppendChild(storageAccountElement);
PublicConfiguration = doc.OuterXml;
}

// Make sure the storage account name in PrivateConfig matches.
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -783,10 +783,13 @@
<data name="DiagnosticsExtensionXmlConfigWadCfgTagNotMatch" xml:space="preserve">
<value>WadCfg start element in the config is not matching the end element.</value>
</data>
<data name="DiagnosticsExtensionConfigNoWadCfgOrXmlCfg" xml:space="preserve">
<value>WadCfg or xmlCfg is not defined in configuration file.</value>
<data name="DiagnosticsExtensionIaaSConfigElementNotDefined" xml:space="preserve">
<value>No WadCfg, WadCfgBlob or xmlCfg element defined in the configuration file.</value>
</data>
<data name="DiagnosticsExtensionInvalidConfigFileFormat" xml:space="preserve">
<value>Invalid diagnostics configuration file. It should be in either xml or json format.</value>
</data>
<data name="DiagnosticsExtensionPaaSConfigElementNotDefined" xml:space="preserve">
<value>No WadCfg or WadCfgBlob element defined in the configuration file.</value>
</data>
</root>