diff options
Diffstat (limited to 'plugins')
7 files changed, 304 insertions, 37 deletions
diff --git a/plugins/plugins-context/plugins-context-locking/plugins-context-locking-curator/pom.xml b/plugins/plugins-context/plugins-context-locking/plugins-context-locking-curator/pom.xml index 2dcdcf8de..8424969d7 100644 --- a/plugins/plugins-context/plugins-context-locking/plugins-context-locking-curator/pom.xml +++ b/plugins/plugins-context/plugins-context-locking/plugins-context-locking-curator/pom.xml @@ -1,6 +1,7 @@ <!-- ============LICENSE_START======================================================= Copyright (C) 2018 Ericsson. All rights reserved. + Modifications Copyright (C) 2019 Nordix Foundation. ================================================================================ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -47,11 +48,11 @@ <artifactId>curator-recipes</artifactId> <version>4.0.1</version> </dependency> - <!-- The latest Zookeeper version fixes the vulnerabilities --> + <!-- This Zookeeper version fixes the vulnerabilities --> <dependency> <groupId>org.apache.zookeeper</groupId> <artifactId>zookeeper</artifactId> - <version>3.5.4-beta</version> + <version>3.4.13</version> <exclusions> <!-- Zookeeper uses an ancient version of log4j --> <exclusion> diff --git a/plugins/plugins-context/plugins-context-locking/plugins-context-locking-curator/src/main/java/org/onap/policy/apex/plugins/context/locking/curator/CuratorLockManager.java b/plugins/plugins-context/plugins-context-locking/plugins-context-locking-curator/src/main/java/org/onap/policy/apex/plugins/context/locking/curator/CuratorLockManager.java index bc8ce9055..ce727b8bf 100644 --- a/plugins/plugins-context/plugins-context-locking/plugins-context-locking-curator/src/main/java/org/onap/policy/apex/plugins/context/locking/curator/CuratorLockManager.java +++ b/plugins/plugins-context/plugins-context-locking/plugins-context-locking-curator/src/main/java/org/onap/policy/apex/plugins/context/locking/curator/CuratorLockManager.java @@ -1,19 +1,20 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. * ================================================================================ * 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========================================================= */ @@ -32,6 +33,8 @@ import org.apache.curator.utils.CloseableUtils; import org.apache.zookeeper.CreateMode; import org.onap.policy.apex.context.ContextException; import org.onap.policy.apex.context.impl.locking.AbstractLockManager; +import org.onap.policy.apex.context.parameters.ContextParameterConstants; +import org.onap.policy.apex.context.parameters.LockManagerParameters; import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; import org.onap.policy.common.parameters.ParameterService; import org.slf4j.ext.XLogger; @@ -75,11 +78,19 @@ public class CuratorLockManager extends AbstractLockManager { super.init(key); // Get the lock manager parameters - final CuratorLockManagerParameters lockParameters = ParameterService - .get(CuratorLockManagerParameters.class.getSimpleName()); + final LockManagerParameters lockParameters = ParameterService.get(ContextParameterConstants.LOCKING_GROUP_NAME); + + if (!(lockParameters instanceof CuratorLockManagerParameters)) { + String message = "could not set up Curator locking, " + + "curator lock manager parameters are not set"; + LOGGER.warn(message); + throw new ContextException(message); + } + + final CuratorLockManagerParameters curatorLockPars = (CuratorLockManagerParameters)lockParameters; // Check if the curator address has been set - curatorZookeeperAddress = lockParameters.getZookeeperAddress(); + curatorZookeeperAddress = curatorLockPars.getZookeeperAddress(); if (curatorZookeeperAddress == null || curatorZookeeperAddress.trim().length() == 0) { String message = "could not set up Curator locking, " + "check if the curator Zookeeper address parameter is set correctly"; @@ -89,8 +100,8 @@ public class CuratorLockManager extends AbstractLockManager { // Set up the curator framework we'll use curatorFramework = CuratorFrameworkFactory.builder().connectString(curatorZookeeperAddress) - .retryPolicy(new ExponentialBackoffRetry(lockParameters.getZookeeperConnectSleepTime(), - lockParameters.getZookeeperContextRetries())) + .retryPolicy(new ExponentialBackoffRetry(curatorLockPars.getZookeeperConnectSleepTime(), + curatorLockPars.getZookeeperContextRetries())) .build(); // Listen for changes on the Curator connection @@ -102,8 +113,8 @@ public class CuratorLockManager extends AbstractLockManager { // Wait for the connection to be made try { curatorFramework.blockUntilConnected( - lockParameters.getZookeeperConnectSleepTime() * lockParameters.getZookeeperContextRetries(), - TimeUnit.MILLISECONDS); + curatorLockPars.getZookeeperConnectSleepTime() * curatorLockPars.getZookeeperContextRetries(), + TimeUnit.MILLISECONDS); } catch (final InterruptedException e) { // restore the interrupt status Thread.currentThread().interrupt(); @@ -123,7 +134,7 @@ public class CuratorLockManager extends AbstractLockManager { // We'll use Ephemeral nodes for locks on the Zookeeper server curatorFramework.create().withMode(CreateMode.EPHEMERAL_SEQUENTIAL); - LOGGER.exit("init(" + key + "," + lockParameters + ")"); + LOGGER.exit("init(" + key + "," + curatorLockPars + ")"); } /* diff --git a/plugins/plugins-context/plugins-context-locking/plugins-context-locking-curator/src/main/java/org/onap/policy/apex/plugins/context/locking/curator/CuratorLockManagerParameters.java b/plugins/plugins-context/plugins-context-locking/plugins-context-locking-curator/src/main/java/org/onap/policy/apex/plugins/context/locking/curator/CuratorLockManagerParameters.java index ac936d436..39972a7f1 100644 --- a/plugins/plugins-context/plugins-context-locking/plugins-context-locking-curator/src/main/java/org/onap/policy/apex/plugins/context/locking/curator/CuratorLockManagerParameters.java +++ b/plugins/plugins-context/plugins-context-locking/plugins-context-locking-curator/src/main/java/org/onap/policy/apex/plugins/context/locking/curator/CuratorLockManagerParameters.java @@ -1,19 +1,20 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. * ================================================================================ * 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========================================================= */ @@ -30,7 +31,7 @@ import org.onap.policy.apex.context.parameters.LockManagerParameters; public class CuratorLockManagerParameters extends LockManagerParameters { // @formatter:off /** The default address used to connect to the Zookeeper server. */ - public static final String DEFAULT_ZOOKEEPER_ADDRESS = "localhost:2181"; + public static final String DEFAULT_ZOOKEEPER_ADDRESS = "localhost:2181"; /** The default sleep time to use when connecting to the Zookeeper server. */ public static final int DEFAULT_ZOOKEEPER_CONNECT_SLEEP_TIME = 1000; diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/test/java/org/onap/policy/apex/plugins/event/carrier/kafka/ApexKafkaConsumerTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/test/java/org/onap/policy/apex/plugins/event/carrier/kafka/ApexKafkaConsumerTest.java new file mode 100644 index 000000000..bbebbc3b8 --- /dev/null +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/test/java/org/onap/policy/apex/plugins/event/carrier/kafka/ApexKafkaConsumerTest.java @@ -0,0 +1,97 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Samsung. 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.event.carrier.kafka; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import org.junit.Before; +import org.junit.Test; +import org.onap.policy.apex.service.engine.event.ApexEventException; +import org.onap.policy.apex.service.engine.event.ApexEventProducer; +import org.onap.policy.apex.service.engine.event.ApexEventReceiver; +import org.onap.policy.apex.service.engine.event.PeeredReference; +import org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnologyParameters; +import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters; +import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMode; + +public class ApexKafkaConsumerTest { + ApexKafkaConsumer apexKafkaConsumer = null; + EventHandlerParameters consumerParameters = null; + ApexEventReceiver incomingEventReceiver = null; + ApexEventProducer apexKafkaProducer = null; + + /** + * Set up testing. + * + * @throws ApexEventException on test set up errors. + */ + @Before + public void setUp() throws ApexEventException { + apexKafkaConsumer = new ApexKafkaConsumer(); + consumerParameters = new EventHandlerParameters(); + apexKafkaProducer = new ApexKafkaProducer(); + consumerParameters + .setCarrierTechnologyParameters(new KafkaCarrierTechnologyParameters() {}); + apexKafkaConsumer.init("TestApexKafkaConsumer", consumerParameters, incomingEventReceiver); + } + + @Test + public void testStart() { + apexKafkaConsumer.start(); + } + + @Test + public void testGetName() { + assertEquals("TestApexKafkaConsumer", apexKafkaConsumer.getName()); + } + + @Test + public void testGetPeeredReference() { + assertNull(apexKafkaConsumer.getPeeredReference(EventHandlerPeeredMode.REQUESTOR)); + } + + @Test + public void testSetPeeredReference() { + PeeredReference peeredReference = new PeeredReference(EventHandlerPeeredMode.REQUESTOR, + apexKafkaConsumer, apexKafkaProducer); + apexKafkaConsumer.setPeeredReference(EventHandlerPeeredMode.REQUESTOR, peeredReference); + assertNotNull(apexKafkaConsumer.getPeeredReference(EventHandlerPeeredMode.REQUESTOR)); + } + + @Test(expected = java.lang.NullPointerException.class) + public void testRun() { + apexKafkaConsumer.run(); + } + + @Test(expected = java.lang.NullPointerException.class) + public void testStop() { + apexKafkaConsumer.stop(); + } + + @Test(expected = ApexEventException.class) + public void testInitWithNonKafkaCarrierTechnologyParameters() throws ApexEventException { + consumerParameters.setCarrierTechnologyParameters(new CarrierTechnologyParameters() {}); + apexKafkaConsumer.init("TestApexKafkaConsumer", consumerParameters, incomingEventReceiver); + } + +} diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/test/java/org/onap/policy/apex/plugins/event/carrier/kafka/ApexKafkaProducerTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/test/java/org/onap/policy/apex/plugins/event/carrier/kafka/ApexKafkaProducerTest.java new file mode 100644 index 000000000..7300474c7 --- /dev/null +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/test/java/org/onap/policy/apex/plugins/event/carrier/kafka/ApexKafkaProducerTest.java @@ -0,0 +1,83 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Samsung. 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.event.carrier.kafka; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import org.junit.Before; +import org.junit.Test; +import org.onap.policy.apex.service.engine.event.ApexEventException; +import org.onap.policy.apex.service.engine.event.PeeredReference; +import org.onap.policy.apex.service.engine.event.SynchronousEventCache; +import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters; +import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMode; + +public class ApexKafkaProducerTest { + ApexKafkaProducer apexKafkaProducer = null; + ApexKafkaConsumer apexKafkaConsumer = null; + EventHandlerParameters producerParameters = null; + PeeredReference peeredReference = null; + SynchronousEventCache synchronousEventCache = null; + private static final long DEFAULT_SYNCHRONOUS_EVENT_TIMEOUT = 1000; + + /** + * Set up testing. + */ + @Before + public void setUp() throws Exception { + apexKafkaProducer = new ApexKafkaProducer(); + apexKafkaConsumer = new ApexKafkaConsumer(); + producerParameters = new EventHandlerParameters(); + + } + + @Test(expected = ApexEventException.class) + public void testInit() throws ApexEventException { + apexKafkaProducer.init("TestApexKafkaProducer", producerParameters); + } + + @Test + public void testGetName() { + assertNull(apexKafkaProducer.getName()); + } + + @Test + public void testGetPeeredReference() { + assertNull(apexKafkaProducer.getPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS)); + } + + @Test + public void testWithProperValues() throws ApexEventException { + producerParameters + .setCarrierTechnologyParameters(new KafkaCarrierTechnologyParameters() {}); + synchronousEventCache = new SynchronousEventCache(EventHandlerPeeredMode.SYNCHRONOUS, + apexKafkaConsumer, apexKafkaProducer, DEFAULT_SYNCHRONOUS_EVENT_TIMEOUT); + apexKafkaProducer.setPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS, + synchronousEventCache); + apexKafkaProducer.init("TestApexKafkaProducer", producerParameters); + assertEquals("TestApexKafkaProducer", apexKafkaProducer.getName()); + assertNotNull(apexKafkaProducer.getPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS)); + apexKafkaProducer.stop(); + } + +} diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/test/java/org/onap/policy/apex/plugins/event/carrier/kafka/KafkaCarrierTechnologyParametersTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/test/java/org/onap/policy/apex/plugins/event/carrier/kafka/KafkaCarrierTechnologyParametersTest.java new file mode 100644 index 000000000..6eca1dcf0 --- /dev/null +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/test/java/org/onap/policy/apex/plugins/event/carrier/kafka/KafkaCarrierTechnologyParametersTest.java @@ -0,0 +1,69 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Samsung. 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.event.carrier.kafka; + +import static org.junit.Assert.assertNotNull; + +import java.util.Properties; +import org.junit.Before; +import org.junit.Test; +import org.onap.policy.common.parameters.GroupValidationResult; + +public class KafkaCarrierTechnologyParametersTest { + + KafkaCarrierTechnologyParameters kafkaCarrierTechnologyParameters = null; + Properties kafkaProducerProperties = null; + Properties kafkaConsumerProperties = null; + GroupValidationResult result = null; + + /** + * Set up testing. + * + * @throws Exception on setup errors + */ + @Before + public void setUp() throws Exception { + kafkaCarrierTechnologyParameters = new KafkaCarrierTechnologyParameters(); + kafkaProducerProperties = kafkaCarrierTechnologyParameters.getKafkaProducerProperties(); + kafkaConsumerProperties = kafkaCarrierTechnologyParameters.getKafkaConsumerProperties(); + } + + @Test + public void testKafkaCarrierTechnologyParameters() { + assertNotNull(kafkaCarrierTechnologyParameters); + } + + @Test + public void testGetKafkaProducerProperties() { + assertNotNull(kafkaProducerProperties); + } + + @Test + public void testGetKafkaConsumerProperties() { + assertNotNull(kafkaConsumerProperties); + } + + @Test + public void testValidate() { + result = kafkaCarrierTechnologyParameters.validate(); + assertNotNull(result); + } +} diff --git a/plugins/plugins-persistence/plugins-persistence-jpa/plugins-persistence-jpa-hibernate/pom.xml b/plugins/plugins-persistence/plugins-persistence-jpa/plugins-persistence-jpa-hibernate/pom.xml index 2343a3ab8..ae2def8d2 100644 --- a/plugins/plugins-persistence/plugins-persistence-jpa/plugins-persistence-jpa-hibernate/pom.xml +++ b/plugins/plugins-persistence/plugins-persistence-jpa/plugins-persistence-jpa-hibernate/pom.xml @@ -1,23 +1,17 @@ -<!-- - ============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"> +<!-- ============LICENSE_START======================================================= + Copyright (C) 2018 Ericsson. All rights reserved. Modifications Copyright + (C) 2019 Nordix Foundation. ================================================================================ + 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-persistence.plugins-persistence-jpa</groupId> @@ -72,6 +66,17 @@ <groupId>org.hibernate</groupId> <artifactId>hibernate-c3p0</artifactId> <version>${version.hibernate}</version> + <exclusions> + <exclusion> + <groupId>com.mchange</groupId> + <artifactId>c3p0</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>com.mchange</groupId> + <artifactId>c3p0</artifactId> + <version>0.9.5.3</version> </dependency> </dependencies> |