-
Notifications
You must be signed in to change notification settings - Fork 81
IGNITE-28731 Create cluster auto activation plugin #355
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
DenisPolo
wants to merge
4
commits into
apache:master
Choose a base branch
from
DenisPolo:ignite-28731
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7c1bff5
IGNITE-28731 Create cluster auto activation plugin
17fd2f2
IGNITE-28731 Create cluster auto activation plugin - Fix issues
bfd6320
IGNITE-28731 Create cluster auto activation plugin - fix snapshot ver…
115b23d
IGNITE-28731 Create cluster auto activation plugin - fix some more is…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| Apache Ignite Auto Activation Plugin | ||
| ------------------------------------ | ||
| Apache Ignite Auto Activation plugin enables cluster activation at startup, subject to configured conditions. | ||
|
|
||
| The plugin skips cluster activation in any of next cases: | ||
|
|
||
| - Cluster state is ACTIVE or ACTIVE_READ_ONLY | ||
| - Cluster baseline is not empty | ||
| - `condition` contains any client node | ||
|
|
||
| Depending on how you use Ignite, you can an extension using one of the following methods: | ||
|
|
||
| - If you use the binary distribution, move the libs/{module-dir} to the 'libs' directory of the Ignite distribution before starting the node. | ||
| - Add libraries from libs/{module-dir} to the classpath of your application. | ||
| - Add a module as a Maven dependency to your project. | ||
|
|
||
|
|
||
| Building Module And Running Tests | ||
| --------------------------------- | ||
|
|
||
| To build and run Auto Activation extension use the command below: | ||
|
|
||
| mvn clean package -pl modules/auto-activation-ext | ||
|
|
||
|
|
||
| Importing Auto Activation Plugin In Maven Project | ||
| ------------------------------------------------- | ||
|
|
||
| If you are using Maven to manage dependencies of your project, you can add Auto Activation Plugin module | ||
| dependency like this: | ||
|
|
||
| ```xml | ||
|
|
||
| <project xmlns="http://maven.apache.org/POM/4.0.0" | ||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 | ||
| http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
| <artifactId>your.project</artifactId> | ||
| ... | ||
| <dependencies> | ||
| ... | ||
| <dependency> | ||
| <groupId>org.apache.ignite</groupId> | ||
| <artifactId>ignite-auto-activation-ext</artifactId> | ||
| <version>1.0.0-SNAPSHOT</version> | ||
| </dependency> | ||
| ... | ||
| </dependencies> | ||
| ... | ||
| </project> | ||
| ``` | ||
|
|
||
| Usage | ||
| ----------------------------------- | ||
|
|
||
| To enable cluster auto activation add next properties to your ignite-server.xml configurations | ||
| ``` | ||
| <bean id="grid.cfg" class="org.apache.ignite.configuration.IgniteConfiguration"> | ||
| <property name="pluginProviders"> | ||
| <bean class="opt.apache.ignite.activation.AutoActivationPluginProvider"> | ||
| <constructor-arg name="condition" ref="condition" /> | ||
| </bean> | ||
| </property> | ||
| </bean> | ||
| ``` | ||
| where "condition" can be one of the following beans: | ||
| ``` | ||
| <bean id="condition" class="opt.apache.ignite.activation.ActivateByConsistentID"> | ||
| <constructor-arg name="requiredNodes"> | ||
| <util:set> | ||
| <value>server-0</value> | ||
| <value>server-1</value> | ||
| </util:set> | ||
| </constructor-arg> | ||
| </bean> | ||
| ``` | ||
| where `server-0` and `server-1` are consistent ID's of required server nodes in the activated cluster | ||
|
|
||
| or | ||
| ``` | ||
| <bean id="condition" class="opt.apache.ignite.activation.ActivateByNodeAttribute"> | ||
| <constructor-arg name="attributeName" value="ATTR"/> | ||
| <constructor-arg name="requiredValues"> | ||
| <util:set> | ||
| <value>attribute-0</value> | ||
| <value>attribute-1</value> | ||
| </util:set> | ||
| </constructor-arg> | ||
| </bean> | ||
| ``` | ||
| where `attribute-0` and `attribute-1` are values of user-defined attribute `ATTR` that will be used to choose server nodes for cluster auto activation. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
|
|
||
| <!-- | ||
| ~ 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. | ||
| --> | ||
|
|
||
| <!-- | ||
| POM file. | ||
| --> | ||
| <project xmlns="http://maven.apache.org/POM/4.0.0" | ||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
|
|
||
| <parent> | ||
| <groupId>org.apache.ignite</groupId> | ||
| <artifactId>ignite-parent-ext-internal</artifactId> | ||
| <version>1</version> | ||
| <relativePath>../../parent-internal/pom.xml</relativePath> | ||
| </parent> | ||
|
|
||
| <artifactId>ignite-auto-activation-ext</artifactId> | ||
| <version>1.0.0-SNAPSHOT</version> | ||
| <url>https://ignite.apache.org</url> | ||
|
|
||
| <dependencies> | ||
| <dependency> | ||
| <groupId>${project.groupId}</groupId> | ||
| <artifactId>ignite-core</artifactId> | ||
| <scope>provided</scope> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>${project.groupId}</groupId> | ||
| <artifactId>ignite-core</artifactId> | ||
| <type>test-jar</type> | ||
| <scope>test</scope> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>${project.groupId}</groupId> | ||
| <artifactId>ignite-log4j2</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>org.springframework</groupId> | ||
| <artifactId>spring-beans</artifactId> | ||
| <version>${spring.version}</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>org.springframework</groupId> | ||
| <artifactId>spring-context</artifactId> | ||
| <version>${spring.version}</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| </dependencies> | ||
| <build> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-compiler-plugin</artifactId> | ||
| <configuration> | ||
| <source>11</source> | ||
| <target>11</target> | ||
| </configuration> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
|
|
||
| </project> |
64 changes: 64 additions & 0 deletions
64
...uto-activation-ext/src/main/java/opt/apache/ignite/activation/ActivateByConsistentID.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| /* | ||
| * 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 opt.apache.ignite.activation; | ||
|
|
||
| import java.util.Collection; | ||
| import java.util.LinkedHashSet; | ||
| import java.util.Set; | ||
| import org.apache.ignite.IgniteException; | ||
| import org.apache.ignite.cluster.ClusterNode; | ||
| import org.apache.ignite.lang.IgnitePredicate; | ||
|
|
||
| /** | ||
| * Activate cluster when nodes with specified ConsistentID values join topology. | ||
| */ | ||
| public class ActivateByConsistentID implements IgnitePredicate<Collection<ClusterNode>> { | ||
| /** Collection of required nodes ConsistentIDs. */ | ||
| private final Set<String> requiredNodes; | ||
|
|
||
| /** | ||
| * @param requiredNodes List of ConsistentIDs. | ||
| */ | ||
| public ActivateByConsistentID(Set<String> requiredNodes) { | ||
| if (requiredNodes == null || requiredNodes.isEmpty()) | ||
| throw new IllegalArgumentException("requiredNodes must be set"); | ||
|
|
||
| this.requiredNodes = requiredNodes; | ||
| } | ||
|
|
||
| /** {@inheritDoc} */ | ||
| @Override public boolean apply(Collection<ClusterNode> nodes) { | ||
| Set<String> missingNodes = new LinkedHashSet<>(requiredNodes); | ||
|
|
||
| for (ClusterNode node : nodes) { | ||
| String nodeConsistentId = node.consistentId().toString(); | ||
|
|
||
| if (missingNodes.contains(nodeConsistentId) && node.isClient()) { | ||
| throw new IgniteException("Auto-activation-plugin supports only server nodes. This node is client: ID " | ||
| + node.consistentId() + ", IP " + node.addresses()); | ||
| } | ||
|
|
||
| missingNodes.remove(nodeConsistentId); | ||
|
|
||
| if (missingNodes.isEmpty()) | ||
| break; | ||
| } | ||
|
|
||
| return missingNodes.isEmpty(); | ||
| } | ||
| } |
72 changes: 72 additions & 0 deletions
72
...to-activation-ext/src/main/java/opt/apache/ignite/activation/ActivateByNodeAttribute.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| /* | ||
| * 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 opt.apache.ignite.activation; | ||
|
|
||
| import java.util.Collection; | ||
| import java.util.LinkedHashSet; | ||
| import java.util.Set; | ||
| import org.apache.ignite.IgniteException; | ||
| import org.apache.ignite.cluster.ClusterNode; | ||
| import org.apache.ignite.lang.IgnitePredicate; | ||
|
|
||
| /** | ||
| * Activate cluster when nodes with all specified attributes values join topology. | ||
| */ | ||
| public class ActivateByNodeAttribute implements IgnitePredicate<Collection<ClusterNode>> { | ||
| /** Node's attribute name. */ | ||
| private final String attrName; | ||
|
|
||
| /** Collection of values for node's attribute. */ | ||
| private final Set<String> requiredValues; | ||
|
|
||
| /** | ||
| * @param attributeName Node's attribute name. | ||
| * @param requiredValues List of values for node's attribute. | ||
| */ | ||
| public ActivateByNodeAttribute(String attributeName, Set<String> requiredValues) { | ||
| if (attributeName == null || attributeName.isBlank()) | ||
| throw new IllegalArgumentException("attributeName must be set"); | ||
|
|
||
| if (requiredValues == null || requiredValues.isEmpty()) | ||
| throw new IllegalArgumentException("requiredValues must be set"); | ||
|
|
||
| this.attrName = attributeName; | ||
| this.requiredValues = requiredValues; | ||
| } | ||
|
|
||
| /** {@inheritDoc} */ | ||
| @Override public boolean apply(Collection<ClusterNode> nodes) { | ||
| Set<String> missingNodes = new LinkedHashSet<>(requiredValues); | ||
|
|
||
| for (ClusterNode node : nodes) { | ||
| String attrVal = node.attribute(attrName); | ||
|
|
||
| if (missingNodes.contains(attrVal) && node.isClient()) { | ||
| throw new IgniteException("Auto-activation-plugin supports only server nodes. This node is client: ID " | ||
| + node.consistentId() + ", IP " + node.addresses()); | ||
| } | ||
|
|
||
| missingNodes.remove(attrVal); | ||
|
|
||
| if (missingNodes.isEmpty()) | ||
| break; | ||
| } | ||
|
|
||
| return missingNodes.isEmpty(); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.