use of com.yahoo.transaction.NestedTransaction 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.transaction.NestedTransaction in project vespa by vespa-engine.
the class Deployment method activate.
/**
* Activates this. If it is not already prepared, this will call prepare first.
*/
@Override
public void activate() {
if (!prepared)
prepare();
TimeoutBudget timeoutBudget = new TimeoutBudget(clock, timeout);
long sessionId = session.getSessionId();
validateSessionStatus(session);
ActivateLock activateLock = tenant.getActivateLock();
boolean activateLockAcquired = false;
try {
log.log(LogLevel.DEBUG, "Trying to acquire lock " + activateLock + " for session " + sessionId);
activateLockAcquired = activateLock.acquire(timeoutBudget, ignoreLockFailure);
if (!activateLockAcquired) {
throw new ActivationConflictException("Did not get activate lock for session " + sessionId + " within " + timeout);
}
log.log(LogLevel.DEBUG, "Lock acquired " + activateLock + " for session " + sessionId);
NestedTransaction transaction = new NestedTransaction();
transaction.add(deactivateCurrentActivateNew(applicationRepository.getActiveSession(session.getApplicationId()), session, ignoreSessionStaleFailure));
if (hostProvisioner.isPresent()) {
hostProvisioner.get().activate(transaction, session.getApplicationId(), session.getAllocatedHosts().getHosts());
}
transaction.commit();
session.waitUntilActivated(timeoutBudget);
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new InternalServerException("Error activating application", e);
} finally {
if (activateLockAcquired) {
log.log(LogLevel.DEBUG, "Trying to release lock " + activateLock + " for session " + sessionId);
activateLock.release();
log.log(LogLevel.DEBUG, "Lock released " + activateLock + " for session " + sessionId);
}
}
log.log(LogLevel.INFO, session.logPre() + "Session " + sessionId + " activated successfully using " + (hostProvisioner.isPresent() ? hostProvisioner.get() : "no host provisioner") + ". Config generation " + session.getMetaData().getGeneration());
}
use of com.yahoo.transaction.NestedTransaction in project vespa by vespa-engine.
the class CuratorDatabaseClient method writeTo.
/**
* Writes the given nodes to the given state (whether or not they are already in this state or another),
* and returns a copy of the incoming nodes in their persisted state.
*
* @param toState the state to write the nodes to
* @param nodes the list of nodes to write
* @param agent the agent causing this change
* @return the nodes in their persisted state
*/
public List<Node> writeTo(Node.State toState, List<Node> nodes, Agent agent, Optional<String> reason) {
try (NestedTransaction nestedTransaction = new NestedTransaction()) {
List<Node> writtenNodes = writeTo(toState, nodes, agent, reason, nestedTransaction);
nestedTransaction.commit();
return writtenNodes;
}
}
use of com.yahoo.transaction.NestedTransaction in project vespa by vespa-engine.
the class CuratorDatabaseTest method commitCreate.
private void commitCreate(String path, CuratorDatabase database) {
NestedTransaction t = new NestedTransaction();
CuratorTransaction c = database.newCuratorTransactionIn(t);
c.add(CuratorOperations.create(path));
t.commit();
}
use of com.yahoo.transaction.NestedTransaction in project vespa by vespa-engine.
the class CuratorDatabaseTest method testThatCounterIncreasesAlsoOnCommitFailureFromExistingTransaction.
@Test
public void testThatCounterIncreasesAlsoOnCommitFailureFromExistingTransaction() throws Exception {
MockCurator curator = new MockCurator();
CuratorDatabase database = new CuratorDatabase(curator, Path.fromString("/"), true);
assertEquals(0L, (long) curator.counter("/changeCounter").get().get().postValue());
try {
NestedTransaction t = new NestedTransaction();
CuratorTransaction separateC = new CuratorTransaction(curator);
// fail as parent does not exist
separateC.add(CuratorOperations.create("/1/2"));
t.add(separateC);
CuratorTransaction c = database.newCuratorTransactionIn(t);
// does not fail
c.add(CuratorOperations.create("/1"));
t.commit();
fail("Expected exception");
} catch (Exception expected) {
// expected because the parent does not exist
}
assertEquals(1L, (long) curator.counter("/changeCounter").get().get().postValue());
}
Aggregations