Skip to content

Commit

Permalink
resolve #1578 | update curator to latest version (#1592)
Browse files Browse the repository at this point in the history
* resolve #1578 | update curator to latest version

This change also removes the `Reaper` class that is no longer required since v2.9
see: https://www.javadoc.io/doc/org.apache.curator/curator-recipes/4.2.0/org/apache/curator/framework/recipes/locks/Reaper.html

* Update hermes-common/src/main/java/pl/allegro/tech/hermes/common/admin/zookeeper/ZookeeperAdminTool.java

Co-authored-by: Mateusz <[email protected]>

Co-authored-by: Mateusz <[email protected]>
Co-authored-by: Piotr Rżysko <[email protected]>
  • Loading branch information
3 people authored Nov 17, 2022
1 parent aa2cebf commit 13e3704
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 35 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ allprojects {
jackson : '2.11.4',
jersey : '2.35',
jetty : '9.4.19.v20190610',
curator : '2.12.0',
curator : '5.3.0',
dropwizard_metrics: '4.1.0',
micrometer_metrics: '1.2.1',
wiremock : '2.27.2',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

public interface AdminTool {

void start() throws AdminToolStartupException;

void retransmit(SubscriptionName subscriptionName);

enum Operations {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.recipes.locks.Reaper;
import org.apache.zookeeper.CreateMode;
import pl.allegro.tech.hermes.api.SubscriptionName;
import pl.allegro.tech.hermes.common.admin.AdminTool;
import pl.allegro.tech.hermes.common.admin.AdminToolStartupException;
import pl.allegro.tech.hermes.common.exception.RetransmissionException;
import pl.allegro.tech.hermes.infrastructure.zookeeper.ZookeeperPaths;

Expand All @@ -17,22 +15,12 @@ public class ZookeeperAdminTool implements AdminTool {
private final ZookeeperPaths zookeeperPaths;
private final CuratorFramework curatorFramework;
private final ObjectMapper objectMapper;
private final Reaper reaper;

public ZookeeperAdminTool(ZookeeperPaths zookeeperPaths, CuratorFramework curatorFramework,
ObjectMapper objectMapper, int reapingInterval) {
ObjectMapper objectMapper) {
this.zookeeperPaths = zookeeperPaths;
this.curatorFramework = curatorFramework;
this.objectMapper = objectMapper;
this.reaper = new Reaper(curatorFramework, reapingInterval);
}

public void start() throws AdminToolStartupException {
try {
this.reaper.start();
} catch (Exception ex) {
throw new AdminToolStartupException(ex);
}
}

@Override
Expand All @@ -47,10 +35,8 @@ public void retransmit(SubscriptionName subscriptionName) {
private void executeAdminOperation(SubscriptionName subscriptionName, String name) throws Exception {
String path = zookeeperPaths.adminOperationPath(name);

String createdPath = curatorFramework.create()
curatorFramework.create()
.withMode(CreateMode.EPHEMERAL_SEQUENTIAL)
.forPath(path, objectMapper.writeValueAsBytes(subscriptionName));

reaper.addPath(createdPath);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public class StorageClustersProperties {
private String connectionString = "localhost:2181";
private int sessionTimeout = 10000;
private int connectTimeout = 1000;
private int adminReaperInterval = 180000;
private List<StorageProperties> clusters = new ArrayList<>();

@NestedConfigurationProperty
Expand Down Expand Up @@ -131,11 +130,4 @@ public void setConnectTimeout(int connectTimeout) {
this.connectTimeout = connectTimeout;
}

public int getAdminReaperInterval() {
return adminReaperInterval;
}

public void setAdminReaperInterval(int adminReaperInterval) {
this.adminReaperInterval = adminReaperInterval;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ ZookeeperGroupRepositoryFactory zookeeperGroupRepositoryFactory() {
@Bean(initMethod = "start")
ZookeeperRepositoryManager repositoryManager(ZookeeperGroupRepositoryFactory zookeeperGroupRepositoryFactory) {
return new ZookeeperRepositoryManager(clientManager(), dcNameProvider(), objectMapper,
zookeeperPaths(), zookeeperGroupRepositoryFactory, storageClustersProperties.getAdminReaperInterval());
zookeeperPaths(), zookeeperGroupRepositoryFactory);
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,17 @@ public class ZookeeperRepositoryManager implements RepositoryManager {
private final Map<String, ReadinessRepository> readinessRepositoriesByDc = new HashMap<>();
private final Map<String, OfflineRetransmissionRepository> offlineRetransmissionRepositoriesByDc = new HashMap<>();
private final ZookeeperGroupRepositoryFactory zookeeperGroupRepositoryFactory;
private final Integer adminReaperInterval;

public ZookeeperRepositoryManager(ZookeeperClientManager clientManager,
DatacenterNameProvider datacenterNameProvider,
ObjectMapper mapper,
ZookeeperPaths paths,
ZookeeperGroupRepositoryFactory zookeeperGroupRepositoryFactory,
Integer adminReaperInterval) {
ZookeeperGroupRepositoryFactory zookeeperGroupRepositoryFactory) {
this.datacenterNameProvider = datacenterNameProvider;
this.mapper = mapper;
this.paths = paths;
this.clientManager = clientManager;
this.zookeeperGroupRepositoryFactory = zookeeperGroupRepositoryFactory;
this.adminReaperInterval = adminReaperInterval;
initRepositoryTypeMap();
}

Expand Down Expand Up @@ -115,7 +112,7 @@ public void start() {
UndeliveredMessageLog undeliveredMessageLog = new ZookeeperUndeliveredMessageLog(zookeeper, paths, mapper);
undeliveredMessageLogsByDc.put(dcName, undeliveredMessageLog);

AdminTool adminTool = new ZookeeperAdminTool(paths, client.getCuratorFramework(), mapper, adminReaperInterval);
AdminTool adminTool = new ZookeeperAdminTool(paths, client.getCuratorFramework(), mapper);
adminToolByDc.put(dcName, adminTool);

ReadinessRepository readinessRepository = new ZookeeperDatacenterReadinessRepository(zookeeper, mapper, paths);
Expand All @@ -124,8 +121,6 @@ public void start() {
ZookeeperOfflineRetransmissionRepository offlineRetransmissionRepository =
new ZookeeperOfflineRetransmissionRepository(zookeeper, mapper, paths);
offlineRetransmissionRepositoriesByDc.put(dcName, offlineRetransmissionRepository);

adminTool.start();
}
}

Expand Down

0 comments on commit 13e3704

Please sign in to comment.