Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions DeployConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@
"type": "CONFIG",
"essential": false
},
{
"name": "MODULE_VERSION",
"value": null,
"description": "Exact module version including CI build number. Must be identical to MODULE_VERSION of the associated sidecar container.",
"type": "CONFIG",
"essential": true
Comment thread
PBobylev marked this conversation as resolved.
Resolved
},
{
"name": "JAVA_OPTIONS",
"value": null,
Expand Down Expand Up @@ -154,6 +161,34 @@
"type": "KAFKA",
"essential": true
},
{
"name": "KAFKA_TENANT_FILTER_ENABLED",
"value": "false",
"description": "Enables Kafka tenant filtering: messages are processed only for tenants entitled to this module version",
"type": "KAFKA",
"essential": false
},
{
"name": "KAFKA_TENANT_FILTER_TENANT_DISABLED_STRATEGY",
"value": "skip",
"description": "Strategy applied to a Kafka message of a non-entitled tenant",
"type": "KAFKA",
"essential": false
},
{
"name": "KAFKA_TENANT_FILTER_ALL_TENANTS_DISABLED_STRATEGY",
Comment thread
PBobylev marked this conversation as resolved.
Resolved
"value": "fail",
"description": "Strategy applied when no tenant is entitled to this module version",
"type": "KAFKA",
"essential": false
},
{
"name": "KAFKA_TENANT_FILTER_ENTITLEMENT_REFRESH_INTERVAL_SECONDS",
"value": "900",
"description": "Interval in seconds for refreshing the tenant entitlement cache",
"type": "KAFKA",
"essential": false
},
{
"name": "KAFKA_PRODUCER_TENANT_COLLECTION",
"value": "ALL",
Expand Down
37 changes: 21 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,27 @@ API for Data Export Spring module.

## Environment variables:

| Name | Default value | Description |
|:----------------------------------------|:-----------------------:|:-------------------------------------------------------------------------------------------------------------------------------------------------------|
| DB_HOST | postgres | Postgres hostname |
| DB_PORT | 5432 | Postgres port |
| DB_USERNAME | folio_admin | Postgres username |
| DB_PASSWORD | - | Postgres username password |
| DB_DATABASE | okapi_modules | Postgres database name |
| KAFKA_HOST | kafka | Kafka broker hostname |
| KAFKA_PORT | 9092 | Kafka broker port |
| OKAPI_URL | http://okapi:9130 | Okapi url |
| SYSTEM\_USER\_NAME | data-export-system-user | Username of the system user |
| SYSTEM\_USER\_PASSWORD | - | Password of the system user |
| SYSTEM\_USER\_ENABLED | true | Defines if system user must be created at service tenant initialization or used for egress service requests |
| ENV | folio | Logical name of the deployment, must be set if Kafka/Elasticsearch are shared for environments, `a-z (any case)`, `0-9`, `-`, `_` symbols only allowed |
| JOB_EXPIRATION_PERIOD_DAYS | 7 | Expiration period of export jobs, acquisition jobs have no expiration, bulk edit jobs use own rules to define it with using mod-configuration |
| JOB_DOWNLOAD_FILE_CONNECTION_TIMEOUT_MS | 5000 | Connection timeout to download exported file from storage |
| Name | Default value | Description |
|:---------------------------------------------------------|:----------------------------:|:-------------------------------------------------------------------------------------------------------------------------------------------------------|
| DB_HOST | postgres | Postgres hostname |
| DB_PORT | 5432 | Postgres port |
| DB_USERNAME | folio_admin | Postgres username |
| DB_PASSWORD | - | Postgres username password |
| DB_DATABASE | okapi_modules | Postgres database name |
| KAFKA_HOST | kafka | Kafka broker hostname |
| KAFKA_PORT | 9092 | Kafka broker port |
| KAFKA_TENANT_FILTER_ENABLED | false | Enables tenant-aware Kafka message filtering for mixed-version deployments |
| KAFKA_TENANT_FILTER_TENANT_DISABLED_STRATEGY | skip | Strategy applied when a message's tenant is not entitled to this module version. Supported values are `ACCEPT`, `SKIP`, and `FAIL` |
| KAFKA_TENANT_FILTER_ALL_TENANTS_DISABLED_STRATEGY | fail | Strategy applied when no tenants are entitled to this module version. Supported values are `FAIL` and `SKIP` |
| KAFKA_TENANT_FILTER_ENTITLEMENT_REFRESH_INTERVAL_SECONDS | 900 | Interval in seconds for refreshing the tenant-entitlement cache |
| MODULE_VERSION | project version from pom.xml | **Required.** Exact module version including CI build number. Must be identical to the `MODULE_VERSION` supplied to this module's sidecar container |
| OKAPI_URL | http://okapi:9130 | Okapi url |
| SYSTEM\_USER\_NAME | data-export-system-user | Username of the system user |
| SYSTEM\_USER\_PASSWORD | - | Password of the system user |
| SYSTEM\_USER\_ENABLED | true | Defines if system user must be created at service tenant initialization or used for egress service requests |
| ENV | folio | Logical name of the deployment, must be set if Kafka/Elasticsearch are shared for environments, `a-z (any case)`, `0-9`, `-`, `_` symbols only allowed |
| JOB_EXPIRATION_PERIOD_DAYS | 7 | Expiration period of export jobs, acquisition jobs have no expiration, bulk edit jobs use own rules to define it with using mod-configuration |
| JOB_DOWNLOAD_FILE_CONNECTION_TIMEOUT_MS | 5000 | Connection timeout to download exported file from storage |


## Additional information
Expand Down
14 changes: 7 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>4.1.1</version>
<version>4.1.2</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>

Expand Down Expand Up @@ -34,7 +34,7 @@
<export-configs.yaml.file>${project.basedir}/src/main/resources/swagger.api/export-configs.yaml</export-configs.yaml.file>
<job-deletion-intervals.yaml.file>${project.basedir}/src/main/resources/swagger.api/job-deletion-intervals.yaml</job-deletion-intervals.yaml.file>

<folio-spring-base.version>10.0.1</folio-spring-base.version>
<folio-spring-base.version>10.1.0-SNAPSHOT</folio-spring-base.version>
<folio-service-tools.version>6.0.1</folio-service-tools.version>
<folio-module-descriptor-validator.version>1.0.1</folio-module-descriptor-validator.version>
<lombok.version>1.18.48</lombok.version>
Expand Down Expand Up @@ -69,6 +69,11 @@
<artifactId>folio-spring-base</artifactId>
<version>${folio-spring-base.version}</version>
</dependency>
<dependency>
<groupId>org.folio</groupId>
<artifactId>folio-spring-kafka</artifactId>
<version>${folio-spring-base.version}</version>
</dependency>
<dependency>
<groupId>org.folio</groupId>
<artifactId>folio-service-tools-spring-dev</artifactId>
Expand Down Expand Up @@ -115,11 +120,6 @@
<artifactId>spring-boot-starter-quartz</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-kafka</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.apache.kafka.common.serialization.StringSerializer;
import org.folio.spring.FolioExecutionContext;
import org.folio.spring.FolioModuleMetadata;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.kafka.autoconfigure.KafkaProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -29,7 +30,8 @@ public class KafkaConfiguration {
private final KafkaProperties kafkaProperties;

@Bean
public <V> ConcurrentKafkaListenerContainerFactory<String, V> kafkaListenerContainerFactory(ConsumerFactory<String, V> cf) {
public <V> ConcurrentKafkaListenerContainerFactory<String, V> kafkaListenerContainerFactory(
@Qualifier("consumerFactory") ConsumerFactory<String, V> cf) {
var factory = new ConcurrentKafkaListenerContainerFactory<String, V>();
factory.setConsumerFactory(cf);
if (kafkaProperties.getListener().getAckMode() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ public class JobUpdatesListenerService {
id = KafkaService.EVENT_LISTENER_ID,
containerFactory = "kafkaListenerContainerFactory",
topicPattern = "${application.kafka.topic-pattern}",
groupId = "${application.kafka.group-id}")
groupId = "${application.kafka.group-id}",
filter = "tenantAwareMessageFilter")
Comment thread
PBobylev marked this conversation as resolved.
Resolved
public void receiveJobExecutionUpdate(@Payload Job jobExecutionUpdate, @Headers Map<String, Object> messageHeaders) {
var defaultFolioExecutionContext = DefaultFolioExecutionContext.fromMessageHeaders(folioModuleMetadata, messageHeaders);
try (var context = new FolioExecutionContextSetter(defaultFolioExecutionContext)) {
Expand Down
35 changes: 35 additions & 0 deletions src/main/java/org/folio/des/service/ModuleVersionChecker.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.folio.des.service;

import jakarta.annotation.PostConstruct;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

/** Warns on startup if the Kafka tenant filter is enabled but MODULE_VERSION is not set. */
@Log4j2
@Component
@RequiredArgsConstructor
@ConditionalOnProperty(prefix = "folio.kafka.tenant-filter", name = "enabled", havingValue = "true")
public class ModuleVersionChecker {

static final String MODULE_VERSION = "MODULE_VERSION";

private final Environment environment;

@PostConstruct
void check() {
if (!isModuleVersionSet()) {
log.warn(
"Kafka tenant filter is enabled, but {} is not set. The version without the CI build "
+ "number will be used, which may cause entitlement lookup to fail",
MODULE_VERSION);
}
}

private boolean isModuleVersionSet() {
return StringUtils.isNotBlank(environment.getProperty(MODULE_VERSION));
}
}
12 changes: 11 additions & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
folio:
kafka:
tenant-filter:
enabled: ${KAFKA_TENANT_FILTER_ENABLED:false}
ignore-empty-batch: true
tenant-disabled-strategy: ${KAFKA_TENANT_FILTER_TENANT_DISABLED_STRATEGY:skip}
all-tenants-disabled-strategy: ${KAFKA_TENANT_FILTER_ALL_TENANTS_DISABLED_STRATEGY:fail}
entitlement-refresh-interval-seconds: ${KAFKA_TENANT_FILTER_ENTITLEMENT_REFRESH_INTERVAL_SECONDS:900}
system-user:
enabled: ${SYSTEM_USER_ENABLED:true}
username: ${SYSTEM_USER_NAME:data-export-system-user}
Expand All @@ -23,9 +30,12 @@ logging:
level:
liquibase: debug
org.folio.des.client.*: debug
okapi:
url: ${folio.okapi-url}
spring:
application:
name: mod-data-export-spring
version: ${MODULE_VERSION:@project.version@}
jpa:
hibernate:
ddl-auto: none
Expand Down Expand Up @@ -94,7 +104,7 @@ application:
"data-export.job.command":
partitions: ${DATA_EXPORT_JOB_COMMAND_TOPIC_PARTITIONS:50}
topic-pattern: ${ENV:folio}.(.*\.)?data-export.job.update
group-id: ${ENV:folio}-mod-data-export-spring-events-group
group-id: ${ENV:folio}-mod-data-export-spring-events-group-${spring.application.version}
job:
expirationPeriodDays: ${JOB_EXPIRATION_PERIOD_DAYS:7}
downloadFileConnectionTimeoutMs: ${JOB_DOWNLOAD_FILE_CONNECTION_TIMEOUT_MS:5000}
Loading
Loading