public static void Run([ActivityTrigger] DurableActivityContext context, ILogger log, ExecutionContext executionContext) { // config and input _log = log; var input = new { ResourceGroupName = context.GetInput <Tuple <string, string> >().Item1, ResourcesName = context.GetInput <Tuple <string, string> >().Item2 }; var config = executionContext.BuildConfiguration(); var clientId = config["ApplicationId"]; var clientSecret = config["ApplicationSecret"]; var tenantId = config["TenantId"]; string subscriptionId = config["SubscriptionId"]; log.LogInformation($"delete activity group start {input.ResourcesName} "); try { // authenticate and delete resource group if (!AzureCredentials.Make(tenantId, clientId, clientSecret, subscriptionId) .TryGetAzure(out IAzure azure, message => _log.LogError(message))) { return; } azure.DeleteResourcesInGroup(input.ResourceGroupName, input.ResourcesName, s => _log.LogWarning(s)); } catch (Exception e) { _log.LogError($"delete activity group {input.ResourceGroupName} {e.Message}", e); } }
public static string[] Run([ActivityTrigger] DurableActivityContext context, ILogger log, ExecutionContext executionContext) { //config and input _log = log; var input = new { Name = context.GetInput <string>() }; var config = executionContext.BuildConfiguration(); var clientId = config["ApplicationId"]; var clientSecret = config["ApplicationSecret"]; var tenantId = config["TenantId"]; string subscriptionId = config["SubscriptionId"]; log.LogInformation($"Get resources activity start {input.Name}"); try { // authenticate and return names of VMSSs that start with the prefix if (!AzureCredentials.Make(tenantId, clientId, clientSecret, subscriptionId) .TryGetAzure(out IAzure azure, message => _log.LogError(message))) { return(Array.Empty <string>()); } return(azure.GetVmssNames(input.Name).ToArray()); } catch (Exception e) { _log.LogError($"Get resources activity error {e.Message}", e); } return(Array.Empty <string>()); }
public static void Run([ActivityTrigger] DurableActivityContext context, ILogger log, ExecutionContext executionContext) { // config and input _log = log; var input = new { ResourceGroupName = context.GetInput <string>() }; var config = executionContext.BuildConfiguration(); var clientId = config["ApplicationId"]; var clientSecret = config["ApplicationSecret"]; var tenantId = config["TenantId"]; string subscriptionId = config["SubscriptionId"]; var region = config["Region"]; log.LogInformation($"create resource group activity start {input.ResourceGroupName} "); try { // authenticate and create resource group if not exists if (!AzureCredentials.Make(tenantId, clientId, clientSecret, subscriptionId) .TryGetAzure(out IAzure azure, message => _log.LogError(message))) { return; } azure.GetOrCreateResourceGroup(input.ResourceGroupName, region); } catch (Exception e) { _log.LogError($"create resource group activity error processing function {e.Message}", e); } }
public static async Task <string> Run([ActivityTrigger] DurableActivityContext context, ILogger log, ExecutionContext executionContext) { //config and input _log = log; var input = new { Name = context.GetInput <Tuple <string, int> >().Item1, Index = context.GetInput <Tuple <string, int> >().Item2 }; var config = executionContext.BuildConfiguration(); var clientId = config["ApplicationId"]; var clientSecret = config["ApplicationSecret"]; var tenantId = config["TenantId"]; string subscriptionId = config["SubscriptionId"]; string sourceStorageName = config["SourceStorageName"]; string sourceStorageKey = config["SourceStorageKey"]; string sourceContainerName = config["SourceAppsContainerName"]; log.LogInformation($"duplicate storage activity start {input.Name} {input.Index} "); try { // authenticate if (!AzureCredentials.Make(tenantId, clientId, clientSecret, subscriptionId) .TryGetAzure(out var azure, message => _log.LogError(message))) { return(string.Empty); } // create target storage account var targetStorage = azure .StorageAccounts .Define($"{input.Name.ToLower()}{input.Index}") .WithRegion(Region.EuropeWest) .WithExistingResourceGroup(input.Name) .Create(); // copy the source blob to the target container await new CloudStorageAccount(new StorageCredentials(sourceStorageName, sourceStorageKey), true) .CreateCloudBlobClient() .CopyContainerByName(sourceContainerName, new CloudBlobClient(new Uri(targetStorage.EndPoints.Primary.Blob), new StorageCredentials(targetStorage.Name, targetStorage.GetKeys()[0].Value))); // return account key for the new storage return(targetStorage.GetKeys().FirstOrDefault()?.Value); } catch (Exception e) { _log.LogError($"duplicate storage activity error {e.Message}", e); } return(string.Empty); }
public static async Task Run([ActivityTrigger] DurableActivityContext context, ILogger log, ExecutionContext executionContext) { //config and input _log = log; var input = new { Name = context.GetInput <Tuple <string, int, int, string> >().Item1, Index = context.GetInput <Tuple <string, int, int, string> >().Item2, Count = context.GetInput <Tuple <string, int, int, string> >().Item3, StorageKey = context.GetInput <Tuple <string, int, int, string> >().Item4 }; var config = executionContext.BuildConfiguration(); var clientId = config["ApplicationId"]; var clientSecret = config["ApplicationSecret"]; var tenantId = config["TenantId"]; string subscriptionId = config["SubscriptionId"]; string userName = config["NodeUserName"]; string password = config["NodeUserPassword"]; var templatePath = config["TemplateFileUri"]; var scriptFile = config["ScriptFileUri"]; var commandToExecute = config["CommandToExecute"]; string sourceContainerName = config["SourceAppsContainerName"]; var region = config["Region"]; var omsKey = config["OmsWorkspaceKey"]; var omsId = config["OmsWorkspaceId"]; log.LogInformation($"Provision activity start {input.Name} {input.Index}"); try { // get the files URIs to be downloaded to each node var fileUris = (await new CloudStorageAccount(new StorageCredentials($"{input.Name.ToLower()}{input.Index}", input.StorageKey), true) .CreateCloudBlobClient() .GetContainerReference(sourceContainerName) .ListBlobsSegmentedAsync(new BlobContinuationToken())) .Results .Select(t => $"{t.Uri.ToString()}") .Append($"{scriptFile}") .ToArray(); // set deployment parameters var parameters = Parameters.Make( $"{input.Name}{input.Index}", AddressRange.Make(input.Index).AddressRangeString, fileUris, commandToExecute, userName, password, input.Count, omsId, omsKey); // authenticate if (!AzureCredentials.Make(tenantId, clientId, clientSecret, subscriptionId) .TryGetAzure(out var azure, message => _log.LogError(message))) { return; } // deploy template _log.LogInformation($"deploy template with parameters: {parameters}"); azure.DeployResourcesToGroup(input.Name, parameters, region, templatePath, s => _log.LogWarning(s)); } catch (Exception e) { _log.LogError($"Provision activity error {e.Message}", e); } }