

# Create jobs and schedules in Control-M Planning
<a name="jobs-schedules-control-m"></a>

Now that you have the job type deployed and a connection profile for AWS connectivity, you can start creating and running jobs.

Each AWS Mainframe Modernization service job consists of a set of attributes, in four sections. Each section can have many attributes. The following list shows some of the more commonly used attributes.
+ General:
  + The job name
  + The application and sub-application that the job belongs to
  + The JCL to submit
  + A link to documentation
+ Scheduling:
  + Months and Days this job is eligible to run
  + Calendars such as a business accounting periods, holidays, or other special dates that cannot be defined algorithmically
  + Time windows
  + Cyclic behavior
+ Prerequisites:
  + Upstream dependencies (usually jobs, which must be completed successfully before this job becomes eligible to run)
  + Resources that might be required
  + User action that might be required
+ Actions performed by Control-M upon completion of the job:
  + Determining job success or failure (usually based on the job's completion codes, but you can override that setting to use output text or checks for a specific status)
  + Notifications, such as email, for failure or success
  + Publishing status for downstream dependencies

As with connection profiles, jobs can be created and deployed [in the GUI](https://documents.bmc.com/supportu/9.0.21/en-US/Documentation/Creating_a_Job.htm) or [in JSON](https://docs.bmc.com/docs/automation-api/monthly/code-reference-1116950299.html) and deployed by using Control-M Automation API.

The following sections examine some common workflow scenarios:
+ [Initiate jobs based on the status code of previous jobs](status-code.md)
+ [Automate job runs on a scheduled frequency](scheduled.md)
+ [Base job runs on events](event-based.md)

# Initiate jobs based on the status of previous jobs
<a name="status-code"></a>

Create a flow of jobs called a workflow. Jobs in the workflow are interconnected with dependencies on successful completion of the previous jobs.

## Using the Control-M Web GUI
<a name="using-gui"></a>

To initiate a job from the Control-M user interface, do the following:

1. In the **Planning** domain, add a new **Workspace**. This opens a canvas with an empty folder object.

1. Select the AWS Mainframe Modernization job type (if you are using the supplied job type template, this is called [M2JOB](https://github.com/aws-samples/aws-mainframe-modernization-controlm-integration/blob/main/assets/AWS-jobs.json)), and drag it onto the folder.

1. After the color of the job type changes to green, drop it. The pane on the right contains the **General**, **Scheduling**, **Prerequisites**, and **Actions** sections. To create the job, see the standard instructions in the [Control-M documentation](https://documents.bmc.com/supportu/9.0.21/en-US/Documentation/Creating_a_Job.htm).

1. Next, you need the **Job Name** values to configure the job types. You can find the **Job Name** values on the **Application** definition screen of the AWS Mainframe Modernization console or by running the [ListBatchJobDefinitions API](https://docs.aws.amazon.com/m2/latest/APIReference/API_ListBatchJobDefinitions.html). For this pilot, repeat steps 2–4 for several jobs, naming each one with any names you choose. Example names are `CBANK`, `CURRENCY`, I`NVFUNDS`, `BROKERAGE`, `RISKMGMT`, and `BANK-SERVICE-Managed-M2`.

1. To connect these jobs into the flow that you want, choose the condition triangle under the job object, and drag it onto the next job. For example, choose the condition triangle under `CBANK`, and drag it onto `CURRENCY`. This action makes `CBANK` the predecessor of `CURRENCY`. By default, `CBANK` must now be completed successfully before CURRENCY becomes eligible to run.

The following screenshot shows the Control-M Planning view of the basic job flow.



![\[Job flow on the left and properties on the right.\]](http://docs.aws.amazon.com/prescriptive-guidance/latest/control-m-batch-scheduler/images/workflow-control-m-web-1.png)


*Image provided courtesy of BMC Software, Inc. ©2022*

## Using JSON
<a name="using-json"></a>

The same flow can be coded in JSON:

```
{
  "Defaults": {
    "Application": "AWSM2",
    "SubApplication": "Replatform-Managed",
    "Job": {
      "Host": "ctm-worker",
      "Output": {}
    }
  },
  "jog-managed-m2": {
    "Type": "Folder",
    "ControlmServer": "psctm",
    "OrderMethod": "Manual",
    "SiteStandard": "_z_DemoBusinessFlows",
    "CBANK": {
      "Type": "Job:AWS Mainframe Modernization",
      "ConnectionProfile": "MANAGED-M2-REPLATFORM",
      "JCL Name": "iefbr14",
      "Retrieve CloudWatch Logs": "checked",
      "Action": "Start Batch Job",
      "Application Version": "1"
    },
    "CURRENCY": {
      "Type": "Job:AWS Mainframe Modernization",
      "ConnectionProfile": "MANAGED-M2-REPLATFORM",
      "JCL Name": "iefbr14",
      "Retrieve CloudWatch Logs": "checked",
      "Action": "Start Batch Job",
      "Application Version": "1"
    },
    "BROKERAGE": {
      "Type": "Job:AWS Mainframe Modernization",
      "ConnectionProfile": "MANAGED-M2-REPLATFORM",
      "JCL Name": "iefbr14",
      "Retrieve CloudWatch Logs": "checked",
      "Action": "Start Batch Job",
      "Application Version": "1"
    },
    "INVFUNDS": {
      "Type": "Job:AWS Mainframe Modernization",
      "ConnectionProfile": "MANAGED-M2-REPLATFORM",
      "JCL Name": "iefbr14",
      "Retrieve CloudWatch Logs": "checked",
      "Action": "Start Batch Job",
      "Application Version": "1"
    },
    "RISKMGMT": {
      "Type": "Job:AWS Mainframe Modernization",
      "ConnectionProfile": "MANAGED-M2-REPLATFORM",
      "JCL Name": "iefbr14",
      "Retrieve CloudWatch Logs": "checked",
      "Action": "Start Batch Job",
      "Application Version": "1"
    },
    "BANK-SERVICE-Managed-M2": {
      "Type": "Job:SLAManagement",
      "ServiceName": "Bank Service - Managed M2",
      "RunAs": "ctmagent",
      "CompleteBy": {
        "Time": "12:00",
        "Days": "0"
      }
    },
    "leftbranch": {
      "Type": "Flow",
      "Sequence": [
        "CURRENCY",
        "RISKMGMT",
        "BANK-SERVICE-Managed-M2"
      ]
    },
    "middlebranch": {
      "Type": "Flow",
      "Sequence": [
        "CBANK",
        "CURRENCY",
        "INVFUNDS",
        "BANK-SERVICE-Managed-M2"
      ]
    },
    "rightbranch": {
      "Type": "Flow",
      "Sequence": [
        "CURRENCY",
        "BROKERAGE",
        "BANK-SERVICE-Managed-M2"
      ]
    }
  }
}
```

To deploy this flow, use the deploy service:

```
ctm deploy folder-MANAGED-M2-REPLATFORM.json
```

# Automate job runs on a scheduled frequency
<a name="scheduled"></a>

Using the flow that you created in the previous steps, you can add basic and runtime scheduling.
+ Basic scheduling defines which days a job can run (for example, every weekday, only on working days, month end, or quarter end).
+ Runtime scheduling determines when a job will run on the day that it's eligible to run (for example, every hour, after specified resources are available, or only after manual confirmation).

You can set the basic and runtime scheduling on the **Scheduling** tab.

# Base job runs on events
<a name="event-based"></a>

Control-M Managed File Transfer (MFT) is an FTP/SFTP client and server that you can use to watch and transfer files between a local host and a remote host. For more information about defining a File Transfer job, see the [Control-M documentation](https://documents.bmc.com/supportu/9.0.21/en-US/Documentation/File_Transfer_Job.htm).

This pilot uses the File Transfer job to watch for a file-creation event of a file with the .poc extension in the `/bmcfile`  folder in an S3 bucket named `bmc-poc-bucket`. When that event occurs, the Control-M job is initiated to run the next job. You can optionally pass the full path, including the bucket name.