All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.yahoo.vespa.hosted.provision.provisioning.FirmwareChecks Maven / Gradle / Ivy

There is a newer version: 8.441.21
Show newest version
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.provision.provisioning;

import com.yahoo.lang.CachedSupplier;
import com.yahoo.vespa.hosted.provision.persistence.CuratorDb;

import java.time.Clock;
import java.time.Duration;
import java.time.Instant;
import java.util.Optional;

/**
 * Keeps cached data about when to do a firmware check on the hosts managed by a node repository.
 *
 * The data kept here is managed through POST and DELETE to /nodes/v2/upgrade/firmware
 * 

* Reads and writes are not locked, as writes do not depend on prior state. *

* Local cache expires periodically, and on writes from this host, for testing. * * @author jonmv */ public class FirmwareChecks { private static final Duration cacheExpiry = Duration.ofMinutes(1); private final CuratorDb database; private final Clock clock; private final CachedSupplier> checkAfter; public FirmwareChecks(CuratorDb database, Clock clock) { this.database = database; this.clock = clock; this.checkAfter = new CachedSupplier<>(database::readFirmwareCheck, cacheExpiry); } /** Returns the instant after which a firmware check is required, or empty if none currently are. */ public Optional requiredAfter() { return checkAfter.get(); } /** Requests a firmware check for all hosts managed by this node repository. */ public void request() { database.writeFirmwareCheck(Optional.of(clock.instant())); checkAfter.invalidate(); } /** Clears any outstanding firmware checks for this node repository. */ public void cancel() { database.writeFirmwareCheck(Optional.empty()); checkAfter.invalidate(); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy