Esempio n. 1
0
    def write_environment_1( self, BUFFER=None ):
        if not BUFFER:
            BUFFER = self.FILE

        BUFFER.write( "\n\n# CYLC SUITE ENVIRONMENT:" )

        # write the static suite variables
        for var, val in self.__class__.suite_env.items():
            BUFFER.write( "\nexport " + var + "=" + str(val) )

        if str(self.__class__.suite_env.get('CYLC_UTC')) == 'True':
            BUFFER.write( "\nexport TZ=UTC" )

        # override and write task-host-specific suite variables
        suite_work_dir = sitecfg.get_derived_host_item( self.suite, 'suite work directory', self.host, self.owner )
        st_env = deepcopy( self.__class__.suite_task_env ) 
        st_env[ 'CYLC_SUITE_RUN_DIR'    ] = sitecfg.get_derived_host_item( self.suite, 'suite run directory', self.host, self.owner )
        st_env[ 'CYLC_SUITE_WORK_DIR'   ] = suite_work_dir
        st_env[ 'CYLC_SUITE_SHARE_DIR'  ] = sitecfg.get_derived_host_item( self.suite, 'suite share directory', self.host, self.owner )
        st_env[ 'CYLC_SUITE_SHARE_PATH' ] = '$CYLC_SUITE_SHARE_DIR' # DEPRECATED
        rsp = self.jobconfig['remote suite path']
        if rsp:
            st_env[ 'CYLC_SUITE_DEF_PATH' ] = rsp
        else:
            # replace home dir with '$HOME' for evaluation on the task host
            st_env[ 'CYLC_SUITE_DEF_PATH' ] = re.sub( os.environ['HOME'], '$HOME', st_env['CYLC_SUITE_DEF_PATH'] )
        for var, val in st_env.items():
            BUFFER.write( "\nexport " + var + "=" + str(val) )

        task_work_dir  = os.path.join( suite_work_dir, self.jobconfig['work sub-directory'] )

        use_login_shell = sitecfg.get_host_item( 'use login shell', self.host, self.owner )
        comms = sitecfg.get_host_item( 'task communication method', self.host, self.owner )

        BUFFER.write( "\n\n# CYLC TASK ENVIRONMENT:" )
        BUFFER.write( "\nexport CYLC_TASK_ID=" + self.task_id )
        BUFFER.write( "\nexport CYLC_TASK_NAME=" + self.task_name )
        BUFFER.write( "\nexport CYLC_TASK_MSG_RETRY_INTVL=" + str( sitecfg.get( ['task messaging','retry interval in seconds'])) )
        BUFFER.write( "\nexport CYLC_TASK_MSG_MAX_TRIES=" + str( sitecfg.get( ['task messaging','maximum number of tries'])) )
        BUFFER.write( "\nexport CYLC_TASK_MSG_TIMEOUT=" + str( sitecfg.get( ['task messaging','connection timeout in seconds'])) )
        BUFFER.write( "\nexport CYLC_TASK_IS_COLDSTART=" + str( self.jobconfig['is cold-start']) )
        BUFFER.write( "\nexport CYLC_TASK_CYCLE_TIME=" + self.tag )
        BUFFER.write( "\nexport CYLC_TASK_LOG_ROOT=" + self.log_root )
        BUFFER.write( '\nexport CYLC_TASK_NAMESPACE_HIERARCHY="' + ' '.join( self.jobconfig['namespace hierarchy']) + '"')
        BUFFER.write( "\nexport CYLC_TASK_TRY_NUMBER=" + str(self.jobconfig['try number']) )
        BUFFER.write( "\nexport CYLC_TASK_COMMS_METHOD=" + comms )
        BUFFER.write( "\nexport CYLC_TASK_SSH_LOGIN_SHELL=" + str(use_login_shell) )
        BUFFER.write( "\nexport CYLC_TASK_WORK_DIR=" + task_work_dir )
        BUFFER.write( "\nexport CYLC_TASK_WORK_PATH=$CYLC_TASK_WORK_DIR") # DEPRECATED
Esempio n. 2
0
    def __init__( self, task_id, suite, jobconfig, submit_num ):

        self.jobconfig = jobconfig

        self.task_id = task_id
        self.suite = suite
        self.logfiles = jobconfig.get( 'log files' )

        self.job_submit_command_template = jobconfig.get('command template')

        # Local job script path: append submit number.
        # (used by both local and remote tasks)
        tag = task_id + TaskID.DELIM + submit_num

        self.local_jobfile_path = os.path.join( \
                sitecfg.get_derived_host_item( self.suite, 'suite job log directory' ), tag )

        # The directory is created in config.py
        self.logfiles.add_path( self.local_jobfile_path )

        task_host = jobconfig.get('task host')
        task_owner  = jobconfig.get('task owner')

        self.remote_shell_template = sitecfg.get_host_item( 'remote shell template', task_host, task_owner )

        if is_remote_host(task_host) or is_remote_user(task_owner):
            # REMOTE TASK OR USER ACCOUNT SPECIFIED FOR TASK - submit using ssh
            self.local = False
            if task_owner:
                self.task_owner = task_owner
            else:
                self.task_owner = None

            if task_host:
                self.task_host = task_host
            else:
                self.task_host = socket.gethostname()

            self.remote_jobfile_path = os.path.join( \
                    sitecfg.get_derived_host_item( self.suite, 'suite job log directory', self.task_host, self.task_owner ), tag )

            # Remote log files
            self.stdout_file = self.remote_jobfile_path + ".out"
            self.stderr_file = self.remote_jobfile_path + ".err"

            # Used in command construction:
            self.jobfile_path = self.remote_jobfile_path

            # Record paths of remote log files for access by gui
            if True:
                # by ssh URL
                url_prefix = self.task_host
                if self.task_owner:
                    url_prefix = self.task_owner + "@" + url_prefix
                self.logfiles.add_path( url_prefix + ':' + self.stdout_file)
                self.logfiles.add_path( url_prefix + ':' + self.stderr_file)
            else:
                # CURRENTLY DISABLED:
                # If the remote and suite hosts see a common filesystem, or
                # if the remote task is really just a local task with a
                # different owner, we could just use local filesystem access.
                # But to use this: (a) special namespace config would be
                # required to indicate we have a common filesystem, and
                # (b) we'd need to consider how the log directory can be
                # specified (for example use of '$HOME' as for remote
                # task use would not work here as log file access is by
                # gui under the suite owner account.
                self.logfiles.add_path( self.stdout_file )
                self.logfiles.add_path( self.stderr_file )
        else:
            # LOCAL TASKS
            self.local = True
            self.task_owner = None
            # Used in command construction:
            self.jobfile_path = self.local_jobfile_path

            # Local stdout and stderr log file paths:
            self.stdout_file = self.local_jobfile_path + ".out"
            self.stderr_file = self.local_jobfile_path + ".err"

            # interpolate environment variables in extra logs
            for idx in range( 0, len( self.logfiles.paths )):
                self.logfiles.paths[idx] = expandvars( self.logfiles.paths[idx] )

            # Record paths of local log files for access by gui
            self.logfiles.add_path( self.stdout_file)
            self.logfiles.add_path( self.stderr_file)

        # set some defaults that can be overridden by derived classes
        self.jobconfig[ 'directive prefix'    ] = None
        self.jobconfig[ 'directive final'     ] = "# FINAL DIRECTIVE"
        self.jobconfig[ 'directive connector' ] = " "
        self.jobconfig[ 'job vacation signal' ] = None

        # overrideable methods
        self.set_directives()
        self.set_job_vacation_signal()
        self.set_scripting()
        self.set_environment()