Skip to content

Commit 8634346

Browse files
committed
ISSUE-#15 - Enhance service component reporting with detailed instance state breakdown in mcp_main.py
- Added warnings for non-STARTED instances and improved host information display. - Summarized instance states with counts for better visibility. - Affected file: src/mcp_ambari_api/mcp_main.py
1 parent a17c103 commit 8634346

File tree

1 file changed

+47
-18
lines changed

1 file changed

+47
-18
lines changed

src/mcp_ambari_api/mcp_main.py

Lines changed: 47 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -607,30 +607,59 @@ async def get_service_components(service_name: str) -> str:
607607
# Add instance counts if available
608608
if total_count > 0:
609609
result_lines.append(f" Instances: {started_count} started / {installed_count} installed / {total_count} total")
610-
611-
# Add host information
610+
if started_count < total_count:
611+
result_lines.append(f" [WARNING] {total_count - started_count} instance(s) are NOT in STARTED state")
612+
613+
# Add host information - non-STARTED instances shown in full, STARTED summarized
612614
if host_components:
615+
non_started = [
616+
(hc.get("HostRoles", {}).get("host_name", "Unknown"),
617+
hc.get("HostRoles", {}).get("state", "Unknown"))
618+
for hc in host_components
619+
if hc.get("HostRoles", {}).get("state") != "STARTED"
620+
]
621+
started_hosts = [
622+
hc.get("HostRoles", {}).get("host_name", "Unknown")
623+
for hc in host_components
624+
if hc.get("HostRoles", {}).get("state") == "STARTED"
625+
]
626+
613627
result_lines.append(f" Hosts ({len(host_components)} instances):")
614-
for j, host_comp in enumerate(host_components[:5], 1): # Show first 5 hosts
615-
host_roles = host_comp.get("HostRoles", {})
616-
host_name = host_roles.get("host_name", "Unknown")
617-
host_state = host_roles.get("state", "Unknown")
618-
result_lines.append(f" {j}. {host_name} [{host_state}]")
619-
620-
if len(host_components) > 5:
621-
result_lines.append(f" ... and {len(host_components) - 5} more hosts")
628+
629+
if non_started:
630+
result_lines.append(f" [WARNING] {len(non_started)} instance(s) not in STARTED state:")
631+
for host_name, host_state in non_started:
632+
result_lines.append(f" !! {host_name} [{host_state}]")
633+
634+
if started_hosts:
635+
if len(started_hosts) <= 5:
636+
for host_name in started_hosts:
637+
result_lines.append(f" - {host_name} [STARTED]")
638+
else:
639+
result_lines.append(f" - {len(started_hosts)} hosts [STARTED] (omitted for brevity)")
622640
else:
623641
result_lines.append(" Hosts: No host assignments found")
624-
642+
625643
result_lines.append("")
626-
627-
# Add summary statistics
628-
total_instances = sum(len(comp.get("host_components", [])) for comp in components)
629-
started_components = len([comp for comp in components if comp.get("ServiceComponentInfo", {}).get("state") == "STARTED"])
630-
644+
645+
# Add summary statistics with per-instance state breakdown
646+
instance_state_counts: dict = {}
647+
for comp in components:
648+
for hc in comp.get("host_components", []):
649+
state = hc.get("HostRoles", {}).get("state", "Unknown")
650+
instance_state_counts[state] = instance_state_counts.get(state, 0) + 1
651+
652+
total_instances = sum(instance_state_counts.values())
653+
non_started_total = total_instances - instance_state_counts.get("STARTED", 0)
654+
631655
result_lines.append("Summary:")
632-
result_lines.append(f" - Components: {len(components)} total, {started_components} started")
633-
result_lines.append(f" - Total component instances across all hosts: {total_instances}")
656+
result_lines.append(f" - Components: {len(components)} types")
657+
result_lines.append(f" - Total instances across all hosts: {total_instances}")
658+
for state, count in sorted(instance_state_counts.items()):
659+
marker = " [!]" if state != "STARTED" else ""
660+
result_lines.append(f" {state}: {count}{marker}")
661+
if non_started_total > 0:
662+
result_lines.append(f" [WARNING] {non_started_total} instance(s) are NOT in STARTED state across all components")
634663

635664
return "\n".join(result_lines)
636665

0 commit comments

Comments
 (0)