|
| 1 | +# Composer Migrate script |
| 2 | + |
| 3 | +This document describes usage of composer_migrate.py script. |
| 4 | + |
| 5 | +The purpose of the script is to provide a tool to migrate Composer 2 environments to Composer 3. The script performs side-by-side migration using save/load snapshots operations. The script performs the following steps: |
| 6 | + |
| 7 | +1. Obtains the configuration of the source Composer 2 environment. |
| 8 | +2. Creates Composer 3 environment with the corresponding configuration. |
| 9 | +3. Pauses all dags in the source Composer 2 environment. |
| 10 | +4. Saves a snapshot of the source Composer 2 environment. |
| 11 | +5. Loads the snapshot to the target the Composer 3 environment. |
| 12 | +6. Unpauses the dags in the target Composer 3 environment (only dags that were unpaused in the source Composer 2 environment will be unpaused). |
| 13 | + |
| 14 | + |
| 15 | +## Prerequisites |
| 16 | +1. [Make sure you are authorized](https://cloud.google.com/sdk/gcloud/reference/auth/login) through `gcloud auth login` before invoking the script . The script requires [permissions to access the Composer environment](https://cloud.google.com/composer/docs/how-to/access-control). |
| 17 | + |
| 18 | +1. The script depends on [Python](https://www.python.org/downloads/) 3.8 (or newer), [gcloud](https://cloud.google.com/sdk/docs/install) and [curl](https://curl.se/). Make sure you have all those tools installed. |
| 19 | + |
| 20 | +1. Make sure that your Composer environment that you want to migrate is healthy. Refer to [this documentation](https://cloud.google.com/composer/docs/monitoring-dashboard) for more information specific signals indicating good "Environment health" and "Database health". If your environment is not healthy, fix the environment before running this script. |
| 21 | + |
| 22 | +## Limitations |
| 23 | +1. Only Composer 2 environments can be migrated with the script. |
| 24 | + |
| 25 | +1. The Composer 3 environment will be created in the same project and region as the Composer 2 environment. |
| 26 | + |
| 27 | +1. Airflow version of the Composer 3 environment can't be lower than the Airflow version of the source Composer 2 environment. |
| 28 | + |
| 29 | +1. The script currently does not have any error handling mechanism in case of |
| 30 | + failure in running gcloud commands. |
| 31 | + |
| 32 | +1. The script currently does not perform any validation before attempting migration. If e.g. Airflow configuration of the Composer 2 environment is not supported in Composer 3, the script will fail when loading the snapshot. |
| 33 | + |
| 34 | +1. Dags are paused by the script one by one, so with environments containing large number of dags it is advised to pause them manually before running the script as this step can take a long time. |
| 35 | + |
| 36 | +1. Workloads configuration of created Composer 3 environment might slightly differ from the configuration of Composer 2 environment. The script attempts to create an environment with the most similar configuration with values rounded up to the nearest allowed value. |
| 37 | + |
| 38 | +## Usage |
| 39 | + |
| 40 | +### Dry run |
| 41 | +Script executed in dry run mode will only print the configuration of the Composer 3 environment that would be created. |
| 42 | +``` |
| 43 | +python3 composer_migrate.py \ |
| 44 | + --project [PROJECT NAME] \ |
| 45 | + --location [REGION] \ |
| 46 | + --source_environment [SOURCE ENVIRONMENT NAME] \ |
| 47 | + --target_environment [TARGET ENVIRONMENT NAME] \ |
| 48 | + --target_airflow_version [TARGET AIRFLOW VERSION] \ |
| 49 | + --dry_run |
| 50 | +``` |
| 51 | + |
| 52 | +Example: |
| 53 | + |
| 54 | +``` |
| 55 | +python3 composer_migrate.py \ |
| 56 | + --project my-project \ |
| 57 | + --location us-central1 \ |
| 58 | + --source_environment my-composer-2-environment \ |
| 59 | + --target_environment my-composer-3-environment \ |
| 60 | + --target_airflow_version 2.10.2 \ |
| 61 | + --dry_run |
| 62 | +``` |
| 63 | + |
| 64 | +### Migrate |
| 65 | +``` |
| 66 | +python3 composer_migrate.py \ |
| 67 | + --project [PROJECT NAME] \ |
| 68 | + --location [REGION] \ |
| 69 | + --source_environment [SOURCE ENVIRONMENT NAME] \ |
| 70 | + --target_environment [TARGET ENVIRONMENT NAME] \ |
| 71 | + --target_airflow_version [TARGET AIRFLOW VERSION] |
| 72 | +``` |
| 73 | + |
| 74 | +Example: |
| 75 | + |
| 76 | +``` |
| 77 | +python3 composer_migrate.py \ |
| 78 | + --project my-project \ |
| 79 | + --location us-central1 \ |
| 80 | + --source_environment my-composer-2-environment \ |
| 81 | + --target_environment my-composer-3-environment \ |
| 82 | + --target_airflow_version 2.10.2 |
| 83 | +``` |
| 84 | + |
| 85 | +## Troubleshooting |
| 86 | + |
| 87 | +1. Make sure that all prerequisites are met - you have the right permissions and tools, you are authorized and the environment is healthy. |
| 88 | + |
| 89 | +1. Follow up with [support channels](https://cloud.google.com/composer/docs/getting-support) if you need additional help. When contacting Google Cloud Support, make sure to provide all relevant information including complete output from this script. |
0 commit comments