Search in sources :

Example 6 with LocalSession

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;
}
Also used : Path(com.yahoo.path.Path) TenantName(com.yahoo.config.provision.TenantName) ModelFactoryRegistry(com.yahoo.vespa.config.server.modelfactory.ModelFactoryRegistry) LocalSession(com.yahoo.vespa.config.server.session.LocalSession) Tenants(com.yahoo.vespa.config.server.tenant.Tenants) GlobalComponentRegistry(com.yahoo.vespa.config.server.GlobalComponentRegistry) FilesApplicationPackage(com.yahoo.config.model.application.provider.FilesApplicationPackage) ApplicationPackage(com.yahoo.config.application.api.ApplicationPackage) VespaModelFactory(com.yahoo.vespa.model.VespaModelFactory) NullConfigModelRegistry(com.yahoo.config.model.NullConfigModelRegistry) Tenant(com.yahoo.vespa.config.server.tenant.Tenant) TestComponentRegistry(com.yahoo.vespa.config.server.TestComponentRegistry) RemoteSession(com.yahoo.vespa.config.server.session.RemoteSession) SessionContext(com.yahoo.vespa.config.server.session.SessionContext) SuperModelGenerationCounter(com.yahoo.vespa.config.server.SuperModelGenerationCounter) File(java.io.File) MockCurator(com.yahoo.vespa.curator.mock.MockCurator) SessionZooKeeperClient(com.yahoo.vespa.config.server.session.SessionZooKeeperClient)

Example 7 with LocalSession

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;
}
Also used : TenantFileSystemDirs(com.yahoo.vespa.config.server.deploy.TenantFileSystemDirs) LocalSession(com.yahoo.vespa.config.server.session.LocalSession) SessionContext(com.yahoo.vespa.config.server.session.SessionContext) SuperModelGenerationCounter(com.yahoo.vespa.config.server.SuperModelGenerationCounter) FilesApplicationPackage(com.yahoo.config.model.application.provider.FilesApplicationPackage) ApplicationPackage(com.yahoo.config.application.api.ApplicationPackage) File(java.io.File)

Example 8 with LocalSession

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());
}
Also used : ConfigserverConfig(com.yahoo.cloud.config.ConfigserverConfig) ManualClock(com.yahoo.test.ManualClock) LocalSession(com.yahoo.vespa.config.server.session.LocalSession) Test(org.junit.Test)

Example 9 with LocalSession

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));
}
Also used : Tenant(com.yahoo.vespa.config.server.tenant.Tenant) Version(com.yahoo.component.Version) LocalSession(com.yahoo.vespa.config.server.session.LocalSession)

Example 10 with LocalSession

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();
}
Also used : SessionFactory(com.yahoo.vespa.config.server.session.SessionFactory) LocalSessionRepo(com.yahoo.vespa.config.server.session.LocalSessionRepo) LocalSession(com.yahoo.vespa.config.server.session.LocalSession)

Aggregations

LocalSession (com.yahoo.vespa.config.server.session.LocalSession)11 Tenant (com.yahoo.vespa.config.server.tenant.Tenant)5 LocalSessionRepo (com.yahoo.vespa.config.server.session.LocalSessionRepo)3 ApplicationPackage (com.yahoo.config.application.api.ApplicationPackage)2 FilesApplicationPackage (com.yahoo.config.model.application.provider.FilesApplicationPackage)2 ApplicationId (com.yahoo.config.provision.ApplicationId)2 SuperModelGenerationCounter (com.yahoo.vespa.config.server.SuperModelGenerationCounter)2 SessionContext (com.yahoo.vespa.config.server.session.SessionContext)2 SessionFactory (com.yahoo.vespa.config.server.session.SessionFactory)2 Tenants (com.yahoo.vespa.config.server.tenant.Tenants)2 File (java.io.File)2 Test (org.junit.Test)2 ConfigserverConfig (com.yahoo.cloud.config.ConfigserverConfig)1 Version (com.yahoo.component.Version)1 DeployLogger (com.yahoo.config.application.api.DeployLogger)1 NullConfigModelRegistry (com.yahoo.config.model.NullConfigModelRegistry)1 TenantName (com.yahoo.config.provision.TenantName)1 Path (com.yahoo.path.Path)1 Slime (com.yahoo.slime.Slime)1 ManualClock (com.yahoo.test.ManualClock)1