You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ja...@apache.org on 2023/01/09 16:29:57 UTC

[camel-quarkus-examples] branch 2.13.x updated: Remove lock producer

This is an automated email from the ASF dual-hosted git repository.

jamesnetherton pushed a commit to branch 2.13.x
in repository https://gitbox.apache.org/repos/asf/camel-quarkus-examples.git


The following commit(s) were added to refs/heads/2.13.x by this push:
     new 9318730  Remove lock producer
9318730 is described below

commit 93187304e9d37990a4b17206c37ea8cc2deb9126
Author: Lukas Lowinger <ll...@redhat.com>
AuthorDate: Tue Dec 13 17:21:46 2022 +0100

    Remove lock producer
---
 cluster-leader-election/README.adoc                | 11 +++--
 .../java/org/acme/master/ClusterLockProducer.java  | 52 ----------------------
 .../src/main/resources/application.properties      |  7 ++-
 3 files changed, 8 insertions(+), 62 deletions(-)

diff --git a/cluster-leader-election/README.adoc b/cluster-leader-election/README.adoc
index 1fd74d1..c8ddbe2 100644
--- a/cluster-leader-election/README.adoc
+++ b/cluster-leader-election/README.adoc
@@ -43,7 +43,7 @@ https://camel.apache.org/camel-quarkus/latest/first-steps.html#_package_and_run_
 
 [source,shell]
 ----
-$ mvn clean package -Dquarkus.profile=local
+$ mvn clean package
 ----
 
 === Native mode
@@ -55,14 +55,14 @@ To prepare a native executable using GraalVM, run the following command:
 
 [source,shell]
 ----
-$ mvn clean package -Pnative -Dquarkus.profile=local
+$ mvn clean package -Pnative
 ----
 
 == Local Playground
 
 The first example uses the traditional Camel route domain-specific language (DSL), where we incorporate the master component along with the timer component (see link:src/main/java/org/acme/master/CamelRoute.java[CamelRoute]).
 
-Although we will ultimately deploy this application out to a Kubernetes cluster, we want to demonstrate and test this functionality in our local environment. When doing so, we won't have access to the https://kubernetes.io/docs/reference/kubernetes-api/cluster-resources/lease-v1/[Kubernetes leases], so we will implement the locking using the camel-file component. Because of the environmental differences, we will leverage Quarkus profiles to produce the correct CamelClusterService impleme [...]
+Although we will ultimately deploy this application out to a Kubernetes cluster, we want to demonstrate and test this functionality in our local environment. When doing so, we won't have access to the https://kubernetes.io/docs/reference/kubernetes-api/cluster-resources/lease-v1/[Kubernetes leases], so we will implement the locking using the camel-file component.
 
 If a new instance of the application is started locally, then the newly started application will not be able to obtain the locks and therefore will not run the timer component. If you kill the leader, the other application will check the lock, see that it's not locked, and subsequently obtain the lock and start processing. Additionally, we can apply settings to designate how often we want the service to check the locks and acquire the lock.
 
@@ -96,10 +96,9 @@ In a local environment, we used the FileLockClusterService. Now that we are read
 
 === Setup service account
 
-In this deployment, we have two replicas, but we want only one pod to run the processes. The configuration contains two items of note:
+In this deployment, we have two replicas, but we want only one pod to run the processes. The configuration note:
 
 * Notice the serviceAccountName in the deployment config. For this deployment, we need to set up a service account that specifically has access to the https://kubernetes.io/docs/reference/kubernetes-api/cluster-resources/lease-v1/[Kubernetes leases].
-* We are getting the kubernetes namespace from environment variable which is used to set up the `KubernetesClusterService` to point the same namespace as our application. This will tell the application to attempt to acquire the lease objects in the same namespace as our application.
 
 Before we deploy, we need to set up the service account and give it permissions to read and write to the lease objects:
 
@@ -113,7 +112,7 @@ kubectl apply -f src/main/kubernetes/service-account.yaml
 ==== Deploy
 [source,shell]
 ----
-mvn clean package -DskipTests -Dquarkus.kubernetes.deploy=true -Dkubernetes
+mvn clean package -DskipTests -Dquarkus.kubernetes.deploy=true -Dkubernetes -Dquarkus.camel.cluster.file.enabled=false -Dquarkus.camel.cluster.kubernetes.enabled=true
 ----
 
 Once we deploy the application into Kubernetes, the application will use the `KubernetesClusterService` implementation of the `CamelClusterService` to perform the leadership elections. To do this, the service will periodically query the lease information and attempt to update the information if the last update has not been performed in the designated lease time. The configuration for the timing of the leader election activity is more detailed, which should be expected; we are no longer s [...]
diff --git a/cluster-leader-election/src/main/java/org/acme/master/ClusterLockProducer.java b/cluster-leader-election/src/main/java/org/acme/master/ClusterLockProducer.java
deleted file mode 100644
index 86855c6..0000000
--- a/cluster-leader-election/src/main/java/org/acme/master/ClusterLockProducer.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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.acme.master;
-
-import java.util.concurrent.TimeUnit;
-
-import javax.enterprise.context.ApplicationScoped;
-import javax.enterprise.inject.Produces;
-
-import org.apache.camel.CamelContext;
-import org.apache.camel.cluster.CamelClusterService;
-import org.apache.camel.component.file.cluster.FileLockClusterService;
-import org.apache.camel.component.kubernetes.cluster.KubernetesClusterService;
-import org.eclipse.microprofile.config.inject.ConfigProperty;
-
-@ApplicationScoped
-public class ClusterLockProducer {
-
-    @ConfigProperty(name = "cluster.leader.election.root.folder", defaultValue = "target/cluster")
-    String rootFolder;
-
-    @Produces
-    public CamelClusterService clusterService(CamelContext camelContext) {
-        String kubernetesNamespace = System.getenv("KUBERNETES_NAMESPACE");
-        if (kubernetesNamespace != null) {
-            KubernetesClusterService service = new KubernetesClusterService();
-            service.setKubernetesNamespace(kubernetesNamespace);
-            return service;
-        } else {
-            FileLockClusterService service = new FileLockClusterService();
-            service.setRoot(rootFolder);
-            service.setAcquireLockDelay(1, TimeUnit.SECONDS);
-            service.setAcquireLockInterval(1, TimeUnit.SECONDS);
-            return service;
-        }
-    }
-
-}
diff --git a/cluster-leader-election/src/main/resources/application.properties b/cluster-leader-election/src/main/resources/application.properties
index 0b8307e..e3681da 100644
--- a/cluster-leader-election/src/main/resources/application.properties
+++ b/cluster-leader-election/src/main/resources/application.properties
@@ -43,8 +43,7 @@ quarkus.kubernetes.service-account=camel-leader-election
 #
 quarkus.openshift.service-account=camel-leader-election
 
-# Uncomment after https://github.com/apache/camel-quarkus/issues/3918 is solved
-#camel.cluster.file.enabled = true
-#camel.cluster.file.id = ${node.id}
-#camel.cluster.file.root = target/cluster wait for
+quarkus.camel.cluster.file.enabled = true
+quarkus.camel.cluster.file.id = ${node.id}
+quarkus.camel.cluster.file.root = target/cluster