Search in sources :

Example 1 with TimeoutBudget

use of com.yahoo.vespa.config.server.TimeoutBudget in project vespa by vespa-engine.

the class Deployment method activate.

/**
 * Activates this. If it is not already prepared, this will call prepare first.
 */
@Override
public void activate() {
    if (!prepared)
        prepare();
    TimeoutBudget timeoutBudget = new TimeoutBudget(clock, timeout);
    long sessionId = session.getSessionId();
    validateSessionStatus(session);
    ActivateLock activateLock = tenant.getActivateLock();
    boolean activateLockAcquired = false;
    try {
        log.log(LogLevel.DEBUG, "Trying to acquire lock " + activateLock + " for session " + sessionId);
        activateLockAcquired = activateLock.acquire(timeoutBudget, ignoreLockFailure);
        if (!activateLockAcquired) {
            throw new ActivationConflictException("Did not get activate lock for session " + sessionId + " within " + timeout);
        }
        log.log(LogLevel.DEBUG, "Lock acquired " + activateLock + " for session " + sessionId);
        NestedTransaction transaction = new NestedTransaction();
        transaction.add(deactivateCurrentActivateNew(applicationRepository.getActiveSession(session.getApplicationId()), session, ignoreSessionStaleFailure));
        if (hostProvisioner.isPresent()) {
            hostProvisioner.get().activate(transaction, session.getApplicationId(), session.getAllocatedHosts().getHosts());
        }
        transaction.commit();
        session.waitUntilActivated(timeoutBudget);
    } catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        throw new InternalServerException("Error activating application", e);
    } finally {
        if (activateLockAcquired) {
            log.log(LogLevel.DEBUG, "Trying to release lock " + activateLock + " for session " + sessionId);
            activateLock.release();
            log.log(LogLevel.DEBUG, "Lock released " + activateLock + " for session " + sessionId);
        }
    }
    log.log(LogLevel.INFO, session.logPre() + "Session " + sessionId + " activated successfully using " + (hostProvisioner.isPresent() ? hostProvisioner.get() : "no host provisioner") + ". Config generation " + session.getMetaData().getGeneration());
}
Also used : ActivationConflictException(com.yahoo.vespa.config.server.ActivationConflictException) InternalServerException(com.yahoo.vespa.config.server.http.InternalServerException) NestedTransaction(com.yahoo.transaction.NestedTransaction) TimeoutBudget(com.yahoo.vespa.config.server.TimeoutBudget) InternalServerException(com.yahoo.vespa.config.server.http.InternalServerException) ActivationConflictException(com.yahoo.vespa.config.server.ActivationConflictException) ActivateLock(com.yahoo.vespa.config.server.tenant.ActivateLock)

Example 2 with TimeoutBudget

use of com.yahoo.vespa.config.server.TimeoutBudget in project vespa by vespa-engine.

the class ApplicationApiHandler method handlePOST.

@Override
protected HttpResponse handlePOST(HttpRequest request) {
    Tenant tenant = getExistingTenant(request);
    TenantName tenantName = tenant.getName();
    TimeoutBudget timeoutBudget = SessionHandler.getTimeoutBudget(request, zookeeperBarrierTimeout);
    PrepareParams prepareParams = PrepareParams.fromHttpRequest(request, tenantName, zookeeperBarrierTimeout);
    Slime deployLog = createDeployLog();
    DeployLogger logger = SessionCreateHandler.createLogger(request, deployLog, tenantName);
    String name = SessionCreateHandler.getNameProperty(request, logger);
    SessionCreateHandler.validateDataAndHeader(request);
    PrepareResult result = applicationRepository.createSessionAndPrepareAndActivate(tenant, request.getData(), request.getHeader(contentTypeHeader), timeoutBudget, name, prepareParams, shouldIgnoreLockFailure(request), shouldIgnoreSessionStaleFailure(request), Instant.now());
    return new SessionPrepareAndActivateResponse(result, tenantName, request, prepareParams.getApplicationId(), zone);
}
Also used : Tenant(com.yahoo.vespa.config.server.tenant.Tenant) TenantName(com.yahoo.config.provision.TenantName) TimeoutBudget(com.yahoo.vespa.config.server.TimeoutBudget) DeployLogger(com.yahoo.config.application.api.DeployLogger) Slime(com.yahoo.slime.Slime) PrepareParams(com.yahoo.vespa.config.server.session.PrepareParams)

Example 3 with TimeoutBudget

use of com.yahoo.vespa.config.server.TimeoutBudget in project vespa by vespa-engine.

the class SessionCreateHandler method handlePOST.

@Override
protected HttpResponse handlePOST(HttpRequest request) {
    Slime deployLog = createDeployLog();
    final TenantName tenantName = Utils.getTenantNameFromSessionRequest(request);
    Utils.checkThatTenantExists(tenants, tenantName);
    Tenant tenant = tenants.getTenant(tenantName);
    TimeoutBudget timeoutBudget = SessionHandler.getTimeoutBudget(request, zookeeperBarrierTimeout);
    DeployLogger logger = createLogger(request, deployLog, tenantName);
    long sessionId;
    if (request.hasProperty("from")) {
        ApplicationId applicationId = getFromApplicationId(request);
        sessionId = applicationRepository.createSessionFromExisting(tenant, logger, timeoutBudget, applicationId);
    } else {
        validateDataAndHeader(request);
        String name = getNameProperty(request, logger);
        sessionId = applicationRepository.createSession(tenant, timeoutBudget, request.getData(), request.getHeader(ApplicationApiHandler.contentTypeHeader), name);
    }
    return createResponse(request, tenantName, deployLog, sessionId);
}
Also used : Tenant(com.yahoo.vespa.config.server.tenant.Tenant) TenantName(com.yahoo.config.provision.TenantName) TimeoutBudget(com.yahoo.vespa.config.server.TimeoutBudget) DeployLogger(com.yahoo.config.application.api.DeployLogger) Slime(com.yahoo.slime.Slime) ApplicationId(com.yahoo.config.provision.ApplicationId)

Example 4 with TimeoutBudget

use of com.yahoo.vespa.config.server.TimeoutBudget in project vespa by vespa-engine.

the class Deployment method prepare.

/**
 * Prepares this. This does nothing if this is already prepared
 */
@Override
public void prepare() {
    if (prepared)
        return;
    TimeoutBudget timeoutBudget = new TimeoutBudget(clock, timeout);
    session.prepare(logger, new PrepareParams.Builder().applicationId(session.getApplicationId()).timeoutBudget(timeoutBudget).ignoreValidationErrors(!validate).vespaVersion(version.toString()).build(), Optional.empty(), tenant.getPath(), clock.instant());
    this.prepared = true;
}
Also used : TimeoutBudget(com.yahoo.vespa.config.server.TimeoutBudget)

Example 5 with TimeoutBudget

use of com.yahoo.vespa.config.server.TimeoutBudget in project vespa by vespa-engine.

the class SessionRepo method internalGetSession.

private synchronized SESSIONTYPE internalGetSession(long id, long timeoutInMillis) throws InterruptedException {
    TimeoutBudget timeoutBudget = new TimeoutBudget(Clock.systemUTC(), Duration.ofMillis(timeoutInMillis));
    do {
        SESSIONTYPE session = getSession(id);
        if (session != null) {
            return session;
        }
        wait(100);
    } while (timeoutBudget.hasTimeLeft());
    throw new NotFoundException("Unable to retrieve session with id " + id + " before timeout was reached");
}
Also used : NotFoundException(com.yahoo.vespa.config.server.NotFoundException) TimeoutBudget(com.yahoo.vespa.config.server.TimeoutBudget)

Aggregations

TimeoutBudget (com.yahoo.vespa.config.server.TimeoutBudget)7 Tenant (com.yahoo.vespa.config.server.tenant.Tenant)4 ApplicationId (com.yahoo.config.provision.ApplicationId)3 TenantName (com.yahoo.config.provision.TenantName)3 DeployLogger (com.yahoo.config.application.api.DeployLogger)2 Slime (com.yahoo.slime.Slime)2 PrepareParams (com.yahoo.vespa.config.server.session.PrepareParams)2 ApplicationMetaData (com.yahoo.config.application.api.ApplicationMetaData)1 NestedTransaction (com.yahoo.transaction.NestedTransaction)1 ActivationConflictException (com.yahoo.vespa.config.server.ActivationConflictException)1 NotFoundException (com.yahoo.vespa.config.server.NotFoundException)1 InternalServerException (com.yahoo.vespa.config.server.http.InternalServerException)1 ActivateLock (com.yahoo.vespa.config.server.tenant.ActivateLock)1