def shards_table(mv: MaintenanceView, cv: ClusterView, ni: int) -> str: headers = [ "SHARD INDEX", "CURRENT STATE", "TARGET STATE", "MAINTENANCE STATUS", "LAST UPDATED", ] tbl = [] for shard in mv.get_shards_by_node_index(ni): target_state = mv.shard_target_state shard_state = mv.get_shard_state(shard) cur_op_state = shard_state.current_operational_state current_state = colored( cur_op_state.name, _color_shard_op_state( cur_op_state, # pyre-ignore mv.shard_target_state, ), ) mnt_status = mv.get_shard_maintenance_status(shard) maintenance_status = colored( mnt_status.name, _color(mnt_status)) last_updated_at = mv.get_shard_last_updated_at( shard) if last_updated_at: last_updated = ( f"{last_updated_at} " f"({naturaltime(last_updated_at)})") else: last_updated = "-" tbl.append([ shard.shard_index, current_state, # pyre-ignore target_state.name, maintenance_status, last_updated, ]) return tabulate(tbl, headers=headers, tablefmt="plain")
def aggregated(mv: MaintenanceView, cv: ClusterView) -> str: headers = [ "NODE INDEX", "NODE NAME", "LOCATION", "TARGET STATE", "CURRENT STATE", "MAINTENANCE STATUS", "LAST UPDATED", ] tbl = [] for ni in mv.affected_storage_node_indexes: nv = cv.get_node_view(node_index=ni) node_index = ni node_name = nv.node_name location = nv.location target_state = ( # pyre-ignore f"{mv.shard_target_state.name}" f"({len(mv.get_shards_by_node_index(ni))})") # current_state chunks = [] for cur_op_state, num in sorted( Counter( (mv.get_shard_state( shard).current_operational_state for shard in mv.get_shards_by_node_index(ni) )).items(), key=lambda x: x[0].name, ): chunks.append( colored( f"{cur_op_state.name}({num})", _color_shard_op_state( cur_op_state, # pyre-ignore mv.shard_target_state, ), )) current_state = ",".join(chunks) # maintenance status mnt_statuses = [ mv.get_shard_maintenance_status(shard) for shard in mv.get_shards_by_node_index(ni) ] chunks = [] for mnt_status, num in sorted( Counter(mnt_statuses).items(), key=lambda x: x[0].name): chunks.append( colored(f"{mnt_status.name}({num})", _color(mnt_status))) maintenance_status = ",".join(chunks) last_updated_at_time = min(( ShardMaintenanceProgress.from_thrift( # pyre-ignore ss.maintenance).last_updated_at for ss in nv.shard_states if ss.maintenance)) last_updated_at = ( f"{last_updated_at_time} ({naturaltime(last_updated_at_time)})" ) tbl.append([ node_index, node_name, location, target_state, current_state, maintenance_status, last_updated_at, ]) return tabulate(tabular_data=tbl, headers=headers, tablefmt="plain")