Pochatkin commented on code in PR #2121:
URL: https://github.com/apache/ignite-3/pull/2121#discussion_r1218081042


##########
modules/compute/src/main/java/org/apache/ignite/internal/compute/JobClassLoaderFactory.java:
##########
@@ -71,22 +67,48 @@ public JobClassLoaderFactory(Function<String, Version> 
detectLastUnitVersion, Ig
      * @param units The units of the job.
      * @return The class loader.
      */
-    public JobClassLoader createClassLoader(List<DeploymentUnit> units) {
-        URL[] classPath = units.stream()
-                .map(this::constructPath)
-                .flatMap(JobClassLoaderFactory::collectClasspath)
-                .toArray(URL[]::new);
-
-        if (LOG.isDebugEnabled()) {
-            LOG.debug("Classpath for job: " + Arrays.toString(classPath));
-        }
+    public CompletableFuture<JobClassLoader> 
createClassLoader(List<DeploymentUnit> units) {
+        Map<Integer, Stream<URL>> map = new TreeMap<>();
+
+        CompletableFuture[] futures = IntStream.range(0, units.size())
+                .mapToObj(id -> {
+                    return constructPath(units.get(id))
+                            .thenApply(JobClassLoaderFactory::collectClasspath)
+                            .thenApply(stream -> map.put(id, stream));
+                }).toArray(CompletableFuture[]::new);
+
+        return CompletableFuture.allOf(futures).thenApply(v -> {
+            return map.values().stream()
+                    .flatMap(Function.identity())
+                    .toArray(URL[]::new);
+        })
+                .thenApply(it -> new JobClassLoader(it, 
getClass().getClassLoader()))
+                .whenComplete((cl, err) -> {
+                    if (err != null) {
+                        LOG.error("Failed to create class loader", err);
+                    } else {
+                        System.out.println(map);
+                        System.out.println("Created class loader: " + cl);
+                        LOG.debug("Created class loader: {}", cl);
+                    }
+                });
+    }
 
-        return new JobClassLoader(classPath, getClass().getClassLoader());
+    private CompletableFuture<Path> constructPath(DeploymentUnit unit) {
+        return CompletableFuture.completedFuture(unit.version())
+                .thenCompose(version -> {
+                    if (version == Version.LATEST) {
+                        return lastVersion(unit.name());
+                    } else {
+                        return CompletableFuture.completedFuture(version);
+                    }
+                })
+                .thenCompose(version -> deployment.path(unit.name(), version));
     }
 
-    private Path constructPath(DeploymentUnit unit) {
-        Version version = unit.version() == Version.LATEST ? 
detectLastUnitVersion.apply(unit.name()) : unit.version();
-        return deployment.path(unit.name(), version);
+    private CompletableFuture<Version> lastVersion(String name) {
+        return deployment.versionsAsync(name)
+                .thenApply(versions -> 
versions.stream().max(Version::compareTo).orElseThrow());

Review Comment:
   Or else throw NoSuchElementException. Do you expect it?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to