summaryrefslogtreecommitdiffstats
path: root/configserver
diff options
context:
space:
mode:
authorHarald Musum <musum@verizonmedia.com>2020-08-20 07:40:21 +0200
committerHarald Musum <musum@verizonmedia.com>2020-08-20 07:40:21 +0200
commit427a8ff09ba630f2f160fb2a3e98bc6fe0fd2efd (patch)
tree4e087cfc86b4857622f8d5adfdd9a36b286595f5 /configserver
parent003014bafce3a9ac1de4a51ef0e60ddc7c76ee0e (diff)
Use tenant name and session id in + clean up tests
Diffstat (limited to 'configserver')
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionRepository.java3
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionZooKeeperClient.java13
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/ApplicationRepositoryTest.java3
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/application/TenantApplicationsTest.java10
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/session/LocalSessionTest.java35
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/session/MockSessionZKClient.java3
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionPreparerTest.java59
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionRepositoryTest.java7
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionZooKeeperClientTest.java62
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/tenant/TenantRepositoryTest.java9
10 files changed, 133 insertions, 71 deletions
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionRepository.java b/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionRepository.java
index cce79412cfe..1964750495b 100644
--- a/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionRepository.java
+++ b/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionRepository.java
@@ -654,8 +654,7 @@ public class SessionRepository {
private SessionZooKeeperClient createSessionZooKeeperClient(long sessionId) {
String serverId = componentRegistry.getConfigserverConfig().serverId();
- Path sessionPath = getSessionPath(sessionId);
- return new SessionZooKeeperClient(curator, componentRegistry.getConfigCurator(), sessionPath, serverId);
+ return new SessionZooKeeperClient(curator, componentRegistry.getConfigCurator(), tenantName, sessionId, serverId);
}
private File getAndValidateExistingSessionAppDir(long sessionId) {
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionZooKeeperClient.java b/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionZooKeeperClient.java
index bbf72067b00..fc01584cde1 100644
--- a/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionZooKeeperClient.java
+++ b/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionZooKeeperClient.java
@@ -11,12 +11,14 @@ import com.yahoo.config.provision.AllocatedHosts;
import com.yahoo.config.provision.ApplicationId;
import com.yahoo.config.provision.AthenzDomain;
import com.yahoo.config.provision.DockerImage;
+import com.yahoo.config.provision.TenantName;
import com.yahoo.path.Path;
import com.yahoo.text.Utf8;
import com.yahoo.transaction.Transaction;
import com.yahoo.vespa.config.server.UserConfigDefinitionRepo;
import com.yahoo.vespa.config.server.deploy.ZooKeeperClient;
import com.yahoo.vespa.config.server.deploy.ZooKeeperDeployer;
+import com.yahoo.vespa.config.server.tenant.TenantRepository;
import com.yahoo.vespa.config.server.zookeeper.ConfigCurator;
import com.yahoo.vespa.config.server.zookeeper.ZKApplicationPackage;
import com.yahoo.vespa.curator.Curator;
@@ -47,17 +49,20 @@ public class SessionZooKeeperClient {
private static final String ATHENZ_DOMAIN = "athenzDomain";
private final Curator curator;
private final ConfigCurator configCurator;
+ private final TenantName tenantName;
private final Path sessionPath;
private final Path sessionStatusPath;
private final String serverId; // hostname
public SessionZooKeeperClient(Curator curator,
ConfigCurator configCurator,
- Path sessionPath,
+ TenantName tenantName,
+ long sessionId,
String serverId) {
this.curator = curator;
this.configCurator = configCurator;
- this.sessionPath = sessionPath;
+ this.tenantName = tenantName;
+ this.sessionPath = getSessionPath(tenantName, sessionId);
this.serverId = serverId;
this.sessionStatusPath = sessionPath.append(ConfigCurator.SESSIONSTATE_ZK_SUBPATH);
}
@@ -247,4 +252,8 @@ public class SessionZooKeeperClient {
transaction.commit();
}
+ private static Path getSessionPath(TenantName tenantName, long sessionId) {
+ return TenantRepository.getSessionsPath(tenantName).append(String.valueOf(sessionId));
+ }
+
}
diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/ApplicationRepositoryTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/ApplicationRepositoryTest.java
index c2e394fc450..f85911eac01 100644
--- a/configserver/src/test/java/com/yahoo/vespa/config/server/ApplicationRepositoryTest.java
+++ b/configserver/src/test/java/com/yahoo/vespa/config/server/ApplicationRepositoryTest.java
@@ -410,7 +410,8 @@ public class ApplicationRepositoryTest {
FilesApplicationPackage.fromFile(testApp),
new SessionZooKeeperClient(curator,
configCurator,
- sessionRepository.getSessionPath(sessionId),
+ tenant1,
+ sessionId,
ConfigUtils.getCanonicalHostName()));
sessionRepository.addLocalSession(localSession2);
assertEquals(2, sessionRepository.getLocalSessions().size());
diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/application/TenantApplicationsTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/application/TenantApplicationsTest.java
index 05f7aade168..cde115eec40 100644
--- a/configserver/src/test/java/com/yahoo/vespa/config/server/application/TenantApplicationsTest.java
+++ b/configserver/src/test/java/com/yahoo/vespa/config/server/application/TenantApplicationsTest.java
@@ -171,19 +171,21 @@ public class TenantApplicationsTest {
@Test
public void testListConfigs() throws IOException, SAXException {
+ applications = TenantApplications.create(componentRegistry, TenantName.defaultName());
assertdefaultAppNotFound();
VespaModel model = new VespaModel(FilesApplicationPackage.fromFile(new File("src/test/apps/app")));
- applications.createApplication(ApplicationId.defaultId());
- applications.createPutTransaction(ApplicationId.defaultId(), 1).commit();
+ ApplicationId applicationId = ApplicationId.defaultId();
+ applications.createApplication(applicationId);
+ applications.createPutTransaction(applicationId, 1).commit();
applications.reloadConfig(ApplicationSet.fromSingle(new Application(model,
new ServerCache(),
1,
false,
vespaVersion,
MetricUpdater.createTestUpdater(),
- ApplicationId.defaultId())));
- Set<ConfigKey<?>> configNames = applications.listConfigs(ApplicationId.defaultId(), Optional.of(vespaVersion), false);
+ applicationId)));
+ Set<ConfigKey<?>> configNames = applications.listConfigs(applicationId, Optional.of(vespaVersion), false);
assertTrue(configNames.contains(new ConfigKey<>("sentinel", "hosts", "cloud.config")));
configNames = applications.listConfigs(ApplicationId.defaultId(), Optional.of(vespaVersion), true);
diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/session/LocalSessionTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/session/LocalSessionTest.java
index cf01c9b6713..fb268492dd7 100644
--- a/configserver/src/test/java/com/yahoo/vespa/config/server/session/LocalSessionTest.java
+++ b/configserver/src/test/java/com/yahoo/vespa/config/server/session/LocalSessionTest.java
@@ -69,17 +69,17 @@ public class LocalSessionTest {
@Test
public void require_that_session_is_initialized() throws Exception {
- LocalSession session = createSession(TenantName.defaultName(), 2);
+ LocalSession session = createSession(applicationId(), 2);
assertThat(session.getSessionId(), is(2L));
- session = createSession(TenantName.defaultName(), Long.MAX_VALUE);
+ session = createSession(applicationId(), Long.MAX_VALUE);
assertThat(session.getSessionId(), is(Long.MAX_VALUE));
assertThat(session.getActiveSessionAtCreate(), is(0L));
}
@Test
public void require_that_marking_session_modified_changes_status_to_new() throws Exception {
- LocalSession session = createSession(TenantName.defaultName(), 3);
- doPrepare(session);
+ LocalSession session = createSession(applicationId(), 3);
+ doPrepare(session, applicationId());
assertThat(session.getStatus(), is(Session.Status.PREPARE));
session.getApplicationFile(Path.createRoot(), Session.Mode.READ);
assertThat(session.getStatus(), is(Session.Status.PREPARE));
@@ -89,7 +89,7 @@ public class LocalSessionTest {
@Test
public void require_that_application_file_can_be_fetched() throws Exception {
- LocalSession session = createSession(TenantName.defaultName(), 3);
+ LocalSession session = createSession(applicationId(), 3);
ApplicationFile f1 = session.getApplicationFile(Path.fromString("services.xml"), Session.Mode.READ);
ApplicationFile f2 = session.getApplicationFile(Path.fromString("services2.xml"), Session.Mode.READ);
assertTrue(f1.exists());
@@ -98,36 +98,37 @@ public class LocalSessionTest {
@Test(expected = IllegalStateException.class)
public void require_that_no_provision_info_throws_exception() throws Exception {
- createSession(TenantName.defaultName(), 3).getAllocatedHosts();
+ createSession(applicationId(), 3).getAllocatedHosts();
}
- private LocalSession createSession(TenantName tenant, long sessionId) throws Exception {
- return createSession(tenant, sessionId, Optional.empty());
+ private LocalSession createSession(ApplicationId applicationId, long sessionId) throws Exception {
+ return createSession(applicationId, sessionId, Optional.empty());
}
- private LocalSession createSession(TenantName tenant, long sessionId,
+ private LocalSession createSession(ApplicationId applicationId, long sessionId,
Optional<AllocatedHosts> allocatedHosts) throws Exception {
- SessionZooKeeperClient zkc = new MockSessionZKClient(curator, tenant, sessionId, allocatedHosts);
+ TenantName tenantName = applicationId.tenant();
+ SessionZooKeeperClient zkc = new MockSessionZKClient(curator, tenantName, sessionId, allocatedHosts);
zkc.createWriteStatusTransaction(Session.Status.NEW).commit();
ZooKeeperClient zkClient = new ZooKeeperClient(configCurator, new BaseDeployLogger(),
- TenantRepository.getSessionsPath(tenant).append(String.valueOf(sessionId)));
+ TenantRepository.getSessionsPath(tenantName).append(String.valueOf(sessionId)));
if (allocatedHosts.isPresent()) {
zkClient.write(allocatedHosts.get());
}
zkClient.write(Collections.singletonMap(new Version(0, 0, 0), new MockFileRegistry()));
TenantApplications applications = tenantRepository.getTenant(tenantName).getApplicationRepo();
- applications.createApplication(applicationId());
- LocalSession session = new LocalSession(tenant, sessionId, FilesApplicationPackage.fromFile(testApp), zkc);
- session.setApplicationId(applicationId());
+ applications.createApplication(applicationId);
+ LocalSession session = new LocalSession(tenantName, sessionId, FilesApplicationPackage.fromFile(testApp), zkc);
+ session.setApplicationId(applicationId);
return session;
}
- private void doPrepare(LocalSession session) {
- doPrepare(session, new PrepareParams.Builder().applicationId(applicationId()).build());
+ private void doPrepare(LocalSession session, ApplicationId applicationId) {
+ doPrepare(session, new PrepareParams.Builder().applicationId(applicationId).build());
}
private void doPrepare(LocalSession session, PrepareParams params) {
- SessionRepository sessionRepository = tenantRepository.getTenant(tenantName).getSessionRepository();
+ SessionRepository sessionRepository = tenantRepository.getTenant(params.getApplicationId().tenant()).getSessionRepository();
sessionRepository.prepareLocalSession(session, getLogger(), params, Optional.empty(), tenantPath, Instant.now());
}
diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/session/MockSessionZKClient.java b/configserver/src/test/java/com/yahoo/vespa/config/server/session/MockSessionZKClient.java
index 296fbf56b3d..0451ef84e09 100644
--- a/configserver/src/test/java/com/yahoo/vespa/config/server/session/MockSessionZKClient.java
+++ b/configserver/src/test/java/com/yahoo/vespa/config/server/session/MockSessionZKClient.java
@@ -34,7 +34,8 @@ public class MockSessionZKClient extends SessionZooKeeperClient {
MockSessionZKClient(Curator curator, TenantName tenantName, long sessionId, ApplicationPackage application) {
super(curator,
ConfigCurator.create(curator),
- TenantRepository.getSessionsPath(tenantName).append(String.valueOf(sessionId)),
+ tenantName,
+ sessionId,
ConfigUtils.getCanonicalHostName());
this.app = application;
curator.create(TenantRepository.getSessionsPath(tenantName).append(String.valueOf(sessionId)));
diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionPreparerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionPreparerTest.java
index ee8f00f6bcf..3aee202e42c 100644
--- a/configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionPreparerTest.java
+++ b/configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionPreparerTest.java
@@ -42,6 +42,7 @@ import com.yahoo.vespa.config.server.provision.HostProvisionerProvider;
import com.yahoo.vespa.config.server.tenant.ContainerEndpointsCache;
import com.yahoo.vespa.config.server.tenant.EndpointCertificateMetadataStore;
import com.yahoo.vespa.config.server.tenant.EndpointCertificateRetriever;
+import com.yahoo.vespa.config.server.tenant.TenantRepository;
import com.yahoo.vespa.config.server.zookeeper.ConfigCurator;
import com.yahoo.vespa.config.util.ConfigUtils;
import com.yahoo.vespa.curator.mock.MockCurator;
@@ -81,7 +82,6 @@ import static org.junit.Assert.assertTrue;
public class SessionPreparerTest {
private static final Path tenantPath = Path.createRoot();
- private static final Path sessionsPath = tenantPath.append("sessions").append("testapp");
private static final File testApp = new File("src/test/apps/app");
private static final File invalidTestApp = new File("src/test/apps/illegalApp");
private static final Version version123 = new Version(1, 2, 3);
@@ -146,25 +146,44 @@ public class SessionPreparerTest {
@Test
public void require_that_application_validation_exception_is_ignored_if_forced() throws IOException {
- prepare(invalidTestApp, new PrepareParams.Builder().applicationId(applicationId()).ignoreValidationErrors(true).timeoutBudget(TimeoutBudgetTest.day()).build());
+ prepare(invalidTestApp,
+ new PrepareParams.Builder()
+ .applicationId(applicationId())
+ .ignoreValidationErrors(true)
+ .timeoutBudget(TimeoutBudgetTest.day())
+ .build(),
+ 1);
}
@Test
public void require_that_zookeeper_is_not_written_to_if_dryrun() throws IOException {
- prepare(testApp, new PrepareParams.Builder().applicationId(applicationId()).dryRun(true).timeoutBudget(TimeoutBudgetTest.day()).build());
- assertFalse(configCurator.exists(sessionsPath.append(ConfigCurator.USERAPP_ZK_SUBPATH).append("services.xml").getAbsolute()));
+ long sessionId = 1;
+ prepare(testApp,
+ new PrepareParams.Builder()
+ .applicationId(applicationId())
+ .dryRun(true)
+ .timeoutBudget(TimeoutBudgetTest.day())
+ .build(),
+ 1);
+ Path sessionPath = sessionPath(sessionId);
+ assertFalse(configCurator.exists(sessionPath.append(ConfigCurator.USERAPP_ZK_SUBPATH).append("services.xml").getAbsolute()));
}
@Test
public void require_that_filedistribution_is_ignored_on_dryrun() throws IOException {
- PrepareResult result = prepare(testApp, new PrepareParams.Builder().applicationId(applicationId()).dryRun(true).build());
+ PrepareResult result = prepare(testApp,
+ new PrepareParams.Builder()
+ .applicationId(applicationId())
+ .dryRun(true)
+ .build(),
+ 1);
assertTrue(result.getFileRegistries().get(version321).export().isEmpty());
}
@Test
public void require_that_application_is_prepared() throws Exception {
prepare(testApp);
- assertTrue(configCurator.exists(sessionsPath.append(ConfigCurator.USERAPP_ZK_SUBPATH).append("services.xml").getAbsolute()));
+ assertTrue(configCurator.exists(sessionPath(1).append(ConfigCurator.USERAPP_ZK_SUBPATH).append("services.xml").getAbsolute()));
}
@Test(expected = InvalidApplicationException.class)
@@ -194,21 +213,17 @@ public class SessionPreparerTest {
@Test
public void require_that_application_id_is_written_in_prepare() throws IOException {
- TenantName tenant = TenantName.from("tenant");
- ApplicationId origId = new ApplicationId.Builder()
- .tenant(tenant)
- .applicationName("foo").instanceName("quux").build();
- PrepareParams params = new PrepareParams.Builder().applicationId(origId).build();
+ PrepareParams params = new PrepareParams.Builder().applicationId(applicationId()).build();
+ int sessionId = 1;
prepare(testApp, params);
- assertTrue(configCurator.exists(sessionsPath.append(SessionZooKeeperClient.APPLICATION_ID_PATH).getAbsolute()));
- assertThat(createSessionZooKeeperClient().readApplicationId().get(), is(origId));
+ assertThat(createSessionZooKeeperClient(sessionId).readApplicationId().get(), is(applicationId()));
}
@Test
public void require_that_file_reference_of_application_package_is_written_to_zk() throws Exception {
flagSource.withBooleanFlag(Flags.CONFIGSERVER_DISTRIBUTE_APPLICATION_PACKAGE.id(), true);
prepare(testApp);
- assertTrue(configCurator.exists(sessionsPath.append(APPLICATION_PACKAGE_REFERENCE_PATH).getAbsolute()));
+ assertTrue(configCurator.exists(sessionPath(1).append(APPLICATION_PACKAGE_REFERENCE_PATH).getAbsolute()));
}
@Test
@@ -333,10 +348,14 @@ public class SessionPreparerTest {
}
private PrepareResult prepare(File app, PrepareParams params) throws IOException {
+ return prepare(app, params, 1);
+ }
+
+ private PrepareResult prepare(File app, PrepareParams params, long sessionId) throws IOException {
FilesApplicationPackage applicationPackage = getApplicationPackage(app);
return preparer.prepare(new HostRegistry<>(), getLogger(), params,
Optional.empty(), tenantPath, Instant.now(), applicationPackage.getAppDir(),
- applicationPackage, createSessionZooKeeperClient());
+ applicationPackage, createSessionZooKeeperClient(sessionId));
}
private FilesApplicationPackage getApplicationPackage(File testFile) throws IOException {
@@ -361,7 +380,15 @@ public class SessionPreparerTest {
}
private SessionZooKeeperClient createSessionZooKeeperClient() {
- return new SessionZooKeeperClient(curator, configCurator, sessionsPath, ConfigUtils.getCanonicalHostName());
+ return createSessionZooKeeperClient(1);
+ }
+
+ private SessionZooKeeperClient createSessionZooKeeperClient(long sessionId) {
+ return new SessionZooKeeperClient(curator, configCurator, applicationId().tenant(), sessionId, ConfigUtils.getCanonicalHostName());
+ }
+
+ private Path sessionPath(long sessionId) {
+ return TenantRepository.getSessionsPath(applicationId().tenant()).append(String.valueOf(sessionId));
}
private static class FailWithTransientExceptionProvisioner implements Provisioner {
diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionRepositoryTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionRepositoryTest.java
index 9b9682faf5f..fb7b5280b1e 100644
--- a/configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionRepositoryTest.java
+++ b/configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionRepositoryTest.java
@@ -151,13 +151,10 @@ public class SessionRepositoryTest {
}
private void createSession(long sessionId, boolean wait) {
- createSession(sessionId, wait, sessionRepository);
- }
-
- private void createSession(long sessionId, boolean wait, SessionRepository sessionRepository) {
SessionZooKeeperClient zkc = new SessionZooKeeperClient(curator,
ConfigCurator.create(curator),
- sessionRepository.getSessionPath(sessionId),
+ tenantName,
+ sessionId,
ConfigUtils.getCanonicalHostName());
zkc.createNewSession(Instant.now());
if (wait) {
diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionZooKeeperClientTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionZooKeeperClientTest.java
index 2fc4c0f456f..d6e16cec7e9 100644
--- a/configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionZooKeeperClientTest.java
+++ b/configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionZooKeeperClientTest.java
@@ -3,8 +3,10 @@ package com.yahoo.vespa.config.server.session;
import com.yahoo.config.FileReference;
import com.yahoo.config.provision.ApplicationId;
+import com.yahoo.config.provision.TenantName;
import com.yahoo.path.Path;
import com.yahoo.text.Utf8;
+import com.yahoo.vespa.config.server.tenant.TenantRepository;
import com.yahoo.vespa.config.server.zookeeper.ConfigCurator;
import com.yahoo.vespa.config.util.ConfigUtils;
import com.yahoo.vespa.curator.Curator;
@@ -23,6 +25,8 @@ import static org.junit.Assert.assertTrue;
*/
public class SessionZooKeeperClientTest {
+ private static final TenantName tenantName = TenantName.defaultName();
+
private Curator curator;
private ConfigCurator configCurator;
@@ -30,11 +34,12 @@ public class SessionZooKeeperClientTest {
public void setup() {
curator = new MockCurator();
configCurator = ConfigCurator.create(curator);
+ curator.create(sessionsPath());
}
@Test
public void require_that_status_can_be_updated() {
- SessionZooKeeperClient zkc = createSessionZKClient("1");
+ SessionZooKeeperClient zkc = createSessionZKClient(1);
zkc.writeStatus(Session.Status.NEW);
assertThat(zkc.readStatus(), is(Session.Status.NEW));
@@ -50,45 +55,53 @@ public class SessionZooKeeperClientTest {
@Test
public void require_that_status_is_written_to_zk() {
- SessionZooKeeperClient zkc = createSessionZKClient("2");
+ int sessionId = 2;
+ SessionZooKeeperClient zkc = createSessionZKClient(sessionId);
zkc.writeStatus(Session.Status.NEW);
- String path = "/2" + ConfigCurator.SESSIONSTATE_ZK_SUBPATH;
+ String path = sessionPath(sessionId).append(ConfigCurator.SESSIONSTATE_ZK_SUBPATH).getAbsolute();
assertTrue(configCurator.exists(path));
assertThat(configCurator.getData(path), is("NEW"));
}
@Test
public void require_that_status_is_read_from_zk() {
- SessionZooKeeperClient zkc = createSessionZKClient("3");
- curator.set(Path.fromString("3").append(ConfigCurator.SESSIONSTATE_ZK_SUBPATH), Utf8.toBytes("PREPARE"));
+ int sessionId = 3;
+ SessionZooKeeperClient zkc = createSessionZKClient(sessionId);
+ curator.set(sessionPath(sessionId).append(ConfigCurator.SESSIONSTATE_ZK_SUBPATH), Utf8.toBytes("PREPARE"));
assertThat(zkc.readStatus(), is(Session.Status.PREPARE));
}
@Test
public void require_that_application_id_is_written_to_zk() {
ApplicationId id = new ApplicationId.Builder()
- .tenant("tenant")
- .applicationName("foo").instanceName("bim").build();
- SessionZooKeeperClient zkc = createSessionZKClient("3");
+ .tenant(tenantName)
+ .applicationName("foo")
+ .instanceName("bim")
+ .build();
+ int sessionId = 3;
+ SessionZooKeeperClient zkc = createSessionZKClient(sessionId);
zkc.writeApplicationId(id);
- String path = "/3/" + SessionZooKeeperClient.APPLICATION_ID_PATH;
+ String path = sessionPath(sessionId).append(SessionZooKeeperClient.APPLICATION_ID_PATH).getAbsolute();
assertTrue(configCurator.exists(path));
- assertThat(configCurator.getData(path), is("tenant:foo:bim"));
+ assertThat(configCurator.getData(path), is(id.serializedForm()));
}
@Test
public void require_that_application_id_is_read_from_zk() {
ApplicationId id = new ApplicationId.Builder()
- .tenant("tenant")
- .applicationName("bar").instanceName("quux").build();
+ .tenant("tenant")
+ .applicationName("bar")
+ .instanceName("quux")
+ .build();
String idNoVersion = id.serializedForm();
- assertApplicationIdParse("3", idNoVersion, idNoVersion);
+ assertApplicationIdParse(3, idNoVersion, idNoVersion);
}
@Test
public void require_that_create_time_can_be_written_and_read() {
- SessionZooKeeperClient zkc = createSessionZKClient("3");
- curator.delete(Path.fromString("3"));
+ int sessionId = 3;
+ SessionZooKeeperClient zkc = createSessionZKClient(sessionId);
+ curator.delete(sessionPath(sessionId));
assertThat(zkc.readCreateTime(), is(Instant.EPOCH));
Instant now = Instant.now();
zkc.createNewSession(now);
@@ -99,26 +112,35 @@ public class SessionZooKeeperClientTest {
@Test
public void require_that_application_package_file_reference_can_be_written_and_read() {
final FileReference testRef = new FileReference("test-ref");
- SessionZooKeeperClient zkc = createSessionZKClient("3");
+ SessionZooKeeperClient zkc = createSessionZKClient(3);
zkc.writeApplicationPackageReference(testRef);
assertThat(zkc.readApplicationPackageReference(), is(testRef));
}
- private void assertApplicationIdParse(String sessionId, String idString, String expectedIdString) {
+ private void assertApplicationIdParse(long sessionId, String idString, String expectedIdString) {
SessionZooKeeperClient zkc = createSessionZKClient(sessionId);
- String path = "/" + sessionId + "/" + SessionZooKeeperClient.APPLICATION_ID_PATH;
+ String path = sessionPath(sessionId).append(SessionZooKeeperClient.APPLICATION_ID_PATH).getAbsolute();
configCurator.putData(path, idString);
ApplicationId applicationId = zkc.readApplicationId().get();
assertThat(applicationId.serializedForm(), is(expectedIdString));
}
- private SessionZooKeeperClient createSessionZKClient(String sessionId) {
+ private SessionZooKeeperClient createSessionZKClient(long sessionId) {
SessionZooKeeperClient zkc = new SessionZooKeeperClient(curator,
ConfigCurator.create(curator),
- Path.fromString(sessionId),
+ tenantName,
+ sessionId,
ConfigUtils.getCanonicalHostName());
zkc.createNewSession(Instant.now());
return zkc;
}
+ private static Path sessionsPath() {
+ return TenantRepository.getSessionsPath(tenantName);
+ }
+
+ private static Path sessionPath(long sessionId) {
+ return sessionsPath().append(String.valueOf(sessionId));
+ }
+
}
diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/tenant/TenantRepositoryTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/tenant/TenantRepositoryTest.java
index f372b21b065..a31b06bbebb 100644
--- a/configserver/src/test/java/com/yahoo/vespa/config/server/tenant/TenantRepositoryTest.java
+++ b/configserver/src/test/java/com/yahoo/vespa/config/server/tenant/TenantRepositoryTest.java
@@ -5,7 +5,9 @@ import com.yahoo.cloud.config.ConfigserverConfig;
import com.yahoo.component.Version;
import com.yahoo.config.model.test.MockApplicationPackage;
import com.yahoo.config.provision.ApplicationId;
+import com.yahoo.config.provision.ApplicationName;
import com.yahoo.config.provision.Environment;
+import com.yahoo.config.provision.InstanceName;
import com.yahoo.config.provision.RegionName;
import com.yahoo.config.provision.SystemName;
import com.yahoo.config.provision.TenantName;
@@ -84,8 +86,9 @@ public class TenantRepositoryTest {
@Test
public void testListenersAdded() throws IOException, SAXException {
TenantApplications applicationRepo = tenantRepository.getTenant(tenant1).getApplicationRepo();
- applicationRepo.createApplication(ApplicationId.defaultId());
- applicationRepo.createPutTransaction(ApplicationId.defaultId(), 4).commit();
+ ApplicationId id = ApplicationId.from(tenant1, ApplicationName.defaultName(), InstanceName.defaultName());
+ applicationRepo.createApplication(id);
+ applicationRepo.createPutTransaction(id, 4).commit();
applicationRepo.reloadConfig(ApplicationSet.fromSingle(
new Application(new VespaModel(MockApplicationPackage.createEmpty()),
new ServerCache(),
@@ -93,7 +96,7 @@ public class TenantRepositoryTest {
false,
new Version(1, 2, 3),
MetricUpdater.createTestUpdater(),
- ApplicationId.defaultId())));
+ id)));
assertEquals(1, listener.reloaded.get());
}