Search in sources :

Example 1 with BadRequestException

use of com.yahoo.vespa.config.server.http.BadRequestException 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 2 with BadRequestException

use of com.yahoo.vespa.config.server.http.BadRequestException 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 3 with BadRequestException

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

the class TenantHandler method handleGET.

@Override
protected HttpResponse handleGET(HttpRequest request) {
    if (isGetTenantRequest(request)) {
        final TenantName tenantName = getTenantNameFromRequest(request);
        Utils.checkThatTenantExists(tenants, tenantName);
        return new TenantGetResponse(tenantName);
    } else if (isListTenantsRequest(request)) {
        return new ListTenantsResponse(tenants.getAllTenantNames());
    } else {
        throw new BadRequestException(request.getUri().toString());
    }
}
Also used : TenantName(com.yahoo.config.provision.TenantName) BadRequestException(com.yahoo.vespa.config.server.http.BadRequestException)

Aggregations

BadRequestException (com.yahoo.vespa.config.server.http.BadRequestException)3 ApplicationId (com.yahoo.config.provision.ApplicationId)2 TenantName (com.yahoo.config.provision.TenantName)2 Tenant (com.yahoo.vespa.config.server.tenant.Tenant)2 TenantApplications (com.yahoo.vespa.config.server.application.TenantApplications)1 InternalServerException (com.yahoo.vespa.config.server.http.InternalServerException)1 Test (org.junit.Test)1