Exemplo n.º 1
0
        internal static async Task <bool> ValidateServiceUri(string serviceUri, TimeSpan timeout, CancellationToken cancellationToken)
        {
            var applicationUri = UtilityHelper.GetApplicationUriFromServiceUri(serviceUri);
            var serviceList    = await InvokeWithRetryAsync(() =>
                                                            FabricClient.QueryManager.GetServiceListAsync(new Uri(UtilityHelper.GetUriFromCustomUri(applicationUri)), new Uri(UtilityHelper.GetUriFromCustomUri(serviceUri)), timeout, cancellationToken)
                                                            );

            if (serviceList.Count == 0)
            {
                throw new FabricException(StringResources.ServiceNotFound,
                                          FabricErrorCode.ServiceNotFound);
            }

            if (serviceList?[0] != null && serviceList[0].ServiceKind == ServiceKind.Stateful && ((StatefulService)serviceList[0]).HasPersistedState)
            {
                return(true);
            }

            throw new FabricException(StringResources.InvalidForStatelessServices, FabricErrorCode.InvalidForStatelessServices);
        }
Exemplo n.º 2
0
 internal static async Task <ServiceList> GetServiceList(string applicationUri)
 {
     return(await InvokeWithRetryAsync <ServiceList>(() =>
                                                     FabricClient.QueryManager.GetServiceListAsync(new Uri(UtilityHelper.GetUriFromCustomUri(applicationUri)))
                                                     ));
 }
Exemplo n.º 3
0
        internal static async Task <bool> ValidateApplicationUri(string applicationUri, TimeSpan timeout, CancellationToken cancellationToken)
        {
            var serviceList = await InvokeWithRetryAsync <ServiceList>(() => FabricClient.QueryManager.GetServiceListAsync(new Uri(UtilityHelper.GetUriFromCustomUri(applicationUri)), null, timeout, cancellationToken));

            return(serviceList != null);
        }
Exemplo n.º 4
0
 internal static async Task InitiatePartitionDataLoss(Guid dataLossGuid, string serviceNameUri, string partitionId, TimeSpan timeout)
 {
     await InvokeWithRetryAsync(() =>
     {
         return(FabricClient.TestManager.StartPartitionDataLossAsync(dataLossGuid,
                                                                     PartitionSelector.PartitionIdOf(new Uri(UtilityHelper.GetUriFromCustomUri(serviceNameUri)), Guid.Parse(partitionId)), DataLossMode.PartialDataLoss));
     }
                                );
 }
 private async Task DisablePartitionBackup(CancellationToken cancellationToken)
 {
     await Program.ServiceAgent.DisableProtectionAsync(new Uri(UtilityHelper.GetUriFromCustomUri(this.ServiceUri)),
                                                       Guid.Parse(this.PartitionId),
                                                       BackupRestoreServiceConfig.ApiTimeout, cancellationToken);
 }
        private async Task <bool> IsPartitionBackupSuspended(StatefulService statefulService, string processQueueTypeTrace)
        {
            var suspendStore = await SuspendStore.CreateOrGetSuspendStatusStore(statefulService);

            var fabricKey          = UtilityHelper.GetBackupMappingKey(this.ServiceUri, this.PartitionId);
            var containsSuspension = await suspendStore.GetValueAsync(fabricKey) ?? await suspendStore.GetValueAsync(ServiceUri) ?? await suspendStore.GetValueAsync(UtilityHelper.GetApplicationUriFromServiceUri(ServiceUri));

            BackupRestoreTrace.TraceSource.WriteInfo(processQueueTypeTrace, "IsPartition Suspended {0}", containsSuspension != null);
            return(containsSuspension != null);
        }
        private BackupPolicyDataStructure GetBackupPolicyDataStructure(BackupPolicy backupPolicyModel, string serviceName, string partitionId)
        {
            BackupPolicyDataStructure backupPolicy;

            switch (backupPolicyModel.BackupSchedule.BackupScheduleType)
            {
            case BackupScheduleType.FrequencyBased:
                backupPolicy = new FrequencyBasedBackupPolicy();
                var frequencyBasedSchedulePolicy = (FrequencyBasedBackupSchedule)backupPolicyModel.BackupSchedule;
                backupPolicy.PolicyType = BackupPolicyType.FrequencyBased;
                var freqBackupPolicy = (FrequencyBasedBackupPolicy)backupPolicy;
                freqBackupPolicy.RunFrequency = (ushort)frequencyBasedSchedulePolicy.Interval;

                if (frequencyBasedSchedulePolicy.IntervalType == BackupScheduleInterval.Hours)
                {
                    freqBackupPolicy.RunFrequencyType = BackupPolicyRunFrequency.Hours;
                }

                if (frequencyBasedSchedulePolicy.IntervalType == BackupScheduleInterval.Minutes)
                {
                    freqBackupPolicy.RunFrequencyType = BackupPolicyRunFrequency.Minutes;
                }

                break;

            case BackupScheduleType.TimeBased:
                backupPolicy = new ScheduleBasedBackupPolicy();
                var scheduleBasedSchedulePolicy = (TimeBasedBackupSchedule)backupPolicyModel.BackupSchedule;
                backupPolicy.PolicyType = BackupPolicyType.ScheduleBased;

                var schdBackupPolicy = (ScheduleBasedBackupPolicy)backupPolicy;
                if (scheduleBasedSchedulePolicy.ScheduleFrequencyType == BackupScheduleFrequency.Daily)
                {
                    schdBackupPolicy.RunSchedule = BackupPolicyRunSchedule.Daily;
                }

                if (scheduleBasedSchedulePolicy.ScheduleFrequencyType == BackupScheduleFrequency.Weekly)
                {
                    schdBackupPolicy.RunSchedule = BackupPolicyRunSchedule.Weekly;
                }

                schdBackupPolicy.RunDays  = new List <DayOfWeek>(scheduleBasedSchedulePolicy.RunDays);
                schdBackupPolicy.RunTimes = new List <TimeSpan>(scheduleBasedSchedulePolicy.RunTimes);

                break;

            default:
                throw new FabricPeriodicBackupNotEnabledException();
            }

            backupPolicy.MaxIncrementalBackups = Convert.ToByte(backupPolicyModel.MaxIncrementalBackup);
            backupPolicy.Name     = backupPolicyModel.Name;
            backupPolicy.PolicyId = backupPolicyModel.UniqueId;

            switch (backupPolicyModel.Storage.BackupStorageType)
            {
            case BackupStorageType.FileShare:
                var fileShareStorage = (FileShareBackupStorageInfo)backupPolicyModel.Storage;
                backupPolicy.StoreInformation = new FileShareBackupStore
                {
                    AccessType          = String.IsNullOrEmpty(fileShareStorage.PrimaryUserName) ? FileShareAccessType.None : FileShareAccessType.DomainUser,
                    FileSharePath       = Path.Combine(fileShareStorage.Path, UtilityHelper.GetBaseDirectoryPathForPartition(serviceName, partitionId)),
                    PrimaryUserName     = fileShareStorage.PrimaryUserName,
                    PrimaryPassword     = fileShareStorage.PrimaryPassword,
                    SecondaryUserName   = fileShareStorage.SecondaryUserName,
                    SecondaryPassword   = fileShareStorage.SecondaryPassword,
                    IsPasswordEncrypted = fileShareStorage.IsPasswordEncrypted,
                };
                break;

            case BackupStorageType.AzureBlobStore:
                var azureStorage = (AzureBlobBackupStorageInfo)backupPolicyModel.Storage;
                backupPolicy.StoreInformation = new AzureBlobBackupStore
                {
                    ConnectionString      = azureStorage.ConnectionString,
                    ContainerName         = azureStorage.ContainerName,
                    FolderPath            = UtilityHelper.GetBaseDirectoryPathForPartition(serviceName, partitionId),             // TODO: This should be constructed
                    IsAccountKeyEncrypted = azureStorage.IsConnectionStringEncrypted,
                };
                break;

            case BackupStorageType.DsmsAzureBlobStore:
                var dsmsAzureStorage = (DsmsAzureBlobBackupStorageInfo)backupPolicyModel.Storage;
                backupPolicy.StoreInformation = new DsmsAzureBlobBackupStore
                {
                    StorageCredentialsSourceLocation = dsmsAzureStorage.StorageCredentialsSourceLocation,
                    ContainerName = dsmsAzureStorage.ContainerName,
                    FolderPath    = UtilityHelper.GetBaseDirectoryPathForPartition(serviceName, partitionId),                     // TODO: This should be constructed
                };
                break;
            }

            return(backupPolicy);
        }
Exemplo n.º 8
0
        private void PopulateApplicationServiceAndPartitionInfo(RestorePoint recoveryPoint, string metadataFile)
        {
            var tokens       = metadataFile.Split('\\');
            var tokensLength = tokens.Length;

            if (tokensLength >= 4)
            {
                var partitionIdStr     = tokens[tokensLength - 2];
                var serviceNameStr     = tokens[tokensLength - 3];
                var applicationNameStr = tokens[tokensLength - 4];

                recoveryPoint.PartitionInformation.Id = Guid.Parse(partitionIdStr);
                recoveryPoint.ApplicationName         = new Uri(String.Format("fabric:/{0}", UtilityHelper.GetUriFromCustomUri(applicationNameStr)));
                recoveryPoint.ServiceName             =
                    new Uri(String.Format("{0}/{1}", recoveryPoint.ApplicationName, UtilityHelper.GetUriFromCustomUri(serviceNameStr)));
            }
        }