Search in sources :

Example 1 with LocalSession

use of com.yahoo.vespa.config.server.session.LocalSession in project vespa by vespa-engine.

the class ApplicationRepository method remove.

/**
 * Removes a previously deployed application
 *
 * @return true if the application was found and removed, false if it was not present
 * @throws RuntimeException if the remove transaction fails. This method is exception safe.
 */
public boolean remove(ApplicationId applicationId) {
    Optional<Tenant> owner = Optional.ofNullable(tenants.getTenant(applicationId.tenant()));
    if (!owner.isPresent())
        return false;
    TenantApplications tenantApplications = owner.get().getApplicationRepo();
    if (!tenantApplications.listApplications().contains(applicationId))
        return false;
    // TODO: Push lookup logic down
    long sessionId = tenantApplications.getSessionIdForApplication(applicationId);
    LocalSessionRepo localSessionRepo = owner.get().getLocalSessionRepo();
    LocalSession session = localSessionRepo.getSession(sessionId);
    if (session == null)
        return false;
    NestedTransaction transaction = new NestedTransaction();
    localSessionRepo.removeSession(session.getSessionId(), transaction);
    // TODO: Not unit tested
    session.delete(transaction);
    // TODO: Not unit tested
    transaction.add(new Rotations(owner.get().getCurator(), owner.get().getPath()).delete(applicationId));
    // (When rotations are updated in zk, we need to redeploy the zone app, on the right config server
    // this is done asynchronously in application maintenance by the node repository)
    transaction.add(tenantApplications.deleteApplication(applicationId));
    hostProvisioner.ifPresent(provisioner -> provisioner.remove(transaction, applicationId));
    transaction.onCommitted(() -> log.log(LogLevel.INFO, "Deleted " + applicationId));
    transaction.commit();
    return true;
}
Also used : Tenant(com.yahoo.vespa.config.server.tenant.Tenant) LocalSessionRepo(com.yahoo.vespa.config.server.session.LocalSessionRepo) LocalSession(com.yahoo.vespa.config.server.session.LocalSession) NestedTransaction(com.yahoo.transaction.NestedTransaction) TenantApplications(com.yahoo.vespa.config.server.application.TenantApplications) Rotations(com.yahoo.vespa.config.server.tenant.Rotations)

Example 2 with LocalSession

use of com.yahoo.vespa.config.server.session.LocalSession in project vespa by vespa-engine.

the class ApplicationRepository method prepare.

public PrepareResult prepare(Tenant tenant, long sessionId, PrepareParams prepareParams, Instant now) {
    validateThatLocalSessionIsNotActive(tenant, sessionId);
    LocalSession session = getLocalSession(tenant, sessionId);
    ApplicationId applicationId = prepareParams.getApplicationId();
    Optional<ApplicationSet> currentActiveApplicationSet = getCurrentActiveApplicationSet(tenant, applicationId);
    Slime deployLog = createDeployLog();
    DeployLogger logger = new DeployHandlerLogger(deployLog.get().setArray("log"), prepareParams.isVerbose(), applicationId);
    ConfigChangeActions actions = session.prepare(logger, prepareParams, currentActiveApplicationSet, tenant.getPath(), now);
    logConfigChangeActions(actions, logger);
    log.log(LogLevel.INFO, Tenants.logPre(applicationId) + "Session " + sessionId + " prepared successfully. ");
    return new PrepareResult(sessionId, actions, deployLog);
}
Also used : PrepareResult(com.yahoo.vespa.config.server.http.v2.PrepareResult) LocalSession(com.yahoo.vespa.config.server.session.LocalSession) ConfigChangeActions(com.yahoo.vespa.config.server.configchange.ConfigChangeActions) DeployHandlerLogger(com.yahoo.vespa.config.server.deploy.DeployHandlerLogger) DeployLogger(com.yahoo.config.application.api.DeployLogger) SilentDeployLogger(com.yahoo.vespa.config.server.session.SilentDeployLogger) ApplicationId(com.yahoo.config.provision.ApplicationId) ApplicationSet(com.yahoo.vespa.config.server.application.ApplicationSet) Slime(com.yahoo.slime.Slime)

Example 3 with LocalSession

use of com.yahoo.vespa.config.server.session.LocalSession in project vespa by vespa-engine.

the class ApplicationRepository method createSessionFromExisting.

public long createSessionFromExisting(Tenant tenant, DeployLogger logger, TimeoutBudget timeoutBudget, ApplicationId applicationId) {
    LocalSessionRepo localSessionRepo = tenant.getLocalSessionRepo();
    SessionFactory sessionFactory = tenant.getSessionFactory();
    LocalSession fromSession = getExistingSession(tenant, applicationId);
    LocalSession session = sessionFactory.createSessionFromExisting(fromSession, logger, 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)

Example 4 with LocalSession

use of com.yahoo.vespa.config.server.session.LocalSession in project vespa by vespa-engine.

the class ApplicationRepository method activate.

public ApplicationId activate(Tenant tenant, long sessionId, TimeoutBudget timeoutBudget, boolean ignoreLockFailure, boolean ignoreSessionStaleFailure) {
    LocalSession localSession = getLocalSession(tenant, sessionId);
    Deployment deployment = deployFromPreparedSession(localSession, tenant, timeoutBudget.timeLeft());
    deployment.setIgnoreLockFailure(ignoreLockFailure);
    deployment.setIgnoreSessionStaleFailure(ignoreSessionStaleFailure);
    deployment.activate();
    return localSession.getApplicationId();
}
Also used : LocalSession(com.yahoo.vespa.config.server.session.LocalSession) Deployment(com.yahoo.vespa.config.server.deploy.Deployment)

Example 5 with LocalSession

use of com.yahoo.vespa.config.server.session.LocalSession 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());
    }
}
Also used : Tenant(com.yahoo.vespa.config.server.tenant.Tenant) LocalSession(com.yahoo.vespa.config.server.session.LocalSession) Tenants(com.yahoo.vespa.config.server.tenant.Tenants) Clock(java.time.Clock) ApplicationId(com.yahoo.config.provision.ApplicationId) HandlerTest(com.yahoo.vespa.config.server.http.HandlerTest) SessionHandlerTest(com.yahoo.vespa.config.server.http.SessionHandlerTest) Test(org.junit.Test)

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