예제 #1
0
            public void Write(string value, ConsoleColor?color = null)
            {
                if (color.HasValue)
                {
                    lineParts.Add(() => Console.ForegroundColor = color.Value);
                }

                lineParts.Add(() => { AdjustCursorTop(value.Count(c => c == '\n')); Console.Write(value); });

                RefreshableConsole.Render();
            }
예제 #2
0
        public async Task <bool> DeployAsync()
        {
            var isDeploymentSuccessful = false;
            var mainTimer = Stopwatch.StartNew();

            RefreshableConsole.WriteLine("Running...");

            await ValidateTokenProviderAsync();

            tokenCredentials = new TokenCredentials(new RefreshableAzureServiceTokenProvider("https://management.azure.com/"));
            azureCredentials = new AzureCredentials(tokenCredentials, null, null, AzureEnvironment.AzureGlobalCloud);
            azureClient      = GetAzureClient(azureCredentials);

            await ValidateConfigurationAsync();

            try
            {
                RefreshableConsole.WriteLine();
                RefreshableConsole.WriteLine($"VM host: {configuration.VmName}.{configuration.RegionName}.cloudapp.azure.com");
                RefreshableConsole.WriteLine($"VM username: {configuration.VmUsername}");
                RefreshableConsole.WriteLine($"VM password: {configuration.VmPassword}");
                RefreshableConsole.WriteLine();

                await CreateResourceGroupAsync();

                BatchAccount     batchAccount      = null;
                IGenericResource appInsights       = null;
                ICosmosDBAccount cosmosDb          = null;
                IStorageAccount  storageAccount    = null;
                IVirtualMachine  linuxVm           = null;
                ConnectionInfo   sshConnectionInfo = null;

                await Task.WhenAll(new Task[]
                {
                    Task.Run(async() => batchAccount   = await CreateBatchAccountAsync(), cts.Token),
                    Task.Run(async() => appInsights    = await CreateAppInsightsResourceAsync(), cts.Token),
                    Task.Run(async() => cosmosDb       = await CreateCosmosDbAsync(), cts.Token),
                    Task.Run(async() => storageAccount = await CreateStorageAccountAsync(), cts.Token),

                    Task.Run(async() =>
                    {
                        linuxVm           = await CreateVirtualMachineAsync();
                        sshConnectionInfo = new ConnectionInfo(linuxVm.GetPrimaryPublicIPAddress().Fqdn, configuration.VmUsername, new PasswordAuthenticationMethod(configuration.VmUsername, configuration.VmPassword));
                        await WaitForSshConnectivityAsync(sshConnectionInfo);
                        await ConfigureVmAsync(sshConnectionInfo);
                    }, cts.Token)
                });

                var vmManagedIdentity = linuxVm.SystemAssignedManagedServiceIdentityPrincipalId;

                await AssignVmAsBillingReaderToSubscriptionAsync(vmManagedIdentity);
                await AssignVmAsContributorToAppInsightsAsync(vmManagedIdentity, appInsights);
                await AssignVmAsContributorToCosmosDb(vmManagedIdentity, cosmosDb);
                await AssignVmAsContributorToBatchAccountAsync(vmManagedIdentity, batchAccount);
                await AssignVmAsContributorToStorageAccountAsync(vmManagedIdentity, storageAccount);
                await AssignVmAsDataReaderToStorageAccountAsync(vmManagedIdentity, storageAccount);

                await RestartVmAsync(linuxVm);
                await WaitForSshConnectivityAsync(sshConnectionInfo);
                await WaitForDockerComposeAsync(sshConnectionInfo);
                await WaitForCromwellAsync(sshConnectionInfo);

                isDeploymentSuccessful = await VerifyInstallationAsync(storageAccount);

                if (!isDeploymentSuccessful)
                {
                    await DeleteResourceGroupIfUserConsentsAsync();
                }
            }
            catch (Microsoft.Rest.Azure.CloudException cloudException)
            {
                var json = cloudException.Response.Content;
                RefreshableConsole.WriteLine(json);
                Debugger.Break();
                WriteGeneralRetryMessageToConsole();
                await DeleteResourceGroupIfUserConsentsAsync();
            }
            catch (Exception exc)
            {
                RefreshableConsole.WriteLine(exc.ToString());
                Debugger.Break();
                WriteGeneralRetryMessageToConsole();
                await DeleteResourceGroupIfUserConsentsAsync();
            }

            RefreshableConsole.WriteLine($"Completed in {mainTimer.Elapsed.TotalMinutes:n1} minutes.");

            return(isDeploymentSuccessful);
        }