From 8fd7adbb9428bc0c14f5f08a321eabd582fbaf48 Mon Sep 17 00:00:00 2001 From: Brinda Santh Date: Thu, 19 Dec 2019 16:11:31 -0500 Subject: Cluster distributed lock service. Included and fixed clustered env properties and utils. Fixed docker compose instance sequence numbers. Issue-ID: CCSDK-2011 Signed-off-by: Brinda Santh Change-Id: Ie28935ae7cb3de8c77cd7110993304eb49799b6c --- .../src/main/dc/docker-compose-cluster.yaml | 24 ++++++++++--------- .../application/src/main/docker/startService.sh | 6 ----- .../BluePrintProcessorCluster.kt | 28 ++++++++++------------ 3 files changed, 25 insertions(+), 33 deletions(-) (limited to 'ms/blueprintsprocessor/application/src/main') diff --git a/ms/blueprintsprocessor/application/src/main/dc/docker-compose-cluster.yaml b/ms/blueprintsprocessor/application/src/main/dc/docker-compose-cluster.yaml index f43f19c52..a37089f10 100644 --- a/ms/blueprintsprocessor/application/src/main/dc/docker-compose-cluster.yaml +++ b/ms/blueprintsprocessor/application/src/main/dc/docker-compose-cluster.yaml @@ -20,20 +20,20 @@ services: image: nats-streaming:latest container_name: nats hostname: nats - command: "-cid cds-cluster --auth tokenAuth -store file -dir store-nats-1 --cluster_node_id nats-1" + command: "-cid cds-cluster --auth tokenAuth -store file -dir store-nats-0 --cluster_node_id nats-0" networks: - cds-network ports: - "8222:8222" - "4222:4222" restart: always - cds-controller-1: + cds-controller-0: depends_on: - db - nats image: onap/ccsdk-blueprintsprocessor:latest - container_name: cds-controller-1 - hostname: cds-controller-1 + container_name: cds-controller-0 + hostname: cds-controller-0 networks: - cds-network ports: @@ -49,9 +49,10 @@ services: source: ./config environment: # Same as hostname and container name + CLUSTER_ENABLED: "true" CLUSTER_ID: cds-cluster - CLUSTER_NODE_ID: cds-controller-1 - CLUSTER_MEMBERS: cds-controller-1,resource-resolution-1 + CLUSTER_NODE_ID: cds-controller-0 + CLUSTER_MEMBERS: cds-controller-0,resource-resolution-0 CLUSTER_STORAGE_PATH: /opt/app/onap/config/cluster #CLUSTER_CONFIG_FILE: /opt/app/onap/config/atomix/atomix-multicast.conf NATS_HOSTS: nats://nats:4222 @@ -60,13 +61,13 @@ services: APP_CONFIG_HOME: /opt/app/onap/config STICKYSELECTORKEY: ENVCONTEXT: dev - resource-resolution-1: + resource-resolution-0: depends_on: - db - nats image: onap/ccsdk-blueprintsprocessor:latest - container_name: resource-resolution-1 - hostname: resource-resolution-1 + container_name: resource-resolution-0 + hostname: resource-resolution-0 networks: - cds-network ports: @@ -81,9 +82,10 @@ services: type: bind source: ./config environment: + CLUSTER_ENABLED: "true" CLUSTER_ID: cds-cluster - CLUSTER_NODE_ID: resource-resolution-1 - CLUSTER_MEMBERS: cds-controller-1,resource-resolution-1 + CLUSTER_NODE_ID: resource-resolution-0 + CLUSTER_MEMBERS: cds-controller-0,resource-resolution-0 CLUSTER_STORAGE_PATH: /opt/app/onap/config/cluster #CLUSTER_CONFIG_FILE: /opt/app/onap/config/atomix/atomix-multicast.conf NATS_HOSTS: nats://nats:4222 diff --git a/ms/blueprintsprocessor/application/src/main/docker/startService.sh b/ms/blueprintsprocessor/application/src/main/docker/startService.sh index f5967dcb4..f516a3c57 100644 --- a/ms/blueprintsprocessor/application/src/main/docker/startService.sh +++ b/ms/blueprintsprocessor/application/src/main/docker/startService.sh @@ -18,10 +18,4 @@ exec java -classpath "/etc:${APP_HOME}/lib/*:/lib/*:/src:/schema:/generated-sour -Djava.security.egd=file:/dev/./urandom \ -DAPPNAME=${APPLICATIONNAME} -DAPPENV=${APP_ENV} -DAPPVERSION=${APP_VERSION} -DNAMESPACE=${NAMESPACE} \ -Dspring.config.location=${APP_CONFIG_HOME}/ \ --DCLUSTER_ID=${CLUSTER_ID} \ --DCLUSTER_NODE_ID=${CLUSTER_NODE_ID} \ --DCLUSTER_NODE_ADDRESS=${CLUSTER_NODE_ID} \ --DCLUSTER_MEMBERS=${CLUSTER_MEMBERS} \ --DCLUSTER_STORAGE_PATH=${CLUSTER_STORAGE_PATH} \ --DCLUSTER_CONFIG_FILE=${CLUSTER_CONFIG_FILE} \ org.onap.ccsdk.cds.blueprintsprocessor.BlueprintProcessorApplicationKt diff --git a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BluePrintProcessorCluster.kt b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BluePrintProcessorCluster.kt index b78ebf68b..4c9314ec2 100644 --- a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BluePrintProcessorCluster.kt +++ b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BluePrintProcessorCluster.kt @@ -22,6 +22,8 @@ import org.onap.ccsdk.cds.blueprintsprocessor.core.service.ClusterInfo 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.splitCommaAsList +import org.onap.ccsdk.cds.controllerblueprints.core.utils.ClusterUtils import org.springframework.boot.context.event.ApplicationReadyEvent import org.springframework.context.event.EventListener import org.springframework.stereotype.Component @@ -52,7 +54,7 @@ import javax.annotation.PreDestroy * CLUSTER_STORAGE_PATH: /opt/app/onap/config/cluster * CLUSTER_CONFIG_FILE: /opt/app/onap/config/atomix/atomix-multicast.conf * 4. Cluster will be enabled only all the above properties present in the environments. - * if CLUSTER_ID is present, then it will try to create cluster. + * if CLUSTER_ENABLED is present, then it will try to create cluster. */ @Component open class BluePrintProcessorCluster(private val bluePrintClusterService: BluePrintClusterService) { @@ -61,25 +63,22 @@ open class BluePrintProcessorCluster(private val bluePrintClusterService: BluePr @EventListener(ApplicationReadyEvent::class) fun startAndJoinCluster() = runBlocking { - val clusterId = System.getProperty(BluePrintConstants.PROPERTY_CLUSTER_ID) - if (!clusterId.isNullOrEmpty()) { + if (BluePrintConstants.CLUSTER_ENABLED) { - val nodeId = System.getProperty(BluePrintConstants.PROPERTY_CLUSTER_NODE_ID) - ?: throw BluePrintProcessorException("couldn't get environment variable ${BluePrintConstants.PROPERTY_CLUSTER_NODE_ID}") + val clusterId = ClusterUtils.clusterId() + val nodeId = ClusterUtils.clusterNodeId() + val nodeAddress = ClusterUtils.clusterNodeAddress() - val nodeAddress = System.getProperty(BluePrintConstants.PROPERTY_CLUSTER_NODE_ADDRESS) - ?: throw BluePrintProcessorException("couldn't get environment variable ${BluePrintConstants.PROPERTY_CLUSTER_NODE_ADDRESS}") - - val clusterMembers = System.getProperty(BluePrintConstants.PROPERTY_CLUSTER_MEMBERS) + val clusterMembers = System.getenv(BluePrintConstants.PROPERTY_CLUSTER_MEMBERS) ?: throw BluePrintProcessorException("couldn't get environment variable ${BluePrintConstants.PROPERTY_CLUSTER_MEMBERS}") - val clusterMemberList = clusterMembers.split(",").map { it.trim() }.toList() + val clusterMemberList = clusterMembers.splitCommaAsList() - val clusterStorage = System.getProperty(BluePrintConstants.PROPERTY_CLUSTER_STORAGE_PATH) + val clusterStorage = System.getenv(BluePrintConstants.PROPERTY_CLUSTER_STORAGE_PATH) ?: throw BluePrintProcessorException("couldn't get environment variable ${BluePrintConstants.PROPERTY_CLUSTER_STORAGE_PATH}") - val clusterConfigFile = System.getProperty(BluePrintConstants.PROPERTY_CLUSTER_CONFIG_FILE) + val clusterConfigFile = System.getenv(BluePrintConstants.PROPERTY_CLUSTER_CONFIG_FILE) val clusterInfo = ClusterInfo( id = clusterId, nodeId = nodeId, @@ -89,10 +88,7 @@ open class BluePrintProcessorCluster(private val bluePrintClusterService: BluePr ) bluePrintClusterService.startCluster(clusterInfo) } else { - log.info( - "Cluster is disabled, to enable cluster set the environment " + - "properties[CLUSTER_ID,CLUSTER_NODE_ID, CLUSTER_NODE_ADDRESS, CLUSTER_MEMBERS,CLUSTER_CONFIG_FILE]" - ) + log.info("Cluster is disabled, to enable cluster set the environment CLUSTER_* properties.") } } -- cgit 1.2.3-korg