ptupitsyn commented on code in PR #1698: URL: https://github.com/apache/ignite-3/pull/1698#discussion_r1113186412
########## modules/api/src/main/java/org/apache/ignite/deployment/IgniteDeployment.java: ########## @@ -0,0 +1,74 @@ +/* + * 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.deployment; + +import java.util.Set; +import java.util.concurrent.CompletableFuture; +import org.apache.ignite.deployment.version.Version; + +/** + * Provides access to the Deployment Unit functionality. + */ +public interface IgniteDeployment { + + default CompletableFuture<Boolean> deploy(String id, DeploymentUnit deploymentUnit) { Review Comment: Async methods in public API should have `Async` suffix. ########## modules/api/src/main/java/org/apache/ignite/deployment/IgniteDeployment.java: ########## @@ -0,0 +1,74 @@ +/* + * 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.deployment; + +import java.util.Set; +import java.util.concurrent.CompletableFuture; +import org.apache.ignite.deployment.version.Version; + +/** + * Provides access to the Deployment Unit functionality. + */ +public interface IgniteDeployment { + Review Comment: Extra blank line here and below. ########## modules/api/src/main/java/org/apache/ignite/deployment/IgniteDeployment.java: ########## @@ -0,0 +1,74 @@ +/* + * 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.deployment; + +import java.util.Set; +import java.util.concurrent.CompletableFuture; +import org.apache.ignite.deployment.version.Version; + +/** + * Provides access to the Deployment Unit functionality. + */ +public interface IgniteDeployment { + + default CompletableFuture<Boolean> deploy(String id, DeploymentUnit deploymentUnit) { + return deploy(id, Version.latest(), deploymentUnit); + } + + /** + * Deploy provided unit to current node. + * After deploy finished, this deployment unit will be place to CMG group asynchronously. + * + * @param id Unit identifier. + * @param version Unit version. + * @param deploymentUnit Unit content. + * @return Future with success or not result. + */ + CompletableFuture<Boolean> deploy(String id, Version version, DeploymentUnit deploymentUnit); + + default CompletableFuture<Void> undeploy(String id) { + return undeploy(id, Version.latest()); + } + + /** + * Undeploy unit with corresponding identifier and version. + * Note that unit files will be deleted asynchronously. + * + * @param id Unit identifier. + * @param version Unit version. + * @return Future completed when unit will be undeployed. + */ + CompletableFuture<Void> undeploy(String id, Version version); + + /** + * List of all deployed units identifiers. + * + * @return Future with result. + */ + CompletableFuture<Set<UnitStatus>> list(); Review Comment: ```suggestion CompletableFuture<List<UnitStatus>> list(); ``` Is there a reason to return a `Set`? ########## modules/api/src/main/java/org/apache/ignite/deployment/IgniteDeployment.java: ########## @@ -0,0 +1,74 @@ +/* + * 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.deployment; + +import java.util.Set; +import java.util.concurrent.CompletableFuture; +import org.apache.ignite.deployment.version.Version; + +/** + * Provides access to the Deployment Unit functionality. + */ +public interface IgniteDeployment { + + default CompletableFuture<Boolean> deploy(String id, DeploymentUnit deploymentUnit) { + return deploy(id, Version.latest(), deploymentUnit); + } + + /** + * Deploy provided unit to current node. + * After deploy finished, this deployment unit will be place to CMG group asynchronously. + * + * @param id Unit identifier. + * @param version Unit version. + * @param deploymentUnit Unit content. + * @return Future with success or not result. + */ + CompletableFuture<Boolean> deploy(String id, Version version, DeploymentUnit deploymentUnit); + + default CompletableFuture<Void> undeploy(String id) { + return undeploy(id, Version.latest()); + } + + /** + * Undeploy unit with corresponding identifier and version. + * Note that unit files will be deleted asynchronously. + * + * @param id Unit identifier. + * @param version Unit version. + * @return Future completed when unit will be undeployed. + */ + CompletableFuture<Void> undeploy(String id, Version version); + + /** + * List of all deployed units identifiers. + * + * @return Future with result. + */ + CompletableFuture<Set<UnitStatus>> list(); + + /** + * List with all deployed versions of required unit identifiers. + * + * @param unitId unit identifier. + * @return Future with result. + */ + CompletableFuture<Set<Version>> versions(String unitId); Review Comment: Same as above - `Set` vs `List`. Javadoc says `List`. ########## modules/api/src/main/java/org/apache/ignite/deployment/IgniteDeployment.java: ########## @@ -0,0 +1,74 @@ +/* + * 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.deployment; + +import java.util.Set; +import java.util.concurrent.CompletableFuture; +import org.apache.ignite.deployment.version.Version; + +/** + * Provides access to the Deployment Unit functionality. + */ +public interface IgniteDeployment { + + default CompletableFuture<Boolean> deploy(String id, DeploymentUnit deploymentUnit) { + return deploy(id, Version.latest(), deploymentUnit); + } + + /** + * Deploy provided unit to current node. + * After deploy finished, this deployment unit will be place to CMG group asynchronously. + * + * @param id Unit identifier. + * @param version Unit version. + * @param deploymentUnit Unit content. + * @return Future with success or not result. + */ + CompletableFuture<Boolean> deploy(String id, Version version, DeploymentUnit deploymentUnit); + + default CompletableFuture<Void> undeploy(String id) { Review Comment: Missing javadoc here and below. ########## modules/api/src/main/java/org/apache/ignite/deployment/UnitStatus.java: ########## @@ -0,0 +1,102 @@ +/* + * 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.deployment; + +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; +import org.apache.ignite.deployment.version.Version; + +/** + * Deployment unit status. + */ +public class UnitStatus { Review Comment: Let's override `toString`. ########## modules/api/src/main/java/org/apache/ignite/Ignite.java: ########## @@ -67,6 +68,8 @@ public interface Ignite extends AutoCloseable { */ IgniteCompute compute(); + IgniteDeployment deployment(); Review Comment: Missing javadoc ########## modules/api/src/main/java/org/apache/ignite/deployment/DeploymentUnit.java: ########## @@ -0,0 +1,69 @@ +/* + * 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.deployment; + +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Path; + +/** + * Deployment unit interface. + */ +public interface DeploymentUnit { + + /** + * Unit content. + * + * @return Name of deployment unit. + */ + String unitName(); Review Comment: ```suggestion String name(); ``` ########## modules/code-deployment/src/main/java/org/apache/ignite/internal/deployunit/DeploymentManagerImpl.java: ########## @@ -0,0 +1,410 @@ +/* + * 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.internal.metastorage.dsl.Conditions.exists; +import static org.apache.ignite.internal.metastorage.dsl.Conditions.notExists; +import static org.apache.ignite.internal.metastorage.dsl.Conditions.revision; +import static org.apache.ignite.internal.metastorage.dsl.Operations.put; + +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.StandardCopyOption; +import java.nio.file.StandardOpenOption; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.Flow.Subscriber; +import java.util.concurrent.Flow.Subscription; +import java.util.stream.Collectors; +import org.apache.ignite.deployment.DeploymentUnit; +import org.apache.ignite.deployment.IgniteDeployment; +import org.apache.ignite.deployment.UnitStatus; +import org.apache.ignite.deployment.UnitStatus.UnitStatusBuilder; +import org.apache.ignite.deployment.version.Version; +import org.apache.ignite.internal.cluster.management.ClusterManagementGroupManager; +import org.apache.ignite.internal.deployunit.configuration.DeploymentConfiguration; +import org.apache.ignite.internal.deployunit.exception.DeployUnitWriteMetaException; +import org.apache.ignite.internal.deployunit.exception.DeploymentUnitReadException; +import org.apache.ignite.internal.deployunit.exception.UndeployNotExistedDeploymentUnitException; +import org.apache.ignite.internal.deployunit.message.DeployUnitMessageTypes; +import org.apache.ignite.internal.deployunit.message.DeployUnitRequest; +import org.apache.ignite.internal.deployunit.message.DeployUnitRequestBuilder; +import org.apache.ignite.internal.deployunit.message.DeployUnitRequestImpl; +import org.apache.ignite.internal.deployunit.message.DeployUnitResponse; +import org.apache.ignite.internal.deployunit.message.DeployUnitResponseBuilder; +import org.apache.ignite.internal.deployunit.message.DeployUnitResponseImpl; +import org.apache.ignite.internal.deployunit.message.UndeployUnitRequest; +import org.apache.ignite.internal.deployunit.message.UndeployUnitRequestImpl; +import org.apache.ignite.internal.deployunit.message.UndeployUnitResponseImpl; +import org.apache.ignite.internal.future.InFlightFutures; +import org.apache.ignite.internal.logger.IgniteLogger; +import org.apache.ignite.internal.logger.Loggers; +import org.apache.ignite.internal.manager.IgniteComponent; +import org.apache.ignite.internal.metastorage.Entry; +import org.apache.ignite.internal.metastorage.MetaStorageManager; +import org.apache.ignite.internal.metastorage.dsl.Operation; +import org.apache.ignite.internal.metastorage.dsl.Operations; +import org.apache.ignite.lang.ByteArray; +import org.apache.ignite.network.ClusterNode; +import org.apache.ignite.network.ClusterService; + +/** + * Deployment manager implementation. + */ +public class DeploymentManagerImpl implements IgniteDeployment, IgniteComponent { + + private static final IgniteLogger LOG = Loggers.forClass(DeploymentManagerImpl.class); + + private static final String DEPLOY_UNIT_PREFIX = "deploy-unit."; + + private static final String UNITS_PREFIX = DEPLOY_UNIT_PREFIX + "units."; + + /** + * Meta storage. + */ + private final MetaStorageManager metaStorage; + + /** + * Deployment configuration. + */ + private final DeploymentConfiguration configuration; + + /** + * Cluster management group manager. + */ + private final ClusterManagementGroupManager cmgManager; + + /** + * In flight futures tracker. + */ + private final InFlightFutures inFlightFutures = new InFlightFutures(); + + /** + * Cluster service. + */ + private final ClusterService clusterService; + + /** + * Folder for units. + */ + private Path unitsFolder; + + /** + * Constructor. + * + * @param clusterService Cluster service. + * @param metaStorage Meta storage. + * @param workDir Node working directory. + * @param configuration Deployment configuration. + * @param cmgManager Cluster management group manager. + */ + public DeploymentManagerImpl(ClusterService clusterService, + MetaStorageManager metaStorage, + Path workDir, + DeploymentConfiguration configuration, + ClusterManagementGroupManager cmgManager) { + this.clusterService = clusterService; + this.metaStorage = metaStorage; + this.configuration = configuration; + this.cmgManager = cmgManager; + unitsFolder = workDir; + } + + @Override + public CompletableFuture<Boolean> deploy(String id, Version version, DeploymentUnit deploymentUnit) { + Set<Operation> operations = new HashSet<>(); + + ByteArray key = new ByteArray(UNITS_PREFIX + id + ":" + version.render()); Review Comment: Is `null` a valid `id`? Empty string? ########## modules/code-deployment/src/main/java/org/apache/ignite/internal/deployunit/DeploymentManagerImpl.java: ########## @@ -0,0 +1,410 @@ +/* + * 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.internal.metastorage.dsl.Conditions.exists; +import static org.apache.ignite.internal.metastorage.dsl.Conditions.notExists; +import static org.apache.ignite.internal.metastorage.dsl.Conditions.revision; +import static org.apache.ignite.internal.metastorage.dsl.Operations.put; + +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.StandardCopyOption; +import java.nio.file.StandardOpenOption; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.Flow.Subscriber; +import java.util.concurrent.Flow.Subscription; +import java.util.stream.Collectors; +import org.apache.ignite.deployment.DeploymentUnit; +import org.apache.ignite.deployment.IgniteDeployment; +import org.apache.ignite.deployment.UnitStatus; +import org.apache.ignite.deployment.UnitStatus.UnitStatusBuilder; +import org.apache.ignite.deployment.version.Version; +import org.apache.ignite.internal.cluster.management.ClusterManagementGroupManager; +import org.apache.ignite.internal.deployunit.configuration.DeploymentConfiguration; +import org.apache.ignite.internal.deployunit.exception.DeployUnitWriteMetaException; +import org.apache.ignite.internal.deployunit.exception.DeploymentUnitReadException; +import org.apache.ignite.internal.deployunit.exception.UndeployNotExistedDeploymentUnitException; +import org.apache.ignite.internal.deployunit.message.DeployUnitMessageTypes; +import org.apache.ignite.internal.deployunit.message.DeployUnitRequest; +import org.apache.ignite.internal.deployunit.message.DeployUnitRequestBuilder; +import org.apache.ignite.internal.deployunit.message.DeployUnitRequestImpl; +import org.apache.ignite.internal.deployunit.message.DeployUnitResponse; +import org.apache.ignite.internal.deployunit.message.DeployUnitResponseBuilder; +import org.apache.ignite.internal.deployunit.message.DeployUnitResponseImpl; +import org.apache.ignite.internal.deployunit.message.UndeployUnitRequest; +import org.apache.ignite.internal.deployunit.message.UndeployUnitRequestImpl; +import org.apache.ignite.internal.deployunit.message.UndeployUnitResponseImpl; +import org.apache.ignite.internal.future.InFlightFutures; +import org.apache.ignite.internal.logger.IgniteLogger; +import org.apache.ignite.internal.logger.Loggers; +import org.apache.ignite.internal.manager.IgniteComponent; +import org.apache.ignite.internal.metastorage.Entry; +import org.apache.ignite.internal.metastorage.MetaStorageManager; +import org.apache.ignite.internal.metastorage.dsl.Operation; +import org.apache.ignite.internal.metastorage.dsl.Operations; +import org.apache.ignite.lang.ByteArray; +import org.apache.ignite.network.ClusterNode; +import org.apache.ignite.network.ClusterService; + +/** + * Deployment manager implementation. + */ +public class DeploymentManagerImpl implements IgniteDeployment, IgniteComponent { + + private static final IgniteLogger LOG = Loggers.forClass(DeploymentManagerImpl.class); + + private static final String DEPLOY_UNIT_PREFIX = "deploy-unit."; + + private static final String UNITS_PREFIX = DEPLOY_UNIT_PREFIX + "units."; + + /** + * Meta storage. + */ + private final MetaStorageManager metaStorage; + + /** + * Deployment configuration. + */ + private final DeploymentConfiguration configuration; + + /** + * Cluster management group manager. + */ + private final ClusterManagementGroupManager cmgManager; + + /** + * In flight futures tracker. + */ + private final InFlightFutures inFlightFutures = new InFlightFutures(); + + /** + * Cluster service. + */ + private final ClusterService clusterService; + + /** + * Folder for units. + */ + private Path unitsFolder; + + /** + * Constructor. + * + * @param clusterService Cluster service. + * @param metaStorage Meta storage. + * @param workDir Node working directory. + * @param configuration Deployment configuration. + * @param cmgManager Cluster management group manager. + */ + public DeploymentManagerImpl(ClusterService clusterService, + MetaStorageManager metaStorage, + Path workDir, + DeploymentConfiguration configuration, + ClusterManagementGroupManager cmgManager) { + this.clusterService = clusterService; + this.metaStorage = metaStorage; + this.configuration = configuration; + this.cmgManager = cmgManager; + unitsFolder = workDir; + } + + @Override + public CompletableFuture<Boolean> deploy(String id, Version version, DeploymentUnit deploymentUnit) { Review Comment: Missing argument validation. ########## modules/code-deployment/src/main/java/org/apache/ignite/internal/deployunit/UnitMetaSerializer.java: ########## @@ -0,0 +1,86 @@ +/* + * 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.charset.StandardCharsets; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import org.apache.ignite.deployment.version.Version; + +/** + * Serializer for {@link UnitMeta}. + */ +public class UnitMetaSerializer { + private static final String SEPARATOR = ";"; + private static final String LIST_SEPARATOR = ":"; + + /** + * Constructor. + */ + private UnitMetaSerializer() { + + } + + + /** + * Serialize unit meta. + * + * @param meta Unit meta. + * @return Serialized unit meta. + */ + public static byte[] serialize(UnitMeta meta) { + StringBuilder sb = new StringBuilder(); + + sb.append(meta.getId()).append(SEPARATOR) Review Comment: Should we use a `BinaryTuple` instead of separated string? Should be cleaner and more efficient. ########## modules/api/src/main/java/org/apache/ignite/deployment/DeploymentUnit.java: ########## @@ -0,0 +1,69 @@ +/* + * 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.deployment; + +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Path; + +/** + * Deployment unit interface. + */ +public interface DeploymentUnit { + + /** + * Unit content. Review Comment: ```suggestion * Unit name. ``` ########## modules/api/src/main/java/org/apache/ignite/deployment/DeploymentUnit.java: ########## @@ -0,0 +1,69 @@ +/* + * 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.deployment; + +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Path; + +/** + * Deployment unit interface. + */ +public interface DeploymentUnit { + + /** + * Unit content. + * + * @return Name of deployment unit. + */ + String unitName(); + + /** + * Input stream with deployment unit content. + * + * @return input stream with deployment unit content. + */ + InputStream content(); + + + /** + * Create deployment unit from local path. + * + * @param path Path to local file. + * @return Deployment unit based on local file. + */ + static DeploymentUnit fromPath(Path path) { Review Comment: Missing argument validation (`unitName` will fail later when `path` is null). ########## modules/api/src/main/java/org/apache/ignite/deployment/IgniteDeployment.java: ########## @@ -0,0 +1,74 @@ +/* + * 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.deployment; + +import java.util.Set; +import java.util.concurrent.CompletableFuture; +import org.apache.ignite.deployment.version.Version; + +/** + * Provides access to the Deployment Unit functionality. + */ +public interface IgniteDeployment { + + default CompletableFuture<Boolean> deploy(String id, DeploymentUnit deploymentUnit) { + return deploy(id, Version.latest(), deploymentUnit); + } + + /** + * Deploy provided unit to current node. + * After deploy finished, this deployment unit will be place to CMG group asynchronously. + * + * @param id Unit identifier. + * @param version Unit version. + * @param deploymentUnit Unit content. + * @return Future with success or not result. + */ + CompletableFuture<Boolean> deploy(String id, Version version, DeploymentUnit deploymentUnit); + + default CompletableFuture<Void> undeploy(String id) { + return undeploy(id, Version.latest()); + } + + /** + * Undeploy unit with corresponding identifier and version. + * Note that unit files will be deleted asynchronously. + * + * @param id Unit identifier. + * @param version Unit version. + * @return Future completed when unit will be undeployed. + */ + CompletableFuture<Void> undeploy(String id, Version version); Review Comment: What if there is no unit with specified id and/or version? Do we get an exception? Should we return `CompletableFuture<Boolean>` to indicate whether the unit existed? ########## modules/api/src/main/java/org/apache/ignite/deployment/IgniteDeployment.java: ########## @@ -0,0 +1,74 @@ +/* + * 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.deployment; + +import java.util.Set; +import java.util.concurrent.CompletableFuture; +import org.apache.ignite.deployment.version.Version; + +/** + * Provides access to the Deployment Unit functionality. + */ +public interface IgniteDeployment { + + default CompletableFuture<Boolean> deploy(String id, DeploymentUnit deploymentUnit) { + return deploy(id, Version.latest(), deploymentUnit); + } + + /** + * Deploy provided unit to current node. + * After deploy finished, this deployment unit will be place to CMG group asynchronously. + * + * @param id Unit identifier. + * @param version Unit version. + * @param deploymentUnit Unit content. + * @return Future with success or not result. + */ + CompletableFuture<Boolean> deploy(String id, Version version, DeploymentUnit deploymentUnit); + + default CompletableFuture<Void> undeploy(String id) { + return undeploy(id, Version.latest()); + } + + /** + * Undeploy unit with corresponding identifier and version. + * Note that unit files will be deleted asynchronously. + * + * @param id Unit identifier. + * @param version Unit version. + * @return Future completed when unit will be undeployed. + */ + CompletableFuture<Void> undeploy(String id, Version version); + + /** + * List of all deployed units identifiers. + * + * @return Future with result. + */ + CompletableFuture<Set<UnitStatus>> list(); + + /** + * List with all deployed versions of required unit identifiers. + * + * @param unitId unit identifier. + * @return Future with result. + */ + CompletableFuture<Set<Version>> versions(String unitId); + + CompletableFuture<UnitStatus> status(String id); Review Comment: What if there is no unit with the specified id? Does this method return null or throw? -- 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]
