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);
}
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);
}
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());
}
}
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));
}
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));
}
Aggregations