Search in sources :

Example 36 with TenantName

use of com.yahoo.config.provision.TenantName in project vespa by vespa-engine.

the class SessionContentHandler method getContentRequest.

private SessionContentRequestV2 getContentRequest(HttpRequest request) {
    final TenantName tenantName = Utils.getTenantNameFromSessionRequest(request);
    validateRequest(tenantName);
    long sessionId = getSessionIdV2(request);
    String contentPath = SessionContentRequestV2.getContentPath(request);
    ApplicationFile applicationFile = applicationRepository.getApplicationFileFromSession(tenantName, sessionId, contentPath, ContentRequest.getApplicationFileMode(request.getMethod()));
    return new SessionContentRequestV2(request, sessionId, tenantName, contentPath, applicationFile);
}
Also used : TenantName(com.yahoo.config.provision.TenantName) ApplicationFile(com.yahoo.config.application.api.ApplicationFile)

Example 37 with TenantName

use of com.yahoo.config.provision.TenantName 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 38 with TenantName

use of com.yahoo.config.provision.TenantName 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)

Example 39 with TenantName

use of com.yahoo.config.provision.TenantName in project vespa by vespa-engine.

the class SessionPrepareHandlerTest method require_that_preparing_with_multiple_tenants_work.

@Test
public void require_that_preparing_with_multiple_tenants_work() throws Exception {
    // Need different repos for 'default' tenant as opposed to the 'test' tenant
    LocalSessionRepo localRepoDefault = new LocalSessionRepo(Clock.systemUTC());
    final TenantName defaultTenant = TenantName.defaultName();
    addTenant(defaultTenant, localRepoDefault, new RemoteSessionRepo(tenant), new MockSessionFactory());
    addTestTenant();
    final SessionHandler handler = createHandler(builder);
    long sessionId = 1;
    // Deploy with default tenant
    MockSession session = new MockSession(sessionId, null);
    localRepoDefault.addSession(session);
    pathPrefix = "/application/v2/tenant/" + defaultTenant + "/session/";
    HttpResponse response = handler.handle(SessionHandlerTest.createTestRequest(pathPrefix, HttpRequest.Method.PUT, Cmd.PREPARED, sessionId));
    assertNotNull(response);
    assertThat(SessionHandlerTest.getRenderedString(response), response.getStatus(), is(OK));
    assertThat(session.getStatus(), is(Session.Status.PREPARE));
    // Same session id, as this is for another tenant
    session = new MockSession(sessionId, null);
    localRepo.addSession(session);
    String applicationName = "myapp";
    pathPrefix = "/application/v2/tenant/" + tenant + "/session/" + sessionId + "/prepared?applicationName=" + applicationName;
    response = handler.handle(SessionHandlerTest.createTestRequest(pathPrefix));
    assertNotNull(response);
    assertThat(SessionHandlerTest.getRenderedString(response), response.getStatus(), is(OK));
    assertThat(session.getStatus(), is(Session.Status.PREPARE));
    sessionId++;
    session = new MockSession(sessionId, null);
    localRepo.addSession(session);
    pathPrefix = "/application/v2/tenant/" + tenant + "/session/" + sessionId + "/prepared?applicationName=" + applicationName + "&instance=quux";
    response = handler.handle(SessionHandlerTest.createTestRequest(pathPrefix));
    assertNotNull(response);
    assertThat(SessionHandlerTest.getRenderedString(response), response.getStatus(), is(OK));
    assertThat(session.getStatus(), is(Session.Status.PREPARE));
}
Also used : TenantName(com.yahoo.config.provision.TenantName) HttpResponse(com.yahoo.container.jdisc.HttpResponse) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 40 with TenantName

use of com.yahoo.config.provision.TenantName in project vespa by vespa-engine.

the class SessionPreparerTest method require_that_application_id_is_written_in_prepare.

@Test
public void require_that_application_id_is_written_in_prepare() throws IOException {
    TenantName tenant = TenantName.from("tenant");
    ApplicationId origId = new ApplicationId.Builder().tenant(tenant).applicationName("foo").instanceName("quux").build();
    PrepareParams params = new PrepareParams.Builder().applicationId(origId).build();
    preparer.prepare(getContext(getApplicationPackage(testApp)), getLogger(), params, Optional.empty(), tenantPath, Instant.now());
    SessionZooKeeperClient zkc = new SessionZooKeeperClient(curator, sessionsPath);
    assertTrue(configCurator.exists(sessionsPath.append(SessionZooKeeperClient.APPLICATION_ID_PATH).getAbsolute()));
    assertThat(zkc.readApplicationId(), is(origId));
}
Also used : TenantName(com.yahoo.config.provision.TenantName) ApplicationId(com.yahoo.config.provision.ApplicationId) Test(org.junit.Test)

Aggregations

TenantName (com.yahoo.config.provision.TenantName)48 Test (org.junit.Test)15 ApplicationId (com.yahoo.config.provision.ApplicationId)12 Map (java.util.Map)12 LinkedHashMap (java.util.LinkedHashMap)11 Tenant (com.yahoo.vespa.config.server.tenant.Tenant)9 LbServicesConfig (com.yahoo.cloud.config.LbServicesConfig)4 ApplicationInfo (com.yahoo.config.model.api.ApplicationInfo)4 ApplicationName (com.yahoo.config.provision.ApplicationName)4 SuperModel (com.yahoo.config.model.api.SuperModel)3 Slime (com.yahoo.slime.Slime)3 TimeoutBudget (com.yahoo.vespa.config.server.TimeoutBudget)3 PrepareParams (com.yahoo.vespa.config.server.session.PrepareParams)3 File (java.io.File)3 ArrayList (java.util.ArrayList)3 DeployLogger (com.yahoo.config.application.api.DeployLogger)2 DeployState (com.yahoo.config.model.deploy.DeployState)2 Version (com.yahoo.config.provision.Version)2 Zone (com.yahoo.config.provision.Zone)2 ConfigKey (com.yahoo.vespa.config.ConfigKey)2