use of com.yahoo.vespa.applicationmodel.HostName in project vespa by vespa-engine.
the class RetryingJaxRsStrategy method apply.
@Override
public <R> R apply(final Function<T, R> function) throws IOException {
ProcessingException sampleException = null;
for (int i = 0; i < NUM_LOOP_ATTEMPTS; ++i) {
for (final HostName hostName : hostNames) {
final T jaxRsClient = jaxRsClientFactory.createClient(apiClass, hostName, port, pathPrefix, scheme);
try {
return function.apply(jaxRsClient);
} catch (ProcessingException e) {
sampleException = e;
logger.log(Level.INFO, "Failed REST API call to " + hostName + ":" + port + pathPrefix + " (in retry loop): " + e.getMessage());
}
}
}
final String message = String.format("Giving up invoking REST API after %d tries against hosts %s.%s", NUM_LOOP_ATTEMPTS, hostNames, sampleException == null ? "" : ", sample error: " + sampleException.getMessage());
assert sampleException != null;
throw new IOException(message, sampleException);
}
use of com.yahoo.vespa.applicationmodel.HostName in project vespa by vespa-engine.
the class JerseyJaxRsClientFactory method createClient.
/**
* Contains some workarounds for HTTP/JAX-RS/Jersey issues. See:
* https://jersey.java.net/apidocs/latest/jersey/org/glassfish/jersey/client/ClientProperties.html#SUPPRESS_HTTP_COMPLIANCE_VALIDATION
* https://jersey.java.net/apidocs/latest/jersey/org/glassfish/jersey/client/HttpUrlConnectorProvider.html#SET_METHOD_WORKAROUND
*/
@Override
public <T> T createClient(final Class<T> apiClass, final HostName hostName, final int port, final String pathPrefix, String scheme) {
final UriBuilder uriBuilder = UriBuilder.fromPath(pathPrefix).host(hostName.s()).port(port).scheme(scheme);
ClientBuilder builder = ClientBuilder.newBuilder().property(ClientProperties.CONNECT_TIMEOUT, connectTimeoutMs).property(ClientProperties.READ_TIMEOUT, readTimeoutMs).property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, // Allow empty PUT. TODO: Fix API.
true).property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, // Allow e.g. PATCH method.
true).property(ClientProperties.FOLLOW_REDIRECTS, true);
if (sslContext != null) {
builder.sslContext(sslContext);
}
if (hostnameVerifier != null) {
builder.hostnameVerifier(hostnameVerifier);
}
if (userAgent != null) {
builder.register((ClientRequestFilter) context -> context.getHeaders().put(HttpHeaders.USER_AGENT, Collections.singletonList(userAgent)));
}
final WebTarget target = builder.build().target(uriBuilder);
// TODO: Check if this fills up non-heap memory with loaded classes.
return WebResourceFactory.newResource(apiClass, target);
}
use of com.yahoo.vespa.applicationmodel.HostName in project vespa by vespa-engine.
the class NodesResponse method toSlime.
private void toSlime(Node node, boolean allFields, Cursor object) {
object.setString("url", nodeParentUrl + node.hostname());
if (!allFields)
return;
object.setString("id", node.id());
object.setString("state", NodeStateSerializer.wireNameOf(node.state()));
object.setString("type", node.type().name());
object.setString("hostname", node.hostname());
object.setString("type", toString(node.type()));
if (node.parentHostname().isPresent()) {
object.setString("parentHostname", node.parentHostname().get());
}
object.setString("openStackId", node.openStackId());
object.setString("flavor", node.flavor().name());
object.setString("canonicalFlavor", node.flavor().canonicalName());
object.setDouble("minDiskAvailableGb", node.flavor().getMinDiskAvailableGb());
object.setDouble("minMainMemoryAvailableGb", node.flavor().getMinMainMemoryAvailableGb());
if (node.flavor().getDescription() != null && !node.flavor().getDescription().isEmpty())
object.setString("description", node.flavor().getDescription());
object.setDouble("minCpuCores", node.flavor().getMinCpuCores());
if (node.flavor().cost() > 0)
object.setLong("cost", node.flavor().cost());
object.setBool("fastDisk", node.flavor().hasFastDisk());
object.setString("environment", node.flavor().getType().name());
if (node.allocation().isPresent()) {
toSlime(node.allocation().get().owner(), object.setObject("owner"));
toSlime(node.allocation().get().membership(), object.setObject("membership"));
object.setLong("restartGeneration", node.allocation().get().restartGeneration().wanted());
object.setLong("currentRestartGeneration", node.allocation().get().restartGeneration().current());
object.setString("wantedDockerImage", nodeRepository.dockerImage().withTag(node.allocation().get().membership().cluster().vespaVersion()).asString());
object.setString("wantedVespaVersion", node.allocation().get().membership().cluster().vespaVersion().toFullString());
try {
object.setBool("allowedToBeDown", orchestrator.getNodeStatus(new HostName(node.hostname())) == HostStatus.ALLOWED_TO_BE_DOWN);
} catch (HostNameNotFoundException e) {
/* ok */
}
}
object.setLong("rebootGeneration", node.status().reboot().wanted());
object.setLong("currentRebootGeneration", node.status().reboot().current());
node.status().vespaVersion().filter(version -> !version.isEmpty()).ifPresent(version -> {
object.setString("vespaVersion", version.toFullString());
object.setString("currentDockerImage", nodeRepository.dockerImage().withTag(version).asString());
// TODO: Remove these when they are no longer read
object.setString("hostedVersion", version.toFullString());
object.setString("convergedStateVersion", version.toFullString());
});
object.setLong("failCount", node.status().failCount());
object.setBool("hardwareFailure", node.status().hardwareFailureDescription().isPresent());
node.status().hardwareFailureDescription().ifPresent(failure -> object.setString("hardwareFailureDescription", failure));
object.setBool("wantToRetire", node.status().wantToRetire());
object.setBool("wantToDeprovision", node.status().wantToDeprovision());
toSlime(node.history(), object.setArray("history"));
ipAddressesToSlime(node.ipAddresses(), object.setArray("ipAddresses"));
ipAddressesToSlime(node.additionalIpAddresses(), object.setArray("additionalIpAddresses"));
node.status().hardwareDivergence().ifPresent(hardwareDivergence -> object.setString("hardwareDivergence", hardwareDivergence));
}
use of com.yahoo.vespa.applicationmodel.HostName in project vespa by vespa-engine.
the class SingleInstanceClusterControllerClientFactory method createClient.
@Override
public ClusterControllerClient createClient(List<HostName> clusterControllers, String clusterName) {
if (clusterControllers.isEmpty()) {
throw new IllegalArgumentException("No cluster controller instances found");
}
HostName controllerHostName = clusterControllers.iterator().next();
// TODO: Get this from service monitor.
int port = CLUSTERCONTROLLER_HARDCODED_PORT;
log.log(LogLevel.DEBUG, () -> "For cluster '" + clusterName + "' with controllers " + clusterControllers + ", creating api client for " + controllerHostName.s() + ":" + port);
JaxRsStrategy<ClusterControllerJaxRsApi> strategy = new NoRetryJaxRsStrategy<>(controllerHostName, port, jaxRsClientFactory, ClusterControllerJaxRsApi.class, CLUSTERCONTROLLER_API_PATH, CLUSTERCONTROLLER_HARDCODED_SCHEME);
return new ClusterControllerClientImpl(strategy, clusterName);
}
use of com.yahoo.vespa.applicationmodel.HostName in project vespa by vespa-engine.
the class ClusterApiImpl method storageNodeInGroup.
private Optional<StorageNode> storageNodeInGroup(Predicate<ServiceInstance> storageServicePredicate) {
if (!VespaModelUtil.isStorage(serviceCluster)) {
return Optional.empty();
}
Set<StorageNode> storageNodes = new HashSet<>();
for (ServiceInstance serviceInstance : servicesInGroup) {
if (!storageServicePredicate.test(serviceInstance)) {
continue;
}
HostName hostName = serviceInstance.hostName();
if (nodeGroup.contains(hostName)) {
if (storageNodes.contains(hostName)) {
throw new IllegalStateException("Found more than 1 storage service instance on " + hostName + ": last service instance is " + serviceInstance.configId() + " in storage cluster " + clusterInfo());
}
StorageNode storageNode = new StorageNodeImpl(nodeGroup.getApplication(), clusterId(), serviceInstance, clusterControllerClientFactory);
storageNodes.add(storageNode);
}
}
if (storageNodes.size() > 1) {
throw new IllegalStateException("Found more than 1 storage node (" + storageNodes + ") in the same cluster (" + clusterInfo() + ") in the same node group (" + getNodeGroup().toCommaSeparatedString() + "): E.g. suspension of such a setup is not supported " + " by the Cluster Controller and is dangerous w.r.t. data redundancy.");
}
return storageNodes.stream().findFirst();
}
Aggregations