public static async Task RunV3([TimerTrigger("0 0 16 * * *", RunOnStartup = false)] TimerInfo myTimer, ILogger log)
        {
            log.LogInformation($"Performance tests were started by timer trigger at: {DateTime.Now}");

            IPerformanceRunOptionsFactory factory = new V3PerformanceRunOptionsFactory(log);
            PerformanceRunOptions         options = await factory.CreateAsync();

            await PerformanceManager.Execute(string.Empty, options, log);
        }
Esempio n. 2
0
        public static async Task <IActionResult> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, ILogger log)
        {
            try
            {
                log.LogInformation($"Performance tests were started by http trigger at: {DateTime.Now}");

                string testId = string.Empty;
                req.GetQueryParameterDictionary().TryGetValue("testId", out testId);

                if (!req.GetQueryParameterDictionary().TryGetValue("version", out string version))
                {
                    return(new BadRequestObjectResult("Specify 'version' of 'v2' or 'v3' on the query string."));
                }

                PerformanceRunOptions options = null;
                switch (version.ToLowerInvariant())
                {
                case "v2":
                    IPerformanceRunOptionsFactory v2factory = new V2PerformanceRunOptionsFactory(log);
                    options = await v2factory.CreateAsync();

                    break;

                case "v3":
                    IPerformanceRunOptionsFactory v3factory = new V3PerformanceRunOptionsFactory(log);
                    options = await v3factory.CreateAsync();

                    break;

                default:
                    return(new BadRequestObjectResult("Specify 'version' of 'v2' or 'v3' on the query string."));
                }

                await PerformanceManager.Execute(testId, options, log);

                return(new ContentResult()
                {
                    Content = string.IsNullOrEmpty(testId) ? "All tests started" : $"Tests started: {testId}",
                    ContentType = "text/html"
                });
            }
            catch (Exception ex)
            {
                log.LogError(ex.ToString());
                return(new ContentResult()
                {
                    Content = "Exception:" + ex,
                    ContentType = "text/html"
                });
            }
        }
        public static async Task Execute(string testId, PerformanceRunOptions options, ILogger log)
        {
            var authenticationContext = new AuthenticationContext($"https://login.windows.net/{options.TenantId}");
            var credential            = new ClientCredential(options.ClientId, options.ClientSecret);
            var result = await authenticationContext.AcquireTokenAsync("https://management.core.windows.net/", credential);

            if (result == null)
            {
                throw new AuthenticationException("Failed to obtain the JWT token");
            }

            var credentials = new TokenCredentials(result.AccessToken);

            using (var client = new ComputeManagementClient(credentials))
            {
                client.SubscriptionId = options.SubscriptionId;
                await VirtualMachinesOperationsExtensions.BeginRunCommandAsync(client.VirtualMachines, options.SiteResourceGroup, options.VM,
                                                                               new RunCommandInput("RunPowerShellScript",
                                                                                                   new List <string>()
                {
                    $"& 'C:\\Tools\\ps\\run.ps1' '{options.AppUrl}' '{testId}' '{options.ExtensionUrl}'"
                }));
            }
        }