コード例 #1
0
        public static async Task CreateSiteResources(
            [OrchestrationTrigger] DurableOrchestrationContextBase context,
            ILogger log)
        {
            CreationParameters creationParams = context.GetInput <CreationParameters>();

            if (!context.IsReplaying)
            {
                log.LogWarning("ORC - Creating Site Resources in: {resourceGroup}", creationParams.ResourceGroupName);
            }

            // site resources (sql server, sql db, redis cache, storageAccount (record attachments), ???)
            var storageRequest = CreateStorageAccountRequest.FromCreationParams(creationParams);

            storageRequest.StorageAccountName = ResourceCreationActivities.GenerateStorageAccountName(creationParams, string.Empty);

            var t1 = context.CallSubOrchestratorAsync(nameof(CreateSiteSqlServerAndDatabase), creationParams);
            var t2 = context.CallActivityAsync <CreateStorageAccountResult>(nameof(ResourceCreationActivities.CreateStorageAccount), storageRequest);
            await Task.WhenAll(t1, t2);

            if (!context.IsReplaying)
            {
                log.LogWarning($"ORC - Created Storage Account Name: {t2.Result.StorageAccountName} - Primary Key: {t2.Result.PrimaryKey.KeyName}, {t2.Result.PrimaryKey.Value}");
                log.LogWarning($"ORC - Created Site Resources in Resource Group: {creationParams.ResourceGroupName}");
            }
        }
コード例 #2
0
        public static async Task <CreateStorageAccountResult> CreateStorageAccount(
            [ActivityTrigger] CreateStorageAccountRequest storageParams,
            ILogger log)
        {
            log.LogWarning("Creating Storage Account in Resource Group: {resourceGroupName}", storageParams.ResourceGroupName);

            var storageClientProvider = Container.GetService <IAzureClientProvider <IStorageManagementClient> >();
            var storageClient         = await storageClientProvider.Get(storageParams.TenantID, storageParams.SubscriptionID);

            var saParams = new StorageAccountCreateParameters
            {
                Sku        = new Microsoft.Azure.Management.Storage.Models.Sku(Microsoft.Azure.Management.Storage.Models.SkuName.StandardGRS),
                Location   = storageParams.AzureResourceLocation,
                Kind       = Kind.Storage,
                Encryption = new Encryption("Microsoft.Storage", new EncryptionServices(blob: new EncryptionService(enabled: true))),
                Tags       = GenerateTags(storageParams)
            };

            StorageAccount sa = await storageClient.StorageAccounts.CreateAsync(storageParams.ResourceGroupName, storageParams.StorageAccountName, saParams);

            log.LogWarning($"Created Storage Account {sa.Name} ({sa.Sku.Name}) in Resource Group: {storageParams.ResourceGroupName}");

            StorageAccountListKeysResult keys = await storageClient.StorageAccounts.ListKeysAsync(storageParams.ResourceGroupName, storageParams.StorageAccountName);

            return(new CreateStorageAccountResult()
            {
                StorageAccountName = storageParams.StorageAccountName,
                PrimaryKey = keys.Keys.FirstOrDefault(),
                BlobUrl = sa.PrimaryEndpoints.Blob
            });
        }
コード例 #3
0
        public static async Task CreateCoreResources(
            [OrchestrationTrigger] DurableOrchestrationContextBase context,
            ILogger log)
        {
            CreationParameters creationParams = context.GetInput <CreationParameters>();

            if (!context.IsReplaying)
            {
                log.LogWarning("ORC - Creating Core Resources in: {resourceGroupName}", creationParams.ResourceGroupName);
            }

            //await context.CallActivityWithRetryAsync(
            //	nameof(ResourceCreationActivities.CreateAppServicePlan),
            //	new RetryOptions(TimeSpan.FromMinutes(1), maxNumberOfAttempts: 3)
            //	{
            //		BackoffCoefficient = 1.0,
            //		Handle = ex =>
            //		{
            //			if (ex is CloudException)
            //			{
            //				log.LogError(ex, "failed to create app service plan...");
            //				return true;
            //			}
            //			// don't bother retrying on any other exceptions
            //			return false;
            //		},
            //		RetryTimeout = TimeSpan.FromMinutes(1)
            //	},
            //	creationParams);

            var storageRequest = CreateStorageAccountRequest.FromCreationParams(creationParams);

            storageRequest.StorageAccountName = ResourceCreationActivities.GenerateStorageAccountName(creationParams, "logs");

            var t1 = context.CallSubOrchestratorAsync(nameof(CreateCustomerAppServicePlan), creationParams);
            var t2 = context.CallActivityAsync <CreateStorageAccountResult>(nameof(ResourceCreationActivities.CreateStorageAccount), storageRequest);

            await Task.WhenAll(t1, t2);

            if (!context.IsReplaying)
            {
                log.LogWarning($"ORC - Created Storage Account Name: {t2.Result.StorageAccountName} - Primary Key: {t2.Result.PrimaryKey.KeyName}, {t2.Result.PrimaryKey.Value}");
                log.LogWarning($"ORC - Created Core Resources in: {creationParams.ResourceGroupName}");
            }
        }