Skip to content

Commit

Permalink
Target Java 17 (#65)
Browse files Browse the repository at this point in the history
* Target java 17
* Bump easymock version
* Update ehcache dependency
* Updates ehcache cache creation
* Avoid adding null items to the cache
* Bump commons-lang3 dependency
* Fix imports to use correct package
* Disable selenium tests
* Update ci java version
* Update Docker container to java 17
---------

Co-authored-by: Daniel Bernstein <[email protected]>
  • Loading branch information
mikejritter and dbernstein authored Oct 27, 2023
1 parent da9859a commit 55fe0d2
Show file tree
Hide file tree
Showing 14 changed files with 93 additions and 57 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ jobs:
uses: actions/checkout@v2

# https://github.com/actions/setup-java
- name: Install JDK 11
- name: Install JDK 17
uses: actions/setup-java@v2
with:
java-version: 11
java-version: 17
distribution: adopt

# https://github.com/actions/cache
Expand All @@ -47,7 +47,7 @@ jobs:
uses: actions/setup-java@v2
if: github.ref == 'refs/heads/develop' && github.event_name == 'push'
with:
java-version: 11
java-version: 17
distribution: adopt
server-id: sonatype-snapshots # Value of the distributionManagement/repository/id field of the pom.xml
server-username: SONATYPE_USERNAME # env variable for sonatype username
Expand All @@ -59,7 +59,7 @@ jobs:
uses: actions/setup-java@v2
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
with:
java-version: 11
java-version: 17
distribution: adopt
server-id: sonatype-releases # Value of the distributionManagement/repository/id field of the pom.xml
server-username: SONATYPE_USERNAME # env variable for sonatype username
Expand Down
2 changes: 1 addition & 1 deletion common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
</dependency>

<dependency>
<groupId>net.sf.ehcache</groupId>
<groupId>org.ehcache</groupId>
<artifactId>ehcache</artifactId>
</dependency>

Expand Down
49 changes: 38 additions & 11 deletions common/src/main/java/org/duracloud/mill/util/Iterators.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,19 @@
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.function.Supplier;

import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;
import org.ehcache.Cache;
import org.ehcache.CacheManager;
import org.ehcache.config.CacheConfiguration;
import org.ehcache.config.builders.CacheConfigurationBuilder;
import org.ehcache.config.builders.CacheManagerBuilder;
import org.ehcache.config.builders.ResourcePoolsBuilder;
import org.ehcache.config.units.MemoryUnit;
import org.ehcache.expiry.ExpiryPolicy;

/**
* Static utility methods pertaining to Iterator instances.
Expand All @@ -25,8 +32,29 @@
*/
public class Iterators {

private static final CacheManager cacheManager =
CacheManager.newInstance(Iterators.class.getResource("/ehcache.xml"));
private static final CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder().build(true);
private static final CacheConfiguration<String, String> cacheConfig =
CacheConfigurationBuilder.newCacheConfigurationBuilder(
String.class, String.class,
ResourcePoolsBuilder.newResourcePoolsBuilder().heap(150, MemoryUnit.MB))
.withExpiry(new ExpiryPolicy<>() {
@Override
public Duration getExpiryForCreation(String s, String s2) {
return Duration.ofSeconds(86400);
}

@Override
public Duration getExpiryForAccess(String s, Supplier<? extends String> supplier) {
return Duration.ofSeconds(86400);
}

@Override
public Duration getExpiryForUpdate(String s, Supplier<? extends String> supplier,
String s2) {
return Duration.ofSeconds(86400);
}
})
.build();

private Iterators() {
// Ensures no instances are made of this class, as there are only static members.
Expand All @@ -45,12 +73,11 @@ private Iterators() {
public static Iterator<String> difference(Iterator<String> iterA, Iterator<String> iterB)
throws IOException {
String cacheName = "compare-" + System.currentTimeMillis();
cacheManager.addCache(cacheName);
Cache cache = cacheManager.getCache(cacheName);
Cache<String, String> cache = cacheManager.createCache(cacheName, cacheConfig);

while (iterB.hasNext()) {
String item = iterB.next();
cache.put(new Element(item, null));
cache.put(item, "");
}

int diffCnt = 0;
Expand All @@ -60,7 +87,7 @@ public static Iterator<String> difference(Iterator<String> iterA, Iterator<Strin
FileWriter fileWriter = new FileWriter(diffFile);
while (iterA.hasNext()) {
String item = iterA.next();
if (!cache.isKeyInCache(item)) {
if (!cache.containsKey(item)) {
// write item to file
fileWriter.write(item + "\n");
diffCnt++;
Expand All @@ -72,8 +99,8 @@ public static Iterator<String> difference(Iterator<String> iterA, Iterator<Strin
fileWriter.close();

// All done with the cache, clean it up
cache.removeAll();
cacheManager.removeCache(cache.getName());
cache.clear();
cacheManager.removeCache(cacheName);

if (diffCnt > 0) {
return new FileLineIterator(diffFile);
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM ghcr.io/phusion/baseimage:jammy-1.0.1

RUN apt-get update && apt-get install openjdk-11-jre-headless wget vim telnet -y
RUN apt-get update && apt-get install openjdk-17-jre-headless wget vim telnet -y
RUN mkdir -p /opt/app

RUN wget -q https://collectors.sumologic.com/rest/download/deb/64 -O SumoCollector.deb && \
Expand Down
2 changes: 1 addition & 1 deletion looping-storagestats-taskproducer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
</dependency>

<dependency>
<groupId>net.sf.ehcache</groupId>
<groupId>org.ehcache</groupId>
<artifactId>ehcache</artifactId>
</dependency>
</dependencies>
Expand Down
2 changes: 1 addition & 1 deletion loopingbittaskproducer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
</dependency>

<dependency>
<groupId>net.sf.ehcache</groupId>
<groupId>org.ehcache</groupId>
<artifactId>ehcache</artifactId>
</dependency>
</dependencies>
Expand Down
2 changes: 1 addition & 1 deletion loopingduptaskproducer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
</dependency>

<dependency>
<groupId>net.sf.ehcache</groupId>
<groupId>org.ehcache</groupId>
<artifactId>ehcache</artifactId>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@
package org.duracloud.mill.ltp.dup;

import java.io.File;
import java.nio.file.Path;
import java.util.List;

import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.config.CacheConfiguration;
import net.sf.ehcache.config.PersistenceConfiguration;
import org.duracloud.common.model.EmailerType;
import org.duracloud.common.queue.QueueType;
import org.duracloud.common.queue.TaskQueue;
Expand All @@ -39,6 +36,11 @@
import org.duracloud.mill.util.PropertyDefinition;
import org.duracloud.mill.util.PropertyDefinitionListBuilder;
import org.duracloud.mill.util.PropertyVerifier;
import org.ehcache.Cache;
import org.ehcache.PersistentCacheManager;
import org.ehcache.config.builders.CacheConfigurationBuilder;
import org.ehcache.config.builders.CacheManagerBuilder;
import org.ehcache.config.builders.ResourcePoolsBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -140,14 +142,15 @@ protected LoopingTaskProducer buildTaskProducer() {
taskQueue = new SQSTaskQueue(getTaskQueueName(ConfigConstants.QUEUE_NAME_DUP_LOW_PRIORITY));
}

CacheManager cacheManager = CacheManager.create();
CacheConfiguration cacheConfig = new CacheConfiguration();
cacheConfig.setName("contentIdCache");
cacheConfig.addPersistence(
new PersistenceConfiguration().strategy(PersistenceConfiguration.Strategy.LOCALTEMPSWAP));
cacheConfig.setEternal(true);
Cache cache = new Cache(cacheConfig);
cacheManager.addCache(cache);
final Path tmpDir = Path.of(System.getProperty("java.io.tmpdir"));
PersistentCacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder()
.with(CacheManagerBuilder.persistence(tmpDir.toFile()))
.withCache("contentIdCache",
CacheConfigurationBuilder.newCacheConfigurationBuilder(
String.class, String.class,
ResourcePoolsBuilder.newResourcePoolsBuilder()))
.build(true);
Cache<String, String> cache = cacheManager.getCache("contentIdCache", String.class, String.class);

String stateFilePath = new File(config.getWorkDirectoryPath(), "dup-producer-state.json").getAbsolutePath();
StateManager<DuplicationMorsel> stateManager = new StateManager<>(stateFilePath, DuplicationMorsel.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
import java.util.Set;
import java.util.concurrent.PriorityBlockingQueue;

import net.sf.ehcache.Cache;
import net.sf.ehcache.Element;
import org.duracloud.common.queue.TaskQueue;
import org.duracloud.common.queue.task.Task;
import org.duracloud.mill.common.storageprovider.StorageProviderFactory;
Expand All @@ -38,6 +36,7 @@
import org.duracloud.mill.task.DuplicationTask;
import org.duracloud.storage.error.NotFoundException;
import org.duracloud.storage.provider.StorageProvider;
import org.ehcache.Cache;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -50,13 +49,13 @@ public class LoopingDuplicationTaskProducer extends LoopingTaskProducer<Duplicat

private DuplicationPolicyManager policyManager;

private Cache cache;
private Cache<String, String> cache;

public LoopingDuplicationTaskProducer(CredentialsRepo credentialsRepo,
StorageProviderFactory storageProviderFactory,
DuplicationPolicyManager policyManager,
TaskQueue taskQueue,
Cache cache,
Cache<String, String> cache,
StateManager<DuplicationMorsel> state,
int maxTaskQueueSize,
Frequency frequency,
Expand All @@ -78,7 +77,7 @@ public LoopingDuplicationTaskProducer(CredentialsRepo credentialsRepo,
/**
* @return the cache
*/
private Cache getCache() {
private Cache<String, String> getCache() {
return cache;
}

Expand Down Expand Up @@ -224,12 +223,12 @@ private void addDuplicationTasksForContentNotInSource(String account,
DuplicationStorePolicy storePolicy,
StorageProvider sourceProvider,
StorageProvider destProvider) {
Cache cache = getCache();
Cache<String, String> cache = getCache();
try {
//load all source into ehcache
Iterator<String> sourceContentIds = sourceProvider.getSpaceContents(spaceId, null);
while (sourceContentIds.hasNext()) {
cache.put(new Element(sourceContentIds.next(), null));
cache.put(sourceContentIds.next(), "");
}
} catch (NotFoundException ex) {
log.info("space not found on source provider: account={}, spaceId={}, storeId={}",
Expand All @@ -253,7 +252,7 @@ private void addDuplicationTasksForContentNotInSource(String account,
while (destContentIds.hasNext()) {
String destContentId = destContentIds.next();
//if not in cache
if (!cache.isKeyInCache(destContentId)) {
if (!cache.containsKey(destContentId)) {
deletions.add(destContentId);
//periodically add deletions to prevent OOM
//in case that there are millions of content ids to delete
Expand All @@ -275,7 +274,7 @@ private void addDuplicationTasksForContentNotInSource(String account,
spaceId,
storePolicy.getSrcStoreId(),
storePolicy.getDestStoreId());
cache.removeAll();
cache.clear();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
import java.util.List;
import java.util.Set;

import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import org.duracloud.common.queue.TaskQueue;
import org.duracloud.common.queue.TimeoutException;
import org.duracloud.common.queue.local.LocalTaskQueue;
Expand All @@ -48,6 +46,11 @@
import org.easymock.EasyMockSupport;
import org.easymock.IAnswer;
import org.easymock.Mock;
import org.ehcache.Cache;
import org.ehcache.CacheManager;
import org.ehcache.config.builders.CacheConfigurationBuilder;
import org.ehcache.config.builders.CacheManagerBuilder;
import org.ehcache.config.builders.ResourcePoolsBuilder;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
Expand All @@ -71,7 +74,7 @@ public class LoopingDuplicationTaskProducerTest extends EasyMockSupport {
private StorageProvider sourceStore;
@Mock
private StorageProvider destStore;
private static Cache cache;
private static Cache<String, String> cache;
@Mock
private DuplicationPolicyManager policyManager;
@Mock
Expand Down Expand Up @@ -115,7 +118,7 @@ public void setUp() throws Exception {
@After
public void tearDown() throws Exception {
verifyAll();
cache.removeAll();
cache.clear();
}

/**
Expand Down Expand Up @@ -495,9 +498,11 @@ public Iterator<String> answer() throws Throwable {
*/
private void setupCache() {
if (cache == null) {
CacheManager cacheManager = CacheManager.getInstance();
cacheManager.addCache(CACHE_NAME);
cache = cacheManager.getCache(CACHE_NAME);
CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder().build(true);
cacheManager.createCache(CACHE_NAME,
CacheConfigurationBuilder.newCacheConfigurationBuilder(String.class, String.class,
ResourcePoolsBuilder.heap(10)));
cache = cacheManager.getCache(CACHE_NAME, String.class, String.class);
}
}

Expand Down
2 changes: 1 addition & 1 deletion loopingtaskproducer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
</dependency>

<dependency>
<groupId>net.sf.ehcache</groupId>
<groupId>org.ehcache</groupId>
<artifactId>ehcache</artifactId>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
*/
package org.duracloud.mill.ltp;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;

/**
* A definition of a bite-sized swath of content ids that can be nibbled by the
Expand Down
2 changes: 2 additions & 0 deletions policy-editor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
</executions>
</plugin>

<!-- Selenium needs to be updated for java 17
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>selenium-maven-plugin</artifactId>
Expand Down Expand Up @@ -114,6 +115,7 @@
</execution>
</executions>
</plugin>
-->
<!--
<plugin>
<groupId>org.codehaus.mojo</groupId>
Expand Down
Loading

0 comments on commit 55fe0d2

Please sign in to comment.