public string GetClusterSettingsFilePath() { string clusterSettingsFilePath = null; string newAdminConfigPath = Environment.GetEnvironmentVariable(EnvironmentAdminConfigPath); if (!string.IsNullOrEmpty(newAdminConfigPath)) { clusterSettingsFilePath = newAdminConfigPath; } else { string fabricDataPath = System.Fabric.FabricDeployer.Utility.GetFabricDataRoot(); if (fabricDataPath != null) { string filePath = Path.Combine(fabricDataPath, DMConstants.ClusterSettingsFileName); if (File.Exists(filePath)) { clusterSettingsFilePath = filePath; } } } if (string.IsNullOrEmpty(clusterSettingsFilePath)) { clusterSettingsFilePath = StandaloneUtility.FindFabricResourceFile(DMConstants.ClusterSettingsFileName); } return(clusterSettingsFilePath); }
private void SetGeneratorSettings() { string wrpSettingsPath = StandaloneUtility.FindFabricResourceFile(DMConstants.WrpSettingsFilename); SettingsType wrpSettings = System.Fabric.Interop.Utility.ReadXml <SettingsType>(wrpSettingsPath); this.ClusterManifestGeneratorSettings = GenerateSettings(wrpSettings, this.Topology); }
public FabricSettingsMetadata GetFabricSettingsMetadata() { //// Extract Configuration if (this.fabricSettingsMetadata2 == null) { string fabricSettingFilePath = StandaloneUtility.FindFabricResourceFile(DMConstants.ConfigurationsFileName); this.fabricSettingsMetadata2 = FabricSettingsMetadata.Create(fabricSettingFilePath); } return(this.fabricSettingsMetadata2); }
internal static async Task <bool> DownloadPackageAsync(string targetPackageVersion, string packageDownloadUriStr, string packageLocalDownloadFilePath) { Uri downloadUri = null; bool result = false; string packageDropDir = Path.GetDirectoryName(packageLocalDownloadFilePath); if (string.IsNullOrEmpty(packageDownloadUriStr)) { SFDeployerTrace.WriteError("Download URI was empty for {0}", targetPackageVersion); return(false); } if (!Uri.TryCreate(packageDownloadUriStr, UriKind.Absolute, out downloadUri)) { SFDeployerTrace.WriteError("Cannot parse uri {0}", packageDownloadUriStr); return(false); } if (!(await StandaloneUtility.IsUriReachableAsync(downloadUri).ConfigureAwait(false))) { SFDeployerTrace.WriteError("Cannot reach download uri for CAB: {0}", downloadUri.AbsoluteUri); return(false); } if (!Directory.Exists(packageDropDir)) { Directory.CreateDirectory(packageDropDir); } try { SFDeployerTrace.WriteInfo("Package {0} downloading to: {1}", targetPackageVersion, packageLocalDownloadFilePath); await StandaloneUtility.DownloadFileAsync(downloadUri, packageLocalDownloadFilePath).ConfigureAwait(false); } catch (Exception ex) { SFDeployerTrace.WriteError("Package {0} download threw: {1}", targetPackageVersion, ex.ToString()); result = false; } if (File.Exists(packageLocalDownloadFilePath)) { SFDeployerTrace.WriteInfo("Package {0} downloaded: {1}", targetPackageVersion, packageLocalDownloadFilePath); result = true; } else { SFDeployerTrace.WriteError("Package {0} failed to download: {1}", targetPackageVersion, packageLocalDownloadFilePath); result = false; } return(result); }
internal static bool EnoughAvailableSpaceOnDrive(string rootDrive) { if (StandaloneUtility.DriveFreeBytes(rootDrive, out ulong availableSpace)) { return(availableSpace >= DMConstants.DriveMinAvailableSpace); } else { SFDeployerTrace.WriteError(StringResources.Error_CouldNotQuerySpaceOnDrive, rootDrive); return(false); } }
internal static async Task <RuntimePackageDetails> ValidateCodeVersionAsync(string targetCodeVersion) { RuntimePackageDetails targetCodePackage = null; if (targetCodeVersion == DMConstants.AutoupgradeCodeVersion) { try { targetCodePackage = DeploymentManager.GetDownloadableRuntimeVersions(DownloadableRuntimeVersionReturnSet.Latest).First <RuntimePackageDetails>(); } catch (Exception ex) { SFDeployerTrace.WriteError( "Failed trying to get latest downloadable versions for auto upgrade version. Exception: {0}", ex); } } else { var currentCodeVersion = await StandaloneUtility.GetCurrentCodeVersion().ConfigureAwait(false); var upgradeableVersions = new List <RuntimePackageDetails>(); try { upgradeableVersions = DeploymentManager.GetUpgradeableRuntimeVersions(currentCodeVersion); } catch (Exception ex) { SFDeployerTrace.WriteError( "Failed trying to load upgradeableVersions for the given version. Exception: {0}", ex); return(null); } targetCodePackage = upgradeableVersions.SingleOrDefault(version => version.Version.Equals(targetCodeVersion)); if (targetCodePackage == null) { // Todo: If no upgradeable version is found, checks for all supported versions. // Need to change this to check for only supported downgradable versions once the goal state file is modified. var allSupportedVersions = DeploymentManager.GetDownloadableRuntimeVersions(); if (allSupportedVersions != null && allSupportedVersions.Any(version => version.Version.Equals(targetCodeVersion))) { targetCodePackage = allSupportedVersions.SingleOrDefault(version => version.Version.Equals(targetCodeVersion)); } } } return(targetCodePackage); }
public StandaloneAdminConfig(string configurationsFilePath = null, bool isUserSet = false) { //// Extract Configuration string fabricSettingFilePath = string.IsNullOrEmpty(configurationsFilePath) ? StandaloneUtility.FindFabricResourceFile(DMConstants.ConfigurationsFileName) : configurationsFilePath; this.fabricSettingsMetadata = FabricSettingsMetadata.Create(fabricSettingFilePath); string clusterSettingsFilePath = this.GetClusterSettingsFilePath(); // Extract Cluster Settings // ReSharper disable once AssignNullToNotNullAttribute - fabric Code Path cannot be null here. this.Version = new AdminConfigVersion("Baseline", "Baseline"); this.standAloneClusterManifestSettings = JsonConvert.DeserializeObject <StandAloneClusterManifestSettings>( File.ReadAllText(clusterSettingsFilePath)); this.IsUserSet = isUserSet; }
internal static int IOTDevicesCount(IEnumerable <string> machineNames) { int numOfIOTCores = 0; object countLock = new object(); Parallel.ForEach( machineNames, (string machineName) => { if (StandaloneUtility.IsIOTCore(machineName)) { lock (countLock) { numOfIOTCores++; } } }); return(numOfIOTCores); }
internal static async Task <string> DownloadCodeVersionAsync(string codeVersion) { var targetPackage = await StandaloneUtility.ValidateCodeVersionAsync(codeVersion); if (targetPackage == null) { throw new FabricException(string.Format("Failed to validate code version {0}", codeVersion)); } string packageDropDir = Helpers.GetNewTempPath(); string packageLocalDownloadPath = Path.Combine(packageDropDir, string.Format(DMConstants.SFPackageDropNameFormat, targetPackage.Version)); bool result = await StandaloneUtility.DownloadPackageAsync(targetPackage.Version, targetPackage.TargetPackageLocation, packageLocalDownloadPath).ConfigureAwait(false); if (!result) { throw new FabricException(string.Format("Failed to download package from {0}", targetPackage.TargetPackageLocation)); } return(packageLocalDownloadPath); }
internal static string GetGoalStateUri() { string goalStateUriStr = null; /* Test code relies on the settings present in ClusterSettings.json for deployment of a specific version. * We need this check for the test code because certain APIs will be invoked before the cluster is even up. */ string clusterSettingsFilepath = StandaloneUtility.FindFabricResourceFile(DMConstants.ClusterSettingsFileName); if (!string.IsNullOrEmpty(clusterSettingsFilepath)) { StandAloneClusterManifestSettings standAloneClusterManifestSettings = JsonConvert.DeserializeObject <StandAloneClusterManifestSettings>(File.ReadAllText(clusterSettingsFilepath)); if (standAloneClusterManifestSettings.CommonClusterSettings != null && standAloneClusterManifestSettings.CommonClusterSettings.Section != null) { SettingsTypeSection settings = standAloneClusterManifestSettings.CommonClusterSettings.Section.ToList().SingleOrDefault( section => section.Name == DMConstants.UpgradeOrchestrationServiceConfigSectionName); if (settings != null) { SettingsTypeSectionParameter goalStatePathParam = settings.Parameter.ToList().SingleOrDefault(param => param.Name == DMConstants.GoalStateFileUrlName); if (goalStatePathParam != null) { goalStateUriStr = goalStatePathParam.Value; } } } } // Check the native config store before using default location. The GoalStateFileUrl may have been overridden by the user. if (string.IsNullOrEmpty(goalStateUriStr)) { NativeConfigStore configStore = NativeConfigStore.FabricGetConfigStore(); goalStateUriStr = configStore.ReadUnencryptedString(DMConstants.UpgradeOrchestrationServiceConfigSectionName, DMConstants.GoalStateFileUrlName); } if (string.IsNullOrEmpty(goalStateUriStr)) { goalStateUriStr = DMConstants.DefaultGoalStateFileUrl; } return(goalStateUriStr); }
public override string GetNextClusterManifestVersion() { return(StandaloneUtility.GetNextClusterManifestVersionHelper(this.ClusterResource, this.TraceLogger, "StandAloneCertificateClusterUpgradeState")); }
public static FileInfo GetClusterManifestFromJsonConfig(string clusterConfigPath, string clusterName, string version) { var clusterResource = DeploymentManagerInternal.GetClusterResource(clusterConfigPath, System.Guid.NewGuid().ToString()); return(StandaloneUtility.ClusterManifestToFile(clusterResource.Current.ExternalState.ClusterManifest, clusterName, version)); }