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