summaryrefslogtreecommitdiffstats
path: root/configserver
diff options
context:
space:
mode:
authorHarald Musum <musum@verizonmedia.com>2020-08-26 14:09:29 +0200
committerHarald Musum <musum@verizonmedia.com>2020-08-26 14:09:29 +0200
commitd99f9f6ba22b168464acbacbd3ed36ba5d0f002a (patch)
treefd8e533ea7dd4001df6f00edc862dfafcab0fad0 /configserver
parentb6842cae09f41e6cd765587c247decaeeb2bf5b5 (diff)
Write tenant metadata for already created tenants as well
Diffstat (limited to 'configserver')
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/tenant/TenantRepository.java15
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/ApplicationRepositoryTest.java27
2 files changed, 33 insertions, 9 deletions
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/tenant/TenantRepository.java b/configserver/src/main/java/com/yahoo/vespa/config/server/tenant/TenantRepository.java
index 83a7820993d..6216e8ebfd6 100644
--- a/configserver/src/main/java/com/yahoo/vespa/config/server/tenant/TenantRepository.java
+++ b/configserver/src/main/java/com/yahoo/vespa/config/server/tenant/TenantRepository.java
@@ -145,9 +145,9 @@ public class TenantRepository {
}
}
- public synchronized void addTenant(TenantName tenantName) {
+ public synchronized Tenant addTenant(TenantName tenantName) {
writeTenantPath(tenantName);
- createTenant(tenantName, componentRegistry.getClock().instant());
+ return createTenant(tenantName, componentRegistry.getClock().instant());
}
public void createAndWriteTenantMetaData(Tenant tenant) {
@@ -242,8 +242,14 @@ public class TenantRepository {
}
// Creates tenant and all its dependencies. This also includes loading active applications
- private void createTenant(TenantName tenantName, Instant created) {
- if (tenants.containsKey(tenantName)) return;
+ private Tenant createTenant(TenantName tenantName, Instant created) {
+ if (tenants.containsKey(tenantName)) {
+ Tenant tenant = getTenant(tenantName);
+ if (useTenantMetaData.value())
+ createAndWriteTenantMetaData(tenant);
+
+ return tenant;
+ }
TenantApplications applicationRepo =
new TenantApplications(tenantName,
@@ -266,6 +272,7 @@ public class TenantRepository {
tenants.putIfAbsent(tenantName, tenant);
if (useTenantMetaData.value())
createAndWriteTenantMetaData(tenant);
+ return tenant;
}
/**
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 cb43e80e82d..bd3053dd61f 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
@@ -172,10 +172,18 @@ public class ApplicationRepositoryTest {
@Test
public void prepareAndActivateWithTenantMetaData() throws IOException {
- FlagSource flagSource = new InMemoryFlagSource().withBooleanFlag(Flags.USE_TENANT_META_DATA.id(), true);
+ InMemoryFlagSource flagSource = new InMemoryFlagSource().withBooleanFlag(Flags.USE_TENANT_META_DATA.id(), false);
setup(flagSource);
- Instant startTime = clock.instant();
+ // Tenants created when flag is false has EPOCH as metadata values
+ Tenant tenant = applicationRepository.getTenant(applicationId());
+ assertEquals(Instant.EPOCH.toEpochMilli(),
+ applicationRepository.getTenantMetaData(tenant).createdTimestamp().toEpochMilli());
+ assertEquals(Instant.EPOCH.toEpochMilli(),
+ applicationRepository.getTenantMetaData(tenant).lastDeployTimestamp().toEpochMilli());
+
+ // Change flag value to true
+ flagSource.withBooleanFlag(Flags.USE_TENANT_META_DATA.id(), true);
Duration duration = Duration.ofHours(1);
clock.advance(duration);
Instant deployTime = clock.instant();
@@ -183,15 +191,24 @@ public class ApplicationRepositoryTest {
assertTrue(result.configChangeActions().getRefeedActions().isEmpty());
assertTrue(result.configChangeActions().getRestartActions().isEmpty());
- Tenant tenant = applicationRepository.getTenant(applicationId());
LocalSession session = tenant.getSessionRepository().getLocalSession(tenant.getApplicationRepo()
.requireActiveSessionOf(applicationId()));
session.getAllocatedHosts();
+ // Only last deploy timestamp updated
+ assertEquals(Instant.EPOCH.toEpochMilli(),
+ applicationRepository.getTenantMetaData(tenant).createdTimestamp().toEpochMilli());
assertEquals(deployTime.toEpochMilli(),
applicationRepository.getTenantMetaData(tenant).lastDeployTimestamp().toEpochMilli());
- assertEquals(startTime.toEpochMilli(),
- applicationRepository.getTenantMetaData(tenant).createdTimestamp().toEpochMilli());
+
+ // Creating a new tenant will have metadata with timestamp equal to current time
+ clock.advance(duration);
+ Instant createTenantTime = clock.instant();
+ Tenant fooTenant = tenantRepository.addTenant(TenantName.from("foo"));
+ assertEquals(createTenantTime.toEpochMilli(),
+ applicationRepository.getTenantMetaData(fooTenant).createdTimestamp().toEpochMilli());
+ assertEquals(createTenantTime.toEpochMilli(),
+ applicationRepository.getTenantMetaData(fooTenant).lastDeployTimestamp().toEpochMilli());
}
@Test