def queued_apps_table(queued_apps): """Returns a PrettyTable representation of the Marathon launch queue content. :param queued_apps: apps to render :type queued_apps: [dict] :rtype: PrettyTable """ def extract_value_from_entry(entry, value): """Extracts the value parameter from given row entry. If value is not present, EMPTY_ENTRY will be returned :param entry: row entry :type entry: [dict] :param value: value which should be extracted :type value: string :rtype: str """ return entry.get('processedOffersSummary', {}).get(value, EMPTY_ENTRY) key_column = 'ID' fields = OrderedDict([ (key_column, lambda entry: marathon.get_app_or_pod_id(entry)), ('SINCE', lambda entry: entry.get('since', EMPTY_ENTRY) ), ('INSTANCES TO LAUNCH', lambda entry: entry.get('count', EMPTY_ENTRY) ), ('WAITING', lambda entry: entry.get('delay', {}).get('overdue', EMPTY_ENTRY) ), ('PROCESSED OFFERS', lambda entry: extract_value_from_entry(entry, 'processedOffersCount') ), ('UNUSED OFFERS', lambda entry: extract_value_from_entry(entry, 'unusedOffersCount') ), ('LAST UNUSED OFFER', lambda entry: extract_value_from_entry(entry, 'lastUnusedOfferAt') ), ('LAST USED OFFER', lambda entry: extract_value_from_entry(entry, 'lastUsedOfferAt') ), ]) tb = table(fields, queued_apps, sortby=key_column) tb.align[key_column] = 'l' tb.align['SINCE'] = 'l' tb.align['INSTANCES TO LAUNCH'] = 'l' tb.align['WAITING'] = 'l' tb.align['PROCESSED OFFERS'] = 'l' tb.align['UNUSED OFFERS'] = 'l' tb.align['LAST UNUSED OFFER'] = 'l' tb.align['LAST USED OFFER'] = 'l' return tb
def _enhance_row_with_overdue_information(rows, queued_apps): """Calculates if configured `backoff` duration for this app or pod definition was exceeded. In that case this application is marked as `overdue`. If the app or pod inside this row should be :param rows: list of rows :type rows: [] :param queued_apps: list of :type queued_apps: [] :returns: true if pod is overdue, false otherwise :rtype: bool """ for row in rows: queued_app = next( (app for app in queued_apps if row.get('id') == marathon.get_app_or_pod_id(app)), None) row['overdue'] = queued_app.get('delay', {}) \ .get('overdue', False) if queued_app else False return rows