Author: Michael Moore is a Certified Master Anaplanner and Director, Enterprise Planning at HP.
Overview of what this article covers:
- Prepare
- Begin authentication
- Complete authentication using code to fetch token
- Load API client code
- Move to Production
- Generate list of PRODUCTION MODELS to update
- Find the SOURCE MODEL for revisions to sync
- Select a SOURCE REVISION to sync to target models
- Sync multiple models
- Sync one model
- Document line item changes using git
- Git commit changes
- Prep Git commit
- Commit line items for every available revision
Note: Below the article is a full download of the steps and code.
1. Prepare
Before authentication, activate the Python virtual environment. From the gnuemacs menu 'Virtual Envs' activate by selecting the ./venv virtual environment. You may need to restart the Python processes after doing this.
1.1. Begin authentication
Login to Anaplan using OAuth2.
1.2. Complete authentication using code to fetch token
Save the URL from login into value of redirect_response
below.
1.3. Load API client code
Authentication details are in the anaplan = OAuth2Session()
object. Pass a dummy value for api_key
to prevent using the DB access_token
.
2. Move to Production
Two approaches are presented to sync changes to models from DEV models to deployed models. First we show how to sync changes to multiple production models. This assumes that all models in a production workspace are derived from the same development model. Later we show how to sync changes to a single model.
2.1. Generate list of PRODUCTION MODELS to update
From a list of production workspaces, find production models in those workspaces.
2.2. Find the SOURCE MODEL for revisions to sync
Need a target model and revision to discover the source model. The simple approach is to pick an arbitrary production model. The first model listed in its latest revision should be the development model.
For different production models, there may be different source models.
We can check all the production models in our tenant to find if any have pending changes from their source model.
2.3. Select a SOURCE REVISION to sync to target models
The simple approach is to find available revisions for a single production model and pick the latest one.
With multiple production models which may have been sync'd to different revisions, the available revisions should be the intersection of revisions for each production model.
We can consider revisions that apply to all production models. Choose one to sync.
We can consider production models that have not yet been sync'd to the selected revision.
2.4. Sync multiple models
To update multiple models use threads with concurrent.futures https://alexwlchan.net/2019/adventures-with-concurrent-futures/
There are multiple steps for each production model. Queue up the first step for each model. When that step completes, queue up the next step. Continue until all steps are done for all models.
2.5. Sync one model
3. Document line item changes using git
From the target model, export the current line items to a git repository using the GitPython library. We establish a correspondence between ALM revision tags and git commits. This gives us the opportunity to compare line items across multiple revisions using git diff.
https://gitpython.readthedocs.io/en/stable/quickstart.html
Here are the git commands we want to automate.
3.1. Git commit changes
Convert revision data to git author, date, and commit message. Git add the latest line items file. Commit changes to the repo.
Each model has its own git repository. Github says the repository name can only contain ASCII letters, digits, and the characters ".", "-", and "_". Convert model names to repo names by replacing any non-alphanumeric characters with - and then trim starting and trailing - characters.
Run the export to create the line item file. The full filename is path_to_repo/filename
.
From the selected revision, get the name, description, createdBy and createdOn to use in git commit message.
3.2. Prep Git commit
3.3. Commit line items for every available revision
Anaplan returns revisions with latest first. To iterate, we need to reverse this list. Sync a revision and then export it's line items to commit to git. Repeat.
Download available here
If you'd like to download this article, it's available here:
Questions? Leave a comment!