private async Task ServiceExistingCheckUtility(Func <Task> sendToServiceNodeFunc, TimeSpan timeout, CancellationToken cancellationToken, string processQueueTypeTrace)
        {
            try
            {
                await sendToServiceNodeFunc();

                BackupRestoreTrace.TraceSource.WriteInfo(processQueueTypeTrace, "Sent successfully");
            }
            catch (Exception exception)
            {
                var fabricException = exception as FabricException;
                if (fabricException?.ErrorCode == FabricErrorCode.ServiceOffline ||
                    fabricException?.ErrorCode == FabricErrorCode.PartitionNotFound)
                {
                    try
                    {
                        await FabricClientHelper.ValidatePartition(this.ServiceUri, this.PartitionId, timeout,
                                                                   cancellationToken);
                    }
                    catch (Exception validateException)
                    {
                        var validateFabricException = validateException as FabricException;
                        if (validateFabricException?.ErrorCode == FabricErrorCode.PartitionNotFound)
                        {
                            BackupRestoreTrace.TraceSource.WriteInfo(processQueueTypeTrace, "Request {0} is Deleted as Partition Doesn't exist", this);
                            return;
                        }
                    }
                }

                throw;
            }
        }
Exemple #2
0
        internal static async Task <string> GetCustomServiceUri(string serviceNameUri, TimeSpan timeout, CancellationToken cancellationToken)
        {
            string applicationNameUri = await FabricClientHelper.GetFabricApplicationUriFromServiceUri(serviceNameUri, timeout, cancellationToken);

            string applicationName = GetNameFromUri(applicationNameUri);
            string serviceName     = RemoveApplicationNameUriFromServiceNameUri(applicationNameUri, serviceNameUri);

            return(CreateUriFromApplicationAndServiceName(applicationName, serviceName));
        }
Exemple #3
0
        internal static async Task <string> GetFabricUriFromRequstHeader(string fabricRequestHeader, TimeSpan timeout, CancellationToken cancellationToken)
        {
            string fabricUri = null;

            try
            {
                string[] segments           = fabricRequestHeader.Split('/');
                string   type               = segments[0];
                string   serviceNameUri     = null;
                string   applicationNameUri = null;
                string   applicationName    = null;
                string   serviceName        = null;

                switch (type)
                {
                case "Applications":
                    applicationNameUri = String.Format("fabric:/{0}", string.Join("/", segments.Skip(1)).Trim('/'));
                    applicationName    = GetNameFromUri(applicationNameUri);
                    fabricUri          = CreateUriFromApplicationAndServiceName(applicationName);
                    break;

                case "Services":
                    serviceNameUri     = String.Format("fabric:/{0}", string.Join("/", segments.Skip(1)).Trim('/'));
                    applicationNameUri = await FabricClientHelper.GetFabricApplicationUriFromServiceUri(serviceNameUri, timeout, cancellationToken);

                    applicationName = GetNameFromUri(applicationNameUri);
                    serviceName     = RemoveApplicationNameUriFromServiceNameUri(applicationNameUri, serviceNameUri);
                    fabricUri       = CreateUriFromApplicationAndServiceName(applicationName, serviceName);
                    break;

                case "Partitions":
                    if (segments.Length != 2 || String.IsNullOrEmpty(segments[1]))
                    {
                        throw new ArgumentException("Invalid argument");
                    }
                    fabricUri = await GetFabricUriFromPartitionId(segments[1], timeout, cancellationToken);

                    break;

                default:
                    throw new ArgumentException(StringResources.InvalidArguments);
                }
            }
            catch (Exception exception)
            {
                if (exception is FabricException)
                {
                    throw;
                }
                else
                {
                    LogException(TraceType, exception);
                    throw new FabricException(exception.Message, (FabricErrorCode)exception.HResult);
                }
            }
            return(fabricUri);
        }
Exemple #4
0
        internal static async Task <string> GetFabricUriFromPartitionId(string partitionId, TimeSpan timeout, CancellationToken cancellationToken)
        {
            string serviceNameUri = await FabricClientHelper.GetFabricServiceUriFromPartitionId(partitionId, timeout, cancellationToken);

            string applicationNameUri = await FabricClientHelper.GetFabricApplicationUriFromServiceUri(serviceNameUri, timeout, cancellationToken);

            string applicationName = GetNameFromUri(applicationNameUri);
            string serviceName     = RemoveApplicationNameUriFromServiceNameUri(applicationNameUri, serviceNameUri);

            return(string.Format("{0}/{1}",
                                 CreateUriFromApplicationAndServiceName(applicationName, serviceName), partitionId));
        }
        private async Task <bool> CancelDataLoss(string processQueueTypeTrace)
        {
            bool isCancelDataLossSuccess = false;

            try
            {
                await FabricClientHelper.CancelPartitionDataLoss(this.DataLossGuid, Constants.RequestDataLossTimeout);

                isCancelDataLossSuccess = true;
                BackupRestoreTrace.TraceSource.WriteInfo(processQueueTypeTrace, "Canceled the Data Loss Successfully");
            }
            catch (Exception exception)
            {
                BackupRestoreTrace.TraceSource.WriteInfo(processQueueTypeTrace,
                                                         "Exception in GetPartitionDataLossProgress {0}",
                                                         exception.ToString());
            }
            return(isCancelDataLossSuccess);
        }
Exemple #6
0
        internal static async Task <string> GetFabricUriFromRequstHeaderForPartitions(string fabricRequestHeader, TimeSpan timeout, CancellationToken cancellationToken)
        {
            string fabricUri;

            try
            {
                string[] segments = fabricRequestHeader.Split('/');
                string   type     = segments[0];

                switch (type)
                {
                case "Partitions":
                    if (segments.Length != 2 || string.IsNullOrEmpty(segments[1]))
                    {
                        throw new ArgumentException(StringResources.InvalidArguments);
                    }
                    string serviceNameUri = await FabricClientHelper.GetFabricServiceUriFromPartitionId(segments[1], timeout, cancellationToken);

                    string applicationNameUri = await FabricClientHelper.GetFabricApplicationUriFromServiceUri(serviceNameUri, timeout, cancellationToken);

                    string applicationName = GetNameFromUri(applicationNameUri);
                    string serviceName     = RemoveApplicationNameUriFromServiceNameUri(applicationNameUri, serviceNameUri);
                    fabricUri = string.Format("{0}/{1}",
                                              CreateUriFromApplicationAndServiceName(applicationName, serviceName), segments[1]);
                    break;

                default:
                    throw new ArgumentException(StringResources.InvalidArguments);
                }
            }
            catch (Exception exception)
            {
                LogException(TraceType, exception);
                FabricException fabricException = exception as FabricException;
                if (fabricException != null)
                {
                    throw;
                }

                throw new ArgumentException(StringResources.InvalidArguments);
            }
            return(fabricUri);
        }
        private async Task <PartitionDataLossProgress> GetPartitionDataLossProgress(string processQueueTypeTrace)
        {
            PartitionDataLossProgress partitionDataLossProgress = null;

            try
            {
                partitionDataLossProgress = await FabricClientHelper.GetPartitionDataLossProgress(this.DataLossGuid, Constants.GetDataLossProgressTimeout);

                BackupRestoreTrace.TraceSource.WriteInfo(processQueueTypeTrace,
                                                         "Get GetPartitionDataLossProgress Resulted as {0} with State as {1}",
                                                         partitionDataLossProgress.Result, partitionDataLossProgress.State.ToString());
            }
            catch (Exception exception)
            {
                BackupRestoreTrace.TraceSource.WriteInfo(processQueueTypeTrace,
                                                         "Exception in GetPartitionDataLossProgress {0}",
                                                         exception.ToString());
            }
            return(partitionDataLossProgress);
        }
Exemple #8
0
        public override async Task <bool> Process(Microsoft.ServiceFabric.Services.Runtime.StatefulService statefulService, TimeSpan timeout, CancellationToken cancellationToken, string processQueueTypeTrace)
        {
            WorkItem      workItem      = null;
            WorkItemQueue workItemQueue = await WorkItemQueue.CreateOrGetWorkItemQueue(statefulService);

            BackupMappingStore backupMappingStore =
                await BackupMappingStore.CreateOrGetBackupMappingStore(statefulService);

            BackupRestoreTrace.TraceSource.WriteInfo(processQueueTypeTrace, "Resolving for {0} of type {1} ", this.ApplicationOrServiceUri, this.FabricBackupResourceType);
            try
            {
                if (this.FabricBackupResourceType == FabricBackupResourceType.ApplicationUri)
                {
                    ServiceList serviceList =
                        await FabricClientHelper.GetServiceList(this.ApplicationOrServiceUri);

                    foreach (Query.Service service in serviceList)
                    {
                        if (service.ServiceKind == ServiceKind.Stateful && (service as StatefulService).HasPersistedState)
                        {
                            BackupMapping specificServiceBackupMapping = await backupMappingStore.GetValueAsync(
                                UtilityHelper.GetBackupMappingKey(service.ServiceName.OriginalString, null));

                            if (specificServiceBackupMapping == null || this.WorkItemInfo.WorkItemType == WorkItemPropogationType.SuspendPartition ||
                                this.WorkItemInfo.WorkItemType == WorkItemPropogationType.ResumePartition)
                            {
                                ServicePartitionList servicePartitionList =
                                    await
                                    FabricClientHelper.GetPartitionList(service.ServiceName.OriginalString);

                                foreach (Partition servicePartition in servicePartitionList)
                                {
                                    BackupMapping specificPartitionBackupMapping =
                                        await backupMappingStore.GetValueAsync(UtilityHelper.GetBackupMappingKey(
                                                                                   service.ServiceName.OriginalString,
                                                                                   servicePartition.PartitionInformation.Id.ToString()));

                                    if (specificPartitionBackupMapping == null || this.WorkItemInfo.WorkItemType == WorkItemPropogationType.SuspendPartition ||
                                        this.WorkItemInfo.WorkItemType == WorkItemPropogationType.ResumePartition)
                                    {
                                        //Send to Service Partition
                                        workItem = new SendToServiceNodeWorkItem
                                                       (await UtilityHelper.GetCustomServiceUri(service.ServiceName.OriginalString, timeout, cancellationToken),
                                                       servicePartition.PartitionInformation.Id.ToString(),
                                                       this.WorkItemInfo);
                                        await workItemQueue.AddWorkItem(workItem, timeout, cancellationToken);
                                    }
                                }
                            }
                        }
                    }
                }
                else if (this.FabricBackupResourceType == FabricBackupResourceType.ServiceUri)
                {
                    ServicePartitionList servicePartitionList =
                        await
                        FabricClientHelper.GetPartitionList(this.ApplicationOrServiceUri);

                    foreach (Partition servicePartition in servicePartitionList)
                    {
                        BackupMapping specificPartitionBackupMapping =
                            await backupMappingStore.GetValueAsync(UtilityHelper.GetBackupMappingKey(
                                                                       this.ApplicationOrServiceUri, servicePartition.PartitionInformation.Id.ToString()));

                        if (specificPartitionBackupMapping == null || this.WorkItemInfo.WorkItemType == WorkItemPropogationType.SuspendPartition ||
                            this.WorkItemInfo.WorkItemType == WorkItemPropogationType.ResumePartition)
                        {
                            //Send to Service Partition
                            workItem = new SendToServiceNodeWorkItem
                                           (await UtilityHelper.GetCustomServiceUri(this.ApplicationOrServiceUri, timeout, cancellationToken), servicePartition.PartitionInformation.Id.ToString(), this.WorkItemInfo);
                            await workItemQueue.AddWorkItem(workItem, timeout, cancellationToken);
                        }
                    }
                }
                BackupRestoreTrace.TraceSource.WriteInfo(processQueueTypeTrace, "Resolving successful");
            }
            catch (Exception exception)
            {
                AggregateException aggregateException = exception as AggregateException;
                if (aggregateException != null)
                {
                    BackupRestoreTrace.TraceSource.WriteWarning(processQueueTypeTrace, "Aggregate Exception Stack Trace : {0}",
                                                                exception.StackTrace);
                    foreach (Exception innerException in aggregateException.InnerExceptions)
                    {
                        BackupRestoreTrace.TraceSource.WriteWarning(processQueueTypeTrace,
                                                                    "Inner Exception : {0} , Message : {1} , Stack Trace : {2} ",
                                                                    innerException.InnerException, innerException.Message, innerException.StackTrace);
                    }
                }
                else
                {
                    BackupRestoreTrace.TraceSource.WriteWarning(processQueueTypeTrace,
                                                                "Exception : {0} , Message : {1} , Stack Trace : {2} ",
                                                                exception.InnerException, exception.Message, exception.StackTrace);
                }
                return(false);
            }
            return(true);
        }