PROCEDURE activate_ntf (
  automatic_station_name, asn: name = $required
  nodes_list, nl: file = $optional
  load_map, lm: file = $null
  dump_file, df: file = $optional
  job_class, jc: name = system
  notify_after_aborting, naa: boolean = false
  maximum_restart_attempts, maxra: (BY_NAME, ADVANCED) integer 0..65535 = 0
  protocol_trace, pt: (BY_NAME, ADVANCED) boolean = false
  status)

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

"   This request activates NTF.
*IFEND

  VAR
    abort_file_commands: file = $system.network_transfer_facility.ntf_abort_file_commands
    dump_file_specified : boolean = $specified(dump_file)
    dump_file_value : file = $local.$null
    ignore_status: status
    local_status: status
    mannln_file : file = $system.network_transfer_facility.local_names
    nodes_list_value: file = $local.$null
    ntf_library : file = $system.network_transfer_facility.bound_product
    ntf_log_file : file = $fname('$system.network_transfer_facility.ntf_output_'//$mainframe(id))
    options : name
    scf_library : file = $system.batch_device_support.osf$batch_device_support
  VAREND

  IF $specified(nodes_list) THEN
    nodes_list_value = nodes_list
  IFEND

  IF NOT $file(ntf_library permanent) THEN
    EXIT procedure WITH $status(false 'AM' ame$file_not_known ntf_library 'NTF_ACTIVATION')
  IFEND

  IF NOT $file(scf_library permanent) THEN
    EXIT procedure WITH $status(false 'AM' ame$file_not_known scf_library 'NTF_ACTIVATION')
  IFEND

  MANAGE_JOBS
    select_job name=$name('ntf'//$mainframe(id)) job_state=(deferred, queued, initiated) ..
          user_information='Network Transfer Facility (NTF) for NOS/VE' status=local_status
    IF local_status.normal THEN
      IF $size(jmv$selected_jobs) > 0 THEN
        EXIT procedure WITH $status(false 'RA' 0 'An identical NTF job was found. NTF will not be activated')
      IFEND
    ELSE
      EXIT procedure WITH local_status
    IFEND
  QUIT

  include_line 'use_ntf_utility;manage_ntf_local_names;quit;quit' status=ignore_status
  create_file_permit mannln_file g=public status=ignore_status

  IF $specified(load_map) THEN
    options = all
  ELSE
    options = none
  IFEND

  IF dump_file_specified THEN
    dump_file_value = dump_file
  IFEND

  IF $file(abort_file_commands permanent) THEN
    REPEAT
      delete_file file=abort_file_commands status=local_status
    UNTIL NOT local_status.normal
  IFEND

  TASK ring=11
COLLECT_TEXT output=abort_file_commands until='** END OF ABORT COMMANDS **' substitution_mark='#' status=local_status

  VAR
    abort_commands_status: status
    dump_file: file = $fname('$system.network_transfer_facility.ntf_dump_'//$date('Y2M2D2')//'_'//$time('H24MMSS'))
  VAREND

  IF #dump_file_specified# THEN
    dump_file = #dump_file_value#
  IFEND

  display_message message=' ' to=job
  display_message message='**** Please write a PSR against NTF/VE and provide' to=job
  display_message message='**** as supporting material a permanent file backup' t=job
  display_message message='**** of catalog $SYSTEM.NETWORK_TRANSFER_FACILITY.' t=job
  display_message message=' ' to=job

"  The following commands will display the abort information
"  through the use of the debugger.

  set_file_attributes dump_file fc=list pf=continuous
  put_line '1***** ABORT DUMP OF NTF' o=dump_file
  change_file_attributes file=dump_file ring_attributes=(6, 11, 11)
  put_line '       '//$date(iso)//' '//$time(millisecond) o=dump_file.$eoi
  put_line '       '//$job(os_version)//' - '//$default_family//' - CYBER '//..
$processor(model_number, 0)//' Serial '//$processor(serial_number, 0) o=dump_file.$eoi
  put_lines ('', ' ***** ENVIRONMENT:', '') output=dump_file.$eoi
  display_debugging_environment display_option=user_address output=dump_file.$eoi
  display_debug_task_status task_number=all output=dump_file.$eoi
  put_lines ('', ' ***** TRACEBACK:', '') output=dump_file.$eoi
  display_call count=all start=1 display_option=all_calls output=dump_file.$eoi
  put_lines ('', ' ***** JOB LOG:', '') output=dump_file.$eoi
  display_log display_option=200 output=dump_file.$eoi
  put_lines ('', ' ***** REGISTERS:', '') output=dump_file.$eoi
  display_register kind=all_program number=all type=hex output=dump_file.$eoi
  put_lines ('', ' ***** STACK FRAMES:', '') output=dump_file.$eoi
  display_stack_frame count=all start=1 display_option=all output=dump_file.$eoi
  put_lines ('', ' ***** STATIC SECTION:', '') output=dump_file.$eoi
  display_memory section=$static module=$name($current_module) byte_offset=0 byte_count=16 repeat_count=all ..
        output=dump_file.$eoi

** END OF ABORT COMMANDS **
    IF NOT local_status.normal THEN
      IF local_status.condition = ame$file_not_known THEN
        local_status=$status(false 'PF' pfe$unknown_permanent_file $string(abort_file_commands))
      IFEND
      EXIT PROCEDURE WITH local_status
    IFEND
  TASKEND

  SYSTEM_OPERATOR_UTILITY c=system_operation
    JOB jn=$name('ntf'//$mainframe(id)) job_abort_disposition=terminate job_class=job_class ..
          job_destination_usage=ve_local job_execution_ring=6 job_recovery_disposition=terminate ..
          output_disposition=ntf_log_file ..
          substitution_mark='!' user_information='Network Transfer Facility (NTF) for NOS/VE' ..
          status=local_status

      VAR
        ignore_status: status
        maximum_restart_attempts: integer = !maximum_restart_attempts!
        ntf_job_status: status
        ntf_log_file: file = !ntf_log_file!
        nfv$notify_after_aborting: (JOB) boolean = !notify_after_aborting!
        nfv$ntf_log_debug_messages: (JOB) boolean = !protocol_trace!
        number_of_restarts: integer = 0
        parameters: string ='automatic_station_name=!automatic_station_name!'
        status_string_value: list of string
      VAREND

      IF !protocol_trace! THEN
        VAR
          nfv$rhf_protocol_trace : (JOB) string = 'BTFC'
        VAREND
      IFEND

      IF !nodes_list_value! <> $null THEN
        parameters = parameters//' nl=!nodes_list_value!'
      IFEND

      change_message_level il=full status=ignore_status

      set_debug_ring ring=6

      SYSTEM_OPERATOR_UTILITY c=system_operation
        REPEAT
          IF number_of_restarts > 0 THEN
            display_message message='*** NTF has aborted with the following status:' to=job

            status_string_value = $string(ntf_job_status)

            FOR EACH status_string_list_element IN status_string_value DO
              display_message message=status_string_list_element to=job
            FOREND

            display_message message='*** Attempting restart #'//$string(number_of_restarts) to=(job, job_message)
            display_message message='*************************' to=job
            display_log o=ntf_log_file do=all
            change_file_attributes ntf_log_file ra=(11, 11, 11)

" A small (7 1/2 second) delay is forced before the next restart attempt. The delay will reduce the impact
" on the system should NTF continuously abort immediately after beginning execution.

            wait time=0-0-0.00:00:07.500
          IFEND

          execute_task library=(!ntf_library!, !scf_library!) ..
                starting_procedure=nfp$network_transfer_facility ..
                abort_file=!abort_file_commands! parameters=parameters ..
                load_map=!load_map! load_map_options=!options! status=ntf_job_status

          number_of_restarts = number_of_restarts + 1
        UNTIL (number_of_restarts > maximum_restart_attempts)
      END_SYSTEM_OPERATOR_UTILITY

      IF $variable(nfv$notify_after_aborting, defined) THEN
        IF nfv$notify_after_aborting THEN
          send_operator_message m='NTF job failed, see '//ntf_log_file oc=system_operator
        IFEND
      IFEND
    JOBEND

    EXIT procedure WITH local_status WHEN NOT local_status.normal
  END_SYSTEM_OPERATOR_UTILITY

PROCEND activate_ntf
