Search in sources :

Example 1 with PersistenceException

use of com.yahoo.vespa.hosted.controller.persistence.PersistenceException in project vespa by vespa-engine.

the class TenantController method deleteTenant.

public void deleteTenant(TenantId id, Optional<NToken> token) {
    try (Lock lock = lock(id)) {
        if (!tenant(id).isPresent())
            // TODO: Change exception and message
            throw new NotExistsException(id);
        if (!controller.applications().asList(TenantName.from(id.id())).isEmpty())
            throw new IllegalArgumentException("Could not delete tenant '" + id + "': This tenant has active applications");
        Tenant tenant = tenant(id).get();
        if (tenant.isAthensTenant() && !token.isPresent())
            throw new IllegalArgumentException("Could not delete tenant '" + id + "': No NToken provided");
        try {
            db.deleteTenant(id);
        } catch (PersistenceException e) {
            // TODO: Don't allow these to leak out
            throw new RuntimeException(e);
        }
        if (tenant.isAthensTenant())
            athenzClientFactory.createZmsClientWithAuthorizedServiceToken(token.get()).deleteTenant(tenant.getAthensDomain().get());
        log.info("Deleted " + tenant);
    }
}
Also used : Tenant(com.yahoo.vespa.hosted.controller.api.Tenant) PersistenceException(com.yahoo.vespa.hosted.controller.persistence.PersistenceException) Lock(com.yahoo.vespa.curator.Lock)

Example 2 with PersistenceException

use of com.yahoo.vespa.hosted.controller.persistence.PersistenceException in project vespa by vespa-engine.

the class TenantController method updateTenant.

public void updateTenant(Tenant updatedTenant, Optional<NToken> token) {
    try (Lock lock = lock(updatedTenant.getId())) {
        if (!tenant(updatedTenant.getId()).isPresent())
            throw new IllegalArgumentException("Could not update " + updatedTenant + ": Tenant does not exist");
        if (updatedTenant.isAthensTenant() && !token.isPresent())
            throw new IllegalArgumentException("Could not update " + updatedTenant + ": No NToken provided");
        updateAthenzDomain(updatedTenant, token);
        db.updateTenant(updatedTenant);
        log.info("Updated " + updatedTenant);
    } catch (PersistenceException e) {
        throw new RuntimeException(e);
    }
}
Also used : PersistenceException(com.yahoo.vespa.hosted.controller.persistence.PersistenceException) Lock(com.yahoo.vespa.curator.Lock)

Aggregations

Lock (com.yahoo.vespa.curator.Lock)2 PersistenceException (com.yahoo.vespa.hosted.controller.persistence.PersistenceException)2 Tenant (com.yahoo.vespa.hosted.controller.api.Tenant)1