public async Task <string> ProcessSetUpgradeOrchestrationServiceStateAsync(string inputBlob, TimeSpan timeout, CancellationToken cancellationToken) { UpgradeOrchestrationTrace.TraceSource.WriteInfo(TraceType, "Entering ProcessSetUpgradeOrchestrationServiceStateAsync."); try { // data validation StandAloneCluster cluster = null; if (!string.IsNullOrWhiteSpace(inputBlob)) { JsonSerializerSettings settings = StandaloneUtility.GetStandAloneClusterDeserializerSettings(); cluster = JsonConvert.DeserializeObject <StandAloneCluster>( inputBlob, settings); } await this.storeManager.SetStorageObjectAsync(Constants.ClusterReliableDictionaryKey, inputBlob, this.cancellationToken).ConfigureAwait(false); FabricUpgradeOrchestrationServiceState result = UpgradeOrchestrationMessageProcessor.ConstructServiceStateFromCluster(cluster); return(JsonConvert.SerializeObject( result, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Serialize, NullValueHandling = NullValueHandling.Ignore, })); } catch (Exception e) { UpgradeOrchestrationTrace.TraceSource.WriteWarning(TraceType, "ProcessSetUpgradeOrchestrationServiceStateAsync exception: {0}", e); throw UpgradeOrchestrationMessageProcessor.ConvertToComException(e); } }
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)); }
internal static StandAloneCluster DeserializeClusterResource(string str) { StandAloneCluster result; JsonSerializerSettings settings = StandaloneUtility.GetStandAloneClusterDeserializerSettings(); try { result = JsonConvert.DeserializeObject <StandAloneCluster>(str, settings); isVersionChangedFrom5To6 = false; } catch (JsonSerializationException ex) { UpgradeOrchestrationTrace.TraceSource.WriteWarning(TraceType, "GetClusterResourceAsync: Deserialization error. Error is {0}. Will begin best-effort attempt.", ex.ToString()); var normalizedString = NormalizeClusterResource(str, Assembly.GetExecutingAssembly().GetName().Version.ToString()); result = JsonConvert.DeserializeObject <StandAloneCluster>(normalizedString, settings); isVersionChangedFrom5To6 = true; UpgradeOrchestrationTrace.TraceSource.WriteInfo(TraceType, "GetClusterResourceAsync: Deserialization succeeds after best-effort normalization."); } result.PersistedClusterString = str; return(result); }