@JsonCreator public Region(String region) { this.region = com.yahoo.config.provision.RegionName.from(region); } }
@JsonValue public String value() { return region.value(); }
public boolean isDefault() { return equals(RegionName.defaultName()); }
@Override public boolean isActive() { if(zone.system() == SystemName.cd) { return zone.environment() == Environment.dev || zone.environment() == Environment.prod; } if (zone.system() == SystemName.main) { if (zone.region().equals(RegionName.from("us-east-3"))) { return zone.environment() == Environment.perf || zone.environment() == Environment.prod; } else if (zone.region().equals(RegionName.from("us-west-1"))) { return zone.environment() == Environment.prod; } else if (zone.region().equals(RegionName.from("us-central-1"))) { return zone.environment() == Environment.prod; } else if (zone.region().equals(RegionName.from("ap-southeast-1"))) { return zone.environment() == Environment.prod; } else if (zone.region().equals(RegionName.from("ap-northeast-1"))) { return zone.environment() == Environment.prod; } else if (zone.region().equals(RegionName.from("ap-northeast-2"))) { return zone.environment() == Environment.prod; } else if (zone.region().equals(RegionName.from("eu-west-1"))) { return zone.environment() == Environment.prod; } } return false; }
public void setContainerCluster(ContainerCluster containerCluster) { this.containerCluster = containerCluster; // If we are in a config server cluster the correct zone is propagated through cloud config options, // not through config to deployment options (see StandaloneContainerApplication.scala), // so we need to propagate the zone options into the container from here Environment environment = options.environment().isPresent() ? Environment.from(options.environment().get()) : Environment.defaultEnvironment(); RegionName region = options.region().isPresent() ? RegionName.from(options.region().get()) : RegionName.defaultName(); SystemName system = options.system().isPresent() ? SystemName.from(options.system().get()) : SystemName.defaultSystem(); containerCluster.setZone(new Zone(system, environment, region)); }
/** Do not use */ public static Zone defaultZone() { return new Zone(SystemName.defaultSystem(), Environment.defaultEnvironment(), RegionName.defaultName()); }
public static RegionName defaultName() { return new RegionName("default"); }
public static RegionName from(String region) { return new RegionName(region); }
/** This may be invoked by a continuous build */ public static void main(String[] args) { if (args.length != 2 && args.length != 3) { System.err.println("Usage: DeploymentSpec [file] [environment] [region]?" + "Returns 0 if the specified zone matches the deployment spec, 1 otherwise"); System.exit(1); } try (BufferedReader reader = new BufferedReader(new FileReader(args[0]))) { DeploymentSpec spec = DeploymentSpec.fromXml(reader); Environment environment = Environment.from(args[1]); Optional<RegionName> region = args.length == 3 ? Optional.of(RegionName.from(args[2])) : Optional.empty(); if (spec.includes(environment, region)) System.exit(0); else System.exit(1); } catch (Exception e) { System.err.println("Exception checking deployment spec: " + toMessageString(e)); System.exit(1); } }
private String getConfigserverIdentityName() { return String.format("%s.provider_%s_%s", zone.system() == SystemName.main ? "vespa.vespa" : "vespa.vespa.cd", zone.environment().value(), zone.region().value()); } }
private DeclaredZone readDeclaredZone(Environment environment, Optional<AthenzService> athenzService, Element regionTag) { return new DeclaredZone(environment, Optional.of(RegionName.from(XML.getValue(regionTag).trim())), readActive(regionTag), athenzService); }
private String getHostFromVespaCertificate(List<SubjectAlternativeName> sans) { // TODO Remove this branch once all BM nodes are gone if (sans.stream().anyMatch(san -> san.getValue().endsWith("ostk.yahoo.cloud"))) { return getHostFromCalypsoCertificate(sans); } VespaUniqueInstanceId instanceId = VespaUniqueInstanceId.fromDottedString(getUniqueInstanceId(sans)); if (!zone.environment().value().equals(instanceId.environment())) throw new NodeIdentifierException("Invalid environment: " + instanceId.environment()); if (!zone.region().value().equals(instanceId.region())) throw new NodeIdentifierException("Invalid region(): " + instanceId.region()); List<Node> applicationNodes = nodeRepository.getNodes(ApplicationId.from(instanceId.tenant(), instanceId.application(), instanceId.instance())); return applicationNodes.stream() .filter( node -> node.allocation() .map(allocation -> allocation.membership().index() == instanceId.clusterIndex() && allocation.membership().cluster().id().value().equals(instanceId.clusterId())) .orElse(false)) .map(Node::hostname) .findFirst() .orElseThrow(() -> new NodeIdentifierException("Could not find any node with instance id: " + instanceId.asDottedString())); }
public static ZoneId from(String environment, String region) { return from(Environment.from(environment), RegionName.from(region)); }
private void addIdentityProvider(ContainerCluster cluster, List<ConfigServerSpec> configServerSpecs, HostName loadBalancerName, URI ztsUrl, String athenzDnsSuffix, Zone zone, DeploymentSpec spec) { spec.athenzDomain().ifPresent(domain -> { AthenzService service = spec.athenzService(zone.environment(), zone.region()) .orElseThrow(() -> new RuntimeException("Missing Athenz service configuration")); String zoneDnsSuffix = zone.environment().value() + "-" + zone.region().value() + "." + athenzDnsSuffix; IdentityProvider identityProvider = new IdentityProvider(domain, service, getLoadBalancerName(loadBalancerName, configServerSpecs), ztsUrl, zoneDnsSuffix, zone); cluster.addComponent(identityProvider); cluster.getContainers().forEach(container -> { container.setProp("identity.domain", domain.value()); container.setProp("identity.service", service.value()); }); }); }
public static ZoneId from(String environment, String region, String cloud) { return new ZoneId(Environment.from(environment), RegionName.from(region), CloudName.from(cloud)); }
/** * Returns a config server config containing the right zone settings (and defaults for the rest). * This is useful to allow applications to find out in which zone they are runnung by having the Zone * object (which is constructed from this config) injected. */ @Override public void getConfig(ConfigserverConfig.Builder builder) { builder.system(zone.system().name()); builder.environment(zone.environment().value()); builder.region(zone.region().value()); }
@Inject public Zone(ConfigserverConfig configserverConfig, NodeFlavors nodeFlavors) { this(SystemName.from(configserverConfig.system()), Environment.from(configserverConfig.environment()), RegionName.from(configserverConfig.region()), new FlavorDefaults(configserverConfig), nodeFlavors); }
private SentinelConfig.Application.Builder getApplicationConfig() { SentinelConfig.Application.Builder builder = new SentinelConfig.Application.Builder(); builder.tenant(applicationId.tenant().value()); builder.name(applicationId.application().value()); builder.environment(zone.environment().value()); builder.region(zone.region().value()); builder.instance(applicationId.instance().value()); return builder; }
public String dottedString() { return unCapitalize(applicationId().tenant().value()) + "." + unCapitalize(applicationId().application().value()) + "." + unCapitalize(zoneId.environment().value()) + "." + unCapitalize(zoneId.region().value()) + "." + unCapitalize(applicationId.instance().value()); }