Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FMWK-554 Refactor and restructure starters modules #265

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
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
15 changes: 10 additions & 5 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ image:https://github.com/aerospike-community/spring-data-aerospike-starters/work

|===
|`spring-data-aerospike-starters` |`spring-data-aerospike` |`aerospike-client` |`aerospike-reactor-client`
|0.17.x
|5.0.x
|7.2.x
|7.1.x

|0.15.x, 0.16.x
|4.8.x
|7.2.x
Expand Down Expand Up @@ -108,11 +113,11 @@ spring.data.aerospike.repositories.type=NONE

== Example

You can find usage example in {repo-master}/spring-boot-starter-data-aerospike-example[_spring-boot-starter-data-aerospike-example_] module.
You can find usage example in {repo-master}/spring-boot-starter-example-aerospike[_spring-boot-starter-example-aerospike_] module.

Both reactive and sync examples are based on `embedded-aerospike` dependency usage (which requires docker to be running on the machine). This is the only requirement to be able to run the tests on your machine.
Both reactive and sync examples are based on `embedded-aerospike` dependency usage (which requires Docker to be running on the machine). This is the only requirement to be able to run the tests on your machine.

If you want to run the tests in these modules against your Aerospike instance follow the steps:
If you want to run the tests in these modules against your Aerospike instance follow these steps:

. Update `application.properties` file with the required Aerospike settings (host, port, namespace). This will point spring-data to your Aerospike instance.
. Update with `bootstrap.properties` file with `embedded.containers.enabled=false`. This will disable setup of embedded Aerospike.
. Update `application.properties` file with the required Aerospike settings (hosts, namespace). This will point spring-data to your Aerospike instance.
. Update `bootstrap.properties` file with `embedded.containers.enabled=false`. This will disable setup of embedded Aerospike.
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,11 +38,30 @@
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>3.1.3</version>
<executions>
<execution>
<goals>
<goal>deploy</goal>
</goals>
<configuration>
<deploy>false</deploy>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright 2019 the original author or authors.
*
* Licensed 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
*
* https://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.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.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.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.
*
* @author Anastasiia Smirnova
*/
@AutoConfiguration
@ConditionalOnClass(IAerospikeClient.class)
@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 Expand Up @@ -157,7 +158,7 @@ public abstract static class PolicyDefault {
public Duration sleepBetweenRetries;

/**
* If the key is sent on a write, the key will be stored with the record on the server.
* If the key is sent in a write operation, it will be stored with the record on the server.
*/
public Boolean sendKey;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.springframework.boot.autoconfigure.condition;

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.condition;

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.condition;

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
Expand Up @@ -19,7 +19,6 @@
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.data.aerospike.config.AerospikeDataSettings;

/**
* Configuration properties for Spring Data Aerospike.
Expand All @@ -38,12 +37,12 @@ public class AerospikeDataProperties {
private String namespace;

/**
* Bin name that will be used for storing entity's type.
* Bin name that will be used for storing entity's type. Default value is null
* <p>
*
* @see org.springframework.data.aerospike.convert.AerospikeTypeAliasAccessor
*/
private String typeKey = "@_class";
private String classKey = "@_class";

/**
* Gives ability to disable queries that will run scan on Aerospike server.
Expand Down
Loading
Loading