Skip to content

Commit

Permalink
use distributed configuration, add client-only modules, refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
agrgr committed Dec 22, 2024
1 parent 7f99c0b commit 3adc8b9
Show file tree
Hide file tree
Showing 86 changed files with 878 additions and 355 deletions.
37 changes: 23 additions & 14 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@
<packaging>pom</packaging>

<modules>
<module>spring-boot-autoconfigure-data-aerospike</module>
<module>spring-boot-starter-data-aerospike</module>
<module>spring-boot-starter-data-aerospike-reactive</module>
<module>spring-boot-starter-data-aerospike-example</module>
<module>spring-boot-autoconfigure-aerospike-common</module> <!-- common configuration, internal dependency -->
<module>spring-boot-starter-aerospike</module> <!-- Sync Aerospike client -->
<module>spring-boot-starter-aerospike-reactive</module> <!-- Reactive Aerospike client -->
<module>spring-boot-starter-data-aerospike</module> <!-- Sync Spring Data Aerospike flow -->
<module>spring-boot-starter-data-aerospike-reactive</module> <!-- Reactive Spring Data Aerospike flow -->
<module>spring-boot-starter-example-aerospike</module> <!-- Usage examples -->
</modules>

<properties>
Expand All @@ -40,7 +42,7 @@
<maven.gpg.plugin.version>1.6</maven.gpg.plugin.version>
<flatten.maven.plugin.version>1.6.0</flatten.maven.plugin.version>

<spring-data-aerospike.version>4.8.0</spring-data-aerospike.version>
<spring-data-aerospike.version>4.8.0-local-554_latest</spring-data-aerospike.version>
<aerospike-reactor-client.version>7.1.0</aerospike-reactor-client.version>
<aerospike-client.version>7.2.1</aerospike-client.version>
<embedded-aerospike.version>3.1.6</embedded-aerospike.version>
Expand Down Expand Up @@ -102,37 +104,44 @@
<dependencies>
<dependency>
<groupId>com.aerospike</groupId>
<artifactId>spring-boot-autoconfigure-data-aerospike</artifactId>
<artifactId>spring-boot-autoconfigure-aerospike-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.aerospike</groupId>
<artifactId>spring-boot-starter-data-aerospike-reactive</artifactId>
<artifactId>spring-boot-starter-aerospike</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.aerospike</groupId>
<artifactId>spring-boot-starter-aerospike-reactive</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.aerospike</groupId>
<artifactId>spring-boot-starter-data-aerospike</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>com.aerospike</groupId>
<artifactId>spring-data-aerospike</artifactId>
<version>${spring-data-aerospike.version}</version>
<artifactId>spring-boot-starter-data-aerospike-reactive</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>com.aerospike</groupId>
<artifactId>aerospike-reactor-client</artifactId>
<version>${aerospike-reactor-client.version}</version>
<artifactId>spring-data-aerospike</artifactId>
<version>${spring-data-aerospike.version}</version>
</dependency>
<dependency>
<groupId>com.aerospike</groupId>
<artifactId>aerospike-client</artifactId>
<version>${aerospike-client.version}</version>
</dependency>

<dependency>
<groupId>com.aerospike</groupId>
<artifactId>aerospike-reactor-client</artifactId>
<version>${aerospike-reactor-client.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-test-support</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,25 @@
<version>${revision}</version>
</parent>

<name>Spring Data Aerospike Starters: spring-boot-autoconfigure-data-aerospike</name>
<artifactId>spring-boot-autoconfigure-data-aerospike</artifactId>
<name>Spring Data Aerospike Starters: spring-boot-autoconfigure-aerospike-common</name>
<artifactId>spring-boot-autoconfigure-aerospike-common</artifactId>
<description>Auto configuration for using Spring Data Aerospike</description>

<dependencies>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.aerospike</groupId>
<artifactId>spring-data-aerospike</artifactId>
<optional>true</optional>
</dependency>

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

<dependency>
<groupId>com.aerospike</groupId>
<artifactId>aerospike-client</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>com.aerospike</groupId>
<artifactId>aerospike-reactor-client</artifactId>
<artifactId>spring-data-aerospike</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure-processor</artifactId>
Expand All @@ -54,7 +38,6 @@
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,17 @@
package org.springframework.boot.autoconfigure.aerospike;

import com.aerospike.client.IAerospikeClient;
import com.aerospike.client.policy.ClientPolicy;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.data.aerospike.AerospikeDataProperties;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.util.ValidateHostsProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;

import static org.springframework.boot.autoconfigure.util.AerospikeConfigurationUtils.getClientPolicyConfig;

/**
* {@link EnableAutoConfiguration Auto-configuration} for Aerospike client.
Expand All @@ -31,7 +36,13 @@
*/
@AutoConfiguration
@ConditionalOnClass(IAerospikeClient.class)
@ConditionalOnProperty("spring.aerospike.hosts")
@EnableConfigurationProperties({AerospikeProperties.class, AerospikeDataProperties.class}) // TODO: should data properties be here?
@Conditional(ValidateHostsProperty.class)
@EnableConfigurationProperties(AerospikeProperties.class)
public class AerospikeAutoConfiguration {

@Bean
@ConditionalOnMissingBean
public ClientPolicy aerospikeClientPolicy(AerospikeProperties properties) {
return getClientPolicyConfig(new ClientPolicy(), properties);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,19 @@
import com.aerospike.client.policy.AuthMode;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.data.aerospike.config.AerospikeDataSettings;

import java.time.Duration;

import static org.springframework.data.aerospike.config.AerospikeDataConfigurationSupport.CONFIG_PREFIX_CONNECTION;

/**
* Basic configuration properties for Aerospike client.
* For more details on each option see corresponding field documentation in {@link com.aerospike.client.policy.ClientPolicy}.
*
* @author Anastasiia Smirnova
*/
@Data
@ConfigurationProperties(prefix = "spring.aerospike")
@ConfigurationProperties(prefix = CONFIG_PREFIX_CONNECTION)
public class AerospikeProperties {

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.springframework.boot.autoconfigure.utils;
package org.springframework.boot.autoconfigure.util;

import com.aerospike.client.Host;
import com.aerospike.client.policy.BatchDeletePolicy;
Expand Down Expand Up @@ -28,14 +28,6 @@ public static Collection<Host> getClientHosts(AerospikeProperties properties) {
}
}

public static String getNamespace(AerospikeDataProperties dataProperties) {
if (dataProperties.getNamespace() != null) {
return dataProperties.getNamespace();
} else {
return null;
}
}

public static ClientPolicy getClientPolicyConfig(ClientPolicy clientPolicy, AerospikeProperties properties) {
whenPresent(properties.getUser(), p -> clientPolicy.user = p);
whenPresent(properties.getPassword(), p -> clientPolicy.password = p);
Expand All @@ -57,11 +49,6 @@ public static ClientPolicy getClientPolicyConfig(ClientPolicy clientPolicy, Aero
clientPolicy.batchWritePolicyDefault = setupBatchWritePolicy(properties);
clientPolicy.batchDeletePolicyDefault = setupBatchDeletePolicy(properties);
clientPolicy.batchUDFPolicyDefault = setupBatchUDFPolicy(properties);
// aerospikeEventLoops.ifPresent(loops -> clientPolicy.eventLoops = loops); // TODO

// clientPolicy.user = "tester";
// clientPolicy.password = "psw";

return clientPolicy;
}

Expand Down Expand Up @@ -137,8 +124,16 @@ private static <T> void whenPresent(T param, Consumer<T> consumer) {
consumer.accept(param);
}

public static String getNamespace(AerospikeDataProperties dataProperties) {
if (dataProperties.getNamespace() != null) {
return dataProperties.getNamespace();
} else {
return null;
}
}

public static void getDataSettings(AerospikeDataProperties dataProperties,
AerospikeDataSettings aerospikeDataSettings) {
AerospikeDataSettings aerospikeDataSettings) {
whenPresent(dataProperties.isScansEnabled(), aerospikeDataSettings::setScansEnabled);
whenPresent(dataProperties.isCreateIndexesOnStartup(), aerospikeDataSettings::setCreateIndexesOnStartup);
whenPresent(dataProperties.getIndexCacheRefreshSeconds(), aerospikeDataSettings::setIndexCacheRefreshSeconds);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.springframework.boot.autoconfigure.util;

import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;

import static org.springframework.data.aerospike.config.AerospikeDataConfigurationSupport.CONFIG_PREFIX_DATA;

public class IsClientOnly implements Condition {

@Override
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
String strIsClientOnly = context.getEnvironment().getProperty("starters.aerospike.client-only");
String namespace = context.getEnvironment().getProperty(CONFIG_PREFIX_DATA + ".namespace");
boolean isClientOnly = strIsClientOnly != null && strIsClientOnly.equalsIgnoreCase("true");
boolean hasNamespace = namespace != null && !namespace.isEmpty();
// if the explicit client-only property is true, no need to check for namespace
return isClientOnly || !hasNamespace;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.springframework.boot.autoconfigure.util;

import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;

import static org.springframework.data.aerospike.config.AerospikeDataConfigurationSupport.CONFIG_PREFIX_DATA;

public class IsNotClientOnly implements Condition {

@Override
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
String strIsClientOnly = context.getEnvironment().getProperty("starters.aerospike.client-only");
String namespace = context.getEnvironment().getProperty(CONFIG_PREFIX_DATA + ".namespace");
boolean isClientOnly = strIsClientOnly != null
&& !strIsClientOnly.isEmpty()
&& Boolean.getBoolean(strIsClientOnly);
boolean hasNamespace = namespace != null && !namespace.isEmpty();
// if the explicit client-only property is true, no need to check for namespace
return !isClientOnly && hasNamespace;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.springframework.boot.autoconfigure.util;

import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;

import java.security.InvalidParameterException;

import static org.springframework.data.aerospike.config.AerospikeDataConfigurationSupport.CONFIG_PREFIX_CONNECTION;

public class ValidateHostsProperty implements Condition {

@Override
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
String hostsProperty = CONFIG_PREFIX_CONNECTION + ".hosts";
String hosts = context.getEnvironment().getProperty(hostsProperty);
boolean hasHosts = hosts != null && !hosts.isEmpty();

if (!hasHosts) {
throw new InvalidParameterException("Required property '" + hostsProperty + "' is missing");
}
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Auto Configure
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.springframework.boot.autoconfigure.aerospike.AerospikeAutoConfiguration,\
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.springframework.boot.autoconfigure.aerospike.AerospikeAutoConfiguration

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 3adc8b9

Please sign in to comment.