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;
}
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());
}
}
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);
}
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);
}
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);
}
Aggregations