Example #1
0
 /// <summary>
 /// Update a GAE services's traffic split.
 /// </summary>
 /// <param name="split">The traffic split to set.</param>
 /// <param name="serviceId">The id of the service</param>
 /// <returns>A task that will be comleted once the operation is finished.</returns>
 public async Task UpdateServiceTrafficSplitAsync(TrafficSplit split, string serviceId)
 {
     try
     {
         // Create a service with just the traffic split set.
         Service service = new Service
         {
             Split = split
         };
         var request = Service.Apps.Services.Patch(service, ProjectId, serviceId);
         // Only update the traffic split.
         request.UpdateMask = s_trafficSplitUpdateMask;
         Operation operation = await request.ExecuteAsync();
         await AwaitOperationAsync(operation);
     }
     catch (GoogleApiException ex)
     {
         Debug.WriteLine($"Failed to update traffic split: {ex.Message}");
         throw new DataSourceException(ex.Message, ex);
     }
     catch (TimeoutException ex)
     {
         Debug.WriteLine($"Timeout while updating service: {ex.Message}");
         throw new DataSourceException(ex.Message, ex);
     }
 }
Example #2
0
        private async void OnMigrateTrafficCommand()
        {
            try
            {
                IsLoading = true;
                Caption   = String.Format(Resources.CloudExplorerGaeMigratingAllTrafficCaption, _version.Id);

                var split = new TrafficSplit {
                    Allocations = new Dictionary <string, double?> {
                        [_version.Id] = 1.0
                    }
                };
                var operation = await _owner.DataSource.UpdateServiceTrafficSplitAsync(split, _service.Id);

                await _owner.DataSource.AwaitOperationAsync(operation);

                _owner.InvalidateService(_service.Id);
            }
            catch (DataSourceException ex)
            {
                Debug.WriteLine($"Failed to set traffic to 100%: {ex.Message}");
                IsError = true;
                Caption = String.Format(Resources.CloudExplorerGaeFailedToMigrateAllTrafficCaption, _version.Id);
            }
        }
        public override int GetHashCode()
        {
            int hash = 1;

            if (ResourceName.Length != 0)
            {
                hash ^= ResourceName.GetHashCode();
            }
            if (Trial.Length != 0)
            {
                hash ^= Trial.GetHashCode();
            }
            if (Name.Length != 0)
            {
                hash ^= Name.GetHashCode();
            }
            if (Control != false)
            {
                hash ^= Control.GetHashCode();
            }
            if (TrafficSplit != 0L)
            {
                hash ^= TrafficSplit.GetHashCode();
            }
            hash ^= campaigns_.GetHashCode();
            hash ^= inDesignCampaigns_.GetHashCode();
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
        /// <summary>
        /// Update a service's traffic split.
        /// </summary>
        private async void UpdateTrafficSplit(TrafficSplit split)
        {
            IsLoading = true;
            Children.Clear();
            UpdateContextMenu();
            Caption = Resources.CloudExplorerGaeUpdateTrafficSplitMessage;
            GaeDataSource datasource = root.DataSource.Value;

            try
            {
                Task <Operation> operationTask            = root.DataSource.Value.UpdateServiceTrafficSplit(split, Service.Id);
                Func <Operation, Task <Operation> > fetch = (o) => datasource.GetOperationAsync(o.GetOperationId());
                Predicate <Operation> stopPolling         = (o) => o.Done ?? false;
                Operation             operation           = await Polling <Operation> .Poll(await operationTask, fetch, stopPolling);

                if (operation.Error != null)
                {
                    throw new DataSourceException(operation.Error.Message);
                }
                Service = await datasource.GetServiceAsync(Service.Id);

                Caption = Service.Id;

                EventsReporterWrapper.ReportEvent(GaeTrafficSplitUpdatedEvent.Create(CommandStatus.Success));
            }
            catch (Exception ex) when(ex is DataSourceException || ex is TimeoutException || ex is OperationCanceledException)
            {
                EventsReporterWrapper.ReportEvent(GaeTrafficSplitUpdatedEvent.Create(CommandStatus.Failure));
                IsError = true;

                if (ex is DataSourceException)
                {
                    Caption = Resources.CloudExplorerGaeUpdateTrafficSplitErrorMessage;
                }
                else if (ex is TimeoutException)
                {
                    Caption = Resources.CloudExploreOperationTimeoutMessage;
                }
                else if (ex is OperationCanceledException)
                {
                    Caption = Resources.CloudExploreOperationCanceledMessage;
                }
            }
            finally
            {
                IsLoading = false;
                PresentViewModels();
                Icon = s_serviceIcon.Value;
                UpdateContextMenu();
            }
        }
        /// <summary>
        /// Opens the dialog to manage traffic splitting for the GAE service and
        /// updates the traffic split if the user makes a change.
        /// </summary>
        private void OnSplitTraffic()
        {
            SplitTrafficChange change = SplitTrafficWindow.PromptUser(Service, _versions);

            if (change == null)
            {
                return;
            }

            TrafficSplit split = new TrafficSplit()
            {
                ShardBy     = change.ShardBy,
                Allocations = change.Allocations,
            };

            UpdateTrafficSplit(split);
        }
Example #6
0
        /// <summary>
        /// Opens the dialog to manage traffic splitting for the GAE service and
        /// updates the traffic split if the user makes a change.
        /// </summary>
        private async Task OnSplitTrafficAsync()
        {
            SplitTrafficChange change = SplitTrafficWindow.PromptUser(Service, _versions.Select(x => x.Version));

            if (change == null)
            {
                return;
            }

            TrafficSplit split = new TrafficSplit()
            {
                ShardBy     = change.ShardBy,
                Allocations = change.Allocations,
            };

            await UpdateTrafficSplitAsync(split);
        }
Example #7
0
        /// <summary>
        /// Update a service's traffic split.
        /// </summary>
        private async void UpdateTrafficSplit(TrafficSplit split)
        {
            IsLoading = true;
            Children.Clear();
            UpdateContextMenu();
            Caption = Resources.CloudExplorerGaeUpdateTrafficSplitMessage;
            GaeDataSource datasource = _owner.DataSource;

            try
            {
                var operation = await _owner.DataSource.UpdateServiceTrafficSplitAsync(split, Service.Id);

                await _owner.DataSource.AwaitOperationAsync(operation);

                _owner.InvalidateService(_service.Id);

                EventsReporterWrapper.ReportEvent(GaeTrafficSplitUpdatedEvent.Create(CommandStatus.Success));
            }
            catch (Exception ex) when(ex is DataSourceException || ex is TimeoutException || ex is OperationCanceledException)
            {
                EventsReporterWrapper.ReportEvent(GaeTrafficSplitUpdatedEvent.Create(CommandStatus.Failure));
                IsError = true;

                if (ex is DataSourceException)
                {
                    Caption = Resources.CloudExplorerGaeUpdateTrafficSplitErrorMessage;
                }
                else if (ex is TimeoutException)
                {
                    Caption = Resources.CloudExploreOperationTimeoutMessage;
                }
                else if (ex is OperationCanceledException)
                {
                    Caption = Resources.CloudExploreOperationCanceledMessage;
                }
            }
            finally
            {
                IsLoading = false;
                PresentViewModels();
                Icon = s_serviceIcon.Value;
                UpdateContextMenu();
            }
        }
        /// <summary>
        /// Update a service's traffic split.
        /// </summary>
        private async void UpdateTrafficSplit(TrafficSplit split)
        {
            IsLoading = true;
            Children.Clear();
            UpdateContextMenu();
            Caption = Resources.CloudExplorerGaeUpdateTrafficSplitMessage;
            GaeDataSource datasource = root.DataSource.Value;

            try
            {
                Task<Operation> operationTask = root.DataSource.Value.UpdateServiceTrafficSplit(split, Service.Id);
                Func<Operation, Task<Operation>> fetch = (o) => datasource.GetOperationAsync(o.GetOperationId());
                Predicate<Operation> stopPolling = (o) => o.Done ?? false;
                Operation operation = await Polling<Operation>.Poll(await operationTask, fetch, stopPolling);
                if (operation.Error != null)
                {
                    throw new DataSourceException(operation.Error.Message);
                }
                Service = await datasource.GetServiceAsync(Service.Id);
                Caption = Service.Id;

                EventsReporterWrapper.ReportEvent(GaeTrafficSplitUpdatedEvent.Create(CommandStatus.Success));
            }
            catch (Exception ex) when (ex is DataSourceException || ex is TimeoutException || ex is OperationCanceledException)
            {
                EventsReporterWrapper.ReportEvent(GaeTrafficSplitUpdatedEvent.Create(CommandStatus.Failure));
                IsError = true;

                if (ex is DataSourceException)
                {
                    Caption = Resources.CloudExplorerGaeUpdateTrafficSplitErrorMessage;
                }
                else if (ex is TimeoutException)
                {
                    Caption = Resources.CloudExploreOperationTimeoutMessage;
                }
                else if (ex is OperationCanceledException)
                {
                    Caption = Resources.CloudExploreOperationCanceledMessage;
                }
            }
            finally
            {
                IsLoading = false;
                PresentViewModels();
                Icon = s_serviceIcon.Value;
                UpdateContextMenu();
            }
        }
        /// <summary>
        /// Opens the dialog to manage traffic splitting for the GAE service and 
        /// updates the traffic split if the user makes a change.
        /// </summary>
        private void OnSplitTraffic()
        {
            SplitTrafficChange change = SplitTrafficWindow.PromptUser(Service, _versions);
            if (change == null)
            {
                return;
            }

            TrafficSplit split = new TrafficSplit()
            {
                ShardBy = change.ShardBy,
                Allocations = change.Allocations,
            };
            UpdateTrafficSplit(split);
        }