From adcd4f2bc695840e9ecbc05003bc52c675f22fec Mon Sep 17 00:00:00 2001 From: KAPIL SINGAL Date: Fri, 22 Jan 2021 11:49:51 -0500 Subject: Renaming Files having BluePrint to have Blueprint Replacing BluePrint with Blueprint throughout Issue-ID: CCSDK-3098 Signed-off-by: KAPIL SINGAL Change-Id: Ibee8bad07ae7d9287073db2d4f2f2cd730fa8b96 --- .../core/BluePrintCoreConfiguration.kt | 88 ------------- .../core/BlueprintCoreConfiguration.kt | 88 +++++++++++++ .../core/api/data/BlueprintProcessorData.kt | 4 +- .../core/cluster/BluePrintClusterExtensions.kt | 75 ----------- .../core/cluster/BlueprintClusterExtensions.kt | 75 +++++++++++ .../core/cluster/HazelcastClusterService.kt | 24 ++-- .../core/factory/ComponentNodeFactory.kt | 10 +- .../BlueprintCompilerCacheMessageListener.kt | 12 +- .../core/service/BluePrintClusterService.kt | 106 ---------------- .../core/service/BlueprintClusterService.kt | 106 ++++++++++++++++ .../blueprintsprocessor/core/utils/PayloadUtils.kt | 18 +-- .../core/BluePrintPropertiesTest.kt | 20 --- .../core/BlueprintPropertiesTest.kt | 20 +++ .../core/cluster/BluePrintClusterExtensionsTest.kt | 74 ----------- .../core/cluster/BlueprintClusterExtensionsTest.kt | 74 +++++++++++ .../core/cluster/HazelcastClusterServiceTest.kt | 30 ++--- .../core/utils/BluePrintMappingsTest.kt | 137 --------------------- .../core/utils/BlueprintMappingsTest.kt | 137 +++++++++++++++++++++ 18 files changed, 549 insertions(+), 549 deletions(-) delete mode 100644 ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/BluePrintCoreConfiguration.kt create mode 100644 ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/BlueprintCoreConfiguration.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/cluster/BluePrintClusterExtensions.kt create mode 100644 ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/cluster/BlueprintClusterExtensions.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/service/BluePrintClusterService.kt create mode 100644 ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/service/BlueprintClusterService.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/processor-core/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/BluePrintPropertiesTest.kt create mode 100644 ms/blueprintsprocessor/modules/commons/processor-core/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/BlueprintPropertiesTest.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/processor-core/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/cluster/BluePrintClusterExtensionsTest.kt create mode 100644 ms/blueprintsprocessor/modules/commons/processor-core/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/cluster/BlueprintClusterExtensionsTest.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/processor-core/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/utils/BluePrintMappingsTest.kt create mode 100644 ms/blueprintsprocessor/modules/commons/processor-core/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/utils/BlueprintMappingsTest.kt (limited to 'ms/blueprintsprocessor/modules/commons/processor-core') diff --git a/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/BluePrintCoreConfiguration.kt b/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/BluePrintCoreConfiguration.kt deleted file mode 100644 index 2a4d05dcb..000000000 --- a/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/BluePrintCoreConfiguration.kt +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2019 IBM. - * - * 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. - */ - -package org.onap.ccsdk.cds.blueprintsprocessor.core - -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException -import org.onap.ccsdk.cds.controllerblueprints.core.config.BluePrintLoadConfiguration -import org.onap.ccsdk.cds.controllerblueprints.core.logger -import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintDependencyService -import org.slf4j.LoggerFactory -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.boot.context.properties.bind.Bindable -import org.springframework.boot.context.properties.bind.Binder -import org.springframework.context.ApplicationContext -import org.springframework.context.ApplicationContextAware -import org.springframework.context.annotation.Bean -import org.springframework.context.annotation.Configuration -import org.springframework.core.env.Environment -import org.springframework.stereotype.Service - -@Configuration -open class BluePrintCoreConfiguration(private val bluePrintPropertiesService: BluePrintPropertiesService) { - - companion object { - - const val PREFIX_BLUEPRINT_PROCESSOR = "blueprintsprocessor" - } - - @Bean - open fun bluePrintLoadConfiguration(): BluePrintLoadConfiguration { - return bluePrintPropertiesService - .propertyBeanType(PREFIX_BLUEPRINT_PROCESSOR, BluePrintLoadConfiguration::class.java) - } -} - -@Configuration -open class BluePrintPropertyConfiguration { - - @Autowired - lateinit var environment: Environment - - @Bean - open fun bluePrintPropertyBinder(): Binder { - return Binder.get(environment) - } -} - -@Service -open class BluePrintPropertiesService(private var bluePrintPropertyConfig: BluePrintPropertyConfiguration) { - - private val log = logger(BluePrintPropertiesService::class) - - fun propertyBeanType(prefix: String, type: Class): T { - return try { - bluePrintPropertyConfig.bluePrintPropertyBinder().bind(prefix, Bindable.of(type)).get() - } catch (e: NoSuchElementException) { - val errMsg = "Error: missing property \"$prefix\"... Check the application.properties file." - log.error(errMsg) - throw BluePrintProcessorException(e, errMsg) - } - } -} - -@Configuration -// Add Conditional property , If we try to manage on Application level -open class BlueprintDependencyConfiguration : ApplicationContextAware { - - private val log = LoggerFactory.getLogger(BlueprintDependencyConfiguration::class.java)!! - - override fun setApplicationContext(applicationContext: ApplicationContext) { - BluePrintDependencyService.inject(applicationContext) - log.info("Dependency Management module created...") - } -} diff --git a/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/BlueprintCoreConfiguration.kt b/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/BlueprintCoreConfiguration.kt new file mode 100644 index 000000000..782a7b033 --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/BlueprintCoreConfiguration.kt @@ -0,0 +1,88 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2019 IBM. + * + * 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. + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.core + +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintProcessorException +import org.onap.ccsdk.cds.controllerblueprints.core.config.BlueprintLoadConfiguration +import org.onap.ccsdk.cds.controllerblueprints.core.logger +import org.onap.ccsdk.cds.controllerblueprints.core.service.BlueprintDependencyService +import org.slf4j.LoggerFactory +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.boot.context.properties.bind.Bindable +import org.springframework.boot.context.properties.bind.Binder +import org.springframework.context.ApplicationContext +import org.springframework.context.ApplicationContextAware +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration +import org.springframework.core.env.Environment +import org.springframework.stereotype.Service + +@Configuration +open class BlueprintCoreConfiguration(private val bluePrintPropertiesService: BlueprintPropertiesService) { + + companion object { + + const val PREFIX_BLUEPRINT_PROCESSOR = "blueprintsprocessor" + } + + @Bean + open fun bluePrintLoadConfiguration(): BlueprintLoadConfiguration { + return bluePrintPropertiesService + .propertyBeanType(PREFIX_BLUEPRINT_PROCESSOR, BlueprintLoadConfiguration::class.java) + } +} + +@Configuration +open class BlueprintPropertyConfiguration { + + @Autowired + lateinit var environment: Environment + + @Bean + open fun bluePrintPropertyBinder(): Binder { + return Binder.get(environment) + } +} + +@Service +open class BlueprintPropertiesService(private var bluePrintPropertyConfig: BlueprintPropertyConfiguration) { + + private val log = logger(BlueprintPropertiesService::class) + + fun propertyBeanType(prefix: String, type: Class): T { + return try { + bluePrintPropertyConfig.bluePrintPropertyBinder().bind(prefix, Bindable.of(type)).get() + } catch (e: NoSuchElementException) { + val errMsg = "Error: missing property \"$prefix\"... Check the application.properties file." + log.error(errMsg) + throw BlueprintProcessorException(e, errMsg) + } + } +} + +@Configuration +// Add Conditional property , If we try to manage on Application level +open class BlueprintDependencyConfiguration : ApplicationContextAware { + + private val log = LoggerFactory.getLogger(BlueprintDependencyConfiguration::class.java)!! + + override fun setApplicationContext(applicationContext: ApplicationContext) { + BlueprintDependencyService.inject(applicationContext) + log.info("Dependency Management module created...") + } +} diff --git a/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/api/data/BlueprintProcessorData.kt b/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/api/data/BlueprintProcessorData.kt index 61997061b..924aed898 100644 --- a/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/api/data/BlueprintProcessorData.kt +++ b/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/api/data/BlueprintProcessorData.kt @@ -23,7 +23,7 @@ import com.fasterxml.jackson.databind.JsonNode import com.fasterxml.jackson.databind.node.ObjectNode import io.swagger.annotations.ApiModelProperty import org.onap.ccsdk.cds.controllerblueprints.common.api.EventType -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintConstants import java.util.Date import java.util.UUID @@ -154,7 +154,7 @@ open class Status { var errorMessage: String? = null @get:ApiModelProperty(required = true, value = "Message providing request status") - var message: String = BluePrintConstants.STATUS_SUCCESS + var message: String = BlueprintConstants.STATUS_SUCCESS } open class StepData { diff --git a/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/cluster/BluePrintClusterExtensions.kt b/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/cluster/BluePrintClusterExtensions.kt deleted file mode 100644 index 0a58857f7..000000000 --- a/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/cluster/BluePrintClusterExtensions.kt +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright © 2018-2019 AT&T Intellectual Property. - * - * 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. - */ - -package org.onap.ccsdk.cds.blueprintsprocessor.core.cluster - -import com.hazelcast.cluster.Member -import kotlinx.coroutines.GlobalScope -import kotlinx.coroutines.newSingleThreadContext -import kotlinx.coroutines.withContext -import org.onap.ccsdk.cds.blueprintsprocessor.core.service.BluePrintClusterService -import org.onap.ccsdk.cds.blueprintsprocessor.core.service.ClusterLock -import org.onap.ccsdk.cds.blueprintsprocessor.core.service.ClusterMember -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException -import org.onap.ccsdk.cds.controllerblueprints.core.MDCContext -import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintDependencyService - -/** - * Exposed Dependency Service by this Hazelcast Lib Module - */ -fun BluePrintDependencyService.clusterService(): BluePrintClusterService = - instance(HazelcastClusterService::class) - -/** Optional Cluster Service, returns only if Cluster is enabled */ -fun BluePrintDependencyService.optionalClusterService(): BluePrintClusterService? { - return if (BluePrintConstants.CLUSTER_ENABLED) { - BluePrintDependencyService.clusterService() - } else null -} - -/** Extension to convert Hazelcast Member to Blueprints Cluster Member */ -fun Member.toClusterMember(): ClusterMember { - val memberName: String = this.getAttribute(BluePrintConstants.PROPERTY_CLUSTER_NODE_ID) ?: this.uuid.toString() - return ClusterMember( - id = this.uuid.toString(), - name = memberName, - memberAddress = this.address.toString() - ) -} - -/** - * This function will try to acquire the lock and then execute the provided block. - * If the lock cannot be acquired within timeout, a BlueprintException will be thrown. - * - * Since a lock can only be unlocked by the the thread which acquired the lock, - * this function will confine coroutines within the block to a dedicated thread. - */ -suspend fun ClusterLock.executeWithLock(acquireLockTimeout: Long, block: suspend () -> R): R { - val lock = this - return newSingleThreadContext(lock.name()).use { - withContext(GlobalScope.coroutineContext[MDCContext]?.plus(it) ?: it) { - if (lock.tryLock(acquireLockTimeout)) { - try { - block() - } finally { - lock.unLock() - } - } else - throw BluePrintException("Failed to acquire lock within timeout") - } - } -} diff --git a/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/cluster/BlueprintClusterExtensions.kt b/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/cluster/BlueprintClusterExtensions.kt new file mode 100644 index 000000000..f0504555f --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/cluster/BlueprintClusterExtensions.kt @@ -0,0 +1,75 @@ +/* + * Copyright © 2018-2019 AT&T Intellectual Property. + * + * 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. + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.core.cluster + +import com.hazelcast.cluster.Member +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.newSingleThreadContext +import kotlinx.coroutines.withContext +import org.onap.ccsdk.cds.blueprintsprocessor.core.service.BlueprintClusterService +import org.onap.ccsdk.cds.blueprintsprocessor.core.service.ClusterLock +import org.onap.ccsdk.cds.blueprintsprocessor.core.service.ClusterMember +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintConstants +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintException +import org.onap.ccsdk.cds.controllerblueprints.core.MDCContext +import org.onap.ccsdk.cds.controllerblueprints.core.service.BlueprintDependencyService + +/** + * Exposed Dependency Service by this Hazelcast Lib Module + */ +fun BlueprintDependencyService.clusterService(): BlueprintClusterService = + instance(HazelcastClusterService::class) + +/** Optional Cluster Service, returns only if Cluster is enabled */ +fun BlueprintDependencyService.optionalClusterService(): BlueprintClusterService? { + return if (BlueprintConstants.CLUSTER_ENABLED) { + BlueprintDependencyService.clusterService() + } else null +} + +/** Extension to convert Hazelcast Member to Blueprints Cluster Member */ +fun Member.toClusterMember(): ClusterMember { + val memberName: String = this.getAttribute(BlueprintConstants.PROPERTY_CLUSTER_NODE_ID) ?: this.uuid.toString() + return ClusterMember( + id = this.uuid.toString(), + name = memberName, + memberAddress = this.address.toString() + ) +} + +/** + * This function will try to acquire the lock and then execute the provided block. + * If the lock cannot be acquired within timeout, a BlueprintException will be thrown. + * + * Since a lock can only be unlocked by the the thread which acquired the lock, + * this function will confine coroutines within the block to a dedicated thread. + */ +suspend fun ClusterLock.executeWithLock(acquireLockTimeout: Long, block: suspend () -> R): R { + val lock = this + return newSingleThreadContext(lock.name()).use { + withContext(GlobalScope.coroutineContext[MDCContext]?.plus(it) ?: it) { + if (lock.tryLock(acquireLockTimeout)) { + try { + block() + } finally { + lock.unLock() + } + } else + throw BlueprintException("Failed to acquire lock within timeout") + } + } +} diff --git a/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/cluster/HazelcastClusterService.kt b/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/cluster/HazelcastClusterService.kt index fb9056776..613fc4a58 100644 --- a/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/cluster/HazelcastClusterService.kt +++ b/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/cluster/HazelcastClusterService.kt @@ -33,15 +33,15 @@ import com.hazelcast.scheduledexecutor.IScheduledExecutorService import com.hazelcast.topic.Message import com.hazelcast.topic.MessageListener import kotlinx.coroutines.delay -import org.onap.ccsdk.cds.blueprintsprocessor.core.service.BluePrintClusterMessage -import org.onap.ccsdk.cds.blueprintsprocessor.core.service.BluePrintClusterService +import org.onap.ccsdk.cds.blueprintsprocessor.core.service.BlueprintClusterMessage +import org.onap.ccsdk.cds.blueprintsprocessor.core.service.BlueprintClusterService import org.onap.ccsdk.cds.blueprintsprocessor.core.service.BlueprintClusterMessageListener import org.onap.ccsdk.cds.blueprintsprocessor.core.service.ClusterInfo import org.onap.ccsdk.cds.blueprintsprocessor.core.service.ClusterJoinedEvent import org.onap.ccsdk.cds.blueprintsprocessor.core.service.ClusterLock import org.onap.ccsdk.cds.blueprintsprocessor.core.service.ClusterMember -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintConstants +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintProcessorException import org.onap.ccsdk.cds.controllerblueprints.core.logger import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile import org.onap.ccsdk.cds.controllerblueprints.core.utils.ClusterUtils @@ -53,7 +53,7 @@ import java.util.UUID import java.util.concurrent.TimeUnit @Service -open class HazelcastClusterService(private val applicationEventPublisher: ApplicationEventPublisher) : BluePrintClusterService { +open class HazelcastClusterService(private val applicationEventPublisher: ApplicationEventPublisher) : BlueprintClusterService { private val log = logger(HazelcastClusterService::class) lateinit var hazelcast: HazelcastInstance @@ -78,12 +78,12 @@ open class HazelcastClusterService(private val applicationEventPublisher: Applic } is ClusterInfo -> { - System.setProperty(BluePrintConstants.PROPERTY_CLUSTER_ID, configuration.id) - System.setProperty(BluePrintConstants.PROPERTY_CLUSTER_NODE_ID, configuration.nodeId) + System.setProperty(BlueprintConstants.PROPERTY_CLUSTER_ID, configuration.id) + System.setProperty(BlueprintConstants.PROPERTY_CLUSTER_NODE_ID, configuration.nodeId) val memberAttributeConfig = MemberAttributeConfig() memberAttributeConfig.setAttribute( - BluePrintConstants.PROPERTY_CLUSTER_NODE_ID, + BlueprintConstants.PROPERTY_CLUSTER_NODE_ID, configuration.nodeId ) @@ -122,7 +122,7 @@ open class HazelcastClusterService(private val applicationEventPublisher: Applic } } else -> { - throw BluePrintProcessorException("couldn't understand the cluster configuration") + throw BlueprintProcessorException("couldn't understand the cluster configuration") } } @@ -179,7 +179,7 @@ open class HazelcastClusterService(private val applicationEventPublisher: Applic return ClusterLockImpl(hazelcast, name) } - /** Return interface may change and it will be included in BluePrintClusterService */ + /** Return interface may change and it will be included in BlueprintClusterService */ @UseExperimental suspend fun clusterScheduler(name: String): IScheduledExecutorService { check(::hazelcast.isInitialized) { "failed to start and join cluster" } @@ -225,7 +225,7 @@ open class HazelcastClusterService(private val applicationEventPublisher: Applic check(::hazelcast.isInitialized) { "failed to start and join cluster" } val applicationMembers: MutableMap = hashMapOf() hazelcast.cluster.members.map { member -> - val memberName: String = member.getAttribute(BluePrintConstants.PROPERTY_CLUSTER_NODE_ID) + val memberName: String = member.getAttribute(BlueprintConstants.PROPERTY_CLUSTER_NODE_ID) if (memberName.startsWith(appName, true)) { applicationMembers[memberName] = member } @@ -300,7 +300,7 @@ open class ClusterLockImpl(private val hazelcast: HazelcastInstance, private val class HazelcastMessageListenerAdapter(val listener: BlueprintClusterMessageListener) : MessageListener { override fun onMessage(message: Message?) = message?.let { - BluePrintClusterMessage( + BlueprintClusterMessage( BlueprintClusterTopic.valueOf(it.source as String), it.messageObject, it.publishTime, diff --git a/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/factory/ComponentNodeFactory.kt b/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/factory/ComponentNodeFactory.kt index 2f925dc5b..46ab25e23 100644 --- a/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/factory/ComponentNodeFactory.kt +++ b/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/factory/ComponentNodeFactory.kt @@ -17,7 +17,7 @@ package org.onap.ccsdk.cds.blueprintsprocessor.core.factory -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintProcessorException import org.slf4j.LoggerFactory import org.springframework.context.ApplicationContext import org.springframework.context.ApplicationContextAware @@ -29,16 +29,16 @@ import org.springframework.context.ApplicationContextAware */ interface ComponentNode { - @Throws(BluePrintProcessorException::class) + @Throws(BlueprintProcessorException::class) fun validate(context: MutableMap, componentContext: MutableMap) - @Throws(BluePrintProcessorException::class) + @Throws(BlueprintProcessorException::class) fun process(context: MutableMap, componentContext: MutableMap) - @Throws(BluePrintProcessorException::class) + @Throws(BlueprintProcessorException::class) fun errorHandle(context: MutableMap, componentContext: MutableMap) - @Throws(BluePrintProcessorException::class) + @Throws(BlueprintProcessorException::class) fun reTrigger(context: MutableMap, componentContext: MutableMap) } diff --git a/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/listeners/BlueprintCompilerCacheMessageListener.kt b/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/listeners/BlueprintCompilerCacheMessageListener.kt index 3833379c9..64b4f0ac5 100644 --- a/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/listeners/BlueprintCompilerCacheMessageListener.kt +++ b/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/listeners/BlueprintCompilerCacheMessageListener.kt @@ -17,19 +17,19 @@ package org.onap.ccsdk.cds.blueprintsprocessor.core.listeners import org.onap.ccsdk.cds.blueprintsprocessor.core.cluster.BlueprintClusterTopic -import org.onap.ccsdk.cds.blueprintsprocessor.core.service.BluePrintClusterMessage -import org.onap.ccsdk.cds.blueprintsprocessor.core.service.BluePrintClusterService +import org.onap.ccsdk.cds.blueprintsprocessor.core.service.BlueprintClusterMessage +import org.onap.ccsdk.cds.blueprintsprocessor.core.service.BlueprintClusterService import org.onap.ccsdk.cds.blueprintsprocessor.core.service.BlueprintClusterMessageListener import org.onap.ccsdk.cds.blueprintsprocessor.core.service.ClusterJoinedEvent import org.onap.ccsdk.cds.controllerblueprints.core.logger -import org.onap.ccsdk.cds.controllerblueprints.core.scripts.BluePrintCompileCache +import org.onap.ccsdk.cds.controllerblueprints.core.scripts.BlueprintCompileCache import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty import org.springframework.context.event.EventListener import org.springframework.stereotype.Component @Component @ConditionalOnProperty("CLUSTER_ENABLED", havingValue = "true") -open class BlueprintCompilerCacheMessageListener(private val clusterService: BluePrintClusterService) : BlueprintClusterMessageListener { +open class BlueprintCompilerCacheMessageListener(private val clusterService: BlueprintClusterService) : BlueprintClusterMessageListener { private val log = logger(BlueprintCompilerCacheMessageListener::class) @EventListener(ClusterJoinedEvent::class) @@ -38,10 +38,10 @@ open class BlueprintCompilerCacheMessageListener(private val clusterService: Blu clusterService.addBlueprintClusterMessageListener(BlueprintClusterTopic.BLUEPRINT_CLEAN_COMPILER_CACHE, this) } - override fun onMessage(message: BluePrintClusterMessage?) { + override fun onMessage(message: BlueprintClusterMessage?) { message?.let { log.info("Received ClusterMessage - Cleaning compile cache for blueprint (${it.payload})") - BluePrintCompileCache.cleanClassLoader(it.payload) + BlueprintCompileCache.cleanClassLoader(it.payload) } } } diff --git a/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/service/BluePrintClusterService.kt b/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/service/BluePrintClusterService.kt deleted file mode 100644 index f7ba6f25f..000000000 --- a/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/service/BluePrintClusterService.kt +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright © 2018-2019 AT&T Intellectual Property. - * - * 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. - */ - -package org.onap.ccsdk.cds.blueprintsprocessor.core.service - -import org.onap.ccsdk.cds.blueprintsprocessor.core.cluster.BlueprintClusterTopic -import org.springframework.context.ApplicationEvent -import java.time.Duration -import java.util.Properties -import java.util.UUID - -interface BluePrintClusterService { - - /** Start the cluster with [clusterInfo], By default clustering service is disabled. - * Application module has to start cluster */ - suspend fun startCluster(configuration: T) - - fun clusterJoined(): Boolean - - fun isClient(): Boolean - - fun isLiteMember(): Boolean - - /** Returns [partitionGroup] master member */ - suspend fun masterMember(partitionGroup: String): ClusterMember - - /** Returns all the data cluster members */ - suspend fun allMembers(): Set - - /** - * Returns application cluster members for [appName] joined as server or lite member, - * Node joined as client won't be visible. Here the assumption is node-id is combination of - * application id and replica number, for an example Application cds-cluster then the node ids will be - * cds-cluster-1, cds-cluster-2, cds-cluster-3 - */ - suspend fun applicationMembers(appName: String): Set - - /** Create and get or get the distributed data map store with [name] */ - suspend fun clusterMapStore(name: String): MutableMap - - /** Create and get the distributed lock with [name] */ - suspend fun clusterLock(name: String): ClusterLock - - /** Shut down the cluster with [duration] */ - suspend fun shutDown(duration: Duration) - - /** Send [message] to the listener(s) of a [topic] */ - suspend fun sendMessage(topic: BlueprintClusterTopic, message: T) - - /** Register a [listener] to a [topic] and returns his UUID */ - fun addBlueprintClusterMessageListener(topic: BlueprintClusterTopic, listener: BlueprintClusterMessageListener): UUID - - /** Unregister a listener from a [topic] using his [uuid] and returns true if it succeeded */ - fun removeBlueprintClusterMessageListener(topic: BlueprintClusterTopic, uuid: UUID): Boolean -} - -data class ClusterInfo( - val id: String, - val nodeId: String, - var joinAsClient: Boolean = false, - var properties: Properties?, - var configFile: String -) - -data class ClusterMember( - val id: String, - val name: String, - val memberAddress: String?, - val state: String? = null -) - -interface ClusterLock { - - fun name(): String - suspend fun lock() - suspend fun fenceLock(): String - suspend fun tryLock(timeout: Long): Boolean - suspend fun tryFenceLock(timeout: Long): String - suspend fun unLock() - fun isLocked(): Boolean - fun isLockedByCurrentThread(): Boolean - fun close() -} - -class BluePrintClusterMessage(val topic: BlueprintClusterTopic, val payload: E, publishTime: Long, clusterMember: ClusterMember) - -interface BlueprintClusterMessageListener { - fun onMessage(message: BluePrintClusterMessage?) -} - -class ClusterJoinedEvent(source: Any) : ApplicationEvent(source) - -const val CDS_LOCK_GROUP = "cds-lock" diff --git a/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/service/BlueprintClusterService.kt b/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/service/BlueprintClusterService.kt new file mode 100644 index 000000000..900ae927b --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/service/BlueprintClusterService.kt @@ -0,0 +1,106 @@ +/* + * Copyright © 2018-2019 AT&T Intellectual Property. + * + * 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. + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.core.service + +import org.onap.ccsdk.cds.blueprintsprocessor.core.cluster.BlueprintClusterTopic +import org.springframework.context.ApplicationEvent +import java.time.Duration +import java.util.Properties +import java.util.UUID + +interface BlueprintClusterService { + + /** Start the cluster with [clusterInfo], By default clustering service is disabled. + * Application module has to start cluster */ + suspend fun startCluster(configuration: T) + + fun clusterJoined(): Boolean + + fun isClient(): Boolean + + fun isLiteMember(): Boolean + + /** Returns [partitionGroup] master member */ + suspend fun masterMember(partitionGroup: String): ClusterMember + + /** Returns all the data cluster members */ + suspend fun allMembers(): Set + + /** + * Returns application cluster members for [appName] joined as server or lite member, + * Node joined as client won't be visible. Here the assumption is node-id is combination of + * application id and replica number, for an example Application cds-cluster then the node ids will be + * cds-cluster-1, cds-cluster-2, cds-cluster-3 + */ + suspend fun applicationMembers(appName: String): Set + + /** Create and get or get the distributed data map store with [name] */ + suspend fun clusterMapStore(name: String): MutableMap + + /** Create and get the distributed lock with [name] */ + suspend fun clusterLock(name: String): ClusterLock + + /** Shut down the cluster with [duration] */ + suspend fun shutDown(duration: Duration) + + /** Send [message] to the listener(s) of a [topic] */ + suspend fun sendMessage(topic: BlueprintClusterTopic, message: T) + + /** Register a [listener] to a [topic] and returns his UUID */ + fun addBlueprintClusterMessageListener(topic: BlueprintClusterTopic, listener: BlueprintClusterMessageListener): UUID + + /** Unregister a listener from a [topic] using his [uuid] and returns true if it succeeded */ + fun removeBlueprintClusterMessageListener(topic: BlueprintClusterTopic, uuid: UUID): Boolean +} + +data class ClusterInfo( + val id: String, + val nodeId: String, + var joinAsClient: Boolean = false, + var properties: Properties?, + var configFile: String +) + +data class ClusterMember( + val id: String, + val name: String, + val memberAddress: String?, + val state: String? = null +) + +interface ClusterLock { + + fun name(): String + suspend fun lock() + suspend fun fenceLock(): String + suspend fun tryLock(timeout: Long): Boolean + suspend fun tryFenceLock(timeout: Long): String + suspend fun unLock() + fun isLocked(): Boolean + fun isLockedByCurrentThread(): Boolean + fun close() +} + +class BlueprintClusterMessage(val topic: BlueprintClusterTopic, val payload: E, publishTime: Long, clusterMember: ClusterMember) + +interface BlueprintClusterMessageListener { + fun onMessage(message: BlueprintClusterMessage?) +} + +class ClusterJoinedEvent(source: Any) : ApplicationEvent(source) + +const val CDS_LOCK_GROUP = "cds-lock" diff --git a/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/utils/PayloadUtils.kt b/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/utils/PayloadUtils.kt index 72e5654d4..4ac59802b 100644 --- a/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/utils/PayloadUtils.kt +++ b/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/utils/PayloadUtils.kt @@ -17,11 +17,11 @@ package org.onap.ccsdk.cds.blueprintsprocessor.core.utils import com.fasterxml.jackson.databind.JsonNode -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintConstants +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintProcessorException import org.onap.ccsdk.cds.controllerblueprints.core.asJsonString import org.onap.ccsdk.cds.controllerblueprints.core.returnNullIfMissing -import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService +import org.onap.ccsdk.cds.controllerblueprints.core.service.BlueprintRuntimeService import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils object PayloadUtils { @@ -38,11 +38,11 @@ object PayloadUtils { fun getResponseDataFromPayload(workflowName: String, responsePayload: JsonNode): JsonNode { return responsePayload.get("$workflowName-response").returnNullIfMissing() - ?: throw BluePrintProcessorException("failed to get property($workflowName-response)") + ?: throw BlueprintProcessorException("failed to get property($workflowName-response)") } fun prepareInputsFromWorkflowPayload( - bluePrintRuntimeService: BluePrintRuntimeService<*>, + bluePrintRuntimeService: BlueprintRuntimeService<*>, payload: JsonNode, workflowName: String ) { @@ -51,7 +51,7 @@ object PayloadUtils { } fun prepareDynamicInputsFromWorkflowPayload( - bluePrintRuntimeService: BluePrintRuntimeService<*>, + bluePrintRuntimeService: BlueprintRuntimeService<*>, payload: JsonNode, workflowName: String ) { @@ -61,12 +61,12 @@ object PayloadUtils { } fun prepareDynamicInputsFromComponentPayload( - bluePrintRuntimeService: BluePrintRuntimeService<*>, + bluePrintRuntimeService: BlueprintRuntimeService<*>, payload: JsonNode ) { payload.fields().forEach { property -> - val path = StringBuilder(BluePrintConstants.PATH_INPUTS) - .append(BluePrintConstants.PATH_DIVIDER).append(property.key).toString() + val path = StringBuilder(BlueprintConstants.PATH_INPUTS) + .append(BlueprintConstants.PATH_DIVIDER).append(property.key).toString() bluePrintRuntimeService.put(path, property.value) } } diff --git a/ms/blueprintsprocessor/modules/commons/processor-core/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/BluePrintPropertiesTest.kt b/ms/blueprintsprocessor/modules/commons/processor-core/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/BluePrintPropertiesTest.kt deleted file mode 100644 index c27285020..000000000 --- a/ms/blueprintsprocessor/modules/commons/processor-core/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/BluePrintPropertiesTest.kt +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright © 2019 Bell Canada - * - * 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. - */ - -package org.onap.ccsdk.cds.blueprintsprocessor.core - -// TODO -open class BluePrintPropertiesTest diff --git a/ms/blueprintsprocessor/modules/commons/processor-core/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/BlueprintPropertiesTest.kt b/ms/blueprintsprocessor/modules/commons/processor-core/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/BlueprintPropertiesTest.kt new file mode 100644 index 000000000..fa2e4d41a --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/processor-core/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/BlueprintPropertiesTest.kt @@ -0,0 +1,20 @@ +/* + * Copyright © 2019 Bell Canada + * + * 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. + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.core + +// TODO +open class BlueprintPropertiesTest diff --git a/ms/blueprintsprocessor/modules/commons/processor-core/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/cluster/BluePrintClusterExtensionsTest.kt b/ms/blueprintsprocessor/modules/commons/processor-core/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/cluster/BluePrintClusterExtensionsTest.kt deleted file mode 100644 index 95394e7a9..000000000 --- a/ms/blueprintsprocessor/modules/commons/processor-core/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/cluster/BluePrintClusterExtensionsTest.kt +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright © 2019 Bell Canada. - * - * 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. - */ - -package org.onap.ccsdk.cds.blueprintsprocessor.core.cluster - -import io.mockk.every -import io.mockk.mockk -import io.mockk.verify -import kotlinx.coroutines.runBlocking -import org.junit.Before -import org.junit.Test -import org.onap.ccsdk.cds.blueprintsprocessor.core.service.ClusterLock -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException -import kotlin.test.assertEquals - -class BluePrintClusterExtensionsTest { - - private lateinit var clusterLockMock: ClusterLock - - @Before - fun setup() { - clusterLockMock = mockk() - every { clusterLockMock.name() } returns "mock-lock" - } - - @Test - fun `executeWithLock - should call unlock and return block result`() { - runBlocking { - every { runBlocking { clusterLockMock.tryLock(more(0L)) } } returns true - every { runBlocking { clusterLockMock.unLock() } } returns Unit - - val result = clusterLockMock.executeWithLock(1_000) { "result" } - - verify { runBlocking { clusterLockMock.unLock() } } - assertEquals("result", result) - } - } - - @Test - fun `executeWithLock - should call unlock even when block throws exception`() { - runBlocking { - every { runBlocking { clusterLockMock.tryLock(more(0L)) } } returns true - every { runBlocking { clusterLockMock.unLock() } } returns Unit - - try { - clusterLockMock.executeWithLock(1_000) { throw RuntimeException("It crashed") } - } catch (e: Exception) { - } - - verify { runBlocking { clusterLockMock.unLock() } } - } - } - - @Test(expected = BluePrintException::class) - fun `executeWithLock - should throw exception when lock was not acquired within timeout`() { - runBlocking { - every { runBlocking { clusterLockMock.tryLock(eq(0L)) } } returns false - clusterLockMock.executeWithLock(0) { "Will not run" } - } - } -} diff --git a/ms/blueprintsprocessor/modules/commons/processor-core/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/cluster/BlueprintClusterExtensionsTest.kt b/ms/blueprintsprocessor/modules/commons/processor-core/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/cluster/BlueprintClusterExtensionsTest.kt new file mode 100644 index 000000000..ead24b58d --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/processor-core/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/cluster/BlueprintClusterExtensionsTest.kt @@ -0,0 +1,74 @@ +/* + * Copyright © 2019 Bell Canada. + * + * 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. + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.core.cluster + +import io.mockk.every +import io.mockk.mockk +import io.mockk.verify +import kotlinx.coroutines.runBlocking +import org.junit.Before +import org.junit.Test +import org.onap.ccsdk.cds.blueprintsprocessor.core.service.ClusterLock +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintException +import kotlin.test.assertEquals + +class BlueprintClusterExtensionsTest { + + private lateinit var clusterLockMock: ClusterLock + + @Before + fun setup() { + clusterLockMock = mockk() + every { clusterLockMock.name() } returns "mock-lock" + } + + @Test + fun `executeWithLock - should call unlock and return block result`() { + runBlocking { + every { runBlocking { clusterLockMock.tryLock(more(0L)) } } returns true + every { runBlocking { clusterLockMock.unLock() } } returns Unit + + val result = clusterLockMock.executeWithLock(1_000) { "result" } + + verify { runBlocking { clusterLockMock.unLock() } } + assertEquals("result", result) + } + } + + @Test + fun `executeWithLock - should call unlock even when block throws exception`() { + runBlocking { + every { runBlocking { clusterLockMock.tryLock(more(0L)) } } returns true + every { runBlocking { clusterLockMock.unLock() } } returns Unit + + try { + clusterLockMock.executeWithLock(1_000) { throw RuntimeException("It crashed") } + } catch (e: Exception) { + } + + verify { runBlocking { clusterLockMock.unLock() } } + } + } + + @Test(expected = BlueprintException::class) + fun `executeWithLock - should throw exception when lock was not acquired within timeout`() { + runBlocking { + every { runBlocking { clusterLockMock.tryLock(eq(0L)) } } returns false + clusterLockMock.executeWithLock(0) { "Will not run" } + } + } +} diff --git a/ms/blueprintsprocessor/modules/commons/processor-core/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/cluster/HazelcastClusterServiceTest.kt b/ms/blueprintsprocessor/modules/commons/processor-core/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/cluster/HazelcastClusterServiceTest.kt index ded017940..91ad657a2 100644 --- a/ms/blueprintsprocessor/modules/commons/processor-core/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/cluster/HazelcastClusterServiceTest.kt +++ b/ms/blueprintsprocessor/modules/commons/processor-core/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/cluster/HazelcastClusterServiceTest.kt @@ -33,11 +33,11 @@ import kotlinx.coroutines.withContext import org.junit.After import org.junit.Before import org.junit.Test -import org.onap.ccsdk.cds.blueprintsprocessor.core.service.BluePrintClusterMessage -import org.onap.ccsdk.cds.blueprintsprocessor.core.service.BluePrintClusterService +import org.onap.ccsdk.cds.blueprintsprocessor.core.service.BlueprintClusterMessage +import org.onap.ccsdk.cds.blueprintsprocessor.core.service.BlueprintClusterService import org.onap.ccsdk.cds.blueprintsprocessor.core.service.BlueprintClusterMessageListener import org.onap.ccsdk.cds.blueprintsprocessor.core.service.ClusterInfo -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintConstants import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive import org.onap.ccsdk.cds.controllerblueprints.core.logger import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile @@ -61,8 +61,8 @@ class HazelcastClusterServiceTest { @Test fun testClientFileSystemYamlConfig() { - System.setProperty(BluePrintConstants.PROPERTY_CLUSTER_ID, "test-cluster") - System.setProperty(BluePrintConstants.PROPERTY_CLUSTER_NODE_ID, "node-1234") + System.setProperty(BlueprintConstants.PROPERTY_CLUSTER_ID, "test-cluster") + System.setProperty(BlueprintConstants.PROPERTY_CLUSTER_NODE_ID, "node-1234") System.setProperty( "hazelcast.client.config", normalizedFile("./src/test/resources/hazelcast/hazelcast-client.yaml").absolutePath @@ -75,8 +75,8 @@ class HazelcastClusterServiceTest { @Test fun testServerFileSystemYamlConfig() { - System.setProperty(BluePrintConstants.PROPERTY_CLUSTER_ID, "test-cluster") - System.setProperty(BluePrintConstants.PROPERTY_CLUSTER_NODE_ID, "node-1234") + System.setProperty(BlueprintConstants.PROPERTY_CLUSTER_ID, "test-cluster") + System.setProperty(BlueprintConstants.PROPERTY_CLUSTER_NODE_ID, "node-1234") val configFile = normalizedFile("./src/test/resources/hazelcast/hazelcast.yaml") val config = FileSystemYamlConfig(configFile) assertNotNull(config) @@ -105,7 +105,7 @@ class HazelcastClusterServiceTest { } } - private suspend fun testMessageReceived(bluePrintClusterServices: List) { + private suspend fun testMessageReceived(bluePrintClusterServices: List) { val sender = bluePrintClusterServices[0] as HazelcastClusterService val receiver = bluePrintClusterServices[1] as HazelcastClusterService val messageSent = "hello world" @@ -113,7 +113,7 @@ class HazelcastClusterServiceTest { val uuid = receiver.addBlueprintClusterMessageListener( BlueprintClusterTopic.BLUEPRINT_CLEAN_COMPILER_CACHE, object : BlueprintClusterMessageListener { - override fun onMessage(message: BluePrintClusterMessage?) { + override fun onMessage(message: BlueprintClusterMessage?) { log.info("Message received - ${message?.payload}") isMessageReceived = messageSent == message?.payload } @@ -132,7 +132,7 @@ class HazelcastClusterServiceTest { private suspend fun createCluster( ids: List, joinAsClient: Boolean? = false - ): List { + ): List { return withContext(Dispatchers.Default) { val deferred = ids.map { id -> @@ -164,7 +164,7 @@ class HazelcastClusterServiceTest { } } - private suspend fun testDistributedStore(bluePrintClusterServices: List) { + private suspend fun testDistributedStore(bluePrintClusterServices: List) { /** Test Distributed store creation */ repeat(2) { storeId -> val store = bluePrintClusterServices[0].clusterMapStore( @@ -187,7 +187,7 @@ class HazelcastClusterServiceTest { } } - private suspend fun testDistributedLock(bluePrintClusterServices: List) { + private suspend fun testDistributedLock(bluePrintClusterServices: List) { val lockName = "sample-lock" withContext(Dispatchers.IO) { val deferred = async { @@ -218,7 +218,7 @@ class HazelcastClusterServiceTest { } private suspend fun executeLock( - bluePrintClusterService: BluePrintClusterService, + bluePrintClusterService: BlueprintClusterService, lockId: String, lockName: String ) { @@ -237,7 +237,7 @@ class HazelcastClusterServiceTest { distributedLock.close() } - private suspend fun executeScheduler(bluePrintClusterService: BluePrintClusterService) { + private suspend fun executeScheduler(bluePrintClusterService: BlueprintClusterService) { log.info("initialising ...") val hazelcastClusterService = bluePrintClusterService as HazelcastClusterService @@ -251,7 +251,7 @@ class HazelcastClusterServiceTest { // scheduler.scheduleOnAllMembersAtFixedRate(SampleSchedulerTask(), 0, 5, TimeUnit.SECONDS) } - private suspend fun printReachableMembers(bluePrintClusterServices: List) { + private suspend fun printReachableMembers(bluePrintClusterServices: List) { bluePrintClusterServices.forEach { bluePrintClusterService -> val hazelcastClusterService = bluePrintClusterService as HazelcastClusterService val hazelcast = hazelcastClusterService.hazelcast diff --git a/ms/blueprintsprocessor/modules/commons/processor-core/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/utils/BluePrintMappingsTest.kt b/ms/blueprintsprocessor/modules/commons/processor-core/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/utils/BluePrintMappingsTest.kt deleted file mode 100644 index e8bdbf9ef..000000000 --- a/ms/blueprintsprocessor/modules/commons/processor-core/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/utils/BluePrintMappingsTest.kt +++ /dev/null @@ -1,137 +0,0 @@ -package org.onap.ccsdk.cds.blueprintsprocessor.core.utils - -import org.junit.Assert -import org.junit.Test -import org.junit.runner.RunWith -import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.Flags -import org.onap.ccsdk.cds.controllerblueprints.common.api.ActionIdentifiers -import org.onap.ccsdk.cds.controllerblueprints.common.api.CommonHeader -import org.onap.ccsdk.cds.controllerblueprints.common.api.EventType -import org.onap.ccsdk.cds.controllerblueprints.common.api.Flag -import org.onap.ccsdk.cds.controllerblueprints.core.utils.currentTimestamp -import org.springframework.test.context.junit4.SpringRunner -import java.text.SimpleDateFormat - -@RunWith(SpringRunner::class) -class BluePrintMappingsTest { - - val formatter = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") - val dateString = "2019-01-16T18:25:43.511Z" - val dateForTest = formatter.parse(dateString) - - val flag = Flag.newBuilder().setIsForce(false).setTtl(1).build() - - fun createFlag(): Flags { - val flag = Flags() - flag.isForce = false - flag.ttl = 1 - return flag - } - - @Test - fun flagToJavaTest() { - val flag2 = flag.toJava() - - Assert.assertEquals(flag.isForce, flag2.isForce) - Assert.assertEquals(flag.ttl, flag2.ttl) - } - - @Test - fun flagToProtoTest() { - val flag = createFlag() - val flag2 = flag.toProto() - - Assert.assertEquals(flag.isForce, flag2.isForce) - Assert.assertEquals(flag.ttl, flag2.ttl) - } - - fun createStatus(): org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.Status { - val status = org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.Status() - status.code = 400 - status.errorMessage = "Concurrent modification exception" - status.eventType = EventType.EVENT_COMPONENT_PROCESSING.name - status.message = "Error uploading data" - status.timestamp = dateForTest - return status - } - - @Test - fun statusToProtoTest() { - val status = createStatus() - val status2 = status.toProto() - - Assert.assertEquals(status.code, status2.code) - Assert.assertEquals(status.errorMessage, status2.errorMessage) - Assert.assertEquals(status.eventType, status2.eventType.name) - Assert.assertEquals(status.message, status2.message) - Assert.assertEquals(status.timestamp.toString(), status2.timestamp) - } - - @Test - fun commonHeaderToJavaTest() { - val flag = Flag.newBuilder().setIsForce(true).setTtl(2).build() - - val commonHeader = - CommonHeader.newBuilder().setOriginatorId("Origin").setRequestId("requestID").setSubRequestId("subRequestID").setTimestamp(dateString) - .setFlag(flag).build() - val commonHeader2 = commonHeader.toJava() - - Assert.assertEquals(commonHeader.originatorId, commonHeader2.originatorId) - Assert.assertEquals(commonHeader.requestId, commonHeader2.requestId) - Assert.assertEquals(commonHeader.subRequestId, commonHeader2.subRequestId) - Assert.assertEquals(commonHeader.timestamp, formatter.format(commonHeader2.timestamp)) - } - - fun createCommonHeader(): org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.CommonHeader { - val commonHeader = org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.CommonHeader() - commonHeader.flags = createFlag() - commonHeader.originatorId = "1234" - commonHeader.requestId = "2345" - commonHeader.subRequestId = "0123" - commonHeader.timestamp = dateForTest - return commonHeader - } - - @Test - fun commonHeaderToProtoTest() { - val commonHeader = createCommonHeader() - val commonHeader2 = commonHeader.toProto() - Assert.assertEquals(commonHeader.originatorId, commonHeader2.originatorId) - Assert.assertEquals(commonHeader.requestId, commonHeader2.requestId) - Assert.assertEquals(commonHeader.subRequestId, commonHeader2.subRequestId) - Assert.assertEquals(commonHeader.timestamp.currentTimestamp(), commonHeader2.timestamp) - } - - @Test - fun actionIdentifierToJavaTest() { - val actionIdentifiers = - ActionIdentifiers.newBuilder().setActionName("Process Action").setBlueprintName("BlueprintName").setBlueprintVersion("3.0") - .setMode("Execution").build() - val actionIdentifiers2 = actionIdentifiers.toJava() - - Assert.assertEquals(actionIdentifiers.actionName, actionIdentifiers2.actionName) - Assert.assertEquals(actionIdentifiers.blueprintName, actionIdentifiers2.blueprintName) - Assert.assertEquals(actionIdentifiers.blueprintVersion, actionIdentifiers2.blueprintVersion) - Assert.assertEquals(actionIdentifiers.mode, actionIdentifiers2.mode) - } - - fun createActionIdentifier(): org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ActionIdentifiers { - val ac = org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ActionIdentifiers() - ac.mode = "mode" - ac.blueprintVersion = "version" - ac.blueprintName = "name" - ac.actionName = "action" - return ac - } - - @Test - fun actionIdentifierToProtoTest() { - val actionIdentifiers = createActionIdentifier() - val actionIdentifiers2 = actionIdentifiers.toProto() - - Assert.assertEquals(actionIdentifiers.actionName, actionIdentifiers2.actionName) - Assert.assertEquals(actionIdentifiers.blueprintName, actionIdentifiers2.blueprintName) - Assert.assertEquals(actionIdentifiers.blueprintVersion, actionIdentifiers2.blueprintVersion) - Assert.assertEquals(actionIdentifiers.mode, actionIdentifiers2.mode) - } -} diff --git a/ms/blueprintsprocessor/modules/commons/processor-core/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/utils/BlueprintMappingsTest.kt b/ms/blueprintsprocessor/modules/commons/processor-core/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/utils/BlueprintMappingsTest.kt new file mode 100644 index 000000000..1549c9cdf --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/processor-core/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/utils/BlueprintMappingsTest.kt @@ -0,0 +1,137 @@ +package org.onap.ccsdk.cds.blueprintsprocessor.core.utils + +import org.junit.Assert +import org.junit.Test +import org.junit.runner.RunWith +import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.Flags +import org.onap.ccsdk.cds.controllerblueprints.common.api.ActionIdentifiers +import org.onap.ccsdk.cds.controllerblueprints.common.api.CommonHeader +import org.onap.ccsdk.cds.controllerblueprints.common.api.EventType +import org.onap.ccsdk.cds.controllerblueprints.common.api.Flag +import org.onap.ccsdk.cds.controllerblueprints.core.utils.currentTimestamp +import org.springframework.test.context.junit4.SpringRunner +import java.text.SimpleDateFormat + +@RunWith(SpringRunner::class) +class BlueprintMappingsTest { + + val formatter = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") + val dateString = "2019-01-16T18:25:43.511Z" + val dateForTest = formatter.parse(dateString) + + val flag = Flag.newBuilder().setIsForce(false).setTtl(1).build() + + fun createFlag(): Flags { + val flag = Flags() + flag.isForce = false + flag.ttl = 1 + return flag + } + + @Test + fun flagToJavaTest() { + val flag2 = flag.toJava() + + Assert.assertEquals(flag.isForce, flag2.isForce) + Assert.assertEquals(flag.ttl, flag2.ttl) + } + + @Test + fun flagToProtoTest() { + val flag = createFlag() + val flag2 = flag.toProto() + + Assert.assertEquals(flag.isForce, flag2.isForce) + Assert.assertEquals(flag.ttl, flag2.ttl) + } + + fun createStatus(): org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.Status { + val status = org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.Status() + status.code = 400 + status.errorMessage = "Concurrent modification exception" + status.eventType = EventType.EVENT_COMPONENT_PROCESSING.name + status.message = "Error uploading data" + status.timestamp = dateForTest + return status + } + + @Test + fun statusToProtoTest() { + val status = createStatus() + val status2 = status.toProto() + + Assert.assertEquals(status.code, status2.code) + Assert.assertEquals(status.errorMessage, status2.errorMessage) + Assert.assertEquals(status.eventType, status2.eventType.name) + Assert.assertEquals(status.message, status2.message) + Assert.assertEquals(status.timestamp.toString(), status2.timestamp) + } + + @Test + fun commonHeaderToJavaTest() { + val flag = Flag.newBuilder().setIsForce(true).setTtl(2).build() + + val commonHeader = + CommonHeader.newBuilder().setOriginatorId("Origin").setRequestId("requestID").setSubRequestId("subRequestID").setTimestamp(dateString) + .setFlag(flag).build() + val commonHeader2 = commonHeader.toJava() + + Assert.assertEquals(commonHeader.originatorId, commonHeader2.originatorId) + Assert.assertEquals(commonHeader.requestId, commonHeader2.requestId) + Assert.assertEquals(commonHeader.subRequestId, commonHeader2.subRequestId) + Assert.assertEquals(commonHeader.timestamp, formatter.format(commonHeader2.timestamp)) + } + + fun createCommonHeader(): org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.CommonHeader { + val commonHeader = org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.CommonHeader() + commonHeader.flags = createFlag() + commonHeader.originatorId = "1234" + commonHeader.requestId = "2345" + commonHeader.subRequestId = "0123" + commonHeader.timestamp = dateForTest + return commonHeader + } + + @Test + fun commonHeaderToProtoTest() { + val commonHeader = createCommonHeader() + val commonHeader2 = commonHeader.toProto() + Assert.assertEquals(commonHeader.originatorId, commonHeader2.originatorId) + Assert.assertEquals(commonHeader.requestId, commonHeader2.requestId) + Assert.assertEquals(commonHeader.subRequestId, commonHeader2.subRequestId) + Assert.assertEquals(commonHeader.timestamp.currentTimestamp(), commonHeader2.timestamp) + } + + @Test + fun actionIdentifierToJavaTest() { + val actionIdentifiers = + ActionIdentifiers.newBuilder().setActionName("Process Action").setBlueprintName("BlueprintName").setBlueprintVersion("3.0") + .setMode("Execution").build() + val actionIdentifiers2 = actionIdentifiers.toJava() + + Assert.assertEquals(actionIdentifiers.actionName, actionIdentifiers2.actionName) + Assert.assertEquals(actionIdentifiers.blueprintName, actionIdentifiers2.blueprintName) + Assert.assertEquals(actionIdentifiers.blueprintVersion, actionIdentifiers2.blueprintVersion) + Assert.assertEquals(actionIdentifiers.mode, actionIdentifiers2.mode) + } + + fun createActionIdentifier(): org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ActionIdentifiers { + val ac = org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ActionIdentifiers() + ac.mode = "mode" + ac.blueprintVersion = "version" + ac.blueprintName = "name" + ac.actionName = "action" + return ac + } + + @Test + fun actionIdentifierToProtoTest() { + val actionIdentifiers = createActionIdentifier() + val actionIdentifiers2 = actionIdentifiers.toProto() + + Assert.assertEquals(actionIdentifiers.actionName, actionIdentifiers2.actionName) + Assert.assertEquals(actionIdentifiers.blueprintName, actionIdentifiers2.blueprintName) + Assert.assertEquals(actionIdentifiers.blueprintVersion, actionIdentifiers2.blueprintVersion) + Assert.assertEquals(actionIdentifiers.mode, actionIdentifiers2.mode) + } +} -- cgit 1.2.3-korg