valepakh commented on code in PR #6556: URL: https://github.com/apache/ignite-3/pull/6556#discussion_r2325110720
########## modules/code-deployment/src/test/java/org/apache/ignite/internal/deployunit/StaticDeploymentUnitObserverTest.java: ########## @@ -0,0 +1,80 @@ +/* + * 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 org.apache.ignite.deployment.version.Version.parseVersion; +import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willBe; +import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsInAnyOrder; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.stream.Collectors; +import org.apache.ignite.deployment.version.Version; +import org.apache.ignite.internal.testframework.WorkDirectory; +import org.apache.ignite.internal.testframework.WorkDirectoryExtension; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +/** + * Test suite for {@link StaticDeploymentUnitObserver}. + */ +@ExtendWith(WorkDirectoryExtension.class) +public class StaticDeploymentUnitObserverTest { + private StaticDeploymentUnitObserver observer; + + private StubDeploymentUnitStore deploymentUnitStore; + + @WorkDirectory + private Path workDir; + + @BeforeEach + public void setup() { + deploymentUnitStore = new StubDeploymentUnitStore(); + this.observer = new StaticDeploymentUnitObserver(deploymentUnitStore, "node1", workDir); + } + + @Test + public void test() throws IOException { + Files.createDirectories(workDir.resolve("unit1").resolve("1.0.0")); + Files.createDirectories(workDir.resolve("unit1").resolve("1.0.1")); + Files.createDirectories(workDir.resolve("unit1").resolve("1.1.1")); + Files.createDirectories(workDir.resolve("unit2").resolve("1.0.0")); + Files.createDirectories(workDir.resolve("unit3").resolve("1.1.0")); + + assertThat(observer.observeAndRegisterStaticUnits(), willCompleteSuccessfully()); + + CompletableFuture<List<Version>> unit1Statuses = deploymentUnitStore.getNodeStatuses("node1", "unit1") + .thenApply(statuses -> statuses.stream().map(UnitStatus::version).collect(Collectors.toList())); Review Comment: Please extract this to method ########## modules/code-deployment/src/test/java/org/apache/ignite/internal/deployunit/StaticDeploymentUnitObserverTest.java: ########## @@ -0,0 +1,80 @@ +/* + * 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 org.apache.ignite.deployment.version.Version.parseVersion; +import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willBe; +import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsInAnyOrder; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.stream.Collectors; +import org.apache.ignite.deployment.version.Version; +import org.apache.ignite.internal.testframework.WorkDirectory; +import org.apache.ignite.internal.testframework.WorkDirectoryExtension; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +/** + * Test suite for {@link StaticDeploymentUnitObserver}. + */ +@ExtendWith(WorkDirectoryExtension.class) +public class StaticDeploymentUnitObserverTest { + private StaticDeploymentUnitObserver observer; + + private StubDeploymentUnitStore deploymentUnitStore; + + @WorkDirectory + private Path workDir; + + @BeforeEach + public void setup() { + deploymentUnitStore = new StubDeploymentUnitStore(); Review Comment: Maybe it's possible to use real unit store using `StandaloneMetaStorageManager`? Also the skipping functionality should be tested ########## modules/code-deployment/src/integrationTest/java/org/apache/ignite/internal/deployment/ItStaticDeploymentTest.java: ########## @@ -0,0 +1,80 @@ +/* + * 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.deployment; + +import static org.apache.ignite.deployment.version.Version.parseVersion; +import static org.apache.ignite.internal.TestWrappers.unwrapIgniteImpl; +import static org.hamcrest.MatcherAssert.assertThat; + +import java.io.IOException; +import java.nio.file.Path; +import java.util.concurrent.CompletableFuture; +import org.apache.ignite.internal.ClusterPerClassIntegrationTest; +import org.apache.ignite.internal.deployunit.DeploymentStatus; +import org.apache.ignite.internal.deployunit.IgniteDeployment; +import org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class ItStaticDeploymentTest extends ClusterPerClassIntegrationTest { + private DeployFiles files; + + @BeforeEach + public void generateDummy() { + files = new DeployFiles(WORK_DIR); + } + + @Override + protected boolean needInitializeCluster() { + return false; + } + + @Test + public void testStaticDeploy() throws IOException { + DeployFile smallFile = files.smallFile(); + DeployFile mediumFile = files.mediumFile(); + + Path node0WorkDir = CLUSTER.nodeWorkDir(0); + Path node1WorkDir = CLUSTER.nodeWorkDir(1); + Path node2WorkDir = CLUSTER.nodeWorkDir(2); + + DeployFiles.staticDeploy("unit1", parseVersion("1.0.0"), smallFile, node0WorkDir); Review Comment: Could use static import here ########## modules/code-deployment/src/integrationTest/java/org/apache/ignite/internal/deployment/ItStaticDeploymentTest.java: ########## @@ -0,0 +1,80 @@ +/* + * 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.deployment; + +import static org.apache.ignite.deployment.version.Version.parseVersion; +import static org.apache.ignite.internal.TestWrappers.unwrapIgniteImpl; +import static org.hamcrest.MatcherAssert.assertThat; + +import java.io.IOException; +import java.nio.file.Path; +import java.util.concurrent.CompletableFuture; +import org.apache.ignite.internal.ClusterPerClassIntegrationTest; +import org.apache.ignite.internal.deployunit.DeploymentStatus; +import org.apache.ignite.internal.deployunit.IgniteDeployment; +import org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class ItStaticDeploymentTest extends ClusterPerClassIntegrationTest { + private DeployFiles files; + + @BeforeEach + public void generateDummy() { + files = new DeployFiles(WORK_DIR); + } + + @Override + protected boolean needInitializeCluster() { + return false; + } + + @Test + public void testStaticDeploy() throws IOException { + DeployFile smallFile = files.smallFile(); + DeployFile mediumFile = files.mediumFile(); Review Comment: This variable is unused ########## modules/code-deployment/src/integrationTest/java/org/apache/ignite/internal/deployment/DeployFiles.java: ########## @@ -162,6 +162,16 @@ public static UnitStatuses buildStatus(String id, Unit... units) { return builder.build(); } + public static void staticDeploy(String id, Version version, DeployFile file, Path workDir) throws IOException { + Path deploymentRootFolder = workDir.resolve("deployment"); + Path unitFile = deploymentRootFolder.resolve(id).resolve(version.render()).resolve(file.file().getFileName().toString()); Review Comment: ```suggestion Path unitFile = deploymentRootFolder.resolve(id).resolve(version.render()).resolve(file.file().getFileName()); ``` ########## modules/code-deployment/src/integrationTest/java/org/apache/ignite/internal/deployment/ItStaticDeploymentTest.java: ########## @@ -0,0 +1,80 @@ +/* + * 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.deployment; + +import static org.apache.ignite.deployment.version.Version.parseVersion; +import static org.apache.ignite.internal.TestWrappers.unwrapIgniteImpl; +import static org.hamcrest.MatcherAssert.assertThat; + +import java.io.IOException; +import java.nio.file.Path; +import java.util.concurrent.CompletableFuture; +import org.apache.ignite.internal.ClusterPerClassIntegrationTest; +import org.apache.ignite.internal.deployunit.DeploymentStatus; +import org.apache.ignite.internal.deployunit.IgniteDeployment; +import org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class ItStaticDeploymentTest extends ClusterPerClassIntegrationTest { + private DeployFiles files; + + @BeforeEach + public void generateDummy() { + files = new DeployFiles(WORK_DIR); + } + + @Override + protected boolean needInitializeCluster() { + return false; + } + + @Test + public void testStaticDeploy() throws IOException { + DeployFile smallFile = files.smallFile(); + DeployFile mediumFile = files.mediumFile(); + + Path node0WorkDir = CLUSTER.nodeWorkDir(0); + Path node1WorkDir = CLUSTER.nodeWorkDir(1); + Path node2WorkDir = CLUSTER.nodeWorkDir(2); + + DeployFiles.staticDeploy("unit1", parseVersion("1.0.0"), smallFile, node0WorkDir); + + DeployFiles.staticDeploy("unit2", parseVersion("1.0.0"), smallFile, node0WorkDir); + DeployFiles.staticDeploy("unit2", parseVersion("1.0.0"), smallFile, node1WorkDir); + + DeployFiles.staticDeploy("unit3", parseVersion("1.0.0"), smallFile, node0WorkDir); + DeployFiles.staticDeploy("unit3", parseVersion("1.0.0"), smallFile, node1WorkDir); + DeployFiles.staticDeploy("unit3", parseVersion("1.0.0"), smallFile, node2WorkDir); + + DeployFiles.staticDeploy("unit1", parseVersion("1.1.0"), smallFile, node0WorkDir); + DeployFiles.staticDeploy("unit1", parseVersion("1.1.0"), smallFile, node1WorkDir); + + DeployFiles.staticDeploy("unit3", parseVersion("1.0.1"), smallFile, node2WorkDir); + + CLUSTER.startAndInit(3); + + IgniteDeployment node0 = unwrapIgniteImpl(CLUSTER.node(0)).deployment(); + IgniteDeployment node1 = unwrapIgniteImpl(CLUSTER.node(1)).deployment(); + IgniteDeployment node2 = unwrapIgniteImpl(CLUSTER.node(2)).deployment(); + + CompletableFuture<DeploymentStatus> unit1 = node0.nodeStatusAsync("unit1", parseVersion("1.0.0")); Review Comment: Should also check cluster status. Also check all other units statuses. Probably worth adding a complete standalone compute test with broadcast execution to test that the whole chain works. ########## modules/code-deployment/src/integrationTest/java/org/apache/ignite/internal/deployment/ItStaticDeploymentTest.java: ########## @@ -0,0 +1,80 @@ +/* + * 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.deployment; + +import static org.apache.ignite.deployment.version.Version.parseVersion; +import static org.apache.ignite.internal.TestWrappers.unwrapIgniteImpl; +import static org.hamcrest.MatcherAssert.assertThat; + +import java.io.IOException; +import java.nio.file.Path; +import java.util.concurrent.CompletableFuture; +import org.apache.ignite.internal.ClusterPerClassIntegrationTest; +import org.apache.ignite.internal.deployunit.DeploymentStatus; +import org.apache.ignite.internal.deployunit.IgniteDeployment; +import org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class ItStaticDeploymentTest extends ClusterPerClassIntegrationTest { + private DeployFiles files; + + @BeforeEach + public void generateDummy() { + files = new DeployFiles(WORK_DIR); + } + + @Override + protected boolean needInitializeCluster() { + return false; + } + + @Test + public void testStaticDeploy() throws IOException { + DeployFile smallFile = files.smallFile(); + DeployFile mediumFile = files.mediumFile(); + + Path node0WorkDir = CLUSTER.nodeWorkDir(0); + Path node1WorkDir = CLUSTER.nodeWorkDir(1); + Path node2WorkDir = CLUSTER.nodeWorkDir(2); + + DeployFiles.staticDeploy("unit1", parseVersion("1.0.0"), smallFile, node0WorkDir); + + DeployFiles.staticDeploy("unit2", parseVersion("1.0.0"), smallFile, node0WorkDir); + DeployFiles.staticDeploy("unit2", parseVersion("1.0.0"), smallFile, node1WorkDir); + + DeployFiles.staticDeploy("unit3", parseVersion("1.0.0"), smallFile, node0WorkDir); + DeployFiles.staticDeploy("unit3", parseVersion("1.0.0"), smallFile, node1WorkDir); + DeployFiles.staticDeploy("unit3", parseVersion("1.0.0"), smallFile, node2WorkDir); + + DeployFiles.staticDeploy("unit1", parseVersion("1.1.0"), smallFile, node0WorkDir); + DeployFiles.staticDeploy("unit1", parseVersion("1.1.0"), smallFile, node1WorkDir); + + DeployFiles.staticDeploy("unit3", parseVersion("1.0.1"), smallFile, node2WorkDir); + + CLUSTER.startAndInit(3); + + IgniteDeployment node0 = unwrapIgniteImpl(CLUSTER.node(0)).deployment(); + IgniteDeployment node1 = unwrapIgniteImpl(CLUSTER.node(1)).deployment(); + IgniteDeployment node2 = unwrapIgniteImpl(CLUSTER.node(2)).deployment(); + + CompletableFuture<DeploymentStatus> unit1 = node0.nodeStatusAsync("unit1", parseVersion("1.0.0")); + + assertThat(unit1, CompletableFutureMatcher.willBe(DeploymentStatus.DEPLOYED)); Review Comment: Could use static import here ########## modules/code-deployment/src/main/java/org/apache/ignite/internal/deployunit/StaticDeploymentUnitObserver.java: ########## @@ -0,0 +1,152 @@ +/* + * 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 org.apache.ignite.deployment.version.Version.parseVersion; +import static org.apache.ignite.internal.deployunit.DeploymentStatus.DEPLOYED; +import static org.apache.ignite.internal.util.CompletableFutures.allOf; + +import java.io.IOException; +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.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.CompletableFuture; +import java.util.stream.Collectors; +import org.apache.ignite.deployment.version.Version; +import org.apache.ignite.internal.deployunit.exception.DeploymentUnitReadException; +import org.apache.ignite.internal.deployunit.metastore.DeploymentUnitStore; +import org.apache.ignite.internal.deployunit.metastore.status.UnitNodeStatus; +import org.apache.ignite.internal.logger.IgniteLogger; +import org.apache.ignite.internal.logger.Loggers; + +/** + * Observes a predefined directory with statically provisioned deployment units and + * registers their presence in the deployment store. + * + * <p>The observer scans the {@code deploymentUnitsRoot} directory, expecting the following structure: + * {@code <unitId>/<version>/} + * For every discovered {@code unitId}-{@code version} pair that is not yet registered for this node, + * the observer creates (or reuses) a cluster status and then creates the node status marked as + * {@link DeploymentStatus#DEPLOYED}. + */ +public class StaticDeploymentUnitObserver { Review Comment: The name is misleading - observe usually means that we monitor file system and take actions. I think simple `StaticUnitDeployer` will be just fine? ########## modules/code-deployment/src/integrationTest/java/org/apache/ignite/internal/deployment/DeployFiles.java: ########## @@ -162,6 +162,16 @@ public static UnitStatuses buildStatus(String id, Unit... units) { return builder.build(); } + public static void staticDeploy(String id, Version version, DeployFile file, Path workDir) throws IOException { + Path deploymentRootFolder = workDir.resolve("deployment"); + Path unitFile = deploymentRootFolder.resolve(id).resolve(version.render()).resolve(file.file().getFileName().toString()); + Files.createDirectories(unitFile.getParent()); + Files.copy( + file.file(), + unitFile + ); Review Comment: ```suggestion Files.copy(file.file(), unitFile); ``` ########## modules/code-deployment/src/main/java/org/apache/ignite/internal/deployunit/StaticDeploymentUnitObserver.java: ########## @@ -0,0 +1,152 @@ +/* + * 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 org.apache.ignite.deployment.version.Version.parseVersion; +import static org.apache.ignite.internal.deployunit.DeploymentStatus.DEPLOYED; +import static org.apache.ignite.internal.util.CompletableFutures.allOf; + +import java.io.IOException; +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.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.CompletableFuture; +import java.util.stream.Collectors; +import org.apache.ignite.deployment.version.Version; +import org.apache.ignite.internal.deployunit.exception.DeploymentUnitReadException; +import org.apache.ignite.internal.deployunit.metastore.DeploymentUnitStore; +import org.apache.ignite.internal.deployunit.metastore.status.UnitNodeStatus; +import org.apache.ignite.internal.logger.IgniteLogger; +import org.apache.ignite.internal.logger.Loggers; + +/** + * Observes a predefined directory with statically provisioned deployment units and + * registers their presence in the deployment store. + * + * <p>The observer scans the {@code deploymentUnitsRoot} directory, expecting the following structure: + * {@code <unitId>/<version>/} + * For every discovered {@code unitId}-{@code version} pair that is not yet registered for this node, + * the observer creates (or reuses) a cluster status and then creates the node status marked as + * {@link DeploymentStatus#DEPLOYED}. + */ +public class StaticDeploymentUnitObserver { + private static final IgniteLogger LOG = Loggers.forClass(StaticDeploymentUnitObserver.class); + + private final DeploymentUnitStore deploymentUnitStore; + + private final String nodeName; + + private final Path deploymentUnitsRoot; + + /** + * Constructor. + */ + public StaticDeploymentUnitObserver( + DeploymentUnitStore deploymentUnitStore, + String nodeName, + Path deploymentUnitsRoot + ) { + this.deploymentUnitStore = deploymentUnitStore; + this.nodeName = nodeName; + this.deploymentUnitsRoot = deploymentUnitsRoot; + } + + /** + * Scans the filesystem for statically deployed units and registers their cluster and node statuses + * if they are not yet present in the store. + * + * <p>Already registered unit versions for this node are skipped. New ones are registered as DEPLOYED. + */ + public CompletableFuture<Void> observeAndRegisterStaticUnits() { + Map<String, List<Version>> staticUnits = collectStaticUnits(); + + return deploymentUnitStore.getNodeStatuses(nodeName).thenCompose(statuses -> { + List<CompletableFuture<?>> futures = new ArrayList<>(); + + for (UnitNodeStatus status : statuses) { + staticUnits.get(status.id()).remove(status.version()); + if (staticUnits.get(status.id()).isEmpty()) { + staticUnits.remove(status.id()); + } + } + + staticUnits.forEach((id, versions) -> { + versions.forEach(version -> { + LOG.info("Start processing unit {}:{}", id, version); + CompletableFuture<Boolean> future = deploymentUnitStore.createClusterStatus(id, version, Set.of(nodeName)) + .thenCompose(status -> { + if (status == null) { + return deploymentUnitStore.getClusterStatus(id, version).thenCompose(it -> + deploymentUnitStore.createNodeStatus(nodeName, id, version, it.opId(), DEPLOYED) + ); + } else { + return deploymentUnitStore.createNodeStatus(nodeName, id, version, status.opId(), DEPLOYED); + } + }) + .whenComplete((result, t) -> + LOG.info("Finished static status creating {}:{} with result {}", t, id, version, result) + ); + futures.add(future); + }); + }); + + return allOf(futures); + }); + } + + private Map<String, List<Version>> collectStaticUnits() { + Map<String, List<Version>> units = new HashMap<>(); + List<Path> unitFolders = allSubdirectories(deploymentUnitsRoot); + for (Path unitFolder : unitFolders) { + List<Path> versions = allSubdirectories(unitFolder); + units.put( + unitFolder.getFileName().toString(), + versions.stream() + .map(versionFolder -> parseVersion(versionFolder.getFileName().toString())) + .collect(Collectors.toList()) + ); + } + return units; + } + + private static List<Path> allSubdirectories(Path folder) { + List<Path> subfolders = new ArrayList<>(); + try { + Files.walkFileTree(folder, Set.of(), 2, new SimpleFileVisitor<>() { Review Comment: I think it's better to use `maxDepth` of 1, override `visitFile` instead and check the `attrs.isDirectory()`. According to the documentation, > The `visitFile` method is invoked for all files, including directories, encountered at `maxDepth` -- 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