This is an automated email from the ASF dual-hosted git repository.
apkhmv pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/ignite-3.git
The following commit(s) were added to refs/heads/main by this push:
new 281b112b8e IGNITE-23165 Improve error message when deployment unit is
not provided (#4480)
281b112b8e is described below
commit 281b112b8e8448e25db957173f6cab183284875c
Author: Vadim Pakhnushev <[email protected]>
AuthorDate: Tue Oct 1 16:48:08 2024 +0300
IGNITE-23165 Improve error message when deployment unit is not provided
(#4480)
---
modules/client/build.gradle | 1 +
.../org/apache/ignite/client/fakes/FakeCompute.java | 5 ++++-
.../internal/compute/ItComputeTestStandalone.java | 21 ++++++++++++++++++++-
.../ignite/internal/compute/ComputeUtils.java | 9 +++++++--
4 files changed, 32 insertions(+), 4 deletions(-)
diff --git a/modules/client/build.gradle b/modules/client/build.gradle
index a6349dcd15..c193b24a54 100644
--- a/modules/client/build.gradle
+++ b/modules/client/build.gradle
@@ -56,6 +56,7 @@ dependencies {
testImplementation project(':ignite-placement-driver-api')
testImplementation project(':ignite-cluster-management')
testImplementation project(':ignite-compute')
+ testImplementation project(':ignite-code-deployment')
testImplementation project(':ignite-eventlog')
testImplementation(testFixtures(project(':ignite-api')))
testImplementation(testFixtures(project(':ignite-core')))
diff --git
a/modules/client/src/test/java/org/apache/ignite/client/fakes/FakeCompute.java
b/modules/client/src/test/java/org/apache/ignite/client/fakes/FakeCompute.java
index a37b44c249..9c8921722f 100644
---
a/modules/client/src/test/java/org/apache/ignite/client/fakes/FakeCompute.java
+++
b/modules/client/src/test/java/org/apache/ignite/client/fakes/FakeCompute.java
@@ -24,6 +24,7 @@ import static org.apache.ignite.compute.JobStatus.FAILED;
import static
org.apache.ignite.internal.util.CompletableFutures.nullCompletedFuture;
import static
org.apache.ignite.internal.util.CompletableFutures.trueCompletedFuture;
+import java.net.URL;
import java.time.Instant;
import java.util.Collection;
import java.util.List;
@@ -59,6 +60,7 @@ import
org.apache.ignite.internal.compute.JobExecutionContextImpl;
import org.apache.ignite.internal.compute.JobStateImpl;
import org.apache.ignite.internal.compute.MarshallerProvider;
import org.apache.ignite.internal.compute.TaskStateImpl;
+import org.apache.ignite.internal.compute.loader.JobClassLoader;
import org.apache.ignite.internal.table.TableViewInternal;
import org.apache.ignite.internal.util.ExceptionUtils;
import org.apache.ignite.marshalling.Marshaller;
@@ -114,7 +116,8 @@ public class FakeCompute implements IgniteComputeInternal {
}
if (jobClassName.startsWith("org.apache.ignite")) {
- Class<ComputeJob<Object, R>> jobClass =
ComputeUtils.jobClass(this.getClass().getClassLoader(), jobClassName);
+ JobClassLoader jobClassLoader = new JobClassLoader(List.of(), new
URL[]{}, this.getClass().getClassLoader());
+ Class<ComputeJob<Object, R>> jobClass =
ComputeUtils.jobClass(jobClassLoader, jobClassName);
ComputeJob<Object, R> job = ComputeUtils.instantiateJob(jobClass);
CompletableFuture<R> jobFut = job.executeAsync(
new JobExecutionContextImpl(ignite, new AtomicBoolean(),
this.getClass().getClassLoader()), args);
diff --git
a/modules/compute/src/integrationTest/java/org/apache/ignite/internal/compute/ItComputeTestStandalone.java
b/modules/compute/src/integrationTest/java/org/apache/ignite/internal/compute/ItComputeTestStandalone.java
index c076c459f1..0839fac81f 100644
---
a/modules/compute/src/integrationTest/java/org/apache/ignite/internal/compute/ItComputeTestStandalone.java
+++
b/modules/compute/src/integrationTest/java/org/apache/ignite/internal/compute/ItComputeTestStandalone.java
@@ -35,12 +35,14 @@ import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
import org.apache.ignite.Ignite;
+import org.apache.ignite.compute.ComputeException;
import org.apache.ignite.compute.JobDescriptor;
import org.apache.ignite.compute.JobTarget;
import org.apache.ignite.deployment.DeploymentUnit;
import org.apache.ignite.deployment.version.Version;
import org.apache.ignite.internal.app.IgniteImpl;
import org.apache.ignite.internal.deployunit.NodesToDeploy;
+import org.apache.ignite.internal.testframework.IgniteTestUtils;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
@@ -49,7 +51,7 @@ import org.junit.jupiter.api.Test;
/**
* Integration tests for Compute functionality in standalone Ignite node.
*/
-@SuppressWarnings("resource")
+@SuppressWarnings({"resource", "ThrowableNotThrown"})
class ItComputeTestStandalone extends ItComputeBaseTest {
private final DeploymentUnit unit = new DeploymentUnit("jobs",
Version.parseVersion("1.0.0"));
@@ -120,6 +122,23 @@ class ItComputeTestStandalone extends ItComputeBaseTest {
);
}
+ @Test
+ void executeJobWithoutUnit() throws IOException {
+ IgniteImpl entryNode = unwrapIgniteImpl(node(0));
+
+ deployJar(entryNode, "unit", Version.parseVersion("1.0.0"),
"ignite-unit-test-job1-1.0-SNAPSHOT.jar");
+
+ IgniteTestUtils.assertThrows(
+ ComputeException.class,
+ () -> entryNode.compute().execute(
+ JobTarget.node(clusterNode(entryNode)),
+
JobDescriptor.builder("org.apache.ignite.internal.compute.UnitJob").build(),
+ null
+ ),
+ "Cannot load job class by name
'org.apache.ignite.internal.compute.UnitJob'."
+ + " Deployment units list is empty.");
+ }
+
@Test
void executesJobWithLatestUnitVersion() throws IOException {
List<DeploymentUnit> jobUnits = List.of(new
DeploymentUnit("latest-unit", Version.LATEST));
diff --git
a/modules/compute/src/main/java/org/apache/ignite/internal/compute/ComputeUtils.java
b/modules/compute/src/main/java/org/apache/ignite/internal/compute/ComputeUtils.java
index 226e9f82e2..b1d5e6aa38 100644
---
a/modules/compute/src/main/java/org/apache/ignite/internal/compute/ComputeUtils.java
+++
b/modules/compute/src/main/java/org/apache/ignite/internal/compute/ComputeUtils.java
@@ -36,6 +36,7 @@ import org.apache.ignite.compute.JobState;
import org.apache.ignite.compute.task.MapReduceTask;
import org.apache.ignite.deployment.DeploymentUnit;
import org.apache.ignite.deployment.version.Version;
+import org.apache.ignite.internal.compute.loader.JobClassLoader;
import org.apache.ignite.internal.compute.message.DeploymentUnitMsg;
import org.apache.ignite.internal.compute.message.ExecuteResponse;
import org.apache.ignite.internal.compute.message.JobCancelResponse;
@@ -90,11 +91,15 @@ public class ComputeUtils {
* @param <R> Compute job return type.
* @return Compute job class.
*/
- public static <T, R> Class<ComputeJob<T, R>> jobClass(ClassLoader
jobClassLoader, String jobClassName) {
+ public static <T, R> Class<ComputeJob<T, R>> jobClass(JobClassLoader
jobClassLoader, String jobClassName) {
try {
return (Class<ComputeJob<T, R>>) Class.forName(jobClassName, true,
jobClassLoader);
} catch (ClassNotFoundException e) {
- throw new ComputeException(CLASS_INITIALIZATION_ERR, "Cannot load
job class by name '" + jobClassName + "'", e);
+ String message = "Cannot load job class by name '" + jobClassName
+ "'";
+ if (jobClassLoader.units().isEmpty()) {
+ throw new ComputeException(CLASS_INITIALIZATION_ERR, message +
". Deployment units list is empty.", e);
+ }
+ throw new ComputeException(CLASS_INITIALIZATION_ERR, message, e);
}
}