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