示例#1
0
 def format(self):
     result = copy.copy(self.__dict__)
     if self.start_time:
         result['start_time'] = timestamp_to_str(self.start_time)
     if self.end_time:
         result['end_time'] = timestamp_to_str(self.end_time)
     result['run_time'] = _get_run_time(self.start_time, self.end_time)
     return result
示例#2
0
 def format(self):
     result = copy.copy(self.__dict__)
     if self.start_time:
         result['start_time'] = timestamp_to_str(self.start_time)
     if self.end_time:
         result['end_time'] = timestamp_to_str(self.end_time)
     result['run_time'] = _get_run_time(self.start_time, self.end_time)
     return result
示例#3
0
    def _get_instance_end_text(self, instance_data, jobs_data):
        """Format text version of the workflow instance completion message.

        Args:
            instance_data: The data of the completed workflow instance.
            jobs_data: The list of data describing jobs in the workflow
                instance.

        Returns:
            Text message describing the workflow instance.
        """
        TEXT_TEMPLATE = """\
Workflow %(workflow)s instance %(instance)s started at %(start_time)s \
finished after %(run_time)s at %(end_time)s with status %(status)s.

Details are available at  http://%(ui_host)s:%(ui_port)s/jobs/?\
workflow=%(workflow)s&instance=%(instance)s

Jobs:

Name | Last start | Last end | Run time | Status | Url
%(jobs)s
"""
        jobs = ''
        for job_data in jobs_data:
            jobs += '%s | ' % job_data.job
            if not job_data.last_start_time:
                jobs += '| | '
            else:
                jobs += '%s | ' % timestamp_to_str(job_data.last_start_time)
                if not job_data.last_end_time:
                    jobs += '| | '
                else:
                    jobs += '%s | ' % timestamp_to_str(job_data.last_end_time)
                    delta = int(job_data.last_end_time -
                                job_data.last_start_time)
                    jobs += '%s | ' % datetime.timedelta(seconds=delta)
            jobs += '%s | ' % Status.to_string(job_data.status)
            jobs += ('http://%s:%s/executions/?workflow=%s&instance=%s&'
                     'job=%s\n' % (self._ui_host,
                                   self._ui_port,
                                   job_data.workflow,
                                   job_data.instance,
                                   job_data.job))
        start_time = timestamp_to_str(instance_data.start_time)
        end_time = timestamp_to_str(instance_data.end_time)
        delta = int(instance_data.end_time - instance_data.start_time)
        run_time = datetime.timedelta(seconds=delta)
        status = Status.to_string(instance_data.status)
        return TEXT_TEMPLATE % {'workflow': instance_data.workflow,
                                'instance': instance_data.instance,
                                'start_time': start_time,
                                'end_time': end_time,
                                'run_time': run_time,
                                'status': status,
                                'ui_host': self._ui_host,
                                'ui_port': self._ui_port,
                                'jobs': jobs}
示例#4
0
    def _get_instance_end_text(self, instance_data, jobs_data):
        """Format text version of the workflow instance completion message.

        Args:
            instance_data: The data of the completed workflow instance.
            jobs_data: The list of data describing jobs in the workflow
                instance.

        Returns:
            Text message describing the workflow instance.
        """
        TEXT_TEMPLATE = """\
Workflow %(workflow)s instance %(instance)s started at %(start_time)s \
finished after %(run_time)s at %(end_time)s with status %(status)s.

Details are available at  http://%(ui_host)s:%(ui_port)s/jobs/?\
workflow=%(workflow)s&instance=%(instance)s

Jobs:

Name | Last start | Last end | Run time | Status | Url
%(jobs)s
"""
        jobs = ''
        for job_data in jobs_data:
            jobs += '%s | ' % job_data.job
            if not job_data.last_start_time:
                jobs += '| | '
            else:
                jobs += '%s | ' % timestamp_to_str(job_data.last_start_time)
                if not job_data.last_end_time:
                    jobs += '| | '
                else:
                    jobs += '%s | ' % timestamp_to_str(job_data.last_end_time)
                    delta = int(job_data.last_end_time -
                                job_data.last_start_time)
                    jobs += '%s | ' % datetime.timedelta(seconds=delta)
            jobs += '%s | ' % Status.to_string(job_data.status)
            jobs += ('http://%s:%s/executions/?workflow=%s&instance=%s&'
                     'job=%s\n' %
                     (self._ui_host, self._ui_port, job_data.workflow,
                      job_data.instance, job_data.job))
        start_time = timestamp_to_str(instance_data.start_time)
        end_time = timestamp_to_str(instance_data.end_time)
        delta = int(instance_data.end_time - instance_data.start_time)
        run_time = datetime.timedelta(seconds=delta)
        status = Status.to_string(instance_data.status)
        return TEXT_TEMPLATE % {
            'workflow': instance_data.workflow,
            'instance': instance_data.instance,
            'start_time': start_time,
            'end_time': end_time,
            'run_time': run_time,
            'status': status,
            'ui_host': self._ui_host,
            'ui_port': self._ui_port,
            'jobs': jobs
        }
示例#5
0
 def format(self):
     result = copy.copy(self.__dict__)
     result['status'] = Status.to_string(self.status)
     if self.last_start_time:
         result['last_start_time'] = timestamp_to_str(self.last_start_time)
     if self.last_end_time:
         result['last_end_time'] = timestamp_to_str(self.last_end_time)
     result['run_time'] = _get_run_time(self.last_start_time,
                                        self.last_end_time)
     return result
示例#6
0
 def format(self):
     result = copy.copy(self.__dict__)
     result['status'] = Status.to_string(self.status)
     if self.last_start_time:
         result['last_start_time'] = timestamp_to_str(self.last_start_time)
     if self.last_end_time:
         result['last_end_time'] = timestamp_to_str(self.last_end_time)
     result['run_time'] = _get_run_time(self.last_start_time,
                                        self.last_end_time)
     return result
示例#7
0
 def format(self):
     result = copy.copy(self.__dict__)
     result['status'] = Status.to_string(self.status)
     if self.last_start_time:
         result['last_start_time'] = timestamp_to_str(self.last_start_time)
     if self.last_end_time:
         result['last_end_time'] = timestamp_to_str(self.last_end_time)
     # TODO(pawel): run_time can be inferred from start and end time.  To
     # make it easier to parse in the UI, we should send start and end time
     # in seconds.
     result['run_time'] = _get_run_time(self.last_start_time,
                                        self.last_end_time)
     result['running_instance_number'] = str(self.running_instance_number)
     return result
示例#8
0
 def __str__(self):
     if self.start_time:
         start_time = timestamp_to_str(self.start_time)
     else:
         start_time = str(self.start_time)
     if self.end_time:
         end_time = timestamp_to_str(self.end_time)
     else:
         end_time = str(self.end_time)
     return ('ExecutionRecord(info=%s, instance=%s, start_time=%s, '
             'end_time=%s, exit_code=%s, events=%s, properties=%s, '
             'logs=%s)' %
             (self.info, self.instance, start_time, end_time,
              self.exit_code, self.events, self.properties, self.logs))
示例#9
0
 def format(self):
     result = copy.copy(self.__dict__)
     result['status'] = Status.to_string(self.status)
     if self.last_start_time:
         result['last_start_time'] = timestamp_to_str(self.last_start_time)
     if self.last_end_time:
         result['last_end_time'] = timestamp_to_str(self.last_end_time)
     # TODO(pawel): run_time can be inferred from start and end time.  To
     # make it easier to parse in the UI, we should send start and end time
     # in seconds.
     result['run_time'] = _get_run_time(self.last_start_time,
                                        self.last_end_time)
     result['running_instance_number'] = str(self.running_instance_number)
     return result
示例#10
0
 def __str__(self):
     if self.start_time:
         start_time = timestamp_to_str(self.start_time)
     else:
         start_time = str(self.start_time)
     if self.end_time:
         end_time = timestamp_to_str(self.end_time)
     else:
         end_time = str(self.end_time)
     return ('ExecutionRecord(info=%s, instance=%s, start_time=%s, '
             'end_time=%s, exit_code=%s, events=%s, properties=%s, '
             'logs=%s)' %
             (self.info, self.instance, start_time, end_time,
              self.exit_code, self.events, self.properties, self.logs))
示例#11
0
 def format(self):
     result = copy.copy(self.__dict__)
     if not self.owner:
         result['owner'] = ''
     result['expiration_time'] = timestamp_to_str(self.expiration_time)
     result['data'] = token_data_to_str(self.data)
     return result
示例#12
0
 def format(self):
     result = copy.copy(self.__dict__)
     if not self.owner:
         result['owner'] = ''
     result['expiration_time'] = timestamp_to_str(self.expiration_time)
     result['data'] = token_data_to_str(self.data)
     return result
示例#13
0
 def format(self):
     result = copy.copy(self.__dict__)
     result['next_run_time'] = timestamp_to_str(self.next_run_time)
     result['overrun_policy'] = OverrunPolicy.to_string(self.overrun_policy)
     result['max_running_instances'] = str(self.max_running_instances)
     result['parser_params'] = str(self.parser_params)
     return result
示例#14
0
 def format(self):
     result = copy.copy(self.__dict__)
     result['next_run_time'] = timestamp_to_str(self.next_run_time)
     result['overrun_policy'] = OverrunPolicy.to_string(self.overrun_policy)
     result['max_running_instances'] = str(self.max_running_instances)
     result['parser_params'] = str(self.parser_params)
     return result
示例#15
0
 def _get_job_execution_params(self, job_execution_data):
     start_time = timestamp_to_str(job_execution_data.start_time)
     return {'workflow': job_execution_data.workflow,
             'instance': job_execution_data.instance,
             'job': job_execution_data.job,
             'execution': job_execution_data.execution,
             'info': job_execution_data.info,
             'start_time': start_time,
             'ui_host': self._ui_host,
             'ui_port': self._ui_port}
示例#16
0
 def _get_job_execution_params(self, job_execution_data):
     start_time = timestamp_to_str(job_execution_data.start_time)
     return {
         'workflow': job_execution_data.workflow,
         'instance': job_execution_data.instance,
         'job': job_execution_data.job,
         'execution': job_execution_data.execution,
         'info': job_execution_data.info,
         'start_time': start_time,
         'ui_host': self._ui_host,
         'ui_port': self._ui_port
     }
示例#17
0
    def __init__(self, name=None, owner=None):
        """Create blessed version with a given name and owner.

        Name and owner have to either both be set or none should be set.
        Blessed version in use should always have name and owner set.  The
        version of init with name and owner set to None relies on external
        initialization of those fields.
        Args:
            name: The name of the blessed version token.
            owner: The owner of the blessed version token.
        """
        assert (name and owner) or (not name and not owner)
        if name and owner:
            now = BlessedVersion._get_timestamp_millis()
            data_str = ('blessed version created at %s' %
                        timestamp_to_str(now / 1000))
            Token.__init__(self, now, name, owner, sys.maxint, 0, data_str)
        else:
            Token.__init__(self)
示例#18
0
 def __str__(self):
     if self.next_run_time:
         next_run_time = timestamp_to_str(self.next_run_time)
     else:
         next_run_time = str(self.next_run_time)
     if self.recurrence_seconds:
         delta = datetime.timedelta(seconds=self.recurrence_seconds)
         recurrence = str(delta)
     else:
         recurrence = str(self.recurrence_seconds)
     if self.overrun_policy is not None:
         overrun_policy = OverrunPolicy.to_string(self.overrun_policy)
     else:
         overrun_policy = str(self.overrun_policy)
     return ('WorkflowSchedule(next_run_time=%s, recurrence=%s, '
             'overrun_policy=%s, parser_params=%s, workflow=%s, '
             'email=%s, max_running_instances=%s)' %
             (next_run_time, recurrence, overrun_policy, self.parser_params,
              self.workflow, self.emails, str(self.max_running_instances)))
示例#19
0
    def __init__(self, name=None, owner=None):
        """Create blessed version with a given name and owner.

        Name and owner have to either both be set or none should be set.
        Blessed version in use should always have name and owner set.  The
        version of init with name and owner set to None relies on external
        initialization of those fields.
        Args:
            name: The name of the blessed version token.
            owner: The owner of the blessed version token.
        """
        assert (name and owner) or (not name and not owner)
        if name and owner:
            now = BlessedVersion._get_timestamp_millis()
            data_str = ('blessed version created at %s' %
                        timestamp_to_str(now / 1000))
            Token.__init__(self, now, name, owner, sys.maxint, 0, data_str)
        else:
            Token.__init__(self)
示例#20
0
    def _get_job_execution_end_text(self, job_execution_data):
        """Format text version of the job execution completion message.

        Args:
            job_execution_data: The job execution data described in the
            message.
        Returns:
            Html message describing the job execution.
        """
        TEXT_TEMPLATE = """\
Job %(job)s execution in workflow %(workflow)s instance %(instance)s started \
at %(start_time)s finished after %(run_time)s at %(end_time)s with exit code \
%(exit_code)s.

Details are available at http://%(ui_host)s:%(ui_port)s/executions/?workflow=\
%(workflow)s&instance=%(instance)s&job=%(job)s

Execution details:

Workflow: %(workflow)s
Instance: %(instance)s
Job: %(job)s
Execution: %(execution)s
Info: %(info)s
Start time: %(start_time)s
End time: %(end_time)s
Run time: %(run_time)s
Logs: %(logs)s
Exit code: %(exit_code)s
"""
        params = self._get_job_execution_params(job_execution_data)
        end_time = timestamp_to_str(job_execution_data.end_time)
        params['end_time'] = end_time
        delta = int(job_execution_data.end_time -
                    job_execution_data.start_time)
        run_time = datetime.timedelta(seconds=delta)
        params['run_time'] = run_time
        logs = ', '.join(job_execution_data.logs.keys())
        params['logs'] = logs
        params['exit_code'] = job_execution_data.exit_code
        return TEXT_TEMPLATE % params
示例#21
0
    def _get_job_execution_end_text(self, job_execution_data):
        """Format text version of the job execution completion message.

        Args:
            job_execution_data: The job execution data described in the
            message.
        Returns:
            Html message describing the job execution.
        """
        TEXT_TEMPLATE = """\
Job %(job)s execution in workflow %(workflow)s instance %(instance)s started \
at %(start_time)s finished after %(run_time)s at %(end_time)s with exit code \
%(exit_code)s.

Details are available at http://%(ui_host)s:%(ui_port)s/executions/?workflow=\
%(workflow)s&instance=%(instance)s&job=%(job)s

Execution details:

Workflow: %(workflow)s
Instance: %(instance)s
Job: %(job)s
Execution: %(execution)s
Info: %(info)s
Start time: %(start_time)s
End time: %(end_time)s
Run time: %(run_time)s
Logs: %(logs)s
Exit code: %(exit_code)s
"""
        params = self._get_job_execution_params(job_execution_data)
        end_time = timestamp_to_str(job_execution_data.end_time)
        params['end_time'] = end_time
        delta = int(job_execution_data.end_time -
                    job_execution_data.start_time)
        run_time = datetime.timedelta(seconds=delta)
        params['run_time'] = run_time
        logs = ', '.join(job_execution_data.logs.keys())
        params['logs'] = logs
        params['exit_code'] = job_execution_data.exit_code
        return TEXT_TEMPLATE % params
示例#22
0
 def __str__(self):
     if self.next_run_time:
         next_run_time = timestamp_to_str(self.next_run_time)
     else:
         next_run_time = str(self.next_run_time)
     if self.recurrence_seconds:
         delta = datetime.timedelta(seconds=self.recurrence_seconds)
         recurrence = str(delta)
     else:
         recurrence = str(self.recurrence_seconds)
     if self.overrun_policy is not None:
         overrun_policy = OverrunPolicy.to_string(self.overrun_policy)
     else:
         overrun_policy = str(self.overrun_policy)
     return ('WorkflowSchedule(next_run_time=%s, recurrence=%s, '
             'overrun_policy=%s, parser_params=%s, workflow=%s, '
             'email=%s, max_running_instances=%s)' % (next_run_time,
                                                      recurrence,
                                                      overrun_policy,
                                                      self.parser_params,
                                                      self.workflow,
                                                      self.emails,
                                                      str(self.max_running_instances)))
示例#23
0
 def test_timestamp_to_from_str(self):
     self.assertEqual('1970-01-01 00:00:10 UTC', timestamp_to_str(10))
     self.assertEqual(10, str_to_timestamp('1970-01-01 00:00:10 UTC'))
示例#24
0
 def test_timestamp_to_from_str(self):
     self.assertEqual('1970-01-01 00:00:10 UTC', timestamp_to_str(10))
     self.assertEqual(10, str_to_timestamp('1970-01-01 00:00:10 UTC'))
示例#25
0
    def _get_instance_end_html(self, instance_data, jobs_data):
        """Format html version of the workflow instance completion message.

        Args:
            instance_data: The data of the completed workflow instance.
            jobs_data: The list of data describing jobs in the workflow
                instance.

        Returns:
            Html message describing the workflow instance.
        """
        HTML_TEMPLATE = """\
<html>
    <head></head>
    <body>
        <p>
            Workflow %(workflow)s instance %(instance)s started at
            %(start_time)s finished after %(run_time)s at %(end_time)s
            with status <span
style="background-color:%(instance_status_color)s;">%(status)s</span>.
            Click
            <a href="http://%(ui_host)s:%(ui_port)s/jobs/?\
workflow=%(workflow)s&instance=%(instance)s">here</a> for details.
        </p>
        <p>Jobs:<br/>
            <table style="border-collapse:collapse;">
                <tr>
                    <th style="border:1px dotted grey;">Name</th>
                    <th style="border:1px dotted grey;">Last start</th>
                    <th style="border:1px dotted grey;">Last end</th>
                    <th style="border:1px dotted grey;">Run time</th>
                    <th style="border:1px dotted grey;">Status</th>
                </tr>
                %(jobs)s
            </table>
        </p>
    </body>
</html>
"""
        jobs = ''
        for job_data in jobs_data:
            jobs += '<tr>'
            jobs += ('<td style="border:1px dotted grey;">'
                     '<a href="http://%s:%s/executions/?workflow=%s&'
                     'instance=%s&job=%s">%s</a></td>' % (self._ui_host,
                                                          self._ui_port,
                                                          job_data.workflow,
                                                          job_data.instance,
                                                          job_data.job,
                                                          job_data.job))
            if not job_data.last_start_time:
                jobs += ('<td style="border:1px dotted grey;"></td>'
                         '<td style="border:1px dotted grey;"></td>'
                         '<td style="border:1px dotted grey;"></td>')
            else:
                jobs += ('<td style="border:1px dotted grey;">%s</td>' %
                         timestamp_to_str(job_data.last_start_time))
                if not job_data.last_end_time:
                    jobs += ('<td style="border:1px dotted grey;"></td>'
                             '<td style="border:1px dotted grey;"></td>')
                else:
                    delta = int(job_data.last_end_time -
                                job_data.last_start_time)
                    jobs += ('<td style="border:1px dotted grey;">%s</td>'
                             '<td style="border:1px dotted grey;">%s</td>' % (
                                 timestamp_to_str(job_data.last_end_time),
                                 datetime.timedelta(seconds=delta)))
            jobs += ('<td style="border:1px dotted grey;background-color:%s;'
                     'text-align: center;">%s</td>\n' % (
                         Status.COLORS[job_data.status],
                         Status.to_string(job_data.status)))
            jobs += '</tr>'
        start_time = timestamp_to_str(instance_data.start_time)
        end_time = timestamp_to_str(instance_data.end_time)
        delta = int(instance_data.end_time - instance_data.start_time)
        run_time = datetime.timedelta(seconds=delta)
        instance_status_color = Status.COLORS[instance_data.status]
        status = Status.to_string(instance_data.status)
        return HTML_TEMPLATE % {'workflow': instance_data.workflow,
                                'instance': instance_data.instance,
                                'start_time': start_time,
                                'end_time': end_time,
                                'run_time': run_time,
                                'instance_status_color': instance_status_color,
                                'status': status,
                                'ui_host': self._ui_host,
                                'ui_port': self._ui_port,
                                'jobs': jobs}
示例#26
0
    def _get_job_execution_end_html(self, job_execution_data):
        """Format html version of the job execution completion message.

        Args:
            job_execution_data: The job execution data described in the
            message.
        Returns:
            Html message describing the job execution.
        """
        HTML_TEMPLATE = """\
<html>
    <head></head>
    <body>
        <p>
            Job %(job)s execution in workflow %(workflow)s instance
            %(instance)s started at %(start_time)s finished after %(run_time)s
            at %(end_time)s with exit code <span
            style="background-color:%(exit_code_color)s;">%(exit_code)s</span>.
            Click
            <a href="http://%(ui_host)s:%(ui_port)s/executions/?workflow=\
%(workflow)s&instance=%(instance)s&job=%(job)s">here</a> for details.
        </p>
        <p>Execution details:<br/>
            <table style="border-collapse:collapse;">
                <tr>
                    <td style="border:1px dotted grey;"><b>Workflow</b></td>
                    <td style="border:1px dotted grey;">
                        <a href="http://%(ui_host)s:%(ui_port)s/instances/?\
workflow=%(workflow)s">%(workflow)s</a>
                    </td>
                </tr>
                <tr>
                    <td style="border:1px dotted grey;"><b>Instance</b></td>
                    <td style="border:1px dotted grey;">
                        <a href="http://%(ui_host)s:%(ui_port)s/jobs/?\
workflow=%(workflow)s&instance=%(instance)s">%(instance)s</a>
                    </td>
                </tr>
                <tr>
                    <td style="border:1px dotted grey;"><b>Job</b></td>
                    <td style="border:1px dotted grey;">
                    <a href="http://%(ui_host)s:%(ui_port)s/executions/?\
workflow=%(workflow)s&instance=%(instance)s&job=%(job)s">%(job)s</a>
                    </td>
                </tr>
                <tr>
                    <td style="border:1px dotted grey;"><b>Execution</b></td>
                    <td style="border:1px dotted grey;">%(execution)s</td>
                </tr>
                <tr>
                    <td style="border:1px dotted grey;"><b>Info</b></td>
                    <td style="border:1px dotted grey;">%(info)s</td>
                </tr>
                <tr>
                    <td style="border:1px dotted grey;"><b>Start time</b></td>
                    <td style="border:1px dotted grey;">%(start_time)s</td>
                </tr>
                <tr>
                    <td style="border:1px dotted grey;"><b>End time</b></td>
                    <td style="border:1px dotted grey;">%(end_time)s</td>
                </tr>
                <tr>
                    <td style="border:1px dotted grey;"><b>Run time</b></td>
                    <td style="border:1px dotted grey;">%(run_time)s</td>
                </tr>
                <tr>
                    <td style="border:1px dotted grey;"><b>Logs</b></td>
                    <td style="border:1px dotted grey;">%(logs)s</td>
                </tr>
                <tr>
                    <td style="border:1px dotted grey;"><b>Exit code</b></td>
                    <td
style="border:1px dotted grey;background-color:%(exit_code_color)s;">
                        %(exit_code)s
                    </td>
                </tr>
            </table>
        </p>
    </body>
</html>
"""
        params = self._get_job_execution_params(job_execution_data)
        end_time = timestamp_to_str(job_execution_data.end_time)
        params['end_time'] = end_time
        delta = int(job_execution_data.end_time -
                    job_execution_data.start_time)
        run_time = datetime.timedelta(seconds=delta)
        params['run_time'] = run_time
        params['exit_code'] = job_execution_data.exit_code
        exit_code_color = (Status.COLORS[Status.SUCCESS]
                           if job_execution_data.exit_code == 0 else
                           Status.COLORS[Status.FAILURE])
        params['exit_code_color'] = exit_code_color
        logs = []
        for log_type in job_execution_data.logs:
            params['log_type'] = log_type
            logs.append('<a href="http://%(ui_host)s:%(ui_port)s/file/?'
                        'workflow=%(workflow)s&instance=%(instance)s&'
                        'job=%(job)s&execution=%(execution)s&'
                        'log_type=%(log_type)s">%(log_type)s</a>' % params)
        params['logs'] = '&nbsp;|&nbsp;'.join(logs)
        return HTML_TEMPLATE % params
示例#27
0
    def _get_job_execution_end_html(self, job_execution_data):
        """Format html version of the job execution completion message.

        Args:
            job_execution_data: The job execution data described in the
            message.
        Returns:
            Html message describing the job execution.
        """
        HTML_TEMPLATE = """\
<html>
    <head></head>
    <body>
        <p>
            Job %(job)s execution in workflow %(workflow)s instance
            %(instance)s started at %(start_time)s finished after %(run_time)s
            at %(end_time)s with exit code <span
            style="background-color:%(exit_code_color)s;">%(exit_code)s</span>.
            Click
            <a href="http://%(ui_host)s:%(ui_port)s/executions/?workflow=\
%(workflow)s&instance=%(instance)s&job=%(job)s">here</a> for details.
        </p>
        <p>Execution details:<br/>
            <table style="border-collapse:collapse;">
                <tr>
                    <td style="border:1px dotted grey;"><b>Workflow</b></td>
                    <td style="border:1px dotted grey;">
                        <a href="http://%(ui_host)s:%(ui_port)s/instances/?\
workflow=%(workflow)s">%(workflow)s</a>
                    </td>
                </tr>
                <tr>
                    <td style="border:1px dotted grey;"><b>Instance</b></td>
                    <td style="border:1px dotted grey;">
                        <a href="http://%(ui_host)s:%(ui_port)s/jobs/?\
workflow=%(workflow)s&instance=%(instance)s">%(instance)s</a>
                    </td>
                </tr>
                <tr>
                    <td style="border:1px dotted grey;"><b>Job</b></td>
                    <td style="border:1px dotted grey;">
                    <a href="http://%(ui_host)s:%(ui_port)s/executions/?\
workflow=%(workflow)s&instance=%(instance)s&job=%(job)s">%(job)s</a>
                    </td>
                </tr>
                <tr>
                    <td style="border:1px dotted grey;"><b>Execution</b></td>
                    <td style="border:1px dotted grey;">%(execution)s</td>
                </tr>
                <tr>
                    <td style="border:1px dotted grey;"><b>Info</b></td>
                    <td style="border:1px dotted grey;">%(info)s</td>
                </tr>
                <tr>
                    <td style="border:1px dotted grey;"><b>Start time</b></td>
                    <td style="border:1px dotted grey;">%(start_time)s</td>
                </tr>
                <tr>
                    <td style="border:1px dotted grey;"><b>End time</b></td>
                    <td style="border:1px dotted grey;">%(end_time)s</td>
                </tr>
                <tr>
                    <td style="border:1px dotted grey;"><b>Run time</b></td>
                    <td style="border:1px dotted grey;">%(run_time)s</td>
                </tr>
                <tr>
                    <td style="border:1px dotted grey;"><b>Logs</b></td>
                    <td style="border:1px dotted grey;">%(logs)s</td>
                </tr>
                <tr>
                    <td style="border:1px dotted grey;"><b>Exit code</b></td>
                    <td
style="border:1px dotted grey;background-color:%(exit_code_color)s;">
                        %(exit_code)s
                    </td>
                </tr>
            </table>
        </p>
    </body>
</html>
"""
        params = self._get_job_execution_params(job_execution_data)
        end_time = timestamp_to_str(job_execution_data.end_time)
        params['end_time'] = end_time
        delta = int(job_execution_data.end_time -
                    job_execution_data.start_time)
        run_time = datetime.timedelta(seconds=delta)
        params['run_time'] = run_time
        params['exit_code'] = job_execution_data.exit_code
        exit_code_color = (Status.COLORS[Status.SUCCESS] if
                           job_execution_data.exit_code == 0 else
                           Status.COLORS[Status.FAILURE])
        params['exit_code_color'] = exit_code_color
        logs = []
        for log_type in job_execution_data.logs:
            params['log_type'] = log_type
            logs.append('<a href="http://%(ui_host)s:%(ui_port)s/file/?'
                        'workflow=%(workflow)s&instance=%(instance)s&'
                        'job=%(job)s&execution=%(execution)s&'
                        'log_type=%(log_type)s">%(log_type)s</a>' % params)
        params['logs'] = '&nbsp;|&nbsp;'.join(logs)
        return HTML_TEMPLATE % params
示例#28
0
    def _get_instance_end_html(self, instance_data, jobs_data):
        """Format html version of the workflow instance completion message.

        Args:
            instance_data: The data of the completed workflow instance.
            jobs_data: The list of data describing jobs in the workflow
                instance.

        Returns:
            Html message describing the workflow instance.
        """
        HTML_TEMPLATE = """\
<html>
    <head></head>
    <body>
        <p>
            Workflow %(workflow)s instance %(instance)s started at
            %(start_time)s finished after %(run_time)s at %(end_time)s
            with status <span
style="background-color:%(instance_status_color)s;">%(status)s</span>.
            Click
            <a href="http://%(ui_host)s:%(ui_port)s/jobs/?\
workflow=%(workflow)s&instance=%(instance)s">here</a> for details.
        </p>
        <p>Jobs:<br/>
            <table style="border-collapse:collapse;">
                <tr>
                    <th style="border:1px dotted grey;">Name</th>
                    <th style="border:1px dotted grey;">Last start</th>
                    <th style="border:1px dotted grey;">Last end</th>
                    <th style="border:1px dotted grey;">Run time</th>
                    <th style="border:1px dotted grey;">Status</th>
                </tr>
                %(jobs)s
            </table>
        </p>
    </body>
</html>
"""
        jobs = ''
        for job_data in jobs_data:
            jobs += '<tr>'
            jobs += ('<td style="border:1px dotted grey;">'
                     '<a href="http://%s:%s/executions/?workflow=%s&'
                     'instance=%s&job=%s">%s</a></td>' %
                     (self._ui_host, self._ui_port, job_data.workflow,
                      job_data.instance, job_data.job, job_data.job))
            if not job_data.last_start_time:
                jobs += ('<td style="border:1px dotted grey;"></td>'
                         '<td style="border:1px dotted grey;"></td>'
                         '<td style="border:1px dotted grey;"></td>')
            else:
                jobs += ('<td style="border:1px dotted grey;">%s</td>' %
                         timestamp_to_str(job_data.last_start_time))
                if not job_data.last_end_time:
                    jobs += ('<td style="border:1px dotted grey;"></td>'
                             '<td style="border:1px dotted grey;"></td>')
                else:
                    delta = int(job_data.last_end_time -
                                job_data.last_start_time)
                    jobs += ('<td style="border:1px dotted grey;">%s</td>'
                             '<td style="border:1px dotted grey;">%s</td>' %
                             (timestamp_to_str(job_data.last_end_time),
                              datetime.timedelta(seconds=delta)))
            jobs += ('<td style="border:1px dotted grey;background-color:%s;'
                     'text-align: center;">%s</td>\n' %
                     (Status.COLORS[job_data.status],
                      Status.to_string(job_data.status)))
            jobs += '</tr>'
        start_time = timestamp_to_str(instance_data.start_time)
        end_time = timestamp_to_str(instance_data.end_time)
        delta = int(instance_data.end_time - instance_data.start_time)
        run_time = datetime.timedelta(seconds=delta)
        instance_status_color = Status.COLORS[instance_data.status]
        status = Status.to_string(instance_data.status)
        return HTML_TEMPLATE % {
            'workflow': instance_data.workflow,
            'instance': instance_data.instance,
            'start_time': start_time,
            'end_time': end_time,
            'run_time': run_time,
            'instance_status_color': instance_status_color,
            'status': status,
            'ui_host': self._ui_host,
            'ui_port': self._ui_port,
            'jobs': jobs
        }