Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 106 additions & 0 deletions modules/auto-activation-ext/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
Apache Ignite Auto Activation Plugin
Comment thread
DenisPolo marked this conversation as resolved.
------------------------------------
Apache Ignite Auto Activation plugin enables cluster activation at startup, subject to configured conditions.

The plugin skips cluster activation in the following cases:

- Cluster state is either ACTIVE or ACTIVE_READ_ONLY, log message:
```text
[DateTime][INFO][main][AutoActivationPluginProvider] Auto activation skipped - cluster already activated
```
- Cluster baseline topology is not empty, log message:
```text
[DateTime][INFO][main][AutoActivationPluginProvider] Auto activation skipped - baseline is not empty
```
- The baseline topology does not include all nodes listed for activation. A message containing the consistentIds of the missing nodes will be written to ignite.log:
```text
[DateTime][INFO][main][AutoActivationPluginProvider] Auto activation skipped - activation condition not meet (by consistent ID). Missing nodes [<nideConssistentId1>, <nideConssistentId2>, ...]
```
- The node attributes in the topology do not contain the full list of values specified in the cluster's auto-activation settings. The log message will indicate the attribute name and list the missing values as follows:
```text
[DateTime][INFO][main][AutoActivationPluginProvider] Auto activation skipped - activation condition not meet (by node attribute). Attribute: <attributeName>, Missing values [<value1>, <value1>, ...]
```
- The required nodes list for cluster activation contains any client node. In this case, the node will simply not participate in cluster activation, and the log message will be identical to that of a missing node.

Depending on how you use Ignite, you can implement 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.
83 changes: 83 additions & 0 deletions modules/auto-activation-ext/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?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.
-->

<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,73 @@
/*
* 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.HashSet;
import java.util.Set;
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteMessaging;
import org.apache.ignite.cluster.ClusterGroup;
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<Ignite> {
/** 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(Ignite grid) {
Set<String> missingNodes = new HashSet<>(requiredNodes);
ClusterGroup servers = grid.cluster().forServers();
IgniteMessaging messaging = grid.message(servers);

for (ClusterNode node : servers.nodes()) {
String nodeConsistentId = node.consistentId().toString();

missingNodes.remove(nodeConsistentId);

if (missingNodes.isEmpty()) {
messaging.send(
"auto-activation-plugin-events",
"Auto activation plugin set cluster state ACTIVE - activation condition meet (by consistent ID)"
);

return true;
}
}

messaging.send(
"auto-activation-plugin-events",
"Auto activation skipped - activation condition not meet (by consistent ID). Missing nodes " +
"[" + String.join(", ", missingNodes) + "]");

return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* 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.HashSet;
import java.util.Set;
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteMessaging;
import org.apache.ignite.cluster.ClusterGroup;
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<Ignite> {
/** 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(Ignite grid) {
Set<String> missingValues = new HashSet<>(requiredValues);

ClusterGroup servers = grid.cluster().forServers();

IgniteMessaging messaging = grid.message(servers);

for (ClusterNode node : servers.nodes()) {
String attrVal = node.attribute(attrName);

missingValues.remove(attrVal);

if (missingValues.isEmpty()) {
messaging.send(
"auto-activation-plugin-events",
"Auto activation plugin set cluster state ACTIVE - activation condition meet (by node attribute)"
);

return true;
}
}

messaging.send("auto-activation-plugin-events",
"Auto activation skipped - activation condition not meet (by node attribute). "
+ "Attribute: " + attrName + ", Missing values [" + String.join(", ", missingValues) + "]");

return false;
}
}
Loading