Search in sources :

Example 1 with HostNameNotFoundException

use of com.yahoo.vespa.orchestrator.HostNameNotFoundException in project vespa by vespa-engine.

the class MetricsReporter method updateNodeMetrics.

private void updateNodeMetrics(Node node, Map<HostName, List<ServiceInstance>> servicesByHost) {
    Metric.Context context;
    Optional<Allocation> allocation = node.allocation();
    if (allocation.isPresent()) {
        ApplicationId applicationId = allocation.get().owner();
        context = getContextAt("state", node.state().name(), "host", node.hostname(), "tenantName", applicationId.tenant().value(), "applicationId", applicationId.serializedForm().replace(':', '.'), "app", toApp(applicationId), "clustertype", allocation.get().membership().cluster().type().name(), "clusterid", allocation.get().membership().cluster().id().value());
        long wantedRestartGeneration = allocation.get().restartGeneration().wanted();
        metric.set("wantedRestartGeneration", wantedRestartGeneration, context);
        long currentRestartGeneration = allocation.get().restartGeneration().current();
        metric.set("currentRestartGeneration", currentRestartGeneration, context);
        boolean wantToRestart = currentRestartGeneration < wantedRestartGeneration;
        metric.set("wantToRestart", wantToRestart ? 1 : 0, context);
        Version wantedVersion = allocation.get().membership().cluster().vespaVersion();
        double wantedVersionNumber = getVersionAsNumber(wantedVersion);
        metric.set("wantedVespaVersion", wantedVersionNumber, context);
        Optional<Version> currentVersion = node.status().vespaVersion();
        boolean converged = currentVersion.isPresent() && currentVersion.get().equals(wantedVersion);
        metric.set("wantToChangeVespaVersion", converged ? 0 : 1, context);
    } else {
        context = getContextAt("state", node.state().name(), "host", node.hostname());
    }
    Optional<Version> currentVersion = node.status().vespaVersion();
    // Node repo checks for !isEmpty(), so let's do that here too.
    if (currentVersion.isPresent() && !currentVersion.get().isEmpty()) {
        double currentVersionNumber = getVersionAsNumber(currentVersion.get());
        metric.set("currentVespaVersion", currentVersionNumber, context);
    }
    long wantedRebootGeneration = node.status().reboot().wanted();
    metric.set("wantedRebootGeneration", wantedRebootGeneration, context);
    long currentRebootGeneration = node.status().reboot().current();
    metric.set("currentRebootGeneration", currentRebootGeneration, context);
    boolean wantToReboot = currentRebootGeneration < wantedRebootGeneration;
    metric.set("wantToReboot", wantToReboot ? 1 : 0, context);
    metric.set("wantToRetire", node.status().wantToRetire() ? 1 : 0, context);
    metric.set("wantToDeprovision", node.status().wantToDeprovision() ? 1 : 0, context);
    metric.set("hardwareFailure", node.status().hardwareFailureDescription().isPresent() ? 1 : 0, context);
    metric.set("hardwareDivergence", node.status().hardwareDivergence().isPresent() ? 1 : 0, context);
    try {
        HostStatus status = orchestrator.getNodeStatus(new HostName(node.hostname()));
        boolean allowedToBeDown = status == HostStatus.ALLOWED_TO_BE_DOWN;
        metric.set("allowedToBeDown", allowedToBeDown ? 1 : 0, context);
    } catch (HostNameNotFoundException e) {
    // Ignore
    }
    long numberOfServices;
    HostName hostName = new HostName(node.hostname());
    List<ServiceInstance> services = servicesByHost.get(hostName);
    if (services == null) {
        numberOfServices = 0;
    } else {
        Map<ServiceStatus, Long> servicesCount = services.stream().collect(Collectors.groupingBy(ServiceInstance::serviceStatus, Collectors.counting()));
        numberOfServices = servicesCount.values().stream().mapToLong(Long::longValue).sum();
        metric.set("numberOfServicesUp", servicesCount.getOrDefault(ServiceStatus.UP, 0L), context);
        metric.set("numberOfServicesNotChecked", servicesCount.getOrDefault(ServiceStatus.NOT_CHECKED, 0L), context);
        long numberOfServicesDown = servicesCount.getOrDefault(ServiceStatus.DOWN, 0L);
        metric.set("numberOfServicesDown", numberOfServicesDown, context);
        metric.set("someServicesDown", (numberOfServicesDown > 0 ? 1 : 0), context);
        boolean badNode = NodeFailer.badNode(services);
        metric.set("nodeFailerBadNode", (badNode ? 1 : 0), context);
        boolean nodeDownInNodeRepo = node.history().event(History.Event.Type.down).isPresent();
        metric.set("downInNodeRepo", (nodeDownInNodeRepo ? 1 : 0), context);
    }
    metric.set("numberOfServices", numberOfServices, context);
}
Also used : ServiceInstance(com.yahoo.vespa.applicationmodel.ServiceInstance) Allocation(com.yahoo.vespa.hosted.provision.node.Allocation) Version(com.yahoo.component.Version) ServiceStatus(com.yahoo.vespa.applicationmodel.ServiceStatus) Metric(com.yahoo.jdisc.Metric) HostStatus(com.yahoo.vespa.orchestrator.status.HostStatus) ApplicationId(com.yahoo.config.provision.ApplicationId) HostName(com.yahoo.vespa.applicationmodel.HostName) HostNameNotFoundException(com.yahoo.vespa.orchestrator.HostNameNotFoundException)

Example 2 with HostNameNotFoundException

use of com.yahoo.vespa.orchestrator.HostNameNotFoundException 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 3 with HostNameNotFoundException

use of com.yahoo.vespa.orchestrator.HostNameNotFoundException in project vespa by vespa-engine.

the class HostResource method patch.

@Override
public PatchHostResponse patch(String hostNameString, PatchHostRequest request) {
    HostName hostName = new HostName(hostNameString);
    if (request.state != null) {
        HostStatus state;
        try {
            state = HostStatus.valueOf(request.state);
        } catch (IllegalArgumentException dummy) {
            throw new BadRequestException("Bad state in request: '" + request.state + "'");
        }
        try {
            orchestrator.setNodeStatus(hostName, state);
        } catch (HostNameNotFoundException e) {
            log.log(LogLevel.INFO, "Host not found: " + hostName);
            throw new NotFoundException(e);
        } catch (OrchestrationException e) {
            String message = "Failed to set " + hostName + " to " + state + ": " + e.getMessage();
            log.log(LogLevel.INFO, message, e);
            throw new InternalServerErrorException(message);
        }
    }
    PatchHostResponse response = new PatchHostResponse();
    response.description = "ok";
    return response;
}
Also used : PatchHostResponse(com.yahoo.vespa.orchestrator.restapi.wire.PatchHostResponse) OrchestrationException(com.yahoo.vespa.orchestrator.OrchestrationException) BadRequestException(javax.ws.rs.BadRequestException) HostNameNotFoundException(com.yahoo.vespa.orchestrator.HostNameNotFoundException) NotFoundException(javax.ws.rs.NotFoundException) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) HostStatus(com.yahoo.vespa.orchestrator.status.HostStatus) HostName(com.yahoo.vespa.applicationmodel.HostName) HostNameNotFoundException(com.yahoo.vespa.orchestrator.HostNameNotFoundException)

Example 4 with HostNameNotFoundException

use of com.yahoo.vespa.orchestrator.HostNameNotFoundException in project vespa by vespa-engine.

the class HostResource method getHost.

@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 (HostNameNotFoundException e) {
        log.log(LogLevel.INFO, "Host not found: " + hostName);
        throw new NotFoundException(e);
    }
}
Also used : OrchestrationException(com.yahoo.vespa.orchestrator.OrchestrationException) PatchHostRequest(com.yahoo.vespa.orchestrator.restapi.wire.PatchHostRequest) Path(javax.ws.rs.Path) Orchestrator(com.yahoo.vespa.orchestrator.Orchestrator) Inject(javax.inject.Inject) GetHostResponse(com.yahoo.vespa.orchestrator.restapi.wire.GetHostResponse) MediaType(javax.ws.rs.core.MediaType) HostName(com.yahoo.vespa.applicationmodel.HostName) HostStateChangeDeniedException(com.yahoo.vespa.orchestrator.policy.HostStateChangeDeniedException) HostStateChangeDenialReason(com.yahoo.vespa.orchestrator.restapi.wire.HostStateChangeDenialReason) Component(com.yahoo.container.jaxrs.annotation.Component) LogLevel(com.yahoo.log.LogLevel) Host(com.yahoo.vespa.orchestrator.Host) BadRequestException(javax.ws.rs.BadRequestException) URI(java.net.URI) UpdateHostResponse(com.yahoo.vespa.orchestrator.restapi.wire.UpdateHostResponse) HostNameNotFoundException(com.yahoo.vespa.orchestrator.HostNameNotFoundException) Context(javax.ws.rs.core.Context) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) NotFoundException(javax.ws.rs.NotFoundException) List(java.util.List) Response(javax.ws.rs.core.Response) HostService(com.yahoo.vespa.orchestrator.restapi.wire.HostService) WebApplicationException(javax.ws.rs.WebApplicationException) HostStatus(com.yahoo.vespa.orchestrator.status.HostStatus) UriInfo(javax.ws.rs.core.UriInfo) PatchHostResponse(com.yahoo.vespa.orchestrator.restapi.wire.PatchHostResponse) HostApi(com.yahoo.vespa.orchestrator.restapi.HostApi) HostService(com.yahoo.vespa.orchestrator.restapi.wire.HostService) GetHostResponse(com.yahoo.vespa.orchestrator.restapi.wire.GetHostResponse) HostNameNotFoundException(com.yahoo.vespa.orchestrator.HostNameNotFoundException) NotFoundException(javax.ws.rs.NotFoundException) Host(com.yahoo.vespa.orchestrator.Host) URI(java.net.URI) HostName(com.yahoo.vespa.applicationmodel.HostName) HostNameNotFoundException(com.yahoo.vespa.orchestrator.HostNameNotFoundException)

Aggregations

HostName (com.yahoo.vespa.applicationmodel.HostName)4 HostNameNotFoundException (com.yahoo.vespa.orchestrator.HostNameNotFoundException)4 HostStatus (com.yahoo.vespa.orchestrator.status.HostStatus)4 ApplicationId (com.yahoo.config.provision.ApplicationId)2 OrchestrationException (com.yahoo.vespa.orchestrator.OrchestrationException)2 Orchestrator (com.yahoo.vespa.orchestrator.Orchestrator)2 PatchHostResponse (com.yahoo.vespa.orchestrator.restapi.wire.PatchHostResponse)2 URI (java.net.URI)2 List (java.util.List)2 BadRequestException (javax.ws.rs.BadRequestException)2 InternalServerErrorException (javax.ws.rs.InternalServerErrorException)2 NotFoundException (javax.ws.rs.NotFoundException)2 Version (com.yahoo.component.Version)1 ClusterMembership (com.yahoo.config.provision.ClusterMembership)1 NodeType (com.yahoo.config.provision.NodeType)1 Component (com.yahoo.container.jaxrs.annotation.Component)1 HttpRequest (com.yahoo.container.jdisc.HttpRequest)1 HttpResponse (com.yahoo.container.jdisc.HttpResponse)1 Metric (com.yahoo.jdisc.Metric)1 LogLevel (com.yahoo.log.LogLevel)1