public HostStateChangeDeniedException(HostName hostName, String constraintName, String message, Exception e) { this(hostName.s(), constraintName, Optional.empty(), message, e); }
private static String hostAllowedDownPath(ApplicationInstanceReference applicationInstanceReference, HostName hostname) { return hostsAllowedDownPath(applicationInstanceReference) + '/' + hostname.s(); }
@Override public Optional<ApplicationInstance> findInstanceByHost(HostName hostName) { Map<ApplicationInstanceReference, ApplicationInstance> instanceMap = serviceMonitor.getAllApplicationInstances(); List<ApplicationInstance> applicationInstancesUsingHost = instanceMap.entrySet().stream() .filter(entry -> applicationInstanceUsesHost(entry.getValue(), hostName)) .map(Map.Entry::getValue) .collect(Collectors.toList()); if (applicationInstancesUsingHost.isEmpty()) { return Optional.empty(); } if (applicationInstancesUsingHost.size() > 1) { throw new IllegalStateException( "Major assumption broken: Multiple application instances contain host " + hostName.s() + ": " + applicationInstancesUsingHost); } return Optional.of(applicationInstancesUsingHost.get(0)); }
private static WebApplicationException createWebException(String operationDescription, HostName hostname, Exception e, String constraint, String message) { HostStateChangeDenialReason hostStateChangeDenialReason = new HostStateChangeDenialReason( constraint, operationDescription + " failed: " + message); UpdateHostResponse response = new UpdateHostResponse(hostname.s(), hostStateChangeDenialReason); return new WebApplicationException( hostStateChangeDenialReason.toString(), e, Response.status(Response.Status.CONFLICT) .entity(response) .type(MediaType.APPLICATION_JSON_TYPE) .build()); } }
/** * If the node is down (see {@link #badNode}), and there is no "down" history record, we add it. * Otherwise we remove any "down" history record. */ private void updateNodeDownState() { Map<String, Node> activeNodesByHostname = nodeRepository().getNodes(Node.State.active).stream() .collect(Collectors.toMap(Node::hostname, node -> node)); serviceMonitor.getServiceModelSnapshot().getServiceInstancesByHostName() .forEach((hostName, serviceInstances) -> { Node node = activeNodesByHostname.get(hostName.s()); if (node == null) return; if (badNode(serviceInstances)) { recordAsDown(node); } else { clearDownRecord(node); } }); }
@Override public UpdateHostResponse resume(final String hostNameString) { HostName hostName = new HostName(hostNameString); try { orchestrator.resume(hostName); } catch (HostNameNotFoundException e) { log.log(LogLevel.INFO, "Host not found: " + hostName); throw new NotFoundException(e); } catch (UncheckedTimeoutException e) { log.log(LogLevel.INFO, "Failed to resume " + hostName + ": " + e.getMessage()); throw webExceptionFromTimeout("resume", hostName, e); } catch (HostStateChangeDeniedException e) { log.log(LogLevel.INFO, "Failed to resume " + hostName + ": " + e.getMessage()); throw webExceptionWithDenialReason("resume", hostName, e); } return new UpdateHostResponse(hostName.s(), null); }
@Override public <T> T createClient(Class<T> apiClass, HostName hostName, int port, String pathPrefix, String scheme) { UriBuilder uriBuilder = UriBuilder.fromPath(pathPrefix).host(hostName.s()).port(port).scheme(scheme); return createClient(new Params<>(apiClass, uriBuilder.build())); } }
@Override public UpdateHostResponse suspend(String hostNameString) { HostName hostName = new HostName(hostNameString); try { orchestrator.suspend(hostName); } catch (HostNameNotFoundException e) { log.log(LogLevel.INFO, "Host not found: " + hostName); throw new NotFoundException(e); } catch (UncheckedTimeoutException e) { log.log(LogLevel.INFO, "Failed to suspend " + hostName + ": " + e.getMessage()); throw webExceptionFromTimeout("suspend", hostName, e); } catch (HostStateChangeDeniedException e) { log.log(LogLevel.INFO, "Failed to suspend " + hostName + ": " + e.getMessage()); throw webExceptionWithDenialReason("suspend", hostName, e); } return new UpdateHostResponse(hostName.s(), null); }
URI uri = UriBuilder.fromPath(pathPrefix).port(port).scheme(scheme).host(hostName.s()).build(); JaxRsClientFactory.Params<T> params = new JaxRsClientFactory.Params<>(apiClass, uri); params.setConnectTimeout(timeouts.getConnectTimeoutOrThrow());
@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); } }