use of com.yahoo.vespa.config.server.tenant.Tenant in project vespa by vespa-engine.
the class ListApplicationsHandler method listApplicationIds.
private List<ApplicationId> listApplicationIds(TenantName tenantName) {
Utils.checkThatTenantExists(tenants, tenantName);
Tenant tenant = tenants.getTenant(tenantName);
TenantApplications applicationRepo = tenant.getApplicationRepo();
return applicationRepo.listApplications();
}
use of com.yahoo.vespa.config.server.tenant.Tenant in project vespa by vespa-engine.
the class SessionCreateHandler method handlePOST.
@Override
protected HttpResponse handlePOST(HttpRequest request) {
Slime deployLog = createDeployLog();
final TenantName tenantName = Utils.getTenantNameFromSessionRequest(request);
Utils.checkThatTenantExists(tenants, tenantName);
Tenant tenant = tenants.getTenant(tenantName);
TimeoutBudget timeoutBudget = SessionHandler.getTimeoutBudget(request, zookeeperBarrierTimeout);
DeployLogger logger = createLogger(request, deployLog, tenantName);
long sessionId;
if (request.hasProperty("from")) {
ApplicationId applicationId = getFromApplicationId(request);
sessionId = applicationRepository.createSessionFromExisting(tenant, logger, timeoutBudget, applicationId);
} else {
validateDataAndHeader(request);
String name = getNameProperty(request, logger);
sessionId = applicationRepository.createSession(tenant, timeoutBudget, request.getData(), request.getHeader(ApplicationApiHandler.contentTypeHeader), name);
}
return createResponse(request, tenantName, deployLog, sessionId);
}
use of com.yahoo.vespa.config.server.tenant.Tenant in project vespa by vespa-engine.
the class ApplicationHandlerTest method testDelete.
@Test
public void testDelete() throws Exception {
Clock clock = Clock.systemUTC();
ApplicationId defaultId = new ApplicationId.Builder().applicationName(ApplicationName.defaultName()).tenant(mytenantName).build();
assertApplicationExists(mytenantName, null, Zone.defaultZone());
long sessionId = 1;
{
// This block is a real test of the interplay of (most of) the components of the config server
// TODO: Extract it to ApplicationRepositoryTest, rewrite to bypass the HTTP layer and extend
// as login is moved from the HTTP layer into ApplicationRepository
Tenants tenants = addApplication(defaultId, sessionId);
ApplicationHandler handler = createApplicationHandler(tenants);
Tenant mytenant = tenants.getTenant(defaultId.tenant());
LocalSession applicationData = mytenant.getLocalSessionRepo().getSession(sessionId);
assertNotNull(applicationData);
assertNotNull(applicationData.getApplicationId());
assertFalse(provisioner.removed);
deleteAndAssertOKResponse(handler, mytenant, defaultId);
assertTrue(provisioner.removed);
assertThat(provisioner.lastApplicationId.tenant(), is(mytenantName));
assertThat(provisioner.lastApplicationId, is(defaultId));
assertNull(mytenant.getLocalSessionRepo().getSession(sessionId));
assertNull(mytenant.getRemoteSessionRepo().getSession(sessionId));
}
sessionId++;
{
addMockApplication(tenants.getTenant(mytenantName), defaultId, sessionId, clock);
deleteAndAssertOKResponseMocked(defaultId, true);
ApplicationId fooId = new ApplicationId.Builder().tenant(mytenantName).applicationName("foo").instanceName("quux").build();
sessionId++;
addMockApplication(tenants.getTenant(mytenantName), fooId, sessionId, clock);
addMockApplication(tenants.getTenant(foobar), fooId, sessionId, clock);
assertApplicationExists(mytenantName, fooId, Zone.defaultZone());
assertApplicationExists(foobar, fooId, Zone.defaultZone());
deleteAndAssertOKResponseMocked(fooId, true);
assertThat(provisioner.lastApplicationId.tenant(), is(mytenantName));
assertThat(provisioner.lastApplicationId, is(fooId));
assertApplicationExists(mytenantName, null, Zone.defaultZone());
assertApplicationExists(foobar, fooId, Zone.defaultZone());
}
sessionId++;
{
ApplicationId baliId = new ApplicationId.Builder().tenant(mytenantName).applicationName("bali").instanceName("quux").build();
addMockApplication(tenants.getTenant(mytenantName), baliId, sessionId, clock);
deleteAndAssertOKResponseMocked(baliId, true);
assertApplicationExists(mytenantName, null, Zone.defaultZone());
}
}
use of com.yahoo.vespa.config.server.tenant.Tenant in project vespa by vespa-engine.
the class ApplicationHandlerTest method addApplication.
private static Tenants addApplication(ApplicationId applicationId, long sessionId) throws Exception {
// This method is a good illustration of the spaghetti wiring resulting from no design
// TODO: When this setup looks sane we have refactored sufficiently that there is a design
TenantName tenantName = applicationId.tenant();
Path tenantPath = Tenants.getTenantPath(tenantName);
Path sessionPath = tenantPath.append(Tenant.SESSIONS).append(String.valueOf(sessionId));
MockCurator curator = new MockCurator();
GlobalComponentRegistry componentRegistry = new TestComponentRegistry.Builder().curator(curator).modelFactoryRegistry(new ModelFactoryRegistry(Collections.singletonList(new VespaModelFactory(new NullConfigModelRegistry())))).build();
// Creates the application path element in zk
Tenants tenants = new Tenants(componentRegistry);
tenants.addTenant(tenantName);
Tenant tenant = tenants.getTenant(tenantName);
tenant.getApplicationRepo().createPutApplicationTransaction(applicationId, sessionId).commit();
ApplicationPackage app = FilesApplicationPackage.fromFile(testApp);
SessionZooKeeperClient sessionClient = new SessionZooKeeperClient(curator, sessionPath);
SessionContext context = new SessionContext(app, sessionClient, new File("/serverDb"), tenant.getApplicationRepo(), null, new SuperModelGenerationCounter(curator));
tenant.getLocalSessionRepo().addSession(new LocalSession(tenantName, sessionId, null, context));
// TODO: Instead, use ApplicationRepository to deploy the application
sessionClient.writeApplicationId(applicationId);
tenant.getRemoteSessionRepo().addSession(new RemoteSession(tenantName, sessionId, componentRegistry, sessionClient, Clock.systemUTC()));
return tenants;
}
use of com.yahoo.vespa.config.server.tenant.Tenant in project vespa by vespa-engine.
the class ApplicationRepository method deployFromLocalActive.
/**
* Creates a new deployment from the active application, if available.
*
* @param application the active application to be redeployed
* @param timeout the timeout to use for each individual deployment operation
* @return a new deployment from the local active, or empty if a local active application
* was not present for this id (meaning it either is not active or active on another
* node in the config server cluster)
*/
@Override
public Optional<com.yahoo.config.provision.Deployment> deployFromLocalActive(ApplicationId application, Duration timeout) {
Tenant tenant = tenants.getTenant(application.tenant());
if (tenant == null)
return Optional.empty();
LocalSession activeSession = getActiveSession(tenant, application);
if (activeSession == null)
return Optional.empty();
TimeoutBudget timeoutBudget = new TimeoutBudget(clock, timeout);
LocalSession newSession = tenant.getSessionFactory().createSessionFromExisting(activeSession, logger, timeoutBudget);
tenant.getLocalSessionRepo().addSession(newSession);
// Keep manually deployed applications on the latest version, don't change version otherwise
Version version = environment.isManuallyDeployed() ? Vtag.currentVersion : newSession.getVespaVersion();
return Optional.of(Deployment.unprepared(newSession, this, hostProvisioner, tenant, timeout, clock, // don't validate as this is already deployed
false, version));
}
Aggregations