def displayRevisionId(self): # pylint: disable=invalid-name """Returns human readable revision identifier.""" if self.latestRevision: return '%s (currently %s)' % (traffic.GetKey(self), self.revisionName) else: return self.revisionName
def GetTrafficTargetPairs(spec_targets, status_targets, is_platform_managed, latest_ready_revision_name): """Returns the list of TrafficTargetPair's for a Service.""" spec_dict = {traffic.GetKey(t): t for t in spec_targets} status_dict = {traffic.GetKey(t): t for t in status_targets} # For managed the status target for the latest revision is # included by revisionName only and may hold the combined traffic # percent for both latestRevisionName and latestRevision spec targets. # Here we adjust keys in status_dict to match with spec_dict. combined_status_target_id = None if (is_platform_managed and traffic.LATEST_REVISION_KEY in spec_dict and traffic.LATEST_REVISION_KEY not in status_dict and latest_ready_revision_name in status_dict): latest_status_target = status_dict[latest_ready_revision_name] status_dict[traffic.LATEST_REVISION_KEY] = latest_status_target if latest_ready_revision_name in spec_dict: combined_status_target_id = id(latest_status_target) else: del status_dict[latest_ready_revision_name] result = [] for k in set(spec_dict).union(status_dict): spec_target = spec_dict.get(k, None) status_target = status_dict.get(k, None) percent_override = None if id(status_target) == combined_status_target_id: spec_by_latest_target = spec_dict[traffic.LATEST_REVISION_KEY] status_by_latest_percent = min(spec_by_latest_target.percent, status_target.percent) if k == traffic.LATEST_REVISION_KEY: percent_override = status_by_latest_percent else: percent_override = status_target.percent - status_by_latest_percent result.append( TrafficTargetPair(spec_target, status_target, latest_ready_revision_name, percent_override)) return sorted(result, key=traffic.SortKeyFromTarget)
def key(self): return (traffic.LATEST_REVISION_KEY if self.latestRevision else traffic.GetKey(self))