use of com.yahoo.vespa.config.server.application.TenantApplications 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.application.TenantApplications in project vespa by vespa-engine.
the class ApplicationRepository method getCurrentActiveApplicationSet.
private Optional<ApplicationSet> getCurrentActiveApplicationSet(Tenant tenant, ApplicationId appId) {
Optional<ApplicationSet> currentActiveApplicationSet = Optional.empty();
TenantApplications applicationRepo = tenant.getApplicationRepo();
try {
long currentActiveSessionId = applicationRepo.getSessionIdForApplication(appId);
RemoteSession currentActiveSession = getRemoteSession(tenant, currentActiveSessionId);
if (currentActiveSession != null) {
currentActiveApplicationSet = Optional.ofNullable(currentActiveSession.ensureApplicationLoaded());
}
} catch (IllegalArgumentException e) {
// Do nothing if we have no currently active session
}
return currentActiveApplicationSet;
}
use of com.yahoo.vespa.config.server.application.TenantApplications in project vespa by vespa-engine.
the class ListApplicationsHandler method listApplicationIds.
private List<ApplicationId> listApplicationIds(TenantName tenantName) {
Utils.checkThatTenantExists(tenants, tenantName);
Tenant tenant = tenants.getTenant(tenantName);
TenantApplications applicationRepo = tenant.getApplicationRepo();
return applicationRepo.listApplications();
}
use of com.yahoo.vespa.config.server.application.TenantApplications in project vespa by vespa-engine.
the class RemoteSessionRepoTest method testBadApplicationRepoOnActivate.
// If reading a session throws an exception it should be handled and not prevent other applications
// from loading. In this test we just show that we end up with one session in remote session
// repo even if it had bad data (by making getSessionIdForApplication() in FailingTenantApplications
// throw an exception).
@Test
public void testBadApplicationRepoOnActivate() throws Exception {
long sessionId = 3L;
TenantApplications applicationRepo = new FailingTenantApplications();
TenantName mytenant = TenantName.from("mytenant");
Tenant tenant = TenantBuilder.create(new TestComponentRegistry.Builder().curator(curator).build(), mytenant).withApplicationRepo(applicationRepo).build();
curator.create(Tenants.getSessionsPath(mytenant));
remoteSessionRepo = tenant.getRemoteSessionRepo();
assertThat(remoteSessionRepo.listSessions().size(), is(0));
createSession(sessionId, true, mytenant);
assertThat(remoteSessionRepo.listSessions().size(), is(1));
}
use of com.yahoo.vespa.config.server.application.TenantApplications in project vespa by vespa-engine.
the class TenantHandler method handleDELETE.
@Override
protected HttpResponse handleDELETE(HttpRequest request) {
final TenantName tenantName = getTenantNameFromRequest(request);
Utils.checkThatTenantExists(tenants, tenantName);
// TODO: Move logic to ApplicationRepository
Tenant tenant = tenants.getTenant(tenantName);
TenantApplications applicationRepo = tenant.getApplicationRepo();
final List<ApplicationId> activeApplications = applicationRepo.listApplications();
if (activeApplications.isEmpty()) {
try {
tenants.deleteTenant(tenantName);
} catch (IllegalArgumentException e) {
throw e;
} catch (Exception e) {
throw new InternalServerException(Exceptions.toMessageString(e));
}
} else {
throw new BadRequestException("Cannot delete tenant '" + tenantName + "', as it has active applications: " + activeApplications);
}
return new TenantDeleteResponse(tenantName);
}
Aggregations