Skip to content

Commit 4018c55

Browse files
authored
Merge branch 'master' into bug-fix/added-server-license-method-for-tests
2 parents 44a2333 + 5cf80e2 commit 4018c55

26 files changed

+445
-80
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
/target
55
/.idea
66
/*.iml
7+
/bin

ChangeLog.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
66

77
## [Unreleased]
88

9+
### Fixed
10+
11+
- host handling (issue #241)
12+
- logging extended hostresolver
13+
14+
### Added
15+
916
- added smartJoinAttribute and shardingStrategy collection attributes
1017

1118
## [5.0.4] - 2019-18-01

src/main/java/com/arangodb/entity/ArangoDBVersion.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@
2828
*/
2929
public class ArangoDBVersion implements Entity {
3030

31-
public enum License {
32-
ENTERPRISE, COMMUNITY
33-
}
34-
3531
private String server;
3632
private String version;
3733
private License license;

src/main/java/com/arangodb/entity/CollectionPropertiesEntity.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ public class CollectionPropertiesEntity extends CollectionEntity {
3939
private Collection<String> shardKeys;
4040
private final ReplicationFactor replicationFactor;
4141

42+
private String shardingStrategy; // cluster option
43+
private String smartJoinAttribute; // enterprise option
44+
4245
public CollectionPropertiesEntity() {
4346
super();
4447
replicationFactor = new ReplicationFactor();
@@ -126,4 +129,20 @@ public void setSatellite(final Boolean satellite) {
126129
this.replicationFactor.setSatellite(satellite);
127130
}
128131

132+
public String getShardingStrategy() {
133+
return shardingStrategy;
134+
}
135+
136+
public void setShardingStrategy(String shardingStrategy) {
137+
this.shardingStrategy = shardingStrategy;
138+
}
139+
140+
public String getSmartJoinAttribute() {
141+
return smartJoinAttribute;
142+
}
143+
144+
public void setSmartJoinAttribute(String smartJoinAttribute) {
145+
this.smartJoinAttribute = smartJoinAttribute;
146+
}
147+
129148
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* DISCLAIMER
3+
*
4+
* Copyright 2019 ArangoDB GmbH, Cologne, Germany
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
* Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
*/
20+
21+
package com.arangodb.entity;
22+
23+
/**
24+
* @author Axel Becker
25+
*/
26+
public enum License {
27+
28+
ENTERPRISE, COMMUNITY
29+
30+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* DISCLAIMER
3+
*
4+
* Copyright 2019 ArangoDB GmbH, Cologne, Germany
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
* Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
*/
20+
21+
package com.arangodb.entity;
22+
23+
/**
24+
* @author Axel Becker
25+
* https://www.arangodb.com/docs/3.4/http/collection-creating.html
26+
*/
27+
public enum ShardingStrategy {
28+
29+
COMMUNITY_COMPAT("community-compat"),
30+
ENTERPRISE_COMPAT("enterprise-compat"),
31+
ENTERPRISE_SMART_EDGE_COMPAT("enterprise-smart-edge-compat"),
32+
HASH("hash"),
33+
ENTERPRISE_HASH_SMART_EDGE("enterprise-hash-smart-edge");
34+
35+
private String internalName;
36+
37+
private ShardingStrategy(String internalName) {
38+
this.internalName = internalName;
39+
}
40+
41+
public String getInternalName() {
42+
return this.internalName;
43+
}
44+
45+
}

src/main/java/com/arangodb/internal/ArangoExecutorSync.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,23 +53,28 @@ public <T> T execute(final Request request, final Type type, final HostHandle ho
5353
return execute(request, new ResponseDeserializer<T>() {
5454
@Override
5555
public T deserialize(final Response response) throws VPackException {
56-
return createResult(type, response);
56+
T result = createResult(type, response);
57+
return result;
5758
}
5859
}, hostHandle);
5960
}
6061

61-
public <T> T execute(final Request request, final ResponseDeserializer<T> responseDeserializer)
62-
throws ArangoDBException {
62+
public <T> T execute(final Request request, final ResponseDeserializer<T> responseDeserializer) throws ArangoDBException {
6363
return execute(request, responseDeserializer, null);
6464
}
6565

6666
public <T> T execute(
6767
final Request request,
6868
final ResponseDeserializer<T> responseDeserializer,
6969
final HostHandle hostHandle) throws ArangoDBException {
70+
7071
try {
72+
7173
final Response response = protocol.execute(request, hostHandle);
72-
return responseDeserializer.deserialize(response);
74+
T deserialize = responseDeserializer.deserialize(response);
75+
76+
return deserialize;
77+
7378
} catch (final VPackException e) {
7479
throw new ArangoDBException(e);
7580
}

src/main/java/com/arangodb/internal/InternalArangoDatabase.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,13 @@ protected Request getVersionRequest() {
117117
}
118118

119119
protected Request createCollectionRequest(final String name, final CollectionCreateOptions options) {
120-
return request(name(), RequestType.POST, InternalArangoCollection.PATH_API_COLLECTION).setBody(
121-
util().serialize(OptionsBuilder.build(options != null ? options : new CollectionCreateOptions(), name)));
120+
121+
VPackSlice body = util().serialize(OptionsBuilder.build(options != null ? options : new CollectionCreateOptions(), name));
122+
123+
return request(
124+
name(),
125+
RequestType.POST,
126+
InternalArangoCollection.PATH_API_COLLECTION).setBody(body);
122127
}
123128

124129
protected Request getCollectionsRequest(final CollectionsReadOptions options) {

src/main/java/com/arangodb/internal/net/ExtendedHostResolver.java

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,37 @@
2020

2121
package com.arangodb.internal.net;
2222

23+
import java.util.Arrays;
2324
import java.util.Collection;
2425
import java.util.List;
2526

27+
import org.slf4j.Logger;
28+
import org.slf4j.LoggerFactory;
29+
2630
import com.arangodb.internal.util.HostUtils;
2731

2832
/**
2933
* @author Mark Vollmary
3034
*
3135
*/
3236
public class ExtendedHostResolver implements HostResolver {
37+
38+
private static final Logger LOGGER = LoggerFactory.getLogger(ExtendedHostResolver.class);
3339

3440
private static final long MAX_CACHE_TIME = 60 * 60 * 1000;
41+
3542
private EndpointResolver resolver;
36-
private final List<Host> hosts;
43+
private HostSet hosts;
44+
3745
private final Integer maxConnections;
3846
private final ConnectionFactory connectionFactory;
47+
3948
private long lastUpdate;
4049

4150
public ExtendedHostResolver(final List<Host> hosts, final Integer maxConnections,
4251
final ConnectionFactory connectionFactory) {
4352
super();
44-
this.hosts = hosts;
53+
this.hosts = new HostSet(hosts);
4554
this.maxConnections = maxConnections;
4655
this.connectionFactory = connectionFactory;
4756
lastUpdate = 0;
@@ -53,23 +62,40 @@ public void init(final EndpointResolver resolver) {
5362
}
5463

5564
@Override
56-
public List<Host> resolve(final boolean initial, final boolean closeConnections) {
65+
66+
public HostSet resolve(final boolean initial, final boolean closeConnections) {
67+
5768
if (!initial && isExpired()) {
69+
5870
lastUpdate = System.currentTimeMillis();
71+
5972
final Collection<String> endpoints = resolver.resolve(closeConnections);
73+
LOGGER.info("Resolve " + endpoints.size() + " Endpoints");
74+
LOGGER.debug("Endpoints " + Arrays.deepToString(endpoints.toArray()));
75+
6076
if (!endpoints.isEmpty()) {
6177
hosts.clear();
6278
}
79+
6380
for (final String endpoint : endpoints) {
81+
LOGGER.debug("Create HOST from " + endpoint);
82+
6483
if (endpoint.matches(".*://.+:[0-9]+")) {
84+
6585
final String[] s = endpoint.replaceAll(".*://", "").split(":");
6686
if (s.length == 2) {
6787
final HostDescription description = new HostDescription(s[0], Integer.valueOf(s[1]));
68-
hosts.add(HostUtils.createHost(description, maxConnections, connectionFactory));
88+
hosts.addHost(HostUtils.createHost(description, maxConnections, connectionFactory));
89+
} else {
90+
LOGGER.warn("Skip Endpoint (Missung Port)" + endpoint);
6991
}
92+
93+
} else {
94+
LOGGER.warn("Skip Endpoint (Format)" + endpoint);
7095
}
7196
}
7297
}
98+
7399
return hosts;
74100
}
75101

src/main/java/com/arangodb/internal/net/FallbackHostHandler.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public class FallbackHostHandler implements HostHandler {
3838
public FallbackHostHandler(final HostResolver resolver) {
3939
this.resolver = resolver;
4040
iterations = 0;
41-
current = lastSuccess = resolver.resolve(true, false).get(0);
41+
current = lastSuccess = resolver.resolve(true, false).getHostsList().get(0);
4242
firstOpened = true;
4343
}
4444

@@ -54,7 +54,7 @@ public void success() {
5454

5555
@Override
5656
public void fail() {
57-
final List<Host> hosts = resolver.resolve(false, false);
57+
final List<Host> hosts = resolver.resolve(false, false).getHostsList();
5858
final int index = hosts.indexOf(current) + 1;
5959
final boolean inBound = index < hosts.size();
6060
current = hosts.get(inBound ? index : 0);
@@ -79,10 +79,8 @@ public void confirm() {
7979

8080
@Override
8181
public void close() throws IOException {
82-
final List<Host> hosts = resolver.resolve(false, false);
83-
for (final Host host : hosts) {
84-
host.close();
85-
}
82+
final HostSet hosts = resolver.resolve(false, false);
83+
hosts.close();
8684
}
8785

8886
@Override

src/main/java/com/arangodb/internal/net/HostImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,9 @@ public void closeOnError() {
6363
}
6464
}
6565

66+
@Override
67+
public String toString() {
68+
return "HostImpl [connectionPool=" + connectionPool + ", description=" + description + "]";
69+
}
70+
6671
}

src/main/java/com/arangodb/internal/net/HostResolver.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
package com.arangodb.internal.net;
2222

2323
import java.util.Collection;
24-
import java.util.List;
2524

2625
import com.arangodb.ArangoDBException;
2726

@@ -37,6 +36,6 @@ public interface EndpointResolver {
3736

3837
void init(final EndpointResolver resolver);
3938

40-
List<Host> resolve(boolean initial, boolean closeConnections);
39+
HostSet resolve(boolean initial, boolean closeConnections);
4140

4241
}

0 commit comments

Comments
 (0)