Skip to content

Commit

Permalink
Merge pull request #9801 from vespa-engine/jvenstad/tenant-cd
Browse files Browse the repository at this point in the history
Jvenstad/tenant cd
  • Loading branch information
jonmv committed Jun 14, 2019
2 parents 9149dd7 + 88ef55c commit a3c4310
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 10 deletions.
Expand Up @@ -548,19 +548,19 @@ public Map<ClusterSpec.Id, URI> clusterEndpoints(DeploymentId id) {
.orElse(id.applicationId().instance().isTester()))
throw new NotExistsException("Deployment", id.toString());

// TODO jvenstad: Swap to use routingPolicies first, when this is ready.
try {
return Optional.of(routingGenerator.clusterEndpoints(id))
.filter(endpoints -> ! endpoints.isEmpty())
.orElseGet(() -> routingPolicies.get(id).stream()
.filter(policy -> policy.endpointIn(controller.system()).scope() == Endpoint.Scope.zone)
.collect(Collectors.toUnmodifiableMap(policy -> policy.cluster(),
policy -> policy.endpointIn(controller.system()).url())));
var endpoints = routingGenerator.clusterEndpoints(id);
if ( ! endpoints.isEmpty())
return endpoints;
}
catch (RuntimeException e) {
log.log(Level.WARNING, "Failed to get endpoint information for " + id + ": "
+ Exceptions.toMessageString(e));
return Collections.emptyMap();
log.log(Level.WARNING, "Failed to get endpoint information for " + id + ": " + Exceptions.toMessageString(e));
}
return routingPolicies.get(id).stream()
.filter(policy -> policy.endpointIn(controller.system()).scope() == Endpoint.Scope.zone)
.collect(Collectors.toUnmodifiableMap(policy -> policy.cluster(),
policy -> policy.endpointIn(controller.system()).url()));
}

/** Returns all zone-specific cluster endpoints for the given application, in the given zones. */
Expand Down
Expand Up @@ -44,7 +44,7 @@ public static TestConfig fromJson(byte[] jsonBytes) {
ZoneId zone = ZoneId.from(config.field("zone").asString());
SystemName system = SystemName.from(config.field("system").asString());
Map<ZoneId, Map<String, URI>> deployments = new HashMap<>();
config.field("clusterEndpoints").traverse((ObjectTraverser) (zoneId, endpointsObject) -> {
config.field("zoneEndpoints").traverse((ObjectTraverser) (zoneId, endpointsObject) -> {
Map<String, URI> endpoints = new HashMap<>();
endpointsObject.traverse((ObjectTraverser) (cluster, uri) -> endpoints.put(cluster, URI.create(uri.asString())));
deployments.put(ZoneId.from(zoneId), endpoints);
Expand Down
37 changes: 37 additions & 0 deletions hosted-api/src/test/java/ai/vespa/hosted/api/TestConfigTest.java
@@ -0,0 +1,37 @@
package ai.vespa.hosted.api;

import com.yahoo.config.provision.ApplicationId;
import com.yahoo.config.provision.SystemName;
import com.yahoo.config.provision.zone.ZoneId;
import org.junit.Test;

import java.io.IOException;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Map;

import static org.junit.Assert.assertEquals;

/**
* @author jonmv
*/
public class TestConfigTest {

@Test
public void testDeserialization() throws IOException {
TestConfig config = TestConfig.fromJson(Files.readAllBytes(Paths.get("src/test/resources/test-config.json")));
assertEquals(ApplicationId.from("t", "a", "i"),
config.application());
assertEquals(ZoneId.from("dev", "aws-us-east-1c"),
config.zone());
assertEquals(SystemName.PublicCd,
config.system());
assertEquals(Map.of(ZoneId.from("dev", "aws-us-east-1c"),
Map.of("default", URI.create("https://dev.endpoint:443/")),
ZoneId.from("prod", "aws-us-east-1a"),
Map.of("default", URI.create("https://prod.endpoint:443/"))),
config.deployments());
}

}
13 changes: 13 additions & 0 deletions hosted-api/src/test/resources/test-config.json
@@ -0,0 +1,13 @@
{
"application": "t:a:i",
"zone": "dev.aws-us-east-1c",
"system": "publiccd",
"zoneEndpoints": {
"dev.aws-us-east-1c": {
"default": "https://dev.endpoint:443/"
},
"prod.aws-us-east-1a": {
"default": "https://prod.endpoint:443/"
}
}
}

0 comments on commit a3c4310

Please sign in to comment.