PakhomovAlexander commented on code in PR #2099: URL: https://github.com/apache/ignite-3/pull/2099#discussion_r1205185662
########## modules/compute/src/main/java/org/apache/ignite/internal/compute/JobClassLoaderFactory.java: ########## @@ -0,0 +1,115 @@ +/* + * 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; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.nio.file.FileVisitResult; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.SimpleFileVisitor; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import org.apache.ignite.lang.ErrorGroups.Common; +import org.apache.ignite.lang.IgniteException; + +/** + * Creates a class loader for a job. + */ +public class JobClassLoaderFactory { + + /** + * Directory for components. + */ + private final Path componentsDir; + + /** + * Constructor. + * + * @param componentsDir The directory for components. + */ + public JobClassLoaderFactory(Path componentsDir) { + this.componentsDir = componentsDir; + } + + /** + * Create a class loader for the specified units. + * + * @param units The units of the job. + * @return The class loader. + */ + public JobClassLoader createClassLoader(List<String> units) { + if (units.isEmpty()) { + throw new IllegalArgumentException("No units specified"); + } + + URL[] classPath = units.stream() + .map(componentsDir::resolve) + .map(JobClassLoaderFactory::constructClasspath) + .flatMap(Arrays::stream) + .toArray(URL[]::new); + + return new JobClassLoader(classPath, getClass().getClassLoader()); + } + + private static URL[] constructClasspath(Path componentDir) { + if (Files.notExists(componentDir)) { + throw new IllegalArgumentException("Component does not exist: " + componentDir); Review Comment: Why do you use "component" instead of "unit" or "deployment unit"? ########## modules/compute/src/test/java/org/apache/ignite/internal/compute/JobClassLoaderTest.java: ########## @@ -0,0 +1,65 @@ +/* + * 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; + +import static org.junit.jupiter.api.Assertions.assertSame; + +import java.net.URL; +import java.util.stream.Stream; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; +import org.mockito.junit.jupiter.MockitoExtension; + +@ExtendWith(MockitoExtension.class) Review Comment: Where do you use Mockito? -- 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]
