Skip to content

Commit

Permalink
feat: Added database type enum
Browse files Browse the repository at this point in the history
  • Loading branch information
jruaux committed Mar 18, 2024
1 parent 41d90e4 commit aacc417
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 32 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.6.0
0.7.0-SNAPSHOT
6 changes: 6 additions & 0 deletions core/redis-enterprise-admin/redis-enterprise-admin.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,10 @@ bootJar {
jar {
enabled = true
archiveClassifier = ''
}

eclipse {
project {
name = 'redis-enterprise-admin-core'
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.apache.hc.client5.http.classic.methods.HttpPost;
import org.apache.hc.client5.http.impl.auth.BasicScheme;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
import org.apache.hc.client5.http.impl.classic.HttpClients;
import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder;
Expand All @@ -35,7 +34,6 @@
import org.apache.hc.core5.http.HttpHeaders;
import org.apache.hc.core5.http.HttpHost;
import org.apache.hc.core5.http.HttpStatus;
import org.apache.hc.core5.http.ParseException;
import org.apache.hc.core5.http.io.entity.EntityUtils;
import org.apache.hc.core5.http.io.entity.StringEntity;
import org.apache.hc.core5.ssl.SSLContexts;
Expand Down Expand Up @@ -184,17 +182,13 @@ private <T> T read(ClassicHttpRequest request, JavaType type, int successCode)
BasicScheme basicAuth = new BasicScheme();
basicAuth.initPreemptive(new UsernamePasswordCredentials(userName, password.toCharArray()));
localContext.resetAuthExchange(target, basicAuth);
CloseableHttpResponse response = client().execute(request, localContext);
String json;
try {
json = EntityUtils.toString(response.getEntity());
} catch (ParseException e) {
throw new HttpResponseParsingException("Could not parse response", e);
}
if (response.getCode() == successCode) {
return objectMapper.readValue(json, type);
}
throw new HttpResponseException(response.getCode(), response.getReasonPhrase() + " " + json);
return client().execute(request, localContext, r -> {
String content = EntityUtils.toString(r.getEntity());
if (r.getCode() == successCode) {
return objectMapper.readValue(content, type);
}
throw new HttpResponseException(r.getCode(), r.getReasonPhrase() + " " + content);
});
}

private CloseableHttpClient client() throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException {
Expand All @@ -211,15 +205,6 @@ private CloseableHttpClient client() throws KeyManagementException, NoSuchAlgori
return client;
}

private static class HttpResponseParsingException extends IOException {

private static final long serialVersionUID = 1L;

public HttpResponseParsingException(String message, Throwable cause) {
super(message, cause);
}
}

public List<InstalledModule> getModules() throws IOException, GeneralSecurityException {
return get(v1(MODULES),
objectMapper.getTypeFactory().constructCollectionType(List.class, InstalledModule.class));
Expand All @@ -242,11 +227,11 @@ public Database createDatabase(Database database) throws IOException, GeneralSec
.until(() -> executeCommand(uid, new Command("PING")).getResponse().asBoolean());
return response;
}

public List<Database> getDatabases() throws IOException, GeneralSecurityException {
return get(v1(BDBS), objectMapper.getTypeFactory().constructCollectionType(List.class, Database.class));
}

public void deleteAllDatabases() throws IOException, GeneralSecurityException {
getDatabases().stream().map(Database::getUid).forEach(this::deleteDatabase);
Awaitility.await().until(() -> getDatabases().isEmpty());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static List<String> defaultShardKeyRegexes() {
private boolean sharding;
private long memory = DEFAULT_MEMORY;
private Integer port;
private String type;
private Type type;
private boolean ossCluster;
private ProxyPolicy proxyPolicy;
private IPType ossClusterAPIPreferredIPType;
Expand Down Expand Up @@ -117,11 +117,11 @@ public void setPort(Integer port) {
this.port = port;
}

public String getType() {
public Type getType() {
return type;
}

public void setType(String type) {
public void setType(Type type) {
this.type = type;
}

Expand Down Expand Up @@ -231,6 +231,12 @@ public enum ShardPlacement {
SPARSE
}

public enum Type {
@JsonProperty("redis")
REDIS, @JsonProperty("memcached")
MEMCACHED
}

@JsonInclude(JsonInclude.Include.NON_NULL)
public static class ModuleConfig {

Expand Down Expand Up @@ -308,7 +314,7 @@ public static final class Builder {
private boolean sharding;
private long memory = DEFAULT_MEMORY;
private Integer port;
private String type;
private Type type;
private boolean ossCluster;
private ProxyPolicy proxyPolicy;
private IPType ossClusterAPIPreferredIPType;
Expand Down Expand Up @@ -367,7 +373,7 @@ public Builder port(Integer port) {
return this;
}

public Builder type(String type) {
public Builder type(Type type) {
this.type = type;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class TestRedisEnterpriseContainer extends AbstractRedisEnterpriseContain
private Database database = Database.builder().shardCount(2).port(12000).ossCluster(true)
.modules(RedisModule.SEARCH, RedisModule.JSON, RedisModule.TIMESERIES, RedisModule.BLOOM).build();

private static final Logger log = LoggerFactory.getLogger(TestRedisEnterpriseContainer.class);
private final Logger log = LoggerFactory.getLogger(TestRedisEnterpriseContainer.class);

public TestRedisEnterpriseContainer(String dockerImageName) {
super(dockerImageName);
Expand Down
3 changes: 2 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ buildscript {

apply plugin: 'org.kordamp.gradle.kordamp-parentbuild'

rootProject.name = 'redis-enterprise-admin-root'
rootProject.name = 'redis-enterprise-admin'

projects {
directories = ['core']
Expand All @@ -25,6 +25,7 @@ projects {
id 'org.kordamp.gradle.java-project'
}
dirs(['core']) {
id 'eclipse'
id 'java-library'
id 'org.springframework.boot'
id 'io.spring.dependency-management'
Expand Down

0 comments on commit aacc417

Please sign in to comment.