protected internal async Task <List <BackupMappingModel> > GetBackupMappingsDetails(TimeSpan timeout, CancellationToken cancellationToken) { Task <List <BackupMappingModel> > serviceProtectionTask = null; Task <List <BackupMappingModel> > applicationProtectionTask = null; await this.PopulateApplicationServiceAndPartition(timeout, cancellationToken); if (this.FabricBackupResourceType == FabricBackupResourceType.PartitionUri) { BackupMappingModel partitionBackupMapping = await this.BackupMappingStore.GetValueAsync(this.FabricUri, timeout, cancellationToken); if (partitionBackupMapping != null) { return(new List <BackupMappingModel> { partitionBackupMapping }); } serviceProtectionTask = BackupMappingStore.GetProtectionForApplicationOrService(this.ApplicationName, this.ServiceName, timeout, cancellationToken); applicationProtectionTask = BackupMappingStore.GetProtectionForApplicationOrService(this.ApplicationName, null, timeout, cancellationToken); return(await serviceProtectionTask ?? await applicationProtectionTask); } else if (this.FabricBackupResourceType == FabricBackupResourceType.ServiceUri) { serviceProtectionTask = BackupMappingStore.GetAllProtectionForApplicationOrService(this.ApplicationName, this.ServiceName, timeout, cancellationToken); applicationProtectionTask = BackupMappingStore.GetProtectionForApplicationOrService(this.ApplicationName, null, timeout, cancellationToken); await Task.WhenAll(serviceProtectionTask, applicationProtectionTask); if (serviceProtectionTask.Result != null && applicationProtectionTask.Result != null) { return(serviceProtectionTask.Result.Concat(applicationProtectionTask.Result).ToList()); } else { return(applicationProtectionTask.Result ?? serviceProtectionTask.Result); } } else if (this.ApplicationName != null) { return (await BackupMappingStore.GetAllProtectionForApplicationOrService(this.ApplicationName, null, timeout, cancellationToken)); } else { throw new ArgumentException("Invalid Arguments."); } }
private async Task <List <BackupEntityConfigurationInfo> > GetOverriddenBackupConfigurationinfo(string applicationServiceNameUri, BackupSuspensionInfo inheritedBackupSuspensionInfo, TimeSpan timeout, CancellationToken cancellationToken, BRSContinuationToken brsContinuationToken, int maxResultsLocal = 0) { List <BackupEntityConfigurationInfo> backupConfigurationInfos = new List <BackupEntityConfigurationInfo>(); bool listSuspended = false; if (!String.IsNullOrEmpty(brsContinuationToken.IncomingContinuationToken)) { string[] array = brsContinuationToken.IncomingContinuationToken.Split(ContinuationTokenSeparatorChar); brsContinuationToken.IncomingContinuationToken = array[0]; if (array[1] == SuspendedContinuationToken) { // We need to check if we were listing suspended partitions previously or override. listSuspended = true; } } string continuationTokenForSuspendendPartitions = null; if (listSuspended) { // if we were listing overrides, then this continuationTokenForSuspendendPartitions should be null. continuationTokenForSuspendendPartitions = brsContinuationToken.IncomingContinuationToken; } var suspendStore = await SuspendStore.CreateOrGetSuspendStatusStore(this.StatefulService); List <string> suspendedEntities = await suspendStore.GetAllSuspensionWithFabricUri(applicationServiceNameUri, timeout, cancellationToken, continuationTokenForSuspendendPartitions); HashSet <string> suspendedEntitiesHashSet = new HashSet <string>(suspendedEntities); var overridesBackupMappings = await this.BackupMappingStore.GetAllProtectionWithFabricUri(applicationServiceNameUri, timeout, cancellationToken, brsContinuationToken.IncomingContinuationToken); string applicationNameUri = null; string serviceNameUri = null; string partitionId = null; int counter = 0; if (maxResultsLocal != 0) { // if maxResults is equal to zero, then we dont need to sort as we have already filtered the elements. overridesBackupMappings = overridesBackupMappings.OrderBy(backupMapping => backupMapping.ApplicationOrServiceUri).ToList(); } foreach (var overridesBackupMapping in overridesBackupMappings) { if (!applicationServiceNameUri.Equals(overridesBackupMapping.ApplicationOrServiceUri)) { BackupEntityConfigurationInfo backupConfigurationInfo = null; FabricBackupResourceType fabricBackupResourceType = UtilityHelper .GetApplicationAndServicePartitionUri( overridesBackupMapping.ApplicationOrServiceUri, out applicationNameUri, out serviceNameUri, out partitionId); BackupSuspensionInfo backupSuspensionInfo = inheritedBackupSuspensionInfo; switch (fabricBackupResourceType) { case FabricBackupResourceType.PartitionUri: if (suspendedEntitiesHashSet.Contains(overridesBackupMapping.ApplicationOrServiceUri)) { backupSuspensionInfo = new BackupSuspensionInfo(BackupEntityKind.Partition, true); suspendedEntitiesHashSet.Remove(overridesBackupMapping.ApplicationOrServiceUri); } if (listSuspended) { continue; } backupConfigurationInfo = new PartitionBackupConfigurationInfo(serviceNameUri, partitionId, overridesBackupMapping.BackupPolicyName, BackupEntityKind.Partition, backupSuspensionInfo); break; case FabricBackupResourceType.ServiceUri: if (suspendedEntitiesHashSet.Contains(overridesBackupMapping.ApplicationOrServiceUri)) { backupSuspensionInfo = new BackupSuspensionInfo(BackupEntityKind.Service, true); suspendedEntitiesHashSet.Remove(overridesBackupMapping.ApplicationOrServiceUri); } if (listSuspended) { continue; } backupConfigurationInfo = new ServiceBackupConfigurationInfo(serviceNameUri, overridesBackupMapping.BackupPolicyName, BackupEntityKind.Service, backupSuspensionInfo); break; case FabricBackupResourceType.ApplicationUri: if (suspendedEntitiesHashSet.Contains(overridesBackupMapping.ApplicationOrServiceUri)) { backupSuspensionInfo = new BackupSuspensionInfo(BackupEntityKind.Application, true); suspendedEntitiesHashSet.Remove(overridesBackupMapping.ApplicationOrServiceUri); } if (listSuspended) { continue; } backupConfigurationInfo = new ApplicationBackupConfigurationInfo(applicationNameUri, overridesBackupMapping.BackupPolicyName, BackupEntityKind.Application, backupSuspensionInfo); break; } if (backupConfigurationInfo != null) { backupConfigurationInfos.Add(backupConfigurationInfo); counter++; if (maxResultsLocal != 0 && counter == maxResultsLocal) { if (counter < overridesBackupMappings.Count || suspendedEntitiesHashSet.Count > 0) { // we need to check if there are more elements to be listed or not. brsContinuationToken.OutgoingContinuationToken = overridesBackupMapping.ApplicationOrServiceUri + ContinuationTokenSeparatorChar + OverrideContinuationToken; } return(backupConfigurationInfos); } } } } suspendedEntitiesHashSet.Remove(applicationServiceNameUri); foreach (var leftSuspendUri in suspendedEntitiesHashSet) { if (maxResultsLocal != 0) { // if maxResults is equal to zero, then we dont need to sort as we have already filtered the elements. suspendedEntitiesHashSet.ToList().Sort(); } FabricBackupResourceType leftSuspendUriType = UtilityHelper .GetApplicationAndServicePartitionUri( leftSuspendUri, out applicationNameUri, out serviceNameUri, out partitionId); BackupEntityConfigurationInfo backupConfigurationInfo = null; BackupMappingModel backupMapping = null; BackupEntityKind backupEntityKind = BackupEntityKind.Invalid; switch (leftSuspendUriType) { case FabricBackupResourceType.PartitionUri: backupMapping = await this.BackupMappingStore.GetValueAsync(serviceNameUri); backupEntityKind = backupMapping != null ? BackupEntityKind.Service : BackupEntityKind.Invalid; backupMapping = await this.BackupMappingStore.GetValueAsync(applicationNameUri); backupEntityKind = backupMapping != null ? BackupEntityKind.Application : BackupEntityKind.Invalid; backupConfigurationInfo = new PartitionBackupConfigurationInfo(serviceNameUri, partitionId, backupMapping.BackupPolicyName, backupEntityKind, new BackupSuspensionInfo(BackupEntityKind.Partition, true)); break; case FabricBackupResourceType.ServiceUri: backupMapping = await this.BackupMappingStore.GetValueAsync(applicationNameUri); backupEntityKind = backupMapping != null ? BackupEntityKind.Application : BackupEntityKind.Invalid; backupConfigurationInfo = new ServiceBackupConfigurationInfo(serviceNameUri, backupMapping.BackupPolicyName, backupEntityKind, new BackupSuspensionInfo(BackupEntityKind.Service, true)); break; case FabricBackupResourceType.ApplicationUri: backupMapping = await this.BackupMappingStore.GetValueAsync(applicationNameUri); backupEntityKind = backupMapping != null ? BackupEntityKind.Application : BackupEntityKind.Invalid; backupConfigurationInfo = new ApplicationBackupConfigurationInfo(applicationNameUri, backupMapping.BackupPolicyName, backupEntityKind, new BackupSuspensionInfo(BackupEntityKind.Application, true)); break; } if (backupMapping != null && backupEntityKind != BackupEntityKind.Invalid) { backupConfigurationInfos.Add(backupConfigurationInfo); counter++; if (maxResultsLocal != 0 && counter == maxResultsLocal) { if (counter < suspendedEntitiesHashSet.Count) { // we need to check if there are more elements to be listed or not. brsContinuationToken.OutgoingContinuationToken = leftSuspendUri + ContinuationTokenSeparatorChar + SuspendedContinuationToken; } break; } } } return(backupConfigurationInfos); }