{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Working with Application Integrator\n", "\n", "Control-M Application Integrator is a web-based application that allows you to create\n", "custom job types that you can easily deploy in the Control-M environment. These\n", "jobs can be managed alongside any Control-M job, which enables you to manage\n", "on-premises and multi-cloud application workflows for commercial, custom, and home-grown applications through a single platform.\n", "\n", "Control-M Python Client allows you to work with Application Integrator Job Types by providing a base class which you can create your own Application Integrator job types" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Building Custom Application Integrator Job Types with `AIJob`\n", "\n", "You create Application Integrator Job types through the Application Integrator web interface. After you deploy a job to an Agent, you can use it as any other Job type from the job palette in the Planning domain. \n", "\n", "To use the new job type that you create in Control-M Python Client, you need to create the JobType as a class in your code. This is made easy by the `AIJob` class that serves as the base class that provides all the necessary functionalities to make your class work as a valid Automation API definition." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's see a simple example.\n", "\n", "Below we create a simple Application Integrator JobType called **AI SSHCommand**. It accepts two paramaters that we define in the Application Integrator web interface: **Command** and **Flags** in addition to the Connection Profile.\n", "\n", "*Note*: You cannot add or edit Application Integrator connection profiles in Control-M Python Client. You must add them in the Application Integrator web interface.\n", "\n", "\n", "[![AI Job parameters](image.png \"AI Job Parameters\")](image.png)\n", "\n", "Let's create the class in Control-M Python Client" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from ctm_python_client.core.comm import *\n", "from ctm_python_client.core.workflow import *\n", "\n", "from aapi import *\n", "import attrs\n", "\n", "# All JobTypes are decorated with attrs\n", "\n", "@attrs.define\n", "class AIJobSSHCommand(AIJob): # We derive from AIJob, the name of the class can be any valid python class name\n", " _type = AIJob.type_field('AI SSHCommand') # We add a \"type\" field, with the same name you would see in the web interface.\n", " # the name in type IS important and should match the one seen in the Web Interface\n", " # in the Planning section\n", "\n", " command = AIJob.field('Command') # the field name argument needs to match the one in the Web interface\n", " # the name of the field (lower case command) can be any valid python variable name\n", "\n", " flags = AIJob.field_optional('Flags') # this is an optional field, similar to AIJob.field() but not mandatory to use\n", "\n", "\n" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "{\n", " \"AIfolder\": {\n", " \"Type\": \"Folder\",\n", " \"MySSHCommand\": {\n", " \"Type\": \"Job:ApplicationIntegrator:AI SSHCommand\",\n", " \"ConnectionProfile\": \"HOSTCP\",\n", " \"AI-Command\": \"ls\",\n", " \"AI-Flags\": \"-q\"\n", " }\n", " }\n", "}\n" ] } ], "source": [ "# Let's check that the Automation API Json is ok\n", "\n", "workflow = BaseWorkflow() # BaseWorkflow is a workflow which is not connected to any environment\n", "aijob = AIJobSSHCommand('MySSHCommand',\n", " connection_profile='HOSTCP',\n", " command='ls',\n", " flags='-q')\n", "workflow.add(aijob, inpath='AIfolder')\n", "\n", "print(workflow.dumps_json(indent=2))\n" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "{\n", " \"AIfolder\": {\n", " \"Type\": \"Folder\",\n", " \"MySSHCommand\": {\n", " \"Type\": \"Job:ApplicationIntegrator:AI AI SSHCommand\",\n", " \"ConnectionProfile\": \"HOSTCP\",\n", " \"AI-Command\": \"ls\"\n", " }\n", " }\n", "}\n" ] } ], "source": [ "# Let's check that the Automation API Json is ok\n", "\n", "workflow = BaseWorkflow() # BaseWorkflow is a workflow which is not connected to any environment\n", "\n", "# the flags variable is a optional field, we can create job without an optional field\n", "aijob = AIJobSSHCommand('MySSHCommand',\n", " connection_profile='HOSTCP',\n", " command='ls')\n", "workflow.add(aijob, inpath='AIfolder')\n", "\n", "print(workflow.dumps_json(indent=2))" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.10.4 ('venv': venv)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.4" }, "orig_nbformat": 4, "vscode": { "interpreter": { "hash": "e36608863334e111ac1975278d851976534d4d97e80edd449207481e04c86242" } } }, "nbformat": 4, "nbformat_minor": 2 }