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


##########
modules/code-deployment/src/main/java/org/apache/ignite/internal/deployunit/DeploymentUnitAccessor.java:
##########
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.deployunit;
+
+import java.util.concurrent.CompletableFuture;
+import org.apache.ignite.compute.DeploymentUnit;
+import org.apache.ignite.compute.version.Version;
+
+/**
+ * Interface for accessing deployment units.
+ */
+public interface DeploymentUnitAccessor {
+    /**
+     * Detects the latest version of the deployment unit.
+     */
+    CompletableFuture<Version> detectLatestDeployedVersion(String id);
+
+    /**
+     * Acquires the deployment unit. Each call to this method must be matched 
with a call to {@link DisposableDeploymentUnit#release()}.
+     */
+    DisposableDeploymentUnit acquire(DeploymentUnit unit);
+
+    boolean isAcquired(DeploymentUnit unit);

Review Comment:
   Javadocs



##########
modules/code-deployment/src/main/java/org/apache/ignite/internal/deployunit/DeploymentUnitAccessorImpl.java:
##########
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.deployunit;
+
+import static java.util.concurrent.CompletableFuture.completedFuture;
+import static 
org.apache.ignite.internal.rest.api.deployment.DeploymentStatus.DEPLOYED;
+import static 
org.apache.ignite.internal.rest.api.deployment.DeploymentStatus.UPLOADING;
+
+import java.util.concurrent.CompletableFuture;
+import org.apache.ignite.compute.DeploymentUnit;
+import org.apache.ignite.compute.version.Version;
+import 
org.apache.ignite.internal.deployunit.exception.DeploymentUnitNotFoundException;
+import 
org.apache.ignite.internal.deployunit.exception.DeploymentUnitUnavailableException;
+import org.apache.ignite.internal.logger.IgniteLogger;
+import org.apache.ignite.internal.logger.Loggers;
+import org.apache.ignite.internal.util.RefCountedObjectPool;
+
+/**
+ * Implementation of {@link DeploymentUnitAccessor}.
+ */
+public class DeploymentUnitAccessorImpl implements DeploymentUnitAccessor {
+

Review Comment:
   Remove empty line



##########
modules/code-deployment/src/main/java/org/apache/ignite/internal/deployunit/DeploymentUnitAccessor.java:
##########
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.deployunit;
+
+import java.util.concurrent.CompletableFuture;
+import org.apache.ignite.compute.DeploymentUnit;
+import org.apache.ignite.compute.version.Version;
+
+/**
+ * Interface for accessing deployment units.
+ */
+public interface DeploymentUnitAccessor {
+    /**
+     * Detects the latest version of the deployment unit.
+     */
+    CompletableFuture<Version> detectLatestDeployedVersion(String id);
+
+    /**
+     * Acquires the deployment unit. Each call to this method must be matched 
with a call to {@link DisposableDeploymentUnit#release()}.
+     */
+    DisposableDeploymentUnit acquire(DeploymentUnit unit);
+
+    boolean isAcquired(DeploymentUnit unit);
+
+    CompletableFuture<Void> onDemandDeploy(DeploymentUnit unit);

Review Comment:
   On demand deploy shouldn't be here



##########
modules/code-deployment/src/main/java/org/apache/ignite/internal/deployunit/DeploymentUnitAccessorImpl.java:
##########
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.deployunit;
+
+import static java.util.concurrent.CompletableFuture.completedFuture;
+import static 
org.apache.ignite.internal.rest.api.deployment.DeploymentStatus.DEPLOYED;
+import static 
org.apache.ignite.internal.rest.api.deployment.DeploymentStatus.UPLOADING;
+
+import java.util.concurrent.CompletableFuture;
+import org.apache.ignite.compute.DeploymentUnit;
+import org.apache.ignite.compute.version.Version;
+import 
org.apache.ignite.internal.deployunit.exception.DeploymentUnitNotFoundException;
+import 
org.apache.ignite.internal.deployunit.exception.DeploymentUnitUnavailableException;
+import org.apache.ignite.internal.logger.IgniteLogger;
+import org.apache.ignite.internal.logger.Loggers;
+import org.apache.ignite.internal.util.RefCountedObjectPool;
+
+/**
+ * Implementation of {@link DeploymentUnitAccessor}.
+ */
+public class DeploymentUnitAccessorImpl implements DeploymentUnitAccessor {
+
+    private static final IgniteLogger LOG = 
Loggers.forClass(DeploymentUnitAccessorImpl.class);
+    private final RefCountedObjectPool<DeploymentUnit, 
DisposableDeploymentUnit> pool = new RefCountedObjectPool<>();

Review Comment:
   Add extra line space



##########
modules/code-deployment/src/main/java/org/apache/ignite/internal/deployunit/exception/DeploymentUnitNotFoundException.java:
##########
@@ -17,19 +17,63 @@
 
 package org.apache.ignite.internal.deployunit.exception;
 
+import org.apache.ignite.compute.version.Version;
 import org.apache.ignite.lang.ErrorGroups.CodeDeployment;
 import org.apache.ignite.lang.IgniteException;
+import org.jetbrains.annotations.Nullable;
 
 /**
  * Throws when trying to access information about unit which doesn't exist.
  */
 public class DeploymentUnitNotFoundException extends IgniteException {
+
+    /**
+     * Unit id.
+     */
+    private final String id;
+
+    /**
+     * Unit version.
+     */
+    private final Version version;
+
+    /**
+     * Constructor.
+     *
+     * @param id Unit id.
+     */
+    public DeploymentUnitNotFoundException(String id) {
+        super(CodeDeployment.UNIT_NOT_FOUND_ERR, message(id, null));

Review Comment:
   Please use this(id, null)



##########
modules/code-deployment/src/main/java/org/apache/ignite/internal/deployunit/DisposableDeploymentUnit.java:
##########
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.deployunit;
+
+import java.nio.file.Path;
+import java.util.Objects;
+import org.apache.ignite.compute.DeploymentUnit;
+
+/**
+ * Disposable deployment unit.
+ */
+public class DisposableDeploymentUnit {
+    private final DeploymentUnit unit;
+
+    private final Path path;
+
+    private final Runnable release;
+
+    /**
+     * Constructor.
+     *
+     * @param unit Deployment unit.
+     * @param path Path to the deployment unit.
+     * @param release Release.
+     */
+    public DisposableDeploymentUnit(DeploymentUnit unit, Path path, Runnable 
release) {
+        this.unit = unit;
+        this.path = path;
+        this.release = release;
+    }
+
+    /**
+     * Returns deployment unit.
+     *
+     * @return Deployment unit.
+     */
+    public DeploymentUnit unit() {
+        return unit;
+    }
+
+    /**
+     * Returns path to the deployment unit.
+     *
+     * @return Path to the deployment unit.
+     */
+    public Path path() {
+        return path;
+    }
+
+    /**
+     * Releases resources of the unit. This method should be called when the 
unit is not needed any more.
+     */
+    public void release() {
+        release.run();
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) {
+            return true;
+        }
+        if (o == null || getClass() != o.getClass()) {
+            return false;
+        }
+        DisposableDeploymentUnit that = (DisposableDeploymentUnit) o;
+        return Objects.equals(unit, that.unit);
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(unit);
+    }
+
+    @Override
+    public String toString() {
+        return "DisposableDeploymentUnit{"
+                + "unit=" + unit
+                + ", release=" + release + '}';

Review Comment:
   What the reason to add Runnable to string?



##########
modules/compute/src/main/java/org/apache/ignite/internal/compute/loader/JobContextManager.java:
##########
@@ -0,0 +1,134 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.compute.loader;
+
+import java.lang.reflect.Array;
+import java.util.Arrays;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+import org.apache.ignite.compute.DeploymentUnit;
+import org.apache.ignite.compute.version.Version;
+import org.apache.ignite.internal.deployunit.DeploymentUnitAccessor;
+import org.apache.ignite.internal.deployunit.DisposableDeploymentUnit;
+import org.apache.ignite.internal.logger.IgniteLogger;
+import org.apache.ignite.internal.logger.Loggers;
+import org.apache.ignite.internal.util.RefCountedObjectPool;
+
+/**
+ * Manages job context.
+ */
+public class JobContextManager {
+    private static final IgniteLogger LOG = 
Loggers.forClass(JobContextManager.class);
+
+    private final RefCountedObjectPool<List<DeploymentUnit>, JobClassLoader> 
classLoaderPool = new RefCountedObjectPool<>();
+
+    /**
+     * The deployer service.
+     */
+    private final DeploymentUnitAccessor deploymentUnitAccessor;
+
+    /**
+     * The class loader factory.
+     */
+    private final JobClassLoaderFactory classLoaderFactory;
+
+    /**
+     * Constructor.
+     *
+     * @param deploymentUnitAccessor The deployer service.
+     * @param classLoaderFactory The class loader factory.
+     */
+    public JobContextManager(DeploymentUnitAccessor deploymentUnitAccessor, 
JobClassLoaderFactory classLoaderFactory) {
+        this.deploymentUnitAccessor = deploymentUnitAccessor;
+        this.classLoaderFactory = classLoaderFactory;
+    }
+
+    /**
+     * Acquires a class loader for the given deployment units.
+     *
+     * @param units The deployment units.
+     * @return The class loader.
+     */
+    public CompletableFuture<JobContext> 
acquireClassLoader(List<DeploymentUnit> units) {
+        return normalizeVersions(units)
+                .thenCompose(normalizedUnits -> 
onDemandDeploy(normalizedUnits).thenApply(v -> normalizedUnits))
+                .thenApply(normalizedUnits -> 
classLoaderPool.acquire(normalizedUnits, this::createClassLoader))
+                .whenComplete((ctx, err) -> {
+                    if (err != null) {
+                        LOG.error("Failed to acquire class loader for units: " 
+ units, err);
+                    } else {
+                        LOG.debug("Acquired class loader for units: " + units);
+                    }
+                })

Review Comment:
   May you please move these logs to place where it throws and remove this 
whenComplete handler



-- 
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: notifications-unsubscr...@ignite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to