Exemple #1
0
        /// <inheritdoc cref="AzurePSCmdlet.ExecuteCmdlet"/>
        public override void ExecuteCmdlet()
        {
            if (!ShouldProcess(Instance, Resources.ExportingLogFromAnalysisServicesServer))
            {
                return;
            }

            var logfileEndpoint = string.Format(AsAzureEndpoints.LogfileEndpointPathFormat, ServerName);

            AsAzureDataplaneClient.ResetHttpClient();
            using (var message = AsAzureDataplaneClient.CallGetAsync(logfileEndpoint).ConfigureAwait(false).GetAwaiter().GetResult())
            {
                message.EnsureSuccessStatusCode();
                var actionWarning = string.Format(CultureInfo.CurrentCulture, Resources.ExportingLogOverwriteWarning, OutputPath);
                if (AzureSession.Instance.DataStore.FileExists(OutputPath) && !Force.IsPresent && !ShouldContinue(actionWarning, Resources.Confirm))
                {
                    return;
                }
                AzureSession.Instance.DataStore.WriteFile(OutputPath, message.Content.ReadAsStringAsync().Result);
            }
        }
Exemple #2
0
        /// <summary>
        /// Worker Method for the synchronize request.
        /// </summary>
        /// <param name="databaseName">Database name</param>
        /// <param name="pollingUrl">URL for polling</param>
        /// <param name="pollingInterval">Polling interval set by the post response</param>
        /// <param name="maxNumberOfAttempts">Max number of attempts for each poll before the attempt is declared a failure</param>
        /// <returns></returns>
        private async Task <ScaleOutServerDatabaseSyncResult> PollSyncStatusWithRetryAsync(string databaseName, Uri pollingUrl, TimeSpan pollingInterval, int maxNumberOfAttempts = 3)
        {
            return(await Task.Run(async() =>
            {
                ScaleOutServerDatabaseSyncResult response = null;
                var syncCompleted = false;
                var retryCount = 0;

                while (!syncCompleted && retryCount < maxNumberOfAttempts)
                {
                    // Wait for specified polling interval other than retries.
                    if (retryCount == 0)
                    {
                        await Task.Delay(pollingInterval);
                    }
                    else
                    {
                        await Task.Delay(DefaultRetryIntervalForPolling);
                    }

                    this.AsAzureDataplaneClient.ResetHttpClient();
                    using (HttpResponseMessage message = await AsAzureDataplaneClient.CallGetAsync(pollingUrl, string.Empty, correlationId))
                    {
                        bool shouldRetry = false;
                        if (message.IsSuccessStatusCode && message.Content != null)
                        {
                            var responseString = await message.Content.ReadAsStringAsync();
                            response = JsonConvert.DeserializeObject <ScaleOutServerDatabaseSyncResult>(responseString);

                            if (response != null)
                            {
                                var state = response.SyncState;
                                if (state == DatabaseSyncState.Completed || state == DatabaseSyncState.Failed)
                                {
                                    syncCompleted = true;
                                }
                                else
                                {
                                    pollingUrl = message.Headers.Location ?? pollingUrl;
                                    pollingInterval = message.Headers.RetryAfter.Delta ?? pollingInterval;
                                }
                            }
                            else
                            {
                                shouldRetry = true;
                            }
                        }
                        else
                        {
                            shouldRetry = true;
                        }

                        if (shouldRetry)
                        {
                            retryCount++;
                            response = new ScaleOutServerDatabaseSyncResult()
                            {
                                Database = databaseName,
                                SyncState = DatabaseSyncState.Invalid
                            };

                            response.Details = string.Format(
                                "Http Error code: {0}. Message: {1}",
                                message.StatusCode.ToString(),
                                message.Content != null ? await message.Content.ReadAsStringAsync() : string.Empty);

                            if (message.StatusCode >= (HttpStatusCode)400 && message.StatusCode <= (HttpStatusCode)499)
                            {
                                break;
                            }
                        }
                        else
                        {
                            retryCount = 0;
                        }
                    }
                }

                return response;
            }));
        }