internal void LoadSettings(NativeConfigStore nativeConfig) { this.DSTSDnsName = nativeConfig.ReadUnencryptedString(DSTSSectionName, DSTSDnsNameKey); this.DSTSRealm = nativeConfig.ReadUnencryptedString(DSTSSectionName, DSTSRealmKey); this.ServiceDnsName = nativeConfig.ReadUnencryptedString(DSTSSectionName, TVSServiceDnsNameKey); this.ServiceName = nativeConfig.ReadUnencryptedString(DSTSSectionName, ServiceNameKey); this.TokenValidationServiceType = nativeConfig.ReadUnencryptedString(DSTSSectionName, TokenValidationServiceTypeKey); }
public StandAloneFabricSettingsActivator(string clusterId) { this.clusterId = clusterId; if (currentConfigStore != null) { this.currentPrimaryAccountNtlmPassword = currentConfigStore.ReadUnencryptedString(StringConstants.SectionName.FileStoreService, StringConstants.ParameterName.PrimaryAccountNtlmPasswordSecret); this.currentSecondaryAccountNtlmPassword = currentConfigStore.ReadUnencryptedString(StringConstants.SectionName.FileStoreService, StringConstants.ParameterName.SecondaryAccountNtlmPasswordSecret); this.currentCommonNameNtlmPassword = currentConfigStore.ReadUnencryptedString(StringConstants.SectionName.FileStoreService, StringConstants.ParameterName.CommonNameNtlmPasswordSecret); } }
private SecuritySetting() { this.configStore = NativeConfigStore.FabricGetConfigStore(this); string serverAuthCredentialTypeName = configStore.ReadUnencryptedString(SecurityConfigSectionName, ServerAuthCredentialTypeName); CredentialType serverAuthCredentialType = CredentialType.None; if ((!string.IsNullOrEmpty(serverAuthCredentialTypeName)) && (!Enum.TryParse <CredentialType>(serverAuthCredentialTypeName, out serverAuthCredentialType))) { EventStoreLogger.Logger.LogWarning( "Unable to convert configuration value serverAuthCredentialTypeName {0} for {1} type.", serverAuthCredentialTypeName, serverAuthCredentialType); } this.ServerAuthCredentialType = serverAuthCredentialType; if (ServerAuthCredentialType == CredentialType.X509) { this.EndpointProtocol = EndpointProtocol.Https; } else { this.EndpointProtocol = EndpointProtocol.Http; } this.AllowedClientCertThumbprints = null; this.AllowedClientIdentities = null; this.AllowedClientCertCommonNames = null; this.InitializeFromConfig(); }
private bool IsPackageNearExpiry(PackageDetails currentPackage) { bool isNearExpiry = false; NativeConfigStore configStore = NativeConfigStore.FabricGetConfigStore(); string goalStateExpirationReminderInDaysString = configStore.ReadUnencryptedString(DMConstants.UpgradeOrchestrationServiceConfigSectionName, DMConstants.GoalStateExpirationReminderInDays); uint goalStateExpirationReminderInDays; if (string.IsNullOrEmpty(goalStateExpirationReminderInDaysString) || !uint.TryParse(goalStateExpirationReminderInDaysString, out goalStateExpirationReminderInDays)) { this.traceSource.WriteInfo( TraceType, "goalStateExpirationReminderInDays value invalid: \"{0}\". Defaulting to {1}.", goalStateExpirationReminderInDaysString, DMConstants.DefaultGoalStateExpirationReminderInDays); goalStateExpirationReminderInDays = DMConstants.DefaultGoalStateExpirationReminderInDays; } if (currentPackage != null && currentPackage.SupportExpiryDate != null) { isNearExpiry = (currentPackage.SupportExpiryDate - DateTime.UtcNow).Value.TotalDays < goalStateExpirationReminderInDays; } return(isNearExpiry); }
private static string GetReplicatorAddress() { NativeConfigStore configStore = System.Fabric.Common.NativeConfigStore.FabricGetConfigStore(); string replicatorAddress = configStore.ReadUnencryptedString("FabricNode", "UpgradeServiceReplicatorAddress"); return(replicatorAddress); }
private void UpdateTimers() { try { NativeConfigStore configStore = NativeConfigStore.FabricGetConfigStore(); string goalStateFetchIntervalInSecondsString = configStore.ReadUnencryptedString(DMConstants.UpgradeOrchestrationServiceConfigSectionName, DMConstants.GoalStateFetchIntervalInSecondsName); int goalStateFetchIntervalInSeconds; if (string.IsNullOrEmpty(goalStateFetchIntervalInSecondsString) || !int.TryParse(goalStateFetchIntervalInSecondsString, out goalStateFetchIntervalInSeconds)) { this.traceSource.WriteInfo( TraceType, "goalStateFetchIntervalInSeconds value invalid: \"{0}\". Defaulting to {1}.", goalStateFetchIntervalInSecondsString, DMConstants.DefaultGoalStateFetchIntervalInSeconds); goalStateFetchIntervalInSeconds = DMConstants.DefaultGoalStateFetchIntervalInSeconds; } this.timerInterval = TimeSpan.FromSeconds(goalStateFetchIntervalInSeconds); string goalStateProvisioningTimeOfDayString = configStore.ReadUnencryptedString(DMConstants.UpgradeOrchestrationServiceConfigSectionName, DMConstants.GoalStateProvisioningTimeOfDayName); TimeSpan goalStateProvisioningTimeOfDay; if (string.IsNullOrEmpty(goalStateProvisioningTimeOfDayString) || !TimeSpan.TryParse(goalStateProvisioningTimeOfDayString, out goalStateProvisioningTimeOfDay)) { this.traceSource.WriteInfo( TraceType, "goalStateProvisioningTimeOfDay value invalid: \"{0}\". Defaulting to {1}.", goalStateProvisioningTimeOfDayString, DMConstants.DefaultProvisioningTimeOfDay); goalStateProvisioningTimeOfDay = DMConstants.DefaultProvisioningTimeOfDay; } this.provisioningTimeOfDay = goalStateProvisioningTimeOfDay; this.traceSource.WriteInfo( TraceType, "Timers set to: TimerInterval: {0}, ProvisioningTimeOfDay: {1}.", this.timerInterval.ToString(), this.provisioningTimeOfDay.ToString()); } catch (Exception ex) { this.traceSource.WriteError(TraceType, "UpdateTimers threw {0}", ex.ToString()); throw; } }
public static bool GetValue(NativeConfigStore configStore) { ThrowIf.Null(configStore, "configStore"); string value = configStore.ReadUnencryptedString("Common", "EnableEndpointV2"); bool flag = string.IsNullOrEmpty(value) ? false : bool.Parse(value); return(flag); }
private Task InitClusterAnalysisEngineAsync(FabricClient fabricClient, NativeConfigStore configStore, CancellationToken cancellationToken) { #if DotNetCoreClr TestabilityTrace.TraceSource.WriteInfo(FaultAnalysisServiceTraceType, "Skipping Cluster Analysis in .Net Core environment"); return(Task.FromResult(true)); #else string clusterAnalysisEnabledAsString = configStore.ReadUnencryptedString(FASConstants.FaultAnalysisServiceConfigSectionName, ClusterAnalysisEnabledConfig); if (string.IsNullOrWhiteSpace(clusterAnalysisEnabledAsString)) { TestabilityTrace.TraceSource.WriteWarning(FaultAnalysisServiceTraceType, "ClusterAnalysisEnabled feature Flag is Null/Empty. Skipping Cluster Analysis."); return(Task.FromResult(true)); } bool clusterAnalysisEnabled = false; if (!bool.TryParse(clusterAnalysisEnabledAsString, out clusterAnalysisEnabled)) { TestabilityTrace.TraceSource.WriteInfo(FaultAnalysisServiceTraceType, "ClusterAnalysisConfig : {0} Couldn't be parsed. Skipping Cluster Analysis.", clusterAnalysisEnabledAsString); clusterAnalysisEnabled = false; } if (!clusterAnalysisEnabled) { TestabilityTrace.TraceSource.WriteInfo(FaultAnalysisServiceTraceType, "Cluster Anaysis Feature Status is Disabled"); return(Task.FromResult(true)); } TestabilityTrace.TraceSource.WriteInfo(FaultAnalysisServiceTraceType, "Launching Cluster Analysis"); this.clusterAnalysisApiHandler = new System.Fabric.FaultAnalysis.Service.ClusterAnalysis.ClusterAnalysisApiHandler(this.StateManager, fabricClient, cancellationToken); try { return(this.clusterAnalysisApiHandler.InternalLaunchAsync(cancellationToken)); } catch (Exception e) { TestabilityTrace.TraceSource.WriteError(FaultAnalysisServiceTraceType, "Exception Launching Cluster Analysis " + e); throw; } #endif }
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); }
internal void LoadSettings(NativeConfigStore nativeConfig) { this.LinuxProxyImageName = nativeConfig.ReadUnencryptedString(this.GRMSectionName, LinuxProxyImageNameKey); this.WindowsProxyImageName = nativeConfig.ReadUnencryptedString(this.GRMSectionName, WindowsProxyImageNameKey); this.ProxyReplicaCount = nativeConfig.ReadUnencryptedString(this.GRMSectionName, ProxyReplicaCountKey); this.ImageStoreConnectionString = nativeConfig.ReadUnencryptedString("Management", ImageStoreConnectionStringKey); this.IPProviderEnabled = nativeConfig.ReadUnencryptedBool("Hosting", IPProviderEnabledKey, GatewayResourceManagerTrace.TraceSource, Program.TraceType, false); this.LocalNatIPProviderEnabled = nativeConfig.ReadUnencryptedBool("Hosting", LocalNatIPProviderEnabledKey, GatewayResourceManagerTrace.TraceSource, Program.TraceType, false); this.IsolatedNetworkSetup = nativeConfig.ReadUnencryptedBool("Setup", IsolatedNetworkSetupKey, GatewayResourceManagerTrace.TraceSource, Program.TraceType, false); this.ContainerNetworkSetup = nativeConfig.ReadUnencryptedBool("Setup", ContainerNetworkSetupKey, GatewayResourceManagerTrace.TraceSource, Program.TraceType, false); var proxyCPUCores = nativeConfig.ReadUnencryptedString(this.GRMSectionName, ProxyCPUCoresKey); this.ProxyCPUCores = string.IsNullOrEmpty(proxyCPUCores) ? ProxyCPUCoresDefault : proxyCPUCores; var proxyCreateToReadyTimeoutInMinutes = nativeConfig.ReadUnencryptedString(this.GRMSectionName, ProxyCreateToReadyTimeoutInMinutesKey); this.ProxyCreateToReadyTimeoutInMinutes = string.IsNullOrEmpty(proxyCreateToReadyTimeoutInMinutes) ? ProxyCreateToReadyTimeoutInMinutesDefault : TimeSpan.FromMinutes(int.Parse(proxyCreateToReadyTimeoutInMinutes)); try { this.ClientCertThumbprints = nativeConfig.ReadUnencryptedString("Security", ClientCertThumbprintsKey); } catch (Exception) { this.ClientCertThumbprints = string.Empty; } try { this.ClusterCertThumbprints = nativeConfig.ReadUnencryptedString("Security", ClusterCertThumbprintsKey); } catch (Exception) { this.ClusterCertThumbprints = string.Empty; } }
private async Task PollGoalStateForCodePackagesAsync(CancellationToken cancellationToken) { var fabricClient = new FabricClient(); //// region: Initialization Parameters FabricUpgradeProgress upgradeProgress; try { upgradeProgress = await FabricClientRetryHelper.ExecuteFabricActionWithRetryAsync <FabricUpgradeProgress>( () => fabricClient.ClusterManager.GetFabricUpgradeProgressAsync(TimeSpan.FromMinutes(DMConstants.FabricOperationTimeoutInMinutes), cancellationToken), TimeSpan.FromMinutes(DMConstants.FabricOperationTimeoutInMinutes), cancellationToken).ConfigureAwait(false); } catch (Exception ex) { this.traceSource.WriteError(TraceType, "GetFabricUpgradeProgressAsync threw: {0}", ex.ToString()); this.timerInterval = TimeSpan.FromMinutes(DMConstants.FabricUpgradeStatePollIntervalInMinutes); return; } if (!FabricClientWrapper.IsUpgradeCompleted(upgradeProgress.UpgradeState)) { this.timerInterval = TimeSpan.FromMinutes(DMConstants.FabricUpgradeStatePollIntervalInMinutes); this.traceSource.WriteInfo(TraceType, "Cannot retrieve cluster version; FabricUpgradeState is currently: {0}. Will retry in {1}.", upgradeProgress.UpgradeState.ToString(), this.timerInterval.ToString()); return; } string currentVersionStr = upgradeProgress.TargetCodeVersion; Version currentVersion = Version.Parse(currentVersionStr); string packageDropDir = System.Fabric.Common.Helpers.GetNewTempPath(); NativeConfigStore configStore = NativeConfigStore.FabricGetConfigStore(); string goalStateUriStr = configStore.ReadUnencryptedString(DMConstants.UpgradeOrchestrationServiceConfigSectionName, DMConstants.GoalStateFileUrlName); if (string.IsNullOrEmpty(goalStateUriStr)) { goalStateUriStr = DMConstants.DefaultGoalStateFileUrl; } //// endregion this.traceSource.WriteInfo(TraceType, "PollCodePackagesFromGoalState currentVersion: {0}, packageDropDir: {1} goalStateUri: {2}", currentVersionStr, packageDropDir, goalStateUriStr); try { Uri goalStateUri = null; string goalStateJson = null; if (!Uri.TryCreate(goalStateUriStr, UriKind.Absolute, out goalStateUri)) { string errorMessage = string.Format("Cannot parse GoalStateUri: {0}", goalStateUriStr); this.traceSource.WriteError(TraceType, errorMessage); ReleaseAssert.Fail(errorMessage); return; } if (!(await StandaloneUtility.IsUriReachableAsync(goalStateUri).ConfigureAwait(false))) { this.timerInterval = TimeSpan.FromMinutes(DMConstants.FabricGoalStateReachablePollIntervalInMinutes); this.traceSource.WriteWarning(TraceType, "Cannot reach download uri for goal state file: {0}. Will retry in {1}.", goalStateUri.AbsoluteUri, this.timerInterval.ToString()); this.EmitGoalStateReachableHealth(fabricClient, false); return; } else { this.EmitGoalStateReachableHealth(fabricClient, true); } goalStateJson = await GoalStateModel.GetGoalStateFileJsonAsync(goalStateUri).ConfigureAwait(false); if (string.IsNullOrEmpty(goalStateJson)) { this.traceSource.WriteWarning(TraceType, "Loaded goal state JSON is empty."); return; } GoalStateModel model = GoalStateModel.GetGoalStateModelFromJson(goalStateJson); if (model == null || model.Packages == null) { this.traceSource.WriteWarning(TraceType, "Goal state JSON could not be deserialized:\n{0}", goalStateJson); return; } string availableGoalStateVersions = string.Format("Available versions in goal state file: {0}", model.ToString()); this.traceSource.WriteInfo(TraceType, availableGoalStateVersions); IEnumerable <PackageDetails> candidatePackages = model.Packages.Where( package => currentVersion < Version.Parse(package.Version)); if (candidatePackages.Count() == 0) { this.traceSource.WriteInfo(TraceType, "No upgrades available."); } string versionCurrentStr = currentVersionStr; Version versionCurrent = currentVersion; PackageDetails targetPackage = null; for (IEnumerable <PackageDetails> availableCandidatePackages = candidatePackages.Where( package => (package.MinVersion == null || Version.Parse(package.MinVersion) <= versionCurrent)); availableCandidatePackages.Count() > 0; versionCurrentStr = targetPackage.Version, versionCurrent = Version.Parse(versionCurrentStr), availableCandidatePackages = candidatePackages.Where( package => (versionCurrent < Version.Parse(package.Version) && (package.MinVersion == null || Version.Parse(package.MinVersion) <= versionCurrent)))) { if (!IsVersionUpgradeable(versionCurrentStr, model)) { this.traceSource.WriteInfo(TraceType, "Version {0} is not upgradeable.", versionCurrentStr); break; } int numPackages = availableCandidatePackages.Count(); if (numPackages == 0) { this.traceSource.WriteInfo(TraceType, "No upgrade available."); return; } else if (numPackages == 1) { targetPackage = availableCandidatePackages.First(); } else { Version maxVersion = StandaloneGoalStateProvisioner.ZeroVersion; foreach (PackageDetails package in availableCandidatePackages) { Version targetVersion; if (!Version.TryParse(package.Version, out targetVersion)) { this.traceSource.WriteWarning(TraceType, "Package {0} version could not be parsed. Trying another one.", package.Version); continue; } if (targetVersion > maxVersion) { targetPackage = package; maxVersion = targetVersion; } } } try { if (await this.IsPackageProvisionedAsync(targetPackage.Version, fabricClient, cancellationToken).ConfigureAwait(false)) { this.traceSource.WriteInfo(TraceType, "Package {0} is already provisioned.", targetPackage.Version); continue; } } catch (Exception ex) { this.traceSource.WriteError(TraceType, "PackageIsProvisioned for {0} threw: {1}", targetPackage.Version, ex.ToString()); } string packageLocalDownloadPath = Path.Combine(packageDropDir, string.Format(DMConstants.SFPackageDropNameFormat, targetPackage.Version)); if (await StandaloneUtility.DownloadPackageAsync(targetPackage.Version, targetPackage.TargetPackageLocation, packageLocalDownloadPath).ConfigureAwait(false)) { try { this.traceSource.WriteInfo(TraceType, "Copying and provisioning version {0} from {1}.", targetPackage.Version, packageLocalDownloadPath); await ProvisionPackageAsync(targetPackage.Version, packageLocalDownloadPath, cancellationToken).ConfigureAwait(false); } catch (Exception ex) { this.traceSource.WriteError(TraceType, "ProvisionPackageAsync for {0}, package {1} threw: {2}", targetPackage.Version, packageLocalDownloadPath, ex.ToString()); } } } // Determine if current version is latest/doesn't have expiry date. If package expiring, post cluster health warning. PackageDetails currentPackage = model.Packages.Where(package => package.Version == currentVersionStr).FirstOrDefault(); if (currentPackage != null && currentPackage.SupportExpiryDate != null && !currentPackage.IsGoalPackage && !this.IsAutoupgradeInstallEnabled() && this.IsPackageNearExpiry(currentPackage)) { this.traceSource.WriteWarning(TraceType, "Current version {0} expires {1}; emitting cluster warning.", currentVersionStr, currentPackage.SupportExpiryDate); this.EmitClusterVersionSupportedHealth(fabricClient, false, currentVersionStr, currentPackage.SupportExpiryDate); } else { this.traceSource.WriteInfo(TraceType, "Current version {0} is supported. Cluster health OK.", currentVersionStr); this.EmitClusterVersionSupportedHealth(fabricClient, true, null, null); } if (targetPackage != null && !string.IsNullOrEmpty(targetPackage.Version) && this.IsAutoupgradeInstallEnabled()) { try { // fire off an upgrade. this.StartCodeUpgrade(targetPackage.Version, fabricClient); } catch (Exception ex) { this.traceSource.WriteError(TraceType, "StartCodeUpgrade for version {0} threw: {1}", targetPackage.Version, ex.ToString()); } } } finally { if (Directory.Exists(packageDropDir)) { try { FabricDirectory.Delete(packageDropDir, true, true); } catch { } } } }