@JsonValue @Override public String toString() { return clusterId.s() + ":" + serviceType.s(); }
@GET @Path("/{applicationId}") @Produces(MediaType.APPLICATION_JSON) public ApplicationServices getInstance(@PathParam("applicationId") String applicationIdString) { ApplicationId applicationId = ApplicationId.fromSerializedForm(applicationIdString); Map<ServiceId, ServiceStatusInfo> services = healthMonitorApi.getServices(applicationId); List<ServiceResource> serviceResources = services.entrySet().stream().map(entry -> { ServiceResource serviceResource = new ServiceResource(); serviceResource.clusterId = entry.getKey().getClusterId(); serviceResource.serviceType = entry.getKey().getServiceType(); serviceResource.configId = entry.getKey().getConfigId(); serviceResource.serviceStatusInfo = entry.getValue(); return serviceResource; }) .sorted(Comparator.comparing(resource -> resource.serviceType.s())) .collect(Collectors.toList()); ApplicationServices applicationServices = new ApplicationServices(); applicationServices.services = serviceResources; return applicationServices; }
@Override public GetHostResponse getHost(String hostNameString) { HostName hostName = new HostName(hostNameString); try { Host host = orchestrator.getHost(hostName); URI applicationUri = uriInfo.getBaseUriBuilder() .path(InstanceResource.class) .path(host.getApplicationInstanceReference().asString()) .build(); List<HostService> hostServices = host.getServiceInstances().stream() .map(serviceInstance -> new HostService( serviceInstance.getServiceCluster().clusterId().s(), serviceInstance.getServiceCluster().serviceType().s(), serviceInstance.configId().s(), serviceInstance.serviceStatus().name())) .collect(Collectors.toList()); return new GetHostResponse( host.getHostName().s(), host.getHostStatus().name(), applicationUri.toString(), hostServices); } catch (UncheckedTimeoutException e) { log.log(LogLevel.INFO, "Failed to get host " + hostName + ": " + e.getMessage()); throw webExceptionFromTimeout("getHost", hostName, e); } catch (HostNameNotFoundException e) { log.log(LogLevel.INFO, "Host not found: " + hostName); throw new NotFoundException(e); } }