?? RIGHT := 110 ??
?? NEWTITLE := 'INSTALL_SOFTWARE Utility: RAP$SUBMIT_BATCH_JOBS Interface.' ??
MODULE ram$submit_batch_jobs;

{ PURPOSE:
{   This module contains the interface that sets up and submits the batch
{   jobs required to perform an installation event.
{
{ DESIGN:
{   The compiled module resides in RAF$LIBRARY.
{
{ NOTES:
{

?? NEWTITLE := 'Global Declarations Referenced by This Module', EJECT ??
?? PUSH (LISTEXT := ON) ??
*copyc rac$control_file_name
*copyc ost$status
*copyc rat$installation_control_record
*copyc rat$path
?? POP ??
*copyc i#current_sequence_position
*copyc clp$include_line
*copyc clp$put_job_command_response
*copyc clp$trimmed_string_size
*copyc jmp$system_job
*copyc rap$set_file_retention
*copyc rap$write_file_from_memory
?? OLDTITLE ??
?? NEWTITLE := '[XDCL] rap$submit_batch_jobs', EJECT ??

{ PURPOSE:
{   This interface submits the batch jobs required to complete the
{   installation event.
{
{ DESIGN:
{   The installation control file is the mechanism used to pass processing
{   information to the batch jobs.  An installation control file is created
{   from the processing sequence (referenced by the installation control
{   record).  Each batch job will access the installation control file and
{   re-create the processing sequence from it.
{
{   The job processing records from the installation control record contains
{   a record for each job that is required and is used for setting up jobs.
{   The job setup is handled a little differently when a job is submitted
{   from the console than a terminal.
{
{   When submitted from the console the job is created with job class of
{   system.  Also a request for operator action will be given upon any
{   error.  (These are not included in a job submitted from a terminal.)
{
{   In order to install into a family other than that of the current job,
{   the batch job must be in the SYSTEM_OPERATOR_UTILITY.  To still allow
{   testing, SOU is only entered when the batch job is submitted from the
{   console (jmp$system_job=TRUE).
{
{   Each job log is written to EOI of a permanent log file.  The name of the
{   log files are found in the job processing record for each job.
{
{ NOTES:
{   The version of SOU that resides on the deadstart tape is invoked
{   rather than the $SYSTEM (osf$command_library) version.  This avoids
{   problems that may occur if the $SYSTEM version is obsolete.
{
{   ** If installation to other families is to be allowed from a terminal,
{      another scheme will be needed to support testing.  (See above.)
{
{   ** The system catalog default should be coded as a constant.
{

  PROCEDURE [XDCL] rap$submit_batch_jobs
    (VAR installation_control_record {input} : rat$installation_control_record;
     VAR status: ost$status);


    VAR
      command_line: string (2500),
      command_line_length: integer,
      current_job: rat$job_count,
      job_identifier: ost$name,
      job_identifier_length: integer,
      installation_control_file: rat$path,
      install_software_command: rat$path,
      length: integer,
      line: string (osc$max_string_size),
      log_file: rat$path,
      system_catalog: rat$path;


    status.normal := TRUE;

    create_control_file (installation_control_record, installation_control_file, status);
    IF NOT status.normal THEN
      RETURN;
    IFEND;

{ Assemble the command call to INSTALL_SOFTWARE, the program descriptor lives on the builtin library.

    system_catalog := installation_control_record.processing_header_p^.installation_defaults.system_catalog;
    IF system_catalog.size = 0 THEN
      system_catalog.path := ':$SYSTEM.$SYSTEM';
      system_catalog.size := clp$trimmed_string_size (system_catalog.path);
    IFEND;

    STRINGREP (install_software_command.path, install_software_command.size, system_catalog.
          path (1, system_catalog.size), '.OSF$BUILTIN_LIBRARY.INSTALL_SOFTWARE');

{ Each record of the job processing records defines a job that must be submitted.

    FOR current_job := 1 TO UPPERBOUND (installation_control_record.job_processing_records_p^) DO

      job_identifier := installation_control_record.job_processing_records_p^ [current_job].job_identifier;
      job_identifier_length := clp$trimmed_string_size (job_identifier);

      { Assemble the path to the log file under the installation identifier catalog.

      STRINGREP (log_file.path, log_file.size, installation_control_record.processing_header_p^.
            installation_defaults.installation_logs.path (1, installation_control_record.processing_header_p^.
            installation_defaults.installation_logs.size), '.',
            installation_control_record.processing_header_p^.installation_identifier
            (1, clp$trimmed_string_size (installation_control_record.processing_header_p^.
            installation_identifier)), '.', installation_control_record.
            job_processing_records_p^ [current_job].log_file_name
            (1, clp$trimmed_string_size (installation_control_record.job_processing_records_p^ [current_job]
            .log_file_name)), '.$eoi');

      { Assemble the SCL commands that will execute in the batch job.

      IF jmp$system_job () THEN

?? FMT (FORMAT := OFF) ??
        STRINGREP (command_line, command_line_length,
          'JOB jn=', job_identifier (1, job_identifier_length), ' jc=system',
                 ' odi=', log_file.path (1, log_file.size), '; ',
            'WHEN any_fault DO; ',
              '$system.put_line l='' ''//$strrep(osv$status) o=$job_log; ',
              'send_operator_message message=''Job ',
                     job_identifier (1, job_identifier_length),
                     ' failed.  See ', log_file.path (1, log_file.size-5),
                     ' for details.'' operator_class=system_operator; ',
            'WHENEND;',
            'create_variable n=rav$status k=status;',
            '$system.osf$sou_library.system_operator_utility c=system_administration; ',
               install_software_command.path (1, install_software_command.size), '; ',
                'rap$perform_installation ',
                     ' icf=', installation_control_file.path (1, installation_control_file.size),
                     ' ji=', job_identifier (1, job_identifier_length), ' status=rav$status; ',
              'quit; ',
            'quit; ',
            'IF NOT rav$status.normal THEN;',
              'IF $condition(rav$status.condition) = ''RAE$SUBPRODUCTS_FAILED_INSTALL'' THEN;',
                'cancel any_fault;',
                'send_operator_message message=''Errors in job ',
                       job_identifier (1, job_identifier_length),
                       '.  See ', log_file.path (1, log_file.size-5),
                       ' for details.'' operator_class=system_operator; ',
              'ELSE;',
                'cancel any_fault;',
                '$system.put_line l='' ''//$strrep(rav$status) o=$job_log; ',
                'send_operator_message message=''Failure in job ',
                       job_identifier (1, job_identifier_length),
                       '.  See ', log_file.path (1, log_file.size-5),
                       ' for details.'' operator_class=system_operator; ',
              'IFEND;',
            'IFEND;',
          'JOBEND');
?? FMT (FORMAT := ON) ??

      ELSE {not system job}

?? FMT (FORMAT := OFF) ??
        STRINGREP (command_line, command_line_length,
          'JOB jn=', job_identifier (1, job_identifier_length),
                ' odi=', log_file.path (1, log_file.size), '; ',
            '$system.osf$sou_library.system_operator_utility; ',
               install_software_command.path (1, install_software_command.size), '; ',
                'rap$perform_installation ',
                     ' icf=', installation_control_file.path (1, installation_control_file.size),
                     ' ji=', job_identifier (1, job_identifier_length), '; ',
              'quit; ',
            'quit; ',
          'JOBEND');
?? FMT (FORMAT := ON) ??

      IFEND;

      clp$include_line (command_line (1, command_line_length), TRUE, osc$null_name, status);
      IF NOT status.normal THEN
        RETURN;
      IFEND;

      { Display job identifier to $response.

      STRINGREP (line, length, '0Submitted job ', job_identifier (1, job_identifier_length), '.');
      clp$put_job_command_response (line (1, length), status);

    FOREND;

  PROCEND rap$submit_batch_jobs;

?? OLDTITLE ??
?? NEWTITLE := 'create_control_file', EJECT ??

{ PURPOSE:
{   This procedure creates the installation control file for the current
{   installation event.
{
{ DESIGN:
{   The installation control file is created as a file copy of the
{   processing sequence that resides in memory.  Its purpose is to provide
{   batch jobs with access to the same information originally contained in
{   the processing sequence.
{
{   The current sequence position of the processing sequence is assumed to
{   be eoi.
{
{   A retention period of 7 days is placed on the log file.
{
{ NOTES:
{

  PROCEDURE create_control_file
    (VAR installation_control_record {input} : rat$installation_control_record;
     VAR installation_control_file: rat$path;
     VAR status: ost$status);


    CONST
      retention_period = 7;


    status.normal := TRUE;

    { Assemble the path to the installation control file using the installation logs path,
    { the installation identifier and the installation control file name.

    STRINGREP (installation_control_file.path, installation_control_file.size,
          installation_control_record.processing_header_p^.installation_defaults.installation_logs.
          path (1, installation_control_record.processing_header_p^.installation_defaults.
          installation_logs.size), '.', installation_control_record.processing_header_p^.
          installation_identifier (1, clp$trimmed_string_size
          (installation_control_record.processing_header_p^.installation_identifier)), '.',
          rac$control_file_name);

    rap$write_file_from_memory (installation_control_file.path (1, installation_control_file.size),
          i#current_sequence_position (installation_control_record.processing_seq_p),
          installation_control_record.processing_seq_p, status);
    IF NOT status.normal THEN
      RETURN;
    IFEND;

    { Set retention date on the installation control file just created.

    rap$set_file_retention (installation_control_file.path (1, installation_control_file.size),
          retention_period, status);

  PROCEND create_control_file;
MODEND ram$submit_batch_jobs;
