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());
}
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);
}
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);
}
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;
}
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");
}
Aggregations