Search in sources :

Example 1 with ZmsClient

use of com.yahoo.vespa.hosted.controller.api.integration.athenz.ZmsClient in project vespa by vespa-engine.

the class ApplicationController method createApplication.

/**
 * Creates a new application for an existing tenant.
 *
 * @throws IllegalArgumentException if the application already exists
 */
public Application createApplication(ApplicationId id, Optional<NToken> token) {
    if (// TODO: Support instances properly
    !(id.instance().isDefault() || id.instance().value().matches("\\d+")))
        throw new UnsupportedOperationException("Only the instance names 'default' and names which are just the PR number are supported at the moment");
    try (Lock lock = lock(id)) {
        // Validate only application names which do not already exist.
        if (asList(id.tenant()).stream().noneMatch(application -> application.id().application().equals(id.application())))
            com.yahoo.vespa.hosted.controller.api.identifiers.ApplicationId.validate(id.application().value());
        Optional<Tenant> tenant = controller.tenants().tenant(new TenantId(id.tenant().value()));
        if (!tenant.isPresent())
            throw new IllegalArgumentException("Could not create '" + id + "': This tenant does not exist");
        if (get(id).isPresent())
            throw new IllegalArgumentException("Could not create '" + id + "': Application already exists");
        if (// VESPA-1945
        get(dashToUnderscore(id)).isPresent())
            throw new IllegalArgumentException("Could not create '" + id + "': Application " + dashToUnderscore(id) + " already exists");
        if (id.instance().isDefault() && tenant.get().isAthensTenant()) {
            // Only create the athens application for "default" instances.
            if (!token.isPresent())
                throw new IllegalArgumentException("Could not create '" + id + "': No NToken provided");
            ZmsClient zmsClient = zmsClientFactory.createZmsClientWithAuthorizedServiceToken(token.get());
            zmsClient.addApplication(tenant.get().getAthensDomain().get(), new com.yahoo.vespa.hosted.controller.api.identifiers.ApplicationId(id.application().value()));
        }
        LockedApplication application = new LockedApplication(new Application(id), lock);
        store(application);
        log.info("Created " + application);
        return application;
    }
}
Also used : Lock(com.yahoo.vespa.curator.Lock) RotationLock(com.yahoo.vespa.hosted.controller.rotation.RotationLock) TenantId(com.yahoo.vespa.hosted.controller.api.identifiers.TenantId) Tenant(com.yahoo.vespa.hosted.controller.api.Tenant) ZmsClient(com.yahoo.vespa.hosted.controller.api.integration.athenz.ZmsClient)

Example 2 with ZmsClient

use of com.yahoo.vespa.hosted.controller.api.integration.athenz.ZmsClient in project vespa by vespa-engine.

the class TenantController method updateAthenzDomain.

private void updateAthenzDomain(Tenant updatedTenant, Optional<NToken> token) {
    Tenant existingTenant = tenant(updatedTenant.getId()).get();
    if (!existingTenant.isAthensTenant())
        return;
    AthenzDomain existingDomain = existingTenant.getAthensDomain().get();
    AthenzDomain newDomain = updatedTenant.getAthensDomain().get();
    if (existingDomain.equals(newDomain))
        return;
    Optional<Tenant> existingTenantWithNewDomain = tenantHaving(newDomain);
    if (existingTenantWithNewDomain.isPresent())
        throw new IllegalArgumentException("Could not set domain of " + updatedTenant + " to '" + newDomain + "':" + existingTenantWithNewDomain.get() + " already has this domain");
    ZmsClient zmsClient = athenzClientFactory.createZmsClientWithAuthorizedServiceToken(token.get());
    zmsClient.createTenant(newDomain);
    List<Application> applications = controller.applications().asList(TenantName.from(existingTenant.getId().id()));
    applications.forEach(a -> zmsClient.addApplication(newDomain, new com.yahoo.vespa.hosted.controller.api.identifiers.ApplicationId(a.id().application().value())));
    applications.forEach(a -> zmsClient.deleteApplication(existingDomain, new com.yahoo.vespa.hosted.controller.api.identifiers.ApplicationId(a.id().application().value())));
    zmsClient.deleteTenant(existingDomain);
    log.info("Updated Athens domain for " + updatedTenant + " from " + existingDomain + " to " + newDomain);
}
Also used : Tenant(com.yahoo.vespa.hosted.controller.api.Tenant) AthenzDomain(com.yahoo.vespa.athenz.api.AthenzDomain) ZmsClient(com.yahoo.vespa.hosted.controller.api.integration.athenz.ZmsClient)

Aggregations

Tenant (com.yahoo.vespa.hosted.controller.api.Tenant)2 ZmsClient (com.yahoo.vespa.hosted.controller.api.integration.athenz.ZmsClient)2 AthenzDomain (com.yahoo.vespa.athenz.api.AthenzDomain)1 Lock (com.yahoo.vespa.curator.Lock)1 TenantId (com.yahoo.vespa.hosted.controller.api.identifiers.TenantId)1 RotationLock (com.yahoo.vespa.hosted.controller.rotation.RotationLock)1