Search in sources :

Example 16 with Tenant

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

the class TenantHandlerTest method testDeleteTenantWithActiveApplications.

@Test
public void testDeleteTenantWithActiveApplications() throws Exception {
    putSync(HttpRequest.createTestRequest("http://deploy.example.yahoo.com:80/application/v2/tenant/" + a, Method.PUT));
    Tenant tenant = tenants.getTenant(a);
    assertEquals(a, tenant.getName());
    int sessionId = 1;
    ApplicationId app = ApplicationId.from(a, ApplicationName.from("foo"), InstanceName.defaultName());
    ApplicationHandlerTest.addMockApplication(tenant, app, sessionId, Clock.systemUTC());
    try {
        handler.handleDELETE(HttpRequest.createTestRequest("http://deploy.example.yahoo.com:80/application/v2/tenant/" + a, Method.DELETE));
        fail();
    } catch (BadRequestException e) {
        assertThat(e.getMessage(), is("Cannot delete tenant 'a', as it has active applications: [a.foo]"));
    }
}
Also used : Tenant(com.yahoo.vespa.config.server.tenant.Tenant) BadRequestException(com.yahoo.vespa.config.server.http.BadRequestException) ApplicationId(com.yahoo.config.provision.ApplicationId) Test(org.junit.Test)

Example 17 with Tenant

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

the class SessionActiveHandler method handlePUT.

@Override
protected HttpResponse handlePUT(HttpRequest request) {
    final TenantName tenantName = Utils.getTenantNameFromSessionRequest(request);
    Utils.checkThatTenantExists(tenants, tenantName);
    Tenant tenant = tenants.getTenant(tenantName);
    TimeoutBudget timeoutBudget = getTimeoutBudget(request, DEFAULT_ACTIVATE_TIMEOUT);
    final Long sessionId = getSessionIdV2(request);
    ApplicationId applicationId = applicationRepository.activate(tenant, sessionId, timeoutBudget, shouldIgnoreLockFailure(request), shouldIgnoreSessionStaleFailure(request));
    ApplicationMetaData metaData = applicationRepository.getMetadataFromSession(tenant, sessionId);
    return new SessionActiveResponse(metaData.getSlime(), request, applicationId, sessionId, zone);
}
Also used : ApplicationMetaData(com.yahoo.config.application.api.ApplicationMetaData) Tenant(com.yahoo.vespa.config.server.tenant.Tenant) TenantName(com.yahoo.config.provision.TenantName) TimeoutBudget(com.yahoo.vespa.config.server.TimeoutBudget) ApplicationId(com.yahoo.config.provision.ApplicationId)

Example 18 with Tenant

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

the class TenantHandler method handleDELETE.

@Override
protected HttpResponse handleDELETE(HttpRequest request) {
    final TenantName tenantName = getTenantNameFromRequest(request);
    Utils.checkThatTenantExists(tenants, tenantName);
    // TODO: Move logic to ApplicationRepository
    Tenant tenant = tenants.getTenant(tenantName);
    TenantApplications applicationRepo = tenant.getApplicationRepo();
    final List<ApplicationId> activeApplications = applicationRepo.listApplications();
    if (activeApplications.isEmpty()) {
        try {
            tenants.deleteTenant(tenantName);
        } catch (IllegalArgumentException e) {
            throw e;
        } catch (Exception e) {
            throw new InternalServerException(Exceptions.toMessageString(e));
        }
    } else {
        throw new BadRequestException("Cannot delete tenant '" + tenantName + "', as it has active applications: " + activeApplications);
    }
    return new TenantDeleteResponse(tenantName);
}
Also used : Tenant(com.yahoo.vespa.config.server.tenant.Tenant) TenantName(com.yahoo.config.provision.TenantName) InternalServerException(com.yahoo.vespa.config.server.http.InternalServerException) BadRequestException(com.yahoo.vespa.config.server.http.BadRequestException) TenantApplications(com.yahoo.vespa.config.server.application.TenantApplications) ApplicationId(com.yahoo.config.provision.ApplicationId) BadRequestException(com.yahoo.vespa.config.server.http.BadRequestException) InternalServerException(com.yahoo.vespa.config.server.http.InternalServerException)

Example 19 with Tenant

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

the class SessionPrepareHandler method handleGET.

@Override
protected HttpResponse handleGET(HttpRequest request) {
    Tenant tenant = getExistingTenant(request);
    long sessionId = getSessionIdV2(request);
    applicationRepository.validateThatRemoteSessionIsNotActive(tenant, sessionId);
    applicationRepository.validateThatRemoteSessionIsPrepared(tenant, sessionId);
    return new SessionPrepareResponse(createDeployLog(), tenant.getName(), request, sessionId);
}
Also used : Tenant(com.yahoo.vespa.config.server.tenant.Tenant)

Example 20 with Tenant

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

the class DeployTester method deployApp.

/**
 * Do the initial "deploy" with the existing API-less code as the deploy API doesn't support first deploys yet.
 */
public ApplicationId deployApp(String appName, String vespaVersion, Instant now) {
    Tenant tenant = tenant();
    TimeoutBudget timeoutBudget = new TimeoutBudget(clock, Duration.ofSeconds(60));
    ApplicationId id = ApplicationId.from(tenant.getName(), ApplicationName.from(appName), InstanceName.defaultName());
    PrepareParams.Builder paramsBuilder = new PrepareParams.Builder().applicationId(id);
    if (vespaVersion != null)
        paramsBuilder.vespaVersion(vespaVersion);
    long sessionId = applicationRepository.createSession(tenant, timeoutBudget, testApp, appName);
    applicationRepository.prepare(tenant, sessionId, paramsBuilder.build(), now);
    applicationRepository.activate(tenant, sessionId, timeoutBudget, false, false);
    this.id = id;
    return id;
}
Also used : Tenant(com.yahoo.vespa.config.server.tenant.Tenant) TimeoutBudget(com.yahoo.vespa.config.server.TimeoutBudget) ApplicationId(com.yahoo.config.provision.ApplicationId) 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