private static StatefulServiceBase ReadConfiguration(StatefulServiceContext context) { GatewayResourceManagerTrace.TraceSource.WriteInfo(TraceType, "ReadConfiguration"); System.Fabric.Common.NativeConfigStore configStore = System.Fabric.Common.NativeConfigStore.FabricGetConfigStore(); string fabricGatewayResourceManagerReplicatorAddress = configStore.ReadUnencryptedString("FabricNode", "GatewayResourceManagerReplicatorAddress"); return(new FabricGatewayResourceManager(context, fabricGatewayResourceManagerReplicatorAddress)); }
private static StatefulServiceBase ReadConfiguration(StatefulServiceContext context) { System.Fabric.Common.NativeConfigStore configStore = System.Fabric.Common.NativeConfigStore.FabricGetConfigStore(); string faultAnalysisServiceReplicatorAddress = configStore.ReadUnencryptedString("FabricNode", "FaultAnalysisServiceReplicatorAddress"); bool flag = EnableEndpointV2Utility.GetValue(configStore); return(new FaultAnalysisService(context, faultAnalysisServiceReplicatorAddress, flag)); }
private static StatefulServiceBase ReadConfiguration(StatefulServiceContext context) { UpgradeOrchestrationTrace.TraceSource.WriteInfo(TraceType, "ReadConfiguration"); System.Fabric.Common.NativeConfigStore configStore = System.Fabric.Common.NativeConfigStore.FabricGetConfigStore(); string fabricUpgradeOrchestrationServiceReplicatorAddress = configStore.ReadUnencryptedString("FabricNode", "UpgradeOrchestrationServiceReplicatorAddress"); bool flag = EnableEndpointV2Utility.GetValue(configStore); return(new FabricUpgradeOrchestrationService(context, fabricUpgradeOrchestrationServiceReplicatorAddress, flag)); }
public static NativeConfigStore FabricGetConfigStore(IConfigStoreUpdateHandler updateHandler) { NativeCommon.IFabricConfigStoreUpdateHandler nativeUpdateHandler = null; if (updateHandler != null) { nativeUpdateHandler = new ConfigStoreUpdateHandlerBroker(updateHandler); } return(Utility.WrapNativeSyncInvokeInMTA(() => NativeConfigStore.CreateHelper(nativeUpdateHandler), "NativeConfigStore.FabricGetConfigStore")); }
public FaultAnalysisServiceImpl() { System.Fabric.Common.NativeConfigStore configStore = System.Fabric.Common.NativeConfigStore.FabricGetConfigStore(); TestabilityTrace.TraceSource.WriteInfo(TraceType, "'{0}', '{1}'", FASConstants.FaultAnalysisServiceConfigSectionName, FASConstants.StopNodeMinDurationInSecondsName); string minStopDurationAsString = configStore.ReadUnencryptedString(FASConstants.FaultAnalysisServiceConfigSectionName, FASConstants.StopNodeMinDurationInSecondsName); this.minStopDurationInSeconds = string.IsNullOrEmpty(minStopDurationAsString) ? FASConstants.DefaultStopNodeMinDurationInSeconds : int.Parse(minStopDurationAsString); TestabilityTrace.TraceSource.WriteInfo(TraceType, "'{0}', '{1}', '{2}'", FASConstants.FaultAnalysisServiceConfigSectionName, FASConstants.StopNodeMinDurationInSecondsName, this.minStopDurationInSeconds); string maxStopDurationAsString = configStore.ReadUnencryptedString(FASConstants.FaultAnalysisServiceConfigSectionName, FASConstants.StopNodeMaxDurationInSecondsName); this.maxStopDurationInSeconds = string.IsNullOrEmpty(maxStopDurationAsString) ? FASConstants.DefaultStopNodeMaxDurationInSeconds : int.Parse(maxStopDurationAsString); TestabilityTrace.TraceSource.WriteInfo(TraceType, "'{0}', '{1}', '{2}'", FASConstants.FaultAnalysisServiceConfigSectionName, FASConstants.StopNodeMaxDurationInSecondsName, this.maxStopDurationInSeconds); }
public bool ReadUnencryptedBool(string sectionName, string keyName, FabricEvents.ExtensionsEvents traceSource, string traceType, bool throwIfInvalid) { NativeConfigStore configStore = NativeConfigStore.FabricGetConfigStore(); string propertyValueStr = configStore.ReadUnencryptedString(sectionName, keyName); bool propertyValue = false; traceSource.WriteInfo(traceType, "{0} {1}", keyName, propertyValueStr); if (!bool.TryParse(propertyValueStr, out propertyValue)) { string message = string.Format("{0} could not parse: {1}", keyName, propertyValueStr); traceSource.WriteError(traceType, message); if (throwIfInvalid) { throw new InvalidDataException(message); } else { propertyValue = false; } } return(propertyValue); }
private static StandAloneCluster InitClusterResource(FabricNativeConfigStore configStore) { UpgradeOrchestrationTrace.TraceSource.WriteInfo(TraceType, "Enter InitClusterResource"); string fabricDataRoot = FabricEnvironment.GetDataRoot(); string jsonConfigPath = Path.Combine(fabricDataRoot, Microsoft.ServiceFabric.DeploymentManager.Constants.BaselineJsonMetadataFileName); ReleaseAssert.AssertIf(!File.Exists(jsonConfigPath), "Baseline upgrade JsonClusterConfigMetadata not found at {0}.", jsonConfigPath); UpgradeOrchestrationTrace.TraceSource.WriteInfo(TraceType, "Deserializing Json config."); string jsonConfig = File.ReadAllText(jsonConfigPath); if (string.IsNullOrEmpty(jsonConfig)) { throw new FabricValidationException(StringResources.Error_SFJsonConfigInvalid, FabricErrorCode.OperationCanceled); } JsonSerializerSettings settings = StandaloneUtility.GetStandAloneClusterDeserializerSettings(); UpgradeOrchestrationTrace.TraceSource.WriteInfo(TraceType, "Exit InitClusterResource"); return(JsonConvert.DeserializeObject <StandAloneCluster>( jsonConfig, settings)); }
public static NativeConfigStore FabricGetConfigStore() { return(NativeConfigStore.FabricGetConfigStore(null)); }
public async Task ProcessStartClusterConfigurationUpgradeAsync(ConfigurationUpgradeDescription configUpgradeDesc, TimeSpan timeout, CancellationToken cancellationToken) { /* The cancellation token passed in this API call is not used (by design). This token corresponds to the client side call. * The global this.cancellationToken is initialised in RunAsync() and is honored in every API call. */ UpgradeOrchestrationTrace.TraceSource.WriteInfo(TraceType, "Entering ProcessStartUpgradeAsync."); try { UpgradeOrchestrationTrace.TraceSource.WriteInfo(TraceType, "Deserializing input json config string."); StandAloneInstallerJsonModelBase targetJsonConfig = StandAloneInstallerJsonModelBase.GetJsonConfigFromString(configUpgradeDesc.ClusterConfiguration); if (targetJsonConfig == null) { throw new ArgumentException("The input cluster configuration is not in a valid json format or supported apiVersion."); } UpgradeOrchestrationTrace.TraceSource.WriteInfo(TraceType, "Retrieve current cluster resource from StoreManager."); StandAloneCluster cluster = await this.storeManager.GetClusterResourceAsync( Constants.ClusterReliableDictionaryKey, this.cancellationToken).ConfigureAwait(false); bool isInDataLossState = await DatalossHelper.IsInDatalossStateAsync(this.cancellationToken).ConfigureAwait(false); if (!isInDataLossState) { if (cluster == null || cluster.Current == null) { UpgradeOrchestrationTrace.TraceSource.WriteWarning(TraceType, "Persisted cluster resource is not ready: {0}", cluster == null ? "null" : "current = null"); throw new FabricException("UpgradeOrchestrationService is not ready."); } UpgradeOrchestrationTrace.TraceSource.WriteInfo(TraceType, "Setting target config and topology based on new input json config."); if (cluster.Pending != null && !this.IsInterruptibleAsync(cluster.Pending).Result) { throw new FabricException(string.Format("Cluster configuration upgrade of type {0} is already in progress and cannot be interrupted.", cluster.Pending.GetType().Name)); } StandaloneSettingsValidator validator = new StandaloneSettingsValidator(targetJsonConfig); await UpgradeOrchestrationMessageProcessor.ValidateModel(targetJsonConfig, validator, cluster, true).ConfigureAwait(false); var removedNodes = validator.GetRemovedNodes(cluster.Topology); var addedNodes = validator.GetAddedNodes(cluster.Topology); if (addedNodes.Any() && StandaloneUtility.CheckFabricRunningAsGMSA(cluster.Current.CSMConfig)) { /* Need to resolve assembly so that FabricDeployer can load the right binaries from FabricCodePath since not all binaries required by FabricDeployer are present in UOS.Current folder.*/ AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(this.LoadFromFabricCodePath); try { await this.PerformAddNodeOperationGMSAAsync(addedNodes, this.fabricClient, validator.ClusterProperties.NodeTypes).ConfigureAwait(false); } catch (AggregateException ex) { UpgradeOrchestrationTrace.TraceSource.WriteError(TraceType, "Adding nodes for GMSA scenario failed with exception: {0}", ex); throw; } finally { AppDomain.CurrentDomain.AssemblyResolve -= new ResolveEventHandler(this.LoadFromFabricCodePath); } } if (addedNodes.Any()) { cluster.TargetNodeConfig = GetTargetNodeConfigAddNode(validator.Topology, cluster.Current.NodeConfig.Version); } if (removedNodes.Any()) { cluster.TargetNodeConfig = GetTargetNodeConfigRemoveNode(cluster.Topology, removedNodes, cluster.Current.NodeConfig.Version); } else { cluster.Topology = validator.Topology; } cluster.TargetCsmConfig = validator.ClusterProperties; // Cluster is updated above so persist it. await this.storeManager.PersistClusterResourceAsync(Constants.ClusterReliableDictionaryKey, cluster, cancellationToken).ConfigureAwait(false); await this.UpdatePersistedCodeUpgradePackage(validator).ConfigureAwait(false); UpgradeOrchestrationTrace.TraceSource.WriteInfo(TraceType, "Invoking Orchestrator"); await this.orchestrator.StartUpgradeAsync(cluster, this.cancellationToken, configUpgradeDesc).ContinueWith(t => { if (t.Exception != null) { UpgradeOrchestrationTrace.TraceSource.WriteWarning(TraceType, "Orchestrator completed with status: {0} exception: {1}", t.Status, t.Exception); } else { UpgradeOrchestrationTrace.TraceSource.WriteInfo(TraceType, "Orchestrator completed with status: {0}", t.Status); } }); } else { StandaloneSettingsValidator validator = new StandaloneSettingsValidator(targetJsonConfig); await UpgradeOrchestrationMessageProcessor.ValidateModel(targetJsonConfig, validator, cluster, false).ConfigureAwait(false); cluster = FabricUpgradeOrchestrationService.ConstructClusterFromJson(targetJsonConfig, FabricNativeConfigStore.FabricGetConfigStore()); DatalossHelper.DryRunConfigUpgrade(cluster); await this.storeManager.PersistClusterResourceAsync(Constants.ClusterReliableDictionaryKey, cluster, this.cancellationToken); await DatalossHelper.UpdateHeathStateAsync(isHealthy : true).ConfigureAwait(false); } } catch (Exception e) { UpgradeOrchestrationTrace.TraceSource.WriteWarning(TraceType, "ProcessStartUpgradeAsync exception: {0}", e); throw UpgradeOrchestrationMessageProcessor.ConvertToComException(e); } UpgradeOrchestrationTrace.TraceSource.WriteInfo(TraceType, "Exiting ProcessStartUpgradeAsync."); }
private async Task InitializeAsync(CancellationToken cancellationToken) { System.Fabric.Common.NativeConfigStore configStore = System.Fabric.Common.NativeConfigStore.FabricGetConfigStore(); string isTestModeEnabled = configStore.ReadUnencryptedString(FASConstants.FaultAnalysisServiceConfigSectionName, "TestModeEnabled"); if (isTestModeEnabled.ToLowerInvariant() == "true") { TestabilityTrace.TraceSource.WriteInfo(FaultAnalysisServiceTraceType, "Enabling internal test mode"); this.IsTestMode = true; } string apiTestModeString = configStore.ReadUnencryptedString(FASConstants.FaultAnalysisServiceConfigSectionName, "ApiTestMode"); int apiTestMode; if (!int.TryParse(apiTestModeString, out apiTestMode)) { apiTestMode = 0; } string requestTimeout = configStore.ReadUnencryptedString(FASConstants.FaultAnalysisServiceConfigSectionName, FASConstants.RequestTimeoutInSecondsName); int requestTimeoutInSecondsAsInt = string.IsNullOrEmpty(requestTimeout) ? FASConstants.DefaultRequestTimeoutInSeconds : int.Parse(requestTimeout); string operationTimeout = configStore.ReadUnencryptedString(FASConstants.FaultAnalysisServiceConfigSectionName, FASConstants.OperationTimeoutInSecondsName); int operationTimeoutInSecondsAsInt = string.IsNullOrEmpty(operationTimeout) ? FASConstants.DefaultOperationTimeoutInSeconds : int.Parse(operationTimeout); TestabilityTrace.TraceSource.WriteInfo( FaultAnalysisServiceTraceType, "Setting requestTimeout='{0}' and operationTimeout='{1}'", TimeSpan.FromSeconds(requestTimeoutInSecondsAsInt), TimeSpan.FromSeconds(operationTimeoutInSecondsAsInt)); string maxStoredActionCount = configStore.ReadUnencryptedString(FASConstants.FaultAnalysisServiceConfigSectionName, FASConstants.MaxStoredActionCountName); long maxStoredActionCountAsLong = string.IsNullOrEmpty(maxStoredActionCount) ? FASConstants.DefaultMaxStoredActionCount : long.Parse(maxStoredActionCount); string storedActionCleanupIntervalInSeconds = configStore.ReadUnencryptedString(FASConstants.FaultAnalysisServiceConfigSectionName, FASConstants.StoredActionCleanupIntervalInSecondsName); int storedActionCleanupIntervalInSecondsAsInt = string.IsNullOrEmpty(storedActionCleanupIntervalInSeconds) ? FASConstants.DefaultStoredActionCleanupIntervalInSeconds : int.Parse(storedActionCleanupIntervalInSeconds); string completedActionKeepDurationInSeconds = configStore.ReadUnencryptedString(FASConstants.FaultAnalysisServiceConfigSectionName, FASConstants.CompletedActionKeepDurationInSecondsName); int completedActionKeepDurationInSecondsAsInt = string.IsNullOrEmpty(completedActionKeepDurationInSeconds) ? FASConstants.DefaultCompletedActionKeepDurationInSeconds : int.Parse(completedActionKeepDurationInSeconds); TestabilityTrace.TraceSource.WriteInfo( FaultAnalysisServiceTraceType, "MaxStoredActionCount={0}, StoredActionCleanupIntervalInSeconds={1}, CompletedActionKeepDurationInSecondsName={2}", maxStoredActionCountAsLong, storedActionCleanupIntervalInSecondsAsInt, completedActionKeepDurationInSecondsAsInt); string commandStepRetryBackoffInSeconds = configStore.ReadUnencryptedString(FASConstants.FaultAnalysisServiceConfigSectionName, FASConstants.CommandStepRetryBackoffInSecondsName); int commandStepRetryBackoffInSecondsAsInt = string.IsNullOrEmpty(commandStepRetryBackoffInSeconds) ? FASConstants.DefaultCommandStepRetryBackoffInSeconds : int.Parse(commandStepRetryBackoffInSeconds); TestabilityTrace.TraceSource.WriteInfo(FaultAnalysisServiceTraceType, "Read from config commandStepRetryBackoffInSeconds='{0}'", commandStepRetryBackoffInSecondsAsInt); string concurrentRequestsAsString = configStore.ReadUnencryptedString(FASConstants.FaultAnalysisServiceConfigSectionName, FASConstants.ConcurrentRequestsName); int concurrentRequests = string.IsNullOrEmpty(concurrentRequestsAsString) ? FASConstants.DefaultConcurrentRequests : int.Parse(concurrentRequestsAsString); TestabilityTrace.TraceSource.WriteInfo(FaultAnalysisServiceTraceType, "Read from config concurrentRequests='{0}'", concurrentRequests); string dataLossCheckWaitDurationInSecondsAsString = configStore.ReadUnencryptedString(FASConstants.FaultAnalysisServiceConfigSectionName, FASConstants.DataLossCheckWaitDurationInSecondsName); int dataLossCheckWaitDurationInSeconds = string.IsNullOrEmpty(dataLossCheckWaitDurationInSecondsAsString) ? FASConstants.DefaultDataLossCheckWaitDurationInSeconds : int.Parse(dataLossCheckWaitDurationInSecondsAsString); TestabilityTrace.TraceSource.WriteInfo(FaultAnalysisServiceTraceType, "Read from config dataLossCheckWaitDurationInSeconds='{0}'", dataLossCheckWaitDurationInSeconds); string dataLossCheckPollIntervalInSecondsAsString = configStore.ReadUnencryptedString(FASConstants.FaultAnalysisServiceConfigSectionName, FASConstants.DataLossCheckPollIntervalInSecondsName); int dataLossCheckPollIntervalInSeconds = string.IsNullOrEmpty(dataLossCheckPollIntervalInSecondsAsString) ? FASConstants.DefaultDataLossCheckPollIntervalInSeconds : int.Parse(dataLossCheckPollIntervalInSecondsAsString); TestabilityTrace.TraceSource.WriteInfo(FaultAnalysisServiceTraceType, "Read from config dataLossCheckPollIntervalInSeconds='{0}'", dataLossCheckPollIntervalInSeconds); string replicaDropWaitDurationInSecondsAsString = configStore.ReadUnencryptedString(FASConstants.FaultAnalysisServiceConfigSectionName, FASConstants.ReplicaDropWaitDurationInSecondsName); int replicaDropWaitDurationInSeconds = string.IsNullOrEmpty(replicaDropWaitDurationInSecondsAsString) ? FASConstants.DefaultReplicaDropWaitDurationInSeconds : int.Parse(replicaDropWaitDurationInSecondsAsString); TestabilityTrace.TraceSource.WriteInfo(FaultAnalysisServiceTraceType, "Read from config replicaDropWaitDurationInSeconds='{0}'", replicaDropWaitDurationInSeconds); string chaosTelemetrySamplingProbabilityAsString = configStore.ReadUnencryptedString(FASConstants.FaultAnalysisServiceConfigSectionName, FASConstants.ChaosTelemetrySamplingProbabilityConfigKeyName); double chaosTelemetrySamplingProbability = string.IsNullOrEmpty(chaosTelemetrySamplingProbabilityAsString) ? FASConstants.DefaultChaosTelemetrySamplingProbability : double.Parse(chaosTelemetrySamplingProbabilityAsString); TestabilityTrace.TraceSource.WriteInfo(FaultAnalysisServiceTraceType, "Read from config chaosTelemetrySamplingProbability='{0}'", chaosTelemetrySamplingProbability); string chaosTelemetryReportPeriodInSecondsAsString = configStore.ReadUnencryptedString(FASConstants.FaultAnalysisServiceConfigSectionName, FASConstants.ChaostelemetryReportPeriodInSecondsConfigKeyName); int chaostelemetryReportPeriodInSeconds = string.IsNullOrEmpty(chaosTelemetryReportPeriodInSecondsAsString) ? FASConstants.DefaultTelemetryReportPeriodInSeconds : int.Parse(chaosTelemetryReportPeriodInSecondsAsString); TestabilityTrace.TraceSource.WriteInfo(FaultAnalysisServiceTraceType, "Read from config chaostelemetryReportPeriodInSeconds='{0}'", chaostelemetryReportPeriodInSeconds); TestabilityTrace.TraceSource.WriteInfo(FaultAnalysisServiceTraceType, "Creating action tables"); var actionTable = await this.StateManager.GetOrAddAsync <IReliableDictionary <Guid, byte[]> >(FASConstants.ActionReliableDictionaryName).ConfigureAwait(false); var historyTable = await this.StateManager.GetOrAddAsync <IReliableDictionary <Guid, byte[]> >(FASConstants.HistoryReliableDictionaryName).ConfigureAwait(false); var stoppedNodeTable = await this.StateManager.GetOrAddAsync <IReliableDictionary <string, bool> >(FASConstants.StoppedNodeTable); TestabilityTrace.TraceSource.WriteInfo(FaultAnalysisServiceTraceType, "Creating ActionStore"); this.actionStore = new ActionStore( this.StateManager, this.Partition, actionTable, historyTable, stoppedNodeTable, maxStoredActionCountAsLong, storedActionCleanupIntervalInSecondsAsInt, completedActionKeepDurationInSecondsAsInt, this.IsTestMode, cancellationToken); FabricClient fabricClient = new FabricClient(); this.engine = new ReliableFaultsEngine(this.actionStore, this.IsTestMode, this.Partition, commandStepRetryBackoffInSecondsAsInt); this.messageProcessor = new FaultAnalysisServiceMessageProcessor( this.Partition, fabricClient, this.engine, this.actionStore, this.StateManager, stoppedNodeTable, TimeSpan.FromSeconds(requestTimeoutInSecondsAsInt), TimeSpan.FromSeconds(operationTimeoutInSecondsAsInt), concurrentRequests, dataLossCheckWaitDurationInSeconds, dataLossCheckPollIntervalInSeconds, replicaDropWaitDurationInSeconds, cancellationToken); string maxStoredChaosEventCleanupIntervalInSeconds = configStore.ReadUnencryptedString(FASConstants.FaultAnalysisServiceConfigSectionName, FASConstants.StoredChaosEventCleanupIntervalInSecondsConfigName); int maxStoredChaosEventCleanupIntervalInSecondsAsInt = string.IsNullOrEmpty(maxStoredChaosEventCleanupIntervalInSeconds) ? FASConstants.StoredChaosEventCleanupIntervalInSecondsDefault : int.Parse(maxStoredChaosEventCleanupIntervalInSeconds); string maxStoredChaosEventCount = configStore.ReadUnencryptedString(FASConstants.FaultAnalysisServiceConfigSectionName, FASConstants.MaxStoredChaosEventCountConfigName); int maxStoredChaosEventCountAsInt = string.IsNullOrEmpty(maxStoredChaosEventCount) ? FASConstants.MaxStoredChaosEventCountDefault : int.Parse(maxStoredChaosEventCount); this.chaosMessageProcessor = new ChaosMessageProcessor( this.StateManager, apiTestMode, maxStoredChaosEventCleanupIntervalInSecondsAsInt, maxStoredChaosEventCountAsInt, chaosTelemetrySamplingProbability, chaostelemetryReportPeriodInSeconds, this.Partition, fabricClient, this.scheduler, cancellationToken); await this.messageProcessor.ResumePendingActionsAsync(fabricClient, cancellationToken).ConfigureAwait(false); this.faultAnalysisServiceImpl.MessageProcessor = this.messageProcessor; this.faultAnalysisServiceImpl.ChaosMessageProcessor = this.chaosMessageProcessor; this.faultAnalysisServiceImpl.LoadActionMapping(); await this.scheduler.InitializeAsync(fabricClient, this.chaosMessageProcessor, cancellationToken).ConfigureAwait(false); TestabilityTrace.TraceSource.WriteInfo(FaultAnalysisServiceTraceType, "Done initializing engine"); await this.InitClusterAnalysisEngineAsync(fabricClient, configStore, cancellationToken).ConfigureAwait(false); }
internal static StandAloneCluster ConstructClusterFromJson(StandAloneInstallerJsonModelBase jsonModel, FabricNativeConfigStore configStore) { UpgradeOrchestrationTrace.TraceSource.WriteInfo(TraceType, "Creating userconfig, cluster topology, adminconfig."); var userConfig = jsonModel.GetUserConfig(); var clusterTopology = jsonModel.GetClusterTopology(); var adminConfig = new StandaloneAdminConfig(); var logger = new StandAloneTraceLogger("StandAloneDeploymentManager"); UpgradeOrchestrationTrace.TraceSource.WriteInfo(TraceType, "Creating new StandAlone cluster resource."); var clusterId = configStore.ReadUnencryptedString(Constants.SectionName, Constants.ClusterIdParameterName); var clusterResource = new StandAloneCluster(adminConfig, userConfig, clusterTopology, clusterId, logger); return(clusterResource); }
protected override async Task RunAsync(CancellationToken cancellationToken) { UpgradeOrchestrationTrace.TraceSource.WriteInfo(TraceType, "Enter RunAsync"); try { var configStore = FabricNativeConfigStore.FabricGetConfigStore(); StandAloneFabricSettingsActivator.InitializeConfigStore(configStore); UpgradeOrchestrationTrace.TraceSource.WriteInfo(TraceType, "After InitializeAsync"); UpgradeOrchestrationTrace.TraceSource.WriteInfo(TraceType, "Getting cluster resource from store manager."); StandAloneCluster cluster = await this.storeManager.GetClusterResourceAsync(Constants.ClusterReliableDictionaryKey, cancellationToken).ConfigureAwait(false); bool isInDatalossState = await DatalossHelper.IsInDatalossStateAsync(cancellationToken).ConfigureAwait(false); if (!isInDatalossState) { bool isBaselineUpgrade = false; if (cluster == null) { // Cluster resource does not exist, e.g. first time baseline upgrade. UpgradeOrchestrationTrace.TraceSource.WriteInfo(TraceType, "Cluster resource does not exist in store manager. Initiating new clsuter resource."); cluster = FabricUpgradeOrchestrationService.InitClusterResource(configStore); ReleaseAssert.AssertIf(cluster == null, "Cluster Resource cannot be initialized."); isBaselineUpgrade = true; await this.CompleteAndPersistBaselineStateAsync(cluster, cancellationToken).ConfigureAwait(false); } UpgradeOrchestrationTrace.TraceSource.WriteInfo(TraceType, "Setting a valid cancellation token for UpgradeOrchestrationMessageProcessor"); this.messageProcessor.CancellationToken = cancellationToken; /* In version 5.7, we added Iron as a new entry to ReliabilityLevel enum. This entry was added as ReliabilityLevel = 1 and hence, it moved all the existing levels one level down. * For clusters created in <=5.6, when upgraded to 5.7+ the ReliabilityLevel field would be interpreted differently. The below code fixes this issue by reading the * UOS state and comparing it against the actual cluster state. If there is a mismatch it sets the UOS to the correct ReliabilityLevel. */ if (!isBaselineUpgrade && cluster.Current != null && cluster.Current.CSMConfig != null) { UpgradeOrchestrationTrace.TraceSource.WriteInfo(TraceType, "Current ReliabilityLevel set in UOS state {0}", cluster.Current.CSMConfig.ReliabilityLevel); var actualReliabilityLevelForCluster = await this.GetActualReliabilityLevelForCluster(cancellationToken).ConfigureAwait(false); UpgradeOrchestrationTrace.TraceSource.WriteInfo(TraceType, "Actual ReliabilityLevel set for the cluster {0}", actualReliabilityLevelForCluster); if (actualReliabilityLevelForCluster != cluster.Current.CSMConfig.ReliabilityLevel) { UpgradeOrchestrationTrace.TraceSource.WriteInfo(TraceType, "UOS ReliabilityLevel is inconsistent with actual reliability level for the cluster.. Setting UOS state to {0}", actualReliabilityLevelForCluster); cluster.Current.CSMConfig.ReliabilityLevel = actualReliabilityLevelForCluster; await this.storeManager.PersistClusterResourceAsync(Constants.ClusterReliableDictionaryKey, cluster, cancellationToken).ConfigureAwait(false); cluster = await this.storeManager.GetClusterResourceAsync(Constants.ClusterReliableDictionaryKey, cancellationToken).ConfigureAwait(false); UpgradeOrchestrationTrace.TraceSource.WriteInfo(TraceType, "UOS ReliabilityLevel set to {0}", cluster.Current.CSMConfig.ReliabilityLevel); } } /* This is a workaround till actual admin config upgrades are implemented. In 5.7 we changed some properties in ClusterSettings * but those will not take effect for clusters created with version < 5.7 since no upgrade reads those settings. * This workaround initiates a WRP config upgrade in the form of SimpleClusterUpgradeState if the settings found are old (after the code upgrade completes to this version). */ string isAdminConfigUpgradeAttempted = await this.storeManager.GetStorageObjectAsync(Constants.AdminConfigUpgradeAttemptedDictionaryKey, cancellationToken).ConfigureAwait(false); if (!isBaselineUpgrade && string.IsNullOrEmpty(isAdminConfigUpgradeAttempted) && this.IsFirewallRuleDisabled()) { UpgradeOrchestrationTrace.TraceSource.WriteInfo(TraceType, "Old admin configuration settings detected.. Will initiate admin config upgrade after code upgrade completes.."); bool isCurrentCodeUpgradeCompleted = false; while (!isCurrentCodeUpgradeCompleted) { isCurrentCodeUpgradeCompleted = await this.CheckCodeUpgradeCompletedAsync(cancellationToken).ConfigureAwait(false); await Task.Delay(TimeSpan.FromSeconds(10), cancellationToken).ConfigureAwait(false); } UpgradeOrchestrationTrace.TraceSource.WriteInfo(TraceType, "Setting targetWRPConfig to initiate admin config upgrade."); var adminConfig = new StandaloneAdminConfig(); adminConfig.Version.ClusterSettingsVersion = "2.1"; cluster.TargetWrpConfig = adminConfig; await this.storeManager.SetStorageObjectAsync(Constants.AdminConfigUpgradeAttemptedDictionaryKey, "true", cancellationToken).ConfigureAwait(false); } if (!isBaselineUpgrade) { // If the cluster manifest versions don't match, send a health warning for users to know. Task manifestCheck = this.SetupClusterManifestVersionCheck(cancellationToken, cluster.Current.ExternalState.ClusterManifest.Version); UpgradeOrchestrationTrace.TraceSource.WriteInfo(TraceType, "Invoking Orchestrator.StartUpgradeAsync"); Task t = this.Orchestrator.StartUpgradeAsync(cluster, cancellationToken, new ConfigurationUpgradeDescription()); } UpgradeOrchestrationTrace.TraceSource.WriteInfo(TraceType, "Done with Orchestrator.StartUpgradeAsync"); } var goalStateProvisioner = new StandaloneGoalStateProvisioner(this.storeManager, this.Orchestrator, cancellationToken); Task goalStatePollTask = (goalStateProvisioner.IsAutoupgradeEnabled() || goalStateProvisioner.IsAutoupgradeInstallEnabled()) ? goalStateProvisioner.SetUpGoalStatePoll(cancellationToken, this.IsSkipInitialGoalStateCheck()) : Task.Run( () => { goalStateProvisioner.EmitGoalStateReachableHealth(this.fabricClient, true /*success*/); goalStateProvisioner.EmitClusterVersionSupportedHealth(this.fabricClient, true /*success*/); }, cancellationToken); await Task.Delay(Timeout.Infinite, cancellationToken).ConfigureAwait(false); } catch (FabricNotPrimaryException ex) { UpgradeOrchestrationTrace.TraceSource.WriteError(TraceType, ex.ToString()); } catch (FabricObjectClosedException ocex) { UpgradeOrchestrationTrace.TraceSource.WriteError(TraceType, ocex.ToString()); } UpgradeOrchestrationTrace.TraceSource.WriteInfo(TraceType, "Exit RunAsync"); }