Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move to version 1.1.0 mandating java 11 #149

Merged
merged 3 commits into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ This cluster orchestration library is not meant to be used for writing productio
this library fail without even an attempt at managing nor recovering the problem. This is a reasonable limitation for the scope
of this library which is to ease writing multi-machine tests.

=== Required java version

Starting with version 1.1.0, Java 11 is necessary. Version 1.0.3 is the last one compatible with Java 8.

=== Configuring a JVM cluster

Creating a `ClusterConfiguration` instance is the first step to creating a cluster of JVMs.
Expand Down
43 changes: 25 additions & 18 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>org.mortbay.jetty.orchestrator</groupId>
<artifactId>jetty-cluster-orchestrator</artifactId>
<version>1.0.5-SNAPSHOT</version>
<version>1.1.0-SNAPSHOT</version>
<name>Jetty :: JVM Cluster Orchestrator</name>
<url>https://github.com/jetty-project/jetty-cluster-orchestrator</url>
<description>
Expand Down Expand Up @@ -63,7 +63,7 @@
<configuration>
<rules>
<requireJavaVersion>
<version>[1.8,)</version>
<version>[${maven.compiler.source},)</version>
</requireJavaVersion>
<requireMavenVersion>
<version>[3.5,)</version>
Expand All @@ -78,7 +78,14 @@
<artifactId>license-maven-plugin</artifactId>
<inherited>false</inherited>
<configuration>
<header>header-template.txt</header>
<licenseSets>
<licenseSet>
<header>header-template.txt</header>
<includes>
<include>**/*.java</include>
</includes>
</licenseSet>
</licenseSets>
<failIfMissing>true</failIfMissing>
<aggregate>true</aggregate>
<strictCheck>true</strictCheck>
Expand All @@ -88,9 +95,6 @@
<mapping>
<java>DOUBLESLASH_STYLE</java>
</mapping>
<includes>
<include>**/*.java</include>
</includes>
</configuration>
<executions>
<execution>
Expand Down Expand Up @@ -187,7 +191,7 @@
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.5.0</version>
<configuration>
<source>8</source>
<source>${maven.compiler.source}</source>
<additionalOptions>
<additionalOption>-html5</additionalOption>
</additionalOptions>
Expand Down Expand Up @@ -279,13 +283,6 @@
<version>0.35.0</version>
</dependency>

<dependency>
<groupId>org.zeroturnaround</groupId>
<artifactId>zt-process-killer</artifactId>
<version>1.10</version>
<scope>test</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
Expand Down Expand Up @@ -316,16 +313,26 @@
<developer>
<id>lorban</id>
<name>Ludovic Orban</name>
<email>lorban@webtide.com</email>
<organization>Webtide</organization>
<email>lorban@bitronix.be</email>
<organization>Webtide, LLC</organization>
<organizationUrl>https://webtide.com</organizationUrl>
<timezone>1</timezone>
</developer>
<developer>
<id>olamy</id>
<email>olamy@webtide.com</email>
<name>Olivier Lamy</name>
<organization>Webtide</organization>
<email>oliver.lamy@gmail.com</email>
<organization>Webtide, LLC</organization>
<organizationUrl>https://webtide.com</organizationUrl>
<timezone>Australia/Brisbane</timezone>
</developer>
<developer>
<id>joakime</id>
<name>Joakim Erdfelt</name>
<email>joakim.erdfelt@gmail.com</email>
<organization>Webtide, LLC</organization>
<organizationUrl>https://webtide.com</organizationUrl>
<timezone>-6</timezone>
</developer>
</developers>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ public ClusterTools(CuratorFramework curator, GlobalNodeId globalNodeId)
this.globalNodeId = globalNodeId;
}

public String getNodeId()
{
return globalNodeId.getNodeId();
}

public Barrier barrier(String name, int count)
{
return new Barrier(curator, globalNodeId, name, count);
Expand Down
46 changes: 37 additions & 9 deletions src/main/java/org/mortbay/jetty/orchestrator/NodeArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
import java.net.URI;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
Expand Down Expand Up @@ -74,36 +74,64 @@ public NodeArrayFuture executeOn(String id, NodeJob nodeJob)
if (node == null)
throw new IllegalArgumentException("No such node with ID " + id);

List<CompletableFuture<Object>> futures = new ArrayList<>();
Map<String, CompletableFuture<Object>> futures = new HashMap<>();
try
{
CompletableFuture<Object> future = node.rpcClient.callAsync(new ExecuteNodeJobCommand(nodeJob));
futures.add(future);
futures.put(id, future);
}
catch (Exception e)
{
CompletableFuture<Object> future = new CompletableFuture<>();
future.completeExceptionally(e);
futures.add(future);
futures.put(id, future);
}
return new NodeArrayFuture(futures);
}

public NodeArrayFuture executeOn(Set<String> ids, NodeJob nodeJob)
{
Set<String> missingIds = new HashSet<>(nodes.keySet());
ids.forEach(missingIds::remove);
if (!missingIds.isEmpty())
throw new IllegalArgumentException("No such node with ID " + missingIds);

Map<String, CompletableFuture<Object>> futures = new HashMap<>();
for (String id : ids)
{
Node node = nodes.get(id);
try
{
CompletableFuture<Object> future = node.rpcClient.callAsync(new ExecuteNodeJobCommand(nodeJob));
futures.put(id, future);
}
catch (Exception e)
{
CompletableFuture<Object> future = new CompletableFuture<>();
future.completeExceptionally(e);
futures.put(id, future);
}
}
return new NodeArrayFuture(futures);
}

public NodeArrayFuture executeOnAll(NodeJob nodeJob)
{
List<CompletableFuture<Object>> futures = new ArrayList<>();
for (Node node : nodes.values())
Map<String, CompletableFuture<Object>> futures = new HashMap<>();
for (Map.Entry<String, Node> entry : nodes.entrySet())
{
String nodeId = entry.getKey();
Node node = entry.getValue();
try
{
CompletableFuture<Object> future = node.rpcClient.callAsync(new ExecuteNodeJobCommand(nodeJob));
futures.add(future);
futures.put(nodeId, future);
}
catch (Exception e)
{
CompletableFuture<Object> future = new CompletableFuture<>();
future.completeExceptionally(e);
futures.add(future);
futures.put(nodeId, future);
}
}
return new NodeArrayFuture(futures);
Expand Down
36 changes: 30 additions & 6 deletions src/main/java/org/mortbay/jetty/orchestrator/NodeArrayFuture.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,27 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.stream.Collectors;

public class NodeArrayFuture
{
private final List<CompletableFuture<Object>> futures;
private final Map<String, CompletableFuture<Object>> futures;

NodeArrayFuture(List<CompletableFuture<Object>> futures)
NodeArrayFuture(Map<String, CompletableFuture<Object>> futures)
{
this.futures = futures;
}

public void cancel(boolean mayInterruptIfRunning)
{
futures.forEach(f -> f.cancel(mayInterruptIfRunning));
futures.forEach((id, f) -> f.cancel(mayInterruptIfRunning));
}

public void get(long timeout, TimeUnit unit) throws ExecutionException, TimeoutException
Expand All @@ -42,7 +45,7 @@ public void get(long timeout, TimeUnit unit) throws ExecutionException, TimeoutE

TimeoutException timeoutException = null;
List<Throwable> exceptions = new ArrayList<>();
for (CompletableFuture<Object> future : futures)
for (CompletableFuture<Object> future : futures.values())
{
long begin = System.nanoTime();
try
Expand Down Expand Up @@ -102,17 +105,38 @@ public void get() throws ExecutionException
}
}

public Set<String> getAllNodeIds()
{
return futures.keySet();
}

public Set<String> getDoneNodeIds()
{
return futures.entrySet().stream()
.filter(e -> e.getValue().isDone())
.map(Map.Entry::getKey)
.collect(Collectors.toSet());
}

public Set<String> getNotDoneNodeIds()
{
return futures.entrySet().stream()
.filter(e -> !e.getValue().isDone())
.map(Map.Entry::getKey)
.collect(Collectors.toSet());
}

public boolean isAllDone()
{
return futures.stream()
return futures.values().stream()
.map(Future::isDone)
.reduce((b1, b2) -> b1 && b2)
.orElse(true);
}

public boolean isAnyDone()
{
return futures.stream()
return futures.values().stream()
.map(Future::isDone)
.reduce((b1, b2) -> b1 || b2)
.orElse(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ InputStream newInputStream(NodePath path, OpenOption... options) throws IOExcept
}
}

@SuppressWarnings("unchecked")
<A extends BasicFileAttributes> A readAttributes(NodePath path, Class<A> type, LinkOption... options) throws IOException
{
if (!type.equals(BasicFileAttributes.class) && !type.equals(NodeFileAttributes.class))
Expand Down
Loading