{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "# Auto generation of AI Plugins with Control-M Workbench\n", "\n", "Control-M Workbench version 9.21.100 or above allows users to auto generate python code for their AI plugins. We will use the `ext.autogen` module from the Control-M Python Client to generate all classes of Jobs and ConnectionProfiles of all plugins in a workbench environment.\n", "\n", "If you want to follow along, import the [Example Plugin file](EXAMPLEPG.ctmai) into your workbench." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import ctm_python_client.ext.autogen as autogen\n", "\n", "# this will autogenerate a file called generatedplugins.py with the definitions of all plugins you have in workbench\n", "autogen.generate_ai_plugins_classes(output_file=\"./generatedplugins.py\")\n" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "After calling `generate_ai_plugins_classes`, a new python file is generated" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "vscode": { "languageId": "bat" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "from aapi import *\n", "import attrs\n", "\n", "\n", "\n", "# Auto generated code for AI Plugin Example Plugin\n", " \n", "@attrs.define\n", "class AIJobExampleplugin(AIJob):\n", " _type = AIJob.type_field('Example Plugin')\n", "\n", " \n", " examplefield = AIJob.field('ExampleField')\n", " \n", "\n", " \n", " examplewithdefault = AIJob.field_optional('ExampleFieldWithDefault', default='Some Value')\n", " \n", " \n", "@attrs.define\n", "class ConnectionProfileAIExampleplugin(AIConnectionProfile):\n", " _type = AIConnectionProfile.type_field('Example Plugin')\n", "\n", " \n", " examplepassword = AIConnectionProfile.field('ExamplePassword')\n", " \n", "\n", " \n", " \n" ] } ], "source": [ "!type generatedplugins.py" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "We can now import all objects from this file (Jobs and Connection Profiles):" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "from generatedplugins import *" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "With the new classes for Jobs and Connection Profiles, we can create flows with our Application Integrator Plugins:" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "cp = ConnectionProfileAIExampleplugin(\"TESTCP\", centralized=True, examplepassword=\"password\")\n", "job = AIJobExampleplugin(\"MyExampleJob\", connection_profile=\"TESTCP\", examplefield=\"My field\")" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "from ctm_python_client.core.workflow import *\n", "\n", "w = Workflow.workbench()\n", "w.add(cp)\n", "job_name = w.add(job, inpath=\"TestApplicationIntegrator\")" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Environment information:\n", "+-------------------------+--------------------------------------------------+\n", "|Connection Profile Name |TESTCP |\n", "+-------------------------+--------------------------------------------------+\n", "|Connection Profile Scope |Centralized |\n", "+-------------------------+--------------------------------------------------+\n", "\n", "\n", "=============================================\n", "Operation: Execute\n", "Step name: '[Unnamed step]'\n", "=============================================\n", "\n", "Command line: \n", "-------------\n", "echo \"Example Plugin\"\n", "echo \"=== Job Properties ===\"\n", "echo \"Your Example Field = My field\"\n", "echo \"Your Example Field with Default = Some Value\"\n", "echo \" === Connection profile properties ===\"\n", "echo \"Your example password = ****** \"\n", "\n", "\n", "Exit code is: 0\n", "\n", "\n", "\n", "\n", "Job statistics:\n", "+-------------------------+-------------------------+\n", "|Start Time |20230213085531 |\n", "+-------------------------+-------------------------+\n", "|End Time |20230213085532 |\n", "+-------------------------+-------------------------+\n", "|Elapsed Time |71 |\n", "+-------------------------+-------------------------+\n", "Exit Code = 0\n", "Exit Message = Normal completion\n", "\n", "\n", "\n" ] } ], "source": [ "run = w.run()\n", "print(run.get_output(job_name))" ] } ], "metadata": { "kernelspec": { "display_name": "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" }, "vscode": { "interpreter": { "hash": "d9032b4ca98952f2d8ef7482e3f0387efd8c778fc183f9fd462eb251005e479d" } } }, "nbformat": 4, "nbformat_minor": 2 }