Search in sources :

Example 6 with ZoneId

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));
}
Also used : DeployOptions(com.yahoo.vespa.hosted.controller.api.application.v4.model.DeployOptions) ActivateResult(com.yahoo.vespa.hosted.controller.api.ActivateResult) SlimeJsonResponse(com.yahoo.vespa.hosted.controller.restapi.SlimeJsonResponse) ZoneId(com.yahoo.vespa.hosted.controller.api.integration.zone.ZoneId) Inspector(com.yahoo.slime.Inspector) ApplicationId(com.yahoo.config.provision.ApplicationId) ApplicationPackage(com.yahoo.vespa.hosted.controller.application.ApplicationPackage)

Example 7 with ZoneId

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;
}
Also used : HashMap(java.util.HashMap) MetricsService(com.yahoo.vespa.hosted.controller.api.integration.MetricsService) ClusterSpec(com.yahoo.config.provision.ClusterSpec) ClusterUtilization(com.yahoo.vespa.hosted.controller.application.ClusterUtilization) ZoneId(com.yahoo.vespa.hosted.controller.api.integration.zone.ZoneId) ApplicationId(com.yahoo.config.provision.ApplicationId) Map(java.util.Map) HashMap(java.util.HashMap)

Example 8 with ZoneId

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");
}
Also used : ZoneId(com.yahoo.vespa.hosted.controller.api.integration.zone.ZoneId) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ZoneList(com.yahoo.vespa.hosted.controller.api.integration.zone.ZoneList)

Example 9 with ZoneId

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());
}
Also used : DeployOptions(com.yahoo.vespa.hosted.controller.api.application.v4.model.DeployOptions) ScrewdriverId(com.yahoo.vespa.hosted.controller.api.identifiers.ScrewdriverId) ZoneId(com.yahoo.vespa.hosted.controller.api.integration.zone.ZoneId) ScrewdriverBuildJob(com.yahoo.vespa.hosted.controller.api.application.v4.model.ScrewdriverBuildJob) ApplicationSerializer(com.yahoo.vespa.hosted.controller.persistence.ApplicationSerializer) JobType.stagingTest(com.yahoo.vespa.hosted.controller.application.DeploymentJobs.JobType.stagingTest) JobType.systemTest(com.yahoo.vespa.hosted.controller.application.DeploymentJobs.JobType.systemTest) Test(org.junit.Test)

Example 10 with ZoneId

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);
}
Also used : SlimeJsonResponse(com.yahoo.vespa.hosted.controller.restapi.SlimeJsonResponse) ZoneId(com.yahoo.vespa.hosted.controller.api.integration.zone.ZoneId) Slime(com.yahoo.slime.Slime) Cursor(com.yahoo.slime.Cursor)

Aggregations

ZoneId (com.yahoo.vespa.hosted.controller.api.integration.zone.ZoneId)13 ApplicationId (com.yahoo.config.provision.ApplicationId)4 DeployOptions (com.yahoo.vespa.hosted.controller.api.application.v4.model.DeployOptions)4 Application (com.yahoo.vespa.hosted.controller.Application)3 DeploymentId (com.yahoo.vespa.hosted.controller.api.identifiers.DeploymentId)3 Deployment (com.yahoo.vespa.hosted.controller.application.Deployment)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ImmutableList (com.google.common.collect.ImmutableList)2 Version (com.yahoo.component.Version)2 ClusterSpec (com.yahoo.config.provision.ClusterSpec)2 Controller (com.yahoo.vespa.hosted.controller.Controller)2 ActivateResult (com.yahoo.vespa.hosted.controller.api.ActivateResult)2 EndpointStatus (com.yahoo.vespa.hosted.controller.api.application.v4.model.EndpointStatus)2 ApplicationList (com.yahoo.vespa.hosted.controller.application.ApplicationList)2 ApplicationPackage (com.yahoo.vespa.hosted.controller.application.ApplicationPackage)2 JobType.stagingTest (com.yahoo.vespa.hosted.controller.application.DeploymentJobs.JobType.stagingTest)2 JobType.systemTest (com.yahoo.vespa.hosted.controller.application.DeploymentJobs.JobType.systemTest)2 IOException (java.io.IOException)2 URI (java.net.URI)2