Skip to content

Commit aacc417

Browse files
committed
feat: Added database type enum
1 parent 41d90e4 commit aacc417

File tree

6 files changed

+30
-32
lines changed

6 files changed

+30
-32
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.6.0
1+
0.7.0-SNAPSHOT

core/redis-enterprise-admin/redis-enterprise-admin.gradle

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,10 @@ bootJar {
2121
jar {
2222
enabled = true
2323
archiveClassifier = ''
24+
}
25+
26+
eclipse {
27+
project {
28+
name = 'redis-enterprise-admin-core'
29+
}
2430
}

core/redis-enterprise-admin/src/main/java/com/redis/enterprise/Admin.java

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import org.apache.hc.client5.http.classic.methods.HttpPost;
2222
import org.apache.hc.client5.http.impl.auth.BasicScheme;
2323
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
24-
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
2524
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
2625
import org.apache.hc.client5.http.impl.classic.HttpClients;
2726
import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder;
@@ -35,7 +34,6 @@
3534
import org.apache.hc.core5.http.HttpHeaders;
3635
import org.apache.hc.core5.http.HttpHost;
3736
import org.apache.hc.core5.http.HttpStatus;
38-
import org.apache.hc.core5.http.ParseException;
3937
import org.apache.hc.core5.http.io.entity.EntityUtils;
4038
import org.apache.hc.core5.http.io.entity.StringEntity;
4139
import org.apache.hc.core5.ssl.SSLContexts;
@@ -184,17 +182,13 @@ private <T> T read(ClassicHttpRequest request, JavaType type, int successCode)
184182
BasicScheme basicAuth = new BasicScheme();
185183
basicAuth.initPreemptive(new UsernamePasswordCredentials(userName, password.toCharArray()));
186184
localContext.resetAuthExchange(target, basicAuth);
187-
CloseableHttpResponse response = client().execute(request, localContext);
188-
String json;
189-
try {
190-
json = EntityUtils.toString(response.getEntity());
191-
} catch (ParseException e) {
192-
throw new HttpResponseParsingException("Could not parse response", e);
193-
}
194-
if (response.getCode() == successCode) {
195-
return objectMapper.readValue(json, type);
196-
}
197-
throw new HttpResponseException(response.getCode(), response.getReasonPhrase() + " " + json);
185+
return client().execute(request, localContext, r -> {
186+
String content = EntityUtils.toString(r.getEntity());
187+
if (r.getCode() == successCode) {
188+
return objectMapper.readValue(content, type);
189+
}
190+
throw new HttpResponseException(r.getCode(), r.getReasonPhrase() + " " + content);
191+
});
198192
}
199193

200194
private CloseableHttpClient client() throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException {
@@ -211,15 +205,6 @@ private CloseableHttpClient client() throws KeyManagementException, NoSuchAlgori
211205
return client;
212206
}
213207

214-
private static class HttpResponseParsingException extends IOException {
215-
216-
private static final long serialVersionUID = 1L;
217-
218-
public HttpResponseParsingException(String message, Throwable cause) {
219-
super(message, cause);
220-
}
221-
}
222-
223208
public List<InstalledModule> getModules() throws IOException, GeneralSecurityException {
224209
return get(v1(MODULES),
225210
objectMapper.getTypeFactory().constructCollectionType(List.class, InstalledModule.class));
@@ -242,11 +227,11 @@ public Database createDatabase(Database database) throws IOException, GeneralSec
242227
.until(() -> executeCommand(uid, new Command("PING")).getResponse().asBoolean());
243228
return response;
244229
}
245-
230+
246231
public List<Database> getDatabases() throws IOException, GeneralSecurityException {
247232
return get(v1(BDBS), objectMapper.getTypeFactory().constructCollectionType(List.class, Database.class));
248233
}
249-
234+
250235
public void deleteAllDatabases() throws IOException, GeneralSecurityException {
251236
getDatabases().stream().map(Database::getUid).forEach(this::deleteDatabase);
252237
Awaitility.await().until(() -> getDatabases().isEmpty());

core/redis-enterprise-admin/src/main/java/com/redis/enterprise/Database.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public static List<String> defaultShardKeyRegexes() {
3535
private boolean sharding;
3636
private long memory = DEFAULT_MEMORY;
3737
private Integer port;
38-
private String type;
38+
private Type type;
3939
private boolean ossCluster;
4040
private ProxyPolicy proxyPolicy;
4141
private IPType ossClusterAPIPreferredIPType;
@@ -117,11 +117,11 @@ public void setPort(Integer port) {
117117
this.port = port;
118118
}
119119

120-
public String getType() {
120+
public Type getType() {
121121
return type;
122122
}
123123

124-
public void setType(String type) {
124+
public void setType(Type type) {
125125
this.type = type;
126126
}
127127

@@ -231,6 +231,12 @@ public enum ShardPlacement {
231231
SPARSE
232232
}
233233

234+
public enum Type {
235+
@JsonProperty("redis")
236+
REDIS, @JsonProperty("memcached")
237+
MEMCACHED
238+
}
239+
234240
@JsonInclude(JsonInclude.Include.NON_NULL)
235241
public static class ModuleConfig {
236242

@@ -308,7 +314,7 @@ public static final class Builder {
308314
private boolean sharding;
309315
private long memory = DEFAULT_MEMORY;
310316
private Integer port;
311-
private String type;
317+
private Type type;
312318
private boolean ossCluster;
313319
private ProxyPolicy proxyPolicy;
314320
private IPType ossClusterAPIPreferredIPType;
@@ -367,7 +373,7 @@ public Builder port(Integer port) {
367373
return this;
368374
}
369375

370-
public Builder type(String type) {
376+
public Builder type(Type type) {
371377
this.type = type;
372378
return this;
373379
}

core/redis-enterprise-admin/src/test/java/com/redis/enterprise/TestRedisEnterpriseContainer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class TestRedisEnterpriseContainer extends AbstractRedisEnterpriseContain
1212
private Database database = Database.builder().shardCount(2).port(12000).ossCluster(true)
1313
.modules(RedisModule.SEARCH, RedisModule.JSON, RedisModule.TIMESERIES, RedisModule.BLOOM).build();
1414

15-
private static final Logger log = LoggerFactory.getLogger(TestRedisEnterpriseContainer.class);
15+
private final Logger log = LoggerFactory.getLogger(TestRedisEnterpriseContainer.class);
1616

1717
public TestRedisEnterpriseContainer(String dockerImageName) {
1818
super(dockerImageName);

settings.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ buildscript {
1515

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

18-
rootProject.name = 'redis-enterprise-admin-root'
18+
rootProject.name = 'redis-enterprise-admin'
1919

2020
projects {
2121
directories = ['core']
@@ -25,6 +25,7 @@ projects {
2525
id 'org.kordamp.gradle.java-project'
2626
}
2727
dirs(['core']) {
28+
id 'eclipse'
2829
id 'java-library'
2930
id 'org.springframework.boot'
3031
id 'io.spring.dependency-management'

0 commit comments

Comments
 (0)