public async Task PersistCodeUpgradePackageDetailsAsync(string key, CodeUpgradeDetail packageDetails, CancellationToken cancellationToken) { UpgradeOrchestrationTrace.TraceSource.WriteInfo(TraceType, "Enter PersistCodeUpgradePackageDetailsAsync."); var clusterStateTable = await this.stateManager.GetOrAddAsync <IReliableDictionary <string, string> >(Constants.ClusterReliableDictionaryName); try { UpgradeOrchestrationTrace.TraceSource.WriteInfo(TraceType, "Serialize packageDetails into string format."); string packageDetailsString = JsonConvert.SerializeObject( packageDetails, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Serialize, NullValueHandling = NullValueHandling.Ignore, TypeNameHandling = TypeNameHandling.Objects, TypeNameAssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Full }); using (var tx = this.stateManager.CreateTransaction()) { ConditionalValue <string> existingData = await clusterStateTable.TryGetValueAsync(tx, key, Constants.DefaultDictionaryTimeout, cancellationToken).ConfigureAwait(false); if (existingData.HasValue) { bool success = await clusterStateTable.TryUpdateAsync( tx, key, packageDetailsString, existingData.Value).ConfigureAwait(false); if (!success) { UpgradeOrchestrationTrace.TraceSource.WriteWarning( TraceType, "SetStorageObjectAsync: PackageDetails data is not updated. The reason is {0}", string.Equals(packageDetailsString, existingData.Value, StringComparison.OrdinalIgnoreCase) ? "the value is not changed." : "to be investigated."); return; } } else { await clusterStateTable.AddAsync( tx, key, packageDetailsString, Constants.DefaultDictionaryTimeout, cancellationToken).ConfigureAwait(false); } await tx.CommitAsync().ConfigureAwait(false); } } catch (Exception e) { UpgradeOrchestrationTrace.TraceSource.WriteWarning(TraceType, "PersistCodeUpgradePackageDetailsAsync: {0}", e.ToString()); throw; } UpgradeOrchestrationTrace.TraceSource.WriteInfo(TraceType, "Exit PersistCodeUpgradePackageDetailsAsync."); }
private async Task UpdatePersistedCodeUpgradePackage(StandaloneSettingsValidator validator) { bool codeVersionChanged = await validator.IsCodeVersionChangedAsync(validator.ClusterProperties.CodeVersion).ConfigureAwait(false); if (!codeVersionChanged || validator.ClusterProperties.CodeVersion == DMConstants.AutoupgradeCodeVersion) { return; } UpgradeOrchestrationTrace.TraceSource.WriteInfo(TraceType, "Found a different version, updating persistence state with version: {0}", validator.ClusterProperties.CodeVersion); CodeUpgradeDetail packageDetails = new CodeUpgradeDetail() { CodeVersion = validator.ClusterProperties.CodeVersion, IsUserInitiated = true }; await this.storeManager.PersistCodeUpgradePackageDetailsAsync(Constants.CodeUpgradePackageDetails, packageDetails, this.cancellationToken); }
private async void StartCodeUpgrade(string targetCodeVersion, FabricClient fabricClient) { this.traceSource.WriteInfo(TraceType, "StartCodeUpgrade with target code version: {0}", targetCodeVersion); var clusterHealth = await fabricClient.HealthManager.GetClusterHealthAsync().ConfigureAwait(false); if (clusterHealth.AggregatedHealthState != HealthState.Ok) { this.traceSource.WriteInfo(TraceType, "Aggregate Health State: {0} is not OK. Skipping code upgrade with target code version: {1}", clusterHealth.AggregatedHealthState, targetCodeVersion); return; } this.traceSource.WriteInfo(TraceType, "Retrieve current cluster resource from StoreManager."); StandAloneCluster cluster = await this.storeManager.GetClusterResourceAsync( Constants.ClusterReliableDictionaryKey, this.cancellationToken).ConfigureAwait(false); if (cluster == null) { return; } if (cluster.TargetCsmConfig == null) { // use the current csm config if no targetcsmconfig exists cluster.TargetCsmConfig = cluster.Current.CSMConfig; } cluster.TargetCsmConfig.CodeVersion = targetCodeVersion; await this.storeManager.PersistClusterResourceAsync(Constants.ClusterReliableDictionaryKey, cluster, this.cancellationToken).ConfigureAwait(false); CodeUpgradeDetail packageDetails = new CodeUpgradeDetail() { CodeVersion = targetCodeVersion, IsUserInitiated = false }; await this.storeManager.PersistCodeUpgradePackageDetailsAsync(Constants.CodeUpgradePackageDetails, packageDetails, this.cancellationToken); this.traceSource.WriteInfo(TraceType, "Invoking Orchestrator.StartUpgradeAsync from GoalStateProvisioner"); await this.orchestrator.StartUpgradeAsync(cluster, this.cancellationToken, new Description.ConfigurationUpgradeDescription()); }
public async Task <CodeUpgradeDetail> GetCodeUpgradePackageDetailsAsync(string key, CancellationToken cancellationToken) { CodeUpgradeDetail codeUpgradePackageDetails = null; var clusterStateTable = await this.stateManager.GetOrAddAsync <IReliableDictionary <string, string> >(Constants.ClusterReliableDictionaryName); try { using (var tx = this.stateManager.CreateTransaction()) { UpgradeOrchestrationTrace.TraceSource.WriteInfo(TraceType, "Start transaction inside GetCodeUpgradePackageDetailsAsync."); var data = await clusterStateTable.TryGetValueAsync(tx, key, Constants.DefaultDictionaryTimeout, cancellationToken).ConfigureAwait(false); if (data.HasValue) { UpgradeOrchestrationTrace.TraceSource.WriteInfo(TraceType, "Found persisted codeUpgradePackageDetails. Deserializing it."); codeUpgradePackageDetails = JsonConvert.DeserializeObject <CodeUpgradeDetail>( data.Value, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Serialize, NullValueHandling = NullValueHandling.Ignore, TypeNameHandling = TypeNameHandling.Objects }); } } UpgradeOrchestrationTrace.TraceSource.WriteInfo(TraceType, "Exit transaction inside GetCodeUpgradePackageDetailsAsync."); } catch (Exception e) { UpgradeOrchestrationTrace.TraceSource.WriteWarning(TraceType, "GetCodeUpgradePackageDetailsAsync: {0}", e.ToString()); throw; } return(codeUpgradePackageDetails); }