PROCEDURE (HIDDEN) rap$establish_job_classes (
  initiate_jobs: boolean = $required
  status)


*IF $variable(rav$proc_doc,declared)<>'UNKNOWN'

" PURPOSE:
"   This procedure establishes job classes.
"
" DESIGN:
"   This procedure is called by OSP$INITIALIZE_VIRTUAL_SYSTEM on a normal deadstart and later by
"   ACTIVATE_JOB_ENVIRONMENT on all deadstarts.
"   When called by OSP$INITIALIZE_VIRTUAL_SYSTEM, the system scheduling profile is recovered and
"   initiation of jobs is prevented for classes other than SYSTEM and MAINTENANCE.
"   When called by ACTIVATE_JOB_ENVIRONMENT, the system scheduling profile is refreshed in memory
"   and initiation of jobs is allowed.
"
" NOTES:
"   When this procedure is called by the ACTIVATE_JOB_ENVIRONMENT command an event message is
"   used to help isolate where an error originated from.  The variable RAV$EVENT_MESSAGE is set for
"   establishing job classes and will be displayed along with the error should one occur.  The event
"   message is cleared if the procedure finishes without an error.
*IFEND


  IF $variable(rav$event_message, nonlocal) THEN
    "$FORMAT=OFF
    VAR
      rav$event_message: (XREF) status
    VAREND
    "$FORMAT=ON"
    rav$event_message=$status(false, 'RA', rae$establishing_error, 'job classes')
  IFEND

  " Create the subcatalog for scheduling.  Refresh or recover the system
  " scheduling profile.

  "$FORMAT=OFF
  VAR
    ignore_status: status
  VAREND
  "$FORMAT=ON"
  $system.create_catalog catalog=$system.scheduling status=ignore_status

  IF $value(initiate_jobs) THEN
    "$manage_active_scheduling
    $system.osf$builtin_library.manage_active_scheduling
      FOR EACH jc IN $profile_summary(job_class) DO
        change_job_class jc initiation_level=$job_class(jc initiation_level)
      FOREND
    QUIT save_change=true
  ELSE
    "$manage_active_scheduling
    $system.osf$builtin_library.manage_active_scheduling
    QUIT save_change=false
  IFEND

  IF $variable(rav$event_message, local) THEN
    rav$event_message.normal=true
  IFEND

PROCEND rap$establish_job_classes
