private async Task EnablePartitionBackup(BackupPolicy backupPolicy, CancellationToken cancellationToken)
 {
     await Program.ServiceAgent.EnableProtectionAsync(new Uri(UtilityHelper.GetUriFromCustomUri(this.ServiceUri)),
                                                      Guid.Parse(this.PartitionId),
                                                      this.GetBackupPolicyDataStructure(backupPolicy, this.ServiceUri, this.PartitionId),
                                                      BackupRestoreServiceConfig.ApiTimeout, cancellationToken);
 }
Esempio n. 2
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)));
            }
        }
Esempio n. 3
0
        private async Task ProcessBackup(StatefulService statefulService, TimeSpan timeout, CancellationToken cancellationToken, string processQueueTypeTrace)
        {
            BackupRestoreTrace.TraceSource.WriteInfo(processQueueTypeTrace, "Processing the Backup for request Uri : {0} , PartitionId {1}", this.ServiceUri, this.PartitionId);
            var timeOutPersecCycle   = 30000;
            var backupPartitionStore = await BackupPartitionStore.CreateOrGetBackupPartitionStore(statefulService);

            var fabricUri = UtilityHelper.GetBackupMappingKey(this.ServiceUri, this.PartitionId);
            BackupPartitionStatus backupPartitionStatus;

            do
            {
                var backupNowConfiguration =
                    new BackupNowConfiguration()
                {
                    StoreInformation             = this.GetBackupStoreInformationFromBackupStorage(this.BackupStorage),
                    OperationTimeoutMilliseconds = (int)this.BackupTimeout.TotalMilliseconds
                };

                await UtilityHelper.InvokeWithRetry(async() =>
                {
                    await
                    Program.ServiceAgent.BackupPartitionAsync(new Uri(UtilityHelper.GetUriFromCustomUri(this.ServiceUri)),
                                                              Guid.Parse(this.PartitionId),
                                                              this.BackupRequestGuid, backupNowConfiguration, timeout, cancellationToken);
                });

                BackupRestoreTrace.TraceSource.WriteInfo(processQueueTypeTrace, "Requested the BackupPartitionAsync Successfully  for Service Uri :  {0} , PartitionId {1}", this.ServiceUri, this.PartitionId);
                await UtilityHelper.InvokeWithRetry(async() =>
                {
                    using (ITransaction transaction = statefulService.StateManager.CreateTransaction())
                    {
                        var currentBackupPartitionStatus = await backupPartitionStore.GetValueWithUpdateLockModeAsync(fabricUri, timeout, cancellationToken, transaction);
                        if (currentBackupPartitionStatus.BackupPartitionStatusState == BackupState.Accepted)
                        {
                            var toUpdateBackupPartitionStatus = currentBackupPartitionStatus.ToBuilder().WithState(BackupState.BackupInProgress).Build();
                            await backupPartitionStore.UpdateValueAsync(fabricUri, toUpdateBackupPartitionStatus,
                                                                        timeout,
                                                                        cancellationToken,
                                                                        transaction);
                            await transaction.CommitAsync();
                            BackupRestoreTrace.TraceSource.WriteInfo(processQueueTypeTrace, "Updated the Backup partition request to BackupInProcss for request Service Uri :  {0} , PartitionId {1}", this.ServiceUri, this.PartitionId);
                        }
                        else
                        {
                            transaction.Abort();
                            BackupRestoreTrace.TraceSource.WriteInfo(processQueueTypeTrace,
                                                                     "Could not Update the  BackupPartition request to BackupInProcess for request Service Uri :  {0} , PartitionId {1} because currentBackupPartitionStatus value is {2}",
                                                                     this.ServiceUri, this.PartitionId, currentBackupPartitionStatus);
                        }
                    }
                }
                                                    );

                await Task.Delay(timeOutPersecCycle, cancellationToken);

                backupPartitionStatus = await backupPartitionStore.GetValueAsync(fabricUri);

                BackupRestoreTrace.TraceSource.WriteInfo(processQueueTypeTrace, "BackupPartitionstatusState {0},isCancellationRequested {1} for Service Uri :  {2} , PartitionId {3}",
                                                         backupPartitionStatus.BackupPartitionStatusState, cancellationToken.IsCancellationRequested, this.ServiceUri, this.PartitionId);
            } while ((backupPartitionStatus.BackupPartitionStatusState == BackupState.Accepted ||
                      backupPartitionStatus.BackupPartitionStatusState == BackupState.BackupInProgress) &&
                     this.BackupRequestGuid.Equals(backupPartitionStatus.OperationId) &&
                     !cancellationToken.IsCancellationRequested);
            cancellationToken.ThrowIfCancellationRequested();
        }
Esempio n. 4
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);
        }
Esempio n. 5
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);
        }
Esempio n. 6
0
 internal static async Task <ServiceList> GetServiceList(string applicationUri)
 {
     return(await InvokeWithRetryAsync <ServiceList>(() =>
                                                     FabricClient.QueryManager.GetServiceListAsync(new Uri(UtilityHelper.GetUriFromCustomUri(applicationUri)))
                                                     ));
 }
Esempio n. 7
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);
 }