use of com.yahoo.vespa.config.server.tenant.Tenant in project vespa by vespa-engine.
the class ApplicationRepository method remove.
/**
* Removes a previously deployed application
*
* @return true if the application was found and removed, false if it was not present
* @throws RuntimeException if the remove transaction fails. This method is exception safe.
*/
public boolean remove(ApplicationId applicationId) {
Optional<Tenant> owner = Optional.ofNullable(tenants.getTenant(applicationId.tenant()));
if (!owner.isPresent())
return false;
TenantApplications tenantApplications = owner.get().getApplicationRepo();
if (!tenantApplications.listApplications().contains(applicationId))
return false;
// TODO: Push lookup logic down
long sessionId = tenantApplications.getSessionIdForApplication(applicationId);
LocalSessionRepo localSessionRepo = owner.get().getLocalSessionRepo();
LocalSession session = localSessionRepo.getSession(sessionId);
if (session == null)
return false;
NestedTransaction transaction = new NestedTransaction();
localSessionRepo.removeSession(session.getSessionId(), transaction);
// TODO: Not unit tested
session.delete(transaction);
// TODO: Not unit tested
transaction.add(new Rotations(owner.get().getCurator(), owner.get().getPath()).delete(applicationId));
// (When rotations are updated in zk, we need to redeploy the zone app, on the right config server
// this is done asynchronously in application maintenance by the node repository)
transaction.add(tenantApplications.deleteApplication(applicationId));
hostProvisioner.ifPresent(provisioner -> provisioner.remove(transaction, applicationId));
transaction.onCommitted(() -> log.log(LogLevel.INFO, "Deleted " + applicationId));
transaction.commit();
return true;
}
use of com.yahoo.vespa.config.server.tenant.Tenant 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.tenant.Tenant in project vespa by vespa-engine.
the class ApplicationHandler method handlePOST.
@Override
public HttpResponse handlePOST(HttpRequest request) {
ApplicationId applicationId = getApplicationIdFromRequest(request);
Tenant tenant = verifyTenantAndApplication(applicationId);
if (request.getUri().getPath().endsWith("restart"))
return restart(request, applicationId);
if (request.getUri().getPath().endsWith("log"))
return grabLog(request, applicationId, tenant);
throw new NotFoundException("Illegal POST request '" + request.getUri() + "': Must end by /restart or /log");
}
use of com.yahoo.vespa.config.server.tenant.Tenant in project vespa by vespa-engine.
the class ApplicationHandler method handleGET.
@Override
public HttpResponse handleGET(HttpRequest request) {
ApplicationId applicationId = getApplicationIdFromRequest(request);
Tenant tenant = verifyTenantAndApplication(applicationId);
if (isServiceConvergeRequest(request)) {
return applicationRepository.serviceConvergenceCheck(tenant, applicationId, getHostNameFromRequest(request), request.getUri());
}
if (isClusterControllerStatusRequest(request)) {
String hostName = getHostNameFromRequest(request);
String pathSuffix = getPathSuffix(request);
return applicationRepository.clusterControllerStatusPage(tenant, applicationId, hostName, pathSuffix);
}
if (isContentRequest(request)) {
long sessionId = applicationRepository.getSessionIdForApplication(tenant, applicationId);
String contentPath = ApplicationContentRequest.getContentPath(request);
ApplicationFile applicationFile = applicationRepository.getApplicationFileFromSession(tenant.getName(), sessionId, contentPath, ContentRequest.getApplicationFileMode(request.getMethod()));
ApplicationContentRequest contentRequest = new ApplicationContentRequest(request, sessionId, applicationId, zone, contentPath, applicationFile);
return new ContentHandler().get(contentRequest);
}
if (isServiceConvergeListRequest(request)) {
return applicationRepository.serviceListToCheckForConfigConvergence(tenant, applicationId, request.getUri());
}
if (isFiledistributionStatusRequest(request)) {
Duration timeout = HttpHandler.getRequestTimeout(request, Duration.ofSeconds(5));
return applicationRepository.filedistributionStatus(tenant, applicationId, timeout);
}
return new GetApplicationResponse(Response.Status.OK, applicationRepository.getApplicationGeneration(tenant, applicationId));
}
use of com.yahoo.vespa.config.server.tenant.Tenant in project vespa by vespa-engine.
the class SessionPrepareHandler method handlePUT.
@Override
protected HttpResponse handlePUT(HttpRequest request) {
Tenant tenant = getExistingTenant(request);
TenantName tenantName = tenant.getName();
long sessionId = getSessionIdV2(request);
PrepareParams prepareParams = PrepareParams.fromHttpRequest(request, tenantName, zookeeperBarrierTimeout);
PrepareResult result = applicationRepository.prepare(tenant, sessionId, prepareParams, Instant.now());
return new SessionPrepareResponse(result, tenantName, request);
}
Aggregations