Search in sources :

Example 1 with Tenant

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;
}
Also used : Tenant(com.yahoo.vespa.config.server.tenant.Tenant) LocalSessionRepo(com.yahoo.vespa.config.server.session.LocalSessionRepo) LocalSession(com.yahoo.vespa.config.server.session.LocalSession) NestedTransaction(com.yahoo.transaction.NestedTransaction) TenantApplications(com.yahoo.vespa.config.server.application.TenantApplications) Rotations(com.yahoo.vespa.config.server.tenant.Rotations)

Example 2 with Tenant

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);
}
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 Tenant

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");
}
Also used : Tenant(com.yahoo.vespa.config.server.tenant.Tenant) NotFoundException(com.yahoo.vespa.config.server.http.NotFoundException) ApplicationId(com.yahoo.config.provision.ApplicationId)

Example 4 with Tenant

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));
}
Also used : Tenant(com.yahoo.vespa.config.server.tenant.Tenant) ApplicationFile(com.yahoo.config.application.api.ApplicationFile) Duration(java.time.Duration) ApplicationId(com.yahoo.config.provision.ApplicationId) ContentHandler(com.yahoo.vespa.config.server.http.ContentHandler)

Example 5 with Tenant

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);
}
Also used : Tenant(com.yahoo.vespa.config.server.tenant.Tenant) TenantName(com.yahoo.config.provision.TenantName) PrepareParams(com.yahoo.vespa.config.server.session.PrepareParams)

Aggregations

Tenant (com.yahoo.vespa.config.server.tenant.Tenant)21 ApplicationId (com.yahoo.config.provision.ApplicationId)10 TenantName (com.yahoo.config.provision.TenantName)10 LocalSession (com.yahoo.vespa.config.server.session.LocalSession)6 TenantApplications (com.yahoo.vespa.config.server.application.TenantApplications)5 PrepareParams (com.yahoo.vespa.config.server.session.PrepareParams)5 TimeoutBudget (com.yahoo.vespa.config.server.TimeoutBudget)4 DeployLogger (com.yahoo.config.application.api.DeployLogger)3 Slime (com.yahoo.slime.Slime)3 Test (org.junit.Test)3 Version (com.yahoo.component.Version)2 ApplicationFile (com.yahoo.config.application.api.ApplicationFile)2 ApplicationMetaData (com.yahoo.config.application.api.ApplicationMetaData)2 Path (com.yahoo.path.Path)2 NestedTransaction (com.yahoo.transaction.NestedTransaction)2 TestComponentRegistry (com.yahoo.vespa.config.server.TestComponentRegistry)2 BadRequestException (com.yahoo.vespa.config.server.http.BadRequestException)2 Tenants (com.yahoo.vespa.config.server.tenant.Tenants)2 Files (com.google.common.io.Files)1 Inject (com.google.inject.Inject)1