-
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
base: master
Are you sure you want to change the base?
Changes from all commits
7c1bff5
17fd2f2
bfd6320
115b23d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
looks like a verb is missing |
||
|
|
||
| - 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. | ||
| 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. | ||||||||
| --> | ||||||||
|
Comment on lines
+20
to
+22
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Delete to fix |
||||||||
| <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> | ||||||||
| 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); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| 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(); | ||||||
| } | ||||||
| } | ||||||
| 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); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better to use HashSet when we do not need insertion order for iteration |
||||||
|
|
||||||
| 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(); | ||||||
| } | ||||||
| } | ||||||
Uh oh!
There was an error while loading. Please reload this page.