private void ValidateAccountName(string value, string source, string destination, string elementName) { if (value == null) { return; } if (!this.ShouldValidate(value)) { return; } if (!ImageBuilderUtility.IsValidAccountName(value)) { ImageBuilderUtility.TraceAndThrowValidationError( TraceType, StringResources.ImageBuilderError_DiagnosticValidator_InvalidAccountNameFormat, value, source, (destination != null) ? destination : String.Empty, elementName); } }
private void ValidateFileStorePath(FileStoreType fileStore, string source) { if (!this.ShouldValidate(fileStore.Path)) { return; } if (String.IsNullOrEmpty(fileStore.Path)) { ImageBuilderUtility.TraceAndThrowValidationError( TraceType, StringResources.ImageBuilderError_DiagnosticValidator_EmptyFilePathNotAllowed, source, FileStore, FileStorePath); } try { Uri uri = new Uri(fileStore.Path); } catch (Exception e) { ImageBuilderUtility.TraceAndThrowValidationError( TraceType, StringResources.ImageBuilderError_DiagnosticValidator_PathNotValidUri, fileStore.Path, source, FileStore, FileStorePath, e); } }
private void ValidateManagedServiceAccount(FileStoreType fileStore, string source) { if ((this.ShouldValidate(fileStore.Password)) && (!String.IsNullOrEmpty(fileStore.Password))) { ImageBuilderUtility.TraceAndThrowValidationError( TraceType, StringResources.ImageBuilderError_DiagnosticValidator_PasswordAttributeInvalid, Password, AccountType, FileStoreAccessAccountType.ManagedServiceAccount, source, FileStore); } if ((this.ShouldValidate(fileStore.PasswordEncrypted)) && (!String.IsNullOrEmpty(fileStore.PasswordEncrypted))) { ImageBuilderUtility.TraceAndThrowValidationError( TraceType, StringResources.ImageBuilderError_DiagnosticValidator_PasswordAttributeInvalid, PasswordEncrypted, AccountType, FileStoreAccessAccountType.ManagedServiceAccount, source, FileStore); } ValidateAccountName(fileStore.AccountName, source, FileStore, AccountName); }
private T ValidateType <T>(string value, string source, string destination, string elementName) { if (value == null) { return(default(T)); } if (!this.ShouldValidate(value)) { return(default(T)); } T convertedValue = default(T); try { convertedValue = ImageBuilderUtility.ConvertString <T>(value); } catch (Exception) { ImageBuilderUtility.TraceAndThrowValidationError( TraceType, StringResources.ImageBuilderError_DiagnosticValidator_ValueCannotBeConverted, value, typeof(T), source, (destination != null) ? destination : String.Empty, elementName); } return(convertedValue); }
private void ValidatePositiveInteger(string value, string source, string destination, string elementName) { if (value == null) { return; } if (!this.ShouldValidate(value)) { return; } int convertedValue = ValidateType <int>(value, source, destination, elementName); if (convertedValue <= 0) { ImageBuilderUtility.TraceAndThrowValidationError( TraceType, StringResources.ImageBuilderError_DiagnosticValidator_ValueMustBeGreaterThanZero, value, source, (destination != null) ? destination : String.Empty, elementName); } }
public void Add(string name) { if (this.hashSet.Contains(name)) { if (string.IsNullOrEmpty(this.fileName)) { ImageBuilderUtility.TraceAndThrowValidationError( TraceType, StringResources.ImageBuilderError_DuplicateElementFound, this.elementName, this.propertyName, name); } else { ImageBuilderUtility.TraceAndThrowValidationErrorWithFileName( TraceType, this.fileName, StringResources.ImageBuilderError_DuplicateElementFound, this.elementName, this.propertyName, name); } } this.hashSet.Add(name); }
private void ValidateLevelFilter(string value, string source, string destination, string elementName) { if (value == null) { return; } if (!this.ShouldValidate(value)) { return; } ETWTraceLevel etwTraceLevel; if (!Enum.TryParse(value, true, out etwTraceLevel)) { ImageBuilderUtility.TraceAndThrowValidationError( TraceType, StringResources.ImageBuilderError_DiagnosticValidator_InvalidETWLevel, value, ETWTraceLevel.Error, ETWTraceLevel.Warning, ETWTraceLevel.Informational, ETWTraceLevel.Verbose, source, (destination != null) ? destination : String.Empty, elementName); } }
private static void ThrowInvalidCodeUpgradeFileName(string fileName) { ImageBuilderUtility.TraceAndThrowValidationError( FabricErrorCode.ImageBuilderInvalidMsiFile, TraceType, StringResources.ImageBuilderError_InvalidMSIFileName, fileName); }
private void VerifySourceLocation(string settingName, string sectionName, string type) { if (!ImageBuilderUtility.Equals("PlainText", type) && !ImageBuilderUtility.Equals("Encrypted", type) && !ImageBuilderUtility.Equals("SecretsStoreRef", type)) { ImageBuilderUtility.TraceAndThrowValidationError( TraceType, StringResources.ImageBuilderError_ConfigOverrideTypeMismatch, settingName, "Type", sectionName, type, "PlainText/Encrypted/SecretsStoreRef"); } }
private void ValidateRelativePath(string value, string source, string destination, string elementName) { if (value == null) { return; } if (!this.ShouldValidate(value)) { return; } if (Path.IsPathRooted(value)) { ImageBuilderUtility.TraceAndThrowValidationError( TraceType, StringResources.ImageBuilderError_DiagnosticValidator_AbsolutePathNotAllowed, value, source, (destination != null) ? destination : String.Empty, elementName); } string remainingPath = value; while (!String.IsNullOrEmpty(remainingPath)) { string pathPart = Path.GetFileName(remainingPath); if (pathPart.Equals(StringConstants.DoubleDot, StringComparison.Ordinal)) { ImageBuilderUtility.TraceAndThrowValidationError( TraceType, StringResources.ImageBuilderError_DiagnosticValidator_InvalidRelativePath, value, source, (destination != null) ? destination : String.Empty, elementName); } remainingPath = FabricPath.GetDirectoryName(remainingPath); } }
private static void ValidateXCopyPackageAndGetVersion(string packagePath, out string codeVersion) { foreach (string childFolder in ChildFoldersInXcopyPackage) { string newPath = Path.Combine(packagePath, childFolder); if (!FabricDirectory.Exists(newPath)) { ImageBuilderUtility.TraceAndThrowValidationError( FabricProvisionOperation.TraceType, StringResources.ImageStoreError_ChildFolderDoesNotExist_Formatted, childFolder, packagePath); } } codeVersion = "0.0.0.0"; var fabricExeCollection = FabricDirectory.GetFiles(packagePath, "fabric.exe", true, SearchOption.AllDirectories); if (fabricExeCollection.Count() == 0) { ImageBuilderUtility.TraceAndThrowValidationError( FabricProvisionOperation.TraceType, StringResources.ImageStoreError_FabricExeNotFound); } // Build number in version might have leading 0's i.e. 3.0.00123.0 // This causes issues during download, hence trimming the leading 0's #if DotNetCoreClrLinux var versionString = FileVersionInfo.GetVersionInfo(fabricExeCollection.First()).ProductVersion; #else var versionString = FabricFile.GetVersionInfo(fabricExeCollection.First()); #endif Version productVersion = null; if (!Version.TryParse(versionString, out productVersion)) { ImageBuilderUtility.TraceAndThrowValidationError( FabricProvisionOperation.TraceType, StringResources.ImageStoreError_InvalidProductVersion, versionString); } codeVersion = productVersion.ToString(); }
internal static void ValidateRelativePath(string path, string[] reservedDirectoryNames = null) { if (Path.IsPathRooted(path.TrimStart('\\'))) { ImageBuilderUtility.TraceAndThrowValidationError( TraceType, StringResources.ImageBuilderError_AbsolutePathNotAllowed, path); } string remainingPath = path; while (!string.IsNullOrEmpty(remainingPath)) { string pathPart = Path.GetFileName(remainingPath); if (pathPart.Equals(StringConstants.DoubleDot, StringComparison.Ordinal)) { ImageBuilderUtility.TraceAndThrowValidationError( TraceType, StringResources.ImageBuilderError_InvalidRelativePath, path); } remainingPath = FabricPath.GetDirectoryName(remainingPath); if (string.IsNullOrEmpty(remainingPath) && reservedDirectoryNames != null && reservedDirectoryNames.Count() > 0) { foreach (string directoryName in reservedDirectoryNames) { if (string.Compare(directoryName, pathPart, true) == 0) { ImageBuilderUtility.TraceAndThrowReservedDirectoryError( TraceType, StringResources.ImageBuilderError_ReservedDirectoryName, path, pathPart); } } } } }
private static string GetProductVersionLinux(string codePath) { var packageManagerType = FabricEnvironment.GetLinuxPackageManagerType(); switch (packageManagerType) { case LinuxPackageManagerType.Deb: return(GetProductVersionFromFilename(codePath, StringConstants.Deb)); case LinuxPackageManagerType.Rpm: return(GetProductVersionFromFilename(codePath, StringConstants.Rpm)); default: ImageBuilderUtility.TraceAndThrowValidationError( TraceType, StringResources.ImageBuilderError_LinuxPackageManagerUnknown, (int)packageManagerType); return(null); // To please compiler } }
public static bool IsInstaller(string codePackagePath) { #if DotNetCoreClrLinux var packageManagerType = FabricEnvironment.GetLinuxPackageManagerType(); switch (packageManagerType) { case LinuxPackageManagerType.Deb: return(Path.GetExtension(codePackagePath) == ".deb"); case LinuxPackageManagerType.Rpm: return(Path.GetExtension(codePackagePath) == ".rpm"); default: ImageBuilderUtility.TraceAndThrowValidationError( TraceType, StringResources.ImageBuilderError_LinuxPackageManagerUnknown, (int)packageManagerType); return(false); // To please compiler } #else return(Path.GetExtension(codePackagePath) == ".msi"); #endif }
private void ValidateServiceManifestDiagnostics(ServiceManifestType serviceManifestType) { if ((null == serviceManifestType.Diagnostics) || (null == serviceManifestType.Diagnostics.ETW) || (null == serviceManifestType.Diagnostics.ETW.ManifestDataPackages)) { return; } DataPackageType[] dataPackageTypes = serviceManifestType.Diagnostics.ETW.ManifestDataPackages; foreach (DataPackageType dataPackageType in dataPackageTypes) { Version version; if (!Version.TryParse(dataPackageType.Version, out version)) { ImageBuilderUtility.TraceAndThrowValidationError( TraceType, StringResources.ImageBuilderError_DiagnosticValidator_InvalidETWManifestDataPackageVersion, dataPackageType.Version, dataPackageType.Name, serviceManifestType.Name); } } }
public void UpgradeFabric( string currentFabricVersion, string targetFabricVersion, #if !DotNetCoreClrLinux && !DotNetCoreClrIOT string configurationCsvFilePath, #endif TimeSpan timeout, out bool isConfigOnly) { isConfigOnly = false; TimeoutHelper timeoutHelper = new TimeoutHelper(timeout); ImageBuilder.TraceSource.WriteInfo( TraceType, "UpgradeFabric started: CurrentFabricVersion:{0}, TargetFabricVersion:{1}, Timeout:{2}", currentFabricVersion, targetFabricVersion, timeoutHelper.GetRemainingTime()); // If the current version is invalid (ie. Cluster FabricVersion is not determined) // then do not validate if (ImageBuilderUtility.Equals(currentFabricVersion, FabricVersion.Invalid.ToString())) { return; } FabricVersion currentVersion, targetVersion; bool isValid = FabricVersion.TryParse(currentFabricVersion, out currentVersion); if (!isValid) { ImageBuilderUtility.TraceAndThrowValidationError( TraceType, StringResources.ImageBuilderError_InvalidValue, "CurrentFabricVersion", currentFabricVersion); } isValid = FabricVersion.TryParse(targetFabricVersion, out targetVersion); if (!isValid) { ImageBuilderUtility.TraceAndThrowValidationError( TraceType, StringResources.ImageBuilderError_InvalidValue, "TargetFabricVersion", targetFabricVersion); } WinFabStoreLayoutSpecification winFabLayout = WinFabStoreLayoutSpecification.Create(); string currentClusterManifestPath = winFabLayout.GetClusterManifestFile(currentVersion.ConfigVersion); string targetClusterManifestPath = winFabLayout.GetClusterManifestFile(targetVersion.ConfigVersion); ClusterManifestType currentClusterManifest = this.imageStoreWrapper.GetFromStore <ClusterManifestType>(currentClusterManifestPath, timeoutHelper.GetRemainingTime()); ClusterManifestType targetClusterManifest = this.imageStoreWrapper.GetFromStore <ClusterManifestType>(targetClusterManifestPath, timeoutHelper.GetRemainingTime()); timeoutHelper.ThrowIfExpired(); try { // todo: Vaishnav to pass node list object loaded from the location FabricValidator fabricValidator = FabricValidator.Create(currentClusterManifest, null, new WindowsFabricSettings(currentClusterManifest), DeploymentOperations.Update); IEnumerable <KeyValuePair <string, string> > modifiedStaticSettings = fabricValidator.CompareAndAnalyze(targetClusterManifest, null /*Detect changes for any NodeType*/); isConfigOnly = !modifiedStaticSettings.Any(); } catch (Exception e) { ImageBuilderUtility.TraceAndThrowValidationError( TraceType, StringResources.ImageBuilderError_InvalidConfigFabricUpgrade, e.ToString(), currentFabricVersion, targetFabricVersion); } ImageBuilder.TraceSource.WriteInfo( TraceType, "UpgradeFabric completed: CurrentFabricVersion:{0}, TargetFabricVersion:{1}, ConfigOnly:{2}", currentFabricVersion, targetFabricVersion, isConfigOnly); }
private void ValidateFileStoreAccessInformation(FileStoreType fileStore, string source) { if (String.IsNullOrEmpty(fileStore.AccountType)) { if ((this.ShouldValidate(fileStore.AccountName)) && (!String.IsNullOrEmpty(fileStore.AccountName))) { ImageBuilderUtility.TraceAndThrowValidationError( TraceType, StringResources.ImageBuilderError_DiagnosticValidator_AttributeInvalid, AccountName, AccountType, source, FileStore); } if ((this.ShouldValidate(fileStore.Password)) && (!String.IsNullOrEmpty(fileStore.Password))) { ImageBuilderUtility.TraceAndThrowValidationError( TraceType, StringResources.ImageBuilderError_DiagnosticValidator_AttributeInvalid, Password, AccountType, source, FileStore); } if ((this.ShouldValidate(fileStore.PasswordEncrypted)) && (!String.IsNullOrEmpty(fileStore.PasswordEncrypted))) { ImageBuilderUtility.TraceAndThrowValidationError( TraceType, StringResources.ImageBuilderError_DiagnosticValidator_AttributeInvalid, PasswordEncrypted, AccountType, source, FileStore); } return; } if (!this.ShouldValidate(fileStore.AccountType)) { return; } FileStoreAccessAccountType accountType; if (!Enum.TryParse(fileStore.AccountType, out accountType)) { ImageBuilderUtility.TraceAndThrowValidationError( TraceType, StringResources.ImageBuilderError_DiagnosticValidator_InvalidAccountType, fileStore.AccountType, FileStoreAccessAccountType.DomainUser, FileStoreAccessAccountType.ManagedServiceAccount, source, FileStore, AccountType); } switch (accountType) { case FileStoreAccessAccountType.DomainUser: { ValidateDomainUser(fileStore, source); } break; case FileStoreAccessAccountType.ManagedServiceAccount: { ValidateManagedServiceAccount(fileStore, source); } break; } }
internal static string ValidateSfpkgDownloadPathAndGetFileName(string sfpkgPath) { Uri uri; if (!Uri.TryCreate(sfpkgPath, UriKind.Absolute, out uri)) { ImageBuilderUtility.TraceAndThrowValidationError( TraceType, StringResources.Error_InvalidApplicationPackageDownloadUri, sfpkgPath); } if (string.IsNullOrEmpty(uri.Scheme)) { ImageBuilderUtility.TraceAndThrowValidationError( TraceType, StringResources.Error_InvalidApplicationPackageDownloadUri, sfpkgPath); } string protocol = uri.Scheme.ToLowerInvariant(); if (protocol != "http" && protocol != "https") { ImageBuilderUtility.TraceAndThrowValidationError( TraceType, StringResources.Error_InvalidApplicationPackageDownloadUri_Protocol, sfpkgPath, protocol); } var segments = uri.Segments; if (segments.Length == 0) { ImageBuilderUtility.TraceAndThrowValidationError( TraceType, StringResources.Error_InvalidApplicationPackageDownloadUri, sfpkgPath); } var fileName = segments[segments.Length - 1]; if (!fileName.EndsWith(StringConstants.SfpkgExtension)) { ImageBuilderUtility.TraceAndThrowValidationError( TraceType, StringResources.Error_InvalidApplicationPackageDownloadUri_FileName, sfpkgPath, fileName); } if (!ImageBuilderUtility.IsValidFileName(fileName)) { ImageBuilderUtility.TraceAndThrowValidationError( TraceType, StringResources.Error_InvalidApplicationPackageDownloadUri_FileName, sfpkgPath); } return(fileName); }
public void ProvisionFabric( string localCodePath, string localConfigPath, #if !DotNetCoreClrLinux && !DotNetCoreClrIOT string configurationCsvFilePath, #endif string infrastructureManifestFilePath, bool validateOnly, TimeSpan timeout) { TimeoutHelper timeoutHelper = new TimeoutHelper(timeout); #if DotNetCoreClrLinux || DotNetCoreClrIOT ImageBuilder.TraceSource.WriteInfo( TraceType, "Starting ProvisionFabric. CodePath:{0}, ConfigPath:{1}, InfrastructureManifestFilePath:{2}, Timeout:{3}", localCodePath, localConfigPath, infrastructureManifestFilePath, timeoutHelper.GetRemainingTime()); #else ImageBuilder.TraceSource.WriteInfo( TraceType, "Starting ProvisionFabric. CodePath:{0}, ConfigPath:{1}, ConfigurationCsvFilePath:{2}, InfrastructureManifestFilePath:{3}, Timeout:{4}", localCodePath, localConfigPath, configurationCsvFilePath, infrastructureManifestFilePath, timeoutHelper.GetRemainingTime()); #endif // TODO: Once FabricTest has been modified to generate InfrastructureManifest.xml file, we should not // allow InfrastructureManifest file to be optional if (string.IsNullOrEmpty(infrastructureManifestFilePath) || !FabricFile.Exists(infrastructureManifestFilePath)) { infrastructureManifestFilePath = null; ImageBuilder.TraceSource.WriteWarning( TraceType, "The InfrastrucutreManifestFile:{0} is not found", infrastructureManifestFilePath); } string codeVersion = string.Empty, clusterManifestVersion = string.Empty; if (!string.IsNullOrEmpty(localCodePath)) { codeVersion = GetCodeVersion(localCodePath); } if (!string.IsNullOrEmpty(localConfigPath)) { try { var parameters = new Dictionary <string, dynamic> { { DeploymentParameters.ClusterManifestString, localConfigPath }, { DeploymentParameters.InfrastructureManifestString, infrastructureManifestFilePath } }; var deploymentParameters = new DeploymentParameters(); deploymentParameters.SetParameters(parameters, DeploymentOperations.ValidateClusterManifest); DeploymentOperation.ExecuteOperation(deploymentParameters); } catch (Exception e) { ImageBuilderUtility.TraceAndThrowValidationError( FabricProvisionOperation.TraceType, StringResources.ImageBuilderError_ClusterManifestValidationFailed, e.ToString(), localConfigPath); } } if (!validateOnly) { timeoutHelper.ThrowIfExpired(); WinFabStoreLayoutSpecification winFabLayout = WinFabStoreLayoutSpecification.Create(); if (!string.IsNullOrEmpty(localCodePath)) { // Upload MSP file string destinationCodePath; if (ImageBuilderUtility.IsInstaller(localCodePath)) { destinationCodePath = winFabLayout.GetPatchFile(codeVersion); } else if (ImageBuilderUtility.IsCabFile(localCodePath)) { // Upload CAB file destinationCodePath = winFabLayout.GetCabPatchFile(codeVersion); } else { destinationCodePath = winFabLayout.GetCodePackageFolder(codeVersion); } this.imageStoreWrapper.UploadContent(destinationCodePath, localCodePath, timeoutHelper.GetRemainingTime()); } ClusterManifestType clusterManifest = null; if (!string.IsNullOrEmpty(localConfigPath)) { clusterManifest = ImageBuilderUtility.ReadXml <ClusterManifestType>(localConfigPath, this.validatingXmlReaderSettings); clusterManifestVersion = clusterManifest.Version; } if (clusterManifest != null) { // Upload ClusterManifest file ReplaceDefaultImageStoreConnectionString(clusterManifest); string destinationConfigPath = winFabLayout.GetClusterManifestFile(clusterManifestVersion); imageStoreWrapper.SetToStore <ClusterManifestType>(destinationConfigPath, clusterManifest, timeoutHelper.GetRemainingTime()); } } #if DotNetCoreClrLinux || DotNetCoreClrIOT ImageBuilder.TraceSource.WriteInfo( TraceType, "Completed ProvisionFabric. CodePath:{0}, ConfigPath:{1}", localCodePath, localConfigPath); #else ImageBuilder.TraceSource.WriteInfo( TraceType, "Completed ProvisionFabric. CodePath:{0}, ConfigPath:{1}, ConfigurationCsvFilePath:{2}", localCodePath, localConfigPath, configurationCsvFilePath); #endif }