Skip to content

Commit

Permalink
feat(quarkus): enable application.properties configuration
Browse files Browse the repository at this point in the history
* Allow for the process engine to be configured through an applicaton.properties file using a generic properties map which is applied to the QuarkusProcessEngineConfiguration instance through reflection.

Related to CAM-13629
  • Loading branch information
koevskinikola committed Aug 18, 2021
1 parent a94b523 commit ce3dfc0
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
* under one or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information regarding copyright
* ownership. Camunda licenses this file to you under the Apache License,
* Version 2.0; 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.camunda.bpm.quarkus.engine.test.config;

import static org.assertj.core.api.Assertions.assertThat;

import javax.inject.Inject;

import io.quarkus.test.QuarkusUnitTest;
import org.camunda.bpm.engine.ProcessEngine;
import org.camunda.bpm.quarkus.engine.extension.CamundaEngineConfig;
import org.camunda.bpm.quarkus.engine.extension.QuarkusProcessEngineConfiguration;
import org.camunda.bpm.quarkus.engine.test.helper.ProcessEngineAwareExtension;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

public class CamundaEngineConfigurationConfigTest {

@RegisterExtension
static final QuarkusUnitTest unitTest = new ProcessEngineAwareExtension()
.withConfigurationResource("process-engine-config-application.properties")
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class));

@Inject
CamundaEngineConfig config;

@Inject
ProcessEngine processEngine;

@Test
public void shouldLoadProcessEngineConfigurationProperties() {
// given a custom application.properties file

// then
assertThat(config.genericConfig.get("cmmn-enabled")).isEqualTo("false");
assertThat(config.genericConfig.get("dmn-enabled")).isEqualTo("false");
assertThat(config.genericConfig.get("history")).isEqualTo("none");
assertThat(config.genericConfig.get("initialize-telemetry")).isEqualTo("false");
}

@Test
public void shouldApplyProcessEngineConfigurationProperties() {
// given
// a ProcessEngineConfiguration instance
QuarkusProcessEngineConfiguration configuration
= (QuarkusProcessEngineConfiguration) processEngine.getProcessEngineConfiguration();

// then
assertThat(configuration.isCmmnEnabled()).isEqualTo(false);
assertThat(configuration.isDmnEnabled()).isEqualTo(false);
assertThat(configuration.getHistory()).isEqualTo("none");
assertThat(configuration.isInitializeTelemetry()).isEqualTo(false);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.camunda.bpm.quarkus.engine.test;
package org.camunda.bpm.quarkus.engine.test.config;

import static org.assertj.core.api.Assertions.assertThat;

Expand All @@ -28,7 +28,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

public class CamundaEngineConfigTest {
public class CamundaEngineJobExecutorConfigTest {

@RegisterExtension
static final QuarkusUnitTest unitTest = new ProcessEngineAwareExtension()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
quarkus.camunda.generic-properties.cmmn-enabled=false
quarkus.camunda.generic-properties.dmn-enabled=false
quarkus.camunda.generic-properties.history=none
quarkus.camunda.generic-properties.initialize-telemetry=false

quarkus.datasource.jdbc.url=jdbc:h2:mem:camunda;MVCC=TRUE;TRACE_LEVEL_FILE=0;DB_CLOSE_ON_EXIT=FALSE
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,23 @@
*/
package org.camunda.bpm.quarkus.engine.extension;

import java.util.Map;
import java.util.Optional;

import io.quarkus.runtime.annotations.ConfigItem;
import io.quarkus.runtime.annotations.ConfigPhase;
import io.quarkus.runtime.annotations.ConfigRoot;

import java.util.Optional;

@ConfigRoot(phase = ConfigPhase.RUN_TIME, name = "camunda")
public class CamundaEngineConfig {

/**
* The Camunda ProcessEngineConfiguration properties. For more details,
* @see <a href="https://docs.camunda.org/manual/latest/reference/deployment-descriptors/tags/process-engine/#configuration-properties">Process Engine Configuration Properties</a>.
*/
@ConfigItem(name = "generic-properties")
public Map<String, String> genericConfig;

/**
* The Camunda JobExecutor config. It provides available job acquisition thread configuration
* properties. These properties only take effect in a Quarkus environment.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
public class CamundaJobExecutorConfig {

/**
* The Camunda JobExecutor configuration properties. For more details, see
* {@link https://docs.camunda.org/manual/latest/reference/deployment-descriptors/tags/job-executor/#job-acquisition-configuration-properties}
* The Camunda JobExecutor configuration properties. For more details,
* @see <a href="https://docs.camunda.org/manual/latest/reference/deployment-descriptors/tags/job-executor/#job-acquisition-configuration-properties">Job-Acquisition Configuration Properties</a>
*/
@ConfigItem(name = ConfigItem.PARENT)
public Map<String, String> genericConfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@
*/
package org.camunda.bpm.quarkus.engine.extension.impl;

import static com.arjuna.ats.jta.TransactionManager.transactionManager;
import static io.quarkus.datasource.common.runtime.DataSourceUtil.DEFAULT_DATASOURCE_NAME;

import javax.enterprise.inject.spi.BeanManager;
import java.util.ArrayList;
import java.util.List;

import io.quarkus.agroal.runtime.DataSources;
import io.quarkus.arc.runtime.BeanContainer;
import io.quarkus.runtime.RuntimeValue;
Expand All @@ -34,13 +41,6 @@
import org.camunda.bpm.quarkus.engine.extension.QuarkusProcessEngineConfiguration;
import org.eclipse.microprofile.context.ManagedExecutor;

import javax.enterprise.inject.spi.BeanManager;
import java.util.ArrayList;
import java.util.List;

import static com.arjuna.ats.jta.TransactionManager.transactionManager;
import static io.quarkus.datasource.common.runtime.DataSourceUtil.DEFAULT_DATASOURCE_NAME;

@Recorder
public class CamundaEngineRecorder {

Expand All @@ -55,6 +55,10 @@ public RuntimeValue<ProcessEngineConfigurationImpl> createProcessEngineConfigura
CamundaEngineConfig config) {
QuarkusProcessEngineConfiguration configuration = beanContainer.instance(QuarkusProcessEngineConfiguration.class);

// apply properties from config before the datasource configuration.
// We always want to use a Quarkus datasource.
PropertyHelper.applyProperties(configuration, config.genericConfig, PropertyHelper.KEBAB_CASE);

if (configuration.getDataSource() == null) {
String datasource = config.datasource.orElse(DEFAULT_DATASOURCE_NAME);
configuration.setDataSource(DataSources.fromName(datasource));
Expand Down

0 comments on commit ce3dfc0

Please sign in to comment.