use of com.yahoo.vespa.config.server.session.LocalSession 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.session.LocalSession in project vespa by vespa-engine.
the class SessionActiveHandlerTest method addLocalSession.
private LocalSessionRepo addLocalSession(long sessionId, DeployData deployData, SessionZooKeeperClient zkc) {
writeApplicationId(zkc, deployData.getApplicationName());
TenantFileSystemDirs tenantFileSystemDirs = TenantFileSystemDirs.createTestDirs(tenant);
ApplicationPackage app = FilesApplicationPackage.fromFileWithDeployData(testApp, deployData);
localRepo.addSession(new LocalSession(tenant, sessionId, new SessionTest.MockSessionPreparer(), new SessionContext(app, zkc, new File(tenantFileSystemDirs.sessionsPath(), String.valueOf(sessionId)), applicationRepo, new HostRegistry<>(), new SuperModelGenerationCounter(curator))));
return localRepo;
}
use of com.yahoo.vespa.config.server.session.LocalSession in project vespa by vespa-engine.
the class RedeployTest method testPurgingOfOldNonActiveDeployments.
@Test
public void testPurgingOfOldNonActiveDeployments() {
ManualClock clock = new ManualClock(Instant.now());
ConfigserverConfig configserverConfig = new ConfigserverConfig(new ConfigserverConfig.Builder().configServerDBDir(Files.createTempDir().getAbsolutePath()).configDefinitionsDir(Files.createTempDir().getAbsolutePath()).sessionLifetime(60));
DeployTester tester = new DeployTester("src/test/apps/app", configserverConfig, clock);
// session 2 (numbering starts at 2)
tester.deployApp("myapp", Instant.now());
clock.advance(Duration.ofSeconds(10));
Optional<com.yahoo.config.provision.Deployment> deployment2 = tester.redeployFromLocalActive();
assertTrue(deployment2.isPresent());
// session 3
deployment2.get().activate();
long activeSessionId = tester.tenant().getApplicationRepo().getSessionIdForApplication(tester.applicationId());
clock.advance(Duration.ofSeconds(10));
Optional<com.yahoo.config.provision.Deployment> deployment3 = tester.redeployFromLocalActive();
assertTrue(deployment3.isPresent());
// session 4 (not activated)
deployment3.get().prepare();
LocalSession deployment3session = ((Deployment) deployment3.get()).session();
assertNotEquals(activeSessionId, deployment3session);
// No change to active session id
assertEquals(activeSessionId, tester.tenant().getApplicationRepo().getSessionIdForApplication(tester.applicationId()));
assertEquals(3, tester.tenant().getLocalSessionRepo().listSessions().size());
// longer than session lifetime
clock.advance(Duration.ofHours(1));
// All sessions except 3 should be removed after the call to purgeOldSessions
tester.tenant().getLocalSessionRepo().purgeOldSessions();
final Collection<LocalSession> sessions = tester.tenant().getLocalSessionRepo().listSessions();
assertEquals(1, sessions.size());
assertEquals(3, new ArrayList<>(sessions).get(0).getSessionId());
}
use of com.yahoo.vespa.config.server.session.LocalSession 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));
}
use of com.yahoo.vespa.config.server.session.LocalSession in project vespa by vespa-engine.
the class ApplicationRepository method createSession.
public long createSession(Tenant tenant, TimeoutBudget timeoutBudget, File applicationDirectory, String applicationName) {
LocalSessionRepo localSessionRepo = tenant.getLocalSessionRepo();
SessionFactory sessionFactory = tenant.getSessionFactory();
LocalSession session = sessionFactory.createSession(applicationDirectory, applicationName, timeoutBudget);
localSessionRepo.addSession(session);
return session.getSessionId();
}
Aggregations