Search in sources :

Example 6 with TenantId

use of com.yahoo.vespa.hosted.controller.api.identifiers.TenantId in project vespa by vespa-engine.

the class ApplicationApiHandler method createTenant.

private HttpResponse createTenant(String tenantName, HttpRequest request) {
    if (new TenantId(tenantName).isUser())
        return ErrorResponse.badRequest("Use User API to create user tenants.");
    Inspector requestData = toSlime(request.getData()).get();
    Tenant tenant = new Tenant(new TenantId(tenantName), optional("property", requestData).map(Property::new), optional("athensDomain", requestData).map(AthenzDomain::new), optional("propertyId", requestData).map(PropertyId::new));
    if (tenant.isAthensTenant())
        throwIfNotAthenzDomainAdmin(new AthenzDomain(mandatory("athensDomain", requestData).asString()), request);
    NToken token = getUserPrincipal(request).getNToken().orElseThrow(() -> new IllegalArgumentException("Could not create " + tenant + ": No NToken provided"));
    controller.tenants().createAthenzTenant(tenant, token);
    return tenant(tenant, request, true);
}
Also used : TenantId(com.yahoo.vespa.hosted.controller.api.identifiers.TenantId) Tenant(com.yahoo.vespa.hosted.controller.api.Tenant) AthenzDomain(com.yahoo.vespa.athenz.api.AthenzDomain) NToken(com.yahoo.vespa.athenz.api.NToken) Inspector(com.yahoo.slime.Inspector)

Example 7 with TenantId

use of com.yahoo.vespa.hosted.controller.api.identifiers.TenantId in project vespa by vespa-engine.

the class ApplicationApiHandler method updateTenant.

private HttpResponse updateTenant(String tenantName, HttpRequest request) {
    Optional<Tenant> existingTenant = controller.tenants().tenant(new TenantId(tenantName));
    if (!existingTenant.isPresent())
        return ErrorResponse.notFoundError("Tenant '" + tenantName + "' does not exist");
    ;
    Inspector requestData = toSlime(request.getData()).get();
    Tenant updatedTenant;
    switch(existingTenant.get().tenantType()) {
        case USER:
            {
                throw new BadRequestException("Cannot set property or OpsDB user group for user tenant");
            }
        case ATHENS:
            {
                updatedTenant = Tenant.createAthensTenant(new TenantId(tenantName), new AthenzDomain(mandatory("athensDomain", requestData).asString()), new Property(mandatory("property", requestData).asString()), optional("propertyId", requestData).map(PropertyId::new));
                controller.tenants().updateTenant(updatedTenant, getUserPrincipal(request).getNToken());
                break;
            }
        default:
            {
                throw new BadRequestException("Unknown tenant type: " + existingTenant.get().tenantType());
            }
    }
    return tenant(updatedTenant, request, true);
}
Also used : TenantId(com.yahoo.vespa.hosted.controller.api.identifiers.TenantId) Tenant(com.yahoo.vespa.hosted.controller.api.Tenant) AthenzDomain(com.yahoo.vespa.athenz.api.AthenzDomain) Inspector(com.yahoo.slime.Inspector) BadRequestException(javax.ws.rs.BadRequestException) Property(com.yahoo.vespa.hosted.controller.api.identifiers.Property)

Example 8 with TenantId

use of com.yahoo.vespa.hosted.controller.api.identifiers.TenantId in project vespa by vespa-engine.

the class ApplicationApiHandler method verifyApplicationIdentityConfiguration.

private void verifyApplicationIdentityConfiguration(String tenantName, Optional<ApplicationPackage> applicationPackage) {
    // Validate that domain in identity configuration (deployment.xml) is same as tenant domain
    applicationPackage.map(ApplicationPackage::deploymentSpec).flatMap(DeploymentSpec::athenzDomain).ifPresent(identityDomain -> {
        Tenant tenant = controller.tenants().tenant(new TenantId(tenantName)).orElseThrow(() -> new IllegalArgumentException("Tenant does not exist"));
        AthenzDomain tenantDomain = tenant.getAthensDomain().orElseThrow(() -> new IllegalArgumentException("Identity provider only available to Athenz onboarded tenants"));
        if (!Objects.equals(tenantDomain.getName(), identityDomain.value())) {
            throw new ForbiddenException(String.format("Athenz domain in deployment.xml: [%s] must match tenant domain: [%s]", identityDomain.value(), tenantDomain.getName()));
        }
    });
}
Also used : TenantId(com.yahoo.vespa.hosted.controller.api.identifiers.TenantId) ForbiddenException(javax.ws.rs.ForbiddenException) Tenant(com.yahoo.vespa.hosted.controller.api.Tenant) AthenzDomain(com.yahoo.vespa.athenz.api.AthenzDomain) ApplicationPackage(com.yahoo.vespa.hosted.controller.application.ApplicationPackage)

Example 9 with TenantId

use of com.yahoo.vespa.hosted.controller.api.identifiers.TenantId in project vespa by vespa-engine.

the class ApplicationApiHandler method deleteTenant.

private HttpResponse deleteTenant(String tenantName, HttpRequest request) {
    Optional<Tenant> tenant = controller.tenants().tenant(new TenantId(tenantName));
    // NOTE: The Jersey implementation would silently ignore this
    if (!tenant.isPresent())
        return ErrorResponse.notFoundError("Could not delete tenant '" + tenantName + "': Tenant not found");
    controller.tenants().deleteTenant(new TenantId(tenantName), getUserPrincipal(request).getNToken());
    // TODO: Change to a message response saying the tenant was deleted
    return tenant(tenant.get(), request, false);
}
Also used : TenantId(com.yahoo.vespa.hosted.controller.api.identifiers.TenantId) Tenant(com.yahoo.vespa.hosted.controller.api.Tenant)

Example 10 with TenantId

use of com.yahoo.vespa.hosted.controller.api.identifiers.TenantId 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)

Aggregations

TenantId (com.yahoo.vespa.hosted.controller.api.identifiers.TenantId)19 Tenant (com.yahoo.vespa.hosted.controller.api.Tenant)9 ApplicationPackage (com.yahoo.vespa.hosted.controller.application.ApplicationPackage)7 Test (org.junit.Test)7 JobType.stagingTest (com.yahoo.vespa.hosted.controller.application.DeploymentJobs.JobType.stagingTest)6 JobType.systemTest (com.yahoo.vespa.hosted.controller.application.DeploymentJobs.JobType.systemTest)6 Application (com.yahoo.vespa.hosted.controller.Application)5 Version (com.yahoo.component.Version)4 AthenzDomain (com.yahoo.vespa.athenz.api.AthenzDomain)4 Inspector (com.yahoo.slime.Inspector)3 Lock (com.yahoo.vespa.curator.Lock)3 LockedApplication (com.yahoo.vespa.hosted.controller.LockedApplication)3 Property (com.yahoo.vespa.hosted.controller.api.identifiers.Property)3 ApplicationId (com.yahoo.config.provision.ApplicationId)2 Environment (com.yahoo.config.provision.Environment)2 NToken (com.yahoo.vespa.athenz.api.NToken)2 EndpointStatus (com.yahoo.vespa.hosted.controller.api.application.v4.model.EndpointStatus)2 ConfigChangeActions (com.yahoo.vespa.hosted.controller.api.application.v4.model.configserverbindings.ConfigChangeActions)2 DeploymentId (com.yahoo.vespa.hosted.controller.api.identifiers.DeploymentId)2 PropertyId (com.yahoo.vespa.hosted.controller.api.identifiers.PropertyId)2