Search in sources :

Example 1 with TenantApplications

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;
}
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 TenantApplications

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;
}
Also used : RemoteSession(com.yahoo.vespa.config.server.session.RemoteSession) TenantApplications(com.yahoo.vespa.config.server.application.TenantApplications) ApplicationSet(com.yahoo.vespa.config.server.application.ApplicationSet)

Example 3 with TenantApplications

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();
}
Also used : Tenant(com.yahoo.vespa.config.server.tenant.Tenant) TenantApplications(com.yahoo.vespa.config.server.application.TenantApplications)

Example 4 with TenantApplications

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));
}
Also used : Tenant(com.yahoo.vespa.config.server.tenant.Tenant) TenantName(com.yahoo.config.provision.TenantName) TestComponentRegistry(com.yahoo.vespa.config.server.TestComponentRegistry) TenantApplications(com.yahoo.vespa.config.server.application.TenantApplications) Test(org.junit.Test)

Example 5 with TenantApplications

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);
}
Also used : Tenant(com.yahoo.vespa.config.server.tenant.Tenant) TenantName(com.yahoo.config.provision.TenantName) InternalServerException(com.yahoo.vespa.config.server.http.InternalServerException) BadRequestException(com.yahoo.vespa.config.server.http.BadRequestException) TenantApplications(com.yahoo.vespa.config.server.application.TenantApplications) ApplicationId(com.yahoo.config.provision.ApplicationId) BadRequestException(com.yahoo.vespa.config.server.http.BadRequestException) InternalServerException(com.yahoo.vespa.config.server.http.InternalServerException)

Aggregations

TenantApplications (com.yahoo.vespa.config.server.application.TenantApplications)5 Tenant (com.yahoo.vespa.config.server.tenant.Tenant)4 TenantName (com.yahoo.config.provision.TenantName)2 ApplicationId (com.yahoo.config.provision.ApplicationId)1 NestedTransaction (com.yahoo.transaction.NestedTransaction)1 TestComponentRegistry (com.yahoo.vespa.config.server.TestComponentRegistry)1 ApplicationSet (com.yahoo.vespa.config.server.application.ApplicationSet)1 BadRequestException (com.yahoo.vespa.config.server.http.BadRequestException)1 InternalServerException (com.yahoo.vespa.config.server.http.InternalServerException)1 LocalSession (com.yahoo.vespa.config.server.session.LocalSession)1 LocalSessionRepo (com.yahoo.vespa.config.server.session.LocalSessionRepo)1 RemoteSession (com.yahoo.vespa.config.server.session.RemoteSession)1 Rotations (com.yahoo.vespa.config.server.tenant.Rotations)1 Test (org.junit.Test)1