Search in sources :

Example 1 with Tenant

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

the class ControllerTester method createTenant.

public TenantId createTenant(String tenantName, String domainName, Long propertyId) {
    TenantId id = new TenantId(tenantName);
    Optional<Tenant> existing = controller().tenants().tenant(id);
    if (existing.isPresent())
        return id;
    Tenant tenant = Tenant.createAthensTenant(id, createDomain(domainName), new Property("app1Property"), propertyId == null ? Optional.empty() : Optional.of(new PropertyId(propertyId.toString())));
    controller().tenants().createAthenzTenant(tenant, TestIdentities.userNToken);
    assertNotNull(controller().tenants().tenant(id));
    return id;
}
Also used : TenantId(com.yahoo.vespa.hosted.controller.api.identifiers.TenantId) Tenant(com.yahoo.vespa.hosted.controller.api.Tenant) Property(com.yahoo.vespa.hosted.controller.api.identifiers.Property) PropertyId(com.yahoo.vespa.hosted.controller.api.identifiers.PropertyId)

Example 2 with Tenant

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

the class ApplicationApiHandler method setGlobalRotationOverride.

private HttpResponse setGlobalRotationOverride(String tenantName, String applicationName, String instanceName, String environment, String region, boolean inService, HttpRequest request) {
    // Check if request is authorized
    Optional<Tenant> existingTenant = controller.tenants().tenant(new TenantId(tenantName));
    if (!existingTenant.isPresent())
        return ErrorResponse.notFoundError("Tenant '" + tenantName + "' does not exist");
    // Decode payload (reason) and construct parameter to the configserver
    Inspector requestData = toSlime(request.getData()).get();
    String reason = mandatory("reason", requestData).asString();
    String agent = getUserPrincipal(request).getIdentity().getFullName();
    long timestamp = controller.clock().instant().getEpochSecond();
    EndpointStatus.Status status = inService ? EndpointStatus.Status.in : EndpointStatus.Status.out;
    EndpointStatus endPointStatus = new EndpointStatus(status, reason, agent, timestamp);
    // DeploymentId identifies the zone and application we are dealing with
    DeploymentId deploymentId = new DeploymentId(ApplicationId.from(tenantName, applicationName, instanceName), ZoneId.from(environment, region));
    try {
        List<String> rotations = controller.applications().setGlobalRotationStatus(deploymentId, endPointStatus);
        return new MessageResponse(String.format("Rotations %s successfully set to %s service", rotations.toString(), inService ? "in" : "out of"));
    } catch (IOException e) {
        return ErrorResponse.internalServerError("Unable to alter rotation status: " + e.getMessage());
    }
}
Also used : EndpointStatus(com.yahoo.vespa.hosted.controller.api.application.v4.model.EndpointStatus) TenantId(com.yahoo.vespa.hosted.controller.api.identifiers.TenantId) DeploymentId(com.yahoo.vespa.hosted.controller.api.identifiers.DeploymentId) Tenant(com.yahoo.vespa.hosted.controller.api.Tenant) MessageResponse(com.yahoo.vespa.hosted.controller.restapi.MessageResponse) Inspector(com.yahoo.slime.Inspector) IOException(java.io.IOException)

Example 3 with Tenant

use of com.yahoo.vespa.hosted.controller.api.Tenant 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 4 with Tenant

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

the class ApplicationApiHandler method recursiveRoot.

private HttpResponse recursiveRoot(HttpRequest request) {
    Slime slime = new Slime();
    Cursor tenantArray = slime.setArray();
    for (Tenant tenant : controller.tenants().asList()) toSlime(tenantArray.addObject(), tenant, request, true);
    return new SlimeJsonResponse(slime);
}
Also used : Tenant(com.yahoo.vespa.hosted.controller.api.Tenant) SlimeJsonResponse(com.yahoo.vespa.hosted.controller.restapi.SlimeJsonResponse) Slime(com.yahoo.slime.Slime) Cursor(com.yahoo.slime.Cursor)

Example 5 with Tenant

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

Aggregations

Tenant (com.yahoo.vespa.hosted.controller.api.Tenant)18 TenantId (com.yahoo.vespa.hosted.controller.api.identifiers.TenantId)11 AthenzDomain (com.yahoo.vespa.athenz.api.AthenzDomain)7 Inspector (com.yahoo.slime.Inspector)5 Cursor (com.yahoo.slime.Cursor)4 Slime (com.yahoo.slime.Slime)4 NToken (com.yahoo.vespa.athenz.api.NToken)4 Lock (com.yahoo.vespa.curator.Lock)4 EndpointStatus (com.yahoo.vespa.hosted.controller.api.application.v4.model.EndpointStatus)4 Version (com.yahoo.component.Version)3 DeploymentSpec (com.yahoo.config.application.api.DeploymentSpec)3 ApplicationId (com.yahoo.config.provision.ApplicationId)3 Environment (com.yahoo.config.provision.Environment)3 TenantName (com.yahoo.config.provision.TenantName)3 ActivateResult (com.yahoo.vespa.hosted.controller.api.ActivateResult)3 DeployOptions (com.yahoo.vespa.hosted.controller.api.application.v4.model.DeployOptions)3 DeploymentId (com.yahoo.vespa.hosted.controller.api.identifiers.DeploymentId)3 Property (com.yahoo.vespa.hosted.controller.api.identifiers.Property)3 ApplicationPackage (com.yahoo.vespa.hosted.controller.application.ApplicationPackage)3 SlimeJsonResponse (com.yahoo.vespa.hosted.controller.restapi.SlimeJsonResponse)3