Search in sources :

Example 1 with Environment

use of com.yahoo.config.provision.Environment in project vespa by vespa-engine.

the class OverrideProcessor method getParentContext.

private Context getParentContext(Element parent, Context context) {
    Optional<Environment> environment = context.environment;
    RegionName region = context.region;
    if (!environment.isPresent()) {
        environment = getEnvironment(parent);
    }
    if (region.isDefault()) {
        region = getRegion(parent);
    }
    return Context.create(environment, region);
}
Also used : RegionName(com.yahoo.config.provision.RegionName) Environment(com.yahoo.config.provision.Environment)

Example 2 with Environment

use of com.yahoo.config.provision.Environment in project vespa by vespa-engine.

the class OverrideProcessor method getNumberOfOverrides.

private int getNumberOfOverrides(Element child, Context context) {
    int currentMatch = 0;
    Optional<Environment> elementEnvironment = hasEnvironment(child) ? getEnvironment(child) : context.environment;
    RegionName elementRegion = hasRegion(child) ? getRegion(child) : context.region;
    if (elementEnvironment.isPresent() && elementEnvironment.get().equals(environment))
        currentMatch++;
    if (!elementRegion.isDefault() && elementRegion.equals(region))
        currentMatch++;
    return currentMatch;
}
Also used : RegionName(com.yahoo.config.provision.RegionName) Environment(com.yahoo.config.provision.Environment)

Example 3 with Environment

use of com.yahoo.config.provision.Environment in project vespa by vespa-engine.

the class OverrideProcessor method checkConsistentInheritance.

/**
 * Ensures that environment and region does not change from something non-default to something else.
 */
private void checkConsistentInheritance(List<Element> children, Context context) {
    for (Element child : children) {
        Optional<Environment> env = getEnvironment(child);
        RegionName reg = getRegion(child);
        if (env.isPresent() && context.environment.isPresent() && !env.equals(context.environment)) {
            throw new IllegalArgumentException("Environment in child (" + env.get() + ") differs from that inherited from parent (" + context.environment + ") at " + child);
        }
        if (!reg.isDefault() && !context.region.isDefault() && !reg.equals(context.region)) {
            throw new IllegalArgumentException("Region in child (" + reg + ") differs from that inherited from parent (" + context.region + ") at " + child);
        }
    }
}
Also used : RegionName(com.yahoo.config.provision.RegionName) Element(org.w3c.dom.Element) Environment(com.yahoo.config.provision.Environment)

Example 4 with Environment

use of com.yahoo.config.provision.Environment in project vespa by vespa-engine.

the class DeploymentSpecXmlReader method read.

/**
 * Reads a deployment spec from XML
 */
public DeploymentSpec read(String xmlForm) {
    List<Step> steps = new ArrayList<>();
    Optional<String> globalServiceId = Optional.empty();
    Element root = XML.getDocument(xmlForm).getDocumentElement();
    if (validate)
        validateTagOrder(root);
    for (Element environmentTag : XML.getChildren(root)) {
        if (!isEnvironmentName(environmentTag.getTagName()))
            continue;
        Environment environment = Environment.from(environmentTag.getTagName());
        if (environment == Environment.prod) {
            for (Element stepTag : XML.getChildren(environmentTag)) {
                Optional<AthenzService> athenzService = stringAttribute("athenz-service", environmentTag).map(AthenzService::from);
                if (stepTag.getTagName().equals("delay")) {
                    steps.add(new Delay(Duration.ofSeconds(longAttribute("hours", stepTag) * 60 * 60 + longAttribute("minutes", stepTag) * 60 + longAttribute("seconds", stepTag))));
                } else if (stepTag.getTagName().equals("parallel")) {
                    List<DeclaredZone> zones = new ArrayList<>();
                    for (Element regionTag : XML.getChildren(stepTag)) {
                        zones.add(readDeclaredZone(environment, athenzService, regionTag));
                    }
                    steps.add(new ParallelZones(zones));
                } else {
                    // a region: deploy step
                    steps.add(readDeclaredZone(environment, athenzService, stepTag));
                }
            }
        } else {
            steps.add(new DeclaredZone(environment));
        }
        if (environment == Environment.prod)
            globalServiceId = readGlobalServiceId(environmentTag);
        else if (readGlobalServiceId(environmentTag).isPresent())
            throw new IllegalArgumentException("Attribute 'global-service-id' is only valid on 'prod' tag.");
    }
    Optional<AthenzDomain> athenzDomain = stringAttribute("athenz-domain", root).map(AthenzDomain::from);
    Optional<AthenzService> athenzService = stringAttribute("athenz-service", root).map(AthenzService::from);
    return new DeploymentSpec(globalServiceId, readUpgradePolicy(root), readChangeBlockers(root), steps, xmlForm, athenzDomain, athenzService);
}
Also used : AthenzService(com.yahoo.config.provision.AthenzService) AthenzDomain(com.yahoo.config.provision.AthenzDomain) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) Step(com.yahoo.config.application.api.DeploymentSpec.Step) DeclaredZone(com.yahoo.config.application.api.DeploymentSpec.DeclaredZone) Delay(com.yahoo.config.application.api.DeploymentSpec.Delay) ParallelZones(com.yahoo.config.application.api.DeploymentSpec.ParallelZones) DeploymentSpec(com.yahoo.config.application.api.DeploymentSpec) Environment(com.yahoo.config.provision.Environment) ArrayList(java.util.ArrayList) List(java.util.List)

Example 5 with Environment

use of com.yahoo.config.provision.Environment in project vespa by vespa-engine.

the class ZoneApiHandler method root.

private HttpResponse root(HttpRequest request) {
    List<Environment> environments = zoneRegistry.zones().all().ids().stream().map(ZoneId::environment).distinct().sorted(Comparator.comparing(Environment::value)).collect(Collectors.toList());
    Slime slime = new Slime();
    Cursor root = slime.setArray();
    environments.forEach(environment -> {
        Cursor object = root.addObject();
        object.setString("name", environment.value());
        // Returning /zone/v2 is a bit strange, but that's what the original Jersey implementation did
        object.setString("url", request.getUri().resolve("/zone/v2/environment/").resolve(environment.value()).toString());
    });
    return new SlimeJsonResponse(slime);
}
Also used : SlimeJsonResponse(com.yahoo.vespa.hosted.controller.restapi.SlimeJsonResponse) Environment(com.yahoo.config.provision.Environment) Slime(com.yahoo.slime.Slime) Cursor(com.yahoo.slime.Cursor)

Aggregations

Environment (com.yahoo.config.provision.Environment)11 RegionName (com.yahoo.config.provision.RegionName)7 Version (com.yahoo.component.Version)4 DeploymentSpec (com.yahoo.config.application.api.DeploymentSpec)4 Slime (com.yahoo.slime.Slime)4 ApplicationId (com.yahoo.config.provision.ApplicationId)3 TenantName (com.yahoo.config.provision.TenantName)3 Cursor (com.yahoo.slime.Cursor)3 NToken (com.yahoo.vespa.athenz.api.NToken)3 SlimeUtils (com.yahoo.vespa.config.SlimeUtils)3 Application (com.yahoo.vespa.hosted.controller.Application)3 ActivateResult (com.yahoo.vespa.hosted.controller.api.ActivateResult)3 Tenant (com.yahoo.vespa.hosted.controller.api.Tenant)3 DeployOptions (com.yahoo.vespa.hosted.controller.api.application.v4.model.DeployOptions)3 ZoneId (com.yahoo.vespa.hosted.controller.api.integration.zone.ZoneId)3 ApplicationPackage (com.yahoo.vespa.hosted.controller.application.ApplicationPackage)3 DeploymentJobs (com.yahoo.vespa.hosted.controller.application.DeploymentJobs)3 Duration (java.time.Duration)3 Collections (java.util.Collections)3 Joiner (com.google.common.base.Joiner)2