summaryrefslogtreecommitdiffstats
path: root/plugins/plugins-context/plugins-context-distribution
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/plugins-context/plugins-context-distribution')
-rw-r--r--plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-hazelcast/pom.xml46
-rw-r--r--plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-hazelcast/src/main/java/org/onap/policy/apex/plugins/context/distribution/hazelcast/HazelcastContextDistributor.java106
-rw-r--r--plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-hazelcast/src/main/java/org/onap/policy/apex/plugins/context/distribution/hazelcast/package-info.java27
-rw-r--r--plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-hazelcast/src/main/resources/hazelcast/hazelcast.xml.sample55
-rw-r--r--plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-hazelcast/src/test/java/org/onap/policy/apex/plugins/context/distribution/hazelcast/HazelcastContextDistributorTest.java74
-rw-r--r--plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-infinispan/pom.xml53
-rw-r--r--plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-infinispan/src/main/java/org/onap/policy/apex/plugins/context/distribution/infinispan/InfinispanContextDistributor.java115
-rw-r--r--plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-infinispan/src/main/java/org/onap/policy/apex/plugins/context/distribution/infinispan/InfinispanDistributorParameters.java144
-rw-r--r--plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-infinispan/src/main/java/org/onap/policy/apex/plugins/context/distribution/infinispan/InfinispanManager.java122
-rw-r--r--plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-infinispan/src/main/java/org/onap/policy/apex/plugins/context/distribution/infinispan/package-info.java27
-rw-r--r--plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-infinispan/src/main/resources/infinispan/infinispan.xml.sample40
-rw-r--r--plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-infinispan/src/test/java/org/onap/policy/apex/plugins/context/distribution/infinispan/InfinispanContextDistributorTest.java93
-rw-r--r--plugins/plugins-context/plugins-context-distribution/pom.xml41
13 files changed, 943 insertions, 0 deletions
diff --git a/plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-hazelcast/pom.xml b/plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-hazelcast/pom.xml
new file mode 100644
index 000000000..e8fe62565
--- /dev/null
+++ b/plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-hazelcast/pom.xml
@@ -0,0 +1,46 @@
+<!--
+ ============LICENSE_START=======================================================
+ Copyright (C) 2018 Ericsson. All rights reserved.
+ ================================================================================
+ Licensed 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.
+
+ SPDX-License-Identifier: Apache-2.0
+ ============LICENSE_END=========================================================
+-->
+<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.onap.policy.apex-pdp.plugins.plugins-context.plugins-context-distribution</groupId>
+ <artifactId>plugins-context-distribution</artifactId>
+ <version>2.0.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>plugins-context-distribution-hazelcast</artifactId>
+ <name>${project.artifactId}</name>
+ <description>[${project.parent.artifactId}] Plugin for distribution using Hazelcast</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>com.hazelcast</groupId>
+ <artifactId>hazelcast</artifactId>
+ <version>${version.hazelcast}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.onap.policy.apex-pdp.context</groupId>
+ <artifactId>context-test-utils</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-hazelcast/src/main/java/org/onap/policy/apex/plugins/context/distribution/hazelcast/HazelcastContextDistributor.java b/plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-hazelcast/src/main/java/org/onap/policy/apex/plugins/context/distribution/hazelcast/HazelcastContextDistributor.java
new file mode 100644
index 000000000..2b17b17cf
--- /dev/null
+++ b/plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-hazelcast/src/main/java/org/onap/policy/apex/plugins/context/distribution/hazelcast/HazelcastContextDistributor.java
@@ -0,0 +1,106 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * ================================================================================
+ * Licensed 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.apex.plugins.context.distribution.hazelcast;
+
+import java.util.Map;
+
+import org.onap.policy.apex.context.ContextException;
+import org.onap.policy.apex.context.impl.distribution.AbstractDistributor;
+import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
+import org.slf4j.ext.XLogger;
+import org.slf4j.ext.XLoggerFactory;
+
+import com.hazelcast.core.Hazelcast;
+import com.hazelcast.core.HazelcastInstance;
+
+/**
+ * This context distributor distributes context across threads in multiple JVMs on multiple hosts.
+ * It uses hazelcast to distribute maps.
+ *
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class HazelcastContextDistributor extends AbstractDistributor {
+ // Logger for this class
+ private static final XLogger LOGGER = XLoggerFactory.getXLogger(HazelcastContextDistributor.class);
+
+ // The hazelcast instance for distributing context for this JVM
+ private static HazelcastInstance hazelcastInstance = null;
+
+ /**
+ * Create an instance of a Hazelcast Context Distributor.
+ *
+ * @throws ContextException On errors creating the context distributor
+ */
+ public HazelcastContextDistributor() throws ContextException {
+ super();
+ LOGGER.entry("HazelcastContextDistributor()");
+
+ LOGGER.exit("HazelcastContextDistributor()");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.context.impl.distribution.AbstractContextDistributor#init(org.onap.
+ * policy.apex.model.basicmodel.concepts.AxArtifactKey)
+ */
+ @Override
+ public void init(final AxArtifactKey key) throws ContextException {
+ LOGGER.entry("init(" + key + ")");
+
+ super.init(key);
+
+ // Create the hazelcast instance if it does not already exist
+ if (hazelcastInstance == null) {
+ hazelcastInstance = Hazelcast.newHazelcastInstance();
+ }
+
+ LOGGER.exit("init(" + key + ")");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.core.context.impl.distribution.AbstractContextDistributor#
+ * getContextAlbumMap(org.onap.policy.apex.core.model.concepts.AxArtifactKey)
+ */
+ @Override
+ public Map<String, Object> getContextAlbumMap(final AxArtifactKey contextAlbumKey) {
+ // Get the map from Hazelcast
+ LOGGER.info("HazelcastContextDistributor: create album: " + contextAlbumKey.getID());
+ return hazelcastInstance.getMap(contextAlbumKey.getID());
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.onap.policy.apex.core.context.impl.distribution.AbstractContextDistributor#shutdown()
+ */
+ @Override
+ public void shutdown() {
+ // Shut down the hazelcast instance
+ if (hazelcastInstance != null) {
+ hazelcastInstance.shutdown();
+ }
+ hazelcastInstance = null;
+ }
+}
diff --git a/plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-hazelcast/src/main/java/org/onap/policy/apex/plugins/context/distribution/hazelcast/package-info.java b/plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-hazelcast/src/main/java/org/onap/policy/apex/plugins/context/distribution/hazelcast/package-info.java
new file mode 100644
index 000000000..027aeecde
--- /dev/null
+++ b/plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-hazelcast/src/main/java/org/onap/policy/apex/plugins/context/distribution/hazelcast/package-info.java
@@ -0,0 +1,27 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * ================================================================================
+ * Licensed 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+/**
+ * Implements the <a href="http://hazelcast.org/">Hazelcast</a> context distributor for distribution
+ * of Apex context across JVMs.
+ *
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+package org.onap.policy.apex.plugins.context.distribution.hazelcast;
diff --git a/plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-hazelcast/src/main/resources/hazelcast/hazelcast.xml.sample b/plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-hazelcast/src/main/resources/hazelcast/hazelcast.xml.sample
new file mode 100644
index 000000000..5f6c1b005
--- /dev/null
+++ b/plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-hazelcast/src/main/resources/hazelcast/hazelcast.xml.sample
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ============LICENSE_START=======================================================
+ Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ ================================================================================
+ Licensed 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.
+
+ SPDX-License-Identifier: Apache-2.0
+ ============LICENSE_END=========================================================
+-->
+
+<hazelcast xmlns="http://www.hazelcast.com/schema/config"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <group>
+ <name>ApexHazelcastGroup</name>
+ <password>ApexHazelcastGroupPassword</password>
+ </group>
+ <network>
+ <port auto-increment="true">5706</port>
+ <join>
+ <multicast enabled="false">
+ <multicast-group>224.2.2.10</multicast-group>
+ <multicast-port>54327</multicast-port>
+ </multicast>
+ <tcp-ip enabled="true">
+ <members>127.0.0.1</members>
+ </tcp-ip>
+ </join>
+ <interfaces enabled="false">
+ <!-- This value will allow hazelcast to run locally from the IDE -->
+ <interface>127.0.0.*</interface>
+ </interfaces>
+ </network>
+ <properties>
+ <property name="hazelcast.icmp.enabled">true</property>
+ <property name="hazelcast.logging.type">slf4j</property>
+ <!-- disable the hazelcast shutdown hook - prefer to control the shutdown
+ in code -->
+ <property name="hazelcast.shutdownhook.enabled">false</property>
+ <property name="hazelcast.graceful.shutdown.max.wait">60</property>
+ </properties>
+ <executor-service>
+ <pool-size>16</pool-size>
+ </executor-service>
+</hazelcast>
diff --git a/plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-hazelcast/src/test/java/org/onap/policy/apex/plugins/context/distribution/hazelcast/HazelcastContextDistributorTest.java b/plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-hazelcast/src/test/java/org/onap/policy/apex/plugins/context/distribution/hazelcast/HazelcastContextDistributorTest.java
new file mode 100644
index 000000000..c999c95f0
--- /dev/null
+++ b/plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-hazelcast/src/test/java/org/onap/policy/apex/plugins/context/distribution/hazelcast/HazelcastContextDistributorTest.java
@@ -0,0 +1,74 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * ================================================================================
+ * Licensed 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.apex.plugins.context.distribution.hazelcast;
+
+import java.io.IOException;
+
+import org.junit.Test;
+import org.onap.policy.apex.context.parameters.ContextParameters;
+import org.onap.policy.apex.context.test.distribution.ContextAlbumUpdate;
+import org.onap.policy.apex.context.test.distribution.ContextInstantiation;
+import org.onap.policy.apex.context.test.distribution.ContextUpdate;
+import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
+import org.onap.policy.apex.model.basicmodel.handling.ApexModelException;
+import org.slf4j.ext.XLogger;
+import org.slf4j.ext.XLoggerFactory;
+
+public class HazelcastContextDistributorTest {
+ private static final String HAZEL_CAST_PLUGIN_CLASS = HazelcastContextDistributor.class.getCanonicalName();
+ // Logger for this class
+ private static final XLogger logger = XLoggerFactory.getXLogger(HazelcastContextDistributorTest.class);
+
+
+ @Test
+ public void testContextAlbumUpdateHazelcast() throws ApexModelException, IOException, ApexException {
+ logger.debug("Running testContextAlbumUpdateHazelcast test . . .");
+
+ final ContextParameters contextParameters = new ContextParameters();
+ contextParameters.getDistributorParameters().setPluginClass(HAZEL_CAST_PLUGIN_CLASS);
+ new ContextAlbumUpdate().testContextAlbumUpdate();
+
+ logger.debug("Ran testContextAlbumUpdateHazelcast test");
+ }
+
+ @Test
+ public void testContextInstantiationHazelcast() throws ApexModelException, IOException, ApexException {
+ logger.debug("Running testContextInstantiationHazelcast test . . .");
+
+ final ContextParameters contextParameters = new ContextParameters();
+ contextParameters.getDistributorParameters().setPluginClass(HAZEL_CAST_PLUGIN_CLASS);
+ new ContextInstantiation().testContextInstantiation();
+
+ logger.debug("Ran testContextInstantiationHazelcast test");
+ }
+
+ @Test
+ public void testContextUpdateHazelcast() throws ApexModelException, IOException, ApexException {
+ logger.debug("Running testContextUpdateHazelcast test . . .");
+
+ final ContextParameters contextParameters = new ContextParameters();
+ contextParameters.getDistributorParameters().setPluginClass(HAZEL_CAST_PLUGIN_CLASS);
+ new ContextUpdate().testContextUpdate();
+
+ logger.debug("Ran testContextUpdateHazelcast test");
+ }
+
+}
diff --git a/plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-infinispan/pom.xml b/plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-infinispan/pom.xml
new file mode 100644
index 000000000..96ed6e85e
--- /dev/null
+++ b/plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-infinispan/pom.xml
@@ -0,0 +1,53 @@
+<!--
+ ============LICENSE_START=======================================================
+ Copyright (C) 2018 Ericsson. All rights reserved.
+ ================================================================================
+ Licensed 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.
+
+ SPDX-License-Identifier: Apache-2.0
+ ============LICENSE_END=========================================================
+-->
+<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.onap.policy.apex-pdp.plugins.plugins-context.plugins-context-distribution</groupId>
+ <artifactId>plugins-context-distribution</artifactId>
+ <version>2.0.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>plugins-context-distribution-infinispan</artifactId>
+ <name>${project.artifactId}</name>
+ <description>[${project.parent.artifactId}] Plugin for distribution using Infinispan</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.infinispan</groupId>
+ <artifactId>infinispan-core</artifactId>
+ <version>9.2.2.Final</version>
+ <exclusions>
+ <exclusion>
+ <groupId>org.jboss.slf4j</groupId>
+ <artifactId>slf4j-jboss-logging</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.onap.policy.apex-pdp.context</groupId>
+ <artifactId>context-test-utils</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+</project>
diff --git a/plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-infinispan/src/main/java/org/onap/policy/apex/plugins/context/distribution/infinispan/InfinispanContextDistributor.java b/plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-infinispan/src/main/java/org/onap/policy/apex/plugins/context/distribution/infinispan/InfinispanContextDistributor.java
new file mode 100644
index 000000000..9361d0b4c
--- /dev/null
+++ b/plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-infinispan/src/main/java/org/onap/policy/apex/plugins/context/distribution/infinispan/InfinispanContextDistributor.java
@@ -0,0 +1,115 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * ================================================================================
+ * Licensed 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.apex.plugins.context.distribution.infinispan;
+
+import java.util.Map;
+
+import org.infinispan.Cache;
+import org.onap.policy.apex.context.ContextException;
+import org.onap.policy.apex.context.impl.distribution.AbstractDistributor;
+import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
+import org.onap.policy.apex.model.basicmodel.service.ParameterService;
+import org.slf4j.ext.XLogger;
+import org.slf4j.ext.XLoggerFactory;
+
+/**
+ * This context distributor distributes context across threads in multiple JVMs on multiple hosts.
+ * It uses Infinispan to distribute maps.
+ *
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class InfinispanContextDistributor extends AbstractDistributor {
+ // Logger for this class
+ private static final XLogger LOGGER = XLoggerFactory.getXLogger(InfinispanContextDistributor.class);
+
+ // The infinispan manager for distributing context for this JVM
+ private static InfinispanManager infinispanManager = null;
+
+ /**
+ * Create an instance of an Infinispan Context Distributor.
+ *
+ * @throws ContextException On errors creating the context distributor
+ */
+ public InfinispanContextDistributor() throws ContextException {
+ LOGGER.entry("InfinispanContextDistributor()");
+
+ LOGGER.exit("InfinispanContextDistributor()");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * com.ericsson.apex.context.impl.distribution.AbstractContextDistributor#init(com.ericsson.apex
+ * .model.basicmodel.concepts.AxArtifactKey)
+ */
+ @Override
+ public void init(final AxArtifactKey key) throws ContextException {
+ LOGGER.entry("init(" + key + ")");
+
+ super.init(key);
+
+ // Create the infinispan manager if it does not already exist
+ if (infinispanManager == null) {
+ // Get the parameters from the parameter service
+ final InfinispanDistributorParameters parameters =
+ ParameterService.getParameters(InfinispanDistributorParameters.class);
+
+ LOGGER.debug("initiating Infinispan with the parameters: " + parameters);
+
+ // Create the manager
+ infinispanManager = new InfinispanManager(parameters);
+ }
+
+ LOGGER.exit("init(" + key + ")");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.ericsson.apex.core.context.impl.distribution.AbstractContextDistributor#
+ * getContextAlbumMap(com.ericsson.apex.core.model.concepts.AxArtifactKey)
+ */
+ @Override
+ public Map<String, Object> getContextAlbumMap(final AxArtifactKey contextAlbumKey) {
+ LOGGER.info("InfinispanContextDistributor: create album: " + contextAlbumKey.getID());
+
+ // Get the Cache from Infinispan
+ final Cache<String, Object> infinispanCache =
+ infinispanManager.getCacheManager().getCache(contextAlbumKey.getID().replace(':', '_'));
+
+ return infinispanCache;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.ericsson.apex.core.context.impl.distribution.AbstractContextDistributor#shutdown()
+ */
+ @Override
+ public void shutdown() {
+ // Shut down the infinispan manager
+ if (infinispanManager != null) {
+ infinispanManager.shutdown();
+ }
+ infinispanManager = null;
+ }
+}
diff --git a/plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-infinispan/src/main/java/org/onap/policy/apex/plugins/context/distribution/infinispan/InfinispanDistributorParameters.java b/plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-infinispan/src/main/java/org/onap/policy/apex/plugins/context/distribution/infinispan/InfinispanDistributorParameters.java
new file mode 100644
index 000000000..d73955224
--- /dev/null
+++ b/plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-infinispan/src/main/java/org/onap/policy/apex/plugins/context/distribution/infinispan/InfinispanDistributorParameters.java
@@ -0,0 +1,144 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * ================================================================================
+ * Licensed 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.apex.plugins.context.distribution.infinispan;
+
+import org.onap.policy.apex.context.parameters.DistributorParameters;
+import org.onap.policy.apex.model.basicmodel.service.ParameterService;
+
+/**
+ * Distributor parameters for the Infinspan Distributor.
+ *
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class InfinispanDistributorParameters extends DistributorParameters {
+ // @formatter:off
+
+ /** The default Infinispan configuration file location. */
+ public static final String DEFAULT_INFINISPAN_DISTRIBUTION_CONFIG_FILE = "/infinispan/infinispan.xml";
+
+ /** The default Infinispan jgroups configuration file location. */
+ public static final String DEFAULT_INFINISPAN_DISTRIBUTION_JGROUPS_FILE = null;
+
+ /** The default Infinispan IP stack is IPV4. */
+ public static final boolean DEFAULT_INFINISPAN_JAVA_NET_PREFER_IPV4_STACK = true;
+
+ /** The default Infinispan bind address is localhost. */
+ public static final String DEFAULT_INFINSPAN_JGROUPS_BIND_ADDRESS = "localhost";
+
+ // Infinspan configuration file names
+ private String configFile = DEFAULT_INFINISPAN_DISTRIBUTION_CONFIG_FILE;
+ private String jgroupsFile = DEFAULT_INFINISPAN_DISTRIBUTION_JGROUPS_FILE;
+ private boolean preferIPv4Stack = DEFAULT_INFINISPAN_JAVA_NET_PREFER_IPV4_STACK;
+ private String jGroupsBindAddress = DEFAULT_INFINSPAN_JGROUPS_BIND_ADDRESS;
+ // @formatter:on
+
+ /**
+ * The Constructor.
+ */
+ public InfinispanDistributorParameters() {
+ super(InfinispanDistributorParameters.class.getCanonicalName());
+ ParameterService.registerParameters(InfinispanDistributorParameters.class, this);
+ ParameterService.registerParameters(DistributorParameters.class, this);
+ }
+
+ /**
+ * Gets the config file.
+ *
+ * @return the config file
+ */
+ public String getConfigFile() {
+ return configFile;
+ }
+
+ /**
+ * Sets the config file.
+ *
+ * @param configFile the config file
+ */
+ public void setConfigFile(final String configFile) {
+ this.configFile = configFile;
+ }
+
+ /**
+ * Gets the jgroups file.
+ *
+ * @return the jgroups file
+ */
+ public String getJgroupsFile() {
+ return jgroupsFile;
+ }
+
+ /**
+ * Sets the jgroups file.
+ *
+ * @param jgroupsFile the jgroups file
+ */
+ public void setJgroupsFile(final String jgroupsFile) {
+ this.jgroupsFile = jgroupsFile;
+ }
+
+ /**
+ * Prefer I pv 4 stack.
+ *
+ * @return true, if prefer I pv 4 stack
+ */
+ public boolean preferIPv4Stack() {
+ return preferIPv4Stack;
+ }
+
+ /**
+ * Sets the prefer I pv 4 stack.
+ *
+ * @param preferIPv4Stack the prefer I pv 4 stack
+ */
+ public void setPreferIPv4Stack(final boolean preferIPv4Stack) {
+ this.preferIPv4Stack = preferIPv4Stack;
+ }
+
+ /**
+ * Getj groups bind address.
+ *
+ * @return the j groups bind address
+ */
+ public String getjGroupsBindAddress() {
+ return jGroupsBindAddress;
+ }
+
+ /**
+ * Setj groups bind address.
+ *
+ * @param jGroupsBindAddress the j groups bind address
+ */
+ public void setjGroupsBindAddress(final String jGroupsBindAddress) {
+ this.jGroupsBindAddress = jGroupsBindAddress;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.ericsson.apex.context.parameters.DistributorParameters#toString()
+ */
+ @Override
+ public String toString() {
+ return "InfinispanDistributorParameters [configFile=" + configFile + ", jgroupsFile=" + jgroupsFile
+ + ", preferIPv4Stack=" + preferIPv4Stack + ", jGroupsBindAddress=" + jGroupsBindAddress + "]";
+ }
+}
diff --git a/plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-infinispan/src/main/java/org/onap/policy/apex/plugins/context/distribution/infinispan/InfinispanManager.java b/plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-infinispan/src/main/java/org/onap/policy/apex/plugins/context/distribution/infinispan/InfinispanManager.java
new file mode 100644
index 000000000..1a2076f10
--- /dev/null
+++ b/plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-infinispan/src/main/java/org/onap/policy/apex/plugins/context/distribution/infinispan/InfinispanManager.java
@@ -0,0 +1,122 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * ================================================================================
+ * Licensed 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.apex.plugins.context.distribution.infinispan;
+
+import java.io.IOException;
+
+import org.infinispan.manager.DefaultCacheManager;
+import org.infinispan.manager.EmbeddedCacheManager;
+import org.onap.policy.apex.context.ContextException;
+import org.slf4j.ext.XLogger;
+import org.slf4j.ext.XLoggerFactory;
+
+/**
+ * The Class InfinispanManager holds the Infinispan cache manager for a JVM.
+ */
+public class InfinispanManager {
+ // Logger for this class
+ private static final XLogger LOGGER = XLoggerFactory.getXLogger(InfinispanManager.class);
+
+ // The Infinispan Cache Manager
+ private EmbeddedCacheManager cacheManager;
+
+ /**
+ * Constructor, set up an Infinispan cache manager.
+ *
+ * @param infinispanDistributorParameters the infinispan distributor parameters
+ * @throws ContextException On errors connecting to Infinispan
+ */
+ public InfinispanManager(final InfinispanDistributorParameters infinispanDistributorParameters)
+ throws ContextException {
+ LOGGER.entry("Creating Infinispan Manager: " + infinispanDistributorParameters);
+
+ setSystemProperties(infinispanDistributorParameters);
+
+ try {
+ LOGGER.debug("starting infinispan cache manager using specified configuration . . .");
+ cacheManager = new DefaultCacheManager(infinispanDistributorParameters.getConfigFile());
+ LOGGER.debug("started infinispan cache manager using specified configuration");
+ } catch (final IOException ioException) {
+ final String errorMessage =
+ "failed to start infinispan cache manager, no infinispan configuration found on local file system or in classpath, "
+ + "try setting Infinspan \"configFile\" parameter";
+ LOGGER.error(errorMessage);
+ throw new ContextException(errorMessage, ioException);
+ } catch (final Exception e) {
+ LOGGER.error("failed to start infinispan cache manager using specified configuration", e);
+ throw new ContextException("failed to start infinispan cache manager using specified configuration", e);
+ }
+
+ // Start the cache manager
+ cacheManager.start();
+
+ Runtime.getRuntime().addShutdownHook(new InfinspanManagerShutdownHook());
+
+ LOGGER.exit("Created Infinispan Manager: " + infinispanDistributorParameters);
+ }
+
+ /**
+ * Shutdown the manager.
+ */
+ public void shutdown() {
+ if (cacheManager == null) {
+ return;
+ }
+
+ cacheManager.stop();
+ cacheManager = null;
+ }
+
+ /**
+ * Get the cache manager.
+ *
+ * @return the infinispan cache manager
+ */
+ public EmbeddedCacheManager getCacheManager() {
+ return cacheManager;
+ }
+
+ /**
+ * Set system properties used by Infinispan.
+ *
+ * @param infinispanDistributorParameters The parameter values to set are passed as properties
+ */
+ private void setSystemProperties(final InfinispanDistributorParameters infinispanDistributorParameters) {
+ System.setProperty("java.net.preferIPv4Stack",
+ Boolean.toString(infinispanDistributorParameters.preferIPv4Stack()));
+ System.setProperty("jgroups.bind_addr", infinispanDistributorParameters.getjGroupsBindAddress());
+ }
+
+ /**
+ * Private class to implement the shutdown hook for this infinispan manager.
+ */
+ public class InfinspanManagerShutdownHook extends Thread {
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Thread#run()
+ */
+ @Override
+ public void run() {
+ shutdown();
+ }
+ }
+}
diff --git a/plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-infinispan/src/main/java/org/onap/policy/apex/plugins/context/distribution/infinispan/package-info.java b/plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-infinispan/src/main/java/org/onap/policy/apex/plugins/context/distribution/infinispan/package-info.java
new file mode 100644
index 000000000..b9ceeb668
--- /dev/null
+++ b/plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-infinispan/src/main/java/org/onap/policy/apex/plugins/context/distribution/infinispan/package-info.java
@@ -0,0 +1,27 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * ================================================================================
+ * Licensed 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+/**
+ * Implements the <a href="http://infinispan.org/">Infinispan</a> context distributor for
+ * distribution of APEX context across JVMs.
+ *
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+package org.onap.policy.apex.plugins.context.distribution.infinispan;
diff --git a/plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-infinispan/src/main/resources/infinispan/infinispan.xml.sample b/plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-infinispan/src/main/resources/infinispan/infinispan.xml.sample
new file mode 100644
index 000000000..302eac935
--- /dev/null
+++ b/plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-infinispan/src/main/resources/infinispan/infinispan.xml.sample
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ============LICENSE_START=======================================================
+ Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ ================================================================================
+ Licensed 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.
+
+ SPDX-License-Identifier: Apache-2.0
+ ============LICENSE_END=========================================================
+-->
+
+<infinispan xmlns="urn:infinispan:config:8.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:infinispan:config:8.0 http://infinispan.org/schemas/infinispan-config-8.0.xsd">
+ <jgroups>
+ <stack-file name="tcpStack" path="default-configs/default-jgroups-tcp.xml" />
+ </jgroups>
+
+ <cache-container name="ApexCacheContainer" default-cache="TestContext_0.0.1">
+ <transport cluster="apexCluster" stack="tcpStack" />
+ <jmx />
+ <replicated-cache name="LargeContextMap_0.0.1" mode="SYNC" statistics="true">
+ <state-transfer enabled="true" />
+ </replicated-cache>
+ <replicated-cache name="LongSameTypeContextMap_0.0.1" mode="SYNC" statistics="true">
+ <state-transfer enabled="true" />
+ </replicated-cache>
+ <replicated-cache name="TestContext_0.0.1" mode="SYNC">
+ <state-transfer enabled="true" />
+ </replicated-cache>
+ </cache-container>
+</infinispan>
diff --git a/plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-infinispan/src/test/java/org/onap/policy/apex/plugins/context/distribution/infinispan/InfinispanContextDistributorTest.java b/plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-infinispan/src/test/java/org/onap/policy/apex/plugins/context/distribution/infinispan/InfinispanContextDistributorTest.java
new file mode 100644
index 000000000..34fa7d439
--- /dev/null
+++ b/plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-infinispan/src/test/java/org/onap/policy/apex/plugins/context/distribution/infinispan/InfinispanContextDistributorTest.java
@@ -0,0 +1,93 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Ericsson. All rights reserved.
+ * ================================================================================
+ * Licensed 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.policy.apex.plugins.context.distribution.infinispan;
+
+import java.io.IOException;
+
+import org.junit.Test;
+import org.onap.policy.apex.context.parameters.ContextParameters;
+import org.onap.policy.apex.context.test.distribution.ContextAlbumUpdate;
+import org.onap.policy.apex.context.test.distribution.ContextInstantiation;
+import org.onap.policy.apex.context.test.distribution.ContextUpdate;
+import org.onap.policy.apex.context.test.distribution.SequentialContextInstantiation;
+import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
+import org.onap.policy.apex.model.basicmodel.handling.ApexModelException;
+import org.slf4j.ext.XLogger;
+import org.slf4j.ext.XLoggerFactory;
+
+public class InfinispanContextDistributorTest {
+ private static final XLogger logger = XLoggerFactory.getXLogger(InfinispanContextDistributorTest.class);
+
+ private static final String PLUGIN_CLASS = InfinispanContextDistributor.class.getCanonicalName();
+
+ @Test
+ public void testContextAlbumUpdateInfinispan() throws ApexModelException, IOException, ApexException {
+ logger.debug("Running testContextAlbumUpdateInfinispan test . . .");
+
+ final ContextParameters contextParameters = new ContextParameters();
+ contextParameters.getDistributorParameters().setPluginClass(PLUGIN_CLASS);
+ new InfinispanDistributorParameters();
+
+ new ContextAlbumUpdate().testContextAlbumUpdate();
+
+ logger.debug("Ran testContextAlbumUpdateInfinispan test");
+ }
+
+ @Test
+ public void testContextInstantiationInfinispan() throws ApexModelException, IOException, ApexException {
+ logger.debug("Running testContextInstantiationInfinispan test . . .");
+
+ final ContextParameters contextParameters = new ContextParameters();
+ contextParameters.getDistributorParameters().setPluginClass(PLUGIN_CLASS);
+ new InfinispanDistributorParameters();
+
+ new ContextInstantiation().testContextInstantiation();
+
+ logger.debug("Ran testContextInstantiationInfinispan test");
+ }
+
+ @Test
+ public void testContextUpdateInfinispan() throws ApexModelException, IOException, ApexException {
+ logger.debug("Running testContextUpdateInfinispan test . . .");
+
+ final ContextParameters contextParameters = new ContextParameters();
+ contextParameters.getDistributorParameters().setPluginClass(PLUGIN_CLASS);
+ new InfinispanDistributorParameters();
+
+ new ContextUpdate().testContextUpdate();
+
+ logger.debug("Ran testContextUpdateInfinispan test");
+ }
+
+ @Test
+ public void testSequentialContextInstantiationInfinispan() throws ApexModelException, IOException, ApexException {
+ logger.debug("Running testSequentialContextInstantiationInfinispan test . . .");
+
+ final ContextParameters contextParameters = new ContextParameters();
+ contextParameters.getDistributorParameters().setPluginClass(PLUGIN_CLASS);
+ new InfinispanDistributorParameters();
+
+ new SequentialContextInstantiation().testSequentialContextInstantiation();
+
+ logger.debug("Ran testSequentialContextInstantiationInfinispan test");
+ }
+
+
+}
diff --git a/plugins/plugins-context/plugins-context-distribution/pom.xml b/plugins/plugins-context/plugins-context-distribution/pom.xml
new file mode 100644
index 000000000..0433b33f6
--- /dev/null
+++ b/plugins/plugins-context/plugins-context-distribution/pom.xml
@@ -0,0 +1,41 @@
+<!--
+ ============LICENSE_START=======================================================
+ Copyright (C) 2018 Ericsson. All rights reserved.
+ ================================================================================
+ Licensed 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.
+
+ SPDX-License-Identifier: Apache-2.0
+ ============LICENSE_END=========================================================
+-->
+
+<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.onap.policy.apex-pdp.plugins.plugins-context</groupId>
+ <artifactId>plugins-context</artifactId>
+ <version>2.0.0-SNAPSHOT</version>
+ </parent>
+
+ <groupId>org.onap.policy.apex-pdp.plugins.plugins-context.plugins-context-distribution</groupId>
+ <artifactId>plugins-context-distribution</artifactId>
+ <packaging>pom</packaging>
+
+ <name>${project.artifactId}</name>
+ <description>Plugins for 3pps that distribute context</description>
+
+ <modules>
+ <module>plugins-context-distribution-hazelcast</module>
+ <module>plugins-context-distribution-infinispan</module>
+ </modules>
+</project>