From 28a61fe5be96aabd7767c20ff03287737d1d50de Mon Sep 17 00:00:00 2001 From: "quali-spark-agent[bot]" <347101321+quali-spark-agent[bot]@users.noreply.github.com> Date: Fri, 23 Oct 2026 21:22:23 +0000 Subject: [PATCH 1/2] AB#20576: workflows test 3 Generated by spark-agents/docs-writer (local/qwen3-coder-64k). --- docs/workflows/workflows-use-cases.md | 95 +++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) diff --git a/docs/workflows/workflows-use-cases.md b/docs/workflows/workflows-use-cases.md index f1ae594e9..679c3b496 100644 --- a/docs/workflows/workflows-use-cases.md +++ b/docs/workflows/workflows-use-cases.md @@ -518,6 +518,99 @@ grains: --- +### 9. Cleanup Test Environments + +**Motivation:** Automate the cleanup of test environments after testing to reduce costs and maintain resource availability. + +**Benefits:** +- Reduces operational costs by automatically destroying unused test environments +- Prevents resource leakage that can lead to unexpected charges +- Ensures consistent cleanup procedures across all test environments +- Improves resource availability for subsequent tests + +```yaml +spec_version: 2 +description: Cleanup test environments after testing + +workflow: + scope: environment + labels-selector: test-environment # will be available for all test environments + +inputs: + force_cleanup: + type: boolean + default: false + description: Force cleanup even if environment is not in a clean state + +outputs: + cleanup_status: + value: '{{ .grains.cleanup.outputs.status }}' + +grains: + cleanup: + kind: shell + spec: + agent: + name: cloud-agent + files: + - source: scripts + path: scripts/cleanup-test-env.sh + activities: + deploy: + commands: + - name: cleanup + command: 'source cleanup-test-env.sh {{ .bindings.environment_id }} {{ .inputs.force_cleanup }}' + outputs: + - status +``` + +**Shell script:** + +```bash +#!/bin/bash + +environment_id=$1 +force_cleanup=$2 + +# Set default status +status="success" + +echo "Cleaning up test environment: $environment_id" +echo "Force cleanup: $force_cleanup" + +# Check if the environment is a test environment and has appropriate labels +if [ -z "$environment_id" ]; then + echo "Error: No environment ID provided" + status="error" + exit 1 +fi + +# Get environment details +export ENV_DETAILS=$(torque env get "$environment_id" --format json) + +# Extract environment attributes +env_name=$(echo $ENV_DETAILS | jq -r '.name') +env_state=$(echo $ENV_DETAILS | jq -r '.state') + +# Perform cleanup actions +echo "Cleaning up resources in environment: $env_name" + +# Destroy all resources in the environment (example command) +# This would typically interact with your infrastructure management system +if [ "$force_cleanup" = "true" ] || [ "$env_state" = "ready" ]; then + echo "Destroying all resources in environment $environment_id" + # Example: torque env delete "$environment_id" --force +else + echo "Environment not in ready state, skipping cleanup ($env_state)" +fi + +echo "" +echo "Cleanup completed for environment: $environment_id" +echo "Status: $status" +export status +``` + + ## Torque Built-in Workflows :::info @@ -538,6 +631,8 @@ Usage example can be found [here](workflows-overview#torque-built-in-workflows) - Enables scheduled maintenance windows - Facilitates quick recovery from issues through restarts +--- + ### 2. Azure VM Power Management **Workflows:** From 8a573ef40318974973deb4cd8f2c0fecf7430be2 Mon Sep 17 00:00:00 2001 From: "quali-spark-agent[bot]" <347101321+quali-spark-agent[bot]@users.noreply.github.com> Date: Fri, 23 Oct 2026 21:28:02 +0000 Subject: [PATCH 2/2] AB#20576: address review feedback (round 1) Review(s) by @davidbquali. Generated by spark-agents/docs-writer (local/qwen3-coder-64k). --- docs/workflows/workflows-use-cases.md | 334 -------------------------- 1 file changed, 334 deletions(-) diff --git a/docs/workflows/workflows-use-cases.md b/docs/workflows/workflows-use-cases.md index 679c3b496..67cf1d3c2 100644 --- a/docs/workflows/workflows-use-cases.md +++ b/docs/workflows/workflows-use-cases.md @@ -15,65 +15,6 @@ Simple Workflow example to extract Azure VM power state - This information can be useful for various purposes, such as monitoring, troubleshooting, or automation tasks. By extracting the power state, you can determine whether a VM is running, stopped, or in any other power state, and use this information to make informed decisions or trigger further actions based on the VM's power state. - This workflow provides a convenient way to extract the power state of Azure VM resources and make it available as an output for further processing or integration with other systems. -```yaml -spec_version: 2 -description: Workflow with extract Azure VM power state - -workflow: - scope: env_resource - labels-selector: azurerm_linux_virtual_machine # will be available for all azure VM resources type - -inputs: - agent: - type: agent - default: azure-agent - -outputs: - resource_state: - value: '{{ .grains.power-state.activities.deploy.commands.print.outputs.state }}' - -grains: - power-state: - kind: shell - spec: - agent: - name: '{{ .inputs.agent }}' - files: - - source: scripts - path: scripts/print-resource-2.sh - activities: - deploy: - commands: - - name: print - command: 'source print-resource-2.sh {{ .bindings.resource_id }} {{ .bindings.grain_path }}' - outputs: - - state -``` - -**Shell script:** - -```bash -resource_id=$1 -grain_path=$2 -contract_path=$CONTRACT_FILE_PATH - -# will print the attribute "power_state" of the resource -state_str=$(jq --arg ResourceId "$resource_id" --arg GrainPath "$grain_path" '.resources[] | select(.identifier == $ResourceId and .grain_path == $GrainPath) | .attributes | .power_state' $contract_path) - -export state=`echo -n $state_tr | tr -d '"'` - -echo "" -echo "extracted values:" -echo "------------------" -echo "state: $state" -echo "------------------" -echo "" - -cat $CONTRACT_FILE_PATH -echo $state_tr -export $state_tr -``` - ### 2. Attach an EBS volume to an EC2 instance Workflow that attach an EBS volume to an EC2 instance using Ansible grain @@ -86,128 +27,6 @@ Running the "Attach volume to EC2" workflow enables you to enhance the storage c 4. **High Availability**: By attaching multiple EBS volumes to your EC2 instances, you can distribute your data across different volumes. This improves fault tolerance and ensures that your applications remain available even if one volume fails. 5. **Performance Optimization**: EBS volumes offer different performance characteristics based on their volume types. By attaching volumes with the appropriate performance characteristics, you can optimize the storage performance of your EC2 instances and improve the overall responsiveness of your applications. -```yaml -spec_version: 2 -description: Attach an EBS volume to an EC2 instance using Ansible grain - -workflow: - scope: env_resource - labels-selector: aws_instance # will be available for all aws ec2 resources type - -inputs: - ebs_volume_size: - type: string - default: 1 - device_name: - type: string - default: /dev/sdf - volume_type: - type: string - default: gp3 - -outputs: - volume_id: - value: '{{ .grains.attach_volume.outputs.volume_id }}' - quick: true - volume_name: - value: '{{ .grains.attach_volume.outputs.volume_name }}' - quick: true - volume_operation_data: - value: '{{ .grains.attach_volume.outputs.volume_operation_data }}' - quick: true - -grains: - helper: - kind: shell - spec: - agent: - name: cloud-agent - files: - - source: blueprints - path: blueprints/workflows/scripts/attach-detach-helper.sh - activities: - deploy: - commands: - - name: get-outputs - command: 'source attach-detach-helper.sh {{ .bindings.resource_id }} {{ .bindings.grain_path }}' - outputs: - - id - - region - - availability_zone - - attach_volume: - depends-on: helper - kind: ansible - spec: - source: - store: ansible - path: attach_volume/attach_volume.yml - agent: - name: cloud-agent - inputs: - - ec2_instance_id: '{{ .grains.helper.activities.deploy.commands.get-outputs.outputs.id }}' - - aws_region: '{{ .grains.helper.activities.deploy.commands.get-outputs.outputs.region }}' - - availability_zone: '{{ .grains.helper.activities.deploy.commands.get-outputs.outputs.availability_zone }}' - - ebs_volume_size: '{{ .inputs.ebs_volume_size }}' - - device_name: '{{ .inputs.device_name }}' - - volume_type: '{{ .inputs.volume_type }}' - - env_id: '{{ envId }}' - - volume_name: 'ebs-volume-{{ envId }}' - env-vars: [] - outputs: - - volume_operation_data - - volume_name - - volume_id - - inventory-file: - localhost: - hosts: - 127.0.0.1: - ansible_connection: local -``` - -**Ansible playbook:** - -```yaml ---- -- hosts: localhost - connection: local - gather_facts: false - - tasks: - - name: Install boto3 python package - pip: - name: boto3 - - # Create new volume using SSD storage - - name: Create and attach new EBS volume - amazon.aws.ec2_vol: - instance: "{{ ec2_instance_id | replace('\n', '') }}" - region: "{{ aws_region | replace('\n', '') }}" - zone: "{{ availability_zone | replace('\n', '') }}" - volume_size: "{{ ebs_volume_size | replace('\n', '') }}" - device_name: "{{ device_name | replace('\n', '') }}" - volume_type: "{{ volume_type | replace('\n', '') }}" - delete_on_termination: true # The volume will be deleted upon instance termination. - register: attached_volume - - - name: Ensure tags are present on a resource - amazon.aws.ec2_tag: - region: "{{ aws_region | replace('\n', '') }}" - resource: "{{ attached_volume.volume_id }}" - state: present - tags: - Name: "{{ volume_name | replace('\n', '') }}" - env: prod - - - name: Export outputs - torque.collections.export_torque_outputs: - outputs: - volume_name: "{{ volume_name | replace('\n', '') }}" - volume_id: "{{ attached_volume.volume_id }}" - volume_operation_data: "{{ attached_volume }}" -``` - ### 3. Detach an EBS volume from an EC2 instance Workflow that detach an EBS volume from an EC2 instance using Ansible grain @@ -219,77 +38,6 @@ Running the "Detach an EBS volume from an EC2 instance" workflow helps you optim 3. **Data Security**: Detaching EBS volumes from EC2 instances can enhance data security. By detaching volumes before terminating or decommissioning instances, you can ensure that sensitive data stored on those volumes is not accessible to unauthorized users. This helps to protect your data and maintain compliance with security and privacy regulations. 4. **Maintenance and Troubleshooting**: Detaching EBS volumes can be useful for maintenance and troubleshooting purposes. By detaching volumes, you can perform maintenance tasks such as resizing, snapshotting, or modifying volume attributes without impacting the running instances. It also allows you to troubleshoot issues related to specific volumes without affecting the overall availability of your EC2 instances. -```yaml -spec_version: 2 -description: Detach an EBS volume from an EC2 instance - -workflow: - scope: env_resource - labels-selector: aws_instance - -inputs: - volume_id: - type: string - -grains: - helper: - kind: shell - spec: - agent: - name: cloud-agent - files: - - source: blueprints - path: blueprints/workflows/scripts/attach-detach-helper.sh - activities: - deploy: - commands: - - name: get-outputs - command: 'source attach-detach-helper.sh {{ .bindings.resource_id }} {{ .bindings.grain_path }}' - outputs: - - id - - region - - availability_zone - - detach_volume: - depends-on: helper - kind: ansible - spec: - source: - store: ansible - path: detach_volume/detach_volume.yml - agent: - name: cloud-agent - inputs: - - aws_region: '{{ .grains.helper.activities.deploy.commands.get-outputs.outputs.region }}' - - volume_id: '{{ .inputs.volume_id }}' - env-vars: [] - inventory-file: - localhost: - hosts: - 127.0.0.1: - ansible_connection: local - -``` - -**Ansible playbook:** -```yaml ---- -- hosts: localhost - connection: local - gather_facts: false - - tasks: - - name: Install boto3 python package - pip: - name: boto3 - # Detach a volume - - name: Detach a volume - amazon.aws.ec2_vol: - region: "{{ aws_region | replace('\n', '') }}" - id: "{{ volume_id | replace('\n', '') }}" - instance: None -``` - --- ## Data related workflows @@ -528,88 +276,6 @@ grains: - Ensures consistent cleanup procedures across all test environments - Improves resource availability for subsequent tests -```yaml -spec_version: 2 -description: Cleanup test environments after testing - -workflow: - scope: environment - labels-selector: test-environment # will be available for all test environments - -inputs: - force_cleanup: - type: boolean - default: false - description: Force cleanup even if environment is not in a clean state - -outputs: - cleanup_status: - value: '{{ .grains.cleanup.outputs.status }}' - -grains: - cleanup: - kind: shell - spec: - agent: - name: cloud-agent - files: - - source: scripts - path: scripts/cleanup-test-env.sh - activities: - deploy: - commands: - - name: cleanup - command: 'source cleanup-test-env.sh {{ .bindings.environment_id }} {{ .inputs.force_cleanup }}' - outputs: - - status -``` - -**Shell script:** - -```bash -#!/bin/bash - -environment_id=$1 -force_cleanup=$2 - -# Set default status -status="success" - -echo "Cleaning up test environment: $environment_id" -echo "Force cleanup: $force_cleanup" - -# Check if the environment is a test environment and has appropriate labels -if [ -z "$environment_id" ]; then - echo "Error: No environment ID provided" - status="error" - exit 1 -fi - -# Get environment details -export ENV_DETAILS=$(torque env get "$environment_id" --format json) - -# Extract environment attributes -env_name=$(echo $ENV_DETAILS | jq -r '.name') -env_state=$(echo $ENV_DETAILS | jq -r '.state') - -# Perform cleanup actions -echo "Cleaning up resources in environment: $env_name" - -# Destroy all resources in the environment (example command) -# This would typically interact with your infrastructure management system -if [ "$force_cleanup" = "true" ] || [ "$env_state" = "ready" ]; then - echo "Destroying all resources in environment $environment_id" - # Example: torque env delete "$environment_id" --force -else - echo "Environment not in ready state, skipping cleanup ($env_state)" -fi - -echo "" -echo "Cleanup completed for environment: $environment_id" -echo "Status: $status" -export status -``` - ## Torque Built-in Workflows