Search in sources :

Example 1 with UNKNOWN

use of com.yahoo.vespa.hosted.node.admin.nodeagent.NodeAgentImpl.ContainerState.UNKNOWN in project vespa by vespa-engine.

the class NodeAgentImpl method converge.

// Public for testing
void converge() {
    final Optional<ContainerNodeSpec> nodeSpecOptional = nodeRepository.getContainerNodeSpec(hostname);
    // We just removed the node from node repo, so this is expected until NodeAdmin stop this NodeAgent
    if (!nodeSpecOptional.isPresent() && expectNodeNotInNodeRepo)
        return;
    final ContainerNodeSpec nodeSpec = nodeSpecOptional.orElseThrow(() -> new IllegalStateException(String.format("Node '%s' missing from node repository.", hostname)));
    expectNodeNotInNodeRepo = false;
    Optional<Container> container = getContainer();
    if (!nodeSpec.equals(lastNodeSpec)) {
        // will change and we will be reporting duplicate metrics.
        if (container.map(c -> c.state.isRunning()).orElse(false)) {
            storageMaintainer.writeMetricsConfig(containerName, nodeSpec);
        }
        addDebugMessage("Loading new node spec: " + nodeSpec.toString());
        lastNodeSpec = nodeSpec;
    }
    switch(nodeSpec.nodeState) {
        case ready:
        case reserved:
        case parked:
        case failed:
            removeContainerIfNeededUpdateContainerState(nodeSpec, container);
            updateNodeRepoWithCurrentAttributes(nodeSpec);
            break;
        case active:
            storageMaintainer.handleCoreDumpsForContainer(containerName, nodeSpec, false);
            storageMaintainer.getDiskUsageFor(containerName).map(diskUsage -> (double) diskUsage / BYTES_IN_GB / nodeSpec.minDiskAvailableGb).filter(diskUtil -> diskUtil >= 0.8).ifPresent(diskUtil -> storageMaintainer.removeOldFilesFromNode(containerName));
            scheduleDownLoadIfNeeded(nodeSpec);
            if (isDownloadingImage()) {
                addDebugMessage("Waiting for image to download " + imageBeingDownloaded.asString());
                return;
            }
            container = removeContainerIfNeededUpdateContainerState(nodeSpec, container);
            if (!container.isPresent()) {
                storageMaintainer.handleCoreDumpsForContainer(containerName, nodeSpec, false);
                containerState = STARTING;
                startContainer(nodeSpec);
                containerState = UNKNOWN;
            }
            runLocalResumeScriptIfNeeded(nodeSpec);
            // Because it's more important to stop a bad release from rolling out in prod,
            // we put the resume call last. So if we fail after updating the node repo attributes
            // but before resume, the app may go through the tenant pipeline but will halt in prod.
            // 
            // Note that this problem exists only because there are 2 different mechanisms
            // that should really be parts of a single mechanism:
            // - The content of node repo is used to determine whether a new Vespa+application
            // has been successfully rolled out.
            // - Slobrok and internal orchestrator state is used to determine whether
            // to allow upgrade (suspend).
            updateNodeRepoWithCurrentAttributes(nodeSpec);
            logger.info("Call resume against Orchestrator");
            orchestrator.resume(hostname);
            break;
        case inactive:
            removeContainerIfNeededUpdateContainerState(nodeSpec, container);
            updateNodeRepoWithCurrentAttributes(nodeSpec);
            break;
        case provisioned:
            nodeRepository.markAsDirty(hostname);
            break;
        case dirty:
            removeContainerIfNeededUpdateContainerState(nodeSpec, container);
            logger.info("State is " + nodeSpec.nodeState + ", will delete application storage and mark node as ready");
            storageMaintainer.cleanupNodeStorage(containerName, nodeSpec);
            updateNodeRepoWithCurrentAttributes(nodeSpec);
            nodeRepository.markNodeAvailableForNewAllocation(hostname);
            expectNodeNotInNodeRepo = true;
            break;
        default:
            throw new RuntimeException("UNKNOWN STATE " + nodeSpec.nodeState.name());
    }
}
Also used : DockerException(com.yahoo.vespa.hosted.dockerapi.DockerException) ContainerName(com.yahoo.vespa.hosted.dockerapi.ContainerName) Dimensions(com.yahoo.vespa.hosted.dockerapi.metrics.Dimensions) StorageMaintainer(com.yahoo.vespa.hosted.node.admin.maintenance.StorageMaintainer) Environment(com.yahoo.vespa.hosted.node.admin.component.Environment) Date(java.util.Date) PromptContainerData(com.yahoo.vespa.hosted.node.admin.containerdata.PromptContainerData) ThreadFactoryFactory(com.yahoo.concurrent.ThreadFactoryFactory) ProcessResult(com.yahoo.vespa.hosted.dockerapi.ProcessResult) SimpleDateFormat(java.text.SimpleDateFormat) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Node(com.yahoo.vespa.hosted.provision.Node) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) MetricReceiverWrapper(com.yahoo.vespa.hosted.dockerapi.metrics.MetricReceiverWrapper) Future(java.util.concurrent.Future) Duration(java.time.Duration) Map(java.util.Map) ContainerData(com.yahoo.vespa.hosted.node.admin.containerdata.ContainerData) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) LinkedList(java.util.LinkedList) PrefixLogger(com.yahoo.vespa.hosted.node.admin.util.PrefixLogger) ConfigServerContainerData(com.yahoo.vespa.hosted.node.admin.containerdata.ConfigServerContainerData) NodeType(com.yahoo.config.provision.NodeType) DockerOperations(com.yahoo.vespa.hosted.node.admin.docker.DockerOperations) Container(com.yahoo.vespa.hosted.dockerapi.Container) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) DimensionMetrics(com.yahoo.vespa.hosted.dockerapi.metrics.DimensionMetrics) NodeRepository(com.yahoo.vespa.hosted.node.admin.configserver.noderepository.NodeRepository) Instant(java.time.Instant) DockerExecTimeoutException(com.yahoo.vespa.hosted.dockerapi.DockerExecTimeoutException) Executors(java.util.concurrent.Executors) MotdContainerData(com.yahoo.vespa.hosted.node.admin.containerdata.MotdContainerData) UncheckedIOException(java.io.UncheckedIOException) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) List(java.util.List) ContainerNodeSpec(com.yahoo.vespa.hosted.node.admin.ContainerNodeSpec) STARTING(com.yahoo.vespa.hosted.node.admin.nodeagent.NodeAgentImpl.ContainerState.STARTING) DockerImage(com.yahoo.vespa.hosted.dockerapi.DockerImage) Docker(com.yahoo.vespa.hosted.dockerapi.Docker) ABSENT(com.yahoo.vespa.hosted.node.admin.nodeagent.NodeAgentImpl.ContainerState.ABSENT) Orchestrator(com.yahoo.vespa.hosted.node.admin.configserver.orchestrator.Orchestrator) UNKNOWN(com.yahoo.vespa.hosted.node.admin.nodeagent.NodeAgentImpl.ContainerState.UNKNOWN) Clock(java.time.Clock) Optional(java.util.Optional) OrchestratorException(com.yahoo.vespa.hosted.node.admin.configserver.orchestrator.OrchestratorException) ContainerResources(com.yahoo.vespa.hosted.dockerapi.ContainerResources) Container(com.yahoo.vespa.hosted.dockerapi.Container) ContainerNodeSpec(com.yahoo.vespa.hosted.node.admin.ContainerNodeSpec)

Example 2 with UNKNOWN

use of com.yahoo.vespa.hosted.node.admin.nodeagent.NodeAgentImpl.ContainerState.UNKNOWN in project vespa by vespa-engine.

the class NodeAgentImpl method updateNodeRepoWithCurrentAttributes.

private void updateNodeRepoWithCurrentAttributes(final ContainerNodeSpec nodeSpec) {
    final NodeAttributes currentNodeAttributes = new NodeAttributes().withRestartGeneration(nodeSpec.currentRestartGeneration.orElse(null)).withRebootGeneration(nodeSpec.currentRebootGeneration.orElse(0L)).withDockerImage(nodeSpec.currentDockerImage.orElse(new DockerImage(""))).withVespaVersion(nodeSpec.vespaVersion.orElse(""));
    final NodeAttributes wantedNodeAttributes = new NodeAttributes().withRestartGeneration(nodeSpec.wantedRestartGeneration.orElse(null)).withRebootGeneration(nodeSpec.wantedRebootGeneration.orElse(0L)).withDockerImage(nodeSpec.wantedDockerImage.filter(node -> containerState == UNKNOWN).orElse(new DockerImage(""))).withVespaVersion(nodeSpec.wantedVespaVersion.filter(node -> containerState == UNKNOWN).orElse(""));
    publishStateToNodeRepoIfChanged(currentNodeAttributes, wantedNodeAttributes);
}
Also used : DockerException(com.yahoo.vespa.hosted.dockerapi.DockerException) ContainerName(com.yahoo.vespa.hosted.dockerapi.ContainerName) Dimensions(com.yahoo.vespa.hosted.dockerapi.metrics.Dimensions) StorageMaintainer(com.yahoo.vespa.hosted.node.admin.maintenance.StorageMaintainer) Environment(com.yahoo.vespa.hosted.node.admin.component.Environment) Date(java.util.Date) PromptContainerData(com.yahoo.vespa.hosted.node.admin.containerdata.PromptContainerData) ThreadFactoryFactory(com.yahoo.concurrent.ThreadFactoryFactory) ProcessResult(com.yahoo.vespa.hosted.dockerapi.ProcessResult) SimpleDateFormat(java.text.SimpleDateFormat) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Node(com.yahoo.vespa.hosted.provision.Node) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) MetricReceiverWrapper(com.yahoo.vespa.hosted.dockerapi.metrics.MetricReceiverWrapper) Future(java.util.concurrent.Future) Duration(java.time.Duration) Map(java.util.Map) ContainerData(com.yahoo.vespa.hosted.node.admin.containerdata.ContainerData) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) LinkedList(java.util.LinkedList) PrefixLogger(com.yahoo.vespa.hosted.node.admin.util.PrefixLogger) ConfigServerContainerData(com.yahoo.vespa.hosted.node.admin.containerdata.ConfigServerContainerData) NodeType(com.yahoo.config.provision.NodeType) DockerOperations(com.yahoo.vespa.hosted.node.admin.docker.DockerOperations) Container(com.yahoo.vespa.hosted.dockerapi.Container) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) DimensionMetrics(com.yahoo.vespa.hosted.dockerapi.metrics.DimensionMetrics) NodeRepository(com.yahoo.vespa.hosted.node.admin.configserver.noderepository.NodeRepository) Instant(java.time.Instant) DockerExecTimeoutException(com.yahoo.vespa.hosted.dockerapi.DockerExecTimeoutException) Executors(java.util.concurrent.Executors) MotdContainerData(com.yahoo.vespa.hosted.node.admin.containerdata.MotdContainerData) UncheckedIOException(java.io.UncheckedIOException) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) List(java.util.List) ContainerNodeSpec(com.yahoo.vespa.hosted.node.admin.ContainerNodeSpec) STARTING(com.yahoo.vespa.hosted.node.admin.nodeagent.NodeAgentImpl.ContainerState.STARTING) DockerImage(com.yahoo.vespa.hosted.dockerapi.DockerImage) Docker(com.yahoo.vespa.hosted.dockerapi.Docker) ABSENT(com.yahoo.vespa.hosted.node.admin.nodeagent.NodeAgentImpl.ContainerState.ABSENT) Orchestrator(com.yahoo.vespa.hosted.node.admin.configserver.orchestrator.Orchestrator) UNKNOWN(com.yahoo.vespa.hosted.node.admin.nodeagent.NodeAgentImpl.ContainerState.UNKNOWN) Clock(java.time.Clock) Optional(java.util.Optional) OrchestratorException(com.yahoo.vespa.hosted.node.admin.configserver.orchestrator.OrchestratorException) ContainerResources(com.yahoo.vespa.hosted.dockerapi.ContainerResources) DockerImage(com.yahoo.vespa.hosted.dockerapi.DockerImage)

Aggregations

JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 ThreadFactoryFactory (com.yahoo.concurrent.ThreadFactoryFactory)2 NodeType (com.yahoo.config.provision.NodeType)2 Container (com.yahoo.vespa.hosted.dockerapi.Container)2 ContainerName (com.yahoo.vespa.hosted.dockerapi.ContainerName)2 ContainerResources (com.yahoo.vespa.hosted.dockerapi.ContainerResources)2 Docker (com.yahoo.vespa.hosted.dockerapi.Docker)2 DockerException (com.yahoo.vespa.hosted.dockerapi.DockerException)2 DockerExecTimeoutException (com.yahoo.vespa.hosted.dockerapi.DockerExecTimeoutException)2 DockerImage (com.yahoo.vespa.hosted.dockerapi.DockerImage)2 ProcessResult (com.yahoo.vespa.hosted.dockerapi.ProcessResult)2 DimensionMetrics (com.yahoo.vespa.hosted.dockerapi.metrics.DimensionMetrics)2 Dimensions (com.yahoo.vespa.hosted.dockerapi.metrics.Dimensions)2 MetricReceiverWrapper (com.yahoo.vespa.hosted.dockerapi.metrics.MetricReceiverWrapper)2 ContainerNodeSpec (com.yahoo.vespa.hosted.node.admin.ContainerNodeSpec)2 Environment (com.yahoo.vespa.hosted.node.admin.component.Environment)2 NodeRepository (com.yahoo.vespa.hosted.node.admin.configserver.noderepository.NodeRepository)2 Orchestrator (com.yahoo.vespa.hosted.node.admin.configserver.orchestrator.Orchestrator)2 OrchestratorException (com.yahoo.vespa.hosted.node.admin.configserver.orchestrator.OrchestratorException)2 ConfigServerContainerData (com.yahoo.vespa.hosted.node.admin.containerdata.ConfigServerContainerData)2