public async Task PersistClusterResourceAsync(string key, StandAloneCluster cluster, CancellationToken cancellationToken) { UpgradeOrchestrationTrace.TraceSource.WriteInfo(TraceType, "Enter PersistClusterResourceAsync."); var clusterStateTable = await this.stateManager.GetOrAddAsync <IReliableDictionary <string, string> >(Constants.ClusterReliableDictionaryName); try { UpgradeOrchestrationTrace.TraceSource.WriteInfo(TraceType, "Serialize cluster resource into string format."); string clusterString = JsonConvert.SerializeObject( cluster, StandaloneUtility.GetStandAloneClusterSerializerSettings()); using (var tx = this.stateManager.CreateTransaction()) { UpgradeOrchestrationTrace.TraceSource.WriteInfo(TraceType, "Enter transaction inside PersistClusterResourceAsync"); if (string.IsNullOrEmpty(cluster.PersistedClusterString)) { await clusterStateTable.AddAsync( tx, key, clusterString, Constants.DefaultDictionaryTimeout, cancellationToken).ConfigureAwait(false); } else { /* This is a workaround for scenarios where clusters were upgraded from 5.x->6.x. During deserealization, we change the version in UOSState from 5.0.0.0 to 6.0.0.0. This is needed for * newtonsoft deserealization to work with the new assembly versions. Here we revert 6.0.0.0 back to 5.0.0.0 before persisting it so that users can downgrade succesfully from 6.x -> 5.x * versions. Once 5.x is deprecated, we can remove this workaround and persist 6.0.0.0 in UOS state */ if (isVersionChangedFrom5To6) { clusterString = NormalizeClusterResource(clusterString, Version5); } bool success = await clusterStateTable.TryUpdateAsync( tx, key, clusterString, cluster.PersistedClusterString).ConfigureAwait(false); if (!success) { UpgradeOrchestrationTrace.TraceSource.WriteWarning( TraceType, "PersistClusterResourceAsync: StandAloneCluster data is not updated. The reason is {0}", string.Equals(clusterString, cluster.PersistedClusterString, StringComparison.OrdinalIgnoreCase) ? "the value is not changed." : "to be investigated."); return; } } await tx.CommitAsync().ConfigureAwait(false); } UpgradeOrchestrationTrace.TraceSource.WriteInfo(TraceType, "Exit transaction inside PersistClusterResourceAsync"); } catch (Exception e) { UpgradeOrchestrationTrace.TraceSource.WriteWarning(TraceType, "PersistClusterResourceAsync: {0}", e.ToString()); throw; } }