|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": {}, |
| 6 | + "source": [ |
| 7 | + "# Run On Demand" |
| 8 | + ] |
| 9 | + }, |
| 10 | + { |
| 11 | + "cell_type": "code", |
| 12 | + "execution_count": 1, |
| 13 | + "metadata": {}, |
| 14 | + "outputs": [], |
| 15 | + "source": [ |
| 16 | + "from ctm_python_client.core.comm import Environment\n", |
| 17 | + "from aapi import *" |
| 18 | + ] |
| 19 | + }, |
| 20 | + { |
| 21 | + "cell_type": "markdown", |
| 22 | + "metadata": {}, |
| 23 | + "source": [ |
| 24 | + "[AutomationAPI Documentation](https://documents.bmc.com/supportu/API/Monthly/en-US/Documentation/API_Services_RunService.htm#run2)\n", |
| 25 | + "\n", |
| 26 | + "The `run_on_demand()` method in the Control-M Python Client allows you to execute individual jobs, folders, or subfolders dynamically without using Workflow. You do not need to deploy the jobs to the Control-M/EM database and the User Daily job does not need to trigger them. This is useful for event-driven job executions.\n", |
| 27 | + "\n", |
| 28 | + "This guide demonstrates how to use `run_on_demand()` with the `Job`, `Folder`, and `SubFolder` classes.\n", |
| 29 | + "\n", |
| 30 | + "***Requires Control-M/EM version 9.0.21.200***" |
| 31 | + ] |
| 32 | + }, |
| 33 | + { |
| 34 | + "cell_type": "markdown", |
| 35 | + "metadata": {}, |
| 36 | + "source": [ |
| 37 | + "### Code Example:" |
| 38 | + ] |
| 39 | + }, |
| 40 | + { |
| 41 | + "cell_type": "code", |
| 42 | + "execution_count": null, |
| 43 | + "metadata": {}, |
| 44 | + "outputs": [ |
| 45 | + { |
| 46 | + "name": "stdout", |
| 47 | + "output_type": "stream", |
| 48 | + "text": [ |
| 49 | + "+ echo Hello\n", |
| 50 | + "Hello\n", |
| 51 | + "\n", |
| 52 | + "Run Status\n", |
| 53 | + "--------------------------------------------------\n", |
| 54 | + " run_on_demand928 .................. Ended OK\n", |
| 55 | + " HelloJob ...................... Ended OK\n", |
| 56 | + "\n", |
| 57 | + "Run Status\n", |
| 58 | + "--------------------------------------------------\n", |
| 59 | + " TestFolder ........................ Ended OK\n", |
| 60 | + " HelloJob .......................... Ended OK\n", |
| 61 | + "\n" |
| 62 | + ] |
| 63 | + } |
| 64 | + ], |
| 65 | + "source": [ |
| 66 | + "import time\n", |
| 67 | + "# Step 1: Define the Job, Folder, Sub-Folder\n", |
| 68 | + "demand_job = JobCommand('HelloJob', command='echo Hello')\n", |
| 69 | + "demand_sub_folder = SubFolder(\"TestSubFolder\", job_list=[demand_job])\n", |
| 70 | + "demand_folder = Folder(\"TestFolder\", job_list=[demand_job])\n", |
| 71 | + "\n", |
| 72 | + "# Step 2: Define an Environment\n", |
| 73 | + "env = Environment.create_onprem(host='controlm', username='***', password='****')\n", |
| 74 | + "# Step 3: Run the Job On Demand\n", |
| 75 | + "run_demand_job = demand_job.run_on_demand(\n", |
| 76 | + " environment=env,\n", |
| 77 | + " run_as='user',\n", |
| 78 | + " controlm_server='ControlM'\n", |
| 79 | + " )\n", |
| 80 | + "time.sleep(4)\n", |
| 81 | + "run_demand_job.print_output('HelloJob')\n", |
| 82 | + "\n", |
| 83 | + "# Step 4: Run the SubFolder On Demand\n", |
| 84 | + "run_demand_sub_folder = demand_sub_folder.run_on_demand(\n", |
| 85 | + " environment=env,\n", |
| 86 | + " run_as='user',\n", |
| 87 | + " controlm_server='ControlM'\n", |
| 88 | + " )\n", |
| 89 | + "time.sleep(4)\n", |
| 90 | + "run_demand_sub_folder.print_statuses()\n", |
| 91 | + "\n", |
| 92 | + "# Step 5: Run the Folder On Demand\n", |
| 93 | + "run_demand_folder = demand_folder.run_on_demand(\n", |
| 94 | + " environment=env,\n", |
| 95 | + " run_as='user',\n", |
| 96 | + " controlm_server='ControlM'\n", |
| 97 | + " )\n", |
| 98 | + "time.sleep(4)\n", |
| 99 | + "run_demand_folder.print_statuses()\n" |
| 100 | + ] |
| 101 | + }, |
| 102 | + { |
| 103 | + "cell_type": "markdown", |
| 104 | + "metadata": {}, |
| 105 | + "source": [ |
| 106 | + "### Additional Notes:\n", |
| 107 | + "\n", |
| 108 | + "- Ensure that the *Control-M/EM version is 9.0.21.200* or higher. Older versions not support the `run_on_demand()` method.\n", |
| 109 | + "- `Folder`s and `Subfolder`s must include at least one `Job`. If a `Folder` or `SubFolder` does not contain any jobs, an exception will be raised with the error:\n", |
| 110 | + "`\"Run is not allowed for JSON without jobs\"`\n", |
| 111 | + "- The `run_as` user must have the necessary permissions in Control-M.\n", |
| 112 | + "- The `controlm_server` parameter specifies the Control-M server responsible for execution." |
| 113 | + ] |
| 114 | + } |
| 115 | + ], |
| 116 | + "metadata": { |
| 117 | + "kernelspec": { |
| 118 | + "display_name": "venv", |
| 119 | + "language": "python", |
| 120 | + "name": "python3" |
| 121 | + }, |
| 122 | + "language_info": { |
| 123 | + "codemirror_mode": { |
| 124 | + "name": "ipython", |
| 125 | + "version": 3 |
| 126 | + }, |
| 127 | + "file_extension": ".py", |
| 128 | + "mimetype": "text/x-python", |
| 129 | + "name": "python", |
| 130 | + "nbconvert_exporter": "python", |
| 131 | + "pygments_lexer": "ipython3", |
| 132 | + "version": "3.8.9" |
| 133 | + } |
| 134 | + }, |
| 135 | + "nbformat": 4, |
| 136 | + "nbformat_minor": 2 |
| 137 | +} |
0 commit comments