Removed manual shutdown hook for hazelcast 42/101842/2
authorSebastien Premont-Tendland <sebastien.premont@bell.ca>
Mon, 17 Feb 2020 16:14:02 +0000 (11:14 -0500)
committerSebastien Premont-Tendland <sebastien.premont@bell.ca>
Mon, 17 Feb 2020 16:30:57 +0000 (11:30 -0500)
Shutdown hook for hazelcast are already working with spring boot. Just
changed the policy to GRACEFUL (default is TERMINATE). This allow
hazelcast to shutdown gracefully and recover from a rolling upgrade

Also updated the Dockerfile to use multi stage to reduce by ~200Mb
the docker image size.

Issue-ID: CCSDK-2011
Signed-off-by: Sebastien Premont-Tendland <sebastien.premont@bell.ca>
Change-Id: I0034145c7acefa88ed8d16f23a29249c7225ace3

ms/blueprintsprocessor/application/src/main/docker/Dockerfile
ms/blueprintsprocessor/application/src/main/docker/startService.sh
ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BluePrintProcessorCluster.kt
ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintProcessorApplication.kt
ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/cluster/HazlecastClusterService.kt

index 2a85f1c..1035915 100755 (executable)
@@ -1,3 +1,10 @@
+FROM alpine:latest AS extractor
+COPY @project.build.finalName@-@assembly.id@.tar.gz /source.tar.gz
+RUN tar -xzf /source.tar.gz -C /tmp \
+ && cp -rf /tmp/@project.build.finalName@/opt / \
+ && rm -rf /source.tar.gz \
+ && rm -rf /tmp/@project.build.finalName@
+
 FROM omahoco1/alpine-java-python
 
 # add entrypoint
@@ -5,10 +12,6 @@ COPY startService.sh /startService.sh
 RUN chmod 777 /startService.sh && dos2unix /startService.sh
 
 # add application
-COPY @project.build.finalName@-@assembly.id@.tar.gz /source.tar.gz
-RUN tar -xzf /source.tar.gz -C /tmp \
- && cp -rf /tmp/@project.build.finalName@/opt / \
- && rm -rf /source.tar.gz \
- && rm -rf /tmp/@project.build.finalName@
+COPY --from=extractor /opt /opt
 
 ENTRYPOINT [ "/startService.sh" ]
index a9d3992..fb44ffd 100644 (file)
@@ -18,4 +18,6 @@ exec java -classpath "/etc:${APP_HOME}/lib/*:/lib/*:/src:/schema:/generated-sour
 -Djava.security.egd=file:/dev/./urandom \
 -DAPPNAME=${APP_NAME} -DAPPENV=${APP_ENV} -DAPPVERSION=${APP_VERSION} -DNAMESPACE=${NAMESPACE} \
 -Dspring.config.location=${APP_CONFIG_HOME}/ \
+-Dhazelcast.shutdownhook.policy=GRACEFUL \
+-Dhazelcast.graceful.shutdown.max.wait=600 \
 org.onap.ccsdk.cds.blueprintsprocessor.BlueprintProcessorApplicationKt
index f7296d4..2284a6f 100644 (file)
@@ -25,9 +25,7 @@ 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
-import java.time.Duration
 import java.util.Properties
-import javax.annotation.PreDestroy
 
 /**
  * To Start the cluster, minimum 2 Instances/ Replicas od CDS needed.
@@ -85,9 +83,4 @@ open class BluePrintProcessorCluster(private val bluePrintClusterService: BluePr
             log.info("Cluster is disabled, to enable cluster set the environment CLUSTER_* properties.")
         }
     }
-
-    @PreDestroy
-    fun shutDown() = runBlocking {
-        bluePrintClusterService.shutDown(Duration.ofMillis(1))
-    }
 }
index 3709a97..1d1baee 100644 (file)
@@ -19,6 +19,7 @@ package org.onap.ccsdk.cds.blueprintsprocessor
 import org.springframework.boot.SpringApplication
 import org.springframework.boot.autoconfigure.EnableAutoConfiguration
 import org.springframework.boot.autoconfigure.SpringBootApplication
+import org.springframework.boot.autoconfigure.hazelcast.HazelcastAutoConfiguration
 import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
 import org.springframework.context.annotation.ComponentScan
 
@@ -28,7 +29,7 @@ import org.springframework.context.annotation.ComponentScan
  * @author Brinda Santh
  */
 @SpringBootApplication
-@EnableAutoConfiguration(exclude = [DataSourceAutoConfiguration::class])
+@EnableAutoConfiguration(exclude = [DataSourceAutoConfiguration::class, HazelcastAutoConfiguration::class])
 @ComponentScan(basePackages = ["org.onap.ccsdk.cds.blueprintsprocessor", "org.onap.ccsdk.cds.controllerblueprints"])
 open class BlueprintProcessorApplication
 
index 0964145..6be3334 100644 (file)
@@ -54,7 +54,7 @@ open class HazlecastClusterService : BluePrintClusterService {
     var joinedLite = false
 
     override suspend fun <T> startCluster(configuration: T) {
-        /** Get the Hazelcast Cliet or Server instance */
+        /** Get the Hazelcast Client or Server instance */
         hazelcast =
             when (configuration) {
                 is Config -> {
@@ -101,6 +101,8 @@ open class HazlecastClusterService : BluePrintClusterService {
                     } else {
                         /** Hazelcast Server from config file */
                         val hazelcastServerConfiguration = FileSystemYamlConfig(normalizedFile(configFile))
+                        hazelcastServerConfiguration.clusterName = configuration.id
+                        hazelcastServerConfiguration.instanceName = configuration.nodeId
                         hazelcastServerConfiguration.properties = configuration.properties
                         hazelcastServerConfiguration.memberAttributeConfig = memberAttributeConfig
                         joinedLite = hazelcastServerConfiguration.isLiteMember
@@ -116,7 +118,7 @@ open class HazlecastClusterService : BluePrintClusterService {
             }
 
         /** Add the Membership Listeners */
-        hazelcast.cluster.addMembershipListener(BlueprintsClusterMembershipListener(this))
+        hazelcast.cluster.addMembershipListener(BlueprintsClusterMembershipListener())
         log.info(
             "Cluster(${hazelcast.config.clusterName}) node(${hazelcast.name}) created successfully...."
         )
@@ -207,7 +209,7 @@ open class HazlecastClusterService : BluePrintClusterService {
     }
 }
 
-open class BlueprintsClusterMembershipListener(val hazlecastClusterService: HazlecastClusterService) :
+open class BlueprintsClusterMembershipListener() :
     MembershipListener {
     private val log = logger(BlueprintsClusterMembershipListener::class)