These examples provide common usage scenarios for jobs.
Prerequisite:
Creating a Simple Job
This JSON file creates a simple job with no schedule.
-
Create a JSON file with the following contents.
-
Add the job from the DC/OS CLI.
Alternatively, add the job using the API.
Creating a Job with a Schedule
-
Create a JSON file with the following contents.
-
Add the job.
Creating a Job and Associating a Schedule using the API
-
Add a job without a schedule using the instructions above.
-
Create a JSON file with the following contents. This is the schedule for your job.
-
Add the schedule and associate it with the job.
Via the DC/OS CLI:
Via the API:
You can associate a schedule with more than one job.
Creating a Partitioned Jobs Environment
In this example, a partitioned jobs environment is created with the DC/OS UI. This allows you to restrict user access per job, or per job group. The jobs are created in a jobs group named batch
, which is a child of a jobs group named dev
.
The jobs groups are then assigned permissions to users Cory
and Alice
to restrict access.
Prerequisites:
- You must be logged in as a
superuser
.
-
Log into the DC/OS UI as a user with the
superuser
permission.Figure 1. DC/OS Enterprise login
-
Create the partitioned jobs.
-
Select Jobs and click CREATE A JOB.
-
In the ID field, type
dev.batch.job1
. -
In the Command field, type
sleep 1000
(or another valid shell command) and click CREATE A JOB.Figure 2. New job screen
This creates a job in this directory structure in DC/OS: Jobs > dev > batch > job1.
-
Click the + icon in the top right corner to create another job.
Figure 3. Create another job
-
In the ID field, type
dev.batch.job2
. -
In the Command field, type
sleep 1000
(or another valid shell command) and click CREATE A JOB. You should have two jobs:Figure 4. Jobs > dev > batch screen
-
-
Run the jobs.
-
Click Jobs > dev > batch > job1 and click Run Now.
Figure 5. Run now menu
-
Click Jobs > dev > batch > job2 and click Run Now.
-
-
Assign permissions to the jobs.
-
Select Organization > Users and create new users named
Cory
andAlice
.Figure 6. Create a new user
-
Select the user Cory and grant access to
job1
. -
From the Permissions tab, click ADD PERMISSION and toggle the INSERT PERMISSION STRING button to manually enter the permissions.
Figure 7. Add permissions for user ‘Cory’
-
Copy and paste the permissions in the Permissions Strings field. Specify your job group (
dev/batch
), job name (job1
), and action (read
). Actions can be eithercreate
,read
,update
,delete
, orfull
. To permit more than one operation, use a comma to separate them, for example:dcos:service:metronome:metronome:jobs:/dev.batch.job1 read,update
. -
Click ADD PERMISSIONS and then Close.
-
Repeat these steps for user Alice, replacing
job1
withjob2
in the permissions.
-
-
Log out and log back in as your new user to verify the permissions. The user should now have the designated level of access to
dev/batch/job1
anddev/batch/job2
inside the Jobs tab. For example, if you log in as Alice, you should only see jobs2:Figure 8. Restricted view for ‘Alice’
Creating a job which joins a container network
In order to have a job join a network, specify the “networks” field. The following job joins the dcos
network, outputs its IP information, then sleeps:
The field networks
works identical to the networks
field in Marathon.