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
85 changes: 85 additions & 0 deletions modules/auto-activation-ext/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
Apache Ignite Auto Activation Plugin

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace README.txt with README.md

------------------------------------

Apache Ignite Auto Activation plugin enables cluster activation at startup, subject to configured conditions.

Plugin skip cluster activation in any of next cases:

- Cluster state is ACTIVE
- Cluster baseline is not empty

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 (replace '${ignite.version}' with actual Ignite version you are
interested in):

<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">
...
<dependencies>
...
<dependency>
<groupId>org.apache.ignite</groupId>
<artifactId>ignite-auto-activation-ext</artifactId>
<version>${ignite-auto-activation-ext.version}</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>

or

<bean id="condition" class="opt.apache.ignite.activation.ActivateByNodeAttribute">
<constructor-arg name="attributeName" value="ATTR"/>
<constructor-arg name="requiredValues">
<util:set>
<value>server-0</value>
<value>server-1</value>
</util:set>
</constructor-arg>
</bean>
86 changes: 86 additions & 0 deletions modules/auto-activation-ext/pom.xml
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-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,40 @@
package opt.apache.ignite.activation;

import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.Set;
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();

missingNodes.remove(nodeConsistentId);

if (missingNodes.isEmpty()) break;
}

return missingNodes.isEmpty();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package opt.apache.ignite.activation;

import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.Set;
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;
}

/** */

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/** */
/** {@inheritDoc} */

@Override public boolean apply(Collection<ClusterNode> nodes) {
Set<String> missingNodes = new LinkedHashSet<String>(requiredValues);

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

missingNodes.remove(attrVal);

if (missingNodes.isEmpty()) break;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (missingNodes.isEmpty()) break;
if (missingNodes.isEmpty())
break;

use new lines for body of if

}

return missingNodes.isEmpty();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
package opt.apache.ignite.activation;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add license


import java.io.Serializable;
import java.util.Collection;
import java.util.UUID;
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCluster;
import org.apache.ignite.IgniteLogger;
import org.apache.ignite.cluster.ClusterNode;
import org.apache.ignite.cluster.ClusterState;
import org.apache.ignite.lang.IgnitePredicate;
import org.apache.ignite.plugin.CachePluginContext;
import org.apache.ignite.plugin.CachePluginProvider;
import org.apache.ignite.plugin.ExtensionRegistry;
import org.apache.ignite.plugin.IgnitePlugin;
import org.apache.ignite.plugin.PluginConfiguration;
import org.apache.ignite.plugin.PluginContext;
import org.apache.ignite.plugin.PluginProvider;
import org.apache.ignite.plugin.PluginValidationException;

/**
* Activate cluster when specified condition meet
*/
public class AutoActivationPluginProvider implements PluginProvider<PluginConfiguration> {
/** */
private final IgnitePredicate<Collection<ClusterNode>> condition;

/** */
private IgniteLogger logger;

/** */
private Ignite grid;

/**
* @param condition Auto activation condition.
*/
public AutoActivationPluginProvider(IgnitePredicate<Collection<ClusterNode>> condition) {
if (condition == null)
throw new IllegalArgumentException("Auto activation condition must be set");

this.condition = condition;
}

/** {@inheritDoc} */
@Override public String name() {
return "Auto Activation Plugin";
}

/** {@inheritDoc} */
@Override public <T extends IgnitePlugin> T plugin() {
return (T)new IgnitePlugin() {
// No-op.
};
}

/** {@inheritDoc} */
@Override public String version() {
return "1.0";
}

/** {@inheritDoc} */
@Override public String copyright() {
return "";
}

/** {@inheritDoc} */
@Override public void initExtensions(PluginContext pc, ExtensionRegistry er) {
logger = pc.log(this.getClass());
grid = pc.grid();
}

/** {@inheritDoc} */
@Override public <T> T createComponent(PluginContext pc, Class<T> type) {
return null;
}

/** {@inheritDoc} */
@Override public CachePluginProvider createCacheProvider(CachePluginContext cpc) {
return null;
}

/** {@inheritDoc} */
@Override public void start(PluginContext pc) {
// do nothing
}

/** {@inheritDoc} */
@Override public void stop(boolean bln) {
// do nothing
}

/** {@inheritDoc} */
@Override public void onIgniteStart() {

IgniteCluster cluster = grid.cluster();

if (cluster.state() == ClusterState.ACTIVE) {
if (logger.isInfoEnabled()) logger.info("Auto activation skipped - cluster already activated");
return;
}

if (cluster.currentBaselineTopology() != null) {
if (logger.isInfoEnabled()) logger.info("Auto activation skipped - baseline is not empty");
return;
}

if (condition.apply(cluster.nodes())) {
if (logger.isInfoEnabled()) logger.info("Auto activation plugin set cluster state ACTIVE - activation condition meet");
cluster.state(ClusterState.ACTIVE);
}
else {
if (logger.isInfoEnabled()) logger.info("Auto activation skipped - activation condition not meet");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (logger.isInfoEnabled()) logger.info("Auto activation skipped - activation condition not meet");
if (logger.isInfoEnabled())
logger.info("Auto activation skipped - activation condition not meet");

}
}

/** {@inheritDoc} */
@Override public void onIgniteStop(boolean bln) {
// do nothing
}

/** {@inheritDoc} */
@Override public Serializable provideDiscoveryData(UUID uuid) {
return null;
}

/** {@inheritDoc} */
@Override public void receiveDiscoveryData(UUID uuid, Serializable srlzbl) {
// do nothing
}

/** {@inheritDoc} */
@Override public void validateNewNode(ClusterNode cn) throws PluginValidationException {
// do nothing

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// do nothing
// No-op.

}
}
Loading