summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Musum <musum@verizonmedia.com>2021-07-09 13:28:38 +0200
committerHarald Musum <musum@verizonmedia.com>2021-07-09 13:28:38 +0200
commitcc7f426c5fb6d95affe5da8524e6bb3ab55fb842 (patch)
tree0c725f3bc39f1ee31a3788c7fb2514b34e43f8dc
parentb0e2920c62e9679b07600328ae711d6657e70ff9 (diff)
Use Curator instead of ConfigCurator, part 4
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/SuperModelGenerationCounter.java4
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionRepository.java6
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/tenant/TenantRepository.java13
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/zookeeper/InitializedCounter.java30
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/zookeeper/SessionCounter.java9
-rw-r--r--configserver/src/main/resources/configserver-app/services.xml1
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/ApplicationRepositoryTest.java16
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionPreparerTest.java8
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionZooKeeperClientTest.java24
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/tenant/TenantRepositoryTest.java3
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/tenant/TestTenantRepository.java3
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/zookeeper/ConfigCuratorTest.java243
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/zookeeper/InitializedCounterTest.java12
-rw-r--r--orchestrator/src/main/java/com/yahoo/vespa/orchestrator/status/HostInfosCache.java5
-rw-r--r--zkfacade/src/main/java/com/yahoo/vespa/curator/recipes/CuratorCounter.java10
-rw-r--r--zkfacade/src/test/java/com/yahoo/vespa/curator/CuratorCounterTest.java9
16 files changed, 76 insertions, 320 deletions
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/SuperModelGenerationCounter.java b/configserver/src/main/java/com/yahoo/vespa/config/server/SuperModelGenerationCounter.java
index eb57b9346c7..c6ab70adce7 100644
--- a/configserver/src/main/java/com/yahoo/vespa/config/server/SuperModelGenerationCounter.java
+++ b/configserver/src/main/java/com/yahoo/vespa/config/server/SuperModelGenerationCounter.java
@@ -1,4 +1,4 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.config.server;
import com.yahoo.path.Path;
@@ -17,7 +17,7 @@ public class SuperModelGenerationCounter implements GenerationCounter {
private final CuratorCounter counter;
public SuperModelGenerationCounter(Curator curator) {
- this.counter = new CuratorCounter(curator, counterPath.getAbsolute());
+ this.counter = new CuratorCounter(curator, counterPath);
}
/**
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 6c4e3c78232..351099470db 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
@@ -126,7 +126,7 @@ public class SessionRepository {
public SessionRepository(TenantName tenantName,
TenantApplications applicationRepo,
SessionPreparer sessionPreparer,
- ConfigCurator configCurator,
+ Curator curator,
Metrics metrics,
StripedExecutor<TenantName> zkWatcherExecutor,
PermanentApplicationPackage permanentApplicationPackage,
@@ -141,10 +141,10 @@ public class SessionRepository {
ModelFactoryRegistry modelFactoryRegistry,
ConfigDefinitionRepo configDefinitionRepo) {
this.tenantName = tenantName;
- sessionCounter = new SessionCounter(configCurator, tenantName);
+ sessionCounter = new SessionCounter(curator, tenantName);
this.sessionsPath = TenantRepository.getSessionsPath(tenantName);
this.clock = clock;
- this.curator = configCurator.curator();
+ this.curator = curator;
this.sessionLifetime = Duration.ofSeconds(configserverConfig.sessionLifetime());
this.zkWatcherExecutor = command -> zkWatcherExecutor.execute(tenantName, command);
this.permanentApplicationPackage = permanentApplicationPackage;
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 40e6c99df9d..d0387d7aeee 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
@@ -30,7 +30,6 @@ import com.yahoo.vespa.config.server.monitoring.Metrics;
import com.yahoo.vespa.config.server.provision.HostProvisionerProvider;
import com.yahoo.vespa.config.server.session.SessionPreparer;
import com.yahoo.vespa.config.server.session.SessionRepository;
-import com.yahoo.vespa.config.server.zookeeper.ConfigCurator;
import com.yahoo.vespa.curator.Curator;
import com.yahoo.vespa.curator.transaction.CuratorOperations;
import com.yahoo.vespa.curator.transaction.CuratorTransaction;
@@ -98,7 +97,6 @@ public class TenantRepository {
private final Locks<TenantName> tenantLocks = new Locks<>(1, TimeUnit.MINUTES);
private final HostRegistry hostRegistry;
private final TenantListener tenantListener;
- private final ConfigCurator configCurator;
private final Curator curator;
private final Metrics metrics;
private final MetricUpdater metricUpdater;
@@ -126,7 +124,7 @@ public class TenantRepository {
*/
@Inject
public TenantRepository(HostRegistry hostRegistry,
- ConfigCurator configCurator,
+ Curator curator,
Metrics metrics,
FlagSource flagSource,
SecretStore secretStore,
@@ -139,7 +137,7 @@ public class TenantRepository {
ReloadListener reloadListener,
TenantListener tenantListener) {
this(hostRegistry,
- configCurator,
+ curator,
metrics,
new StripedExecutor<>(),
new StripedExecutor<>(),
@@ -159,7 +157,7 @@ public class TenantRepository {
}
public TenantRepository(HostRegistry hostRegistry,
- ConfigCurator configCurator,
+ Curator curator,
Metrics metrics,
StripedExecutor<TenantName> zkApplicationWatcherExecutor ,
StripedExecutor<TenantName> zkSessionWatcherExecutor,
@@ -180,7 +178,7 @@ public class TenantRepository {
this.configserverConfig = configserverConfig;
this.bootstrapExecutor = Executors.newFixedThreadPool(configserverConfig.numParallelTenantLoaders(),
new DaemonThreadFactory("bootstrap-tenant-"));
- this.curator = configCurator.curator();
+ this.curator = curator;
this.metrics = metrics;
metricUpdater = metrics.getOrCreateMetricUpdater(Collections.emptyMap());
this.zkCacheExecutor = zkCacheExecutor;
@@ -197,7 +195,6 @@ public class TenantRepository {
this.configDefinitionRepo = configDefinitionRepo;
this.reloadListener = reloadListener;
this.tenantListener = tenantListener;
- this.configCurator = configCurator;
curator.framework().getConnectionStateListenable().addListener(this::stateChanged);
@@ -344,7 +341,7 @@ public class TenantRepository {
SessionRepository sessionRepository = new SessionRepository(tenantName,
applicationRepo,
sessionPreparer,
- configCurator,
+ curator,
metrics,
zkSessionWatcherExecutor,
permanentApplicationPackage,
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/zookeeper/InitializedCounter.java b/configserver/src/main/java/com/yahoo/vespa/config/server/zookeeper/InitializedCounter.java
index 216c9edd0d0..f36ec164a14 100644
--- a/configserver/src/main/java/com/yahoo/vespa/config/server/zookeeper/InitializedCounter.java
+++ b/configserver/src/main/java/com/yahoo/vespa/config/server/zookeeper/InitializedCounter.java
@@ -2,11 +2,15 @@
package com.yahoo.vespa.config.server.zookeeper;
import java.util.logging.Level;
+
+import com.yahoo.path.Path;
+import com.yahoo.vespa.curator.Curator;
import com.yahoo.vespa.curator.recipes.CuratorCounter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import java.util.logging.Logger;
/**
* A counter that sets its initial value to the number of apps in zookeeper if no counter value is set. Subclass
@@ -16,14 +20,14 @@ import java.util.List;
*/
public class InitializedCounter {
- private static final java.util.logging.Logger log = java.util.logging.Logger.getLogger(InitializedCounter.class.getName());
+ private static final Logger log = java.util.logging.Logger.getLogger(InitializedCounter.class.getName());
final CuratorCounter counter;
- private final String sessionsDirPath;
+ private final Path sessionsDirPath;
- InitializedCounter(ConfigCurator configCurator, String counterPath, String sessionsDirPath) {
+ InitializedCounter(Curator curator, Path counterPath, Path sessionsDirPath) {
this.sessionsDirPath = sessionsDirPath;
- this.counter = new CuratorCounter(configCurator.curator(), counterPath);
- initializeCounterValue(getLatestSessionId(configCurator, sessionsDirPath));
+ this.counter = new CuratorCounter(curator, counterPath);
+ initializeCounterValue(getLatestSessionId(curator, sessionsDirPath));
}
private void initializeCounterValue(Long latestSessionId) {
@@ -40,8 +44,8 @@ public class InitializedCounter {
*
* @return true, if an application exists, false otherwise
*/
- private static boolean applicationExists(ConfigCurator configCurator, String appsPath) {
- return configCurator.exists(appsPath);
+ private static boolean applicationExists(Curator curator, Path appsPath) {
+ return curator.exists(appsPath);
}
/**
@@ -50,12 +54,12 @@ public class InitializedCounter {
*
* @return generation of the latest deployed application
*/
- private static Long getLatestSessionId(ConfigCurator configCurator, String appsPath) {
- if (!applicationExists(configCurator, appsPath)) return null;
+ private static Long getLatestSessionId(Curator curator, Path appsPath) {
+ if (!applicationExists(curator, appsPath)) return null;
Long newestGeneration = null;
try {
- if (!getDeployedApplicationGenerations(configCurator, appsPath).isEmpty()) {
- newestGeneration = Collections.max(getDeployedApplicationGenerations(configCurator, appsPath));
+ if (!getDeployedApplicationGenerations(curator, appsPath).isEmpty()) {
+ newestGeneration = Collections.max(getDeployedApplicationGenerations(curator, appsPath));
}
} catch (Exception e) {
log.log(Level.WARNING, "Could not get newest application generation from Zookeeper");
@@ -63,10 +67,10 @@ public class InitializedCounter {
return newestGeneration;
}
- private static List<Long> getDeployedApplicationGenerations(ConfigCurator configCurator, String appsPath) {
+ private static List<Long> getDeployedApplicationGenerations(Curator curator, Path appsPath) {
ArrayList<Long> generations = new ArrayList<>();
try {
- List<String> stringGenerations = configCurator.getChildren(appsPath);
+ List<String> stringGenerations = curator.getChildren(appsPath);
if (stringGenerations != null && !(stringGenerations.isEmpty())) {
for (String s : stringGenerations) {
generations.add(Long.parseLong(s));
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/zookeeper/SessionCounter.java b/configserver/src/main/java/com/yahoo/vespa/config/server/zookeeper/SessionCounter.java
index 17d0f7e426e..c30743bbaea 100644
--- a/configserver/src/main/java/com/yahoo/vespa/config/server/zookeeper/SessionCounter.java
+++ b/configserver/src/main/java/com/yahoo/vespa/config/server/zookeeper/SessionCounter.java
@@ -3,6 +3,7 @@ package com.yahoo.vespa.config.server.zookeeper;
import com.yahoo.config.provision.TenantName;
import com.yahoo.vespa.config.server.tenant.TenantRepository;
+import com.yahoo.vespa.curator.Curator;
/**
* A counter keeping track of session ids in an atomic fashion across multiple config servers.
@@ -11,10 +12,10 @@ import com.yahoo.vespa.config.server.tenant.TenantRepository;
*/
public class SessionCounter extends InitializedCounter {
- public SessionCounter(ConfigCurator configCurator, TenantName tenantName) {
- super(configCurator,
- TenantRepository.getTenantPath(tenantName).append("sessionCounter").getAbsolute(),
- TenantRepository.getSessionsPath(tenantName).getAbsolute());
+ public SessionCounter(Curator curator, TenantName tenantName) {
+ super(curator,
+ TenantRepository.getTenantPath(tenantName).append("sessionCounter"),
+ TenantRepository.getSessionsPath(tenantName));
}
/**
diff --git a/configserver/src/main/resources/configserver-app/services.xml b/configserver/src/main/resources/configserver-app/services.xml
index d0e366b11a1..13a660221fd 100644
--- a/configserver/src/main/resources/configserver-app/services.xml
+++ b/configserver/src/main/resources/configserver-app/services.xml
@@ -30,7 +30,6 @@
<component id="com.yahoo.vespa.config.server.host.HostRegistry" bundle="configserver" />
<component id="com.yahoo.vespa.config.server.ApplicationRepository" bundle="configserver" />
<component id="com.yahoo.vespa.config.server.version.VersionState" bundle="configserver" />
- <component id="com.yahoo.vespa.config.server.zookeeper.ConfigCurator" bundle="configserver" />
<component id="com.yahoo.vespa.config.server.host.ConfigRequestHostLivenessTracker" bundle="configserver" />
<component id="com.yahoo.config.provision.Zone" bundle="config-provisioning" />
<component id="com.yahoo.vespa.config.server.application.ConfigConvergenceChecker" bundle="configserver" />
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 58b7385f4df..781b0b42b3b 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
@@ -21,6 +21,7 @@ import com.yahoo.config.provision.TenantName;
import com.yahoo.container.jdisc.HttpResponse;
import com.yahoo.io.IOUtils;
import com.yahoo.jdisc.Metric;
+import com.yahoo.path.Path;
import com.yahoo.test.ManualClock;
import com.yahoo.text.Utf8;
import com.yahoo.vespa.config.ConfigKey;
@@ -58,6 +59,7 @@ import org.junit.rules.TemporaryFolder;
import java.io.File;
import java.io.IOException;
+import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.time.Duration;
import java.time.Instant;
@@ -104,7 +106,6 @@ public class ApplicationRepositoryTest {
private OrchestratorMock orchestrator;
private TimeoutBudget timeoutBudget;
private Curator curator;
- private ConfigCurator configCurator;
@Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder();
@@ -115,7 +116,6 @@ public class ApplicationRepositoryTest {
@Before
public void setup() throws IOException {
curator = new MockCurator();
- configCurator = ConfigCurator.create(curator);
ConfigserverConfig configserverConfig = new ConfigserverConfig.Builder()
.payloadCompressionType(ConfigserverConfig.PayloadCompressionType.Enum.UNCOMPRESSED)
.configServerDBDir(temporaryFolder.newFolder().getAbsolutePath())
@@ -331,8 +331,8 @@ public class ApplicationRepositoryTest {
assertNotNull(applicationData.getApplicationId());
assertNotNull(sessionRepository.getLocalSession(sessionId));
assertNotNull(applicationRepository.getActiveSession(applicationId()));
- String sessionNode = sessionRepository.getSessionPath(sessionId).getAbsolute();
- assertTrue(configCurator.exists(sessionNode));
+ Path sessionNode = sessionRepository.getSessionPath(sessionId);
+ assertTrue(curator.exists(sessionNode));
TenantFileSystemDirs tenantFileSystemDirs = tenant.getApplicationRepo().getTenantFileSystemDirs();
File sessionFile = new File(tenantFileSystemDirs.sessionsPath(), String.valueOf(sessionId));
assertTrue(sessionFile.exists());
@@ -344,8 +344,8 @@ public class ApplicationRepositoryTest {
assertTrue(provisioner.removed());
assertEquals(tenant.getName(), provisioner.lastApplicationId().tenant());
assertEquals(applicationId(), provisioner.lastApplicationId());
- assertTrue(configCurator.exists(sessionNode));
- assertEquals(Session.Status.DELETE.name(), configCurator.getData(sessionNode + "/sessionState"));
+ assertTrue(curator.exists(sessionNode));
+ assertEquals(Session.Status.DELETE.name(), Utf8.toString(curator.getData(sessionNode.append("sessionState")).get()));
assertTrue(sessionFile.exists());
assertFalse(applicationRepository.delete(applicationId()));
@@ -395,8 +395,8 @@ public class ApplicationRepositoryTest {
assertTrue(applicationRepository.delete(applicationId()));
// Session should be in state DELETE
- String sessionNode = sessionRepository.getSessionPath(sessionId).getAbsolute();
- assertEquals(Session.Status.DELETE.name(), configCurator.getData(sessionNode + "/sessionState"));
+ Path sessionNode = sessionRepository.getSessionPath(sessionId);
+ assertEquals(Session.Status.DELETE.name(), Utf8.toString(curator.getData(sessionNode.append("sessionState")).get()));
assertNotNull(sessionRepository.getRemoteSession(sessionId)); // session still exists
assertNull(applicationRepository.getActiveSession(applicationId())); // but it is not active
try {
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 27e2d05a9fa..b5c1b4bd24b 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
@@ -87,7 +87,6 @@ public class SessionPreparerTest {
Instant.now(), Instant.now().plus(1, ChronoUnit.DAYS), SignatureAlgorithm.SHA512_WITH_ECDSA, BigInteger.valueOf(12345)).build();
private final InMemoryFlagSource flagSource = new InMemoryFlagSource();
private MockCurator curator;
- private ConfigCurator configCurator;
private SessionPreparer preparer;
private final MockSecretStore secretStore = new MockSecretStore();
private ConfigserverConfig configserverConfig;
@@ -101,7 +100,6 @@ public class SessionPreparerTest {
@Before
public void setUp() throws IOException {
curator = new MockCurator();
- configCurator = ConfigCurator.create(curator);
configserverConfig = new ConfigserverConfig.Builder()
.fileReferencesDir(folder.newFolder().getAbsolutePath())
.configServerDBDir(folder.newFolder().getAbsolutePath())
@@ -162,7 +160,7 @@ public class SessionPreparerTest {
.build(),
sessionId);
Path sessionPath = sessionPath(sessionId);
- assertFalse(configCurator.exists(sessionPath.append(ConfigCurator.USERAPP_ZK_SUBPATH).append("services.xml").getAbsolute()));
+ assertFalse(curator.exists(sessionPath.append(ConfigCurator.USERAPP_ZK_SUBPATH).append("services.xml")));
}
@Test
@@ -181,7 +179,7 @@ public class SessionPreparerTest {
@Test
public void require_that_application_is_prepared() throws Exception {
prepare(testApp);
- assertTrue(configCurator.exists(sessionPath(1).append(ConfigCurator.USERAPP_ZK_SUBPATH).append("services.xml").getAbsolute()));
+ assertTrue(curator.exists(sessionPath(1).append(ConfigCurator.USERAPP_ZK_SUBPATH).append("services.xml")));
}
@Test(expected = InvalidApplicationException.class)
@@ -234,7 +232,7 @@ public class SessionPreparerTest {
@Test
public void require_that_file_reference_of_application_package_is_written_to_zk() throws Exception {
prepare(testApp);
- assertTrue(configCurator.exists(sessionPath(1).append(APPLICATION_PACKAGE_REFERENCE_PATH).getAbsolute()));
+ assertTrue(curator.exists(sessionPath(1).append(APPLICATION_PACKAGE_REFERENCE_PATH)));
}
@Test
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 65c85c28a92..b653ca706aa 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
@@ -1,4 +1,4 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.config.server.session;
import com.yahoo.config.FileReference;
@@ -9,7 +9,6 @@ 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;
import com.yahoo.vespa.curator.mock.MockCurator;
@@ -22,6 +21,7 @@ import java.time.Instant;
import java.util.List;
import java.util.Optional;
+import static com.yahoo.vespa.config.server.zookeeper.ConfigCurator.SESSIONSTATE_ZK_SUBPATH;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
@@ -35,7 +35,6 @@ public class SessionZooKeeperClientTest {
private static final TenantName tenantName = TenantName.defaultName();
private Curator curator;
- private ConfigCurator configCurator;
@Rule
public ExpectedException expectedException = ExpectedException.none();
@@ -43,7 +42,6 @@ public class SessionZooKeeperClientTest {
@Before
public void setup() {
curator = new MockCurator();
- configCurator = ConfigCurator.create(curator);
curator.create(sessionsPath());
}
@@ -68,16 +66,16 @@ public class SessionZooKeeperClientTest {
int sessionId = 2;
SessionZooKeeperClient zkc = createSessionZKClient(sessionId);
zkc.writeStatus(Session.Status.NEW);
- String path = sessionPath(sessionId).append(ConfigCurator.SESSIONSTATE_ZK_SUBPATH).getAbsolute();
- assertTrue(configCurator.exists(path));
- assertThat(configCurator.getData(path), is("NEW"));
+ Path path = sessionPath(sessionId).append(SESSIONSTATE_ZK_SUBPATH);
+ assertTrue(curator.exists(path));
+ assertThat(Utf8.toString(curator.getData(path).get()), is("NEW"));
}
@Test
public void require_that_status_is_read_from_zk() {
int sessionId = 3;
SessionZooKeeperClient zkc = createSessionZKClient(sessionId);
- curator.set(sessionPath(sessionId).append(ConfigCurator.SESSIONSTATE_ZK_SUBPATH), Utf8.toBytes("PREPARE"));
+ curator.set(sessionPath(sessionId).append(SESSIONSTATE_ZK_SUBPATH), Utf8.toBytes("PREPARE"));
assertThat(zkc.readStatus(), is(Session.Status.PREPARE));
}
@@ -91,9 +89,9 @@ public class SessionZooKeeperClientTest {
int sessionId = 3;
SessionZooKeeperClient zkc = createSessionZKClient(sessionId);
zkc.writeApplicationId(id);
- String path = sessionPath(sessionId).append(SessionZooKeeperClient.APPLICATION_ID_PATH).getAbsolute();
- assertTrue(configCurator.exists(path));
- assertThat(configCurator.getData(path), is(id.serializedForm()));
+ Path path = sessionPath(sessionId).append(SessionZooKeeperClient.APPLICATION_ID_PATH);
+ assertTrue(curator.exists(path));
+ assertThat(Utf8.toString(curator.getData(path).get()), is(id.serializedForm()));
}
@Test
@@ -163,8 +161,8 @@ public class SessionZooKeeperClientTest {
private void assertApplicationIdParse(long sessionId, String idString, String expectedIdString) {
SessionZooKeeperClient zkc = createSessionZKClient(sessionId);
- String path = sessionPath(sessionId).append(SessionZooKeeperClient.APPLICATION_ID_PATH).getAbsolute();
- configCurator.putData(path, idString);
+ Path path = sessionPath(sessionId).append(SessionZooKeeperClient.APPLICATION_ID_PATH);
+ curator.set(path, Utf8.toBytes(idString));
ApplicationId applicationId = zkc.readApplicationId().get();
assertThat(applicationId.serializedForm(), is(expectedIdString));
}
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 464b3d1ab64..e64d5999cc7 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
@@ -27,7 +27,6 @@ import com.yahoo.vespa.config.server.modelfactory.ModelFactoryRegistry;
import com.yahoo.vespa.config.server.monitoring.MetricUpdater;
import com.yahoo.vespa.config.server.monitoring.Metrics;
import com.yahoo.vespa.config.server.provision.HostProvisionerProvider;
-import com.yahoo.vespa.config.server.zookeeper.ConfigCurator;
import com.yahoo.vespa.curator.Curator;
import com.yahoo.vespa.curator.mock.MockCurator;
import com.yahoo.vespa.flags.InMemoryFlagSource;
@@ -208,7 +207,7 @@ public class TenantRepositoryTest {
public FailingDuringBootstrapTenantRepository(ConfigserverConfig configserverConfig) {
super(new HostRegistry(),
- ConfigCurator.create(new MockCurator()),
+ new MockCurator(),
Metrics.createTestMetrics(),
new StripedExecutor<>(new InThreadExecutorService()),
new StripedExecutor<>(new InThreadExecutorService()),
diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/tenant/TestTenantRepository.java b/configserver/src/test/java/com/yahoo/vespa/config/server/tenant/TestTenantRepository.java
index 687d58fd23b..6fa16ee819a 100644
--- a/configserver/src/test/java/com/yahoo/vespa/config/server/tenant/TestTenantRepository.java
+++ b/configserver/src/test/java/com/yahoo/vespa/config/server/tenant/TestTenantRepository.java
@@ -17,7 +17,6 @@ import com.yahoo.vespa.config.server.host.HostRegistry;
import com.yahoo.vespa.config.server.modelfactory.ModelFactoryRegistry;
import com.yahoo.vespa.config.server.monitoring.Metrics;
import com.yahoo.vespa.config.server.provision.HostProvisionerProvider;
-import com.yahoo.vespa.config.server.zookeeper.ConfigCurator;
import com.yahoo.vespa.curator.Curator;
import com.yahoo.vespa.curator.mock.MockCurator;
import com.yahoo.vespa.flags.FlagSource;
@@ -47,7 +46,7 @@ public class TestTenantRepository extends TenantRepository {
ReloadListener reloadListener,
TenantListener tenantListener) {
super(hostRegistry,
- ConfigCurator.create(curator),
+ curator,
metrics,
new StripedExecutor<>(new InThreadExecutorService()),
new StripedExecutor<>(new InThreadExecutorService()),
diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/zookeeper/ConfigCuratorTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/zookeeper/ConfigCuratorTest.java
deleted file mode 100644
index 9a8aec72564..00000000000
--- a/configserver/src/test/java/com/yahoo/vespa/config/server/zookeeper/ConfigCuratorTest.java
+++ /dev/null
@@ -1,243 +0,0 @@
-// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.vespa.config.server.zookeeper;
-
-import com.yahoo.text.Utf8;
-import com.yahoo.vespa.curator.mock.MockCurator;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-
-import static org.junit.Assert.*;
-
-/**
- * Tests the ZKFacade using a curator mock.
- *
- * @author hmusum
- */
-public class ConfigCuratorTest {
-
- private final String defKey1 = "attributes";
-
- private final String payload1 = "attribute[5]\n" +
- "attribute[0].name Popularity\n" +
- "attribute[0].datatype string\n" +
- "attribute[0].collectiontype single\n" +
- "attribute[0].removeifzero false\n" +
- "attribute[0].createifnonexistent false\n" +
- "attribute[0].loadtype \"always\"\n" +
- "attribute[0].uniqueonly false\n" +
- "attribute[0].sparse false\n" +
- "attribute[0].noupdate false\n" +
- "attribute[0].fastsearch false\n" +
- "attribute[0].fastaggregate false\n" +
- "attribute[0].fastersearch false\n" +
- "attribute[1].name atA\n" +
- "attribute[1].datatype string\n" +
- "attribute[1].collectiontype weightedset\n" +
- "attribute[1].removeifzero false\n" +
- "attribute[1].createifnonexistent false\n" +
- "attribute[1].loadtype \"always\"\n" +
- "attribute[1].uniqueonly false\n" +
- "attribute[1].sparse false\n" +
- "attribute[1].noupdate false\n" +
- "attribute[1].fastsearch true\n" +
- "attribute[1].fastaggregate false\n" +
- "attribute[1].fastersearch false\n" +
- "attribute[2].name default_fieldlength\n" +
- "attribute[2].datatype uint32\n" +
- "attribute[2].collectiontype single\n" +
- "attribute[2].removeifzero false\n" +
- "attribute[2].createifnonexistent false\n" +
- "attribute[2].loadtype \"always\"\n" +
- "attribute[2].uniqueonly false\n" +
- "attribute[2].sparse false\n" +
- "attribute[2].noupdate true\n" +
- "attribute[2].fastsearch false\n" +
- "attribute[2].fastaggregate false\n" +
- "attribute[2].fastersearch false\n" +
- "attribute[3].name default_literal_fieldlength\n" +
- "attribute[3].datatype uint32\n" +
- "attribute[3].collectiontype single\n" +
- "attribute[3].removeifzero false\n" +
- "attribute[3].createifnonexistent false\n" +
- "attribute[3].loadtype \"always\"\n" +
- "attribute[3].uniqueonly false\n" +
- "attribute[3].sparse false\n" +
- "attribute[3].noupdate true\n" +
- "attribute[3].fastsearch false\n" +
- "attribute[3].fastaggregate false\n" +
- "attribute[3].fastersearch false\n" +
- "attribute[4].name artist_fieldlength\n" +
- "attribute[4].datatype uint32\n" +
- "attribute[4].collectiontype single\n" +
- "attribute[4].removeifzero false\n" +
- "attribute[4].createifnonexistent false\n" +
- "attribute[4].loadtype \"always\"\n" +
- "attribute[4].uniqueonly false\n" +
- "attribute[4].sparse false\n" +
- "attribute[4].noupdate true\n" +
- "attribute[4].fastsearch false\n" +
- "attribute[4].fastaggregate false\n" +
- "attribute[4].fastersearch false\n";
-
- private final String payload3 = "attribute[5]\n" +
- "attribute[0].name Popularity\n" +
- "attribute[0].datatype String\n" +
- "attribute[0].collectiontype single\n" +
- "attribute[0].removeifzero false\n" +
- "attribute[0].createifnonexistent false\n" +
- "attribute[0].loadtype \"always\"\n" +
- "attribute[0].uniqueonly false\n" +
- "attribute[0].sparse false\n" +
- "attribute[0].noupdate false\n" +
- "attribute[0].fastsearch false\n" +
- "attribute[0].fastaggregate false\n" +
- "attribute[0].fastersearch false\n" +
- "attribute[1].name atA\n" +
- "attribute[1].datatype string\n" +
- "attribute[1].collectiontype weightedset\n" +
- "attribute[1].removeifzero false\n" +
- "attribute[1].createifnonexistent false\n" +
- "attribute[1].loadtype \"always\"\n" +
- "attribute[1].uniqueonly false\n" +
- "attribute[1].sparse false\n" +
- "attribute[1].noupdate false\n" +
- "attribute[1].fastsearch true\n" +
- "attribute[1].fastaggregate false\n" +
- "attribute[1].fastersearch false\n" +
- "attribute[2].name default_fieldlength\n" +
- "attribute[2].datatype uint32\n" +
- "attribute[2].collectiontype single\n" +
- "attribute[2].removeifzero false\n" +
- "attribute[2].createifnonexistent false\n" +
- "attribute[2].loadtype \"always\"\n" +
- "attribute[2].uniqueonly false\n" +
- "attribute[2].sparse false\n" +
- "attribute[2].noupdate true\n" +
- "attribute[2].fastsearch false\n" +
- "attribute[2].fastaggregate false\n" +
- "attribute[2].fastersearch false\n" +
- "attribute[3].name default_literal_fieldlength\n" +
- "attribute[3].datatype uint32\n" +
- "attribute[3].collectiontype single\n" +
- "attribute[3].removeifzero false\n" +
- "attribute[3].createifnonexistent false\n" +
- "attribute[3].loadtype \"always\"\n" +
- "attribute[3].uniqueonly false\n" +
- "attribute[3].sparse false\n" +
- "attribute[3].noupdate true\n" +
- "attribute[3].fastsearch false\n" +
- "attribute[3].fastaggregate false\n" +
- "attribute[3].fastersearch false\n" +
- "attribute[4].name artist_fieldlength\n" +
- "attribute[4].datatype uint32\n" +
- "attribute[4].collectiontype single\n" +
- "attribute[4].removeifzero false\n" +
- "attribute[4].createifnonexistent false\n" +
- "attribute[4].loadtype \"always\"\n" +
- "attribute[4].uniqueonly false\n" +
- "attribute[4].sparse false\n" +
- "attribute[4].noupdate true\n" +
- "attribute[4].fastsearch false\n" +
- "attribute[4].fastaggregate false\n" +
- "attribute[4].fastersearch false\n";
-
- private void initAndClearZK(ConfigCurator zkIf) {
- zkIf.initAndClear(ConfigCurator.DEFCONFIGS_ZK_SUBPATH);
- zkIf.initAndClear(ConfigCurator.USERAPP_ZK_SUBPATH);
- }
-
- private ConfigCurator deployApp() {
- ConfigCurator zkIf = create();
- initAndClearZK(zkIf);
- zkIf.putData(ConfigCurator.DEFCONFIGS_ZK_SUBPATH, defKey1, payload1);
- // zkIf.putData(ConfigCurator.USERCONFIGS_ZK_SUBPATH, cfgKey1, payload3);
- String partitionsDef = "version=7\\n" +
- "dataset[].id int\\n" +
- "dataset[].partbits int default=6";
- zkIf.putData(ConfigCurator.DEFCONFIGS_ZK_SUBPATH, "partitions", partitionsDef);
- String partitionsUser = "dataset[0].partbits 8\\n";
- // zkIf.putData(ConfigCurator.USERCONFIGS_ZK_SUBPATH, "partitions", partitionsUser);
- return zkIf;
- }
-
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
-
- @Test
- public void testZKInterface() {
- ConfigCurator zkIf = create();
- zkIf.putData("", "test", "foo");
- zkIf.putData("/test", "me", "bar");
- zkIf.putData("", "test;me;now,then", "baz");
- assertEquals(zkIf.getData("", "test"), "foo");
- assertEquals(zkIf.getData("/test", "me"), "bar");
- assertEquals(zkIf.getData("", "test;me;now,then"), "baz");
- }
-
- @Test
- public void testNonExistingPath() {
- ConfigCurator configCurator = create();
-
- expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage("Cannot read data from path /non-existing, it does not exist");
- configCurator.getData("/non-existing");
- }
-
- @Test
- public void testWatcher() {
- ConfigCurator zkIf = create();
-
- zkIf.putData("", "test", "foo");
- String data = zkIf.getData("/test");
- assertEquals(data, "foo");
- zkIf.putData("", "/test", "bar");
- data = zkIf.getData("/test");
- assertEquals(data, "bar");
-
- zkIf.getChildren("/");
- zkIf.putData("", "test2", "foo2");
- }
-
- private ConfigCurator create() {
- return ConfigCurator.create(new MockCurator());
- }
-
- @Test
- public void testGetDeployedData() {
- ConfigCurator zkIf = deployApp();
- assertEquals(zkIf.getData(ConfigCurator.DEFCONFIGS_ZK_SUBPATH, defKey1), payload1);
- }
-
- @Test
- public void testEmptyData() {
- ConfigCurator zkIf = create();
- zkIf.createNode("/empty", "data");
- assertEquals("", zkIf.getData("/empty", "data"));
- }
-
- @Test
- public void testRecursiveDelete() {
- ConfigCurator configCurator = create();
- configCurator.putData("/foo", Utf8.toBytes("sadsdfsdfsdfsdf"));
- configCurator.putData("/foo/bar", Utf8.toBytes("dsfsdffds"));
- configCurator.putData("/foo/baz",
- Utf8.toBytes("sdf\u00F8l ksdfl skdflsk dflsdkfd welkr3k lkr e4kt4 54l4l353k l534klk3lk4l33k5l 353l4k l43k l4k"));
- configCurator.putData("/foo/bar/dill", Utf8.toBytes("sdfsfe 23 42 3 3 2342"));
- configCurator.putData("/foo", Utf8.toBytes("sdcfsdfsdf"));
- configCurator.putData("/foo", Utf8.toBytes("sdcfsd sdfdffsdf"));
- configCurator.deleteRecurse("/foo");
- assertFalse(configCurator.exists("/foo"));
- assertFalse(configCurator.exists("/foo/bar"));
- assertFalse(configCurator.exists("/foo/bar/dill"));
- assertFalse(configCurator.exists("/foo/bar/baz"));
- try {
- configCurator.getChildren("/foo");
- fail("Got children from nonexisting ZK path");
- } catch (RuntimeException e) {
- assertTrue(e.getCause().getMessage().matches(".*NoNode.*"));
- }
- configCurator.deleteRecurse("/nonexisting");
- }
-
-}
diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/zookeeper/InitializedCounterTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/zookeeper/InitializedCounterTest.java
index f745e023126..656e81a4c2f 100644
--- a/configserver/src/test/java/com/yahoo/vespa/config/server/zookeeper/InitializedCounterTest.java
+++ b/configserver/src/test/java/com/yahoo/vespa/config/server/zookeeper/InitializedCounterTest.java
@@ -1,6 +1,8 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.config.server.zookeeper;
+import com.yahoo.path.Path;
+import com.yahoo.vespa.curator.Curator;
import com.yahoo.vespa.curator.mock.MockCurator;
import org.junit.Test;
@@ -14,12 +16,12 @@ public class InitializedCounterTest {
@Test
public void requireThatCounterIsInitializedFromNumberOfSessions() {
- ConfigCurator configCurator = ConfigCurator.create(new MockCurator());
- configCurator.createNode("/sessions");
- configCurator.createNode("/sessions/1");
- configCurator.createNode("/sessions/2");
+ Curator curator = new MockCurator();
+ curator.create(Path.fromString("/sessions"));
+ curator.create(Path.fromString("/sessions/1"));
+ curator.create(Path.fromString("/sessions/2"));
- InitializedCounter counter = new InitializedCounter(configCurator, "/counter", "/sessions");
+ InitializedCounter counter = new InitializedCounter(curator, Path.fromString("/counter"), Path.fromString("/sessions"));
assertThat(counter.counter.get(), is(2L));
}
diff --git a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/status/HostInfosCache.java b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/status/HostInfosCache.java
index 7ee65ebcd0b..467ee90176d 100644
--- a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/status/HostInfosCache.java
+++ b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/status/HostInfosCache.java
@@ -1,6 +1,7 @@
-// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.orchestrator.status;
+import com.yahoo.path.Path;
import com.yahoo.vespa.applicationmodel.ApplicationInstanceReference;
import com.yahoo.vespa.applicationmodel.HostName;
import com.yahoo.vespa.curator.Curator;
@@ -15,7 +16,7 @@ import java.util.concurrent.atomic.AtomicLong;
* @author hakonhall
*/
public class HostInfosCache implements HostInfosService {
- final static String HOST_STATUS_CACHE_COUNTER_PATH = "/vespa/host-status-service-cache-counter";
+ final static Path HOST_STATUS_CACHE_COUNTER_PATH = Path.fromString("/vespa/host-status-service-cache-counter");
private final CuratorCounter counter;
private final HostInfosService wrappedService;
diff --git a/zkfacade/src/main/java/com/yahoo/vespa/curator/recipes/CuratorCounter.java b/zkfacade/src/main/java/com/yahoo/vespa/curator/recipes/CuratorCounter.java
index dd49b2595a4..2167b45bc02 100644
--- a/zkfacade/src/main/java/com/yahoo/vespa/curator/recipes/CuratorCounter.java
+++ b/zkfacade/src/main/java/com/yahoo/vespa/curator/recipes/CuratorCounter.java
@@ -1,6 +1,7 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.curator.recipes;
+import com.yahoo.path.Path;
import com.yahoo.vespa.curator.Curator;
import org.apache.curator.framework.recipes.atomic.AtomicValue;
import org.apache.curator.framework.recipes.atomic.DistributedAtomicLong;
@@ -9,15 +10,14 @@ import org.apache.curator.framework.recipes.atomic.DistributedAtomicLong;
* A distributed atomic counter.
*
* @author Ulf Lilleengen
- * @since 5.1
*/
public class CuratorCounter {
private final DistributedAtomicLong counter;
- private final String counterPath;
+ private final Path counterPath;
- public CuratorCounter(Curator curator, String counterPath) {
- this.counter = curator.createAtomicCounter(counterPath);
+ public CuratorCounter(Curator curator, Path counterPath) {
+ this.counter = curator.createAtomicCounter(counterPath.getAbsolute());
this.counterPath = counterPath;
}
diff --git a/zkfacade/src/test/java/com/yahoo/vespa/curator/CuratorCounterTest.java b/zkfacade/src/test/java/com/yahoo/vespa/curator/CuratorCounterTest.java
index 6b85953a1ff..3d465c6b71f 100644
--- a/zkfacade/src/test/java/com/yahoo/vespa/curator/CuratorCounterTest.java
+++ b/zkfacade/src/test/java/com/yahoo/vespa/curator/CuratorCounterTest.java
@@ -1,9 +1,10 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.curator;
import com.yahoo.vespa.curator.mock.MockCurator;
import org.apache.curator.framework.recipes.atomic.DistributedAtomicLong;
import org.junit.Test;
+
import static org.junit.Assert.assertEquals;
/**
@@ -14,9 +15,9 @@ public class CuratorCounterTest {
@Test
public void testCounter() throws Exception {
DistributedAtomicLong counter = new MockCurator().createAtomicCounter("/mycounter");
- counter.initialize(4l);
- assertEquals(4l, counter.get().postValue().longValue());
- assertEquals(5l, counter.increment().postValue().longValue());
+ counter.initialize(4L);
+ assertEquals(4L, counter.get().postValue().longValue());
+ assertEquals(5L, counter.increment().postValue().longValue());
}
}