use of com.yahoo.vespa.hosted.controller.api.integration.zone.ZoneId in project vespa by vespa-engine.
the class ApplicationApiHandler method deploy.
private HttpResponse deploy(String tenantName, String applicationName, String instanceName, String environment, String region, HttpRequest request) {
ApplicationId applicationId = ApplicationId.from(tenantName, applicationName, instanceName);
ZoneId zone = ZoneId.from(environment, region);
Map<String, byte[]> dataParts = new MultipartParser().parse(request);
if (!dataParts.containsKey("deployOptions"))
return ErrorResponse.badRequest("Missing required form part 'deployOptions'");
Inspector deployOptions = SlimeUtils.jsonToSlime(dataParts.get("deployOptions")).get();
Optional<ApplicationPackage> applicationPackage = Optional.ofNullable(dataParts.get("applicationZip")).map(ApplicationPackage::new);
verifyApplicationIdentityConfiguration(tenantName, applicationPackage);
// TODO: get rid of the json object
DeployOptions deployOptionsJsonClass = new DeployOptions(screwdriverBuildJobFromSlime(deployOptions.field("screwdriverBuildJob")), optional("vespaVersion", deployOptions).map(Version::new), deployOptions.field("ignoreValidationErrors").asBool(), deployOptions.field("deployCurrentVersion").asBool());
ActivateResult result = controller.applications().deployApplication(applicationId, zone, applicationPackage, deployOptionsJsonClass);
return new SlimeJsonResponse(toSlime(result));
}
use of com.yahoo.vespa.hosted.controller.api.integration.zone.ZoneId in project vespa by vespa-engine.
the class ClusterUtilizationMaintainer method getUpdatedClusterUtilizations.
private Map<ClusterSpec.Id, ClusterUtilization> getUpdatedClusterUtilizations(ApplicationId app, ZoneId zone) {
Map<String, MetricsService.SystemMetrics> systemMetrics = controller.metricsService().getSystemMetrics(app, zone);
Map<ClusterSpec.Id, ClusterUtilization> utilizationMap = new HashMap<>();
for (Map.Entry<String, MetricsService.SystemMetrics> metrics : systemMetrics.entrySet()) {
MetricsService.SystemMetrics systemMetric = metrics.getValue();
ClusterUtilization utilization = new ClusterUtilization(systemMetric.memUtil() / 100, systemMetric.cpuUtil() / 100, systemMetric.diskUtil() / 100, 0);
utilizationMap.put(new ClusterSpec.Id(metrics.getKey()), utilization);
}
return utilizationMap;
}
use of com.yahoo.vespa.hosted.controller.api.integration.zone.ZoneId in project vespa by vespa-engine.
the class ConfigServerRestExecutorImpl method createDiscoveryResponse.
private ProxyResponse createDiscoveryResponse(ProxyRequest proxyRequest) {
ObjectMapper mapper = new ObjectMapper();
DiscoveryResponseStructure responseStructure = new DiscoveryResponseStructure();
String environmentName = proxyRequest.getEnvironment();
ZoneList zones = zoneRegistry.zones().all();
if (!environmentName.isEmpty())
zones = zones.in(Environment.from(environmentName));
for (ZoneId zoneId : zones.ids()) {
responseStructure.uris.add(proxyRequest.getScheme() + "://" + proxyRequest.getControllerPrefix() + zoneId.environment().name() + "/" + zoneId.region().value());
}
JsonNode node = mapper.valueToTree(responseStructure);
return new ProxyResponse(proxyRequest, node.toString(), 200, Optional.empty(), "application/json");
}
use of com.yahoo.vespa.hosted.controller.api.integration.zone.ZoneId in project vespa by vespa-engine.
the class ControllerTest method testDeploymentOfNewInstanceWithIllegalApplicationName.
@Test
public void testDeploymentOfNewInstanceWithIllegalApplicationName() {
ControllerTester tester = new ControllerTester();
String application = "this_application_name_is_far_too_long_and_has_underscores";
ZoneId zone = ZoneId.from("test", "us-east-1");
DeployOptions options = new DeployOptions(Optional.of(new ScrewdriverBuildJob(new ScrewdriverId("123"), null)), Optional.empty(), false, false);
tester.createTenant("tenant", "domain", null);
// Deploy an application which doesn't yet exist, and which has an illegal application name.
try {
tester.controller().applications().deployApplication(ApplicationId.from("tenant", application, "123"), zone, Optional.empty(), options);
fail("Illegal application name should cause validation exception.");
} catch (IllegalArgumentException e) {
assertTrue(e.getMessage().contains("Invalid id"));
}
// Sneak an illegal application in the back door.
tester.createApplication(new ApplicationSerializer().toSlime(new Application(ApplicationId.from("tenant", application, "default"))));
// Deploy a PR instance for the application, with no NToken.
tester.controller().applications().deployApplication(ApplicationId.from("tenant", application, "456"), zone, Optional.empty(), options);
assertTrue(tester.controller().applications().get(ApplicationId.from("tenant", application, "456")).isPresent());
}
use of com.yahoo.vespa.hosted.controller.api.integration.zone.ZoneId in project vespa by vespa-engine.
the class ZoneApiHandler method environment.
private HttpResponse environment(HttpRequest request, Environment environment) {
List<ZoneId> zones = zoneRegistry.zones().all().in(environment).ids();
Slime slime = new Slime();
Cursor root = slime.setArray();
zones.forEach(zone -> {
Cursor object = root.addObject();
object.setString("name", zone.region().value());
object.setString("url", request.getUri().resolve("/zone/v2/environment/").resolve(environment.value() + "/").resolve("region/").resolve(zone.region().value()).toString());
});
return new SlimeJsonResponse(slime);
}
Aggregations