Search in sources :

Example 26 with HostName

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);
}
Also used : IOException(java.io.IOException) HostName(com.yahoo.vespa.applicationmodel.HostName) ProcessingException(javax.ws.rs.ProcessingException)

Example 27 with HostName

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);
}
Also used : ClientBuilder(javax.ws.rs.client.ClientBuilder) SSLContext(javax.net.ssl.SSLContext) HttpHeaders(javax.ws.rs.core.HttpHeaders) HttpUrlConnectorProvider(org.glassfish.jersey.client.HttpUrlConnectorProvider) HostName(com.yahoo.vespa.applicationmodel.HostName) WebResourceFactory(org.glassfish.jersey.client.proxy.WebResourceFactory) UriBuilder(javax.ws.rs.core.UriBuilder) ClientProperties(org.glassfish.jersey.client.ClientProperties) WebTarget(javax.ws.rs.client.WebTarget) HostnameVerifier(javax.net.ssl.HostnameVerifier) ClientRequestFilter(javax.ws.rs.client.ClientRequestFilter) Collections(java.util.Collections) WebTarget(javax.ws.rs.client.WebTarget) UriBuilder(javax.ws.rs.core.UriBuilder) ClientBuilder(javax.ws.rs.client.ClientBuilder)

Example 28 with HostName

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));
}
Also used : NodeFilter(com.yahoo.vespa.hosted.provision.node.filter.NodeFilter) HostNameNotFoundException(com.yahoo.vespa.orchestrator.HostNameNotFoundException) OutputStream(java.io.OutputStream) Cursor(com.yahoo.slime.Cursor) ApplicationId(com.yahoo.config.provision.ApplicationId) ClusterMembership(com.yahoo.config.provision.ClusterMembership) NodeType(com.yahoo.config.provision.NodeType) Slime(com.yahoo.slime.Slime) HttpRequest(com.yahoo.container.jdisc.HttpRequest) Set(java.util.Set) IOException(java.io.IOException) Orchestrator(com.yahoo.vespa.orchestrator.Orchestrator) Node(com.yahoo.vespa.hosted.provision.Node) NodeRepository(com.yahoo.vespa.hosted.provision.NodeRepository) List(java.util.List) History(com.yahoo.vespa.hosted.provision.node.History) HostName(com.yahoo.vespa.applicationmodel.HostName) SlimeUtils(com.yahoo.vespa.config.SlimeUtils) HostStatus(com.yahoo.vespa.orchestrator.status.HostStatus) URI(java.net.URI) HttpResponse(com.yahoo.container.jdisc.HttpResponse) HostName(com.yahoo.vespa.applicationmodel.HostName) HostNameNotFoundException(com.yahoo.vespa.orchestrator.HostNameNotFoundException)

Example 29 with HostName

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);
}
Also used : NoRetryJaxRsStrategy(com.yahoo.vespa.jaxrs.client.NoRetryJaxRsStrategy) HostName(com.yahoo.vespa.applicationmodel.HostName)

Example 30 with HostName

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();
}
Also used : ServiceInstance(com.yahoo.vespa.applicationmodel.ServiceInstance) HostName(com.yahoo.vespa.applicationmodel.HostName) HashSet(java.util.HashSet)

Aggregations

HostName (com.yahoo.vespa.applicationmodel.HostName)46 Test (org.junit.Test)20 ApplicationInstance (com.yahoo.vespa.applicationmodel.ApplicationInstance)14 ServiceType (com.yahoo.vespa.applicationmodel.ServiceType)13 ServiceCluster (com.yahoo.vespa.applicationmodel.ServiceCluster)9 ServiceInstance (com.yahoo.vespa.applicationmodel.ServiceInstance)9 ClusterId (com.yahoo.vespa.applicationmodel.ClusterId)8 HostStatus (com.yahoo.vespa.orchestrator.status.HostStatus)8 List (java.util.List)8 ApplicationId (com.yahoo.config.provision.ApplicationId)7 ApplicationInstanceReference (com.yahoo.vespa.applicationmodel.ApplicationInstanceReference)7 Orchestrator (com.yahoo.vespa.orchestrator.Orchestrator)7 Collectors (java.util.stream.Collectors)7 ApplicationInstanceId (com.yahoo.vespa.applicationmodel.ApplicationInstanceId)6 ConfigId (com.yahoo.vespa.applicationmodel.ConfigId)6 TenantId (com.yahoo.vespa.applicationmodel.TenantId)6 ServiceStatus (com.yahoo.vespa.applicationmodel.ServiceStatus)5 OrchestrationException (com.yahoo.vespa.orchestrator.OrchestrationException)5 StorageNode (com.yahoo.vespa.orchestrator.model.StorageNode)5 IOException (java.io.IOException)5